First let’s do cross-compile a Hello World in C before porting python to friendlyarm, and so we need to install the cross-compiling toolchains for ARM platform (arm-linux-gcc)
To do this we split the tutorial in a few steps:
Step 1: Install the arm-linux-gcc
To do the cross-compiler used the arm-linux-gcc-4.3.2.tgz, which is available at: http://www.friendlyarm.net/dl.php?file=arm-linux-gcc-4.3.2.tgz
Unzip it in /usr/local/armgcc and then add the path in the path like this:
Step 2: Create a sample helloword in C and make the cross-compiler for arm
Create a C program helloworld.c
printf (“Hello World!\n”);
Make a normal build: gcc helloworld.c -o helloNormal
The output will be the one below, which shows that this file is compiled to processor pc:
helloNormal: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU / Linux 2.6.15, not stripped
With this file is not possible to run at friendlyarm they still did not cross-compiler.
To generate the binary cross-compiled arm to do so:
arm-linux-gcc -s helloworld.c -o helloArm
Now we have a program in C that can run on FriendlyArm, to be sure, let’s check the file:
The output will be the one below, which shows that this file is compiled to FriendlyArm:
helloArm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, stripped
Okay, now just put the file in helloArm FriendlyArm and run:
As output we get:
Step 3: Porting python to FriendlyArm
We will download the python in http://www.python.org.
We will use the example version 2.6.5
Once you have downloaded the python will unpack it using tar:
tar -xvzf Python-2.6.5.tgz
The result is the creation of the directory Python-2.6.5, now enter the created directory:
Now, execute the following commands to create the components of the host:
make python Parser/pgen
mv hostpython python
mv Parser/Parser pgen/hostpgen
The next step is to download the correct patch for your version of python which is located in:
Then we will apply the patch:
patch -p1 < Python-2.6.5-xcompile.patch
Then run the following commands:
CC=ppc_6xx-gcc CXX=ppc_6xx-g++ AR=ppc_6xx-ar RANLIB=ppc_6xx-ranlib ./configure –host=ppc-linux –build=i686-pc-linux-gnu –prefix=/python
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”ppc-linux-gcc -shared” CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes
make install HOSTPYTHON=./hostpython BLDSHARED=”ppc-linux-gcc -shared” CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes prefix=~/Python-2.6.5/_install
This will install the binaries and libs in ~/Python-2.6.5/_install.
Copy the entire _install directory to the device, setup the PATH environment variable to include the location of the Python executable and run:
To accelerate the import of Python modules, we recommend creating one. Zip, with that we will not need to copy “all” the files manually.
zip -r -y python26.zip .
Copy the _install/bin/python to the /usr/bin directory on the target:
Copy the python26.zip file to the /usr/lib directory on the target:
Create a directory named python2.6 /usr/lib and copy it to the following directories:
The structure of your directory should be like the one below:
/usr/lib # ls
/python/lib/python2.6 # ls
config lib-dynload site-package
Set the environment variable PYTHONHOME para /usr/ and you will already be running python in his FriendlyArm
Further, this process will build only the binary python, So the libraries will not be running.