Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

14.7 Setting Site Defaults

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. Otherwise, it reads the shell script prefix/share/config.site if it exists, then prefix/etc/config.site 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/config.site. To find out the names of the cache variables you need to set, look for shell variables with ‘_cv_’ in their names in the affected configure scripts, or in the Autoconf M4 source code for those macros.

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/config.site. The command ‘configure --prefix=/usr/share/local/gnu’ would read this file (if CONFIG_SITE is not set to a different file).

     # config.site 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
     
     # 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
       cache_file="$prefix/var/config.cache"
       # A cache file is only valid for one C compiler.
       CC=gcc
     fi

 
 
  Published under the terms of the GNU General Public License Design by Interspire