]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/unbound/acx_python.m4
Fix multiple vulnerabilities in unbound.
[FreeBSD/FreeBSD.git] / contrib / unbound / acx_python.m4
1 AC_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".
30 Please 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         #
62         # Check for site packages
63         #
64         AC_MSG_CHECKING([for Python site-packages path])
65         if test -z "$PYTHON_SITE_PKG"; then
66                 PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
67                         print(distutils.sysconfig.get_python_lib(1,0));"`
68         fi
69         AC_MSG_RESULT([$PYTHON_SITE_PKG])
70         AC_SUBST([PYTHON_SITE_PKG])
71
72         #
73         # final check to see if everything compiles alright
74         #
75         AC_MSG_CHECKING([consistency of all components of python development environment])
76         AC_LANG_PUSH([C])
77         # save current global flags
78         ac_save_LIBS="$LIBS"
79         ac_save_CPPFLAGS="$CPPFLAGS"
80
81         LIBS="$LIBS $PYTHON_LDFLAGS"
82         CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
83         AC_TRY_LINK([
84                 #include <Python.h>
85         ],[
86                 Py_Initialize();
87         ],[pythonexists=yes],[pythonexists=no])
88
89         AC_MSG_RESULT([$pythonexists])
90
91         if test ! "$pythonexists" = "yes"; then
92            AC_MSG_ERROR([
93   Could not link test program to Python. Maybe the main Python library has been
94   installed in some non-standard library path. If so, pass it to configure,
95   via the LDFLAGS environment variable.
96   Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
97   ============================================================================
98    ERROR!
99    You probably have to install the development version of the Python package
100    for your distribution.  The exact name of this package varies among them.
101   ============================================================================
102            ])
103           PYTHON_VERSION=""
104         fi
105         AC_LANG_POP
106         # turn back to default flags
107         CPPFLAGS="$ac_save_CPPFLAGS"
108         LIBS="$ac_save_LIBS"
109
110         #
111         # all done!
112         #
113 ])
114