Commit | Line | Data |
---|---|---|
e342891a BI |
1 | dnl configure.ac |
2 | dnl | |
3 | dnl Copyright 2012, 2013 Brandon Invergo <brandon@invergo.net> | |
4 | dnl | |
5 | dnl Copying and distribution of this file, with or without modification, | |
6 | dnl are permitted in any medium without royalty provided the copyright | |
7 | dnl notice and this notice are preserved. This file is offered as-is, | |
8 | dnl without any warranty. | |
9 | ||
10 | dnl######### | |
11 | dnl README # | |
12 | dnl######### | |
13 | dnl | |
14 | dnl This is a basic Autoconf configure.ac file for Python-based | |
15 | dnl projects. It is not intended to be used as-is, but rather to be | |
16 | dnl modified to the specific needs of the project. | |
17 | dnl | |
18 | dnl Lines prefixed with "dnl" are comments that are automatically | |
19 | dnl removed by Autoconf/M4, thus they will not appear in the generated | |
20 | dnl configure script (see the M4 documentation for more information). | |
21 | dnl Such comments are used in this file to communicate information to | |
22 | dnl you, the developer. In some cases, the comments contain extra | |
23 | dnl macros that you might consider including in your configure script. | |
24 | dnl If you wish to include them, simply remove the "dnl" from the | |
25 | dnl beginning of the line. | |
26 | dnl | |
27 | dnl Lines prefixed with "#" are comments that will appear in the | |
28 | dnl generated configure script. These comments are thus used to clarify | |
29 | dnl to the user what is happening in that script | |
30 | dnl | |
31 | dnl Wherever pyconfigure-specific macros are used, extra comments are | |
32 | dnl included to describe the macros. | |
33 | ||
34 | dnl###################### | |
35 | dnl Package Information # | |
36 | dnl###################### | |
37 | ||
38 | dnl---- | |
39 | dnl Initialize Autoconf with the package metadata | |
40 | dnl The arguments have been set via the project's PKG-INFO file | |
41 | dnl and correspond to: | |
42 | dnl | |
43 | dnl 1) package name (i.e. foo) | |
44 | dnl 2) package version (i.e. 1.2) | |
45 | dnl 3) bug/info/project email address (i.e. bug-foo@gnu.org) | |
46 | dnl---- | |
47 | dnl | |
48 | AC_INIT([mediagoblin], [0.4.0.dev], [cwebber@gnu.org]) | |
49 | ||
a9dc855a | 50 | |
e342891a BI |
51 | dnl---- |
52 | dnl Load macros from the m4/ directory. If you plan to write new | |
53 | dnl macros, put them in files in this directory. | |
54 | dnl---- | |
55 | dnl | |
56 | AC_CONFIG_MACRO_DIR([m4]) | |
57 | ||
58 | ||
dc85ee8c BI |
59 | # The default prefix should be changed from /usr/local. Set it, as in |
60 | # the documentation, to /srv/mediagoblin.example.org/mediagoblin/ | |
e56b493a | 61 | AC_PREFIX_DEFAULT([`pwd`]) |
dc85ee8c BI |
62 | |
63 | ||
e342891a BI |
64 | dnl########################### |
65 | dnl Program/command support # | |
66 | dnl########################### | |
67 | dnl | |
68 | dnl In this section, we check for the presence of important commands | |
69 | dnl and programs. | |
70 | ||
71 | dnl--PC_INIT---------------------------------------------------------- | |
72 | dnl This is the only required macro. Its primary function is to find | |
73 | dnl a Python interpreter that is compatible with the package and set | |
74 | dnl the PYTHON variable to hold its path. It can optionally take | |
a9dc855a CAW |
75 | dnl arguments to specify minimum and/or maximum versions. This is a |
76 | dnl convenience macro that combines the functionality of the macros | |
77 | dnl PC_PROG_PYTHON and PC_PYTHON_VERIFY_VERSION | |
e342891a BI |
78 | dnl PC_INIT: find an interpreter with a version between 2.0 and 3.3.99 |
79 | dnl (in other words, up to and including any possible release | |
80 | dnl in the 3.3 series) | |
81 | dnl PC_INIT([MIN_VER], [MAX_VER]): Find an interpreter that is between | |
82 | dnl the minimum and maximum version. If the min is in the 2.0 | |
83 | dnl series and the max is in the 3.0 series, non-existent | |
84 | dnl releases (2.8 & 2.9) will be correctly skipped. | |
85 | dnl---- | |
86 | dnl | |
a9dc855a CAW |
87 | PC_INIT([2.7], [3.3.1]) |
88 | ||
89 | ||
90 | dnl--PC_PROG_PYTHON--------------------------------------------------- | |
91 | dnl This macro provides a means of finding a Python interpreter. | |
92 | dnl You may optionally pass it argument to pass a path to a binary to | |
93 | dnl check for first. You may also pass a second and third argument to | |
94 | dnl specify the minimum and maximum versions to check for. This works | |
95 | dnl in a naive way by appending the major and minor release numbers to | |
96 | dnl the binary name. By default, this will first check for a binary | |
97 | dnl called "python" and then from there it will check for version- | |
98 | dnl specific binaries (ie "python3", "python2.7") in decending version | |
99 | dnl order. Thus, the highest version binary will be found first. | |
100 | dnl---- | |
101 | dnl | |
102 | dnl PC_PROG_PYTHON | |
103 | ||
e342891a BI |
104 | |
105 | dnl--PC_PYTHON_PROG_PYTHON_CONFIG------------------------------------- | |
106 | dnl In order to use some of the other macros, you also need the | |
107 | dnl python-config command, which will fall subject to the same problem | |
108 | dnl of python3-config being preferred to python2-config. This macro | |
109 | dnl will be automatically included if you use on of the macros that | |
110 | dnl depends on it, so you normally don't have to call it. However, if | |
111 | dnl you require a specific version, you can do something like the | |
112 | dnl following example. | |
113 | dnl---- | |
114 | dnl | |
115 | PC_PYTHON_PROG_PYTHON_CONFIG([python2-config]) | |
116 | if [[ "x$PYTHON_CONFIG" == "x" ]]; then | |
117 | PC_PYTHON_PROG_PYTHON_CONFIG([$PYTHON-config]) | |
118 | fi | |
119 | ||
120 | dnl---- | |
121 | dnl With the following set of macros, we implement an option | |
122 | dnl "--with-virtualenv", which the user can pass to the configure | |
123 | dnl script in order to install to a Virtualenv (AC_ARG_WITH). If the | |
124 | dnl option is specified by the user, then we check if the program is | |
125 | dnl available, checking both for "virtualenv" and "virtualenv2" | |
126 | dnl (AC_CHECK_PROGS) | |
127 | dnl---- | |
128 | dnl | |
129 | # Support installing to a virtualenv via the --with-virtualenv | |
130 | # configure flag | |
131 | AC_ARG_WITH([virtualenv], | |
a9dc855a | 132 | [AS_HELP_STRING([--with-virtualenv], [install to a Python virtualenv])], |
e342891a | 133 | [], |
a9dc855a | 134 | [with_virtualenv=no]) |
e342891a BI |
135 | AS_IF([test "x$with_virtualenv" != xno], |
136 | AC_CHECK_PROGS([VIRTUALENV], [virtualenv virtualenv3 virtualenv2], [no]) | |
137 | AS_IF([test "x$VIRTUALENV" = xno], | |
138 | [AC_MSG_FAILURE( | |
139 | [--with-virtualenv given but virtualenv could not be found])]), | |
140 | AC_SUBST([VIRTUALENV], [no])) | |
141 | AC_ARG_VAR([VIRTUALENV_FLAGS], [flags to pass to the virtualenv command]) | |
142 | ||
143 | dnl---- | |
144 | dnl If the program uses sphinx-build to build documentation, uncomment | |
145 | dnl this to create a SPHINXBUILD variable in the Makefile pointing to | |
146 | dnl the program. Thus, the user would specify | |
147 | dnl SPHINXBUILD=/path/to/sphinx-build as an argument to the configure | |
148 | dnl script. Since building the documentation should be optional, just | |
149 | dnl print a warning. If the program uses some other documentation | |
150 | dnl system, you can do something similar with it. | |
151 | dnl---- | |
152 | dnl | |
153 | # Check for sphinx-build | |
154 | AC_CHECK_PROGS([SPHINXBUILD], [sphinx-build sphinx-build3 sphinx-build2], [no]) | |
155 | AS_IF([test "x$SPHINXBUILD" = xno], | |
156 | AC_MSG_WARN(sphinx-build is required to build documentation)) | |
157 | ||
158 | ||
159 | dnl---- | |
160 | dnl These two are standard Autoconf macros which check for the | |
161 | dnl presence of some programs that we will use in the Makefile. | |
162 | dnl---- | |
163 | dnl | |
164 | AC_PROG_MKDIR_P | |
165 | AC_PROG_INSTALL | |
166 | ||
167 | # Check for a supported database program | |
c62d1744 | 168 | AC_PATH_PROG([SQLITE], [sqlite3]) |
d57dd89e | 169 | AC_PATH_PROG([POSTGRES], [psql]) |
c62d1744 | 170 | AS_IF([test "x$SQLITE" = x -a "x$POSTGRES" = "x"], |
26da3271 | 171 | [AC_MSG_ERROR([SQLite or PostgreSQL is required])]) |
e342891a | 172 | |
c62d1744 | 173 | |
a9dc855a CAW |
174 | dnl################################# |
175 | dnl Python installation properties # | |
176 | dnl################################# | |
177 | dnl | |
178 | dnl In this section, we test for various aspects of the Python | |
179 | dnl installation on the user's computer. | |
180 | ||
181 | dnl--PC_PYTHON_VERIFY_VERSION & PC_PYTHON_CHECK_VERSION---------------- | |
182 | dnl PC_PYTHON_VERIFY_VERSION is used to check if the version of the | |
183 | dnl discovered Python binary meets some requirement. The first argument | |
184 | dnl should be a Python-compatible numerical comparison operator (i.e. | |
185 | dnl "==", "<", ">=", etc.). The second argument should be the version to | |
186 | dnl test against. Finally, you may optionally provide actions to take if | |
187 | dnl it does (3rd argument) or if it does not (4th argument) meet the | |
188 | dnl requirement. | |
189 | dnl | |
190 | dnl PC_PYTHON_CHECK_VERSION simply fetches the version number of the | |
191 | dnl Python interpreter stored in the PYTHON variable | |
192 | dnl---- | |
193 | dnl | |
194 | dnl PC_PYTHON_VERIFY_VERSION([>=], [2.7.1], [AC_MSG_RESULT([yes])], | |
195 | dnl AC_MSG_FAILURE(Python 2 (python_min_ver+) is required)) | |
196 | ||
197 | ||
198 | dnl--PC_PYTHON_CHECK_PREFIX-------------------------------------------- | |
199 | dnl This macro finds out what Python thinks is the PREFIX | |
200 | dnl (i.e. /usr) and stores it in PYTHON_PREFIX. You probably shouldn't | |
201 | dnl use this and you should just stick to $prefix, but here it is | |
202 | dnl anyway. | |
203 | dnl---- | |
204 | dnl | |
205 | dnl PC_PYTHON_CHECK_PREFIX | |
206 | ||
207 | ||
208 | dnl--PC_PYTHON_CHECK_EXEC_PREFIX--------------------------------------- | |
209 | dnl The same as above but for $exec-prefix | |
210 | dnl---- | |
211 | dnl | |
212 | dnl PC_PYTHON_CHECK_EXEC_PREFIX | |
213 | ||
214 | ||
215 | dnl--PC_PYTHON_CHECK_PLATFORM------------------------------------------ | |
216 | dnl This macro checks what platform Python thinks this is (ie | |
217 | dnl "linux2") and stores it in PYTHON_PLATFORM | |
218 | dnl---- | |
219 | dnl | |
220 | dnl PC_PYTHON_CHECK_PLATFORM | |
221 | ||
222 | ||
223 | dnl--PC_PYTHON_CHECK_SITE_DIR------------------------------------------ | |
224 | dnl This checks where Python packages are installed (usually | |
225 | dnl /usr/lib/pythonX.Y/site-packages) and stores it in the variable | |
226 | dnl pythondir. | |
227 | dnl---- | |
228 | dnl | |
229 | dnl PC_PYTHON_CHECK_SITE_DIR | |
230 | ||
231 | ||
e342891a BI |
232 | dnl--PC_PYTHON_SITE_PACKAGE_DIR--------------------------------------- |
233 | dnl This uses PYTHON_SITE_DIR to construct a directory for this | |
234 | dnl project (ie $PYTHON_SITE_DIR/project_name) and stores it in | |
235 | dnl pkgpythondir. This value is used by Automake for installing Python | |
236 | dnl scripts. By default, this begins with $pythondir, unexpanded, to | |
237 | dnl provide compatibility with GNU Makefile specifications, allowing | |
238 | dnl the user to change the prefix from the commandline. | |
239 | dnl---- | |
240 | dnl | |
241 | PC_PYTHON_SITE_PACKAGE_DIR | |
242 | ||
a9dc855a CAW |
243 | |
244 | dnl--PC_PYTHON_CHECK_EXEC_DIR------------------------------------------ | |
245 | dnl Same as PC_PYTHON_CHECK_SITE_DIR but for $exec-prefix. Stored in | |
246 | dnl pyexecdir | |
247 | dnl---- | |
248 | dnl | |
249 | dnl PC_PYTHON_CHECK_EXEC_DIR | |
250 | ||
e342891a BI |
251 | dnl--PC_PYTHON_EXEC_PACKAGE_DIR---------------------------------------- |
252 | dnl Same as PC_PYTHON_SITE_PACKAGE_DIR but for $exec-prefix. Stored in | |
253 | dnl pkgpyexecdir | |
254 | dnl---- | |
255 | dnl | |
256 | PC_PYTHON_EXEC_PACKAGE_DIR | |
257 | ||
258 | ||
259 | dnl############################### | |
260 | dnl Checking Python capabilities # | |
261 | dnl############################### | |
262 | ||
263 | dnl--PC_PYTHON_CHECK_MODULE([PYTHON-MODULE], [ACTION-IF-PRESENT], | |
264 | dnl [ACTION-IF-ABSENT]) | |
265 | dnl This macro lets you check if a given Python module exists on the | |
266 | dnl system. | |
267 | dnl---- | |
268 | dnl | |
269 | dnl PC_PYTHON_CHECK_MODULE([foo]) | |
270 | ||
a9dc855a | 271 | |
e342891a BI |
272 | # Check for python-lxml module |
273 | PC_PYTHON_CHECK_MODULE([lxml], [], | |
274 | [AC_MSG_ERROR([python-lxml is required])]) | |
275 | ||
276 | # Check for the Python Imaging Library | |
277 | PC_PYTHON_CHECK_MODULE([Image], [], | |
278 | [AC_MSG_ERROR([Python Imaging Library is required])]) | |
279 | ||
280 | ||
a9dc855a CAW |
281 | dnl--PC_PYTHON_CHECK_FUNC([PYTHON-MODULE], [FUNCTION], [ARGS], |
282 | dnl [ACTION-IF-SUCCESSFUL], [ACTION-IF-FAIL]) | |
283 | dnl | |
284 | dnl This macro lets you test if a given function, possibly contained | |
285 | dnl in a given module, exists. If any exception is encountered when | |
286 | dnl calling this function, the check will fail. | |
287 | dnl---- | |
288 | dnl | |
289 | dnl # test if Python library foo can do bar() | |
290 | dnl PC_PYTHON_CHECK_FUNC([foo], [bar]) | |
291 | ||
292 | ||
293 | dnl Advanced notes: | |
294 | dnl m4/python.m4 implements Python as a language in Autoconf. This | |
295 | dnl means that you can use all the usual AC_LANG_* macros with Python | |
296 | dnl and it will behave as expected. In particular, this means that you | |
297 | dnl can run arbitrary Python code. For example: | |
298 | dnl | |
299 | dnl AC_LANG_PUSH(Python)[] | |
300 | dnl AC_RUN_IFELSE([AC_LANG_PROGRAM([dnl | |
301 | dnl # some code here | |
302 | dnl import foo | |
303 | dnl ], [dnl | |
304 | dnl # some more code here | |
305 | dnl foo.bar() | |
306 | dnl ])], [ACTION-IF-SUCCESSFUL], [ACTION-IF-FAILED]) | |
307 | dnl AC_LANG_POP(Python)[] | |
308 | dnl | |
309 | dnl As usual, AC_LANG_PROGRAM takes two arguments, PROLOG code and | |
310 | dnl MAIN code. The PROLOG code goes verbatim at the top of the file, | |
311 | dnl while the MAIN code is embedded in an if __name__ == "__main__": | |
312 | dnl block. Python's indentation rules complicate things, however. In | |
313 | dnl particular, you must be sure that all of the code in MAIN is | |
314 | dnl indented once by default. PROLOG code does not require this. | |
315 | ||
316 | ||
317 | dnl################################## | |
318 | dnl Python module build environment # | |
319 | dnl################################## | |
320 | dnl | |
321 | dnl Here we check for necessary information for building Python modules | |
322 | dnl written in C | |
323 | ||
324 | dnl--PC_PYTHON_CHECK_INCLUDES------------------------------------------ | |
325 | dnl This macro figures out the include flags necessary for loading the | |
326 | dnl Python headers (ie -I/usr/lib/python). The results are stored in | |
327 | dnl PYTHON_INCLUDES | |
328 | dnl---- | |
329 | dnl | |
330 | dnl PC_PYTHON_CHECK_INCLUDES | |
331 | ||
332 | ||
333 | dnl--PC_PYTHON_CHECK_HEADERS([ACTION-IF-PRESENT], [ACTION-IF-ABSENT])-- | |
334 | dnl Using the information found from PC_PYTHON_CHECK_INCLUDES, check | |
335 | dnl to make sure that Python.h can be loaded. Note that if you use | |
336 | dnl this, you don't strictly need to also include | |
337 | dnl PC_PYTHON_CHECK_INCLUDES. | |
338 | dnl---- | |
339 | dnl | |
340 | dnl PC_PYTHON_CHECK_HEADERS(,[AC_MSG_ERROR(could not find Python headers)]) | |
341 | ||
342 | ||
343 | dnl--PC_PYTHON_CHECK_LIBS---------------------------------------------- | |
344 | dnl This checks what LIBS flags are necessary to use the Python | |
345 | dnl libraries (ie -lpython). The results are stored in PYTHON_LIBS | |
346 | dnl---- | |
347 | dnl | |
348 | dnl PC_PYTHON_CHECK_LIBS | |
349 | ||
350 | ||
351 | dnl--PC_PYTHON_TEST_LIBS([FUNCTION-TO-TEST], [ACTION-IF-PRESENT], [ACTION-IF-ABSENT]) | |
352 | dnl This checks whether the LIBS flag for libpython discovered with | |
353 | dnl PC_PYTHON_CHECK_LIBS is loadable and if a given function can be | |
354 | dnl found in the library. You may use this to test for the presence of | |
355 | dnl features in the library. | |
356 | dnl---- | |
357 | dnl | |
358 | dnl PC_PYTHON_TEST_LIBS([PyObject_Print],, | |
359 | dnl [AC_MSG_ERROR(The Python library could not be loaded)]) | |
360 | dnl # Add PYTHON_LIBS to LIBS | |
361 | dnl LIBS="$LIBS $PYTHON_LIBS" | |
362 | ||
363 | ||
364 | dnl--PC_PYTHON_CHECK_CFLAGS-------------------------------------------- | |
365 | dnl This macro checks what Python thinks are the proper CFLAGS to | |
366 | dnl use and stores them in PYTHON_CFLAGS. Note that this info is only | |
367 | dnl available for Python versions which include a python-config tool | |
368 | dnl (2.5+). | |
369 | dnl---- | |
370 | dnl | |
371 | dnl PC_PYTHON_CHECK_CFLAGS | |
372 | dnl # Add PYTHON_CFLAGS to CFLAGS | |
373 | dnl CFLAGS="$CFLAGS $PYTHON_CFLAGS" | |
374 | ||
375 | ||
376 | dnl--PC_PYTHON_CHECK_LDFLAGS------------------------------------------- | |
377 | dnl The same as above but for LDFLAGS | |
378 | dnl---- | |
379 | dnl | |
380 | dnl PC_PYTHON_CHECK_LDFLAGS | |
381 | dnl # Add PYTHON_LDFLAGS to LDFLAGS | |
382 | dnl LDFLAGS="$LDFLAGS $PYTHON_LDFLAGS" | |
383 | ||
384 | ||
385 | dnl--PC_PYTHON_CHECK_EXTENSION_SUFFIX---------------------------------- | |
386 | dnl This checks for what Python expects the suffix of extension | |
387 | dnl modules to be (i.e. .cpython-32mu.so) and stores it in | |
388 | dnl PYTHON_EXTENSION SUFFIX. This information is only available for | |
389 | dnl Python 3+ | |
390 | dnl---- | |
391 | dnl | |
392 | dnl PC_PYTHON_CHECK_EXTENSION_SUFFIX | |
393 | ||
394 | ||
395 | dnl--PC_PYTHON_CHECK_ABI_FLAGS---------------------------------------- | |
396 | dnl This checks for the ABI flags used by Python (i.e. "mu") and | |
397 | dnl stores it in PYTHON_ABI_FLAGS. This information is only available | |
398 | dnl for Python 3+ | |
399 | dnl---- | |
400 | dnl | |
401 | dnl PC_PYTHON_CHECK_ABI_FLAGS | |
402 | ||
403 | ||
e342891a BI |
404 | dnl######### |
405 | dnl Finish # | |
406 | dnl######### | |
407 | ||
408 | dnl Define the files to be configured | |
00ed01b7 | 409 | AC_CONFIG_FILES([Makefile]) |
e342891a BI |
410 | dnl Generate config.status |
411 | AC_OUTPUT |