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

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