Commit e3418f69 authored by Thomas Petazzoni's avatar Thomas Petazzoni
Browse files

python: convert to autotargets, bump to 2.7.1, many improvements



This commit does a number of changes and improvements to the Python
interpreter package :

 * It converts the .mk file to the AUTOTARGETS infrastructure. Even
   though Python uses only autoconf and not automake, the AUTOTARGETS
   is a fairly good fit for the Python interpreter, so we make use of
   it.

 * It bumps the version to 2.7.1. As this is a minor release compared
   to 2.7, there are no particular changes needed because of this
   bump. All changes done to the package are cleanups and improvements
   unrelated to the version bump.

 * It uses the system libffi. Until now, Python was building its own
   libffi (a library used by interprets to build code that makes
   function call at runtime). Using the Python internal libffi was not
   working as Python was not passing the appropriate arguments down to
   libffi ./configure script. And it sounded better to use a
   system-wide libffi, that could potentially be used by other
   packages as well. This libffi is needed for the ctypes Python
   module.

 * Remove all "depends on BR2_PACKAGE_PYTHON" by moving all
   Python-related options under a "if BR2_PACKAGE_PYTHON ... endif"
   condition.

 * Make the installation of pre-compiled Python modules (.pyc) the
   default, since they are smaller and do not need to be compiled on
   the target. It is still possible to install uncompiled modules, or
   both the uncompiled and pre-compiled versions.

 * The options to select the set of Python modules to compile has been
   moved to a submenu.

 * The codecscjk (Japanese, Korean and Chinese codecs) module is no
   longer enabled by default.

 * The commented options for gdbm and nis in Python have been
   removed. Those were not supported, so let's get rid of unused code.

 * The option for the tkinker module in Python has been removed, since
   we don't have a package for Tk in Buildroot.

 * Options for the bzip2, sqlite and zlib modules have been added,
   since those modules have external dependencies.

 * The set of patches has been completely reworked and extended, with
   more fine-grained patches and newer functionalities. The patches
   are split in two categories:

    - Patches that make various modifications to the Python build
      system to support cross-compilation or make some minor
      modifications. Those patches are numbered from 0 to 100.

    - Patches that add configuration options to the Python build
      system in order to enable/disable the compilation of Python
      extensions or modules (test modules, pydoc, lib2to3, sqlite, tk,
      curses, expat, codecs-cjk, nis, unicodedata, database modules,
      ssl, bzip2, zlib). These patches are numbered from 100 to 200.

   All features of the previous four patches are preserved, but they
   are organized differently and the patches have been renamed. This
   makes it difficult to see the differences from the existing
   patches.

 * The host Python interpreter is now installed in $(HOST_DIR), since
   it is used to build third party Python modules.

 * The BR2_PACKAGE_PYTHON_DEV option is removed since
   BR2_HAVE_DEVFILES already does the necessary work.

 * The "make -i install" workaround introduced by Maxime Ripard is no
   longer needed. It was caused by the compilation of the tests that
   required the unicodedata module (which wasn't built in the host
   Python interpreter). Since we no longer compile the Python tests,
   the problem doesn't exist anymore and we can avoid this "-i"
   option.

Signed-off-by: default avatarThomas Petazzoni <thomas.petazzoni@free-electrons.com>
parent b06e7ac4
Loading
Loading
Loading
Loading
+28 −37
Original line number Diff line number Diff line
config BR2_PACKAGE_PYTHON
	bool "python"
	depends on BR2_USE_WCHAR
	select BR2_PACKAGE_LIBFFI
	help
	  The python language interpreter.

@@ -9,17 +10,11 @@ config BR2_PACKAGE_PYTHON
comment "python requires a toolchain with WCHAR support"
	depends on !BR2_USE_WCHAR

config BR2_PACKAGE_PYTHON_DEV
	depends on BR2_PACKAGE_PYTHON
	bool "development files on target"
	help
	  If enabled, development files (headers and static libpython) will be
	  installed on the target.
if BR2_PACKAGE_PYTHON

choice
	prompt "Module format to install"
	depends on BR2_PACKAGE_PYTHON
	default BR2_PACKAGE_PYTHON_PY_ONLY
	prompt "python module format to install"
	default BR2_PACKAGE_PYTHON_PYC_ONLY
	help
	  Select Python module format to install on target (py, pyc or both)

@@ -34,51 +29,40 @@ config BR2_PACKAGE_PYTHON_PY_PYC

endchoice

menu "core python modules"

comment "The following modules are unusual or require extra libraries"
	depends on BR2_PACKAGE_PYTHON

config BR2_PACKAGE_PYTHON_BZIP2
	select BR2_PACKAGE_BZIP2
	bool "bzip2 module"
	help
	  bzip2 module for Python

