|
| 1 | +## ------------------------ -*- Autoconf -*- |
| 2 | +## Python 3 file handling, adapted from: |
| 3 | +## Python file handling |
| 4 | +## From Andrew Dalke |
| 5 | +## Updated by James Henstridge |
| 6 | +## ------------------------ |
| 7 | +# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009 |
| 8 | +# Free Software Foundation, Inc. |
| 9 | +# |
| 10 | +# This file is free software; the Free Software Foundation |
| 11 | +# gives unlimited permission to copy and/or distribute it, |
| 12 | +# with or without modifications, as long as this notice is preserved. |
| 13 | + |
| 14 | +# AM_PATH_PYTHON3([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) |
| 15 | +# --------------------------------------------------------------------------- |
| 16 | +# Adds support for distributing Python modules and packages. To |
| 17 | +# install modules, copy them to $(pythondir), using the python_PYTHON |
| 18 | +# automake variable. To install a package with the same name as the |
| 19 | +# automake package, install to $(pkgpythondir), or use the |
| 20 | +# pkgpython_PYTHON automake variable. |
| 21 | +# |
| 22 | +# The variables $(pyexecdir) and $(pkgpyexecdir) are provided as |
| 23 | +# locations to install python extension modules (shared libraries). |
| 24 | +# Another macro is required to find the appropriate flags to compile |
| 25 | +# extension modules. |
| 26 | +# |
| 27 | +# If your package is configured with a different prefix to python, |
| 28 | +# users will have to add the install directory to the PYTHONPATH |
| 29 | +# environment variable, or create a .pth file (see the python |
| 30 | +# documentation for details). |
| 31 | +# |
| 32 | +# If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will |
| 33 | +# cause an error if the version of python installed on the system |
| 34 | +# doesn't meet the requirement. MINIMUM-VERSION should consist of |
| 35 | +# numbers and dots only. |
| 36 | +AC_DEFUN([AM_PATH_PYTHON3], |
| 37 | + [ |
| 38 | + dnl Find a Python 3 interpreter |
| 39 | + m4_define_default([_AM_PYTHON3_INTERPRETER_LIST], |
| 40 | + [python3 python3.0 python3.1]) |
| 41 | +
|
| 42 | + m4_if([$1],[],[ |
| 43 | + dnl No version check is needed. |
| 44 | + # Find any Python 3 interpreter. |
| 45 | + if test -z "$PYTHON3"; then |
| 46 | + AC_PATH_PROGS([PYTHON3], _AM_PYTHON3_INTERPRETER_LIST, :) |
| 47 | + fi |
| 48 | + am_display_PYTHON3=python3 |
| 49 | + ], [ |
| 50 | + dnl A version check is needed. |
| 51 | + if test -n "$PYTHON3"; then |
| 52 | + # If the user set $PYTHON3, use it and don't search something else. |
| 53 | + AC_MSG_CHECKING([whether $PYTHON3 version >= $1]) |
| 54 | + AM_PYTHON3_CHECK_VERSION([$PYTHON3], [$1], |
| 55 | + [AC_MSG_RESULT(yes)], |
| 56 | + [AC_MSG_ERROR(too old)]) |
| 57 | + am_display_PYTHON3=$PYTHON3 |
| 58 | + else |
| 59 | + # Otherwise, try each interpreter until we find one that satisfies |
| 60 | + # VERSION. |
| 61 | + AC_CACHE_CHECK([for a Python3 interpreter with version >= $1], |
| 62 | + [am_cv_pathless_PYTHON3],[ |
| 63 | + for am_cv_pathless_PYTHON3 in _AM_PYTHON3_INTERPRETER_LIST none; do |
| 64 | + test "$am_cv_pathless_PYTHON3" = none && break |
| 65 | + AM_PYTHON3_CHECK_VERSION([$am_cv_pathless_PYTHON3], [$1], [break]) |
| 66 | + done]) |
| 67 | + # Set $PYTHON3 to the absolute path of $am_cv_pathless_PYTHON3. |
| 68 | + if test "$am_cv_pathless_PYTHON3" = none; then |
| 69 | + PYTHON3=: |
| 70 | + else |
| 71 | + AC_PATH_PROG([PYTHON3], [$am_cv_pathless_PYTHON3]) |
| 72 | + fi |
| 73 | + am_display_PYTHON3=$am_cv_pathless_PYTHON3 |
| 74 | + fi |
| 75 | + ]) |
| 76 | +
|
| 77 | + if test "$PYTHON3" = :; then |
| 78 | + dnl Run any user-specified action, or abort. |
| 79 | + m4_default([$3], [AC_MSG_ERROR([no suitable Python3 interpreter found])]) |
| 80 | + else |
| 81 | +
|
| 82 | + dnl Query Python3 for its version number. Getting [:3] seems to be |
| 83 | + dnl the best way to do this; it's what "site.py" does in the standard |
| 84 | + dnl library. |
| 85 | +
|
| 86 | + AC_CACHE_CHECK([for $am_display_PYTHON3 version], [am_cv_python3_version], |
| 87 | + [am_cv_python3_version=`$PYTHON3 -c "import sys; sys.stdout.write(sys.version[[:3]])"`]) |
| 88 | + AC_SUBST([PYTHON3_VERSION], [$am_cv_python3_version]) |
| 89 | +
|
| 90 | + dnl Use the values of $prefix and $exec_prefix for the corresponding |
| 91 | + dnl values of PYTHON3_PREFIX and PYTHON3_EXEC_PREFIX. These are made |
| 92 | + dnl distinct variables so they can be overridden if need be. However, |
| 93 | + dnl general consensus is that you shouldn't need this ability. |
| 94 | +
|
| 95 | + AC_SUBST([PYTHON3_PREFIX], ['${prefix}']) |
| 96 | + AC_SUBST([PYTHON3_EXEC_PREFIX], ['${exec_prefix}']) |
| 97 | +
|
| 98 | + dnl At times (like when building shared libraries) you may want |
| 99 | + dnl to know which OS platform Python3 thinks this is. |
| 100 | +
|
| 101 | + AC_CACHE_CHECK([for $am_display_PYTHON3 platform], [am_cv_python3_platform], |
| 102 | + [am_cv_python3_platform=`$PYTHON3 -c "import sys; sys.stdout.write(sys.platform)"`]) |
| 103 | + AC_SUBST([PYTHON3_PLATFORM], [$am_cv_python3_platform]) |
| 104 | +
|
| 105 | + AC_CACHE_CHECK([for $am_display_PYTHON3 bldlibrary], [am_cv_python3_bldlibrary], |
| 106 | + [am_cv_python3_bldlibrary=`$PYTHON3 -c "import sys; import sysconfig; sys.stdout.write(sysconfig.get_config_var('BLDLIBRARY'))"`]) |
| 107 | + AC_SUBST([PYTHON3_BLDLIBRARY], [$am_cv_python3_bldlibrary]) |
| 108 | +
|
| 109 | + dnl Set up 4 directories: |
| 110 | +
|
| 111 | + dnl python3dir -- where to install python3 scripts. This is the |
| 112 | + dnl site-packages directory, not the python3 standard library |
| 113 | + dnl directory like in previous automake betas. This behavior |
| 114 | + dnl is more consistent with lispdir.m4 for example. |
| 115 | + dnl Query distutils for this directory. distutils does not exist in |
| 116 | + dnl Python3 1.5, so we fall back to the hardcoded directory if it |
| 117 | + dnl doesn't work. |
| 118 | + AC_CACHE_CHECK([for $am_display_PYTHON3 script directory], |
| 119 | + [am_cv_python3_python3dir], |
| 120 | + [if test "x$prefix" = xNONE |
| 121 | + then |
| 122 | + am_py_prefix=$ac_default_prefix |
| 123 | + else |
| 124 | + am_py_prefix=$prefix |
| 125 | + fi |
| 126 | + am_cv_python3_python3dir=`$PYTHON3 -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(0,0,prefix='$am_py_prefix'))" 2>/dev/null || |
| 127 | + echo "$PYTHON3_PREFIX/lib/python$PYTHON3_VERSION/site-packages"` |
| 128 | + case $am_cv_python3_python3dir in |
| 129 | + $am_py_prefix*) |
| 130 | + am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'` |
| 131 | + am_cv_python3_python3dir=`echo "$am_cv_python3_python3dir" | sed "s,^$am__strip_prefix,$PYTHON3_PREFIX,"` |
| 132 | + ;; |
| 133 | + esac |
| 134 | + ]) |
| 135 | + AC_SUBST([python3dir], [$am_cv_python3_python3dir]) |
| 136 | +
|
| 137 | + dnl pkgpython3dir -- $PACKAGE directory under python3dir. Was |
| 138 | + dnl PYTHON3_SITE_PACKAGE in previous betas, but this naming is |
| 139 | + dnl more consistent with the rest of automake. |
| 140 | +
|
| 141 | + AC_SUBST([pkgpython3dir], [\${python3dir}/$PACKAGE]) |
| 142 | +
|
| 143 | + dnl pyexecdir -- directory for installing python3 extension modules |
| 144 | + dnl (shared libraries) |
| 145 | + dnl Query distutils for this directory. distutils does not exist in |
| 146 | + dnl Python3 1.5, so we fall back to the hardcoded directory if it |
| 147 | + dnl doesn't work. |
| 148 | + AC_CACHE_CHECK([for $am_display_PYTHON3 extension module directory], |
| 149 | + [am_cv_python3_pyexecdir], |
| 150 | + [if test "x$exec_prefix" = xNONE |
| 151 | + then |
| 152 | + am_py_exec_prefix=$am_py_prefix |
| 153 | + else |
| 154 | + am_py_exec_prefix=$exec_prefix |
| 155 | + fi |
| 156 | + am_cv_python3_pyexecdir=`$PYTHON3 -c "import sys; from distutils import sysconfig; sys.stdout.write(sysconfig.get_python_lib(1,0,prefix='$am_py_exec_prefix'))" 2>/dev/null || |
| 157 | + echo "$PYTHON3_EXEC_PREFIX/lib/python$PYTHON3_VERSION/site-packages"` |
| 158 | + case $am_cv_python3_pyexecdir in |
| 159 | + $am_py_exec_prefix*) |
| 160 | + am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'` |
| 161 | + am_cv_python3_pyexecdir=`echo "$am_cv_python3_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON3_EXEC_PREFIX,"` |
| 162 | + ;; |
| 163 | + esac |
| 164 | + ]) |
| 165 | + AC_SUBST([py3execdir], [$am_cv_python3_pyexecdir]) |
| 166 | +
|
| 167 | + dnl pkgpy3execdir -- $(py3execdir)/$(PACKAGE) |
| 168 | +
|
| 169 | + AC_SUBST([pkgpy3execdir], [\${py3execdir}/$PACKAGE]) |
| 170 | +
|
| 171 | + dnl Run any user-specified action. |
| 172 | + $2 |
| 173 | + fi |
| 174 | +
|
| 175 | +]) |
| 176 | + |
| 177 | + |
| 178 | +# AM_PYTHON3_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) |
| 179 | +# --------------------------------------------------------------------------- |
| 180 | +# Run ACTION-IF-TRUE if the Python3 interpreter PROG has version >= VERSION. |
| 181 | +# Run ACTION-IF-FALSE otherwise. |
| 182 | +# This test uses sys.hexversion instead of the string equivalent (first |
| 183 | +# word of sys.version), in order to cope with versions such as 2.2c1. |
| 184 | +# This supports Python3 2.0 or higher. (2.0 was released on October 16, 2000). |
| 185 | +AC_DEFUN([AM_PYTHON3_CHECK_VERSION], |
| 186 | + [prog="import sys |
| 187 | +# split strings by '.' and convert to numeric. Append some zeros |
| 188 | +# because we need at least 4 digits for the hex conversion. |
| 189 | +# map returns an iterator in Python3 3.0 and a list in 2.x |
| 190 | +minver = list(map(int, '$2'.split('.'))) + [[0, 0, 0]] |
| 191 | +minverhex = 0 |
| 192 | +# xrange is not present in Python3yy 3.0 and range returns an iterator |
| 193 | +for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[[i]] |
| 194 | +sys.exit(sys.hexversion < minverhex)" |
| 195 | + AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])]) |
0 commit comments