1 ## ------------------------
2 ## Python file handling
4 ## ------------------------
6 # AM_PATH_PYTHON([package, module])
9 # Adds support for distributing Python modules or the special form
10 # of a module called a `package.' Modules of the first type are
11 # files ending in `.py' with no '__init__.py' file. This must be
12 # placed on the PYTHONPATH, and the default location is PYTHON_SITE,
13 # or $(prefix)/lib/python$(PYTHON_VERSION)/site-package
15 # A package module is contained in its own directory. This directory
16 # is named PACKAGE, which was the name given to automake. The full
17 # directory path is PYTHON_SITE_PACKAGE or
18 # $(prefix)/lib/python$(PYTHON_VERSION)/site-package/$(PACKAGE)
19 # where site-package is on the PYTHONPATH. The `__init__.py' file is
20 # located in the directory, along with any other submodules which may
24 AC_DEFUN([AM_PATH_PYTHON],
26 dnl Find a version of Python. I could check for python versions 1.4
27 dnl or earlier, but the default installation locations changed from
28 dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
29 dnl in 1.5, and I don't want to maintain that logic.
31 AC_PATH_PROG(PYTHON, python python1.5)
33 AC_MSG_CHECKING([local Python configuration])
35 dnl Query Python for its version number. Getting [:3] seems to be
36 dnl the best way to do this; it's what "site.py" does in the standard
37 dnl library. Need to change quote character because of [:3]
39 AC_SUBST(PYTHON_VERSION)
40 changequote(<<, >>)dnl
41 PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
45 dnl Use the values of $prefix and $exec_prefix for the corresponding
46 dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX. These are made
47 dnl distinct variables so they can be overridden if need be. However,
48 dnl general consensus is that you shouldn't need this ability.
50 AC_SUBST(PYTHON_PREFIX)
51 PYTHON_PREFIX='${prefix}'
53 AC_SUBST(PYTHON_EXEC_PREFIX)
54 PYTHON_EXEC_PREFIX='${exec_prefix}'
56 dnl At times (like when building shared libraries) you may want
57 dnl to know which OS platform Python thinks this is.
59 AC_SUBST(PYTHON_PLATFORM)
60 PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
63 dnl Set up 4 directories:
65 dnl pythondir -- location of the standard python libraries
66 dnl Also lets automake think PYTHON means something.
69 pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION
71 dnl PYTHON_SITE -- the platform independent site-packages directory
74 PYTHON_SITE=$pythondir/site-packages
76 dnl PYTHON_SITE_PACKAGE -- the $PACKAGE directory under PYTHON_SITE
78 AC_SUBST(PYTHON_SITE_PACKAGE)
79 PYTHON_SITE_PACKAGE=$pythondir/site-packages/$PACKAGE
81 dnl PYTHON_SITE_EXEC -- platform dependent site-packages dir (eg, for
84 AC_SUBST(PYTHON_SITE_EXEC)
85 PYTHON_SITE_EXEC=$PYTHON_EXEC_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
88 dnl Configure PYTHON_SITE_INSTALL so it points to either the module
89 dnl directory or the package subdirectory, depending on the $1
90 dnl parameter ("module" or "package").
92 AC_SUBST(PYTHON_SITE_INSTALL)
93 ifelse($1, module, [PYTHON_SITE_INSTALL=$PYTHON_SITE],
94 $1, package, [PYTHON_SITE_INSTALL=$PYTHON_SITE_PACKAGE],
95 [errprint([Unknown option `$1' used in call to AM_PATH_PYTHON.
96 Valid options are `module' or `package'
102 AC_MSG_RESULT([looks good])