We need a patch to enable the original source to support cross compile.
Suppose we are cross compile Python-2.7.3 for arm, we should do below steps to get the target binary file:
Step 1: build host python:
- tar -xvzf Python-2.7.2.tgz
- cd Python-2.7.2
- ./configure
- make python Parser/pgen
- mv python hostpython
- mv Parser/pgen Parser/hostpgen
Step 2: apply cross compile patch to source.
- patch source [ Python-2.7.2-xcompile.patch].
patch -p1 < Python-2.7.2-xcompile.patch
- add toolchain’s path to PATH enviroment.
export PATH=/home/username/arm/yctek/yctools/gcc/bin:$PATH:
- do configure.
LDFLAGS='-L/home/username/arm/dist/lib' CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++ RANLIB=arm-none-linux-gnueabi-ranlib CFLAGS='--sysroot=/home/username/arm/yctek/yctools/gcc/arm-none-linux-gnueabi/sys-root' ./configure --host=arm-linux-gnueabi --prefix=/home/username/arm/dist
- do make.
make -j 4 HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes HOSTARCH=arm-linux-gnueabi BUILDARCH=x86_64-linux-gnu
- do install.
make install HOSTPYTHON=./hostpython BLDSHARED="arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes prefix=/home/username/arm/dist/python
The final target binary is located in /home/username/arm/dist/python.
ref:
1. http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html
2. http://www.csce.uark.edu/~yfrancku/cross-python.html