www.gibmonks.com

  Previous section   Next section

Practical Programming in Tcl & Tk, Third Edition
By Brent B. Welch

Table of Contents
Chapter 45.  Compiling Tcl and Extensions


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 45-3.

Creating configure templates can be complex and confusing. Mostly this is because a macro processor is being used to create a shell script. 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. Autoconf also has a standard library of m4 macros as part of its distribution. To use tcl.m4 for your own extension, you have some options. The most common way is to copy tcl.m4 into aclocal.m4 in your source directory. Or, you can copy both aclocal.m4 and tcl.m4 and have aclocal.m4 include tcl.m4. If necessary, you can add more custom macros to this aclocal.m4 file. Alternatively, you can copy the tcl.m4 file into the standard autoconf macro library.

The tcl.m4 file defines macros whose names begin with SC_ (for Scriptics). 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.2 configure script, but its use is deprecated.) The idea of tclConfig.sh was to capture some important results of Tcl's configure so 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 SC_ 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@

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)

      Previous section   Next section
    Top