1 From e5b0d225f4343e82791cb80e4e0c01a9b49eeff4 Mon Sep 17 00:00:00 2001
2 From: Gustavo Zacarias <gustavo@zacarias.com.ar>
3 Date: Tue, 7 Mar 2017 22:23:14 +0100
4 Subject: [PATCH] Fix python-config for cross-builds
6 Add a backport of http://bugs.python.org/issue16235 so we can use
7 python-config for cross builds.
9 This basically replaces the python version of python-config with a
10 pure-shell version that's already preprocessed when installed and
11 doesn't depend on the sysconfig import that usually leads to bad
14 Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
16 Makefile.pre.in | 13 +++---
17 Misc/python-config.sh.in | 102 +++++++++++++++++++++++++++++++++++++++++++++++
19 3 files changed, 116 insertions(+), 6 deletions(-)
20 create mode 100644 Misc/python-config.sh.in
22 diff --git a/Makefile.pre.in b/Makefile.pre.in
23 index 33b994d..beb0837 100644
26 @@ -171,7 +171,7 @@ SRCDIRS= @SRCDIRS@
27 SUBDIRSTOO= Include Lib Misc Demo
29 # Files and directories to be distributed
30 -CONFIGFILES= configure configure.ac acconfig.h pyconfig.h.in Makefile.pre.in
31 +CONFIGFILES= configure configure.ac acconfig.h pyconfig.h.in Makefile.pre.in Misc/python-config.sh
32 DISTFILES= README ChangeLog $(CONFIGFILES)
33 DISTDIRS= $(SUBDIRS) $(SUBDIRSTOO) Ext-dummy
34 DIST= $(DISTFILES) $(DISTDIRS)
35 @@ -431,7 +431,7 @@ LIBRARY_OBJS= \
38 all: @DEF_MAKE_ALL_RULE@
39 -build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks
40 +build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks python-config
42 # Compile a binary with profile guided optimization.
44 @@ -1179,10 +1179,12 @@ $(srcdir)/Lib/$(PLATDIR):
46 cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
48 -python-config: $(srcdir)/Misc/python-config.in
49 +python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh
50 # Substitution happens here, as the completely-expanded BINDIR
51 # is not available in configure
52 - sed -e "s,@EXENAME@,$(BINDIR)/python$(VERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config
53 + sed -e "s,@EXENAME@,$(BINDIR)/python$(VERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py
54 + # Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR}
55 + sed -e 's,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g' Misc/python-config.sh >python-config
57 # Install the include files
58 INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
59 @@ -1241,7 +1243,7 @@ libainstall: all python-config
60 $(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
61 $(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
62 $(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(VERSION)-config
64 + $(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py
65 @if [ -s Modules/python.exp -a \
66 "`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
67 echo; echo "Installing support files for building shared extension modules on AIX:"; \
68 @@ -1426,6 +1428,7 @@ clobber: clean profile-removal
69 config.cache config.log pyconfig.h Modules/config.c
70 -rm -rf build platform
71 -rm -rf $(PYTHONFRAMEWORKDIR)
72 + -rm -f python-config.py python-config
74 # Make things extra clean, before making a distribution:
75 # remove all generated files, even Makefile[.pre]
76 diff --git a/Misc/python-config.sh.in b/Misc/python-config.sh.in
78 index 0000000..10db4c1
80 +++ b/Misc/python-config.sh.in
86 + echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--configdir"
90 +if [ "$1" = "" ] ; then
94 +# Returns the actual prefix where this script was installed to.
97 + RESULT=$(dirname $(cd $(dirname "$1") && pwd -P))
98 + if which readlink >/dev/null 2>&1 ; then
99 + RESULT=$(readlink -f "$RESULT")
104 +prefix_build="@prefix@"
105 +prefix_real=$(installed_prefix "$0")
107 +# Use sed to fix paths from their built to locations to their installed to locations.
108 +prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#")
109 +exec_prefix_build="@exec_prefix@"
110 +exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#")
111 +includedir=$(echo "@includedir@")
112 +libdir=$(echo "@libdir@" | sed "s#$prefix_build#$prefix_real#")
113 +CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix_build#$prefix_real#")
117 +SYSLIBS="$LIBM $LIBC"
118 +LIBS="@LIBS@ $SYSLIBS -lpython${VERSION}"
119 +BASECFLAGS="@BASECFLAGS@"
120 +LDLIBRARY="@LDLIBRARY@"
121 +LINKFORSHARED="@LINKFORSHARED@"
123 +PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
124 +LDVERSION="@LDVERSION@"
125 +LIBDEST=${prefix}/lib/python${VERSION}
126 +LIBPL=$(echo "@LIBPL@" | sed "s#$prefix_build#$prefix_real#")
128 +PYTHONFRAMEWORK="@PYTHONFRAMEWORK@"
129 +INCDIR="-I$includedir/python${VERSION}"
130 +PLATINCDIR="-I$includedir/python${VERSION}"
132 +# Scan for --help or unknown argument.
139 + --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir)
154 + echo "$exec_prefix"
157 + echo "$INCDIR $PLATINCDIR"
160 + echo "$INCDIR $PLATINCDIR $BASECFLAGS $CFLAGS $OPT"
167 + if [ -z "$PYTHONFRAMEWORK" ] ; then
168 + LINKFORSHAREDUSED=$LINKFORSHARED
171 + if [ "$PY_ENABLE_SHARED" = "0" ] ; then
172 + LIBPLUSED="-L$LIBPL"
174 + echo "$LIBPLUSED -L$libdir $LIBS $LINKFORSHAREDUSED"
176 + --extension-suffix)
184 diff --git a/configure.ac b/configure.ac
185 index 5d4232f..183a903 100644
188 @@ -905,6 +905,7 @@ fi
190 # Other platforms follow
191 if test $enable_shared = "yes"; then
193 AC_DEFINE(Py_ENABLE_SHARED, 1, [Defined if Python is built as a shared library.])
194 case $ac_sys_system in
196 @@ -965,6 +966,7 @@ if test $enable_shared = "yes"; then
199 else # shared is disabled
201 case $ac_sys_system in
203 BLDLIBRARY='$(LIBRARY)'
204 @@ -2096,6 +2098,9 @@ AC_SUBST(LDCXXSHARED)
207 AC_SUBST(LINKFORSHARED)
208 +AC_SUBST(PY_ENABLE_SHARED)
209 +LIBPL="${prefix}/lib/python${VERSION}/config"
211 # SO is the extension of shared libraries `(including the dot!)
212 # -- usually .so, .sl on HP-UX, .dll on Cygwin
214 @@ -4818,7 +4823,7 @@ AC_MSG_RESULT($ENSUREPIP)
217 # generate output files
218 -AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
219 +AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh)
220 AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])