Blame m4/ax_python_devel.m4

Packit Service 672cf4
# ===========================================================================
Packit Service 6c01f9
#      http://www.gnu.org/software/autoconf-archive/ax_python_devel.html
Packit Service 672cf4
# ===========================================================================
Packit Service 672cf4
#
Packit Service 672cf4
# SYNOPSIS
Packit Service 672cf4
#
Packit Service 672cf4
#   AX_PYTHON_DEVEL([version])
Packit Service 672cf4
#
Packit Service 672cf4
# DESCRIPTION
Packit Service 672cf4
#
Packit Service 672cf4
#   Note: Defines as a precious variable "PYTHON_VERSION". Don't override it
Packit Service 672cf4
#   in your configure.ac.
Packit Service 672cf4
#
Packit Service 672cf4
#   This macro checks for Python and tries to get the include path to
Packit Service 672cf4
#   'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LDFLAGS)
Packit Service 672cf4
#   output variables. It also exports $(PYTHON_EXTRA_LIBS) and
Packit Service 672cf4
#   $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code.
Packit Service 672cf4
#
Packit Service 672cf4
#   You can search for some particular version of Python by passing a
Packit Service 672cf4
#   parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". Please
Packit Service 672cf4
#   note that you *have* to pass also an operator along with the version to
Packit Service 672cf4
#   match, and pay special attention to the single quotes surrounding the
Packit Service 672cf4
#   version number. Don't use "PYTHON_VERSION" for this: that environment
Packit Service 672cf4
#   variable is declared as precious and thus reserved for the end-user.
Packit Service 672cf4
#
Packit Service 672cf4
#   This macro should work for all versions of Python >= 2.1.0. As an end
Packit Service 672cf4
#   user, you can disable the check for the python version by setting the
Packit Service 672cf4
#   PYTHON_NOVERSIONCHECK environment variable to something else than the
Packit Service 672cf4
#   empty string.
Packit Service 672cf4
#
Packit Service 672cf4
#   If you need to use this macro for an older Python version, please
Packit Service 672cf4
#   contact the authors. We're always open for feedback.
Packit Service 672cf4
#
Packit Service 672cf4
# LICENSE
Packit Service 672cf4
#
Packit Service 672cf4
#   Copyright (c) 2009 Sebastian Huber <sebastian-huber@web.de>
Packit Service 672cf4
#   Copyright (c) 2009 Alan W. Irwin
Packit Service 672cf4
#   Copyright (c) 2009 Rafael Laboissiere <rafael@laboissiere.net>
Packit Service 672cf4
#   Copyright (c) 2009 Andrew Collier
Packit Service 672cf4
#   Copyright (c) 2009 Matteo Settenvini <matteo@member.fsf.org>
Packit Service 672cf4
#   Copyright (c) 2009 Horst Knorr <hk_classes@knoda.org>
Packit Service 672cf4
#   Copyright (c) 2013 Daniel Mullner <muellner@math.stanford.edu>
Packit Service 672cf4
#
Packit Service 672cf4
#   This program is free software: you can redistribute it and/or modify it
Packit Service 672cf4
#   under the terms of the GNU General Public License as published by the
Packit Service 672cf4
#   Free Software Foundation, either version 3 of the License, or (at your
Packit Service 672cf4
#   option) any later version.
Packit Service 672cf4
#
Packit Service 672cf4
#   This program is distributed in the hope that it will be useful, but
Packit Service 672cf4
#   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 672cf4
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Packit Service 672cf4
#   Public License for more details.
Packit Service 672cf4
#
Packit Service 672cf4
#   You should have received a copy of the GNU General Public License along
Packit Service 6c01f9
#   with this program. If not, see <http://www.gnu.org/licenses/>.
Packit Service 672cf4
#
Packit Service 672cf4
#   As a special exception, the respective Autoconf Macro's copyright owner
Packit Service 672cf4
#   gives unlimited permission to copy, distribute and modify the configure
Packit Service 672cf4
#   scripts that are the output of Autoconf when processing the Macro. You
Packit Service 672cf4
#   need not follow the terms of the GNU General Public License when using
Packit Service 672cf4
#   or distributing such scripts, even though portions of the text of the
Packit Service 672cf4
#   Macro appear in them. The GNU General Public License (GPL) does govern
Packit Service 672cf4
#   all other use of the material that constitutes the Autoconf Macro.
Packit Service 672cf4
#
Packit Service 672cf4
#   This special exception to the GPL applies to versions of the Autoconf
Packit Service 672cf4
#   Macro released by the Autoconf Archive. When you make and distribute a
Packit Service 672cf4
#   modified version of the Autoconf Macro, you may extend this special
Packit Service 672cf4
#   exception to the GPL to apply to your modified version as well.
Packit Service 672cf4
Packit Service 672cf4
#serial 17
Packit Service 672cf4
Packit Service 672cf4
AU_ALIAS([AC_PYTHON_DEVEL], [AX_PYTHON_DEVEL])
Packit Service 672cf4
AC_DEFUN([AX_PYTHON_DEVEL],[
Packit Service 672cf4
	#
Packit Service 672cf4
	# Allow the use of a (user set) custom python version
Packit Service 672cf4
	#
Packit Service 672cf4
	AC_ARG_VAR([PYTHON_VERSION],[The installed Python
Packit Service 672cf4
		version to use, for example '2.3'. This string
Packit Service 672cf4
		will be appended to the Python interpreter
Packit Service 672cf4
		canonical name.])
Packit Service 672cf4
Packit Service 672cf4
	AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]])
