how to : GNU autotoolset [ autoconf + automake ]

what is GNU autotoolset aka GNU Development tools ?
- for automatic compilation/linking/license/documentation with ease.
- simplify the development of portable programs and simplify the building of programs that are distributed as source code

After you have the source code, you just need to edit one configure.ac at top directory and a Makefile.am at every directory.

autotoolset
[the autotoolkit dependency chart]

aclocal will create a aclocal.m4 which contains the definitions of autoconf macros. Now autoheader will create a config.h.in using aclocal.m4 and configure.ac(configure.in). autoconf will then generate the configure script from configure.ac. automake will create a Makefile.in file from Makefile.am. By running the configure script created above, Makefile will be created from Makefile.in. Also congig.h is created from configure.h.in by running the configure script. Now we have got the Makefile. We can run make or make install/uninstall/whatever and get our job done.

Ok. Try this example.

Say we have a directory structure -

..\helloworld………\–src………….\—-hello.c………….\—-hello.h………….\—-main.cc………….\foofiles………………\—-foo.c………………\—-foo.h

The dependency for creating the binary is like -

foo.c is compiled into a library called libfoo.a
This library is linked with main.cc and hello.cc to
create the binary called helloworld

You need to create configure.ac and Makefile.am
whereever needed such that the above binary helloworld
is creating using autotoolkit.

The above directory can be downloaded from here

The solution follows, but you should give it a try.

helloworld/configure.ac
configure will always remain more or less same most of the times. So do not get afraid by its complexity. Use it as a template. Just that you have to add all directories in AC_CONFIG_FILES.

AC_INIT( [HelloWorld], [0.1], [smr], [helloworld])
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h)
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_CONFIG_FILES( Makefile src/Makefile src/foofiles/Makefile)
AC_OUTPUT

helloworld/Makefile.am
Coz there is no source at the top level directory, So we only specify the subdirectory.

SUBDIRS = src

helloworld/src/Makefile.am
Here we have hello.cc and main.cc to compile using library foofiles/libfoo.a and again specify the subdirectories to consider.

bin_PROGRAMS = helloworld
helloworld_SOURCES = hello.h hello.cc main.cc
SUBDIRS = foofiles
LDADD = foofiles/libfoo.a

bin_PROGRAMS => all executable files to be compiled
lib_LIBRARIES = all libraries to be compile
prog_SOURCES, prog_LDADD, prog_LDFLAGS etc specifies the source files, libraries, and link flags for generation of executable named prog.
but for bin_PROGRAMS, lib_LIBRARIES, noinst_LIBRARIES the field before _ ie bin, lib or noinst, means the place used by make install/uninstall to store the binary or the library.

helloworld/src/foofiles/Makefile.am
Here we just create the libfoo.a directory. The macro AC_PROG_RANLIB defined in configure.ac will take care

noinst_LIBRARIES = libfoo.a
libfoo_a_SOURCES = foo.h foo.cc

thats it. after creating these file start compiling
$ aclocal
$ autoconf
$ autoheader
$ touch NEWS README AUTHORS ChangeLog
$ automake -a
$ ./configure
$ make
$ make install/uninstall/whatever

Isn’t it easy. Just go through the following links to get more on it -
GNU Automake By Example
autotut: Using GNU auto{conf,make,header}
Using Automake and Autoconf with C++
sources.redhat.com/autobook
Learning GNU development tools
How to : GNU Make environment

(c) 2005, smr

One Response to “how to : GNU autotoolset [ autoconf + automake ]”

  1. Jijo Jose Says:

    Very very interesting
    Thanks for your autoconf/makefile links …..
    best wishes for your future ………

    jijo jose

Leave a Reply