Autoconf
lastmod 2020-02-28created 2015-02-1516 edits
How to install
Macros
-
AC_PREREQ([VERSION]) - Specifies the version of autoconf to use. (e.g.
AC_PREREQ([2.59]))
-
AC_INIT (package, version, [bug-report], [tarname], [url]) - https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Initializing-configure.html
- Information about the Package to be built. (e.g.
AC_INIT([hello], [1.0.0], [[email protected]])) - The following M4 macros (e.g., AC_PACKAGE_NAME), output variables (e.g., PACKAGE_NAME), and preprocessor symbols (e.g., PACKAGE_NAME), are defined by AC_INIT:
- AC_PACKAGE_NAME, PACKAGE_NAME
- AC_PACKAGE_TARNAME, PACKAGE_TARNAME
- AC_PACKAGE_VERSION, PACKAGE_VERSION
- AC_PACKAGE_STRING, PACKAGE_STRING
- AC_PACKAGE_BUGREPORT, PACKAGE_BUGREPORT
- AC_PACKAGE_URL, PACKAGE_URL
-
AC_SUBST (variable, [value]) - Create an output variable from a shell variable.
-
AC_CHECK_TYPES (types, [action-if-found], [action-if-not-found], [includes = ‘AC_INCLUDES_DEFAULT’]) - https://www.gnu.org/software/autoconf/manual/autoconf-2.64/html_node/Generic-Types.html
- For each type of the types that is defined, define HAVE_type (in all capitals).
-
AC_LANG_PROGRAM (prologue, body) - https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Generating-Sources.html
- Expands into a source file which consists of the prologue, and then body as body of the main function (e.g., main in C). Since it uses
AC_LANG_SOURCE, the features of the latter are available.
-
AC_COMPILE_IFELSE (input, [action-if-true], [action-if-false]) - https://www.gnu.org/software/autoconf/manual/autoconf-2.66/html_node/Running-the-Compiler.html
- Run the compiler and compilation flags of the current language (see Language Choice) on the input, run the shell commands action-if-true on success, action-if-false otherwise. The input can be made by
AC_LANG_PROGRAMand friends.
Library Files
Use AC_CHECK_LIB and AC_SEARCH_LIBS.
Example
Change output variables
If you want strings of the form @OPENSSL_LIBS@ to be substituted in a Makefile, use AC_SUBST. Enter the code below in configure.ac.
# Check for usable OpenSSL
have_openssl=yes
OPENSSL_INCLUDES="/usr/local/c2core/include"
OPENSSL_LDFLAGS="/usr/local/c2core/lib/libssl.so /usr/local/c2core/lib/libcrypto.so"
OPENSSL_LIBS=""
AC_SUBST([OPENSSL_INCLUDES])
AC_SUBST([OPENSSL_LIBS])
AC_SUBST([OPENSSL_LDFLAGS])
Then update the configure file with the command below.
zlib example
# Check for zlib.
HAVE_ZLIB=0
AS_IF([test "$with_zlib" != no], [
AC_MSG_CHECKING([zlib version])
# First check the zlib header version.
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[
#include <zlib.h>
#if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
# error zlib version too old
#endif
]], [])], [
AC_MSG_RESULT([ok (1.2.0.4 or later)])
# Also need to add -lz to the linker flags and make sure this succeeds.
AC_SEARCH_LIBS([zlibVersion], [z], [
AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.])
HAVE_ZLIB=1
], [
AS_IF([test "$with_zlib" != check], [
AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found])
])
])
], [
AS_IF([test "$with_zlib" = check], [
AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)])
], [
AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)])
])
])
])
AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])
Troubleshooting
undefined AC_PROG_LIBTOOL
When using configure or autoreconf, etc., the following error may occur.
configure.in:14: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1
In this case, you need to install libtool.
Favorite site
Pages that link here