Embedded people have cross compiled python for quite some time now, with more or less success. These activities have taken place in various embedded build systems, such as PTXdist, OpenEmbedded and others.
I suppose instead of wasting the time over and over again, without proper review by the Python core developers, I would like to find out if it is possible to get cross compilation support integrated in the upstream tree. This patch series reflects what we currently have in PTXdist. Please see it as an RFC.
It is probably not perfect yet, but I would like to see some feedback from you Python guys out there. Do you see issues with these patches? Would it be possible in general to get something similar to this series into the Python mainline?
Robert
If cross compiling it must be possible to overwrite the so_ext from the outside.
Signed-off-by: Robert Schwebel r.schwebel@pengutronix.de
--- Lib/distutils/command/build_ext.py | 2 ++ 1 file changed, 2 insertions(+)
Index: Python-3.0/Lib/distutils/command/build_ext.py =================================================================== --- Python-3.0.orig/Lib/distutils/command/build_ext.py +++ Python-3.0/Lib/distutils/command/build_ext.py @@ -642,6 +642,8 @@ class build_ext(Command): ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8] # extensions in debug_mode are named 'module_d.pyd' under windows so_ext = get_config_var('SO') + if os.environ.get('CROSS_COMPILING') == 'yes': + so_ext = os.environ.get('SO') if os.name == 'nt' and self.debug: return os.path.join(*ext_path) + '_d' + so_ext return os.path.join(*ext_path) + so_ext
Robert Schwebel <r.schwebel <at> pengutronix.de> writes:
If cross compiling it must be possible to overwrite the so_ext from the outside.
Thanks for those patches, but please post them to the issue tracker instead (http://bugs.python.org/). If each patch is for a distinct purpose, then open separate issues, otherwise please merge the patches into a single one.
Antoine.
When cross compiling we need a PYTHON_FOR_BUILD, PGEN_FOR_BUILD etc. The names follow usual autotool nomenclatures.
Patch is originally from here: http://bugs.gentoo.org/attachment.cgi?id=130627
and was ported to Python 3.0rc2
Signed-off-by: Robert Schwebel r.schwebel@pengutronix.de
--- Makefile.pre.in | 116 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 82 insertions(+), 34 deletions(-)
Index: Python-3.0/Makefile.pre.in =================================================================== --- Python-3.0.orig/Makefile.pre.in +++ Python-3.0/Makefile.pre.in @@ -28,6 +28,8 @@ VERSION= @VERSION@ srcdir= @srcdir@ VPATH= @srcdir@
+export srcdir + CC= @CC@ CXX= @CXX@ MAINCC= @MAINCC@ @@ -72,6 +74,15 @@ CFLAGSFORSHARED=@CFLAGSFORSHARED@ # C flags used for building the interpreter object files PY_CFLAGS= $(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
+# For cross compile: build compiler options +CC_FOR_BUILD= @CC_FOR_BUILD@ +CROSS_COMPILING= @cross_compiling@ +EXEEXT_FOR_BUILD= @EXEEXT_FOR_BUILD@ +O_FOR_BUILD= @O_FOR_BUILD@ +CFLAGS_FOR_BUILD= @CFLAGS_FOR_BUILD@ +CPPFLAGS_FOR_BUILD= @CPPFLAGS_FOR_BUILD@ -I$(srcdir)/Include +LDFLAGS_FOR_BUILD= @LDFLAGS_FOR_BUILD@ +LIBS_FOR_BUILD= @LIBS_FOR_BUILD@
# Machine-dependent subdirectories MACHDEP= @MACHDEP@ @@ -173,7 +184,8 @@ LIBOBJDIR= Python/ LIBOBJS= @LIBOBJS@
PYTHON= python$(EXE) -BUILDPYTHON= python$(BUILDEXE) +BUILDPYTHON= python$(EXE) +PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
# 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 @@ -203,7 +215,8 @@ GRAMMAR_INPUT= $(srcdir)/Grammar/Grammar
########################################################################## # Parser -PGEN= Parser/pgen$(EXE) +PGEN_FOR_BUILD= Parser/pgen$(EXEEXT_FOR_BUILD) +
POBJS= \ Parser/acceler.o \ @@ -220,18 +233,31 @@ POBJS= \
PARSER_OBJS= $(POBJS) Parser/myreadline.o Parser/tokenizer.o
-PGOBJS= \ - Objects/obmalloc.o \ - Python/mysnprintf.o \ - Parser/tokenizer_pgen.o \ - Parser/printgrammar.o \ - Parser/pgenmain.o +POBJS_FOR_BUILD= \ + Parser/acceler.$(O_FOR_BUILD) \ + Parser/grammar1.$(O_FOR_BUILD) \ + Parser/listnode.$(O_FOR_BUILD) \ + Parser/node.$(O_FOR_BUILD) \ + Parser/parser.$(O_FOR_BUILD) \ + Parser/parsetok.$(O_FOR_BUILD) \ + Parser/bitset.$(O_FOR_BUILD) \ + Parser/metagrammar.$(O_FOR_BUILD) \ + Parser/firstsets.$(O_FOR_BUILD) \ + Parser/grammar.$(O_FOR_BUILD) \ + Parser/pgen.$(O_FOR_BUILD) + +PGOBJS_FOR_BUILD= \ + Objects/obmalloc.$(O_FOR_BUILD) \ + Python/mysnprintf.$(O_FOR_BUILD) \ + Parser/tokenizer_pgen.$(O_FOR_BUILD) \ + Parser/printgrammar.$(O_FOR_BUILD) \ + Parser/pgenmain.$(O_FOR_BUILD)
PARSER_HEADERS= \ Parser/parser.h \ Parser/tokenizer.h
-PGENOBJS= $(PGENMAIN) $(POBJS) $(PGOBJS) +PGENOBJS= $(POBJS_FOR_BUILD) $(PGOBJS_FOR_BUILD)
########################################################################## # AST @@ -385,15 +411,28 @@ $(BUILDPYTHON): Modules/python.o $(LIBRA Modules/python.o \ $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
-platform: $(BUILDPYTHON) - $(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform - +platform: $(PYTHON_FOR_BUILD) + $(RUNSHARED) $(PYTHON_FOR_BUILD) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' > platform
# Build the shared modules -sharedmods: $(BUILDPYTHON) +sharedmods: $(PYTHON_FOR_BUILD) @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) \ + CROSS_COMPILING=$(CROSS_COMPILING) \ + CC='$(CC)' \ + LDSHARED='$(BLDSHARED)' \ + OPT='$(OPT)' \ + $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py -q build \ + ;; \ + *) \ + $(RUNSHARED) \ + CROSS_COMPILING=$(CROSS_COMPILING) \ + CC='$(CC)' \ + LDSHARED='$(BLDSHARED)' \ + OPT='$(OPT)' \ + $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py build \ + ;; \ esac
# Build static library @@ -509,12 +548,12 @@ Modules/python.o: $(srcdir)/Modules/pyth $(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
-$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT) +$(GRAMMAR_H) $(GRAMMAR_C): $(PGEN_FOR_BUILD) $(GRAMMAR_INPUT) -@$(INSTALL) -d Include - -$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C) + -$(PGEN_FOR_BUILD) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
-$(PGEN): $(PGENOBJS) - $(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN) +$(PGEN_FOR_BUILD): $(PGENOBJS) + $(CC_FOR_BUILD) $(OPT) $(LDFLAGS_FOR_BUILD) $(PGENOBJS) $(LIBS_FOR_BUILD) -o $(PGEN_FOR_BUILD)
Parser/grammar.o: $(srcdir)/Parser/grammar.c \ $(srcdir)/Include/token.h \ @@ -567,6 +606,13 @@ Objects/unicodeobject.o: $(srcdir)/Objec Python/formatter_unicode.o: $(srcdir)/Python/formatter_unicode.c \ $(BYTESTR_DEPS)
+############################################################################ +# Cross compile rules + +# .x is a native object files during cross-compile. +.SUFFIXES: .x +.c.x: + $(CC_FOR_BUILD) -c $(CPPFLAGS_FOR_BUILD) $(CFLAGS_FOR_BUILD) -o $@ $<
############################################################################ # Header files @@ -665,7 +711,7 @@ $(LIBRARY_OBJS) $(MODOBJS) Modules/pytho
TESTOPTS= -l $(EXTRATESTOPTS) TESTPROG= $(srcdir)/Lib/test/regrtest.py -TESTPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) -E -bb +TESTPYTHON= $(RUNSHARED) $(PYTHON_FOR_BUILD) -E -tt test: all platform -find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f -$(TESTPYTHON) $(TESTPROG) $(TESTOPTS) @@ -688,8 +734,7 @@ testuniversal: all platform -find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f -$(TESTPYTHON) $(TESTPROG) $(TESTOPTS) -uall $(TESTPYTHON) $(TESTPROG) $(TESTOPTS) -uall - $(RUNSHARED) /usr/libexec/oah/translate ./$(BUILDPYTHON) -E $(TESTPROG) $(TESTOPTS) -uall - + $(RUNSHARED) /usr/libexec/oah/translate $(PYTHON_FOR_BUILD) -E -tt $(TESTPROG) $(TESTOPTS) -uall
# Like testall, but with a single pass only # run an optional script to include some information about the build environment @@ -816,7 +861,8 @@ LIBSUBDIRS= tkinter site-packages test t setuptools setuptools/command setuptools/tests setuptools.egg-info \ multiprocessing multiprocessing/dummy \ curses $(MACHDEPS) -libinstall: build_all $(srcdir)/Lib/$(PLATDIR) + +libinstall: $(srcdir)/Lib/$(PLATDIR) $(PYTHON_FOR_BUILD) @for i in $(SCRIPTDIR) $(LIBDEST); \ do \ if test ! -d $(DESTDIR)$$i; then \ @@ -873,29 +919,29 @@ libinstall: build_all $(srcdir)/Lib/$(PL done $(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \ + $(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST) -f \ -x 'bad_coding|badsyntax|site-packages' $(DESTDIR)$(LIBDEST) -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \ + $(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST) -f \ -x 'bad_coding|badsyntax|site-packages' $(DESTDIR)$(LIBDEST) -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \ + $(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST)/site-packages -f \ -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \ + $(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST)/site-packages -f \ -x badsyntax $(DESTDIR)$(LIBDEST)/site-packages -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ - ./$(BUILDPYTHON) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()" + $(PYTHON_FOR_BUILD) -Wi -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
# Create the PLATDIR source directory, if one wasn't distributed.. $(srcdir)/Lib/$(PLATDIR): mkdir $(srcdir)/Lib/$(PLATDIR) cp $(srcdir)/Lib/plat-generic/regen $(srcdir)/Lib/$(PLATDIR)/regen - export PATH; PATH="`pwd`:$$PATH"; \ + export PATH; PATH="`dirname $(PYTHON_FOR_BUILD)`:$$PATH"; \ export PYTHONPATH; PYTHONPATH="`pwd`/Lib"; \ export DYLD_FRAMEWORK_PATH; DYLD_FRAMEWORK_PATH="`pwd`"; \ export EXE; EXE="$(BUILDEXE)"; \ @@ -976,8 +1022,9 @@ libainstall: all # Install the dynamically loadable modules # This goes into $(exec_prefix) sharedinstall: - $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \ - --prefix=$(prefix) \ + CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' CROSS_COMPILING='$(CROSS_COMPILING)' \ + $(RUNSHARED) $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py install \ + --prefix=$(prefix) \ --install-scripts=$(BINDIR) \ --install-platlib=$(DESTSHARED) \ --root=/$(DESTDIR) @@ -1054,8 +1101,8 @@ frameworkinstallextras:
# This installs a few of the useful scripts in Tools/scripts scriptsinstall: - SRCDIR=$(srcdir) $(RUNSHARED) \ - ./$(BUILDPYTHON) $(srcdir)/Tools/scripts/setup.py install \ + $(RUNSHARED) \ + $(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/setup.py install \ --prefix=$(prefix) \ --install-scripts=$(BINDIR) \ --root=/$(DESTDIR) @@ -1130,11 +1177,12 @@ profile-removal: find . -name '*.gc??' -exec rm -f {} ';'
clobber: clean profile-removal - -rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \ + -rm -f $(BUILDPYTHON) $(PGEN_FOR_BUILD) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \ tags TAGS \ config.cache config.log pyconfig.h Modules/config.c -rm -rf build platform -rm -rf $(PYTHONFRAMEWORKDIR) + -rm -rf buildpython
# Make things extra clean, before making a distribution: # remove all generated files, even Makefile[.pre]
This patch is originally from here: http://bugs.gentoo.org/attachment.cgi?id=130627
Add documentation for cross compilation scenario.
Signed-off-by: Robert Schwebel r.schwebel@pengutronix.de
--- README | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
Index: Python-3.0/README =================================================================== --- Python-3.0.orig/README +++ Python-3.0/README @@ -156,6 +156,50 @@ there. For example: should do a "make clean" at the toplevel first.)
+Cross Compiling +--------------- + +Python can be cross compiled by supplying different --build and --host +parameters to configure. Python is compiled on the "build" system and +executed on the "host" system. Cross compiling python requires a +native Python on the build host, and a natively compiled tool `Pgen'. + +Before cross compiling, Python must first be compiled and installed on +the build host. The configure script will use `cc' and `python', or +environment variables CC_FOR_BUILD or PYTHON_FOR_BUILD, eg: + + CC_FOR_BUILD=gcc-3.3 \ + PYTHON_FOR_BUILD=python3.0 \ + .../configure --build=i686-linux --host=i586-mingw32 + +Cross compiling has been tested under linux, mileage may vary for +other platforms. + +A few reminders on using configure to cross compile: + +- Cross compile tools must be in PATH, + +- Cross compile tools must be prefixed with the host type + (ie i586-mingw32-gcc, powerpc-darwin8-ranlib, ...), + +- CC, CXX, AR, and RANLIB must be undefined when running configure, + they will be auto-detected. + +- Autoconf must be stopped from autodetecting definitions for the + build machine. This is easiest done by creating a config.cache + that overrides ac_cv_* variables appropriately. + +If you need a cross compiler, Debian ships several several (eg: avr, +m68hc1x, mingw32), while dpkg-cross easily creates others. Otherwise, +check out one of these cross toolchain projects: + +- crosstool: + http://www.kegel.com/crosstool + +- OSELAS.Toolchain: + http://www.pengutronix.de/oselas/toolchain/index_en.html + + Copyright and License Information ---------------------------------
Add the necessary bits for feeding PYTHON_FOR_BUILD into the python build process.
Patch is originally from here, adapted to python 3.0rc2: http://bugs.gentoo.org/attachment.cgi?id=130627
Signed-off-by: Robert Schwebel r.schwebel@pengutronix.de
--- configure.in | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 4 deletions(-)
Index: Python-3.0/configure.in =================================================================== --- Python-3.0.orig/configure.in +++ Python-3.0/configure.in @@ -12,6 +12,11 @@ AC_INIT(python, PYTHON_VERSION, http://w AC_CONFIG_SRCDIR([Include/object.h]) AC_CONFIG_HEADER(pyconfig.h)
+# find compiler while respecting --host setting +#AC_CANONICAL_HOST() +AC_CHECK_TOOLS(CC,gcc cc) +AC_CHECK_TOOLS(CXX,g++ c++) + dnl This is for stuff that absolutely must end up in pyconfig.h. dnl Please use pyport.h instead, if possible. AH_TOP([ @@ -214,6 +219,7 @@ AC_SUBST(MACHDEP) AC_MSG_CHECKING(MACHDEP) if test -z "$MACHDEP" then + if test "$cross_compiling" = "no"; then ac_sys_system=`uname -s` if test "$ac_sys_system" = "AIX" -o "$ac_sys_system" = "Monterey64" \ -o "$ac_sys_system" = "UnixWare" -o "$ac_sys_system" = "OpenUNIX"; then @@ -234,6 +240,19 @@ then irix646) MACHDEP="irix6";; '') MACHDEP="unknown";; esac + else + m=`$CC -dumpmachine` + changequote(<<, >>)#dnl + ac_sys_system=`expr "$m" : "[^-]*-([^-]*)"` + changequote([, ])#dnl + + case $ac_sys_system in + cygwin*) ac_sys_system=`echo $ac_sys_system | sed s/cygwin/CYGWIN/g `;; + darwin*) ac_sys_system=`echo $ac_sys_system | sed s/darwin/Darwin/g `;; + freebsd*) ac_sys_system=`echo $ac_sys_system | sed s/freebsd/FreeBSD/g `;; + linux*) ac_sys_system=`echo $ac_sys_system | sed s/linux/Linux/g `;; + esac + fi fi # Some systems cannot stand _XOPEN_SOURCE being defined at all; they @@ -503,9 +522,11 @@ if test -d casesensitivetestdir then AC_MSG_RESULT(yes) BUILDEXEEXT=.exe + case_sensitive=no else AC_MSG_RESULT(no) BUILDEXEEXT=$EXEEXT + case_sensitive=yes fi rmdir CaseSensitiveTestDir
@@ -705,9 +726,9 @@ fi
AC_MSG_RESULT($LDLIBRARY)
-AC_PROG_RANLIB -AC_SUBST(AR) -AC_CHECK_PROGS(AR, ar aal, ar) +# find tools while respecting --host setting +AC_CHECK_TOOL(RANLIB,ranlib) +AC_CHECK_TOOLS(AR,ar aal,ar)
AC_SUBST(SVNVERSION) AC_CHECK_PROG(SVNVERSION, svnversion, found, not-found) @@ -3546,6 +3567,7 @@ else fi
AC_MSG_CHECKING(for %zd printf() format support) +AC_CACHE_VAL(ac_cv_printf_zd_format, AC_TRY_RUN([#include <stdio.h> #include <stddef.h> #include <string.h> @@ -3582,7 +3604,9 @@ int main() }], [AC_MSG_RESULT(yes) AC_DEFINE(PY_FORMAT_SIZE_T, "z", [Define to printf format modifier for Py_ssize_t])], - AC_MSG_RESULT(no)) + AC_MSG_RESULT(no), + AC_MSG_RESULT(no))) +
AC_CHECK_TYPE(socklen_t,, AC_DEFINE(socklen_t,int, @@ -3633,6 +3657,64 @@ for dir in $SRCDIRS; do done AC_MSG_RESULT(done)
+# cross compiling +AC_SUBST(cross_compiling) + +if test "$cross_compiling" = "yes"; then + AC_MSG_CHECKING(cc for build) + CC_FOR_BUILD="${CC_FOR_BUILD-cc}" +else + CC_FOR_BUILD="${CC_FOR_BUILD-$CC}" +fi + +if test "$cross_compiling" = "yes"; then + AC_MSG_RESULT($CC_FOR_BUILD) +fi + +AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler (default: cc)]) + +if test "$cross_compiling" = "yes"; then + AC_MSG_CHECKING(python for build) + PYTHON_FOR_BUILD="${PYTHON_FOR_BUILD-python}" + PYTHON_FOR_BUILD=`which $PYTHON_FOR_BUILD` +else + PYTHON_FOR_BUILD='./$(BUILDPYTHON)' +fi + +if test "$cross_compiling" = "yes"; then + AC_MSG_RESULT($PYTHON_FOR_BUILD) +fi + +AC_ARG_VAR(PYTHON_FOR_BUILD,[build system python (default: python)]) +AC_SUBST(PYTHON_FOR_BUILD) + +if test "$cross_compiling" = "yes"; then + CFLAGS_FOR_BUILD=${CFLAGS_FOR_BUILD-} + CPPFLAGS_FOR_BUILD=${CPPFLAGS_FOR_BUILD- -I.} + CROSS_COMMENT=# + if test "$case_sensitive" = "yes" + then + EXEEXT_FOR_BUILD= + else + EXEEXT_FOR_BUILD=.exe + fi + LDFLAGS_FOR_BUILD=${LDFLAGS_FOR_BUILD-} + LIBS_FOR_BUILD=${LIBS_FOR_BUILD-} + O_FOR_BUILD=x + RUNSHARED="CROSS_TARGET=$ac_sys_system SRCDIR=$srcdir SO=${SO}" +else + CROSS_COMMENT= + EXEEXT_FOR_BUILD=$BUILDEXEEXT + O_FOR_BUILD=o +fi +AC_SUBST(CFLAGS_FOR_BUILD) +AC_SUBST(CPPFLAGS_FOR_BUILD) +AC_SUBST(CROSS_COMMENT) +AC_SUBST(EXEEXT_FOR_BUILD) +AC_SUBST(LDFLAGS_FOR_BUILD) +AC_SUBST(LIBS_FOR_BUILD) +AC_SUBST(O_FOR_BUILD) + # generate output files AC_CONFIG_FILES(Makefile.pre Modules/Setup.config) AC_OUTPUT
When cross compiling, AC_TRY_RUN should not be used. This patch fixes it in a way that for a cross scenario the test can be overwritten on the command line.
Signed-off-by: Robert Schwebel r.schwebel@pengutronix.de
--- configure.in | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
Index: Python-3.0/configure.in =================================================================== --- Python-3.0.orig/configure.in +++ Python-3.0/configure.in @@ -2494,7 +2494,7 @@ AC_CHECK_LIB(c, inet_aton, [$ac_cv_prog_ # On Tru64, chflags seems to be present, but calling it will # exit Python AC_MSG_CHECKING(for chflags) -AC_TRY_RUN([ +AC_RUN_IFELSE([ #include <sys/stat.h> #include <unistd.h> int main(int argc, char*argv[]) @@ -2503,10 +2503,27 @@ int main(int argc, char*argv[]) return 1; return 0; } -],AC_DEFINE(HAVE_CHFLAGS, 1, Define to 1 if you have the `chflags' function.) - AC_MSG_RESULT(yes), +],[ + AC_CACHE_VAL(ac_cv_have_chflags, ac_cv_have_chflags=yes) + AC_MSG_RESULT(yes) +],[ + AC_CACHE_VAL(ac_cv_have_chflags, ac_cv_have_chflags=no) AC_MSG_RESULT(no) +],[ + AC_CACHE_VAL(ac_cv_have_chflags, ac_cv_have_chflags=undef) + AC_MSG_RESULT([crosscompiling, ac_cv_have_chflags=$ac_cv_have_chflags]) +] ) +case $ac_cv_have_chflags in +yes) + AC_DEFINE(HAVE_CHFLAGS, 1, Define to 1 if you have the 'chflags' function.) + ;; +no) + ;; +*) + AC_MSG_ERROR([please specify ac_cv_have_chflags=yes|no]) + ;; +esac
AC_MSG_CHECKING(for lchflags) AC_TRY_RUN([
When cross compiling, AC_TRY_RUN should not be used. This patch fixes it in a way that for a cross scenario the test can be overwritten on the command line.
Signed-off-by: Robert Schwebel r.schwebel@pengutronix.de
--- configure.in | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
Index: Python-3.0/configure.in =================================================================== --- Python-3.0.orig/configure.in +++ Python-3.0/configure.in @@ -2526,7 +2526,7 @@ no) esac
AC_MSG_CHECKING(for lchflags) -AC_TRY_RUN([ +AC_RUN_IFELSE([ #include <sys/stat.h> #include <unistd.h> int main(int argc, char*argv[]) @@ -2535,10 +2535,27 @@ int main(int argc, char*argv[]) return 1; return 0; } -],AC_DEFINE(HAVE_LCHFLAGS, 1, Define to 1 if you have the `lchflags' function.) - AC_MSG_RESULT(yes), +],[ + AC_CACHE_VAL(ac_cv_have_lchflags, ac_cv_have_lchflags=yes) + AC_MSG_RESULT(yes) +],[ + AC_CACHE_VAL(ac_cv_have_lchflags, ac_cv_have_lchflags=no) AC_MSG_RESULT(no) +],[ + AC_CACHE_VAL(ac_cv_have_lchflags, ac_cv_have_lchflags=undef) + AC_MSG_RESULT([crosscompiling, ac_cv_have_lchflags=$ac_cv_have_lchflags]) +] ) +case $ac_cv_have_lchflags in +yes) + AC_DEFINE(HAVE_LCHFLAGS, 1, Define to 1 if you have the 'lchflags' function.) + ;; +no) + ;; +*) + AC_MSG_ERROR([please specify ac_cv_have_lchflags=yes|no]) + ;; +esac
dnl Check if system zlib has *Copy() functions dnl
Add a CROSS_COMPILING=yes variable in order to tell setup.py that we are cross compiling.
Signed-off-by: Robert Schwebel r.schwebel@pengutronix.de
--- setup.py | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-)
Index: Python-3.0/setup.py =================================================================== --- Python-3.0.orig/setup.py +++ Python-3.0/setup.py @@ -18,6 +18,15 @@ from distutils.command.install_lib impor # This global variable is used to hold the list of modules to be disabled. disabled_module_list = []
+import os + +if os.environ.get('CROSS_COMPILING') == 'yes': + sysconfig.get_config_vars() + sysconfig._config_vars.update (os.environ) +else: + sysconfig.get_config_vars() + sysconfig._config_vars['srcdir'] = os.environ['srcdir'] + 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' @@ -260,6 +269,10 @@ class PyBuildExt(build_ext): self.announce('WARNING: skipping import check for Cygwin-based "%s"' % ext.name) return + if os.environ.get('CROSS_COMPILING') == 'yes': + self.announce('WARNING: skipping import check for cross compiled "%s"' + % ext.name) + return ext_filename = os.path.join( self.build_lib, self.get_ext_filename(self.get_ext_fullname(ext.name))) @@ -301,16 +314,20 @@ class PyBuildExt(build_ext): self.failed.append(ext.name)
def get_platform(self): - # Get value of sys.platform + # Get value of target's sys.platform + p = sys.platform + if os.environ.get('CROSS_COMPILING') == 'yes': + p = os.environ.get('CROSS_TARGET') for platform in ['cygwin', 'darwin', 'atheos', 'osf1']: - if sys.platform.startswith(platform): + if p.startswith(platform): return platform - return sys.platform + return p
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') + if os.environ.get('CROSS_COMPILING') != 'yes': + add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') + add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
# Add paths specified in the environment variables LDFLAGS and # CPPFLAGS for header and library files. @@ -355,11 +372,14 @@ class PyBuildExt(build_ext): # lib_dirs and inc_dirs are used to search for files; # 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', - ] - inc_dirs = self.compiler.include_dirs + ['/usr/include'] + lib_dirs = [] + inc_dirs = [] + if os.environ.get('CROSS_COMPILING') != 'yes': + lib_dirs = self.compiler.library_dirs + [ + '/lib64', '/usr/lib64', + '/lib', '/usr/lib', + ] + inc_dirs = self.compiler.include_dirs + ['/usr/include'] exts = [] missing = []
@@ -675,6 +695,9 @@ class PyBuildExt(build_ext): '/sw/include/db3', ]
+ if os.environ.get('CROSS_COMPILING') == 'yes': + db_inc_paths = [] + db_incs = None
# The sqlite interface @@ -694,6 +717,9 @@ class PyBuildExt(build_ext): MIN_SQLITE_VERSION = ".".join([str(x) for x in MIN_SQLITE_VERSION_NUMBER])
+ if os.environ.get('CROSS_COMPILING') == 'yes': + sqlite_inc_paths = [] + # Scan the default include directories before the SQLite specific # ones. This allows one to override the copy of sqlite on OSX, # where /usr/include contains an old version of sqlite.
Handle config args for libffi, for cross compilation.
Signed-off-by: Robert Schwebel r.schwebel@pengutronix.de
--- Makefile.pre.in | 2 ++ setup.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-)
Index: Python-3.0/setup.py =================================================================== --- Python-3.0.orig/setup.py +++ Python-3.0/setup.py @@ -1342,12 +1342,12 @@ class PyBuildExt(build_ext): ffi_configfile): from distutils.dir_util import mkpath mkpath(ffi_builddir) - config_args = [] + config_args = ['--host=%s' % os.environ.get('GNU_HOST'), '--build=%s' % os.environ.get('GNU_BUILD')]
# Pass empty CFLAGS because we'll just append the resulting # CFLAGS to Python's; -g or -O2 is to be avoided. cmd = "cd %s && env CFLAGS='' '%s/configure' %s" \ - % (ffi_builddir, ffi_srcdir, " ".join(config_args)) + % (ffi_builddir, ffi_srcdir, " ".join(config_args))
res = os.system(cmd) if res or not os.path.exists(ffi_configfile): Index: Python-3.0/Makefile.pre.in =================================================================== --- Python-3.0.orig/Makefile.pre.in +++ Python-3.0/Makefile.pre.in @@ -423,6 +423,7 @@ sharedmods: $(PYTHON_FOR_BUILD) CC='$(CC)' \ LDSHARED='$(BLDSHARED)' \ OPT='$(OPT)' \ + CONFIG_ARGS="$(CONFIG_ARGS)" \ $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py -q build \ ;; \ *) \ @@ -431,6 +432,7 @@ sharedmods: $(PYTHON_FOR_BUILD) CC='$(CC)' \ LDSHARED='$(BLDSHARED)' \ OPT='$(OPT)' \ + CONFIG_ARGS="$(CONFIG_ARGS)" \ $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py build \ ;; \ esac
Hi Antoine,
[sorry for the double post, the mails didn't show up in the archive and my procmail had missing slash at the end of the rule...]
Thanks for those patches, but please post them to the issue tracker instead (http://bugs.python.org/). If each patch is for a distinct purpose, then open separate issues, otherwise please merge the patches into a single one.
Yup, will do.
I suspect that some of the design decisions need discussions; should that also take place in the issue tracker, or here on the mailing list?
rsc
On Fri, Jan 9, 2009 at 9:24 AM, Robert Schwebel r.schwebel@pengutronix.de wrote:
Yup, will do.
I suspect that some of the design decisions need discussions; should that also take place in the issue tracker, or here on the mailing list?
For the distutils part, you can use the distutils mailing list if you wish,
http://www.python.org/community/sigs/current/distutils-sig/
Regards Tarek