1238106SdesAC_DEFUN([AC_PYTHON_DEVEL],[
2238106Sdes        #
3238106Sdes        # Allow the use of a (user set) custom python version
4238106Sdes        #
5238106Sdes        AC_ARG_VAR([PYTHON_VERSION],[The installed Python
6238106Sdes                version to use, for example '2.3'. This string
7238106Sdes                will be appended to the Python interpreter
8238106Sdes                canonical name.])
9238106Sdes
10238106Sdes        AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
11238106Sdes        if test -z "$PYTHON"; then
12238106Sdes           AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path])
13238106Sdes           PYTHON_VERSION=""
14238106Sdes        fi
15238106Sdes
16238106Sdes        if test -z "$PYTHON_VERSION"; then
17285206Sdes		PYTHON_VERSION=`$PYTHON -c "import sys; \
18285206Sdes			print(sys.version.split()[[0]])"`
19238106Sdes	fi
20238106Sdes
21238106Sdes        #
22238106Sdes        # Check if you have distutils, else fail
23238106Sdes        #
24238106Sdes        AC_MSG_CHECKING([for the distutils Python package])
25238106Sdes        ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
26238106Sdes        if test -z "$ac_distutils_result"; then
27238106Sdes                AC_MSG_RESULT([yes])
28238106Sdes        else
29238106Sdes                AC_MSG_RESULT([no])
30238106Sdes                AC_MSG_ERROR([cannot import Python module "distutils".
31238106SdesPlease check your Python installation. The error was:
32238106Sdes$ac_distutils_result])
33238106Sdes                PYTHON_VERSION=""
34238106Sdes        fi
35238106Sdes
36238106Sdes        #
37238106Sdes        # Check for Python include path
38238106Sdes        #
39238106Sdes        AC_MSG_CHECKING([for Python include path])
40238106Sdes        if test -z "$PYTHON_CPPFLAGS"; then
41238106Sdes                python_path=`$PYTHON -c "import distutils.sysconfig; \
42285206Sdes                        print(distutils.sysconfig.get_python_inc());"`
43238106Sdes                if test -n "${python_path}"; then
44238106Sdes                        python_path="-I$python_path"
45238106Sdes                fi
46238106Sdes                PYTHON_CPPFLAGS=$python_path
47238106Sdes        fi
48238106Sdes        AC_MSG_RESULT([$PYTHON_CPPFLAGS])
49238106Sdes        AC_SUBST([PYTHON_CPPFLAGS])
50238106Sdes
51238106Sdes        #
52238106Sdes        # Check for Python library path
53238106Sdes        #
54238106Sdes        AC_MSG_CHECKING([for Python library path])
55238106Sdes        if test -z "$PYTHON_LDFLAGS"; then
56238106Sdes                PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
57285206Sdes                        print(get_config_var('BLDLIBRARY'));"`
58238106Sdes        fi
59238106Sdes        AC_MSG_RESULT([$PYTHON_LDFLAGS])
60238106Sdes        AC_SUBST([PYTHON_LDFLAGS])
61238106Sdes
62238106Sdes        #
63238106Sdes        # Check for site packages
64238106Sdes        #
65238106Sdes        AC_MSG_CHECKING([for Python site-packages path])
66238106Sdes        if test -z "$PYTHON_SITE_PKG"; then
67238106Sdes                PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
68285206Sdes                        print(distutils.sysconfig.get_python_lib(1,0));"`
69238106Sdes        fi
70238106Sdes        AC_MSG_RESULT([$PYTHON_SITE_PKG])
71238106Sdes        AC_SUBST([PYTHON_SITE_PKG])
72238106Sdes
73238106Sdes        #
74238106Sdes        # final check to see if everything compiles alright
75238106Sdes        #
76238106Sdes        AC_MSG_CHECKING([consistency of all components of python development environment])
77238106Sdes        AC_LANG_PUSH([C])
78238106Sdes        # save current global flags
79249141Sdes        ac_save_LIBS="$LIBS"
80249141Sdes        ac_save_CPPFLAGS="$CPPFLAGS"
81249141Sdes
82249141Sdes        LIBS="$LIBS $PYTHON_LDFLAGS"
83249141Sdes        CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
84238106Sdes        AC_TRY_LINK([
85238106Sdes                #include <Python.h>
86238106Sdes        ],[
87238106Sdes                Py_Initialize();
88238106Sdes        ],[pythonexists=yes],[pythonexists=no])
89238106Sdes
90238106Sdes        AC_MSG_RESULT([$pythonexists])
91238106Sdes
92238106Sdes        if test ! "$pythonexists" = "yes"; then
93238106Sdes           AC_MSG_ERROR([
94238106Sdes  Could not link test program to Python. Maybe the main Python library has been
95238106Sdes  installed in some non-standard library path. If so, pass it to configure,
96238106Sdes  via the LDFLAGS environment variable.
97238106Sdes  Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
98238106Sdes  ============================================================================
99238106Sdes   ERROR!
100238106Sdes   You probably have to install the development version of the Python package
101238106Sdes   for your distribution.  The exact name of this package varies among them.
102238106Sdes  ============================================================================
103238106Sdes           ])
104238106Sdes          PYTHON_VERSION=""
105238106Sdes        fi
106238106Sdes        AC_LANG_POP
107238106Sdes        # turn back to default flags
108238106Sdes        CPPFLAGS="$ac_save_CPPFLAGS"
109238106Sdes        LIBS="$ac_save_LIBS"
110238106Sdes
111238106Sdes        #
112238106Sdes        # all done!
113238106Sdes        #
114238106Sdes])
115238106Sdes
116