source: git/m4/ax_python_with_version.m4 @ 69e438

spielwiese
Last change on this file since 69e438 was 69e438, checked in by Alexander Dreyer <adreyer@…>, 11 years ago
Skip pyobject.so if linking to libpythonx.y breaks
  • Property mode set to 100644
File size: 4.4 KB
Line 
1# AX_PYTHON_WITH_VERSION( [version], [path] )
2# -----------------------------------------------------------------
3# Handles the various --with-python commands.
4# Input:
5#   $1 is the minimun required python version
6#   $2 is the optional search path for the python executable if needed
7# Ouput:
8#   PYTHON_USE (AM_CONDITIONAL) is true if python executable found
9#   and --with-python was requested; otherwise false.
10#   $PYTHON contains the full executable path to python if PYTHON_USE
11#   is true.
12#
13# Example:
14#   AX_PYTHON_WITH_VERSION([2.4])
15#   or
16#   AX_PYTHON_WITH_VERSION([2.4], "/usr/bin")
17
18AC_DEFUN([AX_PYTHON_WITH_VERSION],
19[
20    AC_ARG_VAR([PYTHON],[Python Executable Path])
21
22    # unless PYTHON was supplied to us (as a precious variable),
23    # see if --with-python[=PythonExecutablePath], --with-python,
24    # --without-python or --with-python=no was given.
25    if test -z "$PYTHON"
26    then
27        AC_MSG_CHECKING(for --with-python)
28        AC_ARG_WITH(
29            python,
30            AS_HELP_STRING([--with-python@<:@=@<:@embed,@:>@PYTHON@:>@],
31                [absolute path name of Python executable]
32            ),
33            [],[withval="yes"]
34        )
35        si_try_embed="no"
36        py_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
37        for elt in $withval; do
38          IFS="$py_save_ifs"
39          case $elt in
40            embed|embedding)
41              si_try_embed="yes"
42            ;;
43            static|dynamic|shared|module)
44            ;;
45            *)
46            si_withval=$elt
47          esac
48        done
49        IFS="$py_save_ifs"
50        if test x"$si_withval" = x""
51        then
52           withval="yes"
53        else
54           withval="$si_withval"
55        fi
56
57        AC_MSG_RESULT($withval)
58        if test "$withval" = "no"
59        then
60            ax_python_use=false
61        else       
62            if test "$withval" = "yes"
63            then
64                # "yes" was specified, but we don't have a path
65                # for the executable.
66                # So, let's search the PATH Environment Variable.
67                AC_PATH_PROGS(
68                    [PYTHON],
69                    [python2 python],
70                    [],
71                    $2
72                )
73            else
74                # $withval must be the executable path then.
75                AC_SUBST([PYTHON], ["${withval}"])
76            fi
77            if test -z "$PYTHON"
78            then
79                AC_MSG_RESULT([no path to python found, skipping python interface!])
80            else
81                AX_PYTHON_VERSION_CHECK([$1],
82                  [ AC_MSG_RESULT(yes)
83                    AX_PYTHON_VERSION_CHECK([3],
84                    [ ax_python_use=false
85                      AC_MSG_RESULT([too recent, skipping python interface!])
86                    ],
87                    [ AC_MSG_RESULT([no (ok)])
88                      ax_python_version=`$PYTHON -c "import sys; print '.'.join(sys.version.split('.')[[:2]])"`
89                      AC_CHECK_LIB([python${ax_python_version}],[main], [
90                          ax_python_use=true
91                          si_embed_python=$si_try_embed
92                          AC_MSG_CHECKING(embedding python interface module)
93                          AC_MSG_RESULT($si_try_embed)
94                          AX_PYTHON_PREFIX( )
95                          AX_PYTHON_LSPEC( )
96                          AX_PYTHON_CSPEC( )
97                        ],
98                        [ ax_python_use=false
99                          AC_MSG_RESULT([Cannot link to python, skipping python interface!])
100                        ]
101                      )
102                    ])
103                  ],
104                  [ ax_python_use=false
105                    AC_MSG_RESULT([too old, skipping python interface!])]
106                )
107            fi
108        fi   
109
110        if  test x"$si_embed_python" = x"yes"
111        then
112          AC_DEFINE(EMBED_PYTHON,1,integrate python)
113          AC_SUBST(EMBED_PYOBJECT_CFLAGS,"\${PYTHON_CSPEC}")
114          AC_SUBST(EMBED_PYOBJECT_LDFLAGS,"\${PYTHON_LSPEC}")
115        fi
116        if test x"$ax_python_use" = x"true"
117        then
118          AC_DEFINE(HAVE_PYTHON,1,[compile python-related stuff])
119        fi
120    fi
121   
122    AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true")
123    AM_CONDITIONAL(SI_EMBED_PYTHON, test x"$ax_python_use$si_embed_python" = x"trueyes")
124    AM_CONDITIONAL(PYTHON_MODULE, test x"$ax_python_use" = x"true" -a x"$si_embed_python" != x"yes" )
125
126])
127
Note: See TracBrowser for help on using the repository browser.