This article details how to cross compile Python for the ARM and PowerPC platforms. It should apply equally to other platforms as well, just plug-in the correct cross-compiler. The article supports Python versions, 2.6.6 (Thanks to evadeflow), 2.7.2 and 3.1.1, 3.1.2, 3.1.3, 3.2.2.
Firstly, download the Python that you want to use from http://www.python.org/
Unpack the Python package using tar:
This will create a directory called Python-2.7.2. Goto the directory:
Then run these commands to build the host components:
make python Parser/pgen
mv python hostpython
mv Parser/pgen Parser/hostpgen
make distclean
Download the correct patch for your version of Python:
- Python-2.6.6-xcompile.patch
- Python-2.7.2-xcompile.patch (With ctypes thanks to Jaux (jaux.net)
- Python-3.1.1-xcompile.patch
- Python-3.1.2-xcompile.patch
- Python-3.1.3-xcompile.patch
- Python-3.2.2-xcompile.patch
Then apply the patch:
patch -p1 < Python-2.7.2-xcompile.patch
Then run this (where ~/Python-2.7.2/_install/ is your desired installation path). Note also that you must replace all instances of the cross compiler and the host build system in the lines below. If you are on an x86_64 machine, then you should use x86_64-linux-gnu as the host.
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="ppc_6xx-gcc -shared" CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes HOSTARCH=ppc-linux BUILDARCH=x86_64-linux-gnu
make install HOSTPYTHON=./hostpython BLDSHARED="ppc_6xx-gcc -shared" CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes prefix=~/Python-2.7.2/_install
This will install all your python binaries and libraries in ~/Python-2.7.2/_install.
Copy the entire _install directory to the device, setup the PATH environment variable to include the path the Python executable and run:
…and hopefully all the tests will run correctly.
To speed up the importing of Python modules on the target, I recommend to zip up the lib directory to make a file called python27.zip. This means that we do not have to copy all the Python files to the target, just the one zip file. This technique might also save space, but that depends on your file system. On the host machine:
zip -r -y python27.zip .
Delete libpythonxxx.a site-packages, lib-dynload, config and anything else you do not need from the python27.zip file.
Copy the _install/bin/python to the /usr/bin directory on the target:
Copy the python27.zip file to the /usr/lib directory on the target:
Create a directory on the target called python2.7 in the /usr/lib directory and copy the following directories to that directory:
- ./lib/python2.7/config
- ./lib/python2.7/lib-dynload
- ./lib/python2.7/site-packages
Your directory structure on the target must be as follows:
python2.7 python27.zip
/python/lib/python2.7 # ls
config lib-dynload site-packages
Set the PYTHONHOME environment variable to /usr/ and you are ready to run Python on the target.
The above patches are based on Chris Lambacher’s patches for Python 2.5 here:
http://whatschrisdoing.com/blog/2006/10/06/howto-cross-compile-python-25/
Other links and credits:
http://www.ailis.de/~k/archives/19-ARM-cross-compiling-howto.html

Thanks for the 3.1/2.6 patch updates. I have some new notes on how to cross compile extensions.
Just did this for an ARM computer I have – problem now is the result in _install is 75MB – my machine has 64 MB.
Any thoughts on optimizing/throwing out whats not needed?
The _install directory is really just for initial testing as it contains lots of extra build artifacts. I believe it is much better and faster to use the zip method of deploying to your final system.
Having said this, here are some ways to get the size down for both methods:
rm -rf include
rm -rf share
cd lib
rm libpython2.6.a
cd python2.6
rm -rf `find . -name test`
rm `find . -name "*.pyo"`
rm `find . -name "*.py"`
cd ../../bin
rm python2.6
And strip the python executable. On powerpc, the command is:
This gets my image down to 20M. Now you can delete modules that you do not think you’ll use. Look in the lib/python2.6 directory and delete any subdirectory that you do not think you’ll use. Example of less used modules would be:
– email, xml, sqlite3, curses, idlelib, encodings, lib2to3, lib-tk, etc.
You may even to able to remove the config directory. I removed it and had success.
This got me down to 11M.
The last piece of optimization would be the lib-dynload directory. Some of these shared objects would definitely be needed, but not all.
So, after being very aggressive my _install image is 6M.
Okay, manually copying each directory was much smaller than 75MB of the tarball, more like 5-10MB. Thanks!
Hi, Thanks for the great tutorial.
I try following it but I got few problems that I hope you can help with.
I am compiling Python-2.6.2 on a Ubuntu-x86 and my target is linux on imx27(arm9)
first, when I compile I got some errors during the compilation and in the end I got:
——————————————————
errors
Failed to find the necessary bits to build these modules:
_bsddb _hashlib _sqlite3
_ssl _tkinter bsddb185
bz2 dbm gdbm
readline sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
Failed to build these modules:
_curses _curses_panel binascii
—————————————————————-
second after I ignored those errors and installed the file on my target, when I am running the test script I got:
———————————————————-
root@freescale /$ python -v /lib/python2.6/test/test___all__.py
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
‘import site’ failed; traceback:
ImportError: No module named site
Python 2.6.2 (r262:71600, Nov 3 2009, 21:04:45)
[GCC 4.1.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
Traceback (most recent call last):
File “/lib/python2.6/test/test___all__.py”, line 1, in
import unittest
ImportError: No module named unittest
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear sys.exc_traceback
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# clear sys.flags
# clear sys.float_info
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup __main__
# cleanup[1] zipimport
# cleanup[1] signal
# cleanup[1] exceptions
# cleanup[1] _warnings
# cleanup sys
# cleanup __builtin__
# cleanup ints: 3 unfreed ints
# cleanup floats
——————————————————————
I am attaching also the configure+make+install commands:
—————————————————————]
CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++ AR=arm-none-linux-gnueabi-ar RANLIB=arm-none-linux-gnueabi-ranlib ./configure –host=arm-linux –build=i686-pc-linux-gnu –prefix=/python
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”arm-none-linux-gnueabi-gcc -shared” CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes
make install HOSTPYTHON=./hostpython BLDSHARED=”arm-none-linux-gnueabi-gcc -shared” CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes prefix=~/workspace/DVE/Http/Python-2.6.2/_install
————————————————————
Hi,
I found the problem, it was all about paths.
now I am facing only one probelm. since the binascii module fail to build lots of test cant run. can you figure why it happens?
Hi Amit,
Can you post the error that the test cases give (for binascii)? Ubuntu is probably missing the package you need to compile it properly. I couldn’t find a binascii package, but it could be part of another package. The error message should help me.
Thanks,
Paul
Hi,
A huge thanks for this – worked a treat. I’ve made a 2.6.4 patch if you want it, email me and I’ll send it.
Being new to Python, I’m still trying to get my head around cross compiling the modules side of it. Looking at the setup.py script, it seems to be looking for include files and library files to link to the modules on the host system not the target. Which I guess is why it’s not able to build modules for which I have valid libraries eg ncurses and readline. Amit, what paths did you change? Anything in setup.py?
Can anyone give any experience of cross compiling modules for python?
Did you need any extra patches? Did you modify Setup.local or something else to add your modules to?
Thanks
Rachel
Hi Rachel!
I’ve tried to find on google a patch for cross-compiling python2.6.4 but there is no result. Could you email for me your patch. My email is nguyentiendat05@gmail.com.
Many thanks for you!
Just updated the post for Python 2.6.4.
Great tutorial! If you’re cross-compiling in OS X, the python executable is actually called python.exe (since OS X filenames are case-insensitive). So the make and mv commands should be:
make python.exe Parser/pgen
mv python.exe hostpython
Thank you for your work for cross compile python.I followed your instructions to cross compile python2.6.4 for powerpc405 (i used eldk as cross compile tool). The compilation process was ok, and no errors occured.
I was expecting a trackback to pop up, but I posted about using your technique and getting functional _ctypes support in the bargain. It occurs to me you could incorporate the technique into future patches.
Thanks Art, appreciate the effort. I will test and incorporate into my patches.
Message for Nguyen Thai Binh: Can you contact me on my email or give me yours: snice1981@gmail.com
I would like to use ELDK also but I don’t know how. If you could give me some tips, it would be greate
Thanks
Thanks for the great explanation and patches. Guido, this should be in the mainline! To encourage the use of Python in embedded development it should be as easy as possible to cross-compile it (at least, no source code patching should be needed).
Compiling on Mac OS X: using .exe trick resolved the first problem, but still the system thinks it is compiling something for mac, since it is trying to use CodeFoundation and so. What should I do? I tried removing mac-related lines from Makefile manually but no luck.
I am trying to cross compile Python for MIPS on Mac OS X and am facing the same issue. Using .exe worked until I hit the problem of the system trying o use CoreFoundation. How was this issue resolved?
I ran into an issue compiling Python 2.6.2 and creating a zip with the standard library. It couldn’t import anything, printing and error:
zipimport.ZipImportError: can’t decompress data; zlib not available
So I simply copied zlib.so to /python/lib/python2.6 and it worked.
Just posting here to help my future self
I am trying to port Python 2.7 to ARM linux but I did not find patch for it, can you email for me your patch. My email is ajeet.yadav.77@gmail.com.
Thanks a lot for these instructions, Paul, they saved me a ton of time. I had to tweak your 2.6.5 patch slightly to work with 2.6.6. Here’s Python-2.6.6-xcompile.patch in case you want to post it. (Note: This includes Arthur Shipkowski’s ctypes patch, which I found extremely helpful as well.)
A note to those folks mentioning test failures and module building problems, etc: the python build will carp if you don’t point it at a zlib and ncurses built for your target. You don’t strictly need these—the generated python installation will work fine without them—but the python tests won’t all run.
I was building these for my target, anyway, so all I had to do was set a few env vars:
export CPPFLAGS=/home/delphi/freescale/ltib/rootfs/usr/include
export LDFLAGS=/home/delphi/freescale/ltib/rootfs/usr/lib
Thanks evadeflow for the 2.6.6 patch. I have now posted it on the page.
Following the instructions for 3.1.2, I’ve got several errors during ‘make install’ in the cross-compile phase. I am compiling on CentOs 5.2 for x86_64 with the target being 32-bit powerpc. The same process for 2.6.6 did not encounter the problems below. One of the manifesttions of the compilation errors is that ‘_install/lib/python3.1/encodings’ contains a handful of compiled modules.
make install HOSTPYTHON=./hostpython BLDSHARED=”powerpc-linux-gcc -shared” CROSS_COMPILE=powerpc-linux- CROSS_COMPILE_TARGET=yes prefix=/home/andreytz/python/Python-3.1.2/_install
PYTHONPATH=/home/andreytz/python/Python-3.1.2/_install/lib/python3.1 \
./hostpython -Wi /home/andreytz/python/Python-3.1.2/_install/lib/python3.1/compileall.py \
-d /home/andreytz/python/Python-3.1.2/_install/lib/python3.1 -f \
-x ‘bad_coding|badsyntax|site-packages|lib2to3/tests/data’ \
/home/andreytz/python/Python-3.1.2/_install/lib/python3.1
Traceback (most recent call last):
File “/home/andreytz/python/Python-3.1.2/_install/lib/python3.1/compileall.py”, line 17, in
import struct
File “/home/andreytz/python/Python-3.1.2/_install/lib/python3.1/struct.py”, line 1, in
from _struct import *
ImportError: /home/andreytz/python/Python-3.1.2/build/lib.linux-x86_64-3.1/_struct.so: wrong ELF class: ELFCLASS32
make: [libinstall] Error 1 (ignored)
The root cause of the problem is that linking against the target _struct.so, which is PPC 32-bit ELF file, fails on the x86_64 host. Actually, the similar problem happens in another place, where the link is attempted against the target time.so. This last problem exissts in python-2.6.6, by the way.
Below is a suggested patch that avoids call to struct.pack().
diff -Naur Python-3.1.2.old/Lib/compileall.py Python-3.1.2/Lib/compileall.py
— Python-3.1.2.old/Lib/compileall.py 2009-04-19 10:14:11.000000000 -0700
+++ Python-3.1.2/Lib/compileall.py 2010-11-15 07:38:05.000000000 -0800
@@ -14,7 +14,6 @@
import os
import sys
import py_compile
-import struct
import imp
__all__ = ["compile_dir","compile_path"]
@@ -58,11 +57,9 @@
if not force:
try:
mtime = int(os.stat(fullname).st_mtime)
- expect = struct.pack(‘ ftime:
continue
except IOError:
pass
Hi,
I tried to cross-compile python 3.1.2 for ARM as per the instructions shown in this page.
All worked fine, but when I tried to execute python on the device, it give me errors for string.
if I execute python “Hello”
then it gives errors.
Did I miss something or what? Can you please help my in cross-compiling python for ARM.
Thanks in advance.
Hi Mahendra,
You’ll need to provide me with more information, could you please attach the error you are seeing?
But also, I assume you are not actually running:
$ python “hello”
Because that is not valid as the first argument must be a script to run. Try just running python without any arguments and see if you get the python prompt.
Paul
Hi Paul,
Thank you for your prompt reply.
I used the following configure script on my fedora machine while cross-compiling python for ARM:
CC=/usr/local/arm/4.2.2-eabi/usr/bin/arm-linux-gcc CXX=/usr/local/arm/4.2.2-eabi/usr/bin/arm-linux-g++ AR=/usr/local/arm/4.2.2-eabi/usr/bin/arm-linux-ar RANLIB=/usr/local/arm/4.2.2-eabi/usr/bin/arm-linux-ranlib ./configure –host=arm-linux –build=i686-pc-linux-gnu –prefix=/python
Then I ran the ‘make’ command as follows:
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”arm-linux-gcc -shared” CROSS_COMPILE=/usr/local/arm/4.2.2-eabi/usr/bin/arm-linux- CROSS_COMPILE_TARGET=yes
And finally,
make install HOSTPYTHON=./hostpython BLDSHARED=”arm-linux-gcc -shared” CROSS_COMPILE=/usr/local/arm/4.2.2-eabi/usr/bin/arm-linux- CROSS_COMPILE_TARGET=yes prefix=~/Python-3.1.2/_install
When I move the generated files to my device, I am able to get the python prompt by navigating to the ‘bin’ directory and executing ‘python3′.
Inside the prompt, if I type ’2+2′ (without quotes) then I do get the output as ’4′.
However, when I try to execute
print “Hello”
the prompt give me error as follows:
>>> print “Hello”
File “”, line 1
print “Hello”
^
SyntaxError: invalid syntax
I am not able to identify, why I get this error. Am I missing anything or does it require any extra configuration?
Thanks in advance,
Mahendra.
Hi Mahendra,
Sorry for the delay, I had to setup my arm system again.
What you are seeing is not a bug, it is a difference between Python3 and Python2 with the print command. See this article:
http://renesd.blogspot.com/2007/09/python-3000-breaks-hello-world.html
If you type this it will work:
[GCC 4.4.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("Hello World")
Hello World
>>>
I would suggest using the Python2 series if you need the old Python syntax to work.
Cheers,
Paul
I have updated the post for Python 3.1.3.
Hi,
Just wanted to drop a line to say thanks! Using your instructions, I was able to cross-compile python 2.6.6 on ppc under QNX
I’m still having some trouble with the _socket module. But I think this is related to my using QNX.
Your instructions/patch were invaluable! Thanks a lot!
Cédric
Hi Cédric
I am trying to cross compile python in QNX 6.4.0, however I got some error indicate that acceler.o could not read symbols: File in wrong format
I am build in a QNX 6.4.0 VMware on a normal PC, and trying to build for a PowrePC target.
I have follow the in sturction exactly till patch(new python build correctly in QNX local target)
I have amend the first line after patch to:
./configure CC=qcc CFLAGS=-Vgcc_ntoppcbe –host=i386-pc-nto-qnx6.4.0 –target=ppc-unknown-nto-qnx6.4.0
I have tried serverial option of make and make install, every time, make stops trying to link acceler.o
any suggestions?
Regards
Ji
Hello,
Do you think that the patches 2.6.x works with the python-2.4.4??
If not, what shoud I do?
Can you help me?
Thank you.
Hi Han,
The patches will not work on Python 2.4 series. I suggest you upgrade to Python 2.6.
Paul
Thank you for your answer.
But I have to cross-compile Python-2.4.4 on an embedded device of my company.
The version should be only 2.4.4.
Aren’t there any tips?
Thank you.
I kind of succeeded in cross-compile.
I have a few question.
The capacity of the necessary file(library, Module, *.py, etc.) is 33MB to execute the “python” executable file.
Is it actually so great?
It’s too great for an embedded device.
And the same python source files(ex: *.py) are executable regardless of computer architecture(ARM and PowerPC)??
Thank you.
Hi Han,
I got my file system down to 6M. If you look at my instructions at the end of the post and one of my comments a bit further down the page (26 October 2009) you should be able to get the size down. You could also look at zipping the Python library as per the instructions
Yes, the *.py files will be compiled by Python to the target architecture before they are run.
Paul
Hi Paul, brilliant write-up. It has saved me many hours of work. May you be blessed forever.
RM
Thanks for your Python-2.6.6-xcompile.patch. I meet some problem about cStringIO module. So I must update python to 2.7.1. Do you have Python-2.7.1-xcompile.patch? Can you email this patch to me? My email is yl.bobby@gmail.com
Thanks a lot!
Thank you very much for this post. It was a great help to me.
The only problem I had was that binascii failed to build. I needed this for the CGI module in Python. I found that binascii is dependent on Zlib. I also found that Zlib was not in my toolchain. But following the instructions at http://www.ailis.de/~k/archives/19-ARM-cross-compiling-howto.html , I was able to cross compile Zlib into my toolchain and binascii built fine. I hope this info is helpful to others and thanks again guys for this post.
The patch works great. Thanks! One minor thing that I seem to get with the configure options is that tracebacks raised by exceptions report the location of python files on the build system instead of the target. I thought the –prefix=/usr option was for this but I must be wrong.
Many thanks for this post. I successfully compiled python 2.6 and 3.1.3 for my ARMv7 platform. Do you have an new patch for 2.7.1 and 3.2 ?
Thanks,
Fred.
hello,
i want to use xmpppy module in ma mini 2440…
how i can install that module ?? i cross compiled python and it runs successfully but with one error.. “couldnt find platform independent libraries..conside setting PYTHONHOME…..”
pls help me
thanks in advance
@fayas: Did you set PYTHONHOME as the error suggested?
Patches for 2.7 and 2.7.1 are uploaded.
With the 2.7 series, the success of the build seems to depend on the version of Python on the host machine. Of course, it shouldn’t, but I only have a Python 2.6 machine to test on. Please let me know how you go.
Hello!
I need to use sqlite but when python finishes with bulid i’m getting following error:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 bsddb185
dbm gdbm sunaudiodev
zlib
To find the necessary bits, look in setup.py in detect_modules() for the module’s name.
Failed to build these modules:
_curses _curses_panel _hashlib
_ssl _tkinter bz2
readline
Also, I tried python with sqlite on host and it works. On host i have installed sqlite3 and libsqlite3-dev.
My setup config+make is as follows:
patch -p1 < Python-2.7.1-xcompile.patch
CC=arm-linux-gcc CXX=arm-linux-g++ AR=arm-linux-ar RANLIB=arm-linux-ranlib ./configure –host=arm-linux –build=i386-linux-gnu –prefix=/python
make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-linux-gcc -shared" CROSS_COMPILE=arm-linux- CROSS_COMPILE_TARGET=yes
make install HOSTPYTHON=./hostpython BLDSHARED="arm-linux-gcc -shared" CROSS_COMPILE=arm-linux- CROSS_COMPILE_TARGET=yes prefix=~/Python-2.6.6/_install
Thanks,
Emil
I have the same problem to Emil. And Some modules can’t be imported, such as time,math.
My gcc version is 4.4.5, arm-linux-gcc version is 3.4.1. Do you have any suggestion?
Thanks.
Hi Carl,
I didn’t solve my problem, time constraint. I used PHP with sqlite2 version, instead of python.
Cheers,
Emil
Hi,
Following up on the patch by ‘at1984z’, here is a patch for v2.7.1 which allows most of the ‘make install’ process to complete.
— Python-2.7.1.old/Lib/compileall.py 2010-03-15 20:00:01.000000000 +0200
+++ Python-2.7.1/Lib/compileall.py 2011-06-17 13:39:33.023233845 +0200
@@ -14,7 +14,7 @@
import os
import sys
import py_compile
-import struct
+#import struct
import imp
__all__ = ["compile_dir","compile_file","compile_path"]
@@ -86,12 +86,12 @@
if not force:
try:
mtime = int(os.stat(fullname).st_mtime)
- expect = struct.pack(‘<4sl', imp.get_magic(), mtime)
+# expect = struct.pack('<4sl', imp.get_magic(), mtime)
cfile = fullname + (__debug__ and 'c' or 'o')
with open(cfile, 'rb') as chandle:
actual = chandle.read(8)
- if expect == actual:
- return success
+# if expect == actual:
+ return success
except IOError:
pass
if not quiet:
Regards,
RM
Patch for 2.7.2 (modified from 2.7.1 patch)
--- orig//configure 2011-06-11 16:46:28.000000000 +0100
+++ new//configure 2011-07-21 02:07:46.000000000 +0100
@@ -13673,7 +13673,7 @@
$as_echo_n "(cached) " >&6
else
if test "$cross_compiling" = yes; then :
- ac_cv_have_long_long_format=no
+ ac_cv_have_long_long_format="cross -- assuming yes"
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -13725,7 +13725,7 @@
$as_echo "$ac_cv_have_long_long_format" >&6; }
fi
-if test "$ac_cv_have_long_long_format" = yes
+if test "$ac_cv_have_long_long_format" != no
then
$as_echo "#define PY_FORMAT_LONG_LONG \"ll\"" >>confdefs.h
diff -ru orig//Makefile.pre.in new//Makefile.pre.in
--- orig//Makefile.pre.in 2011-06-11 16:46:26.000000000 +0100
+++ new//Makefile.pre.in 2011-07-21 02:08:00.000000000 +0100
@@ -182,6 +182,7 @@
PYTHON= python$(EXE)
BUILDPYTHON= python$(BUILDEXE)
+HOSTPYTHON= ./$(BUILDPYTHON)
# The task to run while instrument when building the profile-opt target
PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
@@ -215,6 +216,8 @@
# Parser
PGEN= Parser/pgen$(EXE)
+HOSTPGEN= $(PGEN)
+
POBJS= \
Parser/acceler.o \
Parser/grammar1.o \
@@ -407,8 +410,8 @@
# Build the shared modules
sharedmods: $(BUILDPYTHON)
@case $$MAKEFLAGS in \
- *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
- *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
+ *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' PYTHONXCPREFIX='$(DESTDIR)$(prefix)' $(HOSTPYTHON) -E $(srcdir)/setup.py -q build;; \
+ *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' PYTHONXCPREFIX='$(DESTDIR)$(prefix)' $(HOSTPYTHON) -E $(srcdir)/setup.py build;; \
esac
# Build static library
@@ -542,7 +545,7 @@
$(GRAMMAR_H) $(GRAMMAR_C): Parser/pgen.stamp
Parser/pgen.stamp: $(PGEN) $(GRAMMAR_INPUT)
-@$(INSTALL) -d Include
- $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
+ $(HOSTPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
-touch Parser/pgen.stamp
$(PGEN): $(PGENOBJS)
@@ -925,26 +928,26 @@
done; \
done
$(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
- PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
+ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+ $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST)
- PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+ $(HOSTPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
+ $(HOSTPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ $(HOSTPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
+ $(HOSTPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
# Create the PLATDIR source directory, if one wasn't distributed..
$(srcdir)/Lib/$(PLATDIR):
@@ -1049,7 +1052,9 @@
# Install the dynamically loadable modules
# This goes into $(exec_prefix)
sharedinstall: sharedmods
- $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
+ CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
+ $(RUNSHARED) $(HOSTPYTHON) -E $(srcdir)/setup.py install \
+ --skip-build \
--prefix=$(prefix) \
--install-scripts=$(BINDIR) \
--install-platlib=$(DESTSHARED) \
diff -ru orig//setup.py new//setup.py
--- orig//setup.py 2011-06-11 16:46:28.000000000 +0100
+++ new//setup.py 2011-07-21 02:07:46.000000000 +0100
@@ -23,6 +23,10 @@
# This global variable is used to hold the list of modules to be disabled.
disabled_module_list = []
+# _ctypes fails to cross-compile due to the libffi configure script.
+if os.environ.has_key('PYTHONXCPREFIX'):
+ disabled_module_list.append('_ctypes')
+
def add_dir_to_list(dirlist, dir):
"""Add the directory 'dir' to the list 'dirlist' (at the front) if
1) 'dir' is not already in 'dirlist'
@@ -278,6 +282,14 @@
(ext.name, sys.exc_info()[1]))
self.failed.append(ext.name)
return
+
+ # Inport check will not work when cross-compiling.
+ if os.environ.has_key('PYTHONXCPREFIX'):
+ self.announce(
+ 'WARNING: skipping inport check for cross-compiled: "%s"' %
+ ext.name)
+ return
+
# Workaround for Mac OS X: The Carbon-based modules cannot be
# reliably imported into a command-line Python
if 'Carbon' in ext.extra_link_args:
Revised patch for 2.7.2 including Art’s ctype patch to setup.py
Note I have also knocked out some of the search for /usr/lib and /usr/local/lib so the build doesn’t find headers you might have on your host systems which aren’t relevant for your cross compiled environment. There are definitely more of these!
+++ ./configure 2011-07-25 22:04:05.000000000 +0100
@@ -13673,7 +13673,7 @@
$as_echo_n "(cached) " >&6
else
if test "$cross_compiling" = yes; then :
- ac_cv_have_long_long_format=no
+ ac_cv_have_long_long_format="cross -- assuming yes"
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
@@ -13725,7 +13725,7 @@
$as_echo "$ac_cv_have_long_long_format" >&6; }
fi
-if test "$ac_cv_have_long_long_format" = yes
+if test "$ac_cv_have_long_long_format" != no
then
$as_echo "#define PY_FORMAT_LONG_LONG \"ll\"" >>confdefs.h
--- ./Makefile.pre.in.orig 2011-06-11 16:46:26.000000000 +0100
+++ ./Makefile.pre.in 2011-07-25 22:04:05.000000000 +0100
@@ -182,6 +182,7 @@
PYTHON= python$(EXE)
BUILDPYTHON= python$(BUILDEXE)
+HOSTPYTHON= ./$(BUILDPYTHON)
# The task to run while instrument when building the profile-opt target
PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
@@ -215,6 +216,8 @@
# Parser
PGEN= Parser/pgen$(EXE)
+HOSTPGEN= $(PGEN)
+
POBJS= \
Parser/acceler.o \
Parser/grammar1.o \
@@ -407,8 +410,8 @@
# Build the shared modules
sharedmods: $(BUILDPYTHON)
@case $$MAKEFLAGS in \
- *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
- *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
+ *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' PYTHONXCPREFIX='$(DESTDIR)$(prefix)' $(HOSTPYTHON) -E $(srcdir)/setup.py -q build;; \
+ *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' PYTHONXCPREFIX='$(DESTDIR)$(prefix)' $(HOSTPYTHON) -E $(srcdir)/setup.py build;; \
esac
# Build static library
@@ -542,7 +545,7 @@
$(GRAMMAR_H) $(GRAMMAR_C): Parser/pgen.stamp
Parser/pgen.stamp: $(PGEN) $(GRAMMAR_INPUT)
-@$(INSTALL) -d Include
- $(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
+ $(HOSTPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
-touch Parser/pgen.stamp
$(PGEN): $(PGENOBJS)
@@ -925,26 +928,26 @@
done; \
done
$(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
- PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
+ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+ $(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST)
- PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
+ $(HOSTPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
+ $(HOSTPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
+ $(HOSTPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
- ./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
+ $(HOSTPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
# Create the PLATDIR source directory, if one wasn't distributed..
$(srcdir)/Lib/$(PLATDIR):
@@ -1049,7 +1052,9 @@
# Install the dynamically loadable modules
# This goes into $(exec_prefix)
sharedinstall: sharedmods
- $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
+ CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
+ $(RUNSHARED) $(HOSTPYTHON) -E $(srcdir)/setup.py install \
+ --skip-build \
--prefix=$(prefix) \
--install-scripts=$(BINDIR) \
--install-platlib=$(DESTSHARED) \
--- ./setup.py.orig 2011-06-11 16:46:28.000000000 +0100
+++ ./setup.py 2011-07-26 13:10:39.000000000 +0100
@@ -278,6 +278,14 @@
(ext.name, sys.exc_info()[1]))
self.failed.append(ext.name)
return
+
+ # Inport check will not work when cross-compiling.
+ if os.environ.has_key('PYTHONXCPREFIX'):
+ self.announce(
+ 'WARNING: skipping inport check for cross-compiled: "%s"' %
+ ext.name)
+ return
+
# Workaround for Mac OS X: The Carbon-based modules cannot be
# reliably imported into a command-line Python
if 'Carbon' in ext.extra_link_args:
@@ -369,8 +377,8 @@
def detect_modules(self):
# Ensure that /usr/local is always used
- add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
- add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
+ # add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
+ # add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
self.add_multiarch_paths()
# Add paths specified in the environment variables LDFLAGS and
@@ -427,8 +435,8 @@
# if a file is found in one of those directories, it can
# be assumed that no additional -I,-L directives are needed.
lib_dirs = self.compiler.library_dirs + [
- '/lib64', '/usr/lib64',
- '/lib', '/usr/lib',
+ # '/lib64', '/usr/lib64',
+ # '/lib', '/usr/lib',
]
inc_dirs = self.compiler.include_dirs + ['/usr/include']
exts = []
@@ -1860,7 +1868,7 @@
ffi_configfile):
from distutils.dir_util import mkpath
mkpath(ffi_builddir)
- config_args = []
+ config_args = sysconfig.get_config_var("CONFIG_ARGS").split(" ")
# Pass empty CFLAGS because we'll just append the resulting
# CFLAGS to Python's; -g or -O2 is to be avoided.
[...] 1.0.0c src, PyCrypto 2.3 src, PycURL 7.19.0 src, pyOpenSSL 0.11 src, Python 2.6.6 src with a patch to ease the cross compilation src, Python Imaging Library 1.1.7 src, sqlite 3.7.4 src, yenc 0.3 src, and zlib 1.2.5 src. No [...]