Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / common / m4 / as-python.m4
1 ## ------------------------
2 ## Python file handling
3 ## From Andrew Dalke
4 ## Updated by James Henstridge
5 ## Updated by Andy Wingo to loop through possible pythons
6 ## ------------------------
7
8 # AS_PATH_PYTHON([MINIMUM-VERSION])
9
10 # Adds support for distributing Python modules and packages.  To
11 # install modules, copy them to $(pythondir), using the python_PYTHON
12 # automake variable.  To install a package with the same name as the
13 # automake package, install to $(pkgpythondir), or use the
14 # pkgpython_PYTHON automake variable.
15
16 # The variables $(pyexecdir) and $(pkgpyexecdir) are provided as
17 # locations to install python extension modules (shared libraries).
18 # Another macro is required to find the appropriate flags to compile
19 # extension modules.
20
21 # If your package is configured with a different prefix to python,
22 # users will have to add the install directory to the PYTHONPATH
23 # environment variable, or create a .pth file (see the python
24 # documentation for details).
25
26 # If the MINIMUM-VERSION argument is passed, AS_PATH_PYTHON will
27 # cause an error if the version of python installed on the system
28 # doesn't meet the requirement.  MINIMUM-VERSION should consist of
29 # numbers and dots only.
30
31 # Updated to loop over all possible python binaries by Andy Wingo
32 # <wingo@pobox.com>
33 # Updated to only warn and unset PYTHON if no good one is found
34
35 AC_DEFUN([AS_PATH_PYTHON],
36  [
37   dnl Find a version of Python.  I could check for python versions 1.4
38   dnl or earlier, but the default installation locations changed from
39   dnl $prefix/lib/site-python in 1.4 to $prefix/lib/python1.5/site-packages
40   dnl in 1.5, and I don't want to maintain that logic.
41
42   dnl should we do the version check?
43   PYTHON_CANDIDATES="python python2.2 python2.1 python2.0 python2 \
44                      python1.6 python1.5"
45   ifelse([$1],[],
46          [AC_PATH_PROG(PYTHON, $PYTHON_CANDIDATES)],
47          [
48      AC_MSG_NOTICE(Looking for Python version >= $1)
49     changequote(<<, >>)dnl
50     prog="
51 import sys, string
52 minver = '$1'
53 # split string by '.' and convert to numeric
54 minver_info = map(string.atoi, string.split(minver, '.'))
55 # we can now do comparisons on the two lists:
56 if sys.version_info >= tuple(minver_info):
57         sys.exit(0)
58 else:
59         sys.exit(1)"
60     changequote([, ])dnl
61
62     python_good=false
63     for python_candidate in $PYTHON_CANDIDATES; do
64       unset PYTHON
65       AC_PATH_PROG(PYTHON, $python_candidate) 1> /dev/null 2> /dev/null
66
67       if test "x$PYTHON" = "x"; then continue; fi
68
69       if $PYTHON -c "$prog" 1>&AC_FD_CC 2>&AC_FD_CC; then
70         AC_MSG_CHECKING(["$PYTHON":])
71         AC_MSG_RESULT([okay])
72         python_good=true
73         break;
74       else
75         dnl clear the cache val
76         unset ac_cv_path_PYTHON
77       fi
78     done
79   ])
80
81   if test "$python_good" != "true"; then
82     AC_MSG_WARN([No suitable version of python found])
83     PYTHON=
84   else
85
86   AC_MSG_CHECKING([local Python configuration])
87
88   dnl Query Python for its version number.  Getting [:3] seems to be
89   dnl the best way to do this; it's what "site.py" does in the standard
90   dnl library.  Need to change quote character because of [:3]
91
92   AC_SUBST(PYTHON_VERSION)
93   changequote(<<, >>)dnl
94   PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[:3]"`
95   changequote([, ])dnl
96
97
98   dnl Use the values of $prefix and $exec_prefix for the corresponding
99   dnl values of PYTHON_PREFIX and PYTHON_EXEC_PREFIX.  These are made
100   dnl distinct variables so they can be overridden if need be.  However,
101   dnl general consensus is that you shouldn't need this ability.
102
103   AC_SUBST(PYTHON_PREFIX)
104   PYTHON_PREFIX='${prefix}'
105
106   AC_SUBST(PYTHON_EXEC_PREFIX)
107   PYTHON_EXEC_PREFIX='${exec_prefix}'
108
109   dnl At times (like when building shared libraries) you may want
110   dnl to know which OS platform Python thinks this is.
111
112   AC_SUBST(PYTHON_PLATFORM)
113   PYTHON_PLATFORM=`$PYTHON -c "import sys; print sys.platform"`
114
115
116   dnl Set up 4 directories:
117
118   dnl pythondir -- where to install python scripts.  This is the
119   dnl   site-packages directory, not the python standard library
120   dnl   directory like in previous automake betas.  This behaviour
121   dnl   is more consistent with lispdir.m4 for example.
122   dnl
123   dnl Also, if the package prefix isn't the same as python's prefix,
124   dnl then the old $(pythondir) was pretty useless.
125
126   AC_SUBST(pythondir)
127   pythondir=$PYTHON_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
128
129   dnl pkgpythondir -- $PACKAGE directory under pythondir.  Was
130   dnl   PYTHON_SITE_PACKAGE in previous betas, but this naming is
131   dnl   more consistent with the rest of automake.
132   dnl   Maybe this should be put in python.am?
133
134   AC_SUBST(pkgpythondir)
135   pkgpythondir=\${pythondir}/$PACKAGE
136
137   dnl pyexecdir -- directory for installing python extension modules
138   dnl   (shared libraries)  Was PYTHON_SITE_EXEC in previous betas.
139
140   AC_SUBST(pyexecdir)
141   pyexecdir=$PYTHON_EXEC_PREFIX"/lib/python"$PYTHON_VERSION/site-packages
142
143   dnl pkgpyexecdir -- $(pyexecdir)/$(PACKAGE)
144   dnl   Maybe this should be put in python.am?
145
146   AC_SUBST(pkgpyexecdir)
147   pkgpyexecdir=\${pyexecdir}/$PACKAGE
148
149   AC_MSG_RESULT([looks good])
150
151   fi
152 ])