Autotools template example

Home

Table of Contents

1 autotools process

autoscan  -> configure.scan  -> can be used as template for configure.ac
configure.ac  is an input to  autoconf

autoreconf

1.1 configure.ac

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.68])
AC_INIT([tacpl_ch1], [0.1], [snarvaezsoft@gmail.com])
AM_INIT_AUTOMAKE([-Wall -Werror])
AC_CONFIG_SRCDIR([config.h.in])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.
# FIXME: Replace `main' with a function in `-lm':
AC_CHECK_LIB([m], [abs])

# Checks for header files.
AC_CHECK_HEADERS([stdlib.h])

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AC_CHECK_FUNCS([pow])

AC_CONFIG_FILES([Makefile
                 src/Makefile])
AC_OUTPUT

1.2 Makefile.am (is an input to automake)

SUBDIRS = common src

1.3 src/Makefile.am

## Makefile.am -- Process this file with automake to produce Makefile.in

## run with:
## make clean
## make CXXFLAGS='-g -Wall -O0 '  CFLAGS='-g -Wall -O0 '

## Append to CFLAGS.  Used by gcc to compile c programs
AM_CFLAGS =  -std=gnu11

## Append to CXXFLAGS. Used by g++ to complite cpp programs
AM_CXXFLAGS = -std=c++11

bin_PROGRAMS = jupiter
jupiter_SOURCES = main.c
jupiter_CPPFLAGS = -I$(top_srcdir)/common
jupiter_LDADD = ../common/libjupcommon.a

Makefile.am is an input to automake.

configure.in is an input to autoconf??

1.4 we generate `configure':

$ aclocal
$ autoconf
$ touch NEWS README AUTHORS ChangeLog
$ automake --add-missing --copy
$ autoreconf
$ configure
$ make

aclocal …

Graphically:

INPUT -> PROCESS -> OUTPUT

configure.in ->  autoconf	  -> configure
Makefile.am  ->	 automake	  -> Makefile.in
Makefile.in  ->	 configure	-> Makefile

autoreconf "automatically executes the correct autotools programs"

2 Separate build directory

when building C samples, you can also create separate build directory

mkdir build
cd build
../configure
make

Author: Sebastian Emilio Narvaez

Created: 2019-10-12 Sat 22:16

Emacs 25.2.2 (Org mode 8.2.10)

Validate