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_INIT([foonly], [2.0], [email@example.com])
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 …
Set the variable LN_S to ‘ln –s’ if symbolic links work in the current working directory.
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:
a few shell variables:
Set output variable RANLIB to ‘ranlib’ if the program “ranlib” is found. This is required if any libraries are built in the package.
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”.
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: