010-fix-python-config.patch 6.3 KB

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