Skip to content

Commit d65e2ba

Browse files
author
doko@python.org
committed
- Issue #17086: Backport the patches from the 3.3 branch to cross-build
the package.
1 parent c5200b4 commit d65e2ba

12 files changed

Lines changed: 4225 additions & 249 deletions

File tree

Lib/distutils/sysconfig.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
3838
os.path.pardir))
3939

40+
# set for cross builds
41+
if "_PYTHON_PROJECT_BASE" in os.environ:
42+
# this is the build directory, at least for posix
43+
project_base = os.path.normpath(os.environ["_PYTHON_PROJECT_BASE"])
44+
4045
# python_build: (Boolean) if true, we're either building Python or
4146
# building an extension with an un-installed Python, so we use
4247
# different (hard-wired) directories.
@@ -230,7 +235,7 @@ def get_config_h_filename():
230235
def get_makefile_filename():
231236
"""Return full pathname of installed Makefile from the Python build."""
232237
if python_build:
233-
return os.path.join(os.path.dirname(sys.executable), "Makefile")
238+
return os.path.join(project_base, "Makefile")
234239
lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
235240
return os.path.join(lib_dir, "config", "Makefile")
236241

Lib/distutils/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def get_platform ():
5151
return 'win-ia64'
5252
return sys.platform
5353

54+
# Set for cross builds explicitly
55+
if "_PYTHON_HOST_PLATFORM" in os.environ:
56+
return os.environ["_PYTHON_HOST_PLATFORM"]
57+
5458
if os.name != "posix" or not hasattr(os, 'uname'):
5559
# XXX what about the architecture? NT is Intel or Alpha,
5660
# Mac OS is M68k or PPC, etc.

Lib/plat-generic/regen

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#! /bin/sh
22
set -v
3-
python$EXE ../../Tools/scripts/h2py.py -i '(u_long)' /usr/include/netinet/in.h
3+
eval $PYTHON_FOR_BUILD ../../Tools/scripts/h2py.py -i "'(u_long)'" /usr/include/netinet/in.h

Lib/sysconfig.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ def _safe_realpath(path):
116116
if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower():
117117
_PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
118118

119+
# set for cross builds
120+
if "_PYTHON_PROJECT_BASE" in os.environ:
121+
# the build directory for posix builds
122+
_PROJECT_BASE = os.path.normpath(os.path.abspath("."))
119123
def is_python_build():
120124
for fn in ("Setup.dist", "Setup.local"):
121125
if os.path.isfile(os.path.join(_PROJECT_BASE, "Modules", fn)):
@@ -507,6 +511,10 @@ def get_platform():
507511
return 'win-ia64'
508512
return sys.platform
509513

514+
# Set for cross builds explicitly
515+
if "_PYTHON_HOST_PLATFORM" in os.environ:
516+
return os.environ["_PYTHON_HOST_PLATFORM"]
517+
510518
if os.name != "posix" or not hasattr(os, 'uname'):
511519
# XXX what about the architecture? NT is Intel or Alpha,
512520
# Mac OS is M68k or PPC, etc.

Makefile.pre.in

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ srcdir= @srcdir@
2929
VPATH= @srcdir@
3030
abs_srcdir= @abs_srcdir@
3131
abs_builddir= @abs_builddir@
32+
build= @build@
33+
host= @host@
3234

3335
CC= @CC@
3436
CXX= @CXX@
@@ -190,6 +192,10 @@ UNICODE_OBJS= @UNICODE_OBJS@
190192
PYTHON= python$(EXE)
191193
BUILDPYTHON= python$(BUILDEXE)
192194

195+
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
196+
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
197+
HOST_GNU_TYPE= @host@
198+
193199
# The task to run while instrument when building the profile-opt target
194200
PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
195201
#PROFILE_TASK= $(srcdir)/Lib/test/regrtest.py
@@ -222,6 +228,19 @@ LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@
222228
# Parser
223229
PGEN= Parser/pgen$(EXE)
224230

