Skip to content

Commit 8742119

Browse files
author
doko@python.org
committed
- Issue #16235: Implement python-config as a shell script.
1 parent ed3c412 commit 8742119

5 files changed

Lines changed: 133 additions & 6 deletions

File tree

Makefile.pre.in

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ LIBRARY_OBJS= \
438438

439439
# Default target
440440
all: build_all
441-
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Modules/_testembed
441+
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Modules/_testembed python-config
442442

443443
# Compile a binary with gcc profile guided optimization.
444444
profile-opt:
@@ -1132,10 +1132,12 @@ $(srcdir)/Lib/$(PLATDIR):
11321132
fi; \
11331133
cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
11341134

1135-
python-config: $(srcdir)/Misc/python-config.in
1135+
python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh
11361136
# Substitution happens here, as the completely-expanded BINDIR
11371137
# is not available in configure
1138-
sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config
1138+
sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py
1139+
# Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR}
1140+
sed -e 's,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g' < Misc/python-config.sh >python-config
11391141

11401142
# Install the include files
11411143
INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
@@ -1193,8 +1195,8 @@ libainstall: all python-config
11931195
$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
11941196
$(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
11951197
$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
1198+
$(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py
11961199
$(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config
1197-
rm python-config
11981200
@if [ -s Modules/python.exp -a \
11991201
"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
12001202
echo; echo "Installing support files for building shared extension modules on AIX:"; \
@@ -1381,6 +1383,7 @@ clobber: clean profile-removal
13811383
config.cache config.log pyconfig.h Modules/config.c
13821384
-rm -rf build platform
13831385
-rm -rf $(PYTHONFRAMEWORKDIR)
1386+
-rm -f python-config.py python-config
13841387

13851388
# Make things extra clean, before making a distribution:
13861389
# remove all generated files, even Makefile[.pre]

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ Tests
763763
Build
764764
-----
765765

766+
- Issue #16235: Implement python-config as a shell script.
767+
766768
- Issue #16769: Remove outdated Visual Studio projects.
767769

768770
- Issue #17031: Fix running regen in cross builds.

Misc/python-config.sh.in

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/sh
2+
3+
exit_with_usage ()
4+
{
5+
echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir"
6+
exit $1
7+
}
8+
9+
if [ "$1" = "" ] ; then
10+
exit_with_usage 1
11+
fi
12+
13+
# Returns the actual prefix where this script was installed to.
14+
installed_prefix ()
15+
{
16+
RESULT=$(dirname $(cd $(dirname "$1") && pwd -P))
17+
if which readlink >/dev/null 2>&1 ; then
18+
RESULT=$(readlink -f "$RESULT")
19+
fi
20+
echo $RESULT
21+
}
22+
23+
prefix_build="@prefix@"
24+
prefix_real=$(installed_prefix "$0")
25+
26+
# Use sed to fix paths from their built to locations to their installed to locations.
27+
prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#")
28+
exec_prefix_build="@exec_prefix@"
29+
exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#")
30+
includedir=$(echo "@includedir@" | sed "s#$prefix_build#$prefix_real#")
31+
libdir=$(echo "@libdir@" | sed "s#$prefix_build#$prefix_real#")
32+
CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix_build#$prefix_real#")
33+
VERSION="@VERSION@"
34+
LIBM="@LIBM@"
35+
LIBC="@LIBC@"
36+
SYSLIBS="$LIBM $LIBC"
37+
ABIFLAGS="@ABIFLAGS@"
38+
LIBS="@LIBS@ $SYSLIBS -lpython${VERSION}${ABIFLAGS}"
39+
BASECFLAGS="@BASECFLAGS@"
40+
LDLIBRARY="@LDLIBRARY@"
41+
LINKFORSHARED="@LINKFORSHARED@"
42+
OPT="@OPT@"
43+
PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
44+
LDVERSION="@LDVERSION@"
45+
LIBDEST=${prefix}/lib/python${VERSION}
46+
LIBPL=$(echo "@LIBPL@" | sed "s#$prefix_build#$prefix_real#")
47+
SO="@SO@"
48+
PYTHONFRAMEWORK="@PYTHONFRAMEWORK@"
49+
INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
50+
PLATINCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
51+
52+
# Scan for --help or unknown argument.
53+
for ARG in $*
54+
do
55+
case $ARG in
56+
--help)
57+
exit_with_usage 0
58+
;;
59+
--prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir)
60+
;;
61+
*)
62+
exit_with_usage 1
63+
;;
64+
esac
65+
done
66+
67+
for ARG in "$@"
68+
do
69+
case "$ARG" in
70+
--prefix)
71+
echo "$prefix"
72+
;;
73+
--exec-prefix)
74+
echo "$exec_prefix"
75+
;;
76+
--includes)
77+
echo "$INCDIR $PLATINCDIR"
78+
;;
79+
--cflags)
80+
echo "$INCDIR $PLATINCDIR $BASECFLAGS $CFLAGS $OPT"
81+
;;
82+
--libs)
83+
echo "$LIBS"
84+
;;
85+
--ldflags)
86+
LINKFORSHAREDUSED=
87+
if [ -z "$PYTHONFRAMEWORK" ] ; then
88+
LINKFORSHAREDUSED=$LINKFORSHARED
89+
fi
90+
LIBPLUSED=
91+
if [ "$PY_ENABLE_SHARED" = "0" ] ; then
92+
LIBPLUSED="-L$LIBPL"
93+
fi
94+
echo "$LIBPLUSED -L$libdir $LIBS $LINKFORSHAREDUSED"
95+
;;
96+
--extension-suffix)
97+
echo "$SO"
98+
;;
99+
--abiflags)
100+
echo "$ABIFLAGS"
101+
;;
102+
--configdir)
103+
echo "$LIBPL"
104+
;;
105+
esac
106+
done

