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

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