分类: LINUX
2009-01-22 16:15:26
|
I started with Klaus Reimer’s and made made some updates required by changes between Python 2.2 and 2.5.
The changes I made are captured in an . The changes made the configure.in are to disable rules that cause configure failures when cross compiling because they look for files on the target system or require a test program to be compiled and run. The other changes I added over the patch from Klaus Reimer are for a specific issue I had where md5 and sha hash algorithms were not built because setup.py which builds the modules is not cross compile aware and detected the OpenSSL libraries on my build machine rather than the target.
You can apply the patch with the following command:
lambacck:~/tmp/Python2.5$ patch -p1 < ../Python2.5_xcompile.patch
I next generated a “host” python as in :
lambacck:~/tmp/Python2.5$ ./configure
lambacck:~/tmp/Python2.5$ make python Parser/pgen
lambacck:~/tmp/Python2.5$ mv python hostpython
lambacck:~/tmp/Python2.5$ mv Parser/pgen Parser/hostpgen
lambacck:~/tmp/Python2.5$ make distclean
I exported necessary variables like CC, CXX, AR, RANLIB, LD, CFLAGS, CXXFLAGS, LDFLAGS for my target. The key is for these to point to the libraries you are going to use.
To build and “install” python for the my target I used the following commands:
lambacck:~/tmp/Python2.5$ ./configure –host=ppc-linux –build=i686-pc-linux-gnu –prefix=/python
lambacck:~/tmp/Python2.5$ make EXTRA_CFLAGS=”$CFLAGS” HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=’ppc-linux-gcc -shared’ CROSS_COMPILE=yes
lambacck:~/tmp/Python2.5$ make install EXTRA_CFLAGS=”$CFLAGS” HOSTPYTHON=./hostpython BLDSHARED=’ppc-linux-gcc -shared’ CROSS_COMPILE=yes prefix=/home/lambacck/tmp/dest/python
Note that I needed to use EXTRA_CFLAGS to add my target specific CFLAGS because for some reason the Python configure process does not honor the ones I provided while doing configure. The LDFLAGS variable, however, did work.
Also notice that I set the prefix in the configure step to be /python and the set another prefix in the make install step. The prefix in the configure step is where we are putting python on the file system on the target. The prefix in the install step is where we are putting all of the bits to be able to package them up to be ready to send to the target.
After all that I have a (mostly) functional python environment on my target, but I still needed to get PyXML built. I downloaded the latest distribution, modified setup.py so that expat was forced into little-endian mode and ran the following commands:
lambacck:~/tmp/PyXML-0.8.4$ LDSHARED=’ppc-linux-gcc -shared’ CC=”${CC}” OPT=’-DNDEBUG -g -O3 -Wall -Wstrict-prototypes’ ~/tmp/Python-2.5/hostpython -E setup.py build
lambacck:~/tmp/PyXML-0.8.4$ LDSHARED=’ppc-linux-gcc -shared’ CC=”${CC}” OPT=’-DNDEBUG -g -O3 -Wall -Wstrict-prototypes’ ~/tmp/cross_python/Python-2.5/hostpython -E setup.py install –prefix=$HOME/tmp/dest/python/ –install-scripts=/home/lambacck/tmp/dest/python/bin
It looks like Distutils and the Python build process in general could use some cross compile support. I think this is currently far harder than it has to be.
http://whatschrisdoing.com/blog/2006/10/06/howto-cross-compile-python-25/
=============================================================
export PREFIX=/home/usr/liuhongbing/tmp/install_python
export ARCH=mips
export CROSS_COMPILE=c2-linux-
export CC=${CROSS_COMPILE}gcc
export CXX=${CROSS_COMPILE}g++
export AR=${CROSS_COMPILE}ar
export RANLIB=${CROSS_COMPILE}ranlib
export NM=${CROSS_COMPILE}nm
export AS=${CROSS_COMPILE}as
export LD=${CROSS_COMPILE}ld
./configure --prefix=$PREFIX --build=i686 --target=mips-linux --host=mips-linux
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen CROSS_COMPILE=yes
make install HOSTPYTHON=./hostpython CROSS_COMPILE=yes prefix=/home/usr/liuhongbing/tmp/install_python
交叉编译openssl:
export PREFIX=/home/usr/liuhongbing/tmp/install_openssl
./Configure linux-mips -DB_ENDIAN linux:'c2-linux-gcc' --prefix=$PREFIX