1eda14cbcSMatt Macy# =========================================================================== 2eda14cbcSMatt Macy# https://www.gnu.org/software/autoconf-archive/ax_python_devel.html 3eda14cbcSMatt Macy# =========================================================================== 4eda14cbcSMatt Macy# 5eda14cbcSMatt Macy# SYNOPSIS 6eda14cbcSMatt Macy# 7*b985c9caSMartin Matuska# AX_PYTHON_DEVEL([version[,optional]]) 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# This macro checks for Python and tries to get the include path to 15eda14cbcSMatt Macy# 'Python.h'. It provides the $(PYTHON_CPPFLAGS) and $(PYTHON_LIBS) output 16eda14cbcSMatt Macy# variables. It also exports $(PYTHON_EXTRA_LIBS) and 17eda14cbcSMatt Macy# $(PYTHON_EXTRA_LDFLAGS) for embedding Python in your code. 18eda14cbcSMatt Macy# 19eda14cbcSMatt Macy# You can search for some particular version of Python by passing a 20eda14cbcSMatt Macy# parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". Please 21eda14cbcSMatt Macy# note that you *have* to pass also an operator along with the version to 22eda14cbcSMatt Macy# match, and pay special attention to the single quotes surrounding the 23eda14cbcSMatt Macy# version number. Don't use "PYTHON_VERSION" for this: that environment 24eda14cbcSMatt Macy# variable is declared as precious and thus reserved for the end-user. 25eda14cbcSMatt Macy# 26*b985c9caSMartin Matuska# By default this will fail if it does not detect a development version of 27*b985c9caSMartin Matuska# python. If you want it to continue, set optional to true, like 28*b985c9caSMartin Matuska# AX_PYTHON_DEVEL([], [true]). The ax_python_devel_found variable will be 29*b985c9caSMartin Matuska# "no" if it fails. 30*b985c9caSMartin Matuska# 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# 49eda14cbcSMatt Macy# This program is free software: you can redistribute it and/or modify it 50eda14cbcSMatt Macy# under the terms of the GNU General Public License as published by the 51eda14cbcSMatt Macy# Free Software Foundation, either version 3 of the License, or (at your 52eda14cbcSMatt Macy# option) any later version. 53eda14cbcSMatt Macy# 54eda14cbcSMatt Macy# This program is distributed in the hope that it will be useful, but 55eda14cbcSMatt Macy# WITHOUT ANY WARRANTY; without even the implied warranty of 56eda14cbcSMatt Macy# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 57eda14cbcSMatt Macy# Public License for more details. 58eda14cbcSMatt Macy# 59eda14cbcSMatt Macy# You should have received a copy of the GNU General Public License along 60eda14cbcSMatt Macy# with this program. If not, see <https://www.gnu.org/licenses/>. 61eda14cbcSMatt Macy# 62eda14cbcSMatt Macy# As a special exception, the respective Autoconf Macro's copyright owner 63eda14cbcSMatt Macy# gives unlimited permission to copy, distribute and modify the configure 64eda14cbcSMatt Macy# scripts that are the output of Autoconf when processing the Macro. You 65eda14cbcSMatt Macy# need not follow the terms of the GNU General Public License when using 66eda14cbcSMatt Macy# or distributing such scripts, even though portions of the text of the 67eda14cbcSMatt Macy# Macro appear in them. The GNU General Public License (GPL) does govern 68eda14cbcSMatt Macy# all other use of the material that constitutes the Autoconf Macro. 69eda14cbcSMatt Macy# 70eda14cbcSMatt Macy# This special exception to the GPL applies to versions of the Autoconf 71eda14cbcSMatt Macy# Macro released by the Autoconf Archive. When you make and distribute a 72eda14cbcSMatt Macy# modified version of the Autoconf Macro, you may extend this special 73eda14cbcSMatt Macy# exception to the GPL to apply to your modified version as well. 74eda14cbcSMatt Macy 75*b985c9caSMartin Matuska#serial 36 76eda14cbcSMatt Macy 77eda14cbcSMatt MacyAU_ALIAS([AC_PYTHON_DEVEL], [AX_PYTHON_DEVEL]) 78eda14cbcSMatt MacyAC_DEFUN([AX_PYTHON_DEVEL],[ 79*b985c9caSMartin Matuska # Get whether it's optional 80*b985c9caSMartin Matuska if test -z "$2"; then 81*b985c9caSMartin Matuska ax_python_devel_optional=false 82*b985c9caSMartin Matuska else 83*b985c9caSMartin Matuska ax_python_devel_optional=$2 84*b985c9caSMartin Matuska fi 85*b985c9caSMartin Matuska ax_python_devel_found=yes 86*b985c9caSMartin Matuska 87eda14cbcSMatt Macy # 88eda14cbcSMatt Macy # Allow the use of a (user set) custom python version 89eda14cbcSMatt Macy # 90eda14cbcSMatt Macy AC_ARG_VAR([PYTHON_VERSION],[The installed Python 91eda14cbcSMatt Macy version to use, for example '2.3'. This string 92eda14cbcSMatt Macy will be appended to the Python interpreter 93eda14cbcSMatt Macy canonical name.]) 94eda14cbcSMatt Macy 95eda14cbcSMatt Macy AC_PATH_PROG([PYTHON],[python[$PYTHON_VERSION]]) 96eda14cbcSMatt Macy if test -z "$PYTHON"; then 97*b985c9caSMartin Matuska AC_MSG_WARN([Cannot find python$PYTHON_VERSION in your system path]) 98*b985c9caSMartin Matuska if ! $ax_python_devel_optional; then 99*b985c9caSMartin Matuska AC_MSG_ERROR([Giving up, python development not available]) 100*b985c9caSMartin Matuska fi 101*b985c9caSMartin Matuska ax_python_devel_found=no 102eda14cbcSMatt Macy PYTHON_VERSION="" 103eda14cbcSMatt Macy fi 104eda14cbcSMatt Macy 105*b985c9caSMartin Matuska if test $ax_python_devel_found = yes; then 106eda14cbcSMatt Macy # 107eda14cbcSMatt Macy # Check for a version of Python >= 2.1.0 108eda14cbcSMatt Macy # 109eda14cbcSMatt Macy AC_MSG_CHECKING([for a version of Python >= '2.1.0']) 11015f0b8c3SMartin Matuska ac_supports_python_ver=`$PYTHON -c "import sys; \ 11115f0b8c3SMartin Matuska ver = sys.version.split ()[[0]]; \ 11215f0b8c3SMartin Matuska print (ver >= '2.1.0')"` 113eda14cbcSMatt Macy if test "$ac_supports_python_ver" != "True"; then 114eda14cbcSMatt Macy if test -z "$PYTHON_NOVERSIONCHECK"; then 115eda14cbcSMatt Macy AC_MSG_RESULT([no]) 116*b985c9caSMartin Matuska AC_MSG_WARN([ 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]) 125*b985c9caSMartin Matuska if ! $ax_python_devel_optional; then 126*b985c9caSMartin Matuska AC_MSG_FAILURE([Giving up]) 127*b985c9caSMartin Matuska fi 128*b985c9caSMartin Matuska ax_python_devel_found=no 129*b985c9caSMartin Matuska PYTHON_VERSION="" 130eda14cbcSMatt Macy else 131eda14cbcSMatt Macy AC_MSG_RESULT([skip at user request]) 132eda14cbcSMatt Macy fi 133eda14cbcSMatt Macy else 134eda14cbcSMatt Macy AC_MSG_RESULT([yes]) 135eda14cbcSMatt Macy fi 136*b985c9caSMartin Matuska fi 137eda14cbcSMatt Macy 138*b985c9caSMartin Matuska if test $ax_python_devel_found = yes; then 139eda14cbcSMatt Macy # 14015f0b8c3SMartin Matuska # If the macro parameter ``version'' is set, honour it. 14115f0b8c3SMartin Matuska # A Python shim class, VPy, is used to implement correct version comparisons via 14215f0b8c3SMartin Matuska # string expressions, since e.g. a naive textual ">= 2.7.3" won't work for 14315f0b8c3SMartin Matuska # Python 2.7.10 (the ".1" being evaluated as less than ".3"). 144eda14cbcSMatt Macy # 145eda14cbcSMatt Macy if test -n "$1"; then 146eda14cbcSMatt Macy AC_MSG_CHECKING([for a version of Python $1]) 14715f0b8c3SMartin Matuska cat << EOF > ax_python_devel_vpy.py 14815f0b8c3SMartin Matuskaclass VPy: 14915f0b8c3SMartin Matuska def vtup(self, s): 15015f0b8c3SMartin Matuska return tuple(map(int, s.strip().replace("rc", ".").split("."))) 15115f0b8c3SMartin Matuska def __init__(self): 15215f0b8c3SMartin Matuska import sys 153*b985c9caSMartin Matuska self.vpy = tuple(sys.version_info)[[:3]] 15415f0b8c3SMartin Matuska def __eq__(self, s): 15515f0b8c3SMartin Matuska return self.vpy == self.vtup(s) 15615f0b8c3SMartin Matuska def __ne__(self, s): 15715f0b8c3SMartin Matuska return self.vpy != self.vtup(s) 15815f0b8c3SMartin Matuska def __lt__(self, s): 15915f0b8c3SMartin Matuska return self.vpy < self.vtup(s) 16015f0b8c3SMartin Matuska def __gt__(self, s): 16115f0b8c3SMartin Matuska return self.vpy > self.vtup(s) 16215f0b8c3SMartin Matuska def __le__(self, s): 16315f0b8c3SMartin Matuska return self.vpy <= self.vtup(s) 16415f0b8c3SMartin Matuska def __ge__(self, s): 16515f0b8c3SMartin Matuska return self.vpy >= self.vtup(s) 16615f0b8c3SMartin MatuskaEOF 16715f0b8c3SMartin Matuska ac_supports_python_ver=`$PYTHON -c "import ax_python_devel_vpy; \ 16815f0b8c3SMartin Matuska ver = ax_python_devel_vpy.VPy(); \ 16915f0b8c3SMartin Matuska print (ver $1)"` 17015f0b8c3SMartin Matuska rm -rf ax_python_devel_vpy*.py* __pycache__/ax_python_devel_vpy*.py* 171eda14cbcSMatt Macy if test "$ac_supports_python_ver" = "True"; then 172eda14cbcSMatt Macy AC_MSG_RESULT([yes]) 173eda14cbcSMatt Macy else 174eda14cbcSMatt Macy AC_MSG_RESULT([no]) 175*b985c9caSMartin Matuska AC_MSG_WARN([this package requires Python $1. 176eda14cbcSMatt MacyIf you have it installed, but it isn't the default Python 177eda14cbcSMatt Macyinterpreter in your system path, please pass the PYTHON_VERSION 178eda14cbcSMatt Macyvariable to configure. See ``configure --help'' for reference. 179eda14cbcSMatt Macy]) 180*b985c9caSMartin Matuska if ! $ax_python_devel_optional; then 181*b985c9caSMartin Matuska AC_MSG_ERROR([Giving up]) 182*b985c9caSMartin Matuska fi 183*b985c9caSMartin Matuska ax_python_devel_found=no 184eda14cbcSMatt Macy PYTHON_VERSION="" 185eda14cbcSMatt Macy fi 186eda14cbcSMatt Macy fi 187*b985c9caSMartin Matuska fi 188eda14cbcSMatt Macy 189*b985c9caSMartin Matuska if test $ax_python_devel_found = yes; then 190*b985c9caSMartin Matuska # 191*b985c9caSMartin Matuska # Check if you have distutils, else fail 192*b985c9caSMartin Matuska # 193*b985c9caSMartin Matuska AC_MSG_CHECKING([for the sysconfig Python package]) 194*b985c9caSMartin Matuska ac_sysconfig_result=`$PYTHON -c "import sysconfig" 2>&1` 195*b985c9caSMartin Matuska if test $? -eq 0; then 196*b985c9caSMartin Matuska AC_MSG_RESULT([yes]) 197*b985c9caSMartin Matuska IMPORT_SYSCONFIG="import sysconfig" 198*b985c9caSMartin Matuska else 199*b985c9caSMartin Matuska AC_MSG_RESULT([no]) 200*b985c9caSMartin Matuska 201*b985c9caSMartin Matuska AC_MSG_CHECKING([for the distutils Python package]) 202*b985c9caSMartin Matuska ac_sysconfig_result=`$PYTHON -c "from distutils import sysconfig" 2>&1` 203*b985c9caSMartin Matuska if test $? -eq 0; then 204*b985c9caSMartin Matuska AC_MSG_RESULT([yes]) 205*b985c9caSMartin Matuska IMPORT_SYSCONFIG="from distutils import sysconfig" 206*b985c9caSMartin Matuska else 207*b985c9caSMartin Matuska AC_MSG_WARN([cannot import Python module "distutils". 208*b985c9caSMartin MatuskaPlease check your Python installation. The error was: 209*b985c9caSMartin Matuska$ac_sysconfig_result]) 210*b985c9caSMartin Matuska if ! $ax_python_devel_optional; then 211*b985c9caSMartin Matuska AC_MSG_ERROR([Giving up]) 212*b985c9caSMartin Matuska fi 213*b985c9caSMartin Matuska ax_python_devel_found=no 214*b985c9caSMartin Matuska PYTHON_VERSION="" 215*b985c9caSMartin Matuska fi 216*b985c9caSMartin Matuska fi 217*b985c9caSMartin Matuska fi 218*b985c9caSMartin Matuska 219*b985c9caSMartin Matuska if test $ax_python_devel_found = yes; then 220eda14cbcSMatt Macy # 221eda14cbcSMatt Macy # Check for Python include path 222eda14cbcSMatt Macy # 223eda14cbcSMatt Macy AC_MSG_CHECKING([for Python include path]) 224eda14cbcSMatt Macy if test -z "$PYTHON_CPPFLAGS"; then 225*b985c9caSMartin Matuska if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then 226*b985c9caSMartin Matuska # sysconfig module has different functions 227*b985c9caSMartin Matuska python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \ 228bb2d13b6SMartin Matuska print (sysconfig.get_path ('include'));"` 229*b985c9caSMartin Matuska plat_python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \ 230bb2d13b6SMartin Matuska print (sysconfig.get_path ('platinclude'));"` 231*b985c9caSMartin Matuska else 232*b985c9caSMartin Matuska # old distutils way 233*b985c9caSMartin Matuska python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \ 234*b985c9caSMartin Matuska print (sysconfig.get_python_inc ());"` 235*b985c9caSMartin Matuska plat_python_path=`$PYTHON -c "$IMPORT_SYSCONFIG; \ 236*b985c9caSMartin Matuska print (sysconfig.get_python_inc (plat_specific=1));"` 237*b985c9caSMartin Matuska fi 238eda14cbcSMatt Macy if test -n "${python_path}"; then 239eda14cbcSMatt Macy if test "${plat_python_path}" != "${python_path}"; then 240eda14cbcSMatt Macy python_path="-I$python_path -I$plat_python_path" 241eda14cbcSMatt Macy else 242eda14cbcSMatt Macy python_path="-I$python_path" 243eda14cbcSMatt Macy fi 244eda14cbcSMatt Macy fi 245eda14cbcSMatt Macy PYTHON_CPPFLAGS=$python_path 246eda14cbcSMatt Macy fi 247eda14cbcSMatt Macy AC_MSG_RESULT([$PYTHON_CPPFLAGS]) 248eda14cbcSMatt Macy AC_SUBST([PYTHON_CPPFLAGS]) 249eda14cbcSMatt Macy 250eda14cbcSMatt Macy # 251eda14cbcSMatt Macy # Check for Python library path 252eda14cbcSMatt Macy # 253eda14cbcSMatt Macy AC_MSG_CHECKING([for Python library path]) 254eda14cbcSMatt Macy if test -z "$PYTHON_LIBS"; then 255eda14cbcSMatt Macy # (makes two attempts to ensure we've got a version number 256eda14cbcSMatt Macy # from the interpreter) 257eda14cbcSMatt Macy ac_python_version=`cat<<EOD | $PYTHON - 258eda14cbcSMatt Macy 259eda14cbcSMatt Macy# join all versioning strings, on some systems 260eda14cbcSMatt Macy# major/minor numbers could be in different list elements 261bb2d13b6SMartin Matuskafrom sysconfig import * 262eda14cbcSMatt Macye = get_config_var('VERSION') 263eda14cbcSMatt Macyif e is not None: 264eda14cbcSMatt Macy print(e) 265eda14cbcSMatt MacyEOD` 266eda14cbcSMatt Macy 267eda14cbcSMatt Macy if test -z "$ac_python_version"; then 268eda14cbcSMatt Macy if test -n "$PYTHON_VERSION"; then 269eda14cbcSMatt Macy ac_python_version=$PYTHON_VERSION 270eda14cbcSMatt Macy else 271eda14cbcSMatt Macy ac_python_version=`$PYTHON -c "import sys; \ 272*b985c9caSMartin Matuska print ("%d.%d" % sys.version_info[[:2]])"` 273eda14cbcSMatt Macy fi 274eda14cbcSMatt Macy fi 275eda14cbcSMatt Macy 276eda14cbcSMatt Macy # Make the versioning information available to the compiler 277eda14cbcSMatt Macy AC_DEFINE_UNQUOTED([HAVE_PYTHON], ["$ac_python_version"], 278eda14cbcSMatt Macy [If available, contains the Python version number currently in use.]) 279eda14cbcSMatt Macy 280eda14cbcSMatt Macy # First, the library directory: 281eda14cbcSMatt Macy ac_python_libdir=`cat<<EOD | $PYTHON - 282eda14cbcSMatt Macy 283eda14cbcSMatt Macy# There should be only one 284*b985c9caSMartin Matuska$IMPORT_SYSCONFIG 285bb2d13b6SMartin Matuskae = sysconfig.get_config_var('LIBDIR') 286eda14cbcSMatt Macyif e is not None: 287eda14cbcSMatt Macy print (e) 288eda14cbcSMatt MacyEOD` 289eda14cbcSMatt Macy 290eda14cbcSMatt Macy # Now, for the library: 291eda14cbcSMatt Macy ac_python_library=`cat<<EOD | $PYTHON - 292eda14cbcSMatt Macy 293*b985c9caSMartin Matuska$IMPORT_SYSCONFIG 294bb2d13b6SMartin Matuskac = sysconfig.get_config_vars() 295eda14cbcSMatt Macyif 'LDVERSION' in c: 296eda14cbcSMatt Macy print ('python'+c[['LDVERSION']]) 297eda14cbcSMatt Macyelse: 298eda14cbcSMatt Macy print ('python'+c[['VERSION']]) 299eda14cbcSMatt MacyEOD` 300eda14cbcSMatt Macy 301eda14cbcSMatt Macy # This small piece shamelessly adapted from PostgreSQL python macro; 302eda14cbcSMatt Macy # credits goes to momjian, I think. I'd like to put the right name 303eda14cbcSMatt Macy # in the credits, if someone can point me in the right direction... ? 304eda14cbcSMatt Macy # 305eda14cbcSMatt Macy if test -n "$ac_python_libdir" -a -n "$ac_python_library" 306eda14cbcSMatt Macy then 307eda14cbcSMatt Macy # use the official shared library 308eda14cbcSMatt Macy ac_python_library=`echo "$ac_python_library" | sed "s/^lib//"` 309eda14cbcSMatt Macy PYTHON_LIBS="-L$ac_python_libdir -l$ac_python_library" 310eda14cbcSMatt Macy else 311eda14cbcSMatt Macy # old way: use libpython from python_configdir 312eda14cbcSMatt Macy ac_python_libdir=`$PYTHON -c \ 313*b985c9caSMartin Matuska "from sysconfig import get_python_lib as f; \ 314eda14cbcSMatt Macy import os; \ 315*b985c9caSMartin Matuska print (os.path.join(f(plat_specific=1, standard_lib=1), 'config'));"` 316eda14cbcSMatt Macy PYTHON_LIBS="-L$ac_python_libdir -lpython$ac_python_version" 317eda14cbcSMatt Macy fi 318eda14cbcSMatt Macy 319eda14cbcSMatt Macy if test -z "PYTHON_LIBS"; then 320*b985c9caSMartin Matuska AC_MSG_WARN([ 321eda14cbcSMatt Macy Cannot determine location of your Python DSO. Please check it was installed with 322eda14cbcSMatt Macy dynamic libraries enabled, or try setting PYTHON_LIBS by hand. 323eda14cbcSMatt Macy ]) 324*b985c9caSMartin Matuska if ! $ax_python_devel_optional; then 325*b985c9caSMartin Matuska AC_MSG_ERROR([Giving up]) 326*b985c9caSMartin Matuska fi 327*b985c9caSMartin Matuska ax_python_devel_found=no 328*b985c9caSMartin Matuska PYTHON_VERSION="" 329eda14cbcSMatt Macy fi 330eda14cbcSMatt Macy fi 331*b985c9caSMartin Matuska fi 332*b985c9caSMartin Matuska 333*b985c9caSMartin Matuska if test $ax_python_devel_found = yes; then 334eda14cbcSMatt Macy AC_MSG_RESULT([$PYTHON_LIBS]) 335eda14cbcSMatt Macy AC_SUBST([PYTHON_LIBS]) 336eda14cbcSMatt Macy 337eda14cbcSMatt Macy # 338eda14cbcSMatt Macy # Check for site packages 339eda14cbcSMatt Macy # 340eda14cbcSMatt Macy AC_MSG_CHECKING([for Python site-packages path]) 341eda14cbcSMatt Macy if test -z "$PYTHON_SITE_PKG"; then 342*b985c9caSMartin Matuska if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then 343*b985c9caSMartin Matuska PYTHON_SITE_PKG=`$PYTHON -c " 344*b985c9caSMartin Matuska$IMPORT_SYSCONFIG; 345*b985c9caSMartin Matuskaif hasattr(sysconfig, 'get_default_scheme'): 346*b985c9caSMartin Matuska scheme = sysconfig.get_default_scheme() 347*b985c9caSMartin Matuskaelse: 348*b985c9caSMartin Matuska scheme = sysconfig._get_default_scheme() 349*b985c9caSMartin Matuskaif scheme == 'posix_local': 350*b985c9caSMartin Matuska # Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/ 351*b985c9caSMartin Matuska scheme = 'posix_prefix' 352*b985c9caSMartin Matuskaprefix = '$prefix' 353*b985c9caSMartin Matuskaif prefix == 'NONE': 354*b985c9caSMartin Matuska prefix = '$ac_default_prefix' 355*b985c9caSMartin Matuskasitedir = sysconfig.get_path('purelib', scheme, vars={'base': prefix}) 356*b985c9caSMartin Matuskaprint(sitedir)"` 357*b985c9caSMartin Matuska else 358*b985c9caSMartin Matuska # distutils.sysconfig way 359*b985c9caSMartin Matuska PYTHON_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \ 360*b985c9caSMartin Matuska print (sysconfig.get_python_lib(0,0));"` 361*b985c9caSMartin Matuska fi 362eda14cbcSMatt Macy fi 363eda14cbcSMatt Macy AC_MSG_RESULT([$PYTHON_SITE_PKG]) 364eda14cbcSMatt Macy AC_SUBST([PYTHON_SITE_PKG]) 365eda14cbcSMatt Macy 366eda14cbcSMatt Macy # 367*b985c9caSMartin Matuska # Check for platform-specific site packages 368*b985c9caSMartin Matuska # 369*b985c9caSMartin Matuska AC_MSG_CHECKING([for Python platform specific site-packages path]) 370*b985c9caSMartin Matuska if test -z "$PYTHON_PLATFORM_SITE_PKG"; then 371*b985c9caSMartin Matuska if test "$IMPORT_SYSCONFIG" = "import sysconfig"; then 372*b985c9caSMartin Matuska PYTHON_PLATFORM_SITE_PKG=`$PYTHON -c " 373*b985c9caSMartin Matuska$IMPORT_SYSCONFIG; 374*b985c9caSMartin Matuskaif hasattr(sysconfig, 'get_default_scheme'): 375*b985c9caSMartin Matuska scheme = sysconfig.get_default_scheme() 376*b985c9caSMartin Matuskaelse: 377*b985c9caSMartin Matuska scheme = sysconfig._get_default_scheme() 378*b985c9caSMartin Matuskaif scheme == 'posix_local': 379*b985c9caSMartin Matuska # Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/ 380*b985c9caSMartin Matuska scheme = 'posix_prefix' 381*b985c9caSMartin Matuskaprefix = '$prefix' 382*b985c9caSMartin Matuskaif prefix == 'NONE': 383*b985c9caSMartin Matuska prefix = '$ac_default_prefix' 384*b985c9caSMartin Matuskasitedir = sysconfig.get_path('platlib', scheme, vars={'platbase': prefix}) 385*b985c9caSMartin Matuskaprint(sitedir)"` 386*b985c9caSMartin Matuska else 387*b985c9caSMartin Matuska # distutils.sysconfig way 388*b985c9caSMartin Matuska PYTHON_PLATFORM_SITE_PKG=`$PYTHON -c "$IMPORT_SYSCONFIG; \ 389*b985c9caSMartin Matuska print (sysconfig.get_python_lib(1,0));"` 390*b985c9caSMartin Matuska fi 391*b985c9caSMartin Matuska fi 392*b985c9caSMartin Matuska AC_MSG_RESULT([$PYTHON_PLATFORM_SITE_PKG]) 393*b985c9caSMartin Matuska AC_SUBST([PYTHON_PLATFORM_SITE_PKG]) 394*b985c9caSMartin Matuska 395*b985c9caSMartin Matuska # 396eda14cbcSMatt Macy # libraries which must be linked in when embedding 397eda14cbcSMatt Macy # 398eda14cbcSMatt Macy AC_MSG_CHECKING(python extra libraries) 399eda14cbcSMatt Macy if test -z "$PYTHON_EXTRA_LIBS"; then 400*b985c9caSMartin Matuska PYTHON_EXTRA_LIBS=`$PYTHON -c "$IMPORT_SYSCONFIG; \ 401bb2d13b6SMartin Matuska conf = sysconfig.get_config_var; \ 402eda14cbcSMatt Macy print (conf('LIBS') + ' ' + conf('SYSLIBS'))"` 403eda14cbcSMatt Macy fi 404eda14cbcSMatt Macy AC_MSG_RESULT([$PYTHON_EXTRA_LIBS]) 405eda14cbcSMatt Macy AC_SUBST(PYTHON_EXTRA_LIBS) 406eda14cbcSMatt Macy 407eda14cbcSMatt Macy # 408eda14cbcSMatt Macy # linking flags needed when embedding 409eda14cbcSMatt Macy # 410eda14cbcSMatt Macy AC_MSG_CHECKING(python extra linking flags) 411eda14cbcSMatt Macy if test -z "$PYTHON_EXTRA_LDFLAGS"; then 412*b985c9caSMartin Matuska PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "$IMPORT_SYSCONFIG; \ 413bb2d13b6SMartin Matuska conf = sysconfig.get_config_var; \ 414eda14cbcSMatt Macy print (conf('LINKFORSHARED'))"` 415*b985c9caSMartin Matuska # Hack for macos, it sticks this in here. 416*b985c9caSMartin Matuska PYTHON_EXTRA_LDFLAGS=`echo $PYTHON_EXTRA_LDFLAGS | sed 's/CoreFoundation.*$/CoreFoundation/'` 417eda14cbcSMatt Macy fi 418eda14cbcSMatt Macy AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS]) 419eda14cbcSMatt Macy AC_SUBST(PYTHON_EXTRA_LDFLAGS) 420eda14cbcSMatt Macy 421eda14cbcSMatt Macy # 422eda14cbcSMatt Macy # final check to see if everything compiles alright 423eda14cbcSMatt Macy # 424eda14cbcSMatt Macy AC_MSG_CHECKING([consistency of all components of python development environment]) 425eda14cbcSMatt Macy # save current global flags 426eda14cbcSMatt Macy ac_save_LIBS="$LIBS" 427eda14cbcSMatt Macy ac_save_LDFLAGS="$LDFLAGS" 428eda14cbcSMatt Macy ac_save_CPPFLAGS="$CPPFLAGS" 429*b985c9caSMartin Matuska LIBS="$ac_save_LIBS $PYTHON_LIBS $PYTHON_EXTRA_LIBS" 430eda14cbcSMatt Macy LDFLAGS="$ac_save_LDFLAGS $PYTHON_EXTRA_LDFLAGS" 431eda14cbcSMatt Macy CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS" 432eda14cbcSMatt Macy AC_LANG_PUSH([C]) 433eda14cbcSMatt Macy AC_LINK_IFELSE([ 434eda14cbcSMatt Macy AC_LANG_PROGRAM([[#include <Python.h>]], 435eda14cbcSMatt Macy [[Py_Initialize();]]) 436eda14cbcSMatt Macy ],[pythonexists=yes],[pythonexists=no]) 437eda14cbcSMatt Macy AC_LANG_POP([C]) 438eda14cbcSMatt Macy # turn back to default flags 439eda14cbcSMatt Macy CPPFLAGS="$ac_save_CPPFLAGS" 440eda14cbcSMatt Macy LIBS="$ac_save_LIBS" 441eda14cbcSMatt Macy LDFLAGS="$ac_save_LDFLAGS" 442eda14cbcSMatt Macy 443eda14cbcSMatt Macy AC_MSG_RESULT([$pythonexists]) 444eda14cbcSMatt Macy 445eda14cbcSMatt Macy if test ! "x$pythonexists" = "xyes"; then 446*b985c9caSMartin Matuska AC_MSG_WARN([ 447eda14cbcSMatt Macy Could not link test program to Python. Maybe the main Python library has been 448eda14cbcSMatt Macy installed in some non-standard library path. If so, pass it to configure, 449eda14cbcSMatt Macy via the LIBS environment variable. 450eda14cbcSMatt Macy Example: ./configure LIBS="-L/usr/non-standard-path/python/lib" 451eda14cbcSMatt Macy ============================================================================ 452eda14cbcSMatt Macy ERROR! 453eda14cbcSMatt Macy You probably have to install the development version of the Python package 454eda14cbcSMatt Macy for your distribution. The exact name of this package varies among them. 455eda14cbcSMatt Macy ============================================================================ 456eda14cbcSMatt Macy ]) 457*b985c9caSMartin Matuska if ! $ax_python_devel_optional; then 458*b985c9caSMartin Matuska AC_MSG_ERROR([Giving up]) 459*b985c9caSMartin Matuska fi 460*b985c9caSMartin Matuska ax_python_devel_found=no 461eda14cbcSMatt Macy PYTHON_VERSION="" 462*b985c9caSMartin Matuska fi 463eda14cbcSMatt Macy fi 464eda14cbcSMatt Macy 465eda14cbcSMatt Macy # 466eda14cbcSMatt Macy # all done! 467eda14cbcSMatt Macy # 468eda14cbcSMatt Macy]) 469