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