Packit Service 672cf4
	if test -z "$PYTHON"; then
Packit Service 672cf4
	   AC_MSG_ERROR([Cannot find python$PYTHON_VERSION in your system path])
Packit Service 672cf4
	   PYTHON_VERSION=""
Packit Service 672cf4
	fi
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# Check for a version of Python >= 2.1.0
Packit Service 672cf4
	#
Packit Service 672cf4
	AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
Packit Service 672cf4
	ac_supports_python_ver=`$PYTHON -c "import sys; \
Packit Service 672cf4
		ver = sys.version.split ()[[0]]; \
Packit Service 672cf4
		print (ver >= '2.1.0')"`
Packit Service 672cf4
	if test "$ac_supports_python_ver" != "True"; then
Packit Service 672cf4
		if test -z "$PYTHON_NOVERSIONCHECK"; then
Packit Service 672cf4
			AC_MSG_RESULT([no])
Packit Service 672cf4
			AC_MSG_FAILURE([
Packit Service 672cf4
This version of the AC@&t@_PYTHON_DEVEL macro
Packit Service 672cf4
doesn't work properly with versions of Python before
Packit Service 672cf4
2.1.0. You may need to re-run configure, setting the
Packit Service 672cf4
variables PYTHON_CPPFLAGS, PYTHON_LDFLAGS, PYTHON_SITE_PKG,
Packit Service 672cf4
PYTHON_EXTRA_LIBS and PYTHON_EXTRA_LDFLAGS by hand.
Packit Service 672cf4
Moreover, to disable this check, set PYTHON_NOVERSIONCHECK
Packit Service 672cf4
to something else than an empty string.
Packit Service 672cf4
])
Packit Service 672cf4
		else
Packit Service 672cf4
			AC_MSG_RESULT([skip at user request])
Packit Service 672cf4
		fi
Packit Service 672cf4
	else
Packit Service 672cf4
		AC_MSG_RESULT([yes])
Packit Service 672cf4
	fi
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# if the macro parameter ``version'' is set, honour it
Packit Service 672cf4
	#
Packit Service 672cf4
	if test -n "$1"; then
Packit Service 672cf4
		AC_MSG_CHECKING([for a version of Python $1])
Packit Service 672cf4
		ac_supports_python_ver=`$PYTHON -c "import sys; \
Packit Service 672cf4
			ver = sys.version.split ()[[0]]; \
Packit Service 672cf4
			print (ver $1)"`
Packit Service 672cf4
		if test "$ac_supports_python_ver" = "True"; then
