| Ludicrous Home > Manuals and HowTo's > GNU Build System (configure, automake, ...) |
|
GNU Build System (configure, automake, ...)
Contents
Introduction to the tools of the automatic makefile generation suite.Several tools and files are needed for the automatic makefile generation. ![]() autoscanExamines source files in a given directory tree.
autoconfThis is an alphabetical list of the autoconf macros. automakeautoheaderaclocalScans the system and given folders for m4 macro language files, and merges all needed macros into one file that can be used by the autoconf tool. autoreconfInstalling the various components of the GNU Build System can be tedious: running autopoint for Gettext, automake for `Makefile.in' etc. in each directory. autoreconf runs autoconf, autoheader, aclocal, automake, libtoolize, and autopoint (when appropriate) repeatedly to update the GNU Build System in the specified directories and their subdirectories. configureThis isn't exaclty a tool, but a configuration script generated by some of the above tools. autoupdateUpdates an old configure.ac if preset, or else configure.in, to the syntax of the current version of autoconf.
Steps for creating the automatic makefile generation suite
Additional steps
Automatic generationIt is recommended to write a small shell script to perform the above steps automatically. Here we give an example for such a script. autogen.sh#!/bin/sh if ! test -d config; then mkdir config; fi # For some, when aclocal is launched from autoreconf, the macros in # the m4 folder aren't included, so we launch it here ourselves. aclocal --install -I config --verbose autoreconf --install --verbose if ! test -d build; then mkdir build; fi cd build ../configure make
Tweaking the compilation processHere we give some hints, how to influence in the complete compilation process. configure.acAbsolutely necessaryThe template generated by autoscan needs some modifications, otherwise configure will fail.
Should be done
Could be done
Makefile.amCreating the templates for the Makefile generation is much more easier than the one for the configure script. Makefile.am pointing to subdirectoriesThis is the easiest one. It could be just like this example: SUBDIRS = \ subfolder1 \ subfolder2 Each subdirectory must have its own Makefile.am. Makefile.am for source filesThese are a bit more complicated than the subfolder ones.
Compile programsThe *_PROGRAMS variables specify programs to be built. For each program listed, program_SOURCES lists the source files. Sounds complicated? Look at this example, to see it isn't: bin_PROGRAMS = myProggy anotherProggy EXTRA_PROGRAMS = testProggies myProggy_SOURCES = myMain.cpp anotherProggy_SOURCES = another.cpp testProggies_SOURCES = test.cpp testProggies_CPPFLAGS = -w2 -DTEST=1 Compile flagsThe last line of the above example shows, how to declare specific compiler flags for each program. AM_CPPFLAGS = -w3 \ -I@top_srcdir@/include \ -I@srcdir@/include> \ -I@srcdir@/anothersubfolder/include
Link against librariesYou can define that all programs link against some libraries or specify them for each program: LDADD = \ ../src/libcommon.a \ $(BOOST_PROGRAM_OPTIONS_LIB) myProggy_LDADD = specific.la
Compile librarieslib_LIBRARIES = \ libmyLib.a libmyLib_a_SOURCES = myLib.cpp libmyLib_a_LDFLAGS = -version-info 0:0:0
Linker flagsThe last line of the above example shows, how to declare specific compiler flags for each program or library. ConditionalsBefore using a conditional in the Makefiles, you must define it by using AM_CONDITIONAL in the configure.ac file: AC_ARG_ENABLE(debug,
[ --enable-debug Turn on debugging],
[case "${enableval}" in
yes) debug=true ;;
no) debug=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
esac],[debug=false])
AM_CONDITIONAL(DEBUG, test x$debug = xtrue)
Here is an example of how to use that conditional in `Makefile.am': if DEBUG DBG = debug else DBG = endif noinst_PROGRAMS = $(DBG) Conditionals do not interact very smoothly with the append operator. In particular, an append must happen in the same conditional context as the original assignment. This means that the following will not work: DBG = foo if DEBUG DBG += bar endif DEBUG The behaviour which is probably desired in this situation can be obtained using a temporary variable: if DEBUG TMP_DBG = bar endif DEBUG DBG = foo $(TMP_DBG) More information can be found in the online manual. Nesting configure projectsDeep packages have a configure.ac in each subdirectory, and it looks very much like an aggregate of programs which just happen to be distributed together. For example, suppose you want to include a project in your project tree that already has a configure.ac. This is what you'll have to add to your files:
Other useful stuffpkg-configpkg-config is a system for managing library compile and link flags that works with automake and autoconf.
This information can be directly used in the configure.ac script: PKG_CHECK_MODULES([ACE], [ACE >= 5.4.4]) dnl PKG_CHECK_MODULES([ACE], [ACE = 5.4.7]) AC_SUBST([ACE_CFLAGS]) AC_SUBST([ACE_LIBS]) You can then use this information in the Makefile.am like this: AM_CPPFLAGS = @ACE_CFLAGS@ AM_LDFLAGS = @ACE_LIBS@ Useful links
|
| Document generated by Atlassian Confluence, last changed on jun 20, 2007 by Sven Rieke |