config BR2_PACKAGE_PYTHON_BSDDB
	depends on BR2_PACKAGE_PYTHON
	select BR2_PACKAGE_BERKELEYDB
	bool "bsddb module"
	help
	  bsddb module for Python.

config BR2_PACKAGE_PYTHON_CODECSCJK
	depends on BR2_PACKAGE_PYTHON
	bool "codecscjk module"
	default y
	help
	  Chinese/Japanese/Korean codecs module for Python (large).

config BR2_PACKAGE_PYTHON_CURSES
	depends on BR2_PACKAGE_PYTHON
	select BR2_PACKAGE_NCURSES
	bool "curses module"
	help
	  curses module for Python.

# config BR2_PACKAGE_PYTHON_GDBM
# 	depends on BR2_PACKAGE_PYTHON
# 	bool "gdbm module"
# 	help
# 	  gdbm module for Python.

# config BR2_PACKAGE_PYTHON_NIS
# 	depends on BR2_PACKAGE_PYTHON
# 	bool "nis module"
# 	help
# 	  nis module for Python.

config BR2_PACKAGE_PYTHON_PYEXPAT
	depends on BR2_PACKAGE_PYTHON
	select BR2_PACKAGE_EXPAT
	bool "pyexpat"
	help
	  pyexpat module for Python.

config BR2_PACKAGE_PYTHON_READLINE
	depends on BR2_PACKAGE_PYTHON
	select BR2_PACKAGE_READLINE
	bool "readline"
	help
@@ -86,22 +70,29 @@ config BR2_PACKAGE_PYTHON_READLINE
	  editing in the Python shell).

config BR2_PACKAGE_PYTHON_SSL
	depends on BR2_PACKAGE_PYTHON
	select BR2_PACKAGE_OPENSSL
	bool "ssl"
	help
	  _ssl module for Python (required for https in urllib etc).

config BR2_PACKAGE_PYTHON_TKINTER
	depends on BR2_PACKAGE_PYTHON
	select BR2_PACKAGE_TCL
	bool "tkinter module"
	help
	  tkinter module for Python.

config BR2_PACKAGE_PYTHON_UNICODEDATA
	depends on BR2_PACKAGE_PYTHON
	bool "unicodedata module"
	default y
	help
	  Unicode character database (used by stringprep module) (large).

config BR2_PACKAGE_PYTHON_SQLITE
	bool "sqlite module"
	select BR2_PACKAGE_SQLITE
	help
	  SQLite database support

config BR2_PACKAGE_PYTHON_ZLIB
	bool "zlib module"
	select BR2_PACKAGE_ZLIB
	help
	  zlib support in Python

endmenu

endif
+0 −114
Original line number Diff line number Diff line
Add cross-compilation support in the python Makefile and setup.py since
python has no such support.

The main point here is to first build a python interpreter to run on the
host, and then use it to compile the target python.

We also remove some error-generating code that is irrelevant in our
situation, such as checking if we can import a cross-compiled module.

Patch ported to python2.7 by Maxime Ripard <ripard@archos.com>

diff -rduNp Python-2.7.orig/Makefile.pre.in Python-2.7/Makefile.pre.in
--- Python-2.7.orig/Makefile.pre.in	2010-04-12 02:10:46.000000000 +0200
+++ Python-2.7/Makefile.pre.in	2010-09-21 16:46:07.000000000 +0200
@@ -404,8 +404,8 @@ platform: $(BUILDPYTHON)
 # Build the shared modules
 sharedmods: $(BUILDPYTHON)
 	@case $$MAKEFLAGS in \
-	*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
-	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
+	*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' $(HOSTPYTHON) -E $(srcdir)/setup.py -q build;; \
+	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' $(HOSTPYTHON) -E $(srcdir)/setup.py build;; \
 	esac
 
 # Build static library
@@ -538,7 +538,7 @@ Modules/python.o: $(srcdir)/Modules/pyth
 
 $(GRAMMAR_H) $(GRAMMAR_C): $(PGEN) $(GRAMMAR_INPUT)
 		-@$(INSTALL) -d Include
