3 dnl Copyright 2012, 2013 Brandon Invergo <brandon@invergo.net>
4 dnl 2014 MediaGoblin contributors (see MediaGoblin's AUTHORS)
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.
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.
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.
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
32 dnl Wherever pyconfigure-specific macros are used, extra comments are
33 dnl included to describe the macros.
35 dnl######################
36 dnl Package Information #
37 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:
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)
49 AC_INIT([mediagoblin], [0.7.1.dev], [cwebber@gnu.org])
53 dnl Load macros from the m4/ directory. If you plan to write new
54 dnl macros, put them in files in this directory.
57 AC_CONFIG_MACRO_DIR([m4])
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`])
65 dnl###########################
66 dnl Program/command support #
67 dnl###########################
69 dnl In this section, we check for the presence of important commands
72 AC_ARG_WITH([python3],
73 [AS_HELP_STRING([--with-python3], [Set up to use Python 3 by default.])],
76 AS_IF([test "x$with_python3" != xno],
77 AC_CHECK_PROGS([PYTHON], [python3.3], [none])
78 AS_IF([test "x$PYTHON" = xnone],
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],
84 [No acceptable pythons (2.7, 2.6) could be found])]))
88 dnl--A bit simpler python init----------------------------------------
89 dnl Expect python2.7 or python2.6 unless --with-python3 is given.
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.
109 dnl PC_INIT([3.3], [3.4])
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.
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.
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])
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"
150 # Support doing development in a virtualenv via the --with-virtualenv
152 AC_ARG_WITH([virtualenv],
153 [AS_HELP_STRING([--without-virtualenv], [install to a Python virtualenv])],
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],
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])
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.
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))
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.
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])])
198 dnl#################################
199 dnl Python installation properties #
200 dnl#################################
202 dnl In this section, we test for various aspects of the Python
203 dnl installation on the user's computer.
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
214 dnl PC_PYTHON_CHECK_VERSION simply fetches the version number of the
215 dnl Python interpreter stored in the PYTHON variable
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))
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
229 dnl PC_PYTHON_CHECK_PREFIX
232 dnl--PC_PYTHON_CHECK_EXEC_PREFIX---------------------------------------
233 dnl The same as above but for $exec-prefix
236 dnl PC_PYTHON_CHECK_EXEC_PREFIX
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
244 dnl PC_PYTHON_CHECK_PLATFORM
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
253 dnl PC_PYTHON_CHECK_SITE_DIR
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.
265 dnl PC_PYTHON_SITE_PACKAGE_DIR
268 dnl--PC_PYTHON_CHECK_EXEC_DIR------------------------------------------
269 dnl Same as PC_PYTHON_CHECK_SITE_DIR but for $exec-prefix. Stored in
273 dnl PC_PYTHON_CHECK_EXEC_DIR
275 dnl--PC_PYTHON_EXEC_PACKAGE_DIR----------------------------------------
276 dnl Same as PC_PYTHON_SITE_PACKAGE_DIR but for $exec-prefix. Stored in
280 dnl PC_PYTHON_EXEC_PACKAGE_DIR
283 dnl###############################
284 dnl Checking Python capabilities #
285 dnl###############################
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
293 dnl PC_PYTHON_CHECK_MODULE([foo])
296 dnl # Check for python-lxml module
297 dnl PC_PYTHON_CHECK_MODULE([lxml], [],
298 dnl [AC_MSG_ERROR([python-lxml is required])])
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])])
305 dnl--PC_PYTHON_CHECK_FUNC([PYTHON-MODULE], [FUNCTION], [ARGS],
306 dnl [ACTION-IF-SUCCESSFUL], [ACTION-IF-FAIL])
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.
313 dnl # test if Python library foo can do bar()
314 dnl PC_PYTHON_CHECK_FUNC([foo], [bar])
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:
323 dnl AC_LANG_PUSH(Python)[]
324 dnl AC_RUN_IFELSE([AC_LANG_PROGRAM([dnl
328 dnl # some more code here
330 dnl ])], [ACTION-IF-SUCCESSFUL], [ACTION-IF-FAILED])
331 dnl AC_LANG_POP(Python)[]
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.
341 dnl##################################
342 dnl Python module build environment #
343 dnl##################################
345 dnl Here we check for necessary information for building Python modules
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
354 dnl PC_PYTHON_CHECK_INCLUDES
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.
364 dnl PC_PYTHON_CHECK_HEADERS(,[AC_MSG_ERROR(could not find Python headers)])
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
372 dnl PC_PYTHON_CHECK_LIBS
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.
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"
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
395 dnl PC_PYTHON_CHECK_CFLAGS
396 dnl # Add PYTHON_CFLAGS to CFLAGS
397 dnl CFLAGS="$CFLAGS $PYTHON_CFLAGS"
400 dnl--PC_PYTHON_CHECK_LDFLAGS-------------------------------------------
401 dnl The same as above but for LDFLAGS
404 dnl PC_PYTHON_CHECK_LDFLAGS
405 dnl # Add PYTHON_LDFLAGS to LDFLAGS
406 dnl LDFLAGS="$LDFLAGS $PYTHON_LDFLAGS"
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
416 dnl PC_PYTHON_CHECK_EXTENSION_SUFFIX
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
425 dnl PC_PYTHON_CHECK_ABI_FLAGS
428 dnl--MediaGoblin specific commands/variables ------------------------
435 dnl Define the files to be configured
436 AC_CONFIG_FILES([Makefile])
437 AC_CONFIG_FILES([env], [chmod +x env])
439 dnl Generate config.status