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, string; \
18 print string.split(sys.version)[[0]]"`
22 # Check for a version of Python >= 2.1.0
24 AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
25 ac_supports_python_ver=`$PYTHON -c "import sys, string; \
26 ver = string.split(sys.version)[[0]]; \
27 print ver >= '2.1.0'"`
28 if test "$ac_supports_python_ver" != "True"; then
29 if test -z "$PYTHON_NOVERSIONCHECK"; then
32 This version of the AC@&t@_PYTHON_DEVEL macro
33 doesn't work properly with versions of Python before
34 2.1.0. You may need to re-run configure, setting the
35 variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
36 PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
37 Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
38 to something else than an empty string.
41 AC_MSG_RESULT([skip at user request])
48 # if the macro parameter ``version'' is set, honour it
51 AC_MSG_CHECKING([for a version of Python $1])
52 ac_supports_python_ver=`$PYTHON -c "import sys, string; \
53 ver = string.split(sys.version)[[0]]; \
55 if test "$ac_supports_python_ver" = "True"; then
59 AC_MSG_ERROR([this package requires Python $1.
60 If you have it installed, but it isn't the default Python
61 interpreter in your system path, please pass the PYTHON_VERSION
62 variable to configure. See ``configure --help'' for reference.
69 # Check if you have distutils, else fail
71 AC_MSG_CHECKING([for the distutils Python package])
72 ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
73 if test -z "$ac_distutils_result"; then
77 AC_MSG_ERROR([cannot import Python module "distutils".
78 Please check your Python installation. The error was:
79 $ac_distutils_result])
84 # Check for Python include path
86 AC_MSG_CHECKING([for Python include path])
87 if test -z "$PYTHON_CPPFLAGS"; then
88 python_path=`$PYTHON -c "import distutils.sysconfig; \
89 print distutils.sysconfig.get_python_inc();"`
90 if test -n "${python_path}"; then
91 python_path="-I$python_path"
93 PYTHON_CPPFLAGS=$python_path
95 AC_MSG_RESULT([$PYTHON_CPPFLAGS])
96 AC_SUBST([PYTHON_CPPFLAGS])
99 # Check for Python library path
101 AC_MSG_CHECKING([for Python library path])
102 if test -z "$PYTHON_LDFLAGS"; then
103 # (makes two attempts to ensure we've got a version number
104 # from the interpreter)
105 py_version=`$PYTHON -c "from distutils.sysconfig import *; \
106 from string import join; \
107 print join(get_config_vars('VERSION'))"`
108 if test "$py_version" = "[None]"; then
109 if test -n "$PYTHON_VERSION"; then
110 py_version=$PYTHON_VERSION
112 py_version=`$PYTHON -c "import sys; \
113 print sys.version[[:3]]"`
117 PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
118 from string import join; \
119 print '-L' + get_python_lib(0,1), \
120 '-L' + os.path.dirname(get_python_lib(0,1)), \
121 '-lpython';"`$py_version
123 AC_MSG_RESULT([$PYTHON_LDFLAGS])
124 AC_SUBST([PYTHON_LDFLAGS])
127 # Check for site packages
129 AC_MSG_CHECKING([for Python site-packages path])
130 if test -z "$PYTHON_SITE_PKG"; then
131 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
132 print distutils.sysconfig.get_python_lib(1,0);"`
134 AC_MSG_RESULT([$PYTHON_SITE_PKG])
135 AC_SUBST([PYTHON_SITE_PKG])
138 # libraries which must be linked in when embedding
140 AC_MSG_CHECKING(python extra libraries)
141 if test -z "$PYTHON_EXTRA_LIBS"; then
142 PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
143 conf = distutils.sysconfig.get_config_var; \
144 print conf('LOCALMODLIBS'), conf('LIBS')"`
146 AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
147 AC_SUBST(PYTHON_EXTRA_LIBS)
150 # linking flags needed when embedding
152 AC_MSG_CHECKING(python extra linking flags)
153 if test -z "$PYTHON_EXTRA_LDFLAGS"; then
154 PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
155 conf = distutils.sysconfig.get_config_var; \
156 print conf('LINKFORSHARED')"`
158 AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
159 AC_SUBST(PYTHON_EXTRA_LDFLAGS)
162 # final check to see if everything compiles alright
164 AC_MSG_CHECKING([consistency of all components of python development environment])
166 # save current global flags
168 ac_save_CPPFLAGS="$CPPFLAGS"
170 LIBS="$LIBS $PYTHON_LDFLAGS"
171 CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
176 ],[pythonexists=yes],[pythonexists=no])
178 AC_MSG_RESULT([$pythonexists])
180 if test ! "$pythonexists" = "yes"; then
182 Could not link test program to Python. Maybe the main Python library has been
183 installed in some non-standard library path. If so, pass it to configure,
184 via the LDFLAGS environment variable.
185 Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
186 ============================================================================
188 You probably have to install the development version of the Python package
189 for your distribution. The exact name of this package varies among them.
190 ============================================================================
195 # turn back to default flags
196 CPPFLAGS="$ac_save_CPPFLAGS"