Packit Service 672cf4
		   AC_MSG_RESULT([yes])
Packit Service 672cf4
		else
Packit Service 672cf4
			AC_MSG_RESULT([no])
Packit Service 672cf4
			AC_MSG_ERROR([this package requires Python $1.
Packit Service 672cf4
If you have it installed, but it isn't the default Python
Packit Service 672cf4
interpreter in your system path, please pass the PYTHON_VERSION
Packit Service 672cf4
variable to configure. See ``configure --help'' for reference.
Packit Service 672cf4
])
Packit Service 672cf4
			PYTHON_VERSION=""
Packit Service 672cf4
		fi
Packit Service 672cf4
	fi
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# Check if you have distutils, else fail
Packit Service 672cf4
	#
Packit Service 672cf4
	AC_MSG_CHECKING([for the distutils Python package])
Packit Service 672cf4
	ac_distutils_result=`$PYTHON -c "import distutils" 2>&1`
Packit Service 6c01f9
	if test -z "$ac_distutils_result"; then
Packit Service 672cf4
		AC_MSG_RESULT([yes])
Packit Service 672cf4
	else
Packit Service 672cf4
		AC_MSG_RESULT([no])
Packit Service 672cf4
		AC_MSG_ERROR([cannot import Python module "distutils".
Packit Service 672cf4
Please check your Python installation. The error was:
Packit Service 672cf4
$ac_distutils_result])
Packit Service 672cf4
		PYTHON_VERSION=""
Packit Service 672cf4
	fi
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# Check for Python include path
Packit Service 672cf4
	#
Packit Service 672cf4
	AC_MSG_CHECKING([for Python include path])
Packit Service 672cf4
	if test -z "$PYTHON_CPPFLAGS"; then
Packit Service 672cf4
		python_path=`$PYTHON -c "import distutils.sysconfig; \
Packit Service 672cf4
			print (distutils.sysconfig.get_python_inc ());"`
Packit Service 672cf4
		plat_python_path=`$PYTHON -c "import distutils.sysconfig; \
Packit Service 672cf4
			print (distutils.sysconfig.get_python_inc (plat_specific=1));"`
Packit Service 672cf4
		if test -n "${python_path}"; then
Packit Service 672cf4
			if test "${plat_python_path}" != "${python_path}"; then
Packit Service 672cf4
				python_path="-I$python_path -I$plat_python_path"
Packit Service 672cf4
			else
Packit Service 672cf4
				python_path="-I$python_path"
Packit Service 672cf4
			fi
Packit Service 672cf4
		fi
Packit Service 672cf4
		PYTHON_CPPFLAGS=$python_path
Packit Service 672cf4
	fi
Packit Service 672cf4
	AC_MSG_RESULT([$PYTHON_CPPFLAGS])
Packit Service 672cf4
	AC_SUBST([PYTHON_CPPFLAGS])
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# Check for Python library path
Packit Service 672cf4
	#
Packit Service 672cf4
	AC_MSG_CHECKING([for Python library path])
Packit Service 672cf4
	if test -z "$PYTHON_LDFLAGS"; then
Packit Service 672cf4
		# (makes two attempts to ensure we've got a version number
Packit Service 672cf4
		# from the interpreter)
Packit Service 672cf4
		ac_python_version=`cat<
Packit Service 672cf4
Packit Service 672cf4
# join all versioning strings, on some systems
Packit Service 672cf4
# major/minor numbers could be in different list elements
Packit Service 672cf4
from distutils.sysconfig import *
Packit Service 672cf4
e = get_config_var('VERSION')
Packit Service 672cf4
if e is not None:
Packit Service 672cf4
	print(e)
Packit Service 672cf4
EOD`
Packit Service 672cf4
Packit Service 672cf4
		if test -z "$ac_python_version"; then
Packit Service 672cf4
			if test -n "$PYTHON_VERSION"; then
Packit Service 672cf4
				ac_python_version=$PYTHON_VERSION
Packit Service 672cf4
			else
