1 AC_DEFUN([AC_PYTHON_DEVEL],[
3 # Allow the use of a (user set) custom python version
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
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])
16 if test -z "$PYTHON_VERSION"; then
17 PYTHON_VERSION=`$PYTHON -c "import sys; \
18 print(sys.version.split()[[0]])"`
20 # calculate the version number components.
23 PYTHON_VERSION_MAJOR=`echo $v | sed 's/[^0-9].*//'`
24 if test -z "$PYTHON_VERSION_MAJOR"; then PYTHON_VERSION_MAJOR="0"; fi
25 v=`echo $v | sed -e 's/^[0-9]*$//' -e 's/[0-9]*[^0-9]//'`
26 PYTHON_VERSION_MINOR=`echo $v | sed 's/[^0-9].*//'`
27 if test -z "$PYTHON_VERSION_MINOR"; then PYTHON_VERSION_MINOR="0"; fi
28 v=`echo $v | sed -e 's/^[0-9]*$//' -e 's/[0-9]*[^0-9]//'`
29 PYTHON_VERSION_PATCH=`echo $v | sed 's/[^0-9].*//'`
30 if test -z "$PYTHON_VERSION_PATCH"; then PYTHON_VERSION_PATCH="0"; fi
33 # For some systems, sysconfig exists, but has the wrong paths,
34 # on Debian 10, for python 2.7 and 3.7. So, we check the version,
35 # and for older versions try distutils.sysconfig first. For newer
36 # versions>=3.10, where distutils.sysconfig is deprecated, use
37 # sysconfig first and then attempt the other one.
38 py_distutils_first="no"
39 if test $PYTHON_VERSION_MAJOR -lt 3; then
40 py_distutils_first="yes"
42 if test $PYTHON_VERSION_MAJOR -eq 3 -a $PYTHON_VERSION_MINOR -lt 10; then
43 py_distutils_first="yes"
46 # Check if you have the first module
47 if test "$py_distutils_first" = "yes"; then m="distutils"; else m="sysconfig"; fi
49 AC_MSG_CHECKING([for the $m Python module])
50 if ac_modulecheck_result1=`$PYTHON -c "import $m" 2>&1`; then
57 # if not found, try the other one.
58 if test -z "$sysconfig_module"; then
59 if test "$py_distutils_first" = "yes"; then m2="sysconfig"; else m2="distutils"; fi
60 AC_MSG_CHECKING([for the $m2 Python module])
61 if ac_modulecheck_result2=`$PYTHON -c "import $m2" 2>&1`; then
63 sysconfig_module="$m2"
66 AC_MSG_ERROR([cannot import Python module "$m", or "$m2".
67 Please check your Python installation. The errors are:
69 $ac_modulecheck_result1
71 $ac_modulecheck_result2])
75 if test "$sysconfig_module" = "distutils"; then sysconfig_module="distutils.sysconfig"; fi
78 # Check for Python include path
80 AC_MSG_CHECKING([for Python include path])
81 if test -z "$PYTHON_CPPFLAGS"; then
82 if test "$sysconfig_module" = "sysconfig"; then
83 python_path=`$PYTHON -c 'import sysconfig; \
84 print(sysconfig.get_path("include"));'`
86 python_path=`$PYTHON -c "import distutils.sysconfig; \
87 print(distutils.sysconfig.get_python_inc());"`
89 if test -n "${python_path}"; then
90 python_path="-I$python_path"
92 PYTHON_CPPFLAGS=$python_path
94 AC_MSG_RESULT([$PYTHON_CPPFLAGS])
95 AC_SUBST([PYTHON_CPPFLAGS])
98 # Check for Python library path
100 AC_MSG_CHECKING([for Python library path])
101 if test -z "$PYTHON_LDFLAGS"; then
102 PYTHON_LDFLAGS=`$PYTHON -c "from $sysconfig_module import *; \
103 print('-L'+get_config_var('LIBDIR')+' -L'+get_config_var('LIBDEST')+' '+get_config_var('BLDLIBRARY'));"`
105 AC_MSG_RESULT([$PYTHON_LDFLAGS])
106 AC_SUBST([PYTHON_LDFLAGS])
108 if test -z "$PYTHON_LIBDIR"; then
109 PYTHON_LIBDIR=`$PYTHON -c "from $sysconfig_module import *; \
110 print(get_config_var('LIBDIR'));"`
114 # Check for site packages
116 AC_MSG_CHECKING([for Python site-packages path])
117 if test -z "$PYTHON_SITE_PKG"; then
118 if test "$sysconfig_module" = "sysconfig"; then
119 PYTHON_SITE_PKG=`$PYTHON -c 'import sysconfig; \
120 print(sysconfig.get_path("platlib"));'`
122 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
123 print(distutils.sysconfig.get_python_lib(1,0));"`
126 AC_MSG_RESULT([$PYTHON_SITE_PKG])
127 AC_SUBST([PYTHON_SITE_PKG])
130 # final check to see if everything compiles alright
132 AC_MSG_CHECKING([consistency of all components of python development environment])
134 # save current global flags
136 ac_save_CPPFLAGS="$CPPFLAGS"
138 LIBS="$LIBS $PYTHON_LDFLAGS"
139 CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
140 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
144 ]])],[pythonexists=yes],[pythonexists=no])
146 AC_MSG_RESULT([$pythonexists])
148 if test ! "$pythonexists" = "yes"; then
150 Could not link test program to Python. Maybe the main Python library has been
151 installed in some non-standard library path. If so, pass it to configure,
152 via the LDFLAGS environment variable.
153 Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
154 ============================================================================
156 You probably have to install the development version of the Python package
157 for your distribution. The exact name of this package varies among them.
158 ============================================================================
163 # turn back to default flags
164 CPPFLAGS="$ac_save_CPPFLAGS"