GNU autotools cheatsheet

Table of Contents

1 Introduction

These are just the barest of notes on GNU autotools.

GNU Autoconf, Automake, and Libtool by Vaughan et al., ("the goat book") is a good tutorial and reference, and available on-line. Section 5.2 and Appendix C are particularly helpful.

2 GNU autotools data flow

autotools_dataflow.png

3 Elements

The commands below are roughly in the order they need to be run when developing. The underlined files are those that must be written by hand.

autoscan reads sources
  writes configure.auto (guess at configure.ac)
aclocal reads acinclude.m4, configure.ac
  writes aclocal.m4
autoheader reads aclocal.m4, acconfig.h, configure.ac
  writes config.h.in
automake reads configure.ac, Makefile.am
  writes Makefile.in (others if –add-missing used)
autoconf reads aclocal.m4, configure.ac
  writes configure
configure reads config.site, config.cache, config.h.in, Makefile.in
  writes config.cache, config.status, config.h, Makefile, stamp-h
make reads Makefile, config.h, sources
  writes targets

4 Examples

4.1 The GNU hello-world product

GNU hello has much more sophisticated examples of the necessary files.

4.2 Makefile.am example

Makefile.am:

SUBDIRS = src bin data lib docsrc doc
AUTOMAKE_OPTIONS=gnu

src/Makefile.am:

AUTOMAKE_OPTIONS=gnu
INCLUDES = $(CFITSIOINC) $(WCSINC)
bin_PROGRAMS=imconvolve imarith makefitsim pix2pix imzeros imgauss astromxfer imftinvert coordxfer imremap impix coordtable xyfits2tsv rprofile subtefit sdssremap
imconvolve_SOURCES=imconvolve.c
imarith_SOURCES=imarith.c
makefitsim_SOURCES=makefitsim.c
pix2pix_SOURCES=pix2pix.c
imzeros_SOURCES=imzeros.c
imgauss_SOURCES=imgauss.c
astromxfer_SOURCES=astromxfer.c
imftinvert_SOURCES=imftinvert.c
coordxfer_SOURCES=coordxfer.c
imremap_SOURCES=imremap.c
impix_SOURCES=impix.c
coordtable_SOURCES=coordtable.c
xyfits2tsv_SOURCES=xyfits2tsv.c
rprofile_SOURCES=rprofile.c
subtefit_SOURCES=subtefit.c
sdssremap_SOURCES=sdssremap.c

4.3 configure.ac example

configure.ac:

AC_PREREQ(2.59)
AC_INIT([imstacker],[0.1], [neilsen@fnal.gov])
AC_CONFIG_AUX_DIR(config)

AM_INIT_AUTOMAKE(imstacker,0.1)

AC_CONFIG_SRCDIR([src/imconvolve.c])
AM_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CC
AC_LANG_C
AC_PROG_AWK
AC_PROG_INSTALL
AC_PROG_MAKE_SET

# Checks for libraries.
LIBS="-lwcs -lcfitsio -lfftw3 -L/opt/lib"

AC_CHECK_LIB(popt,main)
AC_CHECK_LIB(m,main)
AC_CHECK_LIB(cfitsio,ffopen)
AC_CHECK_LIB(wcs,wcspih)
AC_CHECK_LIB(gslcblas,main)
AC_CHECK_LIB(gsl,main)
AC_CHECK_LIB(fftw3, fftw_plan_dft_r2c_2d)

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([string.h])
AC_CHECK_HEADERS([/opt/include/fitsio.h],[CFITSIOINC=-I/opt/include])
AC_CHECK_HEADERS([/opt/include/fftw3.h],[FFTWINC=-I/opt/include])
AC_CHECK_HEADERS([/opt/wcslib-4.2/include/wcslib/wcslib.h],[WCSINC=-I/opt/wcslib-4.2/include/wcslib])

AC_SUBST([CFITSIOINC])
AC_SUBST([WCSINC])
AC_SUBST([FFTWINC])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_MALLOC

# Use inline if you can
AC_C_INLINE
if test "$ac_cv_c_inline" != no ; then
   AC_DEFINE(HAVE_INLINE,1,"use inlines")
   AC_SUBST(HAVE_INLINE)
fi

AC_OUTPUT([Makefile src/Makefile])

Author: Eric H. Neilsen, Jr.

Emacs 24.3.1 (Org mode 8.2.5c)

Validate