Next: The Future of aclocal
, Previous: Writing your own aclocal macros, Up: Scanning configure.ac [Contents][Index]
Feature tests offered by Autoconf do not cover all needs. People often have to supplement existing tests with their own macros, or with third-party macros.
There are two ways to organize custom macros in a package.
The first possibility (the historical practice) is to list all your
macros in acinclude.m4. This file will be included in
aclocal.m4 when you run aclocal
, and its macro(s) will
henceforth be visible to autoconf
. However if it contains
numerous macros, it will rapidly become difficult to maintain, and it
will be almost impossible to share macros between packages.
The second possibility, which we do recommend, is to write each macro
in its own file and gather all these files in a directory. This
directory is usually called m4/. To build aclocal.m4,
one should therefore instruct aclocal
to scan m4/.
From the command line, this is done with aclocal -I m4
. The
top-level Makefile.am should also be updated to define
ACLOCAL_AMFLAGS = -I m4
ACLOCAL_AMFLAGS
contains options to pass to aclocal
when aclocal.m4 is to be rebuilt by make
. This line is
also used by autoreconf
(see Using autoreconf
to Update configure Scripts in The Autoconf Manual) to run aclocal
with suitable
options, or by autopoint
(see Invoking the autopoint
Program in GNU gettext tools)
and gettextize
(see Invoking the
gettextize
Program in GNU gettext tools) to locate
the place where Gettext’s macros should be installed. So even if you
do not really care about the rebuild rules, you should define
ACLOCAL_AMFLAGS
.
When aclocal -I m4
is run, it will build a aclocal.m4
that m4_include
s any file from m4/ that defines a
required macro. Macros not found locally will still be searched in
system-wide directories, as explained in Macro search path.
Custom macros should be distributed for the same reason that
configure.ac is: so that other people have all the sources of
your package if they want to work on it. Actually, this distribution
happens automatically because all m4_include
d files are
distributed.
However there is no consensus on the distribution of third-party
macros that your package may use. Many libraries install their own
macro in the system-wide aclocal
directory (see Writing your own aclocal macros). For instance Guile ships with a file called
guile.m4 that contains the macro GUILE_FLAGS
which can
be used to define setup compiler and linker flags appropriate for
using Guile. Using GUILE_FLAGS
in configure.ac will
cause aclocal
to copy guile.m4 into
aclocal.m4, but as guile.m4 is not part of the project,
it will not be distributed. Technically, that means a user which
needs to rebuild aclocal.m4 will have to install Guile first.
This is probably OK, if Guile already is a requirement to build the
package. However, if Guile is only an optional feature, or if your
package might run on architectures where Guile cannot be installed,
this requirement will hinder development. An easy solution is to copy
such third-party macros in your local m4/ directory so they get
distributed.
Next: The Future of aclocal
, Previous: Writing your own aclocal macros, Up: Scanning configure.ac [Contents][Index]