0009-Fix-python-config-for-cross-builds.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. From 1522c6c00ee88eb1148d3b2021d32d819b416375 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
  5. Add a backport of http://bugs.python.org/issue16235 so we can use
  6. python-config for cross builds.
  7. This basically replaces the python version of python-config with a
  8. pure-shell version that's already preprocessed when installed and
  9. doesn't depend on the sysconfig import that usually leads to bad
  10. data/results.
  11. Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
  12. [Bernd: rebased for Python 2.7.15]
  13. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  14. [Peter: update for 2.7.16]
  15. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  16. ---
  17. Makefile.pre.in | 13 +++---
  18. Misc/python-config.sh.in | 102 +++++++++++++++++++++++++++++++++++++++++++++++
  19. configure.ac | 7 +++-
  20. 3 files changed, 116 insertions(+), 6 deletions(-)
  21. create mode 100644 Misc/python-config.sh.in
  22. diff --git a/Makefile.pre.in b/Makefile.pre.in
  23. index c1c98ecc5a..727a92af42 100644
  24. --- a/Makefile.pre.in
  25. +++ b/Makefile.pre.in
  26. @@ -170,7 +170,7 @@ SRCDIRS= @SRCDIRS@
  27. SUBDIRSTOO= Include Lib Misc Demo
  28. # Files and directories to be distributed
  29. -CONFIGFILES= configure configure.ac acconfig.h pyconfig.h.in Makefile.pre.in
  30. +CONFIGFILES= configure configure.ac acconfig.h pyconfig.h.in Makefile.pre.in Misc/python-config.sh
  31. DISTFILES= README ChangeLog $(CONFIGFILES)
  32. DISTDIRS= $(SUBDIRS) $(SUBDIRSTOO) Ext-dummy
  33. DIST= $(DISTFILES) $(DISTDIRS)
  34. @@ -403,7 +403,7 @@ LIBRARY_OBJS= \
  35. # Default target
  36. all: @DEF_MAKE_ALL_RULE@
  37. -build_all: check-clean-src $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks
  38. +build_all: check-clean-src $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks python-config
  39. # Check that the source is clean when building out of source.
  40. check-clean-src:
  41. @@ -1190,10 +1190,12 @@ $(srcdir)/Lib/$(PLATDIR):
  42. fi; \
  43. cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
  44. -python-config: $(srcdir)/Misc/python-config.in
  45. +python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh
  46. # Substitution happens here, as the completely-expanded BINDIR
  47. # is not available in configure
  48. - sed -e "s,@EXENAME@,$(BINDIR)/python$(VERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config
  49. + sed -e "s,@EXENAME@,$(BINDIR)/python$(VERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py
  50. + # Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR}
  51. + sed -e 's,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g' Misc/python-config.sh >python-config
  52. # Install the include files
  53. INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
  54. @@ -1252,7 +1254,7 @@ libainstall: @DEF_MAKE_RULE@ python-config
  55. $(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
  56. $(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
  57. $(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(VERSION)-config
  58. - rm python-config
  59. + $(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py
  60. @if [ -s Modules/python.exp -a \
  61. "`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
  62. echo; echo "Installing support files for building shared extension modules on AIX:"; \
  63. @@ -1434,6 +1436,7 @@ clobber: clean profile-removal
  64. config.cache config.log pyconfig.h Modules/config.c
  65. -rm -rf build platform
  66. -rm -rf $(PYTHONFRAMEWORKDIR)
  67. + -rm -f python-config.py python-config
  68. # Make things extra clean, before making a distribution:
  69. # remove all generated files, even Makefile[.pre]
  70. diff --git a/Misc/python-config.sh.in b/Misc/python-config.sh.in
  71. new file mode 100644
  72. index 0000000000..10db4c12eb
  73. --- /dev/null
  74. +++ b/Misc/python-config.sh.in
  75. @@ -0,0 +1,102 @@
  76. +#!/bin/sh
  77. +
  78. +exit_with_usage ()
  79. +{
  80. + echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--configdir"
  81. + exit $1
  82. +}
  83. +
  84. +if [ "$1" = "" ] ; then
  85. + exit_with_usage 1
  86. +fi
  87. +
  88. +# Returns the actual prefix where this script was installed to.
  89. +installed_prefix ()
  90. +{
  91. + RESULT=$(dirname $(cd $(dirname "$1") && pwd -P))
  92. + if which readlink >/dev/null 2>&1 ; then
  93. + RESULT=$(readlink -f "$RESULT")
  94. + fi
  95. + echo $RESULT
  96. +}
  97. +
  98. +prefix_build="@prefix@"
  99. +prefix_real=$(installed_prefix "$0")
  100. +
  101. +# Use sed to fix paths from their built to locations to their installed to locations.
  102. +prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#")
  103. +exec_prefix_build="@exec_prefix@"
  104. +exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#")
  105. +includedir=$(echo "@includedir@")
  106. +libdir=$(echo "@libdir@" | sed "s#$prefix_build#$prefix_real#")
  107. +CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix_build#$prefix_real#")
  108. +VERSION="@VERSION@"
  109. +LIBM="@LIBM@"
  110. +LIBC="@LIBC@"
  111. +SYSLIBS="$LIBM $LIBC"
  112. +LIBS="@LIBS@ $SYSLIBS -lpython${VERSION}"
  113. +BASECFLAGS="@BASECFLAGS@"
  114. +LDLIBRARY="@LDLIBRARY@"
  115. +LINKFORSHARED="@LINKFORSHARED@"
  116. +OPT="@OPT@"
  117. +PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
  118. +LDVERSION="@LDVERSION@"
  119. +LIBDEST=${prefix}/lib/python${VERSION}
  120. +LIBPL=$(echo "@LIBPL@" | sed "s#$prefix_build#$prefix_real#")
  121. +SO="@SO@"
  122. +PYTHONFRAMEWORK="@PYTHONFRAMEWORK@"
  123. +INCDIR="-I$includedir/python${VERSION}"
  124. +PLATINCDIR="-I$includedir/python${VERSION}"
  125. +
  126. +# Scan for --help or unknown argument.
  127. +for ARG in $*
  128. +do
  129. + case $ARG in
  130. + --help)
  131. + exit_with_usage 0
  132. + ;;
  133. + --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir)
  134. + ;;
  135. + *)
  136. + exit_with_usage 1
  137. + ;;
  138. +esac
  139. +done
  140. +
  141. +for ARG in "$@"
  142. +do
  143. + case "$ARG" in
  144. + --prefix)
  145. + echo "$prefix"
  146. + ;;
  147. + --exec-prefix)
  148. + echo "$exec_prefix"
  149. + ;;
  150. + --includes)
  151. + echo "$INCDIR $PLATINCDIR"
  152. + ;;
  153. + --cflags)
  154. + echo "$INCDIR $PLATINCDIR $BASECFLAGS $CFLAGS $OPT"
  155. + ;;
  156. + --libs)
  157. + echo "$LIBS"
  158. + ;;
  159. + --ldflags)
  160. + LINKFORSHAREDUSED=
  161. + if [ -z "$PYTHONFRAMEWORK" ] ; then
  162. + LINKFORSHAREDUSED=$LINKFORSHARED
  163. + fi
  164. + LIBPLUSED=
  165. + if [ "$PY_ENABLE_SHARED" = "0" ] ; then
  166. + LIBPLUSED="-L$LIBPL"
  167. + fi
  168. + echo "$LIBPLUSED -L$libdir $LIBS $LINKFORSHAREDUSED"
  169. + ;;
  170. + --extension-suffix)
  171. + echo "$SO"
  172. + ;;
  173. + --configdir)
  174. + echo "$LIBPL"
  175. + ;;
  176. +esac
  177. +done
  178. diff --git a/configure.ac b/configure.ac
  179. index 13f90b3ddd..3f28ef1371 100644
  180. --- a/configure.ac
  181. +++ b/configure.ac
  182. @@ -919,6 +919,7 @@ fi
  183. # Other platforms follow
  184. if test $enable_shared = "yes"; then
  185. + PY_ENABLE_SHARED=1
  186. AC_DEFINE(Py_ENABLE_SHARED, 1, [Defined if Python is built as a shared library.])
  187. case $ac_sys_system in
  188. BeOS*)
  189. @@ -979,6 +980,7 @@ if test $enable_shared = "yes"; then
  190. esac
  191. else # shared is disabled
  192. + PY_ENABLE_SHARED=0
  193. case $ac_sys_system in
  194. CYGWIN*)
  195. BLDLIBRARY='$(LIBRARY)'
  196. @@ -2128,6 +2130,9 @@ AC_SUBST(LDCXXSHARED)
  197. AC_SUBST(BLDSHARED)
  198. AC_SUBST(CCSHARED)
  199. AC_SUBST(LINKFORSHARED)
  200. +AC_SUBST(PY_ENABLE_SHARED)
  201. +LIBPL="${prefix}/lib/python${VERSION}/config"
  202. +AC_SUBST(LIBPL)
  203. # SO is the extension of shared libraries `(including the dot!)
  204. # -- usually .so, .sl on HP-UX, .dll on Cygwin
  205. AC_MSG_CHECKING(SO)
  206. @@ -4944,7 +4949,7 @@ AC_MSG_RESULT($ENSUREPIP)
  207. AC_SUBST(ENSUREPIP)
  208. # generate output files
  209. -AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
  210. +AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh)
  211. AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])
  212. AC_OUTPUT
  213. --
  214. 2.11.0