231+
PSRCS= \
232+
Parser/acceler.c \
233+
Parser/grammar1.c \
234+
Parser/listnode.c \
235+
Parser/node.c \
236+
Parser/parser.c \
237+
Parser/parsetok.c \
238+
Parser/bitset.c \
239+
Parser/metagrammar.c \
240+
Parser/firstsets.c \
241+
Parser/grammar.c \
242+
Parser/pgen.c
243+
225244
POBJS= \
226245
Parser/acceler.o \
227246
Parser/grammar1.o \
@@ -237,6 +256,14 @@ POBJS= \
237256

238257
PARSER_OBJS= $(POBJS) Parser/myreadline.o Parser/tokenizer.o
239258

259+
PGSRCS= \
260+
Objects/obmalloc.c \
261+
Python/mysnprintf.c \
262+
Python/pyctype.c \
263+
Parser/tokenizer_pgen.c \
264+
Parser/printgrammar.c \
265+
Parser/pgenmain.c
266+
240267
PGOBJS= \
241268
Objects/obmalloc.o \
242269
Python/mysnprintf.o \
@@ -249,7 +276,8 @@ PARSER_HEADERS= \
249276
Parser/parser.h \
250277
Parser/tokenizer.h
251278

252-
PGENOBJS= $(PGENMAIN) $(POBJS) $(PGOBJS)
279+
PGENSRCS= $(PSRCS) $(PGSRCS)
280+
PGENOBJS= $(POBJS) $(PGOBJS)
253281

254282
##########################################################################
255283
# AST
@@ -391,6 +419,7 @@ build_all_generate_profile:
391419
$(MAKE) all CFLAGS="$(CFLAGS) -fprofile-generate" LIBS="$(LIBS) -lgcov"
392420

393421
run_profile_task:
422+
: # FIXME: can't run for a cross build
394423
./$(BUILDPYTHON) $(PROFILE_TASK)
395424

396425
build_all_use_profile:
@@ -409,7 +438,7 @@ $(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY)
409438
$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
410439

411440
platform: $(BUILDPYTHON)
412-
$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from sysconfig import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform
441+
$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform
413442

414443

415444
# Build the shared modules
@@ -422,7 +451,7 @@ sharedmods: $(BUILDPYTHON)
422451
*) quiet="";; \
423452
esac; \
424453
$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
425-
./$(BUILDPYTHON) -E $(srcdir)/setup.py $$quiet build
454+
$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build
426455

