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