Node: Extending aclocal, Previous: Macros, Up: configure



Writing your own aclocal macros

The aclocal program doesn't have any built-in knowledge of any macros, so it is easy to extend it with your own macros.

This can be used by libraries which want to supply their own Autoconf macros for use by other programs. For instance the gettext library supplies a macro AM_GNU_GETTEXT which should be used by any package using gettext. When the library is installed, it installs this macro so that aclocal will find it.

A macro file's name should end in .m4. Such files should be installed in $(datadir)/aclocal. This is as simple as writing:

     aclocaldir = $(datadir)/aclocal
     aclocal_DATA = mymacro.m4 myothermacro.m4
     

A file of macros should be a series of properly quoted AC_DEFUN's (see Macro Definitions). The aclocal programs also understands AC_REQUIRE (see Prerequisite Macros), so it is safe to put each macro in a separate file. Each file should have no side effects but macro definitions. Especially, any call to AC_PREREQ should be done inside the defined macro, not at the beginning of the file.

Starting with Automake 1.8, aclocal will warn about all underquoted calls to AC_DEFUN. We realize this will annoy a lot of people, because aclocal was not so strict in the past and many third party macros are underquoted; and we have to apologize for this temporary inconvenience. The reason we have to be stricter is that a future implementation of aclocal will have to temporary include all these third party .m4 files, maybe several times, even those which are not actually needed. Doing so should alleviate many problem of the current implementation, however it requires a stricter style from the macro authors. Hopefully it is easy to revise the existing macros. For instance

     # bad style
     AC_PREREQ(2.57)
     AC_DEFUN(AX_FOOBAR,
     [AC_REQUIRE([AX_SOMETHING])dnl
     AX_FOO
     AX_BAR
     ])
     

should be rewritten as

     AC_DEFUN([AX_FOOBAR],
     [AC_PREREQ(2.57)dnl
     AC_REQUIRE([AX_SOMETHING])dnl
     AX_FOO
     AX_BAR
     ])
     

Wrapping the AC_PREREQ call inside the macro ensures that Autoconf 2.57 will not be required if AX_FOOBAR is not actually used. Most importantly, quoting the first argument of AC_DEFUN allows the macro to be redefined or included twice (otherwise this first argument would be expansed during the second definition).

If you have been directed here by the aclocal diagnostic but are not the maintainer of the implicated macro, you will want to contact the maintainer of that macro. Please make sure you have the last version of the macro and that the problem already hasn't been reported before doing so: people tend to work faster when they aren't flooded by mails.