Packit Service 672cf4
				ac_python_version=`$PYTHON -c "import sys; \
Packit Service 672cf4
					print (sys.version[[:3]])"`
Packit Service 672cf4
			fi
Packit Service 672cf4
		fi
Packit Service 672cf4
Packit Service 672cf4
		# Make the versioning information available to the compiler
Packit Service 672cf4
Packit Service 672cf4
		# JW: We don't need it and it interferes with the hack
Packit Service 672cf4
		# to detect multiple Pyhton versions
Packit Service 672cf4
		#AC_DEFINE_UNQUOTED([HAVE_PYTHON], ["$ac_python_version"],
Packit Service 672cf4
                #                  [If available, contains the Python version number currently in use.])
Packit Service 672cf4
Packit Service 672cf4
		# First, the library directory:
Packit Service 672cf4
		ac_python_libdir=`cat<
Packit Service 672cf4
Packit Service 672cf4
# There should be only one
Packit Service 672cf4
import distutils.sysconfig
Packit Service 672cf4
e = distutils.sysconfig.get_config_var('LIBDIR')
Packit Service 672cf4
if e is not None:
Packit Service 672cf4
	print (e)
Packit Service 672cf4
EOD`
Packit Service 672cf4
Packit Service 672cf4
		# Now, for the library:
Packit Service 672cf4
		ac_python_library=`cat<
Packit Service 672cf4
Packit Service 672cf4
import distutils.sysconfig
Packit Service 672cf4
c = distutils.sysconfig.get_config_vars()
Packit Service 672cf4
if 'LDVERSION' in c:
Packit Service 672cf4
	print ('python'+c[['LDVERSION']])
Packit Service 672cf4
else:
Packit Service 672cf4
	print ('python'+c[['VERSION']])
Packit Service 672cf4
EOD`
Packit Service 672cf4
Packit Service 672cf4
		# This small piece shamelessly adapted from PostgreSQL python macro;
Packit Service 672cf4
		# credits goes to momjian, I think. I'd like to put the right name
Packit Service 672cf4
		# in the credits, if someone can point me in the right direction... ?
Packit Service 672cf4
		#
Packit Service 672cf4
		if test -n "$ac_python_libdir" -a -n "$ac_python_library"
Packit Service 672cf4
		then
Packit Service 672cf4
			# use the official shared library
Packit Service 672cf4
			ac_python_library=`echo "$ac_python_library" | sed "s/^lib//"`
Packit Service 672cf4
			PYTHON_LDFLAGS="-L$ac_python_libdir -l$ac_python_library"
Packit Service 672cf4
		else
Packit Service 672cf4
			# old way: use libpython from python_configdir
Packit Service 672cf4
			ac_python_libdir=`$PYTHON -c \
Packit Service 672cf4
			  "from distutils.sysconfig import get_python_lib as f; \
Packit Service 672cf4
			  import os; \
Packit Service 672cf4
			  print (os.path.join(f(plat_specific=1, standard_lib=1), 'config'));"`
Packit Service 672cf4
			PYTHON_LDFLAGS="-L$ac_python_libdir -lpython$ac_python_version"
Packit Service 672cf4
		fi
Packit Service 672cf4
Packit Service 672cf4
		if test -z "PYTHON_LDFLAGS"; then
Packit Service 672cf4
			AC_MSG_ERROR([
Packit Service 672cf4
  Cannot determine location of your Python DSO. Please check it was installed with
Packit Service 672cf4
  dynamic libraries enabled, or try setting PYTHON_LDFLAGS by hand.
Packit Service 672cf4
			])
Packit Service 672cf4
		fi
Packit Service 672cf4
	fi
Packit Service 672cf4
	AC_MSG_RESULT([$PYTHON_LDFLAGS])
Packit Service 672cf4
	AC_SUBST([PYTHON_LDFLAGS])
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# Check for site packages
Packit Service 672cf4
	#
Packit Service 672cf4
	AC_MSG_CHECKING([for Python site-packages path])
Packit Service 672cf4
	if test -z "$PYTHON_SITE_PKG"; then
