Blame 0500-add-python-config-sh.patch

ddb6764
diff -rupN Python-2.7.13/configure.ac Python-2.7.13-new/configure.ac
ddb6764
--- Python-2.7.13/configure.ac	2017-01-21 01:46:07.861593089 +0100
ddb6764
+++ Python-2.7.13-new/configure.ac	2017-01-21 01:46:09.299577736 +0100
ddb6764
@@ -938,6 +938,7 @@ fi
ddb6764
 
ddb6764
 # Other platforms follow
ddb6764
 if test $enable_shared = "yes"; then
ddb6764
+  PY_ENABLE_SHARED=1
ddb6764
   AC_DEFINE(Py_ENABLE_SHARED, 1, [Defined if Python is built as a shared library.])
ddb6764
   case $ac_sys_system in
ddb6764
     BeOS*)
ddb6764
@@ -1005,6 +1006,7 @@ if test $enable_shared = "yes"; then
ddb6764
         ;;
ddb6764
   esac
ddb6764
 else # shared is disabled
ddb6764
+  PY_ENABLE_SHARED=0
ddb6764
   case $ac_sys_system in
ddb6764
     CYGWIN*)
ddb6764
           BLDLIBRARY='$(LIBRARY)'
ddb6764
@@ -1016,6 +1018,9 @@ else # shared is disabled
ddb6764
           LDLIBRARY='libpython$(VERSION).a';;
ddb6764
   esac
ddb6764
 fi
ddb6764
+AC_SUBST(PY_ENABLE_SHARED)
ddb6764
+LIBPL="${prefix}"/lib/python"${VERSION}"/config
ddb6764
+AC_SUBST(LIBPL)
ddb6764
 
ddb6764
 if test "$cross_compiling" = yes; then
ddb6764
 	RUNSHARED=
ddb6764
@@ -5053,7 +5058,13 @@ AC_MSG_RESULT($ENSUREPIP)
ddb6764
 AC_SUBST(ENSUREPIP)
ddb6764
 
ddb6764
 # generate output files
ddb6764
-AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
ddb6764
+AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh)
ddb6764
+
ddb6764
+AM_CONDITIONAL([MACHDEP_WIN32], [test "x$MACHDEP" = "xwin32"])
ddb6764
+AM_COND_IF([MACHDEP_WIN32],
ddb6764
+    [AC_CONFIG_FILES(Misc/python-config-u.sh)],
ddb6764
+    [])
ddb6764
+
ddb6764
 AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])
ddb6764
 AC_OUTPUT
ddb6764
 
ddb6764
diff -rupN Python-2.7.13/Makefile.pre.in Python-2.7.13-new/Makefile.pre.in
ddb6764
--- Python-2.7.13/Makefile.pre.in	2017-01-21 01:46:07.135600840 +0100
ddb6764
+++ Python-2.7.13-new/Makefile.pre.in	2017-01-21 01:46:09.299577736 +0100
ddb6764
@@ -1172,6 +1172,9 @@ python-config: $(srcdir)/Misc/python-con
ddb6764
 	# Substitution happens here, as the completely-expanded BINDIR
ddb6764
 	# is not available in configure
ddb6764
 	sed -e "s,@EXENAME@,$(BINDIR)/python$(VERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config
ddb6764
+	# Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR}
ddb6764
+	sed -e "s,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g" < Misc/python-config.sh >python-config.sh
ddb6764
+	-sed -e "s,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g" < Misc/python-config-u.sh >python-config-u.sh
ddb6764
 
ddb6764
 # Install the include files
ddb6764
 INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
