Merge Trond
[m6w6/libmemcached] / m4 / pandora_python3_devel.m4
1 dnl -*- mode: m4; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 dnl vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 dnl
4 dnl pandora-build: A pedantic build system
5 dnl
6 dnl Copyright (C) 2009 Sun Microsystems, Inc.
7 dnl Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
8 dnl Copyright (c) 2008 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
9 dnl Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
10 dnl Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za>
11 dnl Copyright (c) 2008 Matteo Settenvini <matteo@member.fsf.org>
12 dnl Copyright (c) 2008 Horst Knorr <hk_classes@knoda.org>
13 dnl
14 dnl This program is free software: you can redistribute it and/or modify it
15 dnl under the terms of the GNU General Public License as published by the
16 dnl Free Software Foundation, either version 3 of the License, or (at your
17 dnl option) any later version.
18 dnl
19 dnl This program is distributed in the hope that it will be useful, but
20 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
21 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
22 dnl Public License for more details.
23 dnl
24 dnl You should have received a copy of the GNU General Public License along
25 dnl with this program. If not, see <http://www.gnu.org/licenses/>.
26 dnl
27 dnl As a special exception, the respective Autoconf Macro's copyright owner
28 dnl gives unlimited permission to copy, distribute and modify the configure
29 dnl scripts that are the output of Autoconf when processing the Macro. You
30 dnl need not follow the terms of the GNU General Public License when using
31 dnl or distributing such scripts, even though portions of the text of the
32 dnl Macro appear in them. The GNU General Public License (GPL) does govern
33 dnl all other use of the material that constitutes the Autoconf Macro.
34 dnl
35 dnl This special exception to the GPL applies to versions of the Autoconf
36 dnl Macro released by the Autoconf Macro Archive. When you make and
37 dnl distribute a modified version of the Autoconf Macro, you may extend this
38 dnl special exception to the GPL to apply to your modified version as well.
39
40 dnl SYNOPSIS
41 dnl
42 dnl PANDORA_PYTHON3_DEVEL([version])
43 dnl
44 dnl DESCRIPTION
45 dnl
46 dnl Note: Defines as a precious variable "PYTHON3_VERSION". Don't override it
47 dnl in your configure.ac.
48 dnl
49 dnl This macro checks for Python and tries to get the include path to
50 dnl 'Python.h'. It provides the $(PYTHON3_CPPFLAGS) and $(PYTHON3_LDFLAGS)
51 dnl output variables. It also exports $(PYTHON3_EXTRA_LIBS) and
52 dnl $(PYTHON3_EXTRA_LDFLAGS) for embedding Python in your code.
53 dnl
54 dnl You can search for some particular version of Python by passing a
55 dnl parameter to this macro, for example ">= '2.3.1'", or "== '2.4'". Please
56 dnl note that you *have* to pass also an operator along with the version to
57 dnl match, and pay special attention to the single quotes surrounding the
58 dnl version number. Don't use "PYTHON3_VERSION" for this: that environment
59 dnl variable is declared as precious and thus reserved for the end-user.
60 dnl
61 dnl LAST MODIFICATION
62 dnl
63 dnl 2009-08-23
64
65 AC_DEFUN([PANDORA_PYTHON3_DEVEL],[
66 #
67 # Allow the use of a (user set) custom python version
68 #
69 AC_ARG_VAR([PYTHON3_VERSION],[The installed Python
70 version to use, for example '3.0'. This string
71 will be appended to the Python interpreter
72 canonical name.])
73
74
75 AS_IF([test -z "$PYTHON3"],[
76 AC_PATH_PROG([PYTHON3],[python[$PYTHON3_VERSION]])
77 ])
78 AS_IF([test -z "$PYTHON3"],[
79 AC_MSG_ERROR([Cannot find python$PYTHON3_VERSION in your system path])
80 PYTHON3_VERSION=""
81 ])
82
83 #
84 # if the macro parameter ``version'' is set, honour it
85 #
86 if test -n "$1"; then
87 AC_MSG_CHECKING([for a version of Python $1])
88 ac_supports_python3_ver=`$PYTHON3 -c "import sys, string; \
89 ver = string.split(sys.version)[[0]]; \
90 print(ver $1)"`
91 if test "$ac_supports_python3_ver" = "True"; then
92 AC_MSG_RESULT([yes])
93 else
94 AC_MSG_RESULT([no])
95 AC_MSG_ERROR([this package requires Python $1.
96 If you have it installed, but it isn't the default Python
97 interpreter in your system path, please pass the PYTHON3_VERSION
98 variable to configure. See ``configure --help'' for reference.
99 ])
100 PYTHON_VERSION=""
101 fi
102 fi
103
104 #
105 # Check if you have distutils, else fail
106 #
107 AC_MSG_CHECKING([for Python3 distutils package])
108 ac_python3_distutils_result=`$PYTHON3 -c "import distutils" 2>&1`
109 if test -z "$ac_python3_distutils_result"; then
110 AC_MSG_RESULT([yes])
111 else
112 AC_MSG_RESULT([no])
113 AC_MSG_ERROR([cannot import Python3 module "distutils".
114 Please check your Python3 installation. The error was:
115 $ac_python3_distutils_result])
116 PYTHON3_VERSION=""
117 fi
118
119 #
120 # Check for Python include path
121 #
122 AC_MSG_CHECKING([for Python3 include path])
123 if test -z "$PYTHON3_CPPFLAGS"; then
124 python3_path=`$PYTHON3 -c "import distutils.sysconfig; \
125 print(distutils.sysconfig.get_python_inc());"`
126 if test -n "${python3_path}"; then
127 python3_path="-I$python3_path"
128 fi
129 PYTHON3_CPPFLAGS=$python3_path
130 fi
131 AC_MSG_RESULT([$PYTHON3_CPPFLAGS])
132 AC_SUBST([PYTHON3_CPPFLAGS])
133
134 #
135 # Check for Python library path
136 #
137 AC_MSG_CHECKING([for Python3 library path])
138 if test -z "$PYTHON3_LDFLAGS"; then
139 # (makes two attempts to ensure we've got a version number
140 # from the interpreter)
141 py3_version=`$PYTHON3 -c "from distutils.sysconfig import *; \
142 print(' '.join(get_config_vars('VERSION')))"`
143 if test "$py3_version" == "[None]"; then
144 if test -n "$PYTHON3_VERSION"; then
145 py3_version=$PYTHON3_VERSION
146 else
147 py3_version=`$PYTHON3 -c "import sys; \
148 print(sys.version[[:3]])"`
149 fi
150 fi
151
152 PYTHON3_LDFLAGS=`$PYTHON3 -c "from distutils.sysconfig import *; \
153 print('-L' + get_python_lib(0,1), \
154 '-lpython');"`$py3_version
155 fi
156 AC_MSG_RESULT([$PYTHON3_LDFLAGS])
157 AC_SUBST([PYTHON3_LDFLAGS])
158
159 #
160 # Check for site packages
161 #
162 AC_MSG_CHECKING([for Python3 site-packages path])
163 if test -z "$PYTHON3_SITE_PKG"; then
164 PYTHON3_SITE_PKG=`$PYTHON3 -c "import distutils.sysconfig; \
165 print(distutils.sysconfig.get_python_lib(0,0));"`
166 fi
167 AC_MSG_RESULT([$PYTHON3_SITE_PKG])
168 AC_SUBST([PYTHON3_SITE_PKG])
169
170 #
171 # libraries which must be linked in when embedding
172 #
173 AC_MSG_CHECKING(for Python3 embedding libraries)
174 if test -z "$PYTHON3_EMBED_LIBS"; then
175 PYTHON3_EMBED_LIBS=`$PYTHON3 -c "import distutils.sysconfig; \
176 conf = distutils.sysconfig.get_config_var; \
177 print(conf('LOCALMODLIBS'), conf('LIBS'))"`
178 fi
179 AC_MSG_RESULT([$PYTHON3_EMBED_LIBS])
180 AC_SUBST(PYTHON3_EMBED_LIBS)
181
182 #
183 # linking flags needed when embedding
184 #
185 AC_MSG_CHECKING(for Python3 embedding linking flags)
186 if test -z "$PYTHON3_EMBED_LDFLAGS"; then
187 PYTHON3_EMBED_LDFLAGS=`$PYTHON3 -c "import distutils.sysconfig; \
188 conf = distutils.sysconfig.get_config_var; \
189 print(conf('LINKFORSHARED'))"`
190 fi
191 AC_MSG_RESULT([$PYTHON3_EMBED_LDFLAGS])
192 AC_SUBST(PYTHON3_EMBED_LDFLAGS)
193
194 #
195 # final check to see if everything compiles alright
196 #
197 AC_MSG_CHECKING([for Python3 development environment consistency])
198 AC_LANG_PUSH([C])
199 # save current global flags
200 ac_save_LIBS="$LIBS"
201 ac_save_CPPFLAGS="$CPPFLAGS"
202 LIBS="$ac_save_LIBS $PYTHON3_LDFLAGS"
203 CPPFLAGS="$ac_save_CPPFLAGS $PYTHON3_CPPFLAGS"
204 AC_TRY_LINK([
205 #include <Python.h>
206 ],[
207 Py_Initialize();
208 ],[python3exists=yes],[python3exists=no])
209
210 AC_MSG_RESULT([$python3exists])
211
212 if test ! "$python3exists" = "yes"; then
213 AC_MSG_WARN([
214 Could not link test program to Python3.
215 Maybe the main Python3 library has been installed in some non-standard
216 library path. If so, pass it to configure, via the LDFLAGS environment
217 variable.
218 Example: ./configure LDFLAGS="-L/usr/non-standard-path/python3/lib"
219 ============================================================================
220 ERROR!
221 You probably have to install the development version of the Python3 package
222 for your distribution. The exact name of this package varies among them.
223 ============================================================================
224 ])
225 PYTHON3_VERSION=""
226 fi
227 AC_LANG_POP
228 # turn back to default flags
229 CPPFLAGS="$ac_save_CPPFLAGS"
230 LIBS="$ac_save_LIBS"
231
232 #
233 # all done!
234 #
235 ])
236