0b5e174590b7734b5f487e695c3e12b669008677
[ira/wip.git] / source / scripting / python / config.m4
1 AC_ARG_VAR([PYTHON_VERSION],[The installed Python
2         version to use, for example '2.3'. This string 
3         will be appended to the Python interpreter
4         canonical name.])
5
6 AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
7 if test -z "$PYTHON"; then
8         working_python=no
9         AC_MSG_WARN([No python found])
10 fi
11
12 #
13 # Check for a version of Python >= 2.1.0
14 #
15 AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
16 ac_supports_python_ver=`$PYTHON -c "import sys, string; \
17         ver = string.split(sys.version)[[0]]; \
18         print ver >= '2.1.0'"`
19 if test "$ac_supports_python_ver" != "True"; then
20         working_python=no
21         AC_MSG_RESULT([no])
22 else 
23         AC_MSG_RESULT([yes])
24 fi
25
26 #
27 # Check if you have distutils, else fail
28 #
29 AC_MSG_CHECKING([for the distutils Python package])
30 ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
31 if test -z "$ac_distutils_result"; then
32         AC_MSG_RESULT([yes])
33         working_python=yes
34 else
35         AC_MSG_RESULT([no])
36         working_python=no
37 fi
38
39 #
40 # Check for Python include path
41 #
42 AC_MSG_CHECKING([for Python include path])
43 if test -z "$PYTHON_CPPFLAGS"; then
44         python_path=`$PYTHON -c "import distutils.sysconfig; \
45                         print distutils.sysconfig.get_python_inc();"`
46         if test -n "${python_path}"; then
47                 python_path="-I$python_path"
48         fi
49         PYTHON_CPPFLAGS=$python_path
50 fi
51 AC_MSG_RESULT([$PYTHON_CPPFLAGS])
52 AC_SUBST([PYTHON_CPPFLAGS])
53
54 #
55 # Check for Python library path
56 #
57 AC_MSG_CHECKING([for Python library path])
58 if test -z "$PYTHON_LDFLAGS"; then
59         # (makes two attempts to ensure we've got a version number
60         # from the interpreter)
61         py_version=`$PYTHON -c "from distutils.sysconfig import *; \
62                 from string import join; \
63                 print join(get_config_vars('VERSION'))"`
64         if test "$py_version" == "[None]"; then
65                 if test -n "$PYTHON_VERSION"; then
66                         py_version=$PYTHON_VERSION
67                 else
68                         py_version=`$PYTHON -c "import sys; \
69                                 print sys.version[[:3]]"`
70                 fi
71         fi
72
73         PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
74                 from string import join; \
75                 print '-L' + get_python_lib(0,1), \
76                         '-lpython';"`$py_version
77 fi              
78 AC_MSG_RESULT([$PYTHON_LDFLAGS])
79 AC_SUBST([PYTHON_LDFLAGS])
80
81 #
82 # Check for site packages
83 #
84 AC_MSG_CHECKING([for Python site-packages path])
85 if test -z "$PYTHON_SITE_PKG"; then
86         PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
87                         print distutils.sysconfig.get_python_lib(0,0);"`
88 fi
89 AC_MSG_RESULT([$PYTHON_SITE_PKG])
90 AC_SUBST([PYTHON_SITE_PKG])
91
92 #
93 # libraries which must be linked in when embedding
94 #
95 AC_MSG_CHECKING(python extra libraries)
96 if test -z "$PYTHON_EXTRA_LIBS"; then
97    PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
98                         conf = distutils.sysconfig.get_config_var; \
99                         print conf('LOCALMODLIBS'), conf('LIBS')"`
100 fi
101 AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
102 AC_SUBST(PYTHON_EXTRA_LIBS)
103
104 #
105 # linking flags needed when embedding
106 #
107 AC_MSG_CHECKING(python extra linking flags)
108 if test -z "$PYTHON_EXTRA_LDFLAGS"; then
109         PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
110                 conf = distutils.sysconfig.get_config_var; \
111                 print conf('LINKFORSHARED')"`
112 fi
113 AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
114 AC_SUBST(PYTHON_EXTRA_LDFLAGS)
115
116 SMB_EXT_LIB(LIBPYTHON, [$PYTHON_LDFLAGS], [$PYTHON_CPPFLAGS])
117
118 if test x$working_python = xyes
119 then
120         SMB_ENABLE(LIBPYTHON,YES)
121 else
122         SMB_ENABLE(LIBPYTHON,NO)
123 fi
124