427456
# Build static library
428457
# avoid long command lines, same as LIBRARY_OBJS
@@ -551,12 +580,13 @@ Modules/python.o: $(srcdir)/Modules/python.c
551580
$(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
552581

553582

554-
# Use a stamp file to prevent make -j invoking pgen twice
555-
$(GRAMMAR_H) $(GRAMMAR_C): Parser/pgen.stamp
556-
Parser/pgen.stamp: $(PGEN) $(GRAMMAR_INPUT)
557-
-@$(INSTALL) -d Include
583+
$(GRAMMAR_H): $(GRAMMAR_INPUT) $(PGENSRCS)
584+
@$(MKDIR_P) Include
585+
$(MAKE) $(PGEN)
558586
$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
559-
-touch Parser/pgen.stamp
587+
$(GRAMMAR_C): $(GRAMMAR_H) $(GRAMMAR_INPUT) $(PGENSRCS)
588+
$(MAKE) $(GRAMMAR_H)
589+
touch $(GRAMMAR_C)
560590

561591
$(PGEN): $(PGENOBJS)
562592
$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
@@ -953,37 +983,43 @@ libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c
953983
$(DESTDIR)$(LIBDEST)/distutils/tests ; \
954984
fi
955985
PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
956-
./$(BUILDPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
986+
$(PYTHON_FOR_BUILD) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
957987
-d $(LIBDEST) -f \
958988
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
959989
$(DESTDIR)$(LIBDEST)
960990
PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
961-
./$(BUILDPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
991+
$(PYTHON_FOR_BUILD) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
962992
-d $(LIBDEST) -f \
963993
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
964994
$(DESTDIR)$(LIBDEST)
965995
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
966-
./$(BUILDPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
996+
$(PYTHON_FOR_BUILD) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
967997
-d $(LIBDEST)/site-packages -f \
968998
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
969999
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
970-
./$(BUILDPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
1000+
$(PYTHON_FOR_BUILD) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
9711001
-d $(LIBDEST)/site-packages -f \
9721002
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
9731003
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
974-
./$(BUILDPYTHON) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/Grammar.txt
1004+
$(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/Grammar.txt
9751005
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
976-
./$(BUILDPYTHON) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/PatternGrammar.txt
1006+
$(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/PatternGrammar.txt
9771007

9781008
# Create the PLATDIR source directory, if one wasn't distributed..
9791009
$(srcdir)/Lib/$(PLATDIR):
9801010
mkdir $(srcdir)/Lib/$(PLATDIR)
9811011
cp $(srcdir)/Lib/plat-generic/regen $(srcdir)/Lib/$(PLATDIR)/regen
9821012
export PATH; PATH="`pwd`:$$PATH"; \
983-
export PYTHONPATH; PYTHONPATH="`pwd`/Lib"; \
1013+
export PYTHONPATH; PYTHONPATH="$(srcdir)/Lib:$(abs_builddir)/`cat pybuilddir.txt`"; \
9841014
export DYLD_FRAMEWORK_PATH; DYLD_FRAMEWORK_PATH="`pwd`"; \
9851015
export EXE; EXE="$(BUILDEXE)"; \
9861016
if [ -n "$(MULTIARCH)" ]; then export MULTIARCH; MULTIARCH=$(MULTIARCH); fi; \
1017+
export PYTHON_FOR_BUILD; \
1018+
if [ "$(build)" = "$(host)" ]; then \
1019+
PYTHON_FOR_BUILD="$(BUILDPYTHON)"; \
1020+
else \
1021+
PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)"; \
1022+
fi; \
9871023
cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
9881024

9891025
python-config: $(srcdir)/Misc/python-config.in
@@ -1079,7 +1115,7 @@ libainstall: all python-config
10791115
# Install the dynamically loadable modules
10801116
# This goes into $(exec_prefix)
10811117
sharedinstall: sharedmods
1082-
$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
1118+
$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/setup.py install \
10831119
--prefix=$(prefix) \
10841120
--install-scripts=$(BINDIR) \
10851121
--install-platlib=$(DESTSHARED) \
@@ -1152,7 +1188,7 @@ frameworkinstallextras:
11521188
# This installs a few of the useful scripts in Tools/scripts
11531189
scriptsinstall:
11541190
SRCDIR=$(srcdir) $(RUNSHARED) \
1155-
./$(BUILDPYTHON) $(srcdir)/Tools/scripts/setup.py install \
1191+
$(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/setup.py install \
11561192
--prefix=$(prefix) \
11571193
--install-scripts=$(BINDIR) \
11581194
--root=$(DESTDIR)/
@@ -1219,7 +1255,7 @@ profile-removal:
12191255

12201256
clobber: clean profile-removal
12211257
-rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
1222-
tags TAGS Parser/pgen.stamp \
1258+
tags TAGS \
12231259
config.cache config.log pyconfig.h Modules/config.c
12241260
-rm -rf build platform
12251261
-rm -rf $(PYTHONFRAMEWORKDIR)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ Tests
754754
Build
755755
-----
756756

757+
- Issue #17086: Backport the patches from the 3.3 branch to cross-build
758+
the package.
759+
757760
- Issue #3754: fix typo in pthread AC_CACHE_VAL.
758761

759762
- Issue #17029: Let h2py search the multiarch system include directory.

0 commit comments

Comments
 (0)