1AC_DEFUN([AC_PYTHON_DEVEL],[ 2 # 3 # Allow the use of a (user set) custom python version 4 # 5 AC_ARG_VAR([PYTHON_VERSION],[The installed Python 6 version to use, for example '2.3'. This string 7 will be appended to the Python interpreter 8 canonical name.]) 9 10 AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]]) 11 if test -z "$PYTHON"; then 12 AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path]) 13 PYTHON_VERSION="" 14 fi 15 16 if test -z "$PYTHON_VERSION"; then 17 PYTHON_VERSION=`$PYTHON -c "import sys; \ 18 print(sys.version.split()[[0]])"` 19 fi 20 21 # 22 # Check if you have distutils, else fail 23 # 24 AC_MSG_CHECKING([for the distutils Python package]) 25 if ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`; then 26 AC_MSG_RESULT([yes]) 27 else 28 AC_MSG_RESULT([no]) 29 AC_MSG_ERROR([cannot import Python module "distutils". 30Please check your Python installation. The error was: 31$ac_distutils_result]) 32 PYTHON_VERSION="" 33 fi 34 35 # 36 # Check for Python include path 37 # 38 AC_MSG_CHECKING([for Python include path]) 39 if test -z "$PYTHON_CPPFLAGS"; then 40 python_path=`$PYTHON -c "import distutils.sysconfig; \ 41 print(distutils.sysconfig.get_python_inc());"` 42 if test -n "${python_path}"; then 43 python_path="-I$python_path" 44 fi 45 PYTHON_CPPFLAGS=$python_path 46 fi 47 AC_MSG_RESULT([$PYTHON_CPPFLAGS]) 48 AC_SUBST([PYTHON_CPPFLAGS]) 49 50 # 51 # Check for Python library path 52 # 53 AC_MSG_CHECKING([for Python library path]) 54 if test -z "$PYTHON_LDFLAGS"; then 55 PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \ 56 print('-L'+get_config_var('LIBDIR')+' -L'+get_config_var('LIBDEST')+' '+get_config_var('BLDLIBRARY'));"` 57 fi 58 AC_MSG_RESULT([$PYTHON_LDFLAGS]) 59 AC_SUBST([PYTHON_LDFLAGS]) 60 61 if test -z "$PYTHON_LIBDIR"; then 62 PYTHON_LIBDIR=`$PYTHON -c "from distutils.sysconfig import *; \ 63 print(get_config_var('LIBDIR'));"` 64 fi 65 66 # 67 # Check for site packages 68 # 69 AC_MSG_CHECKING([for Python site-packages path]) 70 if test -z "$PYTHON_SITE_PKG"; then 71 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \ 72 print(distutils.sysconfig.get_python_lib(1,0));"` 73 fi 74 AC_MSG_RESULT([$PYTHON_SITE_PKG]) 75 AC_SUBST([PYTHON_SITE_PKG]) 76 77 # 78 # final check to see if everything compiles alright 79 # 80 AC_MSG_CHECKING([consistency of all components of python development environment]) 81 AC_LANG_PUSH([C]) 82 # save current global flags 83 ac_save_LIBS="$LIBS" 84 ac_save_CPPFLAGS="$CPPFLAGS" 85 86 LIBS="$LIBS $PYTHON_LDFLAGS" 87 CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS" 88 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 89 #include <Python.h> 90 ]],[[ 91 Py_Initialize(); 92 ]])],[pythonexists=yes],[pythonexists=no]) 93 94 AC_MSG_RESULT([$pythonexists]) 95 96 if test ! "$pythonexists" = "yes"; then 97 AC_MSG_ERROR([ 98 Could not link test program to Python. Maybe the main Python library has been 99 installed in some non-standard library path. If so, pass it to configure, 100 via the LDFLAGS environment variable. 101 Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib" 102 ============================================================================ 103 ERROR! 104 You probably have to install the development version of the Python package 105 for your distribution. The exact name of this package varies among them. 106 ============================================================================ 107 ]) 108 PYTHON_VERSION="" 109 fi 110 AC_LANG_POP 111 # turn back to default flags 112 CPPFLAGS="$ac_save_CPPFLAGS" 113 LIBS="$ac_save_LIBS" 114 115 # 116 # all done! 117 # 118]) 119 120