A *much* better method for finding Python.
authoraland <aland>
Wed, 13 Feb 2002 15:09:52 +0000 (15:09 +0000)
committeraland <aland>
Wed, 13 Feb 2002 15:09:52 +0000 (15:09 +0000)
Patch from Gordon Messmer <yinyang@eburg.com>

src/modules/rlm_python/configure
src/modules/rlm_python/configure.in

index d7d7c6c..7d42f44 100755 (executable)
@@ -12,8 +12,6 @@ ac_help=
 ac_default_prefix=/usr/local
 # Any additions from configure.in:
 ac_help="$ac_help
-  --with-rlm-python-version=[0-9].[0-9]   Version of Python to use [2.2]"
-ac_help="$ac_help
   --with-rlm-python-lib-dir=DIR       Directory for Python library files []"
 ac_help="$ac_help
   --with-rlm-python-include-dir=DIR   Directory for Python include files []"
@@ -527,7 +525,7 @@ else
 fi
 
 
-# From configure.in Revision: 1.3 
+# From configure.in Revision: 1.1 
 
 
 if test x$with_rlm_python != xno; then
@@ -535,7 +533,7 @@ if test x$with_rlm_python != xno; then
        # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:539: checking for $ac_word" >&5
+echo "configure:537: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -565,7 +563,7 @@ if test -z "$CC"; then
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:569: checking for $ac_word" >&5
+echo "configure:567: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -616,7 +614,7 @@ fi
       # Extract the first word of "cl", so it can be a program name with args.
 set dummy cl; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:620: checking for $ac_word" >&5
+echo "configure:618: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -648,7 +646,7 @@ fi
 fi
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:652: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:650: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
@@ -659,12 +657,12 @@ cross_compiling=$ac_cv_prog_cc_cross
 
 cat > conftest.$ac_ext << EOF
 
-#line 663 "configure"
+#line 661 "configure"
 #include "confdefs.h"
 
 main(){return(0);}
 EOF
-if { (eval echo configure:668: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:666: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
@@ -690,12 +688,12 @@ if test $ac_cv_prog_cc_works = no; then
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:694: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:692: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:699: checking whether we are using GNU C" >&5
+echo "configure:697: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -704,7 +702,7 @@ else
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:708: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:706: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
@@ -723,7 +721,7 @@ ac_test_CFLAGS="${CFLAGS+set}"
 ac_save_CFLAGS="$CFLAGS"
 CFLAGS=
 echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:727: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:725: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -755,7 +753,7 @@ else
 fi
 
        echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:759: checking how to run the C preprocessor" >&5
+echo "configure:757: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
   CPP=
@@ -770,13 +768,13 @@ else
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 774 "configure"
+#line 772 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:780: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:778: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -787,13 +785,13 @@ else
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 791 "configure"
+#line 789 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:797: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:795: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -804,13 +802,13 @@ else
   rm -rf conftest*
   CPP="${CC-cc} -nologo -E"
   cat > conftest.$ac_ext <<EOF
-#line 808 "configure"
+#line 806 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:814: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:812: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -835,25 +833,7 @@ fi
 echo "$ac_t""$CPP" 1>&6
 
 
-               rlm_python_version=2.2
-       # Check whether --with-rlm-python-version or --without-rlm-python-version was given.
-if test "${with_rlm_python_version+set}" = set; then
-  withval="$with_rlm_python_version"
-   case "$withval" in
-           no)
-               { echo "configure: error: Need rlm-python-version" 1>&2; exit 1; }
-               ;;
-           yes)
-               ;;
-           *)
-               rlm_python_version="$withval"
-               ;;
-         esac 
-       
-fi
-
-
-               rlm_python_lib_dir=
+               PY_LIB_DIR=
        # Check whether --with-rlm-python-lib-dir or --without-rlm-python-lib-dir was given.
 if test "${with_rlm_python_lib_dir+set}" = set; then
   withval="$with_rlm_python_lib_dir"
@@ -864,14 +844,14 @@ if test "${with_rlm_python_lib_dir+set}" = set; then
            yes)
                ;;
            *)
-               rlm_python_lib_dir="$withval"
+               PY_LIB_DIR="$withval"
                ;;
          esac 
        
 fi
 
 
-               rlm_python_inc_dir=
+               PY_INC_DIR=
        # Check whether --with-rlm-python-include-dir or --without-rlm-python-include-dir was given.
 if test "${with_rlm_python_include_dir+set}" = set; then
   withval="$with_rlm_python_include_dir"
@@ -882,33 +862,49 @@ if test "${with_rlm_python_include_dir+set}" = set; then
            yes)
                ;;
            *)
-               rlm_python_include_dir="$withval"
+               PY_INC_DIR="$withval"
                ;;
          esac 
        
 fi
 
 
