* automake.texi (Texinfo): Mention vers*.texi.
[automake.git] / m4 / python.m4
blob0ee447e2ce8d1a65119eb25631131086fbb30cc3
1 ## ------------------------
2 ## Python file handling
3 ## From Andrew Dalke
4 ## ------------------------
6 dnl AM_PATH_PYTHON([package, module])
7 dnl 
9 dnl Adds support for distributing Python modules or the special form
10 dnl of a module called a `package.'  Modules of the first type are 
11 dnl files ending in `.py' with no '__init__.py' file.  This must be
12 dnl placed on the PYTHONPATH, and the default location is PYTHON_SITE,
13 dnl or $(prefix)/lib/python$(PYTHON_VERSION)/site-package
14 dnl 
15 dnl A package module is contained in its own directory.  This directory
16 dnl is named PACKAGE, which was the name given to automake.  The full
17 dnl directory path is PYTHON_SITE_PACKAGE or
18 dnl   $(prefix)/lib/python$(PYTHON_VERSION)/site-package/$(PACKAGE)
19 dnl where site-package is on the PYTHONPATH.  The `__init__.py' file is
20 dnl located in the directory, along with any other submodules which may
21 dnl be necessary.
24 AC_DEFUN(AM_PATH_PYTHON,
25  [
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]"`
42   changequote([, ])dnl
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.
68   AC_SUBST(pythondir)
69   pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION
71   dnl   PYTHON_SITE -- the platform independent site-packages directory
73   AC_SUBST(PYTHON_SITE)
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
82   dnl        shared libraries)
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'
97 ])m4exit(4)])
100   dnl All done.
102   AC_MSG_RESULT(looks good)