- Issue #16235: Implement python-config as a shell script.

This commit is contained in:
doko@python.org 2013-01-26 11:39:31 +01:00
parent ed3c4128c0
commit 874211978c
5 changed files with 133 additions and 6 deletions

View file

@ -438,7 +438,7 @@ LIBRARY_OBJS= \
# Default target
all: build_all
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Modules/_testembed
build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Modules/_testembed python-config
# Compile a binary with gcc profile guided optimization.
profile-opt:
@ -1132,10 +1132,12 @@ $(srcdir)/Lib/$(PLATDIR):
fi; \
cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
python-config: $(srcdir)/Misc/python-config.in
python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh
# Substitution happens here, as the completely-expanded BINDIR
# is not available in configure
sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config
sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py
# Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR}
sed -e 's,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g' < Misc/python-config.sh >python-config
# Install the include files
INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
@ -1193,8 +1195,8 @@ libainstall: all python-config
$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
$(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
$(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py
$(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config
rm python-config
@if [ -s Modules/python.exp -a \
"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
echo; echo "Installing support files for building shared extension modules on AIX:"; \
@ -1381,6 +1383,7 @@ clobber: clean profile-removal
config.cache config.log pyconfig.h Modules/config.c
-rm -rf build platform
-rm -rf $(PYTHONFRAMEWORKDIR)
-rm -f python-config.py python-config
# Make things extra clean, before making a distribution:
# remove all generated files, even Makefile[.pre]

View file

@ -763,6 +763,8 @@ Tests
Build
-----
- Issue #16235: Implement python-config as a shell script.
- Issue #16769: Remove outdated Visual Studio projects.
- Issue #17031: Fix running regen in cross builds.

106
Misc/python-config.sh.in Normal file
View file

@ -0,0 +1,106 @@
#!/bin/sh
exit_with_usage ()
{
echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir"
exit $1
}
if [ "$1" = "" ] ; then
exit_with_usage 1
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
RESULT=$(readlink -f "$RESULT")
fi
echo $RESULT
}
prefix_build="@prefix@"
prefix_real=$(installed_prefix "$0")
# Use sed to fix paths from their built to locations to their installed to locations.
prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#")
exec_prefix_build="@exec_prefix@"
exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#")
includedir=$(echo "@includedir@" | sed "s#$prefix_build#$prefix_real#")
libdir=$(echo "@libdir@" | sed "s#$prefix_build#$prefix_real#")
CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix_build#$prefix_real#")
VERSION="@VERSION@"
LIBM="@LIBM@"
LIBC="@LIBC@"
SYSLIBS="$LIBM $LIBC"
ABIFLAGS="@ABIFLAGS@"
LIBS="@LIBS@ $SYSLIBS -lpython${VERSION}${ABIFLAGS}"
BASECFLAGS="@BASECFLAGS@"
LDLIBRARY="@LDLIBRARY@"
LINKFORSHARED="@LINKFORSHARED@"
OPT="@OPT@"
PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
LDVERSION="@LDVERSION@"
LIBDEST=${prefix}/lib/python${VERSION}
LIBPL=$(echo "@LIBPL@" | sed "s#$prefix_build#$prefix_real#")
SO="@SO@"
PYTHONFRAMEWORK="@PYTHONFRAMEWORK@"
INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
PLATINCDIR="-I$includedir/python${VERSION}${ABIFLAGS}"
# Scan for --help or unknown argument.
for ARG in $*
do
case $ARG in
--help)
exit_with_usage 0
;;
--prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir)
;;
*)
exit_with_usage 1
;;
esac
done
for ARG in "$@"
do
case "$ARG" in
--prefix)
echo "$prefix"
;;
--exec-prefix)
echo "$exec_prefix"
;;
--includes)
echo "$INCDIR $PLATINCDIR"
;;
--cflags)
echo "$INCDIR $PLATINCDIR $BASECFLAGS $CFLAGS $OPT"
;;
--libs)
echo "$LIBS"
;;
--ldflags)
LINKFORSHAREDUSED=
if [ -z "$PYTHONFRAMEWORK" ] ; then
LINKFORSHAREDUSED=$LINKFORSHARED
fi
LIBPLUSED=
if [ "$PY_ENABLE_SHARED" = "0" ] ; then
LIBPLUSED="-L$LIBPL"
fi
echo "$LIBPLUSED -L$libdir $LIBS $LINKFORSHAREDUSED"
;;
--extension-suffix)
echo "$SO"
;;
--abiflags)
echo "$ABIFLAGS"
;;
--configdir)
echo "$LIBPL"
;;
esac
done