-       smart_try_dir=$rlm_python_include_dir
+        PY_PREFIX=`python -c 'import sys ; print sys.prefix'`
+        PY_EXEC_PREFIX=`python -c 'import sys ; print sys.exec_prefix'`
+                PY_VERSION=`python -c 'import sys ; print sys.version[0:3]'`
+                PY_LIBS="-lpython$PY_VERSION"
+        PY_LIB_DIR="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
+        PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
+       PY_INC_DIR="$PY_PREFIX/include/python$PY_VERSION"
+        PY_CFLAGS="-I$PY_PREFIX/include/python$PY_VERSION"
+        PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config/Makefile"
+        PY_LOCALMODLIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
+        PY_BASEMODLIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
+        PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE`
+        PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASEMODLIBS $PY_OTHER_LIBS"
+
+       old_CFLAGS=$CFLAGS
+       CFLAGS="$CFLAGS $PY_CFLAGS"
+       smart_try_dir=$PY_INC_DIR
        
 
 ac_safe=`echo "Python.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for Python.h""... $ac_c" 1>&6
-echo "configure:898: checking for Python.h" >&5
+echo "configure:894: checking for Python.h" >&5
 
 smart_include=
 smart_include_dir=
 
   old_CFLAGS="$CFLAGS"
   cat > conftest.$ac_ext <<EOF
-#line 905 "configure"
+#line 901 "configure"
 #include "confdefs.h"
 #include <Python.h>
 int main() {
  int a = 1;
 ; return 0; }
 EOF
