Autoconf/Automake Basics

Speaker: Mark K. Kim

Linux Users' Group of Davis

March 2, 2004

Slide modified slightly after the talk to fix some errors
and add some minor information

The portability problem

Hardware differences

Endian-ness

Word size

OS differences

Executable file names

Device file names

File name conventions

Compiler differences

Compiler name & arguments

Header file names & definitions

Keywords

Why use Autoconf/Automake?

Portability

Code reuse

Professional look

What does it look like?

Writing a C program – the code

Writing a C program – the execution

Creating `configure` - The steps

`configure` is created from “configure.ac” (using `autoconf`)

“configure.ac” can be created automatically (using `autoscan`)

Creating `configure` - The first try (1/2)

Creating `configure` - The first try (2/2)

Creating `configure` - The first try (2/2)

Creating `configure` - The second try (1/2)

Creating `configure` - The second try (2/2)

Recap – Creating `configure`

Creating `configure`:

Prepare sources and the Makefile.in

Run `autoscan`

Rename configure.scan to configure.ac

Run `autoconf`

./configure

make

Still to consider:

Creating Makefile.in using Automake

Creating config.h.in

Using config.h to make our program portable

What is “configure.ac”?

What is “configure”?

An example program – the code

Example program – the execution

Portability problem!

gettimeofday() is not available on all systems!

Potential solution: Use time()

Better Solution

Use gettimeofday() if available.

Fall back on time() if gettimeofday() is not available.

Better epoch.c – The code

Generating config.h

config.h is created by `configure` from “config.h.in”

“config.h.in” is created by `autoheader` from the C sources and headers.

Sample session

What is “config.h”?

Recap thus far...

autoscan

Rename “configure.scan” to “configure.ac”

autoheader

Rename “Makefile” to “Makefile.in”

autoconf

./configure

make

Creating “Makefile.in” — The steps

Create “Makefile.am” by hand

Run `automake`

What is “Makefile.am”?

Creating “Makefile.in” — The first try

What is “AM_INIT_AUTOMAKE”?

Dealing with AM_INIT_AUTOMAKE

Edit “configure.ac”

Run `aclocal`

automake

autoconf

Editing configure.ac

Automake – Sample session

What is “Makefile.in”?

./configure

What is in the Makefile?

make and make install

The Ultimate Summary

Create sources, “Makefile.am”

`autoscan`

Rename “configure.scan” to “configure.ac”

`autoheader`

Add AM_INIT_AUTOMAKE to “configure.ac”

`aclocal`

`automake --add-missing --copy`

`autoconf`

`./configure`

`make`

`make install`

If you modify your source...

Run `autoscan` again

Compare configure.scan with configure.ac

Update configure.ac

Run `autoreconf`

Things to know...

Autoconf/Automake doesn't make a program portable – YOU DO!

Your program evolves to be more portable.

You can add or write your own tests in m4.
(Place them in “acinclude.m4”)

Resources

GNU Autoconf, Automake, and Libtool:

http://sources.redhat.com/autobook/

The GNU Autoconf Macro archive

http://www.gnu.org/software/ac-archive/

Autotools Tutorial for Beginners

http://www.cbreak.org/

Autoconf / Automake Basics

Autoconf, Automake

Autoconf Automake Autotools talk Linux Users' Group of Davis (LUGOD)

The slides for the talk given at Linux Users' Group of Davis on March 2, 2004 by Mark K. Kim.
http://www.lugod.org/

Mark Kim

2004-02-26T18:35:54