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 | |
---|
18 | AC_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 | # @<:@=@<:@embed,@:>@PYTHON@:>@ |
---|
29 | AC_ARG_WITH( |
---|
30 | python, |
---|
31 | AS_HELP_STRING([--with-python], |
---|
32 | [absolute path name of Python executable] |
---|
33 | ), |
---|
34 | [],[withval="yes"] |
---|
35 | ) |
---|
36 | si_try_embed="no" |
---|
37 | py_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," |
---|
38 | for elt in $withval; do |
---|
39 | IFS="$py_save_ifs" |
---|
40 | case $elt in |
---|
41 | embed|embedding) |
---|
42 | si_try_embed="yes" |
---|
43 | ;; |
---|
44 | static|dynamic|shared|module) |
---|
45 | ;; |
---|
46 | *) |
---|
47 | si_withval=$elt |
---|
48 | esac |
---|
49 | done |
---|
50 | IFS="$py_save_ifs" |
---|
51 | if test x"$si_withval" = x"" |
---|
52 | then |
---|
53 | withval="yes" |
---|
54 | else |
---|
55 | withval="$si_withval" |
---|
56 | fi |
---|
57 | |
---|
58 | AC_MSG_RESULT($withval) |
---|
59 | if test "$withval" = "no" |
---|
60 | then |
---|
61 | ax_python_use=false |
---|
62 | else |
---|
63 | if test "$withval" = "yes" |
---|
64 | then |
---|
65 | # "yes" was specified, but we don't have a path |
---|
66 | # for the executable. |
---|
67 | # So, let's search the PATH Environment Variable. |
---|
68 | AC_PATH_PROGS( |
---|
69 | [PYTHON], |
---|
70 | [python2 python], |
---|
71 | [], |
---|
72 | $2 |
---|
73 | ) |
---|
74 | else |
---|
75 | # $withval must be the executable path then. |
---|
76 | AC_SUBST([PYTHON], ["${withval}"]) |
---|
77 | fi |
---|
78 | if test -z "$PYTHON" |
---|
79 | then |
---|
80 | AC_MSG_RESULT([no path to python found, skipping python interface!]) |
---|
81 | else |
---|
82 | AX_PYTHON_VERSION_CHECK([$1], |
---|
83 | [ AC_MSG_RESULT(yes) |
---|
84 | AX_PYTHON_VERSION_CHECK([3], |
---|
85 | [ ax_python_use=false |
---|
86 | AC_MSG_RESULT([too recent, skipping python interface!]) |
---|
87 | ], |
---|
88 | [ AC_MSG_RESULT([no (ok)]) |
---|
89 | ax_python_version=`$PYTHON -c "import sys; print '.'.join(sys.version.split('.')[[:2]])"` |
---|
90 | AC_CHECK_LIB([python${ax_python_version}],[main], [ |
---|
91 | ax_python_use=true |
---|
92 | si_embed_python=$si_try_embed |
---|
93 | AC_MSG_CHECKING(embedding python interface module) |
---|
94 | AC_MSG_RESULT($si_try_embed) |
---|
95 | AX_PYTHON_PREFIX( ) |
---|
96 | AX_PYTHON_LSPEC( ) |
---|
97 | AX_PYTHON_CSPEC( ) |
---|
98 | ], |
---|
99 | [ ax_python_use=false |
---|
100 | AC_MSG_RESULT([Cannot link to python, skipping python interface!]) |
---|
101 | ] |
---|
102 | ) |
---|
103 | ]) |
---|
104 | ], |
---|
105 | [ ax_python_use=false |
---|
106 | AC_MSG_RESULT([too old, skipping python interface!])] |
---|
107 | ) |
---|
108 | fi |
---|
109 | fi |
---|
110 | |
---|
111 | if test x"$si_embed_python" = x"yes" |
---|
112 | then |
---|
113 | AC_DEFINE(EMBED_PYTHON,1,integrate python) |
---|
114 | AC_SUBST(EMBED_PYOBJECT_CFLAGS,"\${PYTHON_CSPEC}") |
---|
115 | AC_SUBST(EMBED_PYOBJECT_LDFLAGS,"\${PYTHON_LSPEC}") |
---|
116 | fi |
---|
117 | if test x"$ax_python_use" = x"true" |
---|
118 | then |
---|
119 | AC_DEFINE(HAVE_PYTHON,1,[compile python-related stuff]) |
---|
120 | fi |
---|
121 | fi |
---|
122 | |
---|
123 | AM_CONDITIONAL(PYTHON_USE, test x"$ax_python_use" = x"true") |
---|
124 | AM_CONDITIONAL(SI_EMBED_PYTHON, test x"$ax_python_use$si_embed_python" = x"trueyes") |
---|
125 | AM_CONDITIONAL(PYTHON_MODULE, test x"$ax_python_use" = x"true" -a x"$si_embed_python" != x"yes" ) |
---|
126 | |
---|
127 | ]) |
---|
128 | |
---|