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