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