Archive for November, 2009

A simple description of how to use Autotools

November 9, 2009

From

http://smalltalk.gnu.org/blog/bonzinip/all-you-should-really-know-about-autoconf-and-automake

A very good description of a simple use of autoconf and automake:

The problem with autotools is that it is used for complicated things, and people cut-and-paste complicated things even when they ought to be simple. 99% of people just need a way to access .pc files and generate juicy Makefiles, the portability part is taken care by glib, sdl and so on.

The most basic autotools setup is 9 lines.

configure.ac:

AC_INIT([package], [version])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_HEADERS([config.h])     # not really needed
AC_PROG_CC                        # or AC_PROG_CXX
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

Makefile.am:

bin_PROGRAMS = hello
hello_SOURCES = hello.c

And you’re ready for:

$ autoreconf -fvi
$ ./configure
$ make

On top of this, for each package you need, you add:

PKG_CHECK_MODULES([cairo], [cairo])
PKG_CHECK_MODULES([fontconfig], [fontconfig])

AM_CFLAGS = $(cairo_CFLAGS) $(fontconfig_CFLAGS)
LIBS += $(cairo_LIBS) $(fontconfig_LIBS)

respectively in configure.ac (after AC_PROG_CC) and Makefile.am. Is that complicated?