Setting site defaults using CONFIG_SITE

Another way to pass options to configure is to use a site configuration file. This file will be “sourced” by configure to set some values and options, and will save you some bytes on your command line when you’ll invoke configure.

First, write a config.site file:

# -*- shell-script -*-

echo "Loading config.site for $PACKAGE_TARNAME"
echo "(srcdir: $srcdir)"
echo

package=$PACKAGE_TARNAME

echo "config.site: $package"
echo

# Configuration specific to EPITA KB machines (GNU/Linux on x86-64).
case $package in
  tc)
    # Turn off optimization when building with debugging information
    # (the build dir must have ``debug'' in its name).
    case `pwd` in
      *debug*) :
        : ${CFLAGS="-ggdb -O0"}
        : ${CXXFLAGS="-ggdb -O0 -D_GLIBCXX_DEBUG"}
      ;;
    esac
    # Help configure to find the Boost libraries on NetBSD.
    if test -f /usr/pkg/include/boost/config.hpp; then
      with_boost=/usr/pkg/include
    fi

    # Set CC, CXX, BISON, MONOBURG, and other programs as well.
    : ${CC=/u/prof/acu/pub/NetBSD/bin/gcc}
    : ${CXX=/u/prof/acu/pub/NetBSD/bin/g++}
    : ${BISON=/u/prof/yaka/bin/bison}
    : ${MONOBURG=/u/prof/yaka/bin/monoburg}
    # ...
  ;;
esac

set +vx

Then, set the environment variable CONFIG_SITE to the path to this file, and run configure:

$ export CONFIG_SITE="$HOME/src/config.site"
$ ../configure

or if you use a C-shell:

$ setenv CONFIG_SITE "$HOME/src/config.site"
$ ../configure

This is useful when invoking make distcheck: you don’t need to pollute your environment, nor use Automake’s DISTCHECK_CONFIGURE_FLAGS (Making a Tarball).

Of course, you can have several config.site files, one for each architecture you work on for example, and set the CONFIG_SITE variable according to the host/system.