Home > misc > A simple autotool template

A simple autotool template

September 17th, 2011 Leave a comment Go to comments

Every now and then, you feel a big urge to start hacking on a small thingy and need to create Makefiles for it. Turns out that the autotools won’t be that intrusive when we are talking about small programs and you get do a reasonable job with a few lines, first the configure.ac file:

# autoconf
AC_PREREQ(2.59)
AC_INIT([fart], [0.0.1], [damien.lespiau@gmail.com])
AC_CONFIG_MACRO_DIR([build])
AC_CONFIG_AUX_DIR([build])
AC_CONFIG_SRCDIR([fart.c])
AC_CONFIG_HEADERS([config.h])

# automake
AM_INIT_AUTOMAKE([1.11 -Wall foreign no-define])
AM_SILENT_RULES([yes])

# Check for programs
AC_PROG_CC

# Check for header files
AC_HEADER_STDC

AS_COMPILER_FLAGS([WARNING_CFLAGS],
		  ["-Wall -Wshadow -Wcast-align -Wno-uninitialized
		   -Wno-strict-aliasing -Wempty-body -Wformat -Wformat-security
		   -Winit-self -Wdeclaration-after-statement -Wvla
		   -Wpointer-arith"])

PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.24])

AC_OUTPUT([
  Makefile
])

and then Makefile.am:

ACLOCAL_AMFLAGS = -I build ${ACLOCAL_FLAGS}

bin_PROGRAMS = fart

fart_SOURCES =	fart.c
fart_CFLAGS  = $(WARNING_CFLAGS) $(GLIB_CFLAGS)
fart_LDADD   = $(GLIB_LIBS)

After that, it’s just a matter of running autoreconf

$ autoreconf -i

and you are all set!

So, what do you get for this amount of lines?

  • The usual set of automake targets, handy! (“make tags” is so under used!) and bonus features (out of tree builds, extra rules to reconfigure/rebuild the Makefiles on changes in configure.ac/Makefile.an, …)
  • Trying to make the autoconf/automake discreet (putting auxiliary files out of the way, silence mode, automake for non GNU projects)
  • Some decent warning flags (tweak to your liking!)
  • autoreconf cooperating with aclocal thanks to ACLOCAL_AMFLAGS and coping with non standard locations for system m4 macros

I’ll maintain a git tree to help bootstrap my next small hacks, feel free to use it as well!

Categories: misc
  1. December 18th, 2011 at 05:07 | #1

    Hi Damien,

    I can’t find an e-mail address of yours, but I think you can help me.

    I’m trying to use PVRTexLib in a shared library on 64-bit Linux, and it looks like you’ve done that before:

    https://github.com/media-explorer/gdk-pixbuf-texture-tool

    The latest versions of PVRTexLib, however, aren’t compiled with -fPIC, so I can’t link them into a .so. Indeed, even running “make” in gdk-pixbuf-texture fails with the same error. Do you have a version of PVRTexLib that works?

    Thanks,
    Chad

  2. April 7th, 2012 at 14:27 | #2

    Sorry for the late answer, but I never tried on 64 bits, it did work on 32 bits FWIW

  1. No trackbacks yet.