summaryrefslogtreecommitdiffstats
path: root/package/python/python-2.7-001-support-for-build.patch
blob: b0430a4efaa34c191146a7b78fc05cbc5ec18435 (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
146
147
148
149
150
151
152
153
154
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.2/Makefile.pre.in
===================================================================
--- Python-2.7.2.orig/Makefile.pre.in
+++ Python-2.7.2/Makefile.pre.in
@@ -181,7 +181,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
@@ -213,7 +214,8 @@
 
 ##########################################################################
 # Parser
-PGEN=		Parser/pgen$(EXE)
+BUILDPGEN=	Parser/pgen$(EXE)
+PGEN_FOR_BUILD=@PGEN_FOR_BUILD@
 
 POBJS=		\
 		Parser/acceler.o \
@@ -407,8 +409,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
@@ -540,13 +542,13 @@
 
 # Use a stamp file to prevent make -j invoking pgen twice
 $(GRAMMAR_H) $(GRAMMAR_C): Parser/pgen.stamp
-Parser/pgen.stamp: $(PGEN) $(GRAMMAR_INPUT)
+Parser/pgen.stamp: $(PGEN_FOR_BUILD) $(GRAMMAR_INPUT)
 		-@$(INSTALL) -d Include
-		$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
+		$(PGEN_FOR_BUILD) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
 		-touch Parser/pgen.stamp
 
-$(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 \
@@ -926,25 +928,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):
@@ -1049,7 +1051,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) \
@@ -1188,7 +1190,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 Parser/pgen.stamp \
 		config.cache config.log pyconfig.h Modules/config.c
 	-rm -rf build platform
Index: Python-2.7.2/configure.in
===================================================================
--- Python-2.7.2.orig/configure.in
+++ Python-2.7.2/configure.in
@@ -4305,6 +4305,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])