[ Team LiB ] Previous Section Next Section

Using autoconf

Autoconf uses the m4 macro processor to translate the configure.in template into the configure script. The configure script is run by /bin/sh (i.e., the Bourne Shell). Creating the configure.in template is simplified by a standard m4 macro library that is distributed with autoconf. In addition, a Tcl distribution contains a tcl.m4 file that has additional autoconf macros. Among other things, these macros support the standard configure flags described in Table 48-3.

graphics/common_icon.gif

Configure macros are hard.


Creating configure templates can be complex and confusing. There are several layers of macro processing: m4 macros in configure.in, shell variables in configure, autoconf substitutions in Makefile.in, and Makefile variables. The days I have spent trying to change the Tcl configuration files really made me appreciate the simplicity of Tcl! Fortunately, there is now a standard set of Tcl-specific autoconf macros and a sample Tcl extension that uses them. By editing the configure.in and Makefile.in sample templates, you can ignore the details of what is happening under the covers.

The tcl.m4 File

The Tcl source distribution includes tcl.m4 and aclocal.m4 files. The autoconf program looks for the aclocal.m4 file in the same directory as the configure.in template. In our case, the aclocal.m4 file just includes the tcl.m4 file. In the TEA sample extension described later, the tcl.m4 file is kept in a tclconfig subdirectory.

The tcl.m4 file defines macros whose names begin with TEA (for Tcl Extension Architecture). The standard autoconf macro names begin with AC. This book does not provide an exhaustive explanation of all these autoconf macros. Instead, the important ones are explained in the context of the sample extension.

The tcl.m4 file replaces the tclConfig.sh found in previous versions of Tcl. (Actually, tclConfig.sh is still produced by the Tcl 8.4 configure script, but its use is deprecated.) The idea of tclConfig.sh was to capture some important results of Tcl's configure so that they could be included in the configure scripts used by an extension. However, it is better to recompute these settings when configuring an extension because, for example, different compilers could be used to build Tcl and the extension. So, instead of including tclConfig.sh into an extension's configure script, the extension's configure.in should use the TEA macros defined in the tcl.m4 file.

Makefile Templates

Autoconf implements yet another macro mechanism for the Makefile.in templates. The basic idea is that the configure script sets shell variables as it learns things about your system. Finally, it substitutes these variables into Makefile.in to create the working Makefile. The syntax for the substitutions in Makefile.in is:

@configure_variable_name@

For example, the --prefix command line value is put into the prefix shell variable, and then substituted into the Makefile.in template wherever @prefix@ occurs. Often, the make variable and the shell variable have the same name. For example, the following statement in Makefile.in passes the TCL_LIBRARY value determined by configure through to the Makefile:

TCL_LIBRARY = @TCL_LIBRARY@

The AC_SUBST macro specifies what shell variables should be substituted in the Makefile.in template. For example:

AC_SUBST(TCL_LIBRARY)
    [ Team LiB ] Previous Section Next Section