ddb6764
@@ -1230,6 +1233,8 @@ libainstall:	all python-config
ddb6764
 	$(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
ddb6764
 	$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
ddb6764
 	$(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(VERSION)-config
ddb6764
+	$(INSTALL_SCRIPT) python-config.sh $(DESTDIR)$(BINDIR)/python-config.sh
ddb6764
+	-test -f python-config-u.sh && $(INSTALL_SCRIPT) python-config-u.sh $(DESTDIR)$(BINDIR)/python-config-u.sh
ddb6764
 	rm python-config
ddb6764
 	@if [ -s Modules/python.exp -a \
ddb6764
 		"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
ddb6764
diff -rupN Python-2.7.13/Misc/python-config.sh.in Python-2.7.13-new/Misc/python-config.sh.in
ddb6764
--- Python-2.7.13/Misc/python-config.sh.in	1970-01-01 01:00:00.000000000 +0100
ddb6764
+++ Python-2.7.13-new/Misc/python-config.sh.in	2017-01-21 01:46:09.299577736 +0100
ddb6764
@@ -0,0 +1,127 @@
ddb6764
+#!/usr/bin/env sh
ddb6764
+
ddb6764
+exit_with_usage ()
ddb6764
+{
ddb6764
+    echo "Usage: $0 [ignored.py] --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir"
ddb6764
+    exit 1
ddb6764
+}
ddb6764
+
ddb6764
+# Really, python-config.py (and thus .sh) should be called directly, but
ddb6764
+# sometimes software (e.g. GDB) calls python-config.sh as if it were the
ddb6764
+# Python executable, passing python-config.py as the first argument.
ddb6764
+# Work around that oddness by ignoring any .py passed as first arg.
ddb6764
+case "$1" in
ddb6764
+    *.py)
ddb6764
+        shift
ddb6764
+    ;;
ddb6764
+esac
ddb6764
+
ddb6764
+if [ "$1" = "" ] ; then
ddb6764
+    exit_with_usage
ddb6764
+fi
ddb6764
+
ddb6764
+# Returns the actual prefix where this script was installed to.
ddb6764
+installed_prefix ()
ddb6764
+{
ddb6764
+    local RESULT=$(dirname $(cd $(dirname "$1") && pwd -P))
ddb6764
+    local READLINK=readlink
ddb6764
+    if [ "$(uname -s)" = "Darwin" ] ; then
ddb6764
+        # readlink in darwin can't handle -f.  Use greadlink from MacPorts instead.
ddb6764
+        READLINK=greadlink
ddb6764
+    fi
ddb6764
+    # Since we don't know where the output from this script will end up
ddb6764
+    # we keep all paths in Windows-land since MSYS2 can handle that
ddb6764
+    # while native tools can't handle paths in MSYS2-land.
ddb6764
+    if [ "$OSTYPE" = "msys" ]; then
ddb6764
+        RESULT=$(cd "$RESULT" && pwd -W)
ddb6764
+    elif [ $(which $READLINK) ] ; then
ddb6764
+        RESULT=$($READLINK -f "$RESULT")
ddb6764
+    fi
ddb6764
+    echo $RESULT
ddb6764
+}
ddb6764
+
ddb6764
+prefix_build="@prefix@"
ddb6764
+prefix_real=$(installed_prefix "$0")
ddb6764
+
ddb6764
+# Use sed to fix paths from their built to locations to their installed to locations.
ddb6764
+prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#")
ddb6764
+exec_prefix_build="@exec_prefix@"
ddb6764
+exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#")
ddb6764
+includedir=$(echo "@includedir@" | sed "s#$prefix_build#$prefix_real#")
ddb6764
+libdir=$(echo "@libdir@" | sed "s#$prefix_build#$prefix_real#")
ddb6764
+CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix_build#$prefix_real#")
ddb6764
+VERSION="@VERSION@"
ddb6764
+LIBM="@LIBM@"
ddb6764
+LIBC="@LIBC@"
ddb6764
+SYSLIBS="$LIBM $LIBC"
ddb6764
+ABIFLAGS="@ABIFLAGS@"
ddb6764
+# Protect against lack of substitution.
ddb6764
+if [ "$ABIFLAGS" = "@""ABIFLAGS""@" ] ; then
ddb6764
+    ABIFLAGS=
ddb6764
+fi
ddb6764
+LIBS="@LIBS@ $SYSLIBS -lpython${VERSION}${ABIFLAGS}"
ddb6764
+BASECFLAGS="@BASECFLAGS@"
ddb6764
+LDLIBRARY="@LDLIBRARY@"
ddb6764
+LINKFORSHARED="@LINKFORSHARED@"
ddb6764
+OPT="@OPT@"
ddb6764
+PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
ddb6764
+DLLLIBRARY="@DLLLIBRARY@"
ddb6764
+LIBDEST=${prefix}/lib/python${VERSION}
ddb6764
+LIBPL=${LIBDEST}/config
ddb6764
+SO="@SO@"
ddb6764
+PYTHONFRAMEWORK="@PYTHONFRAMEWORK@"
ddb6764
+INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
ddb6764
+PLATINCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
ddb6764
+
ddb6764
+# Scan for --help or unknown argument.
ddb6764
+for ARG in $*
ddb6764
+do
ddb6764
+    case $ARG in
ddb6764
+        --help)
ddb6764
+            exit_with_usage
ddb6764
+        ;;
ddb6764
+        --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags)
ddb6764
+        ;;
ddb6764
+        *)
ddb6764
+            exit_with_usage
ddb6764
+        ;;
ddb6764
+    esac
ddb6764
+done
ddb6764
+
ddb6764
+RESULT=
ddb6764
+for ARG in $*
ddb6764
+do
ddb6764
+    if [ ! -z "$RESULT" ]; then
ddb6764
+        RESULT=$RESULT" "
ddb6764
+    fi
ddb6764
+    case $ARG in
ddb6764
+        --prefix)
ddb6764
+            RESULT=$RESULT"$prefix"
ddb6764
+        ;;
ddb6764
+        --exec-prefix)
ddb6764
+            RESULT=$RESULT"$exec_prefix"
ddb6764
+        ;;
ddb6764
+        --includes)
ddb6764
+            RESULT=$RESULT"$INCDIR"
ddb6764
+        ;;
ddb6764
+        --cflags)
ddb6764
+            RESULT=$RESULT"$INCDIR $BASECFLAGS $CFLAGS $OPT"
ddb6764
+        ;;
ddb6764
+        --libs)
ddb6764
+            RESULT=$RESULT"$LIBS"
ddb6764
+        ;;
ddb6764
+        --ldflags)
ddb6764
+            LINKFORSHAREDUSED=
ddb6764
+            if [ -z "$PYTHONFRAMEWORK" ] ; then
ddb6764
+                LINKFORSHAREDUSED=$LINKFORSHARED
ddb6764
+            fi
ddb6764
+            LIBPLUSED=
ddb6764
+            if [ "$PY_ENABLE_SHARED" = "0" -o -n "${DLLLIBRARY}" ] ; then
ddb6764
+                LIBPLUSED="-L$LIBPL"
ddb6764
+            fi
ddb6764
+            RESULT=$RESULT"$LIBPLUSED -L$libdir $LIBS $LINKFORSHAREDUSED"
ddb6764
+        ;;
ddb6764
+esac
ddb6764
+done
ddb6764
+echo -ne $RESULT
ddb6764
+
ddb6764
diff -rupN Python-2.7.13/Misc/python-config-u.sh.in Python-2.7.13-new/Misc/python-config-u.sh.in
ddb6764
--- Python-2.7.13/Misc/python-config-u.sh.in	1970-01-01 01:00:00.000000000 +0100
ddb6764
+++ Python-2.7.13-new/Misc/python-config-u.sh.in	2017-01-21 01:46:09.299577736 +0100
ddb6764
@@ -0,0 +1,10 @@
ddb6764
+#!/usr/bin/env sh
ddb6764
+
ddb6764
+THISDIR="$(dirname $0)"
ddb6764
+test "$THISDIR" = "." && THISDIR=${PWD}
ddb6764
+
ddb6764
+RESULT=$("${THISDIR}"/python-config.sh "$@")
ddb6764
+
ddb6764
+exec_prefix_win=$("${THISDIR}"/python-config.sh --exec-prefix)
ddb6764
+exec_prefix_unix=@prefix@
ddb6764
+echo $(echo $RESULT | sed "s#${exec_prefix_win}#${exec_prefix_unix}#g")