libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

python.m4 (7637B)


      1 ## ------------------------
      2 ## Python file handling
      3 ## From Andrew Dalke
      4 ## Updated by James Henstridge
      5 ## ------------------------
      6 
      7 # Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
      8 # Free Software Foundation, Inc.
      9 
     10 # This program is free software; you can redistribute it and/or modify
     11 # it under the terms of the GNU General Public License as published by
     12 # the Free Software Foundation; either version 2, or (at your option)
     13 # any later version.
     14 
     15 # This program is distributed in the hope that it will be useful,
     16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18 # GNU General Public License for more details.
     19 
     20 # You should have received a copy of the GNU General Public License
     21 # along with this program; if not, write to the Free Software
     22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
     23 # 02111-1307, USA.
     24 
     25 # AM_PATH_PYTHON([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
     26 
     27 # Adds support for distributing Python modules and packages.  To
     28 # install modules, copy them to $(pythondir), using the python_PYTHON
     29 # automake variable.  To install a package with the same name as the
     30 # automake package, install to $(pkgpythondir), or use the
     31 # pkgpython_PYTHON automake variable.
     32 
     33 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
     34 # locations to install python extension modules (shared libraries).
     35 # Another macro is required to find the appropriate flags to compile
     36 # extension modules.
     37 
     38 # If your package is configured with a different prefix to python,
     39 # users will have to add the install directory to the PYTHONPATH
     40 # environment variable, or create a .pth file (see the python
     41 # documentation for details).
     42 
     43 # If the MINIMUM-VERSION argument is passed, AM_PATH_PYTHON will
     44 # cause an error if the version of python installed on the system
     45 # doesn't meet the requirement.  MINIMUM-VERSION should consist of
     46 # numbers and dots only.
     47 
     48 AC_DEFUN([AM_PATH_PYTHON],
     49  [
     50   dnl Find a Python interpreter.  Python versions prior to 1.5 are not
     51   dnl supported because the default installation locations changed from
     52   dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
     53   dnl in 1.5.
     54   m4_define([_AM_PYTHON_INTERPRETER_LIST],
     55             [python python2 python2.4 python2.3 python2.2 dnl
     56 python2.1 python2.0 python1.6 python1.5])
     57 
     58   m4_if([$1],[],[
     59     dnl No version check is needed.
     60     # Find any Python interpreter.
     61     if test -z "$PYTHON"; then
     62       PYTHON=:
     63       AC_PATH_PROGS([PYTHON], _AM_PYTHON_INTERPRETER_LIST)
     64     fi
     65     am_display_PYTHON=python
     66   ], [
     67     dnl A version check is needed.
     68     if test -n "$PYTHON"; then
     69       # If the user set $PYTHON, use it and don't search something else.
     70       AC_MSG_CHECKING([whether $PYTHON version >= $1])
     71       AM_PYTHON_CHECK_VERSION([$PYTHON], [$1],
     72 			      [AC_MSG_RESULT(yes)],
     73 			      [AC_MSG_ERROR(too old)])
     74       am_display_PYTHON=$PYTHON
     75     else
     76       # Otherwise, try each interpreter until we find one that satisfies
     77       # VERSION.
     78       AC_CACHE_CHECK([for a Python interpreter with version >= $1],
     79 	[am_cv_pathless_PYTHON],[
     80 	for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
     81 	  test "$am_cv_pathless_PYTHON" = none && break
     82 	  AM_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [$1], [break])
     83 	done])
     84       # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
     85       if test "$am_cv_pathless_PYTHON" = none; then
     86 	PYTHON=:
     87       else
     88         AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
     89       fi
     90       am_display_PYTHON=$am_cv_pathless_PYTHON
     91     fi
     92   ])
     93 
     94   if test "$PYTHON" = :; then
     95   dnl Run any user-specified action, or abort.
     96     m4_default([$3], [AC_MSG_ERROR([no suitable Python interpreter found])])
     97   else
     98 
     99   dnl Query Python for its version number.  Getting [:3] seems to be
    100   dnl the best way to do this; it's what "site.py" does in the standard
    101   dnl library.
    102 
    103   AC_CACHE_CHECK([for $am_display_PYTHON version], [am_cv_python_version],
    104     [am_cv_python_version=`$PYTHON -c "import sys; print sys.version[[:3]]"`])
    105   AC_SUBST([PYTHON_VERSION], [$am_cv_python_version])
    106 
    107   dnl Use the values of $prefix and $exec_prefix for the corresponding
    108   dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
    109   dnl distinct variables so they can be overridden if need be.  However,
    110   dnl general consensus is that you shouldn't need this ability.
    111 
    112   AC_SUBST([PYTHON_PREFIX], ['${prefix}'])
    113   AC_SUBST([PYTHON_EXEC_PREFIX], ['${exec_prefix}'])
    114 
    115   dnl At times (like when building shared libraries) you may want
    116   dnl to know which OS platform Python thinks this is.
    117 
    118   AC_CACHE_CHECK([for $am_display_PYTHON platform], [am_cv_python_platform],
    119     [am_cv_python_platform=`$PYTHON -c "import sys; print sys.platform"`])
    120   AC_SUBST([PYTHON_PLATFORM], [$am_cv_python_platform])
    121 
    122 
    123   dnl Set up 4 directories:
    124 
    125   dnl pythondir -- where to install python scripts.  This is the
    126   dnl   site-packages directory, not the python standard library
    127   dnl   directory like in previous automake betas.  This behavior
    128   dnl   is more consistent with lispdir.m4 for example.
    129   dnl Query distutils for this directory.  distutils does not exist in
    130   dnl Python 1.5, so we fall back to the hardcoded directory if it
    131   dnl doesn't work.
    132   AC_CACHE_CHECK([for $am_display_PYTHON script directory],
    133     [am_cv_python_pythondir],
    134     [am_cv_python_pythondir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(0,0,prefix='$PYTHON_PREFIX')" 2>/dev/null ||
    135      echo "$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages"`])
    136   AC_SUBST([pythondir], [$am_cv_python_pythondir])
    137 
    138   dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
    139   dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
    140   dnl   more consistent with the rest of automake.
    141 
    142   AC_SUBST([pkgpythondir], [\${pythondir}/$PACKAGE])
    143 
    144   dnl pyexecdir -- directory for installing python extension modules
    145   dnl   (shared libraries)
    146   dnl Query distutils for this directory.  distutils does not exist in
    147   dnl Python 1.5, so we fall back to the hardcoded directory if it
    148   dnl doesn't work.
    149   AC_CACHE_CHECK([for $am_display_PYTHON extension module directory],
    150     [am_cv_python_pyexecdir],
    151     [am_cv_python_pyexecdir=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib(1,0,prefix='$PYTHON_EXEC_PREFIX')" 2>/dev/null ||
    152      echo "${PYTHON_EXEC_PREFIX}/lib/python${PYTHON_VERSION}/site-packages"`])
    153   AC_SUBST([pyexecdir], [$am_cv_python_pyexecdir])
    154 
    155   dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
    156 
    157   AC_SUBST([pkgpyexecdir], [\${pyexecdir}/$PACKAGE])
    158 
    159   dnl Run any user-specified action.
    160   $2
    161   fi
    162 
    163 ])
    164 
    165 
    166 # AM_PYTHON_CHECK_VERSION(PROG, VERSION, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
    167 # ---------------------------------------------------------------------------
    168 # Run ACTION-IF-TRUE if the Python interpreter PROG has version >= VERSION.
    169 # Run ACTION-IF-FALSE otherwise.
    170 # This test uses sys.hexversion instead of the string equivalent (first
    171 # word of sys.version), in order to cope with versions such as 2.2c1.
    172 # hexversion has been introduced in Python 1.5.2; it's probably not
    173 # worth to support older versions (1.5.1 was released on October 31, 1998).
    174 AC_DEFUN([AM_PYTHON_CHECK_VERSION],
    175  [prog="import sys, string
    176 # split strings by '.' and convert to numeric.  Append some zeros
    177 # because we need at least 4 digits for the hex conversion.
    178 minver = map(int, string.split('$2', '.')) + [[0, 0, 0]]
    179 minverhex = 0
    180 for i in xrange(0, 4): minverhex = (minverhex << 8) + minver[[i]]
    181 sys.exit(sys.hexversion < minverhex)"
    182   AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])])