xref: /freebsd-src/sys/contrib/openzfs/config/ax_python_devel.m4 (revision 81b22a9892b1047e551fc3f1d6d58031bc59a4c3)
1eda14cbcSMatt Macy# ===========================================================================
2eda14cbcSMatt Macy#     https://www.gnu.org/software/autoconf-archive/ax_python_devel.html
3eda14cbcSMatt Macy# ===========================================================================
4eda14cbcSMatt Macy#
5eda14cbcSMatt Macy# SYNOPSIS
6eda14cbcSMatt Macy#
7eda14cbcSMatt Macy#   AX_PYTHON_DEVEL([version], [action-if-not-found])
8eda14cbcSMatt Macy#
9eda14cbcSMatt Macy# DESCRIPTION
10eda14cbcSMatt Macy#
11eda14cbcSMatt Macy#   Note: Defines as a precious variable "PYTHON_VERSION". Don't override it
12eda14cbcSMatt Macy#   in your configure.ac.
13eda14cbcSMatt Macy#
14eda14cbcSMatt Macy#   Note: this is a slightly modified version of the original AX_PYTHON_DEVEL
15eda14cbcSMatt Macy#   macro which accepts an additional [action-if-not-found] argument. This
16eda14cbcSMatt Macy#   allow to detect if Python development is available without aborting the
17eda14cbcSMatt Macy#   configure phase with an hard error in case it is not.
18eda14cbcSMatt Macy#
19eda14cbcSMatt Macy#   This macro checks for Python and tries to get the include path to
20eda14cbcSMatt Macy#   'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LIBS) output
21eda14cbcSMatt Macy#   variables. It also exports $(PYTHON_EXTRA_LIBS) and
22eda14cbcSMatt Macy#   $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code.
23eda14cbcSMatt Macy#
24eda14cbcSMatt Macy#   You can search for some particular version of Python by passing a
25eda14cbcSMatt Macy#   parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". Please
26eda14cbcSMatt Macy#   note that you *have* to pass also an operator along with the version to
27eda14cbcSMatt Macy#   match, and pay special attention to the single quotes surrounding the
28eda14cbcSMatt Macy#   version number. Don't use "PYTHON_VERSION" for this: that environment
29eda14cbcSMatt Macy#   variable is declared as precious and thus reserved for the end-user.
30eda14cbcSMatt Macy#
31eda14cbcSMatt Macy#   This macro should work for all versions of Python >= 2.1.0. As an end
32eda14cbcSMatt Macy#   user, you can disable the check for the python version by setting the
33eda14cbcSMatt Macy#   PYTHON_NOVERSIONCHECK environment variable to something else than the
34eda14cbcSMatt Macy#   empty string.
35eda14cbcSMatt Macy#
36eda14cbcSMatt Macy#   If you need to use this macro for an older Python version, please
37eda14cbcSMatt Macy#   contact the authors. We're always open for feedback.
38eda14cbcSMatt Macy#
39eda14cbcSMatt Macy# LICENSE
40eda14cbcSMatt Macy#
41eda14cbcSMatt Macy#   Copyright (c) 2009 Sebastian Huber <sebastian-huber@web.de>
42eda14cbcSMatt Macy#   Copyright (c) 2009 Alan W. Irwin
43eda14cbcSMatt Macy#   Copyright (c) 2009 Rafael Laboissiere <rafael@laboissiere.net>
44eda14cbcSMatt Macy#   Copyright (c) 2009 Andrew Collier
45eda14cbcSMatt Macy#   Copyright (c) 2009 Matteo Settenvini <matteo@member.fsf.org>
46eda14cbcSMatt Macy#   Copyright (c) 2009 Horst Knorr <hk_classes@knoda.org>
47eda14cbcSMatt Macy#   Copyright (c) 2013 Daniel Mullner <muellner@math.stanford.edu>
48eda14cbcSMatt Macy#   Copyright (c) 2018 loli10K <ezomori.nozomu@gmail.com>
49eda14cbcSMatt Macy#
50eda14cbcSMatt Macy#   This program is free software: you can redistribute it and/or modify it
51eda14cbcSMatt Macy#   under the terms of the GNU General Public License as published by the
52eda14cbcSMatt Macy#   Free Software Foundation, either version 3 of the License, or (at your
53eda14cbcSMatt Macy#   option) any later version.
54eda14cbcSMatt Macy#
55eda14cbcSMatt Macy#   This program is distributed in the hope that it will be useful, but
56eda14cbcSMatt Macy#   WITHOUT ANY WARRANTY; without even the implied warranty of
57eda14cbcSMatt Macy#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
58eda14cbcSMatt Macy#   Public License for more details.
59eda14cbcSMatt Macy#
60eda14cbcSMatt Macy#   You should have received a copy of the GNU General Public License along
61eda14cbcSMatt Macy#   with this program. If not, see <https://www.gnu.org/licenses/>.
62eda14cbcSMatt Macy#
63eda14cbcSMatt Macy#   As a special exception, the respective Autoconf Macro's copyright owner
64eda14cbcSMatt Macy#   gives unlimited permission to copy, distribute and modify the configure
65eda14cbcSMatt Macy#   scripts that are the output of Autoconf when processing the Macro. You
66eda14cbcSMatt Macy#   need not follow the terms of the GNU General Public License when using
67eda14cbcSMatt Macy#   or distributing such scripts, even though portions of the text of the
68eda14cbcSMatt Macy#   Macro appear in them. The GNU General Public License (GPL) does govern
69eda14cbcSMatt Macy#   all other use of the material that constitutes the Autoconf Macro.
70eda14cbcSMatt Macy#
71eda14cbcSMatt Macy#   This special exception to the GPL applies to versions of the Autoconf
72eda14cbcSMatt Macy#   Macro released by the Autoconf Archive. When you make and distribute a
73eda14cbcSMatt Macy#   modified version of the Autoconf Macro, you may extend this special
74eda14cbcSMatt Macy#   exception to the GPL to apply to your modified version as well.
75eda14cbcSMatt Macy
76eda14cbcSMatt Macy#serial 21
77eda14cbcSMatt Macy
78eda14cbcSMatt MacyAU_ALIAS([AC_PYTHON_DEVEL], [AX_PYTHON_DEVEL])
79eda14cbcSMatt MacyAC_DEFUN([AX_PYTHON_DEVEL],[
80eda14cbcSMatt Macy	#
81eda14cbcSMatt Macy	# Allow the use of a (user set) custom python version
82eda14cbcSMatt Macy	#
83eda14cbcSMatt Macy	AC_ARG_VAR([PYTHON_VERSION],[The installed Python
84eda14cbcSMatt Macy		version to use, for example '2.3'. This string
85eda14cbcSMatt Macy		will be appended to the Python interpreter
86eda14cbcSMatt Macy		canonical name.])
87eda14cbcSMatt Macy
88eda14cbcSMatt Macy	AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
89eda14cbcSMatt Macy	if test -z "$PYTHON"; then
90eda14cbcSMatt Macy		m4_ifvaln([$2],[$2],[
91eda14cbcSMatt Macy			AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path])
92eda14cbcSMatt Macy			PYTHON_VERSION=""
93eda14cbcSMatt Macy		])
94eda14cbcSMatt Macy	fi
95eda14cbcSMatt Macy
96eda14cbcSMatt Macy	#
97eda14cbcSMatt Macy	# Check for a version of Python >= 2.1.0
98eda14cbcSMatt Macy	#
99eda14cbcSMatt Macy	AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
1003ff01b23SMartin Matuska	ac_supports_python_ver=`cat<<EOD | $PYTHON -
1013ff01b23SMartin Matuskafrom __future__ import print_function;
1023ff01b23SMartin Matuskaimport sys;
1033ff01b23SMartin Matuskatry:
1043ff01b23SMartin Matuska	from packaging import version;
1053ff01b23SMartin Matuskaexcept ImportError:
1063ff01b23SMartin Matuska	from distlib import version;
1073ff01b23SMartin Matuskaver = sys.version.split ()[[0]];
1083ff01b23SMartin Matuska(tst_cmp, tst_ver) = ">= '2.1.0'".split ();
1093ff01b23SMartin Matuskatst_ver = tst_ver.strip ("'");
1103ff01b23SMartin Matuskaeval ("print (version.LegacyVersion (ver)"+ tst_cmp +"version.LegacyVersion (tst_ver))")
1113ff01b23SMartin MatuskaEOD`
112eda14cbcSMatt Macy	if test "$ac_supports_python_ver" != "True"; then
113eda14cbcSMatt Macy		if test -z "$PYTHON_NOVERSIONCHECK"; then
114eda14cbcSMatt Macy			AC_MSG_RESULT([no])
115eda14cbcSMatt Macy			m4_ifvaln([$2],[$2],[
116eda14cbcSMatt Macy				AC_MSG_FAILURE([
117eda14cbcSMatt MacyThis version of the AC@&t@_PYTHON_DEVEL macro
118eda14cbcSMatt Macydoesn't work properly with versions of Python before
119eda14cbcSMatt Macy2.1.0. You may need to re-run configure, setting the
120eda14cbcSMatt Macyvariables PYTHON_CPPFLAGS, PYTHON_LIBS, PYTHON_SITE_PKG,
121eda14cbcSMatt MacyPYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
122eda14cbcSMatt MacyMoreover, to disable this check, set PYTHON_NOVERSIONCHECK
123eda14cbcSMatt Macyto something else than an empty string.
124eda14cbcSMatt Macy])
125eda14cbcSMatt Macy			])
126eda14cbcSMatt Macy		else
127eda14cbcSMatt Macy			AC_MSG_RESULT([skip at user request])
128eda14cbcSMatt Macy		fi
129eda14cbcSMatt Macy	else
130eda14cbcSMatt Macy		AC_MSG_RESULT([yes])
131eda14cbcSMatt Macy	fi
132eda14cbcSMatt Macy
133eda14cbcSMatt Macy	#
134eda14cbcSMatt Macy	# if the macro parameter ``version'' is set, honour it
135eda14cbcSMatt Macy	#
136eda14cbcSMatt Macy	if test -n "$1"; then
137eda14cbcSMatt Macy		AC_MSG_CHECKING([for a version of Python $1])
1383ff01b23SMartin Matuska		# Why the strip ()?  Because if we don't, version.parse
1393ff01b23SMartin Matuska		# will, for example, report 3.10.0 >= '3.11.0'
1403ff01b23SMartin Matuska		ac_supports_python_ver=`cat<<EOD | $PYTHON -
1413ff01b23SMartin Matuska
1423ff01b23SMartin Matuskafrom __future__ import print_function;
1433ff01b23SMartin Matuskaimport sys;
1443ff01b23SMartin Matuskatry:
1453ff01b23SMartin Matuska	from packaging import version;
1463ff01b23SMartin Matuskaexcept ImportError:
1473ff01b23SMartin Matuska	from distlib import version;
1483ff01b23SMartin Matuskaver = sys.version.split ()[[0]];
1493ff01b23SMartin Matuska(tst_cmp, tst_ver) = "$1".split ();
1503ff01b23SMartin Matuskatst_ver = tst_ver.strip ("'");
1513ff01b23SMartin Matuskaeval ("print (version.LegacyVersion (ver)"+ tst_cmp +"version.LegacyVersion (tst_ver))")
1523ff01b23SMartin MatuskaEOD`
153eda14cbcSMatt Macy		if test "$ac_supports_python_ver" = "True"; then
154eda14cbcSMatt Macy		   AC_MSG_RESULT([yes])
155eda14cbcSMatt Macy		else
156eda14cbcSMatt Macy			AC_MSG_RESULT([no])
157eda14cbcSMatt Macy			m4_ifvaln([$2],[$2],[
158eda14cbcSMatt Macy				AC_MSG_ERROR([this package requires Python $1.
159eda14cbcSMatt MacyIf you have it installed, but it isn't the default Python
160eda14cbcSMatt Macyinterpreter in your system path, please pass the PYTHON_VERSION
161eda14cbcSMatt Macyvariable to configure. See ``configure --help'' for reference.
162eda14cbcSMatt Macy])
163eda14cbcSMatt Macy				PYTHON_VERSION=""
164eda14cbcSMatt Macy			])
165eda14cbcSMatt Macy		fi
166eda14cbcSMatt Macy	fi
167eda14cbcSMatt Macy
168eda14cbcSMatt Macy	#
169eda14cbcSMatt Macy	# Check if you have distutils, else fail
170eda14cbcSMatt Macy	#
171eda14cbcSMatt Macy	AC_MSG_CHECKING([for the distutils Python package])
17216038816SMartin Matuska	if ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`; then
173eda14cbcSMatt Macy		AC_MSG_RESULT([yes])
174eda14cbcSMatt Macy	else
175eda14cbcSMatt Macy		AC_MSG_RESULT([no])
176eda14cbcSMatt Macy		m4_ifvaln([$2],[$2],[
177eda14cbcSMatt Macy			AC_MSG_ERROR([cannot import Python module "distutils".
178eda14cbcSMatt MacyPlease check your Python installation. The error was:
179eda14cbcSMatt Macy$ac_distutils_result])
180eda14cbcSMatt Macy			PYTHON_VERSION=""
181eda14cbcSMatt Macy		])
182eda14cbcSMatt Macy	fi
183eda14cbcSMatt Macy
184eda14cbcSMatt Macy	#
185eda14cbcSMatt Macy	# Check for Python include path
186eda14cbcSMatt Macy	#
187eda14cbcSMatt Macy	AC_MSG_CHECKING([for Python include path])
188eda14cbcSMatt Macy	if test -z "$PYTHON_CPPFLAGS"; then
189eda14cbcSMatt Macy		python_path=`$PYTHON -c "import distutils.sysconfig; \
190eda14cbcSMatt Macy			print (distutils.sysconfig.get_python_inc ());"`
191eda14cbcSMatt Macy		plat_python_path=`$PYTHON -c "import distutils.sysconfig; \
192eda14cbcSMatt Macy			print (distutils.sysconfig.get_python_inc (plat_specific=1));"`
193eda14cbcSMatt Macy		if test -n "${python_path}"; then
194eda14cbcSMatt Macy			if test "${plat_python_path}" != "${python_path}"; then
195eda14cbcSMatt Macy				python_path="-I$python_path -I$plat_python_path"
196eda14cbcSMatt Macy			else
197eda14cbcSMatt Macy				python_path="-I$python_path"
198eda14cbcSMatt Macy			fi
199eda14cbcSMatt Macy		fi
200eda14cbcSMatt Macy		PYTHON_CPPFLAGS=$python_path
201eda14cbcSMatt Macy	fi
202eda14cbcSMatt Macy	AC_MSG_RESULT([$PYTHON_CPPFLAGS])
203eda14cbcSMatt Macy	AC_SUBST([PYTHON_CPPFLAGS])
204eda14cbcSMatt Macy
205eda14cbcSMatt Macy	#
206eda14cbcSMatt Macy	# Check for Python library path
207eda14cbcSMatt Macy	#
208eda14cbcSMatt Macy	AC_MSG_CHECKING([for Python library path])
209eda14cbcSMatt Macy	if test -z "$PYTHON_LIBS"; then
210eda14cbcSMatt Macy		# (makes two attempts to ensure we've got a version number
211eda14cbcSMatt Macy		# from the interpreter)
212eda14cbcSMatt Macy		ac_python_version=`cat<<EOD | $PYTHON -
213eda14cbcSMatt Macy
214eda14cbcSMatt Macy# join all versioning strings, on some systems
215eda14cbcSMatt Macy# major/minor numbers could be in different list elements
216eda14cbcSMatt Macyfrom distutils.sysconfig import *
217eda14cbcSMatt Macye = get_config_var('VERSION')
218eda14cbcSMatt Macyif e is not None:
219eda14cbcSMatt Macy	print(e)
220eda14cbcSMatt MacyEOD`
221eda14cbcSMatt Macy
222eda14cbcSMatt Macy		if test -z "$ac_python_version"; then
223eda14cbcSMatt Macy			if test -n "$PYTHON_VERSION"; then
224eda14cbcSMatt Macy				ac_python_version=$PYTHON_VERSION
225eda14cbcSMatt Macy			else
226eda14cbcSMatt Macy				ac_python_version=`$PYTHON -c "import sys; \
227*81b22a98SMartin Matuska					print ('.'.join(sys.version.split('.')[[:2]]))"`
228eda14cbcSMatt Macy			fi
229eda14cbcSMatt Macy		fi
230eda14cbcSMatt Macy
231eda14cbcSMatt Macy		# Make the versioning information available to the compiler
232eda14cbcSMatt Macy		AC_DEFINE_UNQUOTED([HAVE_PYTHON], ["$ac_python_version"],
233eda14cbcSMatt Macy                                   [If available, contains the Python version number currently in use.])
234eda14cbcSMatt Macy
235eda14cbcSMatt Macy		# First, the library directory:
236eda14cbcSMatt Macy		ac_python_libdir=`cat<<EOD | $PYTHON -
237eda14cbcSMatt Macy
238eda14cbcSMatt Macy# There should be only one
239eda14cbcSMatt Macyimport distutils.sysconfig
240eda14cbcSMatt Macye = distutils.sysconfig.get_config_var('LIBDIR')
241eda14cbcSMatt Macyif e is not None:
242eda14cbcSMatt Macy	print (e)
243eda14cbcSMatt MacyEOD`
244eda14cbcSMatt Macy
245eda14cbcSMatt Macy		# Now, for the library:
246eda14cbcSMatt Macy		ac_python_library=`cat<<EOD | $PYTHON -
247eda14cbcSMatt Macy
248eda14cbcSMatt Macyimport distutils.sysconfig
249eda14cbcSMatt Macyc = distutils.sysconfig.get_config_vars()
250eda14cbcSMatt Macyif 'LDVERSION' in c:
251eda14cbcSMatt Macy	print ('python'+c[['LDVERSION']])
252eda14cbcSMatt Macyelse:
253eda14cbcSMatt Macy	print ('python'+c[['VERSION']])
254eda14cbcSMatt MacyEOD`
255eda14cbcSMatt Macy
256eda14cbcSMatt Macy		# This small piece shamelessly adapted from PostgreSQL python macro;
257eda14cbcSMatt Macy		# credits goes to momjian, I think. I'd like to put the right name
258eda14cbcSMatt Macy		# in the credits, if someone can point me in the right direction... ?
259eda14cbcSMatt Macy		#
260eda14cbcSMatt Macy		if test -n "$ac_python_libdir" -a -n "$ac_python_library"
261eda14cbcSMatt Macy		then
262eda14cbcSMatt Macy			# use the official shared library
263eda14cbcSMatt Macy			ac_python_library=`echo "$ac_python_library" | sed "s/^lib//"`
264eda14cbcSMatt Macy			PYTHON_LIBS="-L$ac_python_libdir -l$ac_python_library"
265eda14cbcSMatt Macy		else
266eda14cbcSMatt Macy			# old way: use libpython from python_configdir
267eda14cbcSMatt Macy			ac_python_libdir=`$PYTHON -c \
268eda14cbcSMatt Macy			  "from distutils.sysconfig import get_python_lib as f; \
269eda14cbcSMatt Macy			  import os; \
270eda14cbcSMatt Macy			  print (os.path.join(f(plat_specific=1, standard_lib=1), 'config'));"`
271eda14cbcSMatt Macy			PYTHON_LIBS="-L$ac_python_libdir -lpython$ac_python_version"
272eda14cbcSMatt Macy		fi
273eda14cbcSMatt Macy
274eda14cbcSMatt Macy		if test -z "PYTHON_LIBS"; then
275eda14cbcSMatt Macy			m4_ifvaln([$2],[$2],[
276eda14cbcSMatt Macy				AC_MSG_ERROR([
277eda14cbcSMatt Macy  Cannot determine location of your Python DSO. Please check it was installed with
278eda14cbcSMatt Macy  dynamic libraries enabled, or try setting PYTHON_LIBS by hand.
279eda14cbcSMatt Macy				])
280eda14cbcSMatt Macy			])
281eda14cbcSMatt Macy		fi
282eda14cbcSMatt Macy	fi
283eda14cbcSMatt Macy	AC_MSG_RESULT([$PYTHON_LIBS])
284eda14cbcSMatt Macy	AC_SUBST([PYTHON_LIBS])
285eda14cbcSMatt Macy
286eda14cbcSMatt Macy	#
287eda14cbcSMatt Macy	# Check for site packages
288eda14cbcSMatt Macy	#
289eda14cbcSMatt Macy	AC_MSG_CHECKING([for Python site-packages path])
290eda14cbcSMatt Macy	if test -z "$PYTHON_SITE_PKG"; then
291eda14cbcSMatt Macy		PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
292eda14cbcSMatt Macy			print (distutils.sysconfig.get_python_lib(0,0));"`
293eda14cbcSMatt Macy	fi
294eda14cbcSMatt Macy	AC_MSG_RESULT([$PYTHON_SITE_PKG])
295eda14cbcSMatt Macy	AC_SUBST([PYTHON_SITE_PKG])
296eda14cbcSMatt Macy
297eda14cbcSMatt Macy	#
298eda14cbcSMatt Macy	# libraries which must be linked in when embedding
299eda14cbcSMatt Macy	#
300eda14cbcSMatt Macy	AC_MSG_CHECKING(python extra libraries)
301eda14cbcSMatt Macy	if test -z "$PYTHON_EXTRA_LIBS"; then
302eda14cbcSMatt Macy	   PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
303eda14cbcSMatt Macy                conf = distutils.sysconfig.get_config_var; \
304eda14cbcSMatt Macy                print (conf('LIBS') + ' ' + conf('SYSLIBS'))"`
305eda14cbcSMatt Macy	fi
306eda14cbcSMatt Macy	AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
307eda14cbcSMatt Macy	AC_SUBST(PYTHON_EXTRA_LIBS)
308eda14cbcSMatt Macy
309eda14cbcSMatt Macy	#
310eda14cbcSMatt Macy	# linking flags needed when embedding
311eda14cbcSMatt Macy	#
312eda14cbcSMatt Macy	AC_MSG_CHECKING(python extra linking flags)
313eda14cbcSMatt Macy	if test -z "$PYTHON_EXTRA_LDFLAGS"; then
314eda14cbcSMatt Macy		PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
315eda14cbcSMatt Macy			conf = distutils.sysconfig.get_config_var; \
316eda14cbcSMatt Macy			print (conf('LINKFORSHARED'))"`
317eda14cbcSMatt Macy	fi
318eda14cbcSMatt Macy	AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
319eda14cbcSMatt Macy	AC_SUBST(PYTHON_EXTRA_LDFLAGS)
320eda14cbcSMatt Macy
321eda14cbcSMatt Macy	#
322eda14cbcSMatt Macy	# final check to see if everything compiles alright
323eda14cbcSMatt Macy	#
324eda14cbcSMatt Macy	AC_MSG_CHECKING([consistency of all components of python development environment])
325eda14cbcSMatt Macy	# save current global flags
326eda14cbcSMatt Macy	ac_save_LIBS="$LIBS"
327eda14cbcSMatt Macy	ac_save_LDFLAGS="$LDFLAGS"
328eda14cbcSMatt Macy	ac_save_CPPFLAGS="$CPPFLAGS"
329eda14cbcSMatt Macy	LIBS="$ac_save_LIBS $PYTHON_LIBS $PYTHON_EXTRA_LIBS $PYTHON_EXTRA_LIBS"
330eda14cbcSMatt Macy	LDFLAGS="$ac_save_LDFLAGS $PYTHON_EXTRA_LDFLAGS"
331eda14cbcSMatt Macy	CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
332eda14cbcSMatt Macy	AC_LANG_PUSH([C])
333eda14cbcSMatt Macy	AC_LINK_IFELSE([
334eda14cbcSMatt Macy		AC_LANG_PROGRAM([[#include <Python.h>]],
335eda14cbcSMatt Macy				[[Py_Initialize();]])
336eda14cbcSMatt Macy		],[pythonexists=yes],[pythonexists=no])
337eda14cbcSMatt Macy	AC_LANG_POP([C])
338eda14cbcSMatt Macy	# turn back to default flags
339eda14cbcSMatt Macy	CPPFLAGS="$ac_save_CPPFLAGS"
340eda14cbcSMatt Macy	LIBS="$ac_save_LIBS"
341eda14cbcSMatt Macy	LDFLAGS="$ac_save_LDFLAGS"
342eda14cbcSMatt Macy
343eda14cbcSMatt Macy	AC_MSG_RESULT([$pythonexists])
344eda14cbcSMatt Macy
345eda14cbcSMatt Macy        if test ! "x$pythonexists" = "xyes"; then
346eda14cbcSMatt Macy		m4_ifvaln([$2],[$2],[
347eda14cbcSMatt Macy			AC_MSG_FAILURE([
348eda14cbcSMatt Macy  Could not link test program to Python. Maybe the main Python library has been
349eda14cbcSMatt Macy  installed in some non-standard library path. If so, pass it to configure,
350eda14cbcSMatt Macy  via the LIBS environment variable.
351eda14cbcSMatt Macy  Example: ./configure LIBS="-L/usr/non-standard-path/python/lib"
352eda14cbcSMatt Macy  ============================================================================
353eda14cbcSMatt Macy   ERROR!
354eda14cbcSMatt Macy   You probably have to install the development version of the Python package
355eda14cbcSMatt Macy   for your distribution.  The exact name of this package varies among them.
356eda14cbcSMatt Macy  ============================================================================
357eda14cbcSMatt Macy	   ])
358eda14cbcSMatt Macy			PYTHON_VERSION=""
359eda14cbcSMatt Macy		])
360eda14cbcSMatt Macy	fi
361eda14cbcSMatt Macy
362eda14cbcSMatt Macy	#
363eda14cbcSMatt Macy	# all done!
364eda14cbcSMatt Macy	#
365eda14cbcSMatt Macy])
366