Learn Autoconf

Swe05
In these exercises you learn to make portable source code packages using autoconf by producing configuration scripts for the interpreter package.

Note: for help about Autoconf and Automake, look up info:autoconf and info:automake in the Gnome browser. Since Autoconf is a macro language for Unix shell code, you may also need help about the shell: man:bash.

A simple example of the use of autoconf is provided in the following package:

Unpack and build it using the following commands:

  gtar zxf hello-3.0.tar.gz
  cd hello-3.0
  autoconf
  ./configure --prefix=$HOME/tmp/hello-3.0
  make
  make install
  make dist

Study the files in the package to see how autoconf is used.

Note the following in Makefile.in

  • Parameters for filesystem layout (prefix, bindir, ...)
  • Parameters for versioning (VERSION, RPMRELEASE)
  • The files that should be distributed (DISTFILES)
  • targets for building the code (hello)
  • targets for deployment (install, uninstall, dist, rpm, ...)
  • targets for deriving the Makefile from Makefile.in

Note that the configure.in file defines

  • the versioning parameters
  • the files to be built by configure: Makefile and hello.spec

Note that hello.spec is a generic RPM spec file. The list of files does not specify any files, but only directories, i.e., all files in those directories are included in the rpm. Since the build is done in a buildroot this is safe.

Exercises

  1. Derive a Makefile.in from your Makefile in which you abstract from any platform specificities, such as installation directories. Be sure to support the following targets: install, uninstall, dist, clean.
  2. Write a configure.in that generates a Makefile from the Makefile.in and tests for availability of programs such as YACC and LEX.
  3. In the file abstract.c you can find the following code:
    #ifdef HAVE_BOEHM
        return GC_malloc(sizeof(Expr));
    #else
        return malloc(sizeof(Expr));
    #endif
    

    Note: please rename HAVE_BOEHM to HAVE_LIBGC; that will interact better with Autoconf. You should also add a line

    #include "config.h"
    
    to the top of abstract.c so that the config.h file created by configure actually gets used.

    In other words, the interpreter will use the Boehm garbage collector for memory allocation if the variable HAVE_LIBGC is defined, otherwise it will use the C standard function malloc. This is the kind of environment dependency that can be resolved using Autoconf.

    Using the AC_CHECK_LIB macro, check whether the library gc is available. If it exists, enable the HAVE_LIBGC variable in config.h and add -lgc to the LIBS makefile variable. Figure out what Autoconf macro does this for you/

    To test your configure script, run it normally (in which case it won't be able to find the library). A copy of the GC library has been installed in /praktikum/se/nix/Linux/current/lib, so you can allow configure to find the library as follows:

    LDFLAGS="-L /praktikum/se/nix/Linux/current/lib -lpthread" ./configure
    
    Make sure that the LDFLAGS variable (additional linker flags) gets passed to the linker in your Makefile.

  4. For building RPMs include an interpreter.spec.in file in the package, which is instantiated by configure to interpreter.spec with package name and version. Provide a make rpm target that builds an RPM from a distribution.

-- EelcoVisser - 16 Sep 2003
-- EelcoDolstra - 18 Nov 2002