source: m4/ac_python_devel.m4 @ 48fa0ee

abac0-leakabac0-meicompt_changesgec13mei-idmei-rt0-nmei_rt0mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2tvf-new-xml
Last change on this file since 48fa0ee was 48fa0ee, checked in by Ted Faber <faber@…>, 14 years ago

Fix a few configure bugs:

Find lib strongswan if it is in /usr/local/lib and give a user
override

Find the site_prel directory and give the user an override

Make the ABAC.py and ABAC.pm swig entries

Find python libraries correctly on FreeBSD
(m4/ac_python_devel.m4)

  • Property mode set to 100644
File size: 9.4 KB
Line 
1# Modifed the version below to cope with FreeBSD python reporting the wrong
2# library directory and to fix a broken bash test dependency.
3
4# ===========================================================================
5#            http://autoconf-archive.cryp.to/ac_python_devel.html
6# ===========================================================================
7#
8# SYNOPSIS
9#
10#   AC_PYTHON_DEVEL([version])
11#
12# DESCRIPTION
13#
14#   Note: Defines as a precious variable "PYTHON_VERSION". Don't override it
15#   in your configure.ac.
16#
17#   This macro checks for Python and tries to get the include path to
18#   'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LDFLAGS)
19#   output variables. It also exports $(PYTHON_EXTRA_LIBS) and
20#   $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code.
21#
22#   You can search for some particular version of Python by passing a
23#   parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". Please
24#   note that you *have* to pass also an operator along with the version to
25#   match, and pay special attention to the single quotes surrounding the
26#   version number. Don't use "PYTHON_VERSION" for this: that environment
27#   variable is declared as precious and thus reserved for the end-user.
28#
29#   This macro should work for all versions of Python >= 2.1.0. As an end
30#   user, you can disable the check for the python version by setting the
31#   PYTHON_NOVERSIONCHECK environment variable to something else than the
32#   empty string.
33#
34#   If you need to use this macro for an older Python version, please
35#   contact the authors. We're always open for feedback.
36#
37# LAST MODIFICATION
38#
39#   2008-04-12
40#
41# COPYLEFT
42#
43#   Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
44#   Copyright (c) 2008 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
45#   Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
46#   Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za>
47#   Copyright (c) 2008 Matteo Settenvini <matteo@member.fsf.org>
48#   Copyright (c) 2008 Horst Knorr <hk_classes@knoda.org>
49#
50#   This program is free software: you can redistribute it and/or modify it
51#   under the terms of the GNU General Public License as published by the
52#   Free Software Foundation, either version 3 of the License, or (at your
53#   option) any later version.
54#
55#   This program is distributed in the hope that it will be useful, but
56#   WITHOUT ANY WARRANTY; without even the implied warranty of
57#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
58#   Public License for more details.
59#
60#   You should have received a copy of the GNU General Public License along
61#   with this program. If not, see <http://www.gnu.org/licenses/>.
62#
63#   As a special exception, the respective Autoconf Macro's copyright owner
64#   gives unlimited permission to copy, distribute and modify the configure
65#   scripts that are the output of Autoconf when processing the Macro. You
66#   need not follow the terms of the GNU General Public License when using
67#   or distributing such scripts, even though portions of the text of the
68#   Macro appear in them. The GNU General Public License (GPL) does govern
69#   all other use of the material that constitutes the Autoconf Macro.
70#
71#   This special exception to the GPL applies to versions of the Autoconf
72#   Macro released by the Autoconf Macro Archive. When you make and
73#   distribute a modified version of the Autoconf Macro, you may extend this
74#   special exception to the GPL to apply to your modified version as well.
75
76AC_DEFUN([AC_PYTHON_DEVEL],[
77        #
78        # Allow the use of a (user set) custom python version
79        #
80        AC_ARG_VAR([PYTHON_VERSION],[The installed Python
81                version to use, for example '2.3'. This string
82                will be appended to the Python interpreter
83                canonical name.])
84
85        AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
86        if test -z "$PYTHON"; then
87           AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path])
88           PYTHON_VERSION=""
89        fi
90
91        #
92        # Check for a version of Python >= 2.1.0
93        #
94        AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
95        ac_supports_python_ver=`$PYTHON -c "import sys, string; \
96                ver = string.split(sys.version)[[0]]; \
97                print ver >= '2.1.0'"`
98        if test "$ac_supports_python_ver" != "True"; then
99                if test -z "$PYTHON_NOVERSIONCHECK"; then
100                        AC_MSG_RESULT([no])
101                        AC_MSG_FAILURE([
102This version of the AC@&t@_PYTHON_DEVEL macro
103doesn't work properly with versions of Python before
1042.1.0. You may need to re-run configure, setting the
105variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
106PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
107Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
108to something else than an empty string.
109])
110                else
111                        AC_MSG_RESULT([skip at user request])
112                fi
113        else
114                AC_MSG_RESULT([yes])
115        fi
116
117        #
118        # if the macro parameter ``version'' is set, honour it
119        #
120        if test -n "$1"; then
121                AC_MSG_CHECKING([for a version of Python $1])
122                ac_supports_python_ver=`$PYTHON -c "import sys, string; \
123                        ver = string.split(sys.version)[[0]]; \
124                        print ver $1"`
125                if test "$ac_supports_python_ver" = "True"; then
126                   AC_MSG_RESULT([yes])
127                else
128                        AC_MSG_RESULT([no])
129                        AC_MSG_ERROR([this package requires Python $1.
130If you have it installed, but it isn't the default Python
131interpreter in your system path, please pass the PYTHON_VERSION
132variable to configure. See ``configure --help'' for reference.
133])
134                        PYTHON_VERSION=""
135                fi
136        fi
137
138        #
139        # Check if you have distutils, else fail
140        #
141        AC_MSG_CHECKING([for the distutils Python package])
142        ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
143        if test -z "$ac_distutils_result"; then
144                AC_MSG_RESULT([yes])
145        else
146                AC_MSG_RESULT([no])
147                AC_MSG_ERROR([cannot import Python module "distutils".
148Please check your Python installation. The error was:
149$ac_distutils_result])
150                PYTHON_VERSION=""
151        fi
152
153        #
154        # Check for Python include path
155        #
156        AC_MSG_CHECKING([for Python include path])
157        if test -z "$PYTHON_CPPFLAGS"; then
158                python_path=`$PYTHON -c "import distutils.sysconfig; \
159                        print distutils.sysconfig.get_python_inc();"`
160                if test -n "${python_path}"; then
161                        python_path="-I$python_path"
162                fi
163                PYTHON_CPPFLAGS=$python_path
164        fi
165        AC_MSG_RESULT([$PYTHON_CPPFLAGS])
166        AC_SUBST([PYTHON_CPPFLAGS])
167
168        #
169        # Check for Python library path
170        #
171        AC_MSG_CHECKING([for Python library path])
172        if test -z "$PYTHON_LDFLAGS"; then
173                # (makes two attempts to ensure we've got a version number
174                # from the interpreter)
175                py_version=`$PYTHON -c "from distutils.sysconfig import *; \
176                        from string import join; \
177                        print join(get_config_vars('VERSION'))"`
178                if test "$py_version" = "[None]"; then
179                        if test -n "$PYTHON_VERSION"; then
180                                py_version=$PYTHON_VERSION
181                        else
182                                py_version=`$PYTHON -c "import sys; \
183                                        print sys.version[[:3]]"`
184                        fi
185                fi
186
187                if test `uname` = 'FreeBSD'; then
188                        if test -d "/usr/local/lib/python$py_version/config";
189                                then
190                        PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
191                                from string import join; \
192                                print '-L' + get_python_lib(0,1) +'/config',\
193                                '-lpython';"`$py_version
194                        fi
195                fi
196                if test -z "$PYTHON_LDFLAGS"; then
197
198                        PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
199                                from string import join; \
200                                print '-L' + get_python_lib(0,1), \
201                                '-lpython';"`$py_version
202                fi
203        fi
204        AC_MSG_RESULT([$PYTHON_LDFLAGS])
205        AC_SUBST([PYTHON_LDFLAGS])
206
207        #
208        # Check for site packages
209        #
210        AC_MSG_CHECKING([for Python site-packages path])
211        if test -z "$PYTHON_SITE_PKG"; then
212                PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
213                        print distutils.sysconfig.get_python_lib(0,0);"`
214        fi
215        AC_MSG_RESULT([$PYTHON_SITE_PKG])
216        AC_SUBST([PYTHON_SITE_PKG])
217
218        #
219        # libraries which must be linked in when embedding
220        #
221        AC_MSG_CHECKING(python extra libraries)
222        if test -z "$PYTHON_EXTRA_LIBS"; then
223           PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
224                conf = distutils.sysconfig.get_config_var; \
225                print conf('LOCALMODLIBS'), conf('LIBS')"`
226        fi
227        AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
228        AC_SUBST(PYTHON_EXTRA_LIBS)
229
230        #
231        # linking flags needed when embedding
232        #
233        AC_MSG_CHECKING(python extra linking flags)
234        if test -z "$PYTHON_EXTRA_LDFLAGS"; then
235                PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
236                        conf = distutils.sysconfig.get_config_var; \
237                        print conf('LINKFORSHARED')"`
238        fi
239        AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
240        AC_SUBST(PYTHON_EXTRA_LDFLAGS)
241
242        #
243        # final check to see if everything compiles alright
244        #
245        AC_MSG_CHECKING([consistency of all components of python development environment])
246        AC_LANG_PUSH([C])
247        # save current global flags
248        LIBS="$ac_save_LIBS $PYTHON_LDFLAGS"
249        CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
250        AC_TRY_LINK([
251                #include <Python.h>
252        ],[
253                Py_Initialize();
254        ],[pythonexists=yes],[pythonexists=no])
255
256        AC_MSG_RESULT([$pythonexists])
257
258        if test ! "$pythonexists" = "yes"; then
259           AC_MSG_ERROR([
260  Could not link test program to Python. Maybe the main Python library has been
261  installed in some non-standard library path. If so, pass it to configure,
262  via the LDFLAGS environment variable.
263  Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
264  ============================================================================
265   ERROR!
266   You probably have to install the development version of the Python package
267   for your distribution.  The exact name of this package varies among them.
268  ============================================================================
269           ])
270          PYTHON_VERSION=""
271        fi
272        AC_LANG_POP
273        # turn back to default flags
274        CPPFLAGS="$ac_save_CPPFLAGS"
275        LIBS="$ac_save_LIBS"
276
277        #
278        # all done!
279        #
280])
Note: See TracBrowser for help on using the repository browser.