0
0
mirror of https://github.com/python/cpython.git synced 2024-11-24 08:52:25 +01:00
cpython/Misc/python-config.sh.in
Michał Górny 14086cfc5e closes bpo-22140: Prevent double substitution of prefix in python-config.sh (#3769)
Fix the logic in python-config.sh to avoid attempting to substitute
prefix in a variable that might have already been subject to
substitution. This e.g. happened if @exec_prefix@ was defined as
"${prefix}" (which is the default of the configure script) -- in which
case the exec_prefix_build variable was initialized with
already-subtituted prefix, and then another round of substitution was
performed which might have resulted in duplicate prefix.

To avoid that, rename the variables so that the variables matching
likely configure names (prefix, exec_prefix) retain their original
values and a '_real' suffix is used for the real values of prefix.

Furthermore, replace the unnecessary prefix and exec_prefix
substitutions with direct prefix_real references since the sed
always replaced the whole string anyway by design.
2017-09-26 22:45:06 -07:00

113 lines
2.9 KiB
Bash

#!/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"
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
if readlink -f "$RESULT" >/dev/null 2>&1; then
RESULT=$(readlink -f "$RESULT")
fi
fi
echo $RESULT
}
prefix_real=$(installed_prefix "$0")
# 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.
prefix="@prefix@"
exec_prefix="@exec_prefix@"
exec_prefix_real=${prefix_real}
includedir=$(echo "@includedir@" | sed "s#$prefix#$prefix_real#")
libdir=$(echo "@libdir@" | sed "s#$prefix#$prefix_real#")
CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix#$prefix_real#")
VERSION="@VERSION@"
LIBM="@LIBM@"
LIBC="@LIBC@"
SYSLIBS="$LIBM $LIBC"
ABIFLAGS="@ABIFLAGS@"
LIBS="-lpython${VERSION}${ABIFLAGS} @LIBS@ $SYSLIBS"
BASECFLAGS="@BASECFLAGS@"
LDLIBRARY="@LDLIBRARY@"
LINKFORSHARED="@LINKFORSHARED@"
OPT="@OPT@"
PY_ENABLE_SHARED="@PY_ENABLE_SHARED@"
LDVERSION="@LDVERSION@"
LIBDEST=${prefix_real}/lib/python${VERSION}
LIBPL=$(echo "@LIBPL@" | sed "s#$prefix#$prefix_real#")
SO="@EXT_SUFFIX@"
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_real"
;;
--exec-prefix)
echo "$exec_prefix_real"
;;
--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