Packit Service 672cf4
		PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
Packit Service 672cf4
			print (distutils.sysconfig.get_python_lib(0,0));"`
Packit Service 672cf4
	fi
Packit Service 672cf4
	AC_MSG_RESULT([$PYTHON_SITE_PKG])
Packit Service 672cf4
	AC_SUBST([PYTHON_SITE_PKG])
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# libraries which must be linked in when embedding
Packit Service 672cf4
	#
Packit Service 672cf4
	AC_MSG_CHECKING(python extra libraries)
Packit Service 672cf4
	if test -z "$PYTHON_EXTRA_LIBS"; then
Packit Service 672cf4
	   PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
Packit Service 672cf4
                conf = distutils.sysconfig.get_config_var; \
Packit Service 672cf4
                print (conf('LIBS') + ' ' + conf('SYSLIBS'))"`
Packit Service 672cf4
	fi
Packit Service 672cf4
	AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
Packit Service 672cf4
	AC_SUBST(PYTHON_EXTRA_LIBS)
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# linking flags needed when embedding
Packit Service 672cf4
	#
Packit Service 672cf4
	AC_MSG_CHECKING(python extra linking flags)
Packit Service 672cf4
	if test -z "$PYTHON_EXTRA_LDFLAGS"; then
Packit Service 672cf4
		PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
Packit Service 672cf4
			conf = distutils.sysconfig.get_config_var; \
Packit Service 672cf4
			print (conf('LINKFORSHARED'))"`
Packit Service 672cf4
	fi
Packit Service 672cf4
	AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
Packit Service 672cf4
	AC_SUBST(PYTHON_EXTRA_LDFLAGS)
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# final check to see if everything compiles alright
Packit Service 672cf4
	#
Packit Service 672cf4
	AC_MSG_CHECKING([consistency of all components of python development environment])
Packit Service 672cf4
	# save current global flags
Packit Service 672cf4
	ac_save_LIBS="$LIBS"
Packit Service 672cf4
	ac_save_CPPFLAGS="$CPPFLAGS"
Packit Service 672cf4
	LIBS="$ac_save_LIBS $PYTHON_LDFLAGS $PYTHON_EXTRA_LDFLAGS $PYTHON_EXTRA_LIBS"
Packit Service 672cf4
	CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
Packit Service 672cf4
	AC_LANG_PUSH([C])
Packit Service 672cf4
	AC_LINK_IFELSE([
Packit Service 672cf4
		AC_LANG_PROGRAM([[#include <Python.h>]],
Packit Service 672cf4
				[[Py_Initialize();]])
Packit Service 672cf4
		],[pythonexists=yes],[pythonexists=no])
Packit Service 672cf4
	AC_LANG_POP([C])
Packit Service 672cf4
	# turn back to default flags
Packit Service 672cf4
	CPPFLAGS="$ac_save_CPPFLAGS"
Packit Service 672cf4
	LIBS="$ac_save_LIBS"
Packit Service 672cf4
Packit Service 672cf4
	AC_MSG_RESULT([$pythonexists])
Packit Service 672cf4
Packit Service 672cf4
        if test ! "x$pythonexists" = "xyes"; then
Packit Service 672cf4
	   AC_MSG_WARN([
Packit Service 672cf4
  Could not link test program to Python. Maybe the main Python library has been
Packit Service 672cf4
  installed in some non-standard library path. If so, pass it to configure,
Packit Service 672cf4
  via the LDFLAGS environment variable.
Packit Service 672cf4
  Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
Packit Service 672cf4
  ============================================================================
Packit Service 672cf4
   You probably have to install the development version of the Python package
Packit Service 672cf4
   for your distribution.  The exact name of this package varies among them.
Packit Service 672cf4
  ============================================================================
Packit Service 672cf4
	   ])
Packit Service 672cf4
	  PYTHON_VERSION=""
Packit Service 672cf4
	fi
Packit Service 672cf4
Packit Service 672cf4
	#
Packit Service 672cf4
	# all done!
Packit Service 672cf4
	#
Packit Service 672cf4
])