configure

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ ac_includes_default="\
625625
ac_subst_vars='LTLIBOBJS
626626
SRCDIRS
627627
THREADHEADERS
628+
LIBPL
629+
PY_ENABLE_SHARED
628630
SOABI
629631
LIBC
630632
LIBM
@@ -5573,6 +5575,7 @@ fi
55735575

55745576
# Other platforms follow
55755577
if test $enable_shared = "yes"; then
5578+
PY_ENABLE_SHARED=1
55765579

55775580
$as_echo "#define Py_ENABLE_SHARED 1" >>confdefs.h
55785581

@@ -5630,6 +5633,7 @@ $as_echo "#define Py_ENABLE_SHARED 1" >>confdefs.h
56305633

56315634
esac
56325635
else # shared is disabled
5636+
PY_ENABLE_SHARED=0
56335637
case $ac_sys_system in
56345638
CYGWIN*)
56355639
BLDLIBRARY='$(LIBRARY)'
@@ -13689,6 +13693,10 @@ LDVERSION='$(VERSION)$(ABIFLAGS)'
1368913693
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LDVERSION" >&5
1369013694
$as_echo "$LDVERSION" >&6; }
1369113695

13696+
13697+
LIBPL="${prefix}/lib/python${VERSION}/config-${LDVERSION}"
13698+
13699+
1369213700
# SO is the extension of shared libraries `(including the dot!)
1369313701
# -- usually .so, .sl on HP-UX, .dll on Cygwin
1369413702
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking SO" >&5
@@ -15136,7 +15144,7 @@ $as_echo "#define HAVE_IPA_PURE_CONST_BUG 1" >>confdefs.h
1513615144
fi
1513715145

1513815146
# generate output files
15139-
ac_config_files="$ac_config_files Makefile.pre Modules/Setup.config Misc/python.pc"
15147+
ac_config_files="$ac_config_files Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh"
1514015148

1514115149
ac_config_files="$ac_config_files Modules/ld_so_aix"
1514215150

@@ -15840,6 +15848,7 @@ do
1584015848
"Makefile.pre") CONFIG_FILES="$CONFIG_FILES Makefile.pre" ;;
1584115849
"Modules/Setup.config") CONFIG_FILES="$CONFIG_FILES Modules/Setup.config" ;;
1584215850
"Misc/python.pc") CONFIG_FILES="$CONFIG_FILES Misc/python.pc" ;;
15851+
"Misc/python-config.sh") CONFIG_FILES="$CONFIG_FILES Misc/python-config.sh" ;;
1584315852
"Modules/ld_so_aix") CONFIG_FILES="$CONFIG_FILES Modules/ld_so_aix" ;;
1584415853
1584515854
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;

configure.ac

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ fi
917917

918918
# Other platforms follow
919919
if test $enable_shared = "yes"; then
920+
PY_ENABLE_SHARED=1
920921
AC_DEFINE(Py_ENABLE_SHARED, 1, [Defined if Python is built as a shared library.])
921922
case $ac_sys_system in
922923
CYGWIN*)
@@ -972,6 +973,7 @@ if test $enable_shared = "yes"; then
972973

973974
esac
974975
else # shared is disabled
976+
PY_ENABLE_SHARED=0
975977
case $ac_sys_system in
976978
CYGWIN*)
977979
BLDLIBRARY='$(LIBRARY)'
@@ -3929,6 +3931,11 @@ AC_MSG_CHECKING(LDVERSION)
39293931
LDVERSION='$(VERSION)$(ABIFLAGS)'
39303932
AC_MSG_RESULT($LDVERSION)
39313933

3934+
dnl define LIBPL after ABIFLAGS and LDVERSION is defined.
3935+
AC_SUBST(PY_ENABLE_SHARED)
3936+
LIBPL="${prefix}/lib/python${VERSION}/config-${LDVERSION}"
3937+
AC_SUBST(LIBPL)
3938+
39323939
# SO is the extension of shared libraries `(including the dot!)
39333940
# -- usually .so, .sl on HP-UX, .dll on Cygwin
39343941
AC_MSG_CHECKING(SO)
@@ -4641,7 +4648,7 @@ if test "$have_gcc_asm_for_x87" = yes; then
46414648
fi
46424649

46434650
# generate output files
4644-
AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
4651+
AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh)
46454652
AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])
46464653
AC_OUTPUT
46474654

0 commit comments

Comments
 (0)