-		-$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
+		-$(HOSTPGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
 
 $(PGEN):	$(PGENOBJS)
 		$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
@@ -920,25 +920,25 @@ libinstall:	build_all $(srcdir)/Lib/$(PL
 	done
 	$(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
 	PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
-		./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
+		$(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 \
+		$(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):
@@ -1043,7 +1043,7 @@ libainstall:	all python-config
 # Install the dynamically loadable modules
 # This goes into $(exec_prefix)
 sharedinstall:
-	$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
+	$(RUNSHARED) $(HOSTPYTHON) -E $(srcdir)/setup.py install \
 	   	--prefix=$(prefix) \
 		--install-scripts=$(BINDIR) \
 		--install-platlib=$(DESTSHARED) \
diff -rduNp Python-2.7.orig/setup.py Python-2.7/setup.py
--- Python-2.7.orig/setup.py	2010-06-27 14:36:16.000000000 +0200
+++ Python-2.7/setup.py	2010-09-21 16:59:59.000000000 +0200
@@ -310,9 +310,9 @@ class PyBuildExt(build_ext):
         try:
             imp.load_dynamic(ext.name, ext_filename)
         except ImportError, why:
-            self.failed.append(ext.name)
-            self.announce('*** WARNING: renaming "%s" since importing it'
-                          ' failed: %s' % (ext.name, why), level=3)
+            self.announce('*** WARNING: Importing "%s" failed, probably '
+                          'because of cross-compilation' % ext.name, level=3)
+            return
             assert not self.inplace
             basename, tail = os.path.splitext(ext_filename)
             newname = basename + "_failed" + tail
@@ -346,10 +346,6 @@ class PyBuildExt(build_ext):
         return sys.platform
 
     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 paths specified in the environment variables LDFLAGS and
         # CPPFLAGS for header and library files.
         # We must get the values from the Makefile and not the environment
@@ -384,12 +380,6 @@ class PyBuildExt(build_ext):
                     for directory in reversed(options.dirs):
                         add_dir_to_list(dir_list, directory)
 
-        if os.path.normpath(sys.prefix) != '/usr':
-            add_dir_to_list(self.compiler.library_dirs,
-                            sysconfig.get_config_var("LIBDIR"))
-            add_dir_to_list(self.compiler.include_dirs,
-                            sysconfig.get_config_var("INCLUDEDIR"))
-
         try:
             have_unicode = unicode
         except NameError:
+153 −0
Original line number Diff line number Diff line
Add support in Python build system to specify host tools

Python needs a Python interpreter and a "pgen" program to build
itself. Unfortunately, the Python build system assumes that it can use
the interpreter and pgen program it has just built to build
itself. Obviously, this cannot work in cross-compilation mode since
the interpreter and the pgen program have been built for the target.

Therefore, this patch adds support in the Python build system for the
new PYTHON_FOR_BUILD and PGEN_FOR_BUILD variables, so that we can
point Python ./configure script to the Python interpreter and pgen
program that have been previously built for the host.

Patch ported to python2.7 by Maxime Ripard <ripard@archos.com>, and
later significantly reworked by Thomas Petazzoni
<thomas.petazzoni@free-electrons.com>, with some inspiration taken
from the Python patches of the PTXdist project.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 Makefile.pre.in |   32 +++++++++++++++++---------------
 configure.in    |   17 +++++++++++++++++
 2 files changed, 34 insertions(+), 15 deletions(-)

Index: Python-2.7.1/Makefile.pre.in
===================================================================
--- Python-2.7.1.orig/Makefile.pre.in
+++ Python-2.7.1/Makefile.pre.in
@@ -178,7 +178,8 @@
 UNICODE_OBJS=   @UNICODE_OBJS@
 
 PYTHON=		python$(EXE)
-BUILDPYTHON=	python$(BUILDEXE)
+BUILDPYTHON=	./python$(BUILDEXE)
+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
@@ -210,7 +211,8 @@
 
 ##########################################################################
 # Parser
-PGEN=		Parser/pgen$(EXE)
+BUILDPGEN=	Parser/pgen$(EXE)
+PGEN_FOR_BUILD=@PGEN_FOR_BUILD@
 
 POBJS=		\
 		Parser/acceler.o \
@@ -404,8 +406,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)' $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py -q build;; \
+	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py build;; \
 	esac
 
 # Build static library
@@ -536,12 +538,12 @@
 	$(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)
+$(BUILDPGEN):	$(PGENOBJS)
+		$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(BUILDPGEN)
 
 Parser/grammar.o:	$(srcdir)/Parser/grammar.c \
 				$(srcdir)/Include/token.h \
@@ -921,25 +923,25 @@
 	done
 	$(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
 	PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
-		./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
+		$(PYTHON_FOR_BUILD) -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 \
+		$(PYTHON_FOR_BUILD) -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 \
+		$(PYTHON_FOR_BUILD) -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 \
+		$(PYTHON_FOR_BUILD) -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()"
+		$(PYTHON_FOR_BUILD) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
 
 # Create the PLATDIR source directory, if one wasn't distributed..
 $(srcdir)/Lib/$(PLATDIR):
@@ -1044,7 +1046,7 @@
 # Install the dynamically loadable modules
 # This goes into $(exec_prefix)
 sharedinstall: sharedmods
-	$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
+	$(RUNSHARED) $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py install \
 	   	--prefix=$(prefix) \
 		--install-scripts=$(BINDIR) \
 		--install-platlib=$(DESTSHARED) \
@@ -1183,7 +1185,7 @@
 	find . -name '*.gc??' -exec rm -f {} ';'
 
 clobber: clean profile-removal
-	-rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
+	-rm -f $(BUILDPYTHON) $(BUILDPGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
 		tags TAGS \
 		config.cache config.log pyconfig.h Modules/config.c
 	-rm -rf build platform
Index: Python-2.7.1/configure.in
===================================================================
--- Python-2.7.1.orig/configure.in
+++ Python-2.7.1/configure.in
@@ -4291,6 +4291,23 @@
 done
 AC_MSG_RESULT(done)
 
+if test "$cross_compiling" = "yes"; then
+   AC_MSG_CHECKING(python for build)
+   PYTHON_FOR_BUILD="${PYTHON_FOR_BUILD}"
+   AC_MSG_RESULT($PYTHON_FOR_BUILD)
+   AC_MSG_CHECKING(pgen for build)
+   PGEN_FOR_BUILD="${PGEN_FOR_BUILD}"
+   AC_MSG_RESULT($PGEN_FOR_BUILD)
+else
+   PYTHON_FOR_BUILD='$(BUILDPYTHON)'
+   PGEN_FOR_BUILD='$(BUILDPGEN)'
+fi
+
+AC_SUBST(PYTHON_FOR_BUILD)
+AC_SUBST(PGEN_FOR_BUILD)
+AC_ARG_VAR(PYTHON_FOR_BUILD,[build system Python])
+AC_ARG_VAR(PGEN_FOR_BUILD,[build system Python pgen])
+
 # generate output files
 AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
 AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])
+55 −0
Original line number Diff line number Diff line
Pass a CROSS_COMPILING variable to setup.py

The setup.py script in the Python source code plays a significant role
in the Python build process. It is responsible for building all the
modules and extensions, and due to this, does various checks that need
to be adjusted when we are cross-compiling.

For that reason, this patch makes sure that a CROSS_COMPILING variable
is passed in the environment of the setup.py script. Later patches in
the stack make use of this variable.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 Makefile.pre.in |    6 +++---
 configure.in    |    3 +++
 2 files changed, 6 insertions(+), 3 deletions(-)

Index: Python-2.7.1/Makefile.pre.in
===================================================================
--- Python-2.7.1.orig/Makefile.pre.in
+++ Python-2.7.1/Makefile.pre.in
@@ -406,8 +406,8 @@
 # Build the shared modules
 sharedmods: $(BUILDPYTHON)
 	@case $$MAKEFLAGS in \
-	*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py -q build;; \
-	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py build;; \
+	*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' CROSS_COMPILING=@CROSS_COMPILING@ $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py -q build;; \
+	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' CROSS_COMPILING=@CROSS_COMPILING@ $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py build;; \
 	esac
 
 # Build static library
@@ -1046,7 +1046,7 @@
 # Install the dynamically loadable modules
 # This goes into $(exec_prefix)
 sharedinstall: sharedmods
-	$(RUNSHARED) $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py install \
+	$(RUNSHARED) CROSS_COMPILING=@CROSS_COMPILING@ $(PYTHON_FOR_BUILD) -E $(srcdir)/setup.py install \
 	   	--prefix=$(prefix) \
 		--install-scripts=$(BINDIR) \
 		--install-platlib=$(DESTSHARED) \
Index: Python-2.7.1/configure.in
===================================================================
--- Python-2.7.1.orig/configure.in
+++ Python-2.7.1/configure.in
@@ -4308,6 +4308,9 @@
 AC_ARG_VAR(PYTHON_FOR_BUILD,[build system Python])
 AC_ARG_VAR(PGEN_FOR_BUILD,[build system Python pgen])
 
+CROSS_COMPILING=$cross_compiling
+AC_SUBST(CROSS_COMPILING)
+
 # generate output files
 AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
 AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])
+26 −0
Original line number Diff line number Diff line
Disable import check when cross-compiling

Once Python has compiled an extension (i.e some C code, potentially
linked to a library), it tries to import it. This cannot work in
cross-compilation mode, so we just disable this check.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
 setup.py |    4 ++++
 1 file changed, 4 insertions(+)

Index: Python-2.7.1/setup.py
===================================================================
--- Python-2.7.1.orig/setup.py
+++ Python-2.7.1/setup.py
@@ -304,6 +304,10 @@
             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)))
Loading