11
configure vendored
View file

@ -625,6 +625,8 @@ ac_includes_default="\
ac_subst_vars='LTLIBOBJS
SRCDIRS
THREADHEADERS
LIBPL
PY_ENABLE_SHARED
SOABI
LIBC
LIBM
@ -5573,6 +5575,7 @@ fi
# Other platforms follow
if test $enable_shared = "yes"; then
PY_ENABLE_SHARED=1
$as_echo "#define Py_ENABLE_SHARED 1" >>confdefs.h
@ -5630,6 +5633,7 @@ $as_echo "#define Py_ENABLE_SHARED 1" >>confdefs.h
esac
else # shared is disabled
PY_ENABLE_SHARED=0
case $ac_sys_system in
CYGWIN*)
BLDLIBRARY='$(LIBRARY)'
@ -13689,6 +13693,10 @@ LDVERSION='$(VERSION)$(ABIFLAGS)'
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LDVERSION" >&5
$as_echo "$LDVERSION" >&6; }
LIBPL="${prefix}/lib/python${VERSION}/config-${LDVERSION}"
# SO is the extension of shared libraries `(including the dot!)
# -- usually .so, .sl on HP-UX, .dll on Cygwin
{ $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
fi
# generate output files
ac_config_files="$ac_config_files Makefile.pre Modules/Setup.config Misc/python.pc"
ac_config_files="$ac_config_files Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh"
ac_config_files="$ac_config_files Modules/ld_so_aix"
@ -15840,6 +15848,7 @@ do
"Makefile.pre") CONFIG_FILES="$CONFIG_FILES Makefile.pre" ;;
"Modules/Setup.config") CONFIG_FILES="$CONFIG_FILES Modules/Setup.config" ;;
"Misc/python.pc") CONFIG_FILES="$CONFIG_FILES Misc/python.pc" ;;
"Misc/python-config.sh") CONFIG_FILES="$CONFIG_FILES Misc/python-config.sh" ;;
"Modules/ld_so_aix") CONFIG_FILES="$CONFIG_FILES Modules/ld_so_aix" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;

View file

@ -917,6 +917,7 @@ fi
# Other platforms follow
if test $enable_shared = "yes"; then
PY_ENABLE_SHARED=1
AC_DEFINE(Py_ENABLE_SHARED, 1, [Defined if Python is built as a shared library.])
case $ac_sys_system in
CYGWIN*)
@ -972,6 +973,7 @@ if test $enable_shared = "yes"; then
esac
else # shared is disabled
PY_ENABLE_SHARED=0
case $ac_sys_system in
CYGWIN*)
BLDLIBRARY='$(LIBRARY)'
@ -3929,6 +3931,11 @@ AC_MSG_CHECKING(LDVERSION)
LDVERSION='$(VERSION)$(ABIFLAGS)'
AC_MSG_RESULT($LDVERSION)
dnl define LIBPL after ABIFLAGS and LDVERSION is defined.
AC_SUBST(PY_ENABLE_SHARED)
LIBPL="${prefix}/lib/python${VERSION}/config-${LDVERSION}"
AC_SUBST(LIBPL)
# SO is the extension of shared libraries `(including the dot!)
# -- usually .so, .sl on HP-UX, .dll on Cygwin
AC_MSG_CHECKING(SO)
@ -4641,7 +4648,7 @@ if test "$have_gcc_asm_for_x87" = yes; then
fi
# generate output files
AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc)
AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc Misc/python-config.sh)
AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])
AC_OUTPUT