Because of the diversity of the Unix system, the famous ‘configure’ script should be runned before compiling the source code on the system. The script check your system environment such as where your library locate and help you decide which part of the source code should be complied. This small simple qucik refrence is made by myself when I started to work as Software Engineer.
You may wonder how this complex script generated. The following chart shows the fact.
user input files optional input processes output files ================ ============== ========= ============ aclocal.m4 - - - - - -. V .--------, configure.in ----------------------->|autoconf|------> configure `--------'
So the “configure” script is generated from `configure.in’ by autoconf. Then Another question came out that what is `configure.in’. In general, m4 macros consist the `configure.in’ file. One `configure.in’ file’s structure often likes this:
AC_INIT(file) checks for programs checks for libraries checks for header files checks for typedefs checks for structures checks for compiler characteristics checks for library functions checks for system services AC_OUTPUT([file...])
Let’s see a very small `configure.in’ file:
AC_PREREQ(2.59)
AC_INIT([foonly], [2.0], [gary@gnu.org])
AM_INIT_AUTOMAKE([1.9 foreign])
AC_PROG_CC
AM_PROG_LEX
AC_PROG_YACC
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
Get puzzled about these m4 macros? Here are some macros I used in my project. List here for myself to easy to reference.
1. AC_PREREQ (version)
Ensure that a recent enough version of Autoconf is being used. Call it before AC_INIT.
2. AC_INIT (package, version, [bug-report], [tarname])
Process any command-line arguments and perform various initializations and verifications.
3. AC_CONFIG_HEADERS (header . . . , [cmds], [init-cmds])
As an alternative to passing ‘-D’ options to the compiler, configure scripts can create a C header file containing ‘#define’ directives. This macro selects this kind of output. It should be called right after AC_INIT.
4. AC_DEFINE (variable, value, [description])
AC_DEFINE_UNQUOTED (variable, value, [description])
Define a C compile preprocessor variable. To use a shell variable, use AC_DEFINE_UNQUOTED instead of AC_DEFINE.
5. AC_CONFIG_FILES (file . . . , [cmds], [init-cmds])
Make AC_OUTPUT create each ‘file’ by copying an input file (by default ‘file.in’),
substituting the output variable values.
6. AC_PROG_ family
a) AC_PROG_CC [compiler-search-list]
Determine a C compiler to use. The default value of CFLAGS is set when called.
b) AC_PROG_CXX [compiler-search-list]
Determine a C++ compiler to use. The default value of CXXFLAGS is set when called.
c) AC_PROG_F77, AC_PROG_YACC …
d) AC_PROG_LN_S
Set the variable LN_S to ‘ln –s’ if symbolic links work in the current working directory.
e) AC_PROG_LIBTOOL
Use the libtool to build your project! Do not ues AC_PROG_RANLIB if you use this macro. Since Libtool will be handling all of the libraries.
Extra macros for Libtool:
i. AC_DISABLE_FAST_INSTALL
ii. AC_DISABLE_SHARED
iii. AC_DISABLE_STATIC
a few shell variables:
f) AC_PROG_RANLIB
Set output variable RANLIB to ‘ranlib’ if the program “ranlib†is found. This is required if any libraries are built in the package.
7. AC_SUBST(name)
This macro takes a single argument, which is the name of a shell variable. When configure generates the files listed in AC_OUTPUT (e.g., `Makefile’), it will substitute the variable’s value (at the end of the configure run — the value can be changed after AC_SUBST is called) anywhere a string of the form `@name@’ is seen.
8. AC_CHECK_LIB (library, function, [if-found], [if-not-found], [other-libraries])
This looks for the named function in the named library specified by its base name. For instance the math library, `libm.a’, would be named simply `m’. If the function is found in the library `foo’, then the C preprocessor macro HAVE_LIBFOO is defined.
9. AC_OUTPUT(Makefile … )
Specify the files which you want to generate by “configureâ€.
10. AC_CONFIG_AUX_DIR(dir)
Specify a directory to store many of the GNU auto tools intermediate files.
See an alphabetical list of each Autoconf macro here and some useful resource:
http://sourceware.org/autobook/
http://www.gnu.org/software/autoconf/