summarylogtreecommitdiffstats
path: root/0028-add-python-config-sh.patch
blob: ddea647c422faef04acefe4a448fbaac82cb78cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
From 6c65a9a8245268b2260c99db33e27205d9a67837 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?=
 <alexey.pawlow@gmail.com>
Date: Thu, 17 Jun 2021 18:51:43 +0530
Subject: [PATCH 028/N] add python config sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Алексей <alexey.pawlow@gmail.com>
Co-authored-by: Christoph Reiter <reiter.christoph@gmail.com>
---
 Misc/python-config.sh.in | 62 +++++++++++++++++++++++++---------------
 1 file changed, 39 insertions(+), 23 deletions(-)

diff --git a/Misc/python-config.sh.in b/Misc/python-config.sh.in
index 2602fe2..e0e048a 100644
--- a/Misc/python-config.sh.in
+++ b/Misc/python-config.sh.in
@@ -1,32 +1,44 @@
 #!/bin/sh
 
-# Keep this script in sync with python-config.in
-
 exit_with_usage ()
 {
     echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir|--embed"
-    exit $1
+    exit 1
 }
 
+# Really, python-config.py (and thus .sh) should be called directly, but
+# sometimes software (e.g. GDB) calls python-config.sh as if it were the
+# Python executable, passing python-config.py as the first argument.
+# Work around that oddness by ignoring any .py passed as first arg.
+case "$1" in
+    *.py)
+        shift
+    ;;
+esac
+
 if [ "$1" = "" ] ; then
-    exit_with_usage 1
+    exit_with_usage
 fi
 
 # Returns the actual prefix where this script was installed to.
 installed_prefix ()
 {
-    RESULT=$(dirname $(cd $(dirname "$1") && pwd -P))
-    if which readlink >/dev/null 2>&1 ; then
-        if readlink -f "$RESULT" >/dev/null 2>&1; then
-          RESULT=$(readlink -f "$RESULT")
-        fi
+    local RESULT=$(dirname $(cd $(dirname "$1") && pwd -P))
+    if [ $(which readlink) ] ; then
+        RESULT=$(readlink -f "$RESULT")
+    fi
+    # Since we don't know where the output from this script will end up
+    # we keep all paths in Windows-land since MSYS2 can handle that
+    # while native tools can't handle paths in MSYS2-land.
+    if [ "$OSTYPE" = "msys" ]; then
+        RESULT=$(cd "$RESULT" && pwd -W)
     fi
     echo $RESULT
 }
 
 prefix_real=$(installed_prefix "$0")
 
-# Use sed to fix paths from their built-to locations to their installed-to
+# Use sed to fix paths from their built-to locations to their installed to
 # locations. Keep prefix & exec_prefix using their original values in case
 # they are referenced in other configure variables, to prevent double
 # substitution, issue #22140.
@@ -41,13 +53,17 @@ LIBM="@LIBM@"
 LIBC="@LIBC@"
 SYSLIBS="$LIBM $LIBC"
 ABIFLAGS="@ABIFLAGS@"
+# Protect against lack of substitution.
+if [ "$ABIFLAGS" = "@""ABIFLAGS""@" ] ; then
+    ABIFLAGS=
+fi
 LIBS="@LIBPYTHON@ @LIBS@ $SYSLIBS"
 LIBS_EMBED="-lpython${VERSION}${ABIFLAGS} @LIBS@ $SYSLIBS"
 BASECFLAGS="@BASECFLAGS@"
-LDLIBRARY="@LDLIBRARY@"
 OPT="@OPT@"
 PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
 LDVERSION="@LDVERSION@"
+LDLIBRARY="@LDLIBRARY@"
 LIBDEST=${prefix_real}/lib/python${VERSION}
 LIBPL=$(echo "@LIBPL@" | sed "s#$prefix#$prefix_real#")
 SO="@EXT_SUFFIX@"
@@ -61,7 +77,7 @@ for ARG in $*
 do
     case $ARG in
         --help)
-            exit_with_usage 0
+            exit_with_usage
         ;;
         --embed)
             PY_EMBED=1
@@ -69,7 +85,7 @@ do
         --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir)
         ;;
         *)
-            exit_with_usage 1
+            exit_with_usage
         ;;
     esac
 done
@@ -80,37 +96,37 @@ fi
 
 for ARG in "$@"
 do
-    case "$ARG" in
+    case $ARG in
         --prefix)
-            echo "$prefix_real"
+            echo -ne "$prefix_real"
         ;;
         --exec-prefix)
-            echo "$exec_prefix_real"
+            echo -ne "$exec_prefix_real "
         ;;
         --includes)
-            echo "$INCDIR $PLATINCDIR"
+            echo -ne "$INCDIR $PLATINCDIR"
         ;;
         --cflags)
-            echo "$INCDIR $PLATINCDIR $BASECFLAGS $CFLAGS $OPT"
+            echo -ne "$INCDIR $PLATINCDIR $BASECFLAGS $CFLAGS $OPT"
         ;;
         --libs)
-            echo "$LIBS"
+            echo -ne "$LIBS"
         ;;
         --ldflags)
             LIBPLUSED=
             if [ "$PY_ENABLE_SHARED" = "0" ] ; then
                 LIBPLUSED="-L$LIBPL"
             fi
-            echo "$LIBPLUSED -L$libdir $LIBS"
+            echo -ne "$LIBPLUSED -L$libdir $LIBS "
         ;;
         --extension-suffix)
-            echo "$SO"
+            echo -ne "$SO "
         ;;
         --abiflags)
-            echo "$ABIFLAGS"
+            echo -ne "$ABIFLAGS "
         ;;
         --configdir)
-            echo "$LIBPL"
+            echo -ne "$LIBPL "
         ;;
 esac
 done
-- 
2.33.0