-if { (eval echo configure:912: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:908: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   smart_include=" "
 else
@@ -952,14 +948,14 @@ eval "smart_include_dir=\"\$smart_include_dir $DIRS\""
       CFLAGS="$old_CFLAGS -I$try"
 
       cat > conftest.$ac_ext <<EOF
-#line 956 "configure"
+#line 952 "configure"
 #include "confdefs.h"
 #include <Python.h>
 int main() {
  int a = 1;
 ; return 0; }
 EOF
-if { (eval echo configure:963: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:959: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   smart_include="-I$try"
 else
@@ -986,30 +982,39 @@ rm -f conftest*
     echo "$ac_t""no" 1>&6 
 fi
 
+       CFLAGS=$old_CFLAGS
 
-       smart_try_dir=$rlm_python_lib_dir
+       if test "x$ac_cv_header_Python_h" = "xyes"; then
+               python_cflags=$PY_CFLAGS
+       else
+               fail="$fail Python.h"
+               targetname=
+       fi
+
+       old_LIBS=$LIBS
+       LIBS="$LIBS $PY_LIB_LOC $PY_EXTRA_LIBS -lm"
+       smart_try_dir=$PY_LIB_DIR
        
 
-echo $ac_n "checking for Py_Initialize in -lpython$rlm_python_version""... $ac_c" 1>&6
-echo "configure:995: checking for Py_Initialize in -lpython$rlm_python_version" >&5
+echo $ac_n "checking for Py_Initialize in -lpython$PY_VERSION""... $ac_c" 1>&6
+echo "configure:1001: checking for Py_Initialize in -lpython$PY_VERSION" >&5
 
 smart_lib=
 smart_lib_dir=
-ac_safe=`echo "python$rlm_python_version" | sed 'y%./+-%__p_%'`
 
   old_LIBS="$LIBS"
-  LIBS="$LIBS -lpython$rlm_python_version"
+  LIBS="$LIBS -lpython$PY_VERSION"
   cat > conftest.$ac_ext <<EOF
-#line 1004 "configure"
+#line 1009 "configure"
 #include "confdefs.h"
 extern char Py_Initialize();
 int main() {
  Py_Initialize()
 ; return 0; }
 EOF
-if { (eval echo configure:1011: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1016: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
-  smart_lib="-lpython$rlm_python_version"
+  smart_lib="-lpython$PY_VERSION"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -1021,7 +1026,7 @@ rm -f conftest*
 
 if test "x$LOCATE" != "x"; then
         DIRS=
-  file=libpython$rlm_python_version${libltdl_cv_shlibext}
+  file=libpython$PY_VERSION${libltdl_cv_shlibext}
 
   for x in `${LOCATE} $file 2>/dev/null`; do
                                         base=`echo $x | sed "s%/${file}%%"`
@@ -1048,7 +1053,7 @@ eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
 
 if test "x$LOCATE" != "x"; then
         DIRS=
-  file=libpython$rlm_python_version.a
+  file=libpython$PY_VERSION.a
 
   for x in `${LOCATE} $file 2>/dev/null`; do
                                         base=`echo $x | sed "s%/${file}%%"`
@@ -1073,19 +1078,19 @@ eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
 
 
     for try in $smart_try_dir $smart_lib_dir /usr/local/lib/ /opt/lib; do
-      LIBS="$old_LIBS -L$try -lpython$rlm_python_version"
+      LIBS="$old_LIBS -L$try -lpython$PY_VERSION"
 
       cat > conftest.$ac_ext <<EOF
-#line 1080 "configure"
+#line 1085 "configure"
 #include "confdefs.h"
 extern char Py_Initialize();
 int main() {
  Py_Initialize()
 ; return 0; }
 EOF
-if { (eval echo configure:1087: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1092: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
-  smart_lib="-L$try -lpython$rlm_python_version"
+  smart_lib="-L$try -lpython$PY_VERSION"
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
@@ -1100,15 +1105,23 @@ rm -f conftest*
 
         if test "x$smart_lib" != "x"; then
     echo "$ac_t""yes" 1>&6
-    eval "ac_cv_lib_$ac_safe_Py_Initialize=yes"
+    eval "ac_cv_lib_python$PY_VERSION_Py_Initialize=yes"
     LIBS="$old_LIBS $smart_lib"
     SMART_LIBS="$SMART_LIBS $smart_lib"
   else
     echo "$ac_t""no" 1>&6 
 fi
 
+       LIBS=$old_LIBS
+
+       if test "x$ac_cv_lib_python" = "xyes"; then
+               python_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS -lm"
+               targetname=rlm_python
+       else
+               targetname=
+               fail="$fail libpython$PY_VERSION"
+       fi
 
-       targetname=rlm_python
 else
        targetname=
        echo \*\*\* module rlm_python is disabled.
index 56a800e..7042ca8 100644 (file)
@@ -7,24 +7,8 @@ if test x$with_[]modname != xno; then
        AC_PROG_CC
        AC_PROG_CPP
 
-       dnl extra argument: --with-rlm-python-include-dir
-       rlm_python_version=2.2
-       AC_ARG_WITH(rlm-python-version,
-       [  --with-rlm-python-version=[0-9].[0-9]   Version of Python to use [2.2]],
-       [ case "$withval" in
-           no)
-               AC_MSG_ERROR(Need rlm-python-version)
-               ;;
-           yes)
-               ;;
-           *)
-               rlm_python_version="$withval"
-               ;;
-         esac ]
-       )
-
        dnl extra argument: --with-rlm-python-lib-dir
-       rlm_python_lib_dir=
+       PY_LIB_DIR=
        AC_ARG_WITH(rlm-python-lib-dir,
        [  --with-rlm-python-lib-dir=DIR       Directory for Python library files []],
        [ case "$withval" in
@@ -34,13 +18,13 @@ if test x$with_[]modname != xno; then
            yes)
                ;;
            *)
-               rlm_python_lib_dir="$withval"
+               PY_LIB_DIR="$withval"
                ;;
          esac ]
        )
 
        dnl extra argument: --with-rlm-python-include-dir
-       rlm_python_inc_dir=
+       PY_INC_DIR=
        AC_ARG_WITH(rlm-python-include-dir,
        [  --with-rlm-python-include-dir=DIR   Directory for Python include files []],
        [ case "$withval" in
@@ -50,22 +34,54 @@ if test x$with_[]modname != xno; then
            yes)
                ;;
            *)
-               rlm_python_include_dir="$withval"
+               PY_INC_DIR="$withval"
                ;;
          esac ]
        )
 
-       smart_try_dir=$rlm_python_include_dir
+        PY_PREFIX=`python -c 'import sys ; print sys.prefix'`
+        PY_EXEC_PREFIX=`python -c 'import sys ; print sys.exec_prefix'`
+        changequote(<<, >>)dnl
+        PY_VERSION=`python -c 'import sys ; print sys.version[0:3]'`
+        changequote([, ])dnl
+        PY_LIBS="-lpython$PY_VERSION"
+        PY_LIB_DIR="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
+        PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python$PY_VERSION/config"
+       PY_INC_DIR="$PY_PREFIX/include/python$PY_VERSION"
+        PY_CFLAGS="-I$PY_PREFIX/include/python$PY_VERSION"
+        PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python$PY_VERSION/config/Makefile"
+        PY_LOCALMODLIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
+        PY_BASEMODLIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE`
+        PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE`
+        PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASEMODLIBS $PY_OTHER_LIBS"
+
+       old_CFLAGS=$CFLAGS
+       CFLAGS="$CFLAGS $PY_CFLAGS"
+       smart_try_dir=$PY_INC_DIR
        AC_SMART_CHECK_INCLUDE(Python.h)
+       CFLAGS=$old_CFLAGS
 
-       smart_try_dir=$rlm_python_lib_dir
-       AC_SMART_CHECK_LIB(python$rlm_python_version, Py_Initialize, 
-               [ python_ldflags="-L$smart_lib_dir -lpython$rlm_python_version $python_ldflags" ],
-               [ fail=$fail" libpython$rlm_python_version" ],
-               [ $python_ldflags ]
-       )
+       if test "x$ac_cv_header_Python_h" = "xyes"; then
+               python_cflags=$PY_CFLAGS
+       else
+               fail="$fail Python.h"
+               targetname=
+       fi
+
+       old_LIBS=$LIBS
+       LIBS="$LIBS $PY_LIB_LOC $PY_EXTRA_LIBS -lm"
+       smart_try_dir=$PY_LIB_DIR
+       AC_SMART_CHECK_LIB(python$PY_VERSION, Py_Initialize)
+       LIBS=$old_LIBS
+
+       if test "x$ac_cv_lib_python" = "xyes"; then
+               python_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS -lm"
+               targetname=modname
+       else
+               targetname=
+               fail="$fail libpython$PY_VERSION"
+       fi
 
-       targetname=modname
 else
        targetname=
        echo \*\*\* module modname is disabled.