summaryrefslogtreecommitdiffstats
path: root/patches/Python-2.6.2/generic/0015-add-cross-compilation-support.patch
blob: 9b408a5f8bc53e3e68fe8f99652491d89e908ec1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
From 430893ea1bad2245f00d44fef62bbfb75db27f96 Mon Sep 17 00:00:00 2001
From: Marc Kleine-Budde <mkl@pengutronix.de>
Date: Mon, 4 May 2009 14:39:18 +0200
Subject: [PATCH] add cross compilation support

This patch adds preliminary cross compilation support to python.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 Lib/distutils/sysconfig.py |   11 +++++++++--
 Makefile.pre.in            |   12 ++++++++----
 configure.in               |   31 ++++++++++++++++++++++++++++---
 setup.py                   |    6 +++++-
 4 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index a00b2f9..b1091da 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -19,9 +19,16 @@ import sys
 from distutils.errors import DistutilsPlatformError
 
 # These are needed in a couple of spots, so just compute them once.
-PREFIX = os.path.normpath(sys.prefix)
-EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
 EXECUTABLE_DIRNAME = os.path.dirname(os.path.abspath(sys.executable))
+if os.environ.get('CROSS_COMPILING') == 'yes':
+    _sysroot=os.environ.get('_python_sysroot')
+    PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
+    EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
+    if '_python_srcdir' in os.environ:
+        EXECUTABLE_DIRNAME = os.path.normpath(os.environ['_python_srcdir'])
+else:
+    PREFIX = os.path.normpath(sys.prefix)
+    EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
 
 # Path to the base directory of the project. On Windows the binary may
 # live in project/PCBuild9.  If we're dealing with an x64 Windows build,
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 8ad6e8b..795b67d 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -72,6 +72,10 @@ CFLAGSFORSHARED=@CFLAGSFORSHARED@
 # C flags used for building the interpreter object files
 PY_CFLAGS=	$(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
 
+# cross compiler options
+ifndef DESTDIR
+sysroot=	@SYSROOT@
+endif
 
 # Machine-dependent subdirectories
 MACHDEP=	@MACHDEP@
@@ -87,11 +91,11 @@ datarootdir=    @datarootdir@
 
 # Expanded directories
 BINDIR=		$(exec_prefix)/bin
-LIBDIR=		$(exec_prefix)/lib
+LIBDIR=		$(sysroot)$(exec_prefix)/lib
 MANDIR=		@mandir@
-INCLUDEDIR=	@includedir@
-CONFINCLUDEDIR=	$(exec_prefix)/include
-SCRIPTDIR=	$(prefix)/lib
+INCLUDEDIR=	$(sysroot)@includedir@
+CONFINCLUDEDIR=	$(sysroot)$(exec_prefix)/include
+SCRIPTDIR=	$(sysroot)$(prefix)/lib
 
 # Detailed destination directories
 BINLIBDEST=	$(LIBDIR)/python$(VERSION)
diff --git a/configure.in b/configure.in
index e65e530..1354b7f 100644
--- a/configure.in
+++ b/configure.in
@@ -12,6 +12,9 @@ AC_INIT(python, PYTHON_VERSION, http://www.python.org/python-bugs)
 AC_CONFIG_SRCDIR([Include/object.h])
 AC_CONFIG_HEADER(pyconfig.h)
 
+AC_CANONICAL_BUILD
+AC_CANONICAL_HOST
+
 dnl This is for stuff that absolutely must end up in pyconfig.h.
 dnl Please use pyport.h instead, if possible.
 AH_TOP([
@@ -756,9 +759,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)
@@ -3729,6 +3732,28 @@ AC_SUBST(PYTHON_FOR_BUILD)
 AC_ARG_VAR(PYTHON_FOR_BUILD,[build system python (default: python)])
 
 
+#
+# Cross compiling
+#
+# special RUNSHARED
+if test "$cross_compiling" = "yes"; then
+    RUNSHARED="\
+		CROSS_COMPILING=yes \
+		_python_cross_host=${ac_cv_host} \
+		_python_sysroot=\"\$(sysroot)\" \
+		_python_srcdir=\"\$(srcdir)\" \
+		_python_prefix=\"\$(prefix)\" \
+		_python_exec_prefix=\"\$(exec_prefix)\""
+fi
+
+# sysroot
+AC_SUBST(SYSROOT)
+if test "$cross_compiling" = "yes"; then
+    AC_MSG_CHECKING([for SYSROOT])
+    AC_MSG_RESULT([$SYSROOT])
+fi
+
+
 # generate output files
 AC_CONFIG_FILES(Makefile.pre Modules/Setup.config)
 AC_OUTPUT
diff --git a/setup.py b/setup.py
index 7beb08b..2c183c4 100644
--- a/setup.py
+++ b/setup.py
@@ -1715,7 +1715,11 @@ class PyBuildExt(build_ext):
                                          ffi_configfile):
                 from distutils.dir_util import mkpath
                 mkpath(ffi_builddir)
-                config_args = []
+
+                if os.environ.get('CROSS_COMPILING') != 'yes':
+                    config_args = []
+                else:
+                    config_args = ['--host=%s' % os.environ["_python_cross_host"],]
 
                 # Pass empty CFLAGS because we'll just append the resulting
                 # CFLAGS to Python's; -g or -O2 is to be avoided.
-- 
1.5.6.3