1 dnl Check if the C compiler accepts a certain C flag, and if so adds it to
3 AC_DEFUN(DIA_CHECK_CFLAG, [
4 AC_MSG_CHECKING(if C compiler accepts $1)
7 AC_TRY_COMPILE([#include <stdio.h>], [printf("hello");],
8 [AC_MSG_RESULT(yes)],dnl
10 CFLAGS="$save_CFLAGS"])
13 ## ------------------------
14 ## Python file handling
16 ## Updated by James Henstridge
17 ## ------------------------
19 # AM_PATH_PYTHON([MINIMUM-VERSION])
21 # Adds support for distributing Python modules and packages. To
22 # install modules, copy them to $(pythondir), using the python_PYTHON
23 # automake variable. To install a package with the same name as the
24 # automake package, install to $(pkgpythondir), or use the
25 # pkgpython_PYTHON automake variable.
27 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
28 # locations to install python extension modules (shared libraries).
29 # Another macro is required to find the appropriate flags to compile
32 # If your package is configured with a different prefix to python,
33 # users will have to add the install directory to the PYTHONPATH
34 # environment variable, or create a .pth file (see the python
35 # documentation for details).
37 # If the MINIUMUM-VERSION argument is passed, AM_PATH_PYTHON will
38 # cause an error if the version of python installed on the system
39 # doesn't meet the requirement. MINIMUM-VERSION should consist of
40 # numbers and dots only.
43 AC_DEFUN([AM_PATH_PYTHON],
45 dnl Find a version of Python. I could check for python versions 1.4
46 dnl or earlier, but the default installation locations changed from
47 dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
48 dnl in 1.5, and I don't want to maintain that logic.
50 if test -z "$PYTHON"; then
51 AC_PATH_PROGS(PYTHON, python python2.1 python2.0 python1.6 python1.5)
54 dnl should we do the version check?
56 AC_MSG_CHECKING(if Python version >= $1)
57 changequote(<<, >>)dnl
61 pyver = string.split(sys.version)[0] # first word is version string
62 # split strings by '.' and convert to numeric
63 minver = map(string.atoi, string.split(minver, '.'))
64 if hasattr(sys, 'version_info'):
65 pyver = sys.version_info[:3]
67 pyver = map(string.atoi, string.split(pyver, '.'))
68 # we can now do comparisons on the two lists:
74 if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
82 AC_MSG_CHECKING([local Python configuration])
84 dnl Query Python for its version number. Getting [:3] seems to be
85 dnl the best way to do this; it's what "site.py" does in the standard
86 dnl library. Need to change quote character because of [:3]
88 AC_SUBST(PYTHON_VERSION)
89 changequote(<<, >>)dnl
90 PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
94 dnl Use the values of $prefix and $exec_prefix for the corresponding
95 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
96 dnl distinct variables so they can be overridden if need be. However,
97 dnl general consensus is that you shouldn't need this ability.
99 AC_SUBST(PYTHON_PREFIX)
100 PYTHON_PREFIX='${prefix}'
102 AC_SUBST(PYTHON_EXEC_PREFIX)
103 PYTHON_EXEC_PREFIX='${exec_prefix}'
105 dnl At times (like when building shared libraries) you may want
106 dnl to know which OS platform Python thinks this is.
108 AC_SUBST(PYTHON_PLATFORM)
109 PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
112 dnl Set up 4 directories:
114 dnl pythondir -- where to install python scripts. This is the
115 dnl site-packages directory, not the python standard library
116 dnl directory like in previous automake betas. This behaviour
117 dnl is more consistent with lispdir.m4 for example.
119 dnl Also, if the package prefix isn't the same as python's prefix,
120 dnl then the old $(pythondir) was pretty useless.
123 pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
125 dnl pkgpythondir -- $PACKAGE directory under pythondir. Was
126 dnl PYTHON_SITE_PACKAGE in previous betas, but this naming is
127 dnl more consistent with the rest of automake.
128 dnl Maybe this should be put in python.am?
130 AC_SUBST(pkgpythondir)
131 pkgpythondir=\${pythondir}/$PACKAGE
133 dnl pyexecdir -- directory for installing python extension modules
134 dnl (shared libraries) Was PYTHON_SITE_EXEC in previous betas.
137 pyexecdir=$PYTHON_EXEC_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
139 dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
140 dnl Maybe this should be put in python.am?
142 AC_SUBST(pkgpyexecdir)
143 pkgpyexecdir=\${pyexecdir}/$PACKAGE
145 AC_MSG_RESULT([looks good])
148 dnl AM_CHECK_PYMOD(MODNAME [,SYMBOL [,ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]]])
149 dnl Check if a module containing a given symbol is visible to python.
150 AC_DEFUN(AM_CHECK_PYMOD,
151 [AC_REQUIRE([AM_PATH_PYTHON])
152 py_mod_var=`echo $1['_']$2 | sed 'y%./+-%__p_%'`
153 AC_MSG_CHECKING(for ifelse([$2],[],,[$2 in ])python module $1)
154 AC_CACHE_VAL(py_cv_mod_$py_mod_var, [
155 ifelse([$2],[], [prog="
163 sys.exit(0)"], [prog="
166 if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC
168 eval "py_cv_mod_$py_mod_var=yes"
170 eval "py_cv_mod_$py_mod_var=no"
173 py_val=`eval "echo \`echo '$py_cv_mod_'$py_mod_var\`"`
174 if test "x$py_val" != xno; then
176 ifelse([$3], [],, [$3
180 ifelse([$4], [],, [$4
185 dnl a macro to check for ability to create python extensions
186 dnl AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
187 dnl function also defines PYTHON_INCLUDES
188 AC_DEFUN([AM_CHECK_PYTHON_HEADERS],
189 [AC_REQUIRE([AM_PATH_PYTHON])
190 AC_MSG_CHECKING(for headers required to compile python extensions)
191 dnl deduce PYTHON_INCLUDES
192 py_prefix=`$PYTHON -c "import sys; print sys.prefix"`
193 py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
194 PYTHON_INCLUDES="-I${py_prefix}/include/python${PYTHON_VERSION}"
195 if test "$py_prefix" != "$py_exec_prefix"; then
196 PYTHON_INCLUDES="$PYTHON_INCLUDES -I${py_exec_prefix}/include/python${PYTHON_VERSION}"
198 AC_SUBST(PYTHON_INCLUDES)
199 dnl check if the headers exist:
200 save_CPPFLAGS="$CPPFLAGS"
201 CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
202 AC_TRY_CPP([#include <Python.h>],dnl
203 [AC_MSG_RESULT(found)
205 [AC_MSG_RESULT(not found)
207 CPPFLAGS="$save_CPPFLAGS"
210 AC_DEFUN([AM_CHECK_PYTHON_LIB],
211 [AC_REQUIRE([AM_PATH_PYTHON])
212 AC_REQUIRE([AM_CHECK_PYTHON_HEADERS])
214 AC_MSG_CHECKING(for libpython${PYTHON_VERSION}.a)
216 py_exec_prefix=`$PYTHON -c "import sys; print sys.exec_prefix"`
218 py_makefile="${py_exec_prefix}/lib/python${PYTHON_VERSION}/config/Makefile"
219 if test -f "$py_makefile"; then
220 dnl extra required libs
221 py_localmodlibs=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $py_makefile`
222 py_basemodlibs=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $py_makefile`
223 py_other_libs=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $py_makefile`
225 dnl now the actual libpython
226 if test -e "${py_exec_prefix}/lib/python${PYTHON_VERSION}/config/libpython${PYTHON_VERSION}.a"; then
227 PYTHON_LIBS="-L${py_exec_prefix}/lib/python${PYTHON_VERSION}/config -lpython${PYTHON_VERSION} $py_localmodlibs $py_basemodlibs $py_other_libs"
230 AC_MSG_RESULT(not found)
233 AC_MSG_RESULT(not found)
235 AC_SUBST(PYTHON_LIBS)])