2000-06-11 02:02:12 +08:00
|
|
|
#
|
|
|
|
# Autoconf macros for configuring the build of Python extension modules
|
|
|
|
#
|
2010-09-21 04:08:53 +08:00
|
|
|
# config/python.m4
|
2000-06-11 02:02:12 +08:00
|
|
|
#
|
|
|
|
|
2001-05-13 01:49:32 +08:00
|
|
|
# PGAC_PATH_PYTHON
|
2000-06-11 02:02:12 +08:00
|
|
|
# ----------------
|
2002-03-30 01:32:55 +08:00
|
|
|
# Look for Python and set the output variable 'PYTHON'
|
|
|
|
# to 'python' if found, empty otherwise.
|
2001-05-13 01:49:32 +08:00
|
|
|
AC_DEFUN([PGAC_PATH_PYTHON],
|
|
|
|
[AC_PATH_PROG(PYTHON, python)
|
|
|
|
if test x"$PYTHON" = x""; then
|
|
|
|
AC_MSG_ERROR([Python not found])
|
|
|
|
fi
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
# _PGAC_CHECK_PYTHON_DIRS
|
|
|
|
# -----------------------
|
2004-10-12 03:32:19 +08:00
|
|
|
# Determine the name of various directories of a given Python installation.
|
2001-05-13 01:49:32 +08:00
|
|
|
AC_DEFUN([_PGAC_CHECK_PYTHON_DIRS],
|
|
|
|
[AC_REQUIRE([PGAC_PATH_PYTHON])
|
2004-09-17 07:30:30 +08:00
|
|
|
AC_MSG_CHECKING([for Python distutils module])
|
2009-10-15 05:59:15 +08:00
|
|
|
if "${PYTHON}" -c 'import distutils' 2>&AS_MESSAGE_LOG_FD
|
2004-09-17 07:30:30 +08:00
|
|
|
then
|
|
|
|
AC_MSG_RESULT(yes)
|
|
|
|
else
|
|
|
|
AC_MSG_RESULT(no)
|
|
|
|
AC_MSG_ERROR([distutils module not found])
|
|
|
|
fi
|
2004-10-11 03:07:55 +08:00
|
|
|
AC_MSG_CHECKING([Python configuration directory])
|
2009-12-16 06:59:55 +08:00
|
|
|
python_majorversion=`${PYTHON} -c "import sys; print(sys.version[[0]])"`
|
2009-01-04 08:54:15 +08:00
|
|
|
python_version=`${PYTHON} -c "import sys; print(sys.version[[:3]])"`
|
2011-11-29 12:50:11 +08:00
|
|
|
python_configdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBPL'))))"`
|
2012-08-30 10:44:59 +08:00
|
|
|
AC_MSG_RESULT([$python_configdir])
|
|
|
|
|
|
|
|
AC_MSG_CHECKING([Python include directories])
|
|
|
|
python_includespec=`${PYTHON} -c "
|
|
|
|
import distutils.sysconfig
|
|
|
|
a = '-I' + distutils.sysconfig.get_python_inc(False)
|
|
|
|
b = '-I' + distutils.sysconfig.get_python_inc(True)
|
|
|
|
if a == b:
|
|
|
|
print(a)
|
|
|
|
else:
|
|
|
|
print(a + ' ' + b)"`
|
|
|
|
AC_MSG_RESULT([$python_includespec])
|
2001-05-13 01:49:32 +08:00
|
|
|
|
2009-12-16 06:59:55 +08:00
|
|
|
AC_SUBST(python_majorversion)[]dnl
|
2004-10-11 03:07:55 +08:00
|
|
|
AC_SUBST(python_version)[]dnl
|
2001-07-11 00:33:02 +08:00
|
|
|
AC_SUBST(python_includespec)[]dnl
|
2001-05-13 01:49:32 +08:00
|
|
|
])# _PGAC_CHECK_PYTHON_DIRS
|
2000-06-11 02:02:12 +08:00
|
|
|
|
|
|
|
|
2001-05-13 01:49:32 +08:00
|
|
|
# PGAC_CHECK_PYTHON_EMBED_SETUP
|
|
|
|
# -----------------------------
|
2004-10-12 03:32:19 +08:00
|
|
|
#
|
|
|
|
# Note: selecting libpython from python_configdir works in all Python
|
|
|
|
# releases, but it generally finds a non-shared library, which means
|
|
|
|
# that we are binding the python interpreter right into libplpython.so.
|
|
|
|
# In Python 2.3 and up there should be a shared library available in
|
|
|
|
# the main library location.
|
2001-05-13 01:49:32 +08:00
|
|
|
AC_DEFUN([PGAC_CHECK_PYTHON_EMBED_SETUP],
|
|
|
|
[AC_REQUIRE([_PGAC_CHECK_PYTHON_DIRS])
|
|
|
|
AC_MSG_CHECKING([how to link an embedded Python application])
|
|
|
|
|
2011-11-29 12:50:11 +08:00
|
|
|
python_libdir=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBDIR'))))"`
|
|
|
|
python_ldlibrary=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDLIBRARY'))))"`
|
|
|
|
python_so=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('SO'))))"`
|
2004-10-12 03:32:19 +08:00
|
|
|
ldlibrary=`echo "${python_ldlibrary}" | sed "s/${python_so}$//"`
|
2013-01-05 21:56:14 +08:00
|
|
|
python_enable_shared=`${PYTHON} -c "import distutils.sysconfig; print(distutils.sysconfig.get_config_vars().get('Py_ENABLE_SHARED',0))"`
|
2004-10-12 03:32:19 +08:00
|
|
|
|
On OS X, link libpython normally, ignoring the "framework" framework.
As of Xcode 5.0, Apple isn't including the Python framework as part of the
SDK-level files, which means that linking to it might fail depending on
whether Xcode thinks you've selected a specific SDK version. According to
their Tech Note 2328, they've basically deprecated the framework method of
linking to libpython and are telling people to link to the shared library
normally. (I'm pretty sure this is in direct contradiction to the advice
they were giving a few years ago, but whatever.) Testing says that this
approach works fine at least as far back as OS X 10.4.11, so let's just
rip out the framework special case entirely. We do still need a special
case to decide that OS X provides a shared library at all, unfortunately
(I wonder why the distutils check doesn't work ...). But this is still
less of a special case than before, so it's fine.
Back-patch to all supported branches, since we'll doubtless be hearing
about this more as more people update to recent Xcode.
2014-05-31 06:18:14 +08:00
|
|
|
if test x"${python_libdir}" != x"" -a x"${python_ldlibrary}" != x"" -a x"${python_ldlibrary}" != x"${ldlibrary}"
|
2004-10-12 03:32:19 +08:00
|
|
|
then
|
|
|
|
# New way: use the official shared library
|
|
|
|
ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"`
|
|
|
|
python_libspec="-L${python_libdir} -l${ldlibrary}"
|
|
|
|
else
|
|
|
|
# Old way: use libpython from python_configdir
|
|
|
|
python_libdir="${python_configdir}"
|
2011-08-18 19:43:16 +08:00
|
|
|
# LDVERSION was introduced in Python 3.2.
|
2011-11-29 12:50:11 +08:00
|
|
|
python_ldversion=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LDVERSION'))))"`
|
2011-08-18 19:43:16 +08:00
|
|
|
if test x"${python_ldversion}" = x""; then
|
|
|
|
python_ldversion=$python_version
|
|
|
|
fi
|
|
|
|
python_libspec="-L${python_libdir} -lpython${python_ldversion}"
|
2004-10-12 03:32:19 +08:00
|
|
|
fi
|
|
|
|
|
On OS X, link libpython normally, ignoring the "framework" framework.
As of Xcode 5.0, Apple isn't including the Python framework as part of the
SDK-level files, which means that linking to it might fail depending on
whether Xcode thinks you've selected a specific SDK version. According to
their Tech Note 2328, they've basically deprecated the framework method of
linking to libpython and are telling people to link to the shared library
normally. (I'm pretty sure this is in direct contradiction to the advice
they were giving a few years ago, but whatever.) Testing says that this
approach works fine at least as far back as OS X 10.4.11, so let's just
rip out the framework special case entirely. We do still need a special
case to decide that OS X provides a shared library at all, unfortunately
(I wonder why the distutils check doesn't work ...). But this is still
less of a special case than before, so it's fine.
Back-patch to all supported branches, since we'll doubtless be hearing
about this more as more people update to recent Xcode.
2014-05-31 06:18:14 +08:00
|
|
|
python_additional_libs=`${PYTHON} -c "import distutils.sysconfig; print(' '.join(filter(None,distutils.sysconfig.get_config_vars('LIBS','LIBC','LIBM','BASEMODLIBS'))))"`
|
2001-05-13 01:49:32 +08:00
|
|
|
|
2004-10-12 03:32:19 +08:00
|
|
|
AC_MSG_RESULT([${python_libspec} ${python_additional_libs}])
|
2001-05-13 01:49:32 +08:00
|
|
|
|
2004-10-12 03:32:19 +08:00
|
|
|
AC_SUBST(python_libdir)[]dnl
|
2001-05-13 01:49:32 +08:00
|
|
|
AC_SUBST(python_libspec)[]dnl
|
2004-10-12 03:32:19 +08:00
|
|
|
AC_SUBST(python_additional_libs)[]dnl
|
2013-01-05 21:56:14 +08:00
|
|
|
AC_SUBST(python_enable_shared)[]dnl
|
2005-09-27 00:48:28 +08:00
|
|
|
|
2001-05-13 01:49:32 +08:00
|
|
|
])# PGAC_CHECK_PYTHON_EMBED_SETUP
|