Gnuautotools

External pages

Gnu Autotools

 make DISTDIR=/destfolder install
installs under /destfolder/$PREFIX

A minimal project consists of configure.ac and Makefile.am. The extension ac stands for autoconf and am for automake. The configure.ac file is being transformed by autoconf into configure script. The Makefile.am is being transformed by automake into Makefile.in. The latter is being used to generate the final Makefile. The config.h is being generate from the template config.h.in by autoheader.

hello world

 // main.c
 #if HAVE_CONFIG_H
 #include <config.h>
 #else
 #error "You should not compile outside autotools."
 #endif 

 int main() {
  printf("Hello world! This is " PACKAGE_STRING "!\n");
  return 0;
 }

 // Makefile.am
 bin_PROGRAMS=    hello
 hello_SOURCE=   main.c

configure.ac

 AC_INIT([foobar], [1.0], [me@mail.com], [program_package_name])
 AC_CONFIG_SRCDIR([src/main.c])
 AC_CONFIG_HEADER(config.h)
 AM_INIT_AUTOMAKE
 AC_PROG_CC
or AC_PROG_CXX for c++
 AC_HEADER_STDC

 AC_SUBST(CFLAGS)
 AC_SUBST(CPPFLAGS)
 AC_SUBST(LDFLAGS)

 LIBC_REQUIRED=2.5
 FOO_MODULES="libc-2.5 >= $LIBC_REQUIRED"
 PKG_CHECK_MODULES(FOO, $FOO_MODULES)
 AC_SUBST(FOO_CFLAGS)
 AC_SUBST(FOO_LIBS)

 #AC_CONFIG_FILES([Makefile src/Makefile])
 AC_OUTPUT(Makefile src/Makefile)

For each file which autoconf should create it must exist a template file with suffix ".in". It is not necessary to create these file per hand.

Makefile.am

 SUBDIRS = src pixmaps
 desktopdir = $(datadir)/applications
 bin_PROGRAMS=smallexample
 smallexample_SOURCES=main.c

aclocal

Then you can run aclocal to create the macro file aclocal.m4

autoheader

Afterwards run the program autoheader to create the file config.h.in from which the configure script creates the config.h.

automake

 automake --add-missing -gnu
creates AUTHORS,ChangeLog,COPYING,INSTALL,NEWS,README and Makefile.in from Makefile.am template.

autoconf

creates configure from configure.ac as well as autom4te.ache.

configure

default options are:

make

has default targets: all, clean, distclean, maintainer-clean, install, install-strip, dist, distcheck uninstall