Previous: , Up: Adding options to a configure script   [Contents][Index]

11.7 Setting Site Defaults

TODO: Where to put this?

Autoconf-generated configure scripts allow your site to provide default values for some configuration values. You do this by creating site- and system-wide initialization files.

If the environment variable CONFIG_SITE is set, configure uses its value as the name of a shell script to read; it is recommended that this be an absolute file name. Otherwise, it reads the shell script prefix/share/ if it exists, then prefix/etc/ if it exists. Thus, settings in machine-specific files override those in machine-independent ones in case of conflict.

Site files can be arbitrary shell scripts, but only certain kinds of code are really appropriate to be in them. Because configure reads any cache file after it has read any site files, a site file can define a default cache file to be shared between all Autoconf-generated configure scripts run on that system (see Cache Files). If you set a default cache file in a site file, it is a good idea to also set the output variable CC in that site file, because the cache file is only valid for a particular compiler, but many systems have several available.

You can examine or override the value set by a command line option to configure in a site file; options set shell variables that have the same names as the options, with any dashes turned into underscores. The exceptions are that --without- and --disable- options are like giving the corresponding --with- or --enable- option and the value ‘no’. Thus, --cache-file=localcache sets the variable cache_file to the value ‘localcache’; --enable-warnings=no or --disable-warnings sets the variable enable_warnings to the value ‘no’; --prefix=/usr sets the variable prefix to the value ‘/usr’; etc.

Site files are also good places to set default values for other output variables, such as CFLAGS, if you need to give them non-default values: anything you would normally do, repetitively, on the command line. If you use non-default values for prefix or exec_prefix (wherever you locate the site file), you can set them in the site file if you specify it with the CONFIG_SITE environment variable.

You can set some cache values in the site file itself. Doing this is useful if you are cross-compiling, where it is impossible to check features that require running a test program. You could “prime the cache” by setting those values correctly for that system in prefix/etc/ To find out the names of the cache variables you need to set, see the documentation of the respective Autoconf macro. If the variables or their semantics are undocumented, you may need to look for shell variables with ‘_cv_’ in their names in the affected configure scripts, or in the Autoconf M4 source code for those macros; but in that case, their name or semantics may change in a future Autoconf version.

The cache file is careful to not override any variables set in the site files. Similarly, you should not override command-line options in the site files. Your code should check that variables such as prefix and cache_file have their default values (as set near the top of configure) before changing them.

Here is a sample file /usr/share/local/gnu/share/ The command ‘configure --prefix=/usr/share/local/gnu’ would read this file (if CONFIG_SITE is not set to a different file).

# /usr/share/local/gnu/share/ for configure
# Change some defaults.
test "$prefix" = NONE && prefix=/usr/share/local/gnu
test "$exec_prefix" = NONE && exec_prefix=/usr/local/gnu
test "$sharedstatedir" = '${prefix}/com' && sharedstatedir=/var
test "$localstatedir" = '${prefix}/var' && localstatedir=/var
test "$runstatedir" = '${localstatedir}/run' && runstatedir=/run

# Give Autoconf 2.x generated configure scripts a shared default
# cache file for feature test results, architecture-specific.
if test "$cache_file" = /dev/null; then
  # A cache file is only valid for one C compiler.

Another use of is for priming the directory variables in a manner consistent with the Filesystem Hierarchy Standard (FHS). Once the following file is installed at /usr/share/, a user can execute simply ./configure --prefix=/usr to get all the directories chosen in the locations recommended by FHS.

# /usr/share/ for FHS defaults when installing below /usr,
# and the respective settings were not changed on the command line.
if test "$prefix" = /usr; then
  test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
  test "$sharedstatedir" = '${prefix}/com' && sharedstatedir=/var
  test "$localstatedir" = '${prefix}/var' && localstatedir=/var

Likewise, on platforms where 64-bit libraries are built by default, then installed in /usr/local/lib64 instead of /usr/local/lib, it is appropriate to install /usr/local/share/

# /usr/local/share/ for platforms that prefer
# the directory /usr/local/lib64 over /usr/local/lib.
test "$libdir" = '${exec_prefix}/lib' && libdir='${exec_prefix}/lib64'

Previous: , Up: Adding options to a configure script   [Contents][Index]