0% found this document useful (0 votes)
48 views556 pages

Auto Tools

Uploaded by

pvt1512
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views556 pages

Auto Tools

Uploaded by

pvt1512
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 556

Foreword

Foreword (1/2)

This presentation targets developers familiar with Unix development tools (shell, make, compiler) that want to learn Autotools. The latest version of this document can be retrieved from
http://www.lrde.epita.fr/~adl/autotools.html

Please mail me corrections and suggestions about this document at [email protected]. Do not send me any general question about the Autotools. Use the appropriate mailing list instead ([email protected], or [email protected]).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

1 / 162

Tool Versions

Foreword (2/2)
This document was updated for the following releases of the Autotools: GNU GNU GNU GNU Autoconf Automake Libtool Gettext 2.65 1.11.1 2.2.6b 0.17 (November (December (November (November 2009) 2009) 2009) 2007)

These were the last releases at the time of writing. The usage of these tools has improved a lot over the last years. Some syntaxes used here will not work with older tools. This a deliberate choice:
New users should learn todays recommended usages. Make sure you have up-to-date tools and do not bother with old releases.
A. Duret-Lutz Using GNU Autotools May 16, 2010 2 / 162

Title Page

Using GNU Autotools


Alexandre Duret-Lutz [email protected]

May 16, 2010 Copyright c 2010 Alexandre Duret-Lutz http://creativecommons.org/licenses/by-sa/2.0/


Trivial source code examples displayed in this tutorial (such as the C les, Makele.ams, and congure.acs of all the amhello projects) can be reused as if they were in the public domain.
A. Duret-Lutz Using GNU Autotools May 16, 2010 3 / 162

Part I The GNU Build System


1

Goals Portable Packages Uniform Builds Package Use Cases The User Point of View The Power User Point of View The Packager Point of View The Maintainer Point of View The congure Process Why We Need Tools
A. Duret-Lutz Using GNU Autotools May 16, 2010 4 / 162

3 4

Goals

Portable Packages

Portable Packages
1

Goals Portable Packages Uniform Builds Package Use Cases The User Point of View The Power User Point of View The Packager Point of View The Maintainer Point of View The congure Process Why We Need Tools

3 4

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

5 / 162

Goals

Portable Packages

Sources of Non-Portability in C
Consider C functions... that do not exist everywhere (e.g., strtod()) that have dierent names (e.g., strchr() vs. index()) that have varying prototypes (e.g., int setpgrp(void); vs. int setpgrp(int, int);) that can behave dierently (e.g., malloc(0);) that might require other libraries (is pow() in libm.so or in libc.so?) that can be dened in dierent headers (string.h vs. strings.h vs. memory.h) How should a package deal with those?

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

6 / 162

Goals

Portable Packages

Possible Solutions

Slice the code with lots of #if/#else Create substitution macros Create substitution functions

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

7 / 162

Goals

Portable Packages

Possible Solutions

Slice the code with lots of #if/#else Create substitution macros Create substitution functions The latter two are to be preferred.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

7 / 162

Goals

Portable Packages

Code Cluttered with #if/#else


Excerpt of call-1.10s alloc trampoline()
#i f ! d e f i n e d (CODE EXECUTABLE) s t a t i c long pagesize = 0; #i f d e f i n e d (EXECUTABLE VIA MMAP DEVZERO) static int zero fd ; #e n d i f i f (! pagesize ) { #i f d e f i n e d (HAVE MACH VM) pagesize = vm page size ; #e l s e pagesize = getpagesize (); #e n d i f #i f d e f i n e d (EXECUTABLE VIA MMAP DEVZERO) z e r o f d = open ( / d e v / z e r o , O RDONLY, 0 6 4 4 ) ; i f ( z e r o f d < 0) { f p r i n t f ( s t d e r r , t r a m p o l i n e : Cannot open / d e v / z e r o ! \ n ) ; abort ( ) ; } #e n d i f } #e n d i f
A. Duret-Lutz Using GNU Autotools May 16, 2010 8 / 162

Goals

Portable Packages

Substitution macros

Excerpt of coreutils-5.2.1s system.h


#i f ! HAVE FSEEKO && ! d e f i n e d f s e e k o # d e f i n e f s e e k o ( s , o , w) ( ( o ) == ( long ) ( o ) \ ? f s e e k ( s , o , w) \ : ( e r r n o = EOVERFLOW, 1)) #e n d i f Then use fseeko() whether it exists or not.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

9 / 162

Goals

Portable Packages

Substitution functions
If strdup() does not exist, link your program with a replacement denition such as

strdup.c (from the GNU C library)


char s t r d u p ( const char s ) { s i z e t len = s t r l e n ( s ) + 1; v o i d new = m a l l o c ( l e n ) ; i f ( new == NULL) r e t u r n NULL ; r e t u r n ( char ) memcpy ( new , s , l e n ) ; }

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

10 / 162

Goals

Uniform Builds

Uniform Builds
1

Goals Portable Packages Uniform Builds Package Use Cases The User Point of View The Power User Point of View The Packager Point of View The Maintainer Point of View The congure Process Why We Need Tools

3 4

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

11 / 162

Goals

Uniform Builds

Need for Automatic Conguration

Maintaining a collection of #define for each system by hand is cumbersome. Requiring users to add the necessary -D, -I, and -l compilation options to Makele is burdensome. Complicated builds hinder the acceptance of free software.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

12 / 162

Goals

Uniform Builds

Need for Automatic Conguration

Maintaining a collection of #define for each system by hand is cumbersome. Requiring users to add the necessary -D, -I, and -l compilation options to Makele is burdensome. Complicated builds hinder the acceptance of free software.

In 1991 people started to write shell scripts to guess these settings for some GNU packages. Since then the congure script is mandatory in any package of the GNU project.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

12 / 162

Goals

Uniform Builds

congures Purpose

congure

congure probes the systems for required functions, libraries, and tools

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

13 / 162

Goals

Uniform Builds

congures Purpose

congure

cong.h

congure probes the systems for required functions, libraries, and tools then it generates a cong.h le with all #defines

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

13 / 162

Goals

Uniform Builds

congures Purpose

congure

Makele

src/ Makele

cong.h

congure probes the systems for required functions, libraries, and tools then it generates a cong.h le with all #defines as well as Makeles to build the package

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

13 / 162

Goals

Uniform Builds

GNU Coding Standards

http://www.gnu.org/prep/standards/ Practices that packages of the GNU project should follow:

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

14 / 162

Goals

Uniform Builds

GNU Coding Standards

http://www.gnu.org/prep/standards/ Practices that packages of the GNU project should follow: program behavior
how to report errors, standard command line options, etc.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

14 / 162

Goals

Uniform Builds

GNU Coding Standards

http://www.gnu.org/prep/standards/ Practices that packages of the GNU project should follow: program behavior
how to report errors, standard command line options, etc.

coding style

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

14 / 162

Goals

Uniform Builds

GNU Coding Standards

http://www.gnu.org/prep/standards/ Practices that packages of the GNU project should follow: program behavior
how to report errors, standard command line options, etc.

coding style conguration

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

14 / 162

Goals

Uniform Builds

GNU Coding Standards

http://www.gnu.org/prep/standards/ Practices that packages of the GNU project should follow: program behavior
how to report errors, standard command line options, etc.

coding style conguration Makele conventions etc.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

14 / 162

Package Use Cases

The User Point of View

The User Point of View


1

Goals Portable Packages Uniform Builds Package Use Cases The User Point of View The Power User Point of View The Packager Point of View The Maintainer Point of View The congure Process Why We Need Tools

3 4

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

15 / 162

Package Use Cases

The User Point of View

Standard Installation Procedure


~ % tar zxf amhello-1.0.tar.gz

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

16 / 162

Package Use Cases

The User Point of View

Standard Installation Procedure


~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

16 / 162

Package Use Cases

The User Point of View

Standard Installation Procedure


~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % ./configure ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

16 / 162

Package Use Cases

The User Point of View

Standard Installation Procedure


~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % ./configure ... ~/amhello-1.0 % make ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

16 / 162

Package Use Cases

The User Point of View

Standard Installation Procedure


~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % ./configure ... ~/amhello-1.0 % make ... ~/amhello-1.0 % make check ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

16 / 162

Package Use Cases

The User Point of View

Standard Installation Procedure


~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % ./configure ... ~/amhello-1.0 % make ... ~/amhello-1.0 % make check ... ~/amhello-1.0 % su Password:

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

16 / 162

Package Use Cases

The User Point of View

Standard Installation Procedure


~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % ./configure ... ~/amhello-1.0 % make ... ~/amhello-1.0 % make check ... ~/amhello-1.0 % su Password: /home/adl/amhello-1.0 # make install ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

16 / 162

Package Use Cases

The User Point of View

Standard Installation Procedure


~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % ./configure ... ~/amhello-1.0 % make ... ~/amhello-1.0 % make check ... ~/amhello-1.0 % su Password: /home/adl/amhello-1.0 # make install ... /home/adl/amhello-1.0 # exit

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

16 / 162

Package Use Cases

The User Point of View

Standard Installation Procedure


~ % tar zxf amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % ./configure ... ~/amhello-1.0 % make ... ~/amhello-1.0 % make check ... ~/amhello-1.0 % su Password: /home/adl/amhello-1.0 # make install ... /home/adl/amhello-1.0 # exit ~/amhello-1.0 % make installcheck ...
A. Duret-Lutz Using GNU Autotools May 16, 2010 16 / 162

Package Use Cases

The User Point of View

Standard Makele Targets


make all Build programs, libraries, documentation, etc. (Same as make.) make install Install what needs to be installed. make install-strip Same as make install, then strip debugging symbols. make uninstall The opposite of make install. make clean Erase what has been built (the opposite of make all). make distclean Additionally erase anything ./configure created. make check Run the test suite, if any. make installcheck Check the installed programs or libraries, if supported. make dist Create PACKAGE-VERSION.tar.gz.
A. Duret-Lutz Using GNU Autotools May 16, 2010 17 / 162

Package Use Cases

The User Point of View

Standard File System Hierarchy


Directory variable prex exec-prex bindir libdir ... includedir datarootdir datadir mandir infodir ... ~/amhello-1.0 % Default value /usr/ local prex exec-prex/bin exec-prex/lib prex/include prex/share datarootdir datarootdir/man datarootdir/info

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

18 / 162

Package Use Cases

The User Point of View

Standard File System Hierarchy


Directory variable prex exec-prex bindir libdir ... includedir datarootdir datadir mandir infodir ... Default value /usr/ local prex exec-prex/bin exec-prex/lib prex/include prex/share datarootdir datarootdir/man datarootdir/info

~/amhello-1.0 % ./configure --prefix ~/usr

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

18 / 162

Package Use Cases

The User Point of View

Standard File System Hierarchy


Directory variable prex exec-prex bindir libdir ... includedir datarootdir datadir mandir infodir ... Default value /usr/ local prex exec-prex/bin exec-prex/lib prex/include prex/share datarootdir datarootdir/man datarootdir/info

~/amhello-1.0 % ./configure --prefix ~/usr ~/amhello-1.0 % make


A. Duret-Lutz Using GNU Autotools May 16, 2010 18 / 162

Package Use Cases

The User Point of View

Standard File System Hierarchy


Directory variable prex exec-prex bindir libdir ... includedir datarootdir datadir mandir infodir ... Default value /usr/ local prex exec-prex/bin exec-prex/lib prex/include prex/share datarootdir datarootdir/man datarootdir/info

~/amhello-1.0 % ./configure --prefix ~/usr ~/amhello-1.0 % make ~/amhello-1.0 % make install


A. Duret-Lutz Using GNU Autotools May 16, 2010 18 / 162

Package Use Cases

The User Point of View

Standard Conguration Variables


./configure automatically detects many settings. You can force some of them using conguration variables. CC C compiler command CFLAGS C compiler ags CXX C++ compiler command CXXFLAGS C++ compiler ags LDFLAGS linker ags CPPFLAGS C/C++ preprocessor ags ... See ./configure --help for a full list. ~/amhello-1.0 %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

19 / 162

Package Use Cases

The User Point of View

Standard Conguration Variables


./configure automatically detects many settings. You can force some of them using conguration variables. CC C compiler command CFLAGS C compiler ags CXX C++ compiler command CXXFLAGS C++ compiler ags LDFLAGS linker ags CPPFLAGS C/C++ preprocessor ags ... See ./configure --help for a full list. ~/amhello-1.0 % ./configure --prefix ~/usr CC=gcc-3 \ CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib
A. Duret-Lutz Using GNU Autotools May 16, 2010 19 / 162

Package Use Cases

The Power User Point of View

The Power User Point of View


1

Goals Portable Packages Uniform Builds Package Use Cases The User Point of View The Power User Point of View The Packager Point of View The Maintainer Point of View The congure Process Why We Need Tools

3 4

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

20 / 162

Package Use Cases

The Power User Point of View

Overriding Default Conguration Settings with cong.site


Recall that old command
~/amhello-1.0 % ./configure --prefix ~/usr CC=gcc-3 \ CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

21 / 162

Package Use Cases

The Power User Point of View

Overriding Default Conguration Settings with cong.site


Recall that old command
~/amhello-1.0 % ./configure --prefix ~/usr CC=gcc-3 \ CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib

Common conguration settings can be put in prex/share/ cong.site


~/amhello-1.0 % cat ~/usr/share/config.site test -z "$CC" && CC=gcc-3 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

21 / 162

Package Use Cases

The Power User Point of View

Overriding Default Conguration Settings with cong.site


Recall that old command
~/amhello-1.0 % ./configure --prefix ~/usr CC=gcc-3 \ CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib

Common conguration settings can be put in prex/share/ cong.site


~/amhello-1.0 % cat ~/usr/share/config.site test -z "$CC" && CC=gcc-3 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib

Reducing the command to...


~/amhello-1.0 % ./configure --prefix ~/usr
configure: loading site script /home/adl/usr/share/config.site ...
A. Duret-Lutz Using GNU Autotools May 16, 2010 21 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees (a.k.a. VPATH Builds)

Objects les, programs, and libraries are built where congure was run.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

22 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees (a.k.a. VPATH Builds)

Objects les, programs, and libraries are built where congure was run. ~ % tar zxf ~/amhello-1.0.tar.gz ~ % cd amhello-1.0

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

22 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees (a.k.a. VPATH Builds)

Objects les, programs, and libraries are built where congure was run. ~ % tar zxf ~/amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % mkdir build && cd build

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

22 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees (a.k.a. VPATH Builds)

Objects les, programs, and libraries are built where congure was run. ~ % tar zxf ~/amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % mkdir build && cd build ~/amhello-1.0/build % ../configure

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

22 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees (a.k.a. VPATH Builds)

Objects les, programs, and libraries are built where congure was run. ~ % tar zxf ~/amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % mkdir build && cd build ~/amhello-1.0/build % ../configure ~/amhello-1.0/build % make ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

22 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees (a.k.a. VPATH Builds)

Objects les, programs, and libraries are built where congure was run. ~ % tar zxf ~/amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % mkdir build && cd build ~/amhello-1.0/build % ../configure ~/amhello-1.0/build % make ... Sources les are in / amhello-1.0/ , built les are all in / amhello-1.0/ build/ .

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

22 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees for Multiple Architectures


Builds for multiple architectures can share the same source tree.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

23 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees for Multiple Architectures


Builds for multiple architectures can share the same source tree.

Have the source on a (possibly read-only) shared directory


~ % cd /nfs/src /nfs/src % tar zxf ~/amhello-1.0.tar.gz

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

23 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees for Multiple Architectures


Builds for multiple architectures can share the same source tree.

Have the source on a (possibly read-only) shared directory


~ % cd /nfs/src /nfs/src % tar zxf ~/amhello-1.0.tar.gz

Compilation on rst host


~ % mkdir /tmp/amh && cd /tmp/amh /tmp/amh % /nfs/src/amhello-1.0/configure /tmp/amh % make && sudo make install

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

23 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees for Multiple Architectures


Builds for multiple architectures can share the same source tree.

Have the source on a (possibly read-only) shared directory


~ % cd /nfs/src /nfs/src % tar zxf ~/amhello-1.0.tar.gz

Compilation on rst host


~ % mkdir /tmp/amh && cd /tmp/amh /tmp/amh % /nfs/src/amhello-1.0/configure /tmp/amh % make && sudo make install

Compilation on second host


~ % mkdir /tmp/amh && cd /tmp/amh /tmp/amh % /nfs/src/amhello-1.0/configure /tmp/amh % make && sudo make install
A. Duret-Lutz Using GNU Autotools May 16, 2010 23 / 162

Package Use Cases

The Power User Point of View

Parallel Build Trees for Multiple Architectures


Builds for multiple architectures can share the same source tree.

Have the source on a (possibly read-only) shared directory


~ % cd /nfs/src /nfs/src % tar zxf ~/amhello-1.0.tar.gz

Compilation on rst host


~ % mkdir /tmp/amh && cd /tmp/amh /tmp/amh % /nfs/src/amhello-1.0/configure /tmp/amh % make && sudo make install

Compilation on second host, assuming shared data


~ % mkdir /tmp/amh && cd /tmp/amh /tmp/amh % /nfs/src/amhello-1.0/configure /tmp/amh % make && sudo make install-exec
A. Duret-Lutz Using GNU Autotools May 16, 2010 23 / 162

Package Use Cases

The Power User Point of View

Two Part Installation

make install = make install-exec + make install-data

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

24 / 162

Package Use Cases

The Power User Point of View

Two Part Installation

make install = make install-exec + make install-data

install platform-dependent les

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

24 / 162

Package Use Cases

The Power User Point of View

Two Part Installation

make install = make install-exec + make install-data

install platform-dependent les install platform-independent les (can be shared among multiple machines)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

24 / 162

Package Use Cases

The Power User Point of View

Cross-Compilation
~/amhello-1.0 % ./configure
checking checking checking checking checking checking checking checking checking checking checking checking checking ... for a BSD-compatible install... /usr/bin/install -c whether build environment is sane... yes for gawk... gawk whether make sets $(MAKE)... yes for gcc... gcc for C compiler default output file name... a.out whether the C compiler works... yes whether we are cross compiling... no for suffix of executables... for suffix of object files... o whether we are using the GNU C compiler... yes whether gcc accepts -g... yes for gcc option to accept ANSI C...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

25 / 162

Package Use Cases

The Power User Point of View

Cross-Compilation
~/amhello-1.0 % ./configure
checking checking checking checking checking checking checking checking checking checking checking checking checking ... for a BSD-compatible install... /usr/bin/install -c whether build environment is sane... yes for gawk... gawk whether make sets $(MAKE)... yes for gcc... gcc for C compiler default output file name... a.out whether the C compiler works... yes whether we are cross compiling... no for suffix of executables... for suffix of object files... o whether we are using the GNU C compiler... yes whether gcc accepts -g... yes for gcc option to accept ANSI C...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

25 / 162

Package Use Cases

The Power User Point of View

Cross-Compilation
~/amhello-1.0 % ./configure --build i686-pc-linux-gnu \ --host i586-mingw32msvc
checking checking checking checking checking checking checking checking checking checking checking checking checking checking ... for a BSD-compatible install... /usr/bin/install -c whether build environment is sane... yes for gawk... gawk whether make sets $(MAKE)... yes for i586-mingw32msvc-strip... i586-mingw32msvc-strip for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc for C compiler default output file name... a.exe whether the C compiler works... yes whether we are cross compiling... yes for suffix of executables... .exe for suffix of object files... o whether we are using the GNU C compiler... yes whether i586-mingw32msvc-gcc accepts -g... yes for i586-mingw32msvc-gcc option to accept ANSI C...
Using GNU Autotools May 16, 2010 25 / 162

A. Duret-Lutz

Package Use Cases

The Power User Point of View

Cross-Compilation
~/amhello-1.0 % ./configure --build i686-pc-linux-gnu \ --host i586-mingw32msvc ... ~/amhello-1.0 % make ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

25 / 162

Package Use Cases

The Power User Point of View

Cross-Compilation
~/amhello-1.0 % ./configure --build i686-pc-linux-gnu \ --host i586-mingw32msvc ... ~/amhello-1.0 % make ... ~/amhello-1.0 % cd src; file hello.exe
hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable

Of course you need a cross-compiler installed rst.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

25 / 162

Package Use Cases

The Power User Point of View

Cross-Compilation
~/amhello-1.0 % ./configure --build i686-pc-linux-gnu \ --host i586-mingw32msvc ... ~/amhello-1.0 % make ... ~/amhello-1.0 % cd src; file hello.exe
hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable

Of course you need a cross-compiler installed rst. Cross-compilation congure options: --build=BUILD The system on which the package is built. --host=HOST The system where built programs & libraries will run. --target=TARGET Only when building compiler tools: the system for which the tools will create output. For simple cross-compilation, only --host=HOST is needed.
A. Duret-Lutz Using GNU Autotools May 16, 2010 25 / 162

Package Use Cases

The Power User Point of View

Renaming Programs at Install Time


Maybe hello is already a command on this host?

.
A. Duret-Lutz Using GNU Autotools May 16, 2010 26 / 162

Package Use Cases

The Power User Point of View

Renaming Programs at Install Time


Maybe hello is already a command on this host? --program-prefix=PREFIX prepend PREFIX to installed program names, --program-suffix=SUFFIX append SUFFIX to installed program names, --program-transform-name=PROGRAM run sed PROGRAM on installed program names.

.
A. Duret-Lutz Using GNU Autotools May 16, 2010 26 / 162

Package Use Cases

The Power User Point of View

Renaming Programs at Install Time


Maybe hello is already a command on this host? --program-prefix=PREFIX prepend PREFIX to installed program names, --program-suffix=SUFFIX append SUFFIX to installed program names, --program-transform-name=PROGRAM run sed PROGRAM on installed program names. ~/amhello-1.0 % ./configure --program-prefix test~/amhello-1.0 % make ~/amhello-1.0 % sudo make install Will install hello as /usr/ local/ bin/ test-hello.
A. Duret-Lutz Using GNU Autotools May 16, 2010 26 / 162

Package Use Cases

The Packager Point of View

The Packager Point of View


1

Goals Portable Packages Uniform Builds Package Use Cases The User Point of View The Power User Point of View The Packager Point of View The Maintainer Point of View The congure Process Why We Need Tools

3 4

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

27 / 162

Package Use Cases

The Packager Point of View

Building Binary Packages Using DESTDIR


DESTDIR is used to relocate a package at install time. ~/amhello-1.0 % ./configure --prefix /usr ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

28 / 162

Package Use Cases

The Packager Point of View

Building Binary Packages Using DESTDIR


DESTDIR is used to relocate a package at install time. ~/amhello-1.0 % ./configure --prefix /usr ... ~/amhello-1.0 % make ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

28 / 162

Package Use Cases

The Packager Point of View

Building Binary Packages Using DESTDIR


DESTDIR is used to relocate a package at install time. ~/amhello-1.0 % ./configure --prefix /usr ... ~/amhello-1.0 % make ... ~/amhello-1.0 % make DESTDIR=$HOME/inst install ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

28 / 162

Package Use Cases

The Packager Point of View

Building Binary Packages Using DESTDIR


DESTDIR is used to relocate a package at install time. ~/amhello-1.0 % ./configure --prefix /usr ... ~/amhello-1.0 % make ... ~/amhello-1.0 % make DESTDIR=$HOME/inst install ... ~/amhello-1.0 % cd ~/inst ~/inst % tar zcvf ~/amhello-1.0-i686.tar.gz . ./ ./usr/ ./usr/bin/ ./usr/bin/hello ... and / amhello-1.0-i686.tar.gz is ready to be uncompressed in / on many hosts.
A. Duret-Lutz Using GNU Autotools May 16, 2010 28 / 162

Package Use Cases

The Maintainer Point of View

The Maintainer Point of View


1

Goals Portable Packages Uniform Builds Package Use Cases The User Point of View The Power User Point of View The Packager Point of View The Maintainer Point of View The congure Process Why We Need Tools

3 4

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

29 / 162

Package Use Cases

The Maintainer Point of View

Preparing Distributions
make dist Create PACKAGE-VERSION.tar.gz. make distcheck Likewise, with many sanity checks. Prefer this one!

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

30 / 162

Package Use Cases

The Maintainer Point of View

Preparing Distributions
make dist Create PACKAGE-VERSION.tar.gz. make distcheck Likewise, with many sanity checks. Prefer this one! make distcheck ensures most of the use cases presented so far work. It tests VPATH builds (with read-only source tree) It ensures make clean, make distclean, and make uninstall do not omit les, It checks that DESTDIR installations work, It runs the test suite (both make check and make installcheck). Releasing a package that fails make distcheck means releasing a package that will disappoint many users.
A. Duret-Lutz Using GNU Autotools May 16, 2010 30 / 162

Package Use Cases

The Maintainer Point of View

Automatic Dependency Tracking


~/amhello-1.0 % ./configure --prefix /usr ... checking dependency style of gcc... gcc3 ... Dependency tracking is performed as a side-eect of compilation. Several methods are supported, and checked for by congure. (The gcc3 method above is the fastest.)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

31 / 162

Package Use Cases

The Maintainer Point of View

Automatic Dependency Tracking


~/amhello-1.0 % ./configure --prefix /usr ... checking dependency style of gcc... gcc3 ... Dependency tracking is performed as a side-eect of compilation. Several methods are supported, and checked for by congure. (The gcc3 method above is the fastest.) Dependency tracking is only needed when the source les change; it can be safely disabled for throw-away installation builds. Slow methods must be enabled explicitly. --disable-dependency-tracking speed up one-time builds --enable-dependency-tracking do not reject slow dependency extractors
A. Duret-Lutz Using GNU Autotools May 16, 2010 31 / 162

Package Use Cases

The Maintainer Point of View

Nested Packages

Autoconscated packages can be nested to arbitrary depth.


A package can distribute a third-party library it uses in a subdirectory. Its possible to gather many packages this way to distribute a set of tools.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

32 / 162

Package Use Cases

The Maintainer Point of View

Nested Packages

Autoconscated packages can be nested to arbitrary depth.


A package can distribute a third-party library it uses in a subdirectory. Its possible to gather many packages this way to distribute a set of tools.

For installers:
A single package to congure, build, and install. configure options are passed recursively to sub-packages. configure --help=recursive shows the help of all sub-packages.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

32 / 162

Package Use Cases

The Maintainer Point of View

Nested Packages

Autoconscated packages can be nested to arbitrary depth.


A package can distribute a third-party library it uses in a subdirectory. Its possible to gather many packages this way to distribute a set of tools.

For installers:
A single package to congure, build, and install. configure options are passed recursively to sub-packages. configure --help=recursive shows the help of all sub-packages.

For maintainers:
Easier integration. The sub-package is autonomous.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

32 / 162

The congure Process

The congure Process


1

Goals Portable Packages Uniform Builds Package Use Cases The User Point of View The Power User Point of View The Packager Point of View The Maintainer Point of View The congure Process Why We Need Tools

3 4

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

33 / 162

The congure Process

The (simplied) congure process

Makele.in

src/ Makele.in

cong.h.in

congure

*.in les are conguration templates

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

34 / 162

The congure Process

The (simplied) congure process

Makele.in

src/ Makele.in

cong.h.in

congure

Makele

src/ Makele

cong.h

*.in les are conguration templates from which congure generates the conguration les to use for building
A. Duret-Lutz Using GNU Autotools May 16, 2010 34 / 162

The congure Process

The (real) congure process

Makele.in congure

src/ Makele.in

cong.h.in

cong reconguration
A. Duret-Lutz Using GNU Autotools May 16, 2010 35 / 162

The congure Process

The (real) congure process

Makele.in congure

src/ Makele.in

cong.h.in

cong.log

cong.log contains a trace of the conguration reconguration


A. Duret-Lutz Using GNU Autotools May 16, 2010 35 / 162

The congure Process

The (real) congure process

Makele.in congure

src/ Makele.in

cong.h.in

cong.status cong.log

cong.status will actually process the templates reconguration


A. Duret-Lutz Using GNU Autotools May 16, 2010 35 / 162

The congure Process

The (real) congure process

Makele.in congure

src/ Makele.in

cong.h.in

cong.status cong.log Makele src/ Makele cong.h

cong.status will actually process the templates reconguration


A. Duret-Lutz Using GNU Autotools May 16, 2010 35 / 162

The congure Process

The (real) congure process

Makele.in congure

src/ Makele.in

cong.h.in

cong.status cong.cache Makele cong.log src/ Makele cong.h

configure -C caches results in cong.cache to speed up recongurations


A. Duret-Lutz Using GNU Autotools May 16, 2010 35 / 162

Why We Need Tools

Why We Need Tools


1

Goals Portable Packages Uniform Builds Package Use Cases The User Point of View The Power User Point of View The Packager Point of View The Maintainer Point of View The congure Process Why We Need Tools

3 4

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

36 / 162

Why We Need Tools

Why We Need Tools


If you try to mimic this build system by hand, youll discover that The GNU Build System has a lot of features. Some users may expect features you do not use.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

37 / 162

Why We Need Tools

Why We Need Tools


If you try to mimic this build system by hand, youll discover that The GNU Build System has a lot of features. Some users may expect features you do not use. Implementing them portably is dicult, and exhausting. (Think portable shell scripts, portable Makeles, on systems you may not have handy.)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

37 / 162

Why We Need Tools

Why We Need Tools


If you try to mimic this build system by hand, youll discover that The GNU Build System has a lot of features. Some users may expect features you do not use. Implementing them portably is dicult, and exhausting. (Think portable shell scripts, portable Makeles, on systems you may not have handy.) You will have to upgrade your setup to follow changes of the GNU Coding Standards.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

37 / 162

Why We Need Tools

Why We Need Tools


If you try to mimic this build system by hand, youll discover that The GNU Build System has a lot of features. Some users may expect features you do not use. Implementing them portably is dicult, and exhausting. (Think portable shell scripts, portable Makeles, on systems you may not have handy.) You will have to upgrade your setup to follow changes of the GNU Coding Standards. GNU Autotools provide:

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

37 / 162

Why We Need Tools

Why We Need Tools


If you try to mimic this build system by hand, youll discover that The GNU Build System has a lot of features. Some users may expect features you do not use. Implementing them portably is dicult, and exhausting. (Think portable shell scripts, portable Makeles, on systems you may not have handy.) You will have to upgrade your setup to follow changes of the GNU Coding Standards. GNU Autotools provide: Tools to create the GNU Build System from simple instructions.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

37 / 162

Why We Need Tools

Why We Need Tools


If you try to mimic this build system by hand, youll discover that The GNU Build System has a lot of features. Some users may expect features you do not use. Implementing them portably is dicult, and exhausting. (Think portable shell scripts, portable Makeles, on systems you may not have handy.) You will have to upgrade your setup to follow changes of the GNU Coding Standards. GNU Autotools provide: Tools to create the GNU Build System from simple instructions. A central place where xes and improvements are made. (A bug-x for a portability issue benets every package.)
A. Duret-Lutz Using GNU Autotools May 16, 2010 37 / 162

Part II GNU Autotools


5

Hello World Introducing Core Autotools Hello World Explained Using Autoconf Using Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

38 / 162

Hello World

Hello World

Hello World Introducing Core Autotools Hello World Explained Using Autoconf Using Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

39 / 162

Hello World

src/ main.c for Hello World


src/ main.c
#i n c l u d e <c o n f i g . h> #i n c l u d e < s t d i o . h> int main ( v o i d ) { p u t s ( H e l l o World ! ) ; p u t s ( T h i s i s PACKAGE STRING . ) ; return 0; }

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

40 / 162

Hello World

Generating All Template Files

Makele.in congure

src/ Makele.in

cong.h.in

cong.status cong.cache Makele cong.log src/ Makele cong.h

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

41 / 162

Hello World

Generating All Template Files

Makele.in congure

src/ Makele.in

cong.h.in

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

41 / 162

Hello World

Generating All Template Files

Makele.in congure

src/ Makele.in

cong.h.in

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

41 / 162

Hello World

Generating All Template Files

congure.ac

autoreconf

Makele.in congure

src/ Makele.in

cong.h.in

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

41 / 162

Hello World

Generating All Template Files

congure.ac

Makele.am

src/ Makele.am

autoreconf

Makele.in congure

src/ Makele.in

cong.h.in

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

41 / 162

Hello World

Autotools Inputs

congure.ac
AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT

Makele.am
SUBDIRS = src

src/ Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

42 / 162

Hello World

Preparing the Package


~/amhello % ls -R .: Makefile.am configure.ac ./src: Makefile.am ~/amhello %

src/

main.c

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

43 / 162

Hello World

Preparing the Package


~/amhello % ls -R .: Makefile.am configure.ac

src/

./src: Makefile.am main.c ~/amhello % autoreconf --install configure.ac:2: installing ./install-sh configure.ac:2: installing ./missing src/Makefile.am: installing ./depcomp ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

43 / 162

Hello World

Preparing the Package


~/amhello % ls -R .: Makefile.am configure.ac

src/

./src: Makefile.am main.c ~/amhello % autoreconf --install configure.ac:2: installing ./install-sh configure.ac:2: installing ./missing src/Makefile.am: installing ./depcomp ~/amhello % ls -R .: Makefile.am configure.ac Makefile.in depcomp* aclocal.m4 install-sh* autom4te.cache/ missing* A. Duret-Lutz Using GNU Autotools config.h.in src/

May 16, 2010

43 / 162

Hello World

Preparing the Package


~/amhello % ls -R .: Makefile.am configure.ac Makefile.in depcomp* aclocal.m4 install-sh* autom4te.cache/ missing* config.h.in src/ configure* ./autom4te.cache: output.0 requests output.1 traces.0 ./src: Makefile.am
A. Duret-Lutz

traces.1

Makefile.in

main.c
Using GNU Autotools May 16, 2010 43 / 162

Hello World

Preparing the Package


~/amhello % ls -R .: Makefile.am configure.ac Makefile.in depcomp* aclocal.m4 install-sh* autom4te.cache/ missing* config.h.in src/ expected conguration templates configure* ./autom4te.cache: output.0 requests output.1 traces.0 ./src: Makefile.am
A. Duret-Lutz

traces.1

Makefile.in

main.c
Using GNU Autotools May 16, 2010 43 / 162

Hello World

Preparing the Package


~/amhello % ls -R .: Makefile.am configure.ac Makefile.in depcomp* aclocal.m4 install-sh* autom4te.cache/ missing* config.h.in src/ denitions for third-party macros configure* used in congure.ac ./autom4te.cache: output.0 requests output.1 traces.0 ./src: Makefile.am
A. Duret-Lutz

traces.1

Makefile.in

main.c
Using GNU Autotools May 16, 2010 43 / 162

Hello World

Preparing the Package


~/amhello % ls -R .: Makefile.am configure.ac Makefile.in depcomp* aclocal.m4 install-sh* autom4te.cache/ missing* config.h.in src/ auxiliary tools configure* used during the build ./autom4te.cache: output.0 requests output.1 traces.0 ./src: Makefile.am
A. Duret-Lutz

traces.1

Makefile.in

main.c
Using GNU Autotools May 16, 2010 43 / 162

Hello World

Preparing the Package


~/amhello % ls -R .: Makefile.am configure.ac Makefile.in depcomp* aclocal.m4 install-sh* autom4te.cache/ missing* config.h.in src/ Autotools cache les configure* ./autom4te.cache: output.0 requests output.1 traces.0 ./src: Makefile.am
A. Duret-Lutz

traces.1

Makefile.in

main.c
Using GNU Autotools May 16, 2010 43 / 162

Hello World

Preparing the Package


~/amhello % ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for gcc... gcc ... checking dependency style of gcc... gcc3 configure: creating ./config.status config.status: creating Makefile config.status: creating src/Makefile config.status: creating config.h config.status: executing depfiles commands ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

43 / 162

Hello World

Preparing the Package


~/amhello % ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for gcc... gcc ... checking dependency style of gcc... gcc3 configure: creating ./config.status config.status: creating Makefile config.status: creating src/Makefile config.status: creating config.h config.status: executing depfiles commands ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

43 / 162

Hello World

Preparing the Package


~/amhello % ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for gcc... gcc ... checking dependency style of gcc... gcc3 configure: creating ./config.status config.status: creating Makefile config.status: creating src/Makefile config.status: creating config.h config.status: executing depfiles commands ~/amhello % make ...
A. Duret-Lutz Using GNU Autotools May 16, 2010 43 / 162

Hello World

Preparing the Package


~/amhello % src/hello Hello World! This is amhello 1.0. ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

43 / 162

Hello World

Preparing the Package


~/amhello % src/hello Hello World! This is amhello 1.0. ~/amhello % make distcheck ... ======================================== amhello archives ready for distribution: amhello-1.0.tar.gz ======================================== ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

43 / 162

Hello World

Preparing the Package


~/amhello % tar ztf amhello-1.0.tar.gz amhello-1.0/ amhello-1.0/Makefile.am amhello-1.0/Makefile.in amhello-1.0/aclocal.m4 amhello-1.0/config.h.in amhello-1.0/configure amhello-1.0/configure.ac amhello-1.0/depcomp amhello-1.0/install-sh amhello-1.0/missing amhello-1.0/src/ amhello-1.0/src/Makefile.am amhello-1.0/src/Makefile.in amhello-1.0/src/main.c ~/amhello %
A. Duret-Lutz Using GNU Autotools May 16, 2010 43 / 162

Introducing Core Autotools

Introducing Core Autotools

Hello World Introducing Core Autotools Hello World Explained Using Autoconf Using Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

44 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf

GNU Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac.

GNU Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac. autoheader Create cong.h.in from congure.ac.

GNU Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac. autoheader Create cong.h.in from congure.ac. autoreconf Run all tools in the right order.

GNU Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac. autoheader Create cong.h.in from congure.ac. autoreconf Run all tools in the right order. autoscan Scan sources for common portability problems, and related macros missing from congure.ac.

GNU Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac. autoheader Create cong.h.in from congure.ac. autoreconf Run all tools in the right order. autoscan Scan sources for common portability problems, and related macros missing from congure.ac. autoupdate Update obsolete macros in congure.ac.

GNU Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac. autoheader Create cong.h.in from congure.ac. autoreconf Run all tools in the right order. autoscan Scan sources for common portability problems, and related macros missing from congure.ac. autoupdate Update obsolete macros in congure.ac. ifnames Gather identiers from all #if/#ifdef/... directives.

GNU Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac. autoheader Create cong.h.in from congure.ac. autoreconf Run all tools in the right order. autoscan Scan sources for common portability problems, and related macros missing from congure.ac. autoupdate Update obsolete macros in congure.ac. ifnames Gather identiers from all #if/#ifdef/... directives. autom4te The heart of Autoconf. It drives M4 and implements the features used by most of the above tools. Useful for creating more than just congure les. GNU Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac. autoheader Create cong.h.in from congure.ac. autoreconf Run all tools in the right order. autoscan Scan sources for common portability problems, and related macros missing from congure.ac. autoupdate Update obsolete macros in congure.ac. ifnames Gather identiers from all #if/#ifdef/... directives. autom4te The heart of Autoconf. It drives M4 and implements the features used by most of the above tools. Useful for creating more than just congure les. GNU Automake automake Create Makele.ins from Makele.ams and congure.ac.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac. autoheader Create cong.h.in from congure.ac. autoreconf Run all tools in the right order. autoscan Scan sources for common portability problems, and related macros missing from congure.ac. autoupdate Update obsolete macros in congure.ac. ifnames Gather identiers from all #if/#ifdef/... directives. autom4te The heart of Autoconf. It drives M4 and implements the features used by most of the above tools. Useful for creating more than just congure les. GNU Automake automake Create Makele.ins from Makele.ams and congure.ac. aclocal Scan congure.ac for uses of third-party macros, and gather denitions in aclocal.m4 .
A. Duret-Lutz Using GNU Autotools May 16, 2010 45 / 162

Introducing Core Autotools

Two Core Packages


GNU Autoconf autoconf Create congure from congure.ac. autoheader Create cong.h.in from congure.ac. autoreconf Run all tools in the right order. autoscan Scan sources for common portability problems, and related macros missing from congure.ac. autoupdate Update obsolete macros in congure.ac. ifnames Gather identiers from all #if/#ifdef/... directives. autom4te The heart of Autoconf. It drives M4 and implements the features used by most of the above tools. Useful for creating more than just congure les. GNU Automake automake Create Makele.ins from Makele.ams and congure.ac. aclocal Scan congure.ac for uses of third-party macros, and gather denitions in aclocal.m4 .
A. Duret-Lutz Using GNU Autotools May 16, 2010 45 / 162

Introducing Core Autotools

Behind autoreconf
congure.ac Makele.am src/ Makele.am

autoreconf

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

Behind autoreconf
congure.ac Makele.am src/ Makele.am

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

Behind autoreconf
congure.ac Makele.am src/ Makele.am

aclocal

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

Behind autoreconf
congure.ac aclocal.m4 Makele.am src/ Makele.am

aclocal

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

Behind autoreconf
congure.ac aclocal.m4 Makele.am src/ Makele.am

aclocal

autoconf

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

Behind autoreconf
congure.ac aclocal.m4 Makele.am src/ Makele.am

aclocal

autoconf

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

Behind autoreconf
congure.ac aclocal.m4 Makele.am src/ Makele.am

aclocal autoheader autoconf

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

Behind autoreconf
congure.ac aclocal.m4 Makele.am src/ Makele.am

aclocal autoheader autoconf

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

Behind autoreconf
congure.ac aclocal.m4 Makele.am src/ Makele.am

aclocal automake autoheader autoconf

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

Behind autoreconf
congure.ac aclocal.m4 Makele.am src/ Makele.am

aclocal automake autoheader autoconf

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 46 / 162

Using GNU Autotools

Introducing Core Autotools

autoreconf is Your Friend


In practice, You do not have to remember the interaction of all tools. Use autoreconf --install to setup the package initially. Rely on the rebuild rules (output in Makeles) to rerun the right autotool when you change some input le. You only need a rough idea of the purpose of each tool to understand errors. (What tool complains and about what?)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

47 / 162

Introducing Core Autotools

autoreconf is Your Friend


In practice, You do not have to remember the interaction of all tools. Use autoreconf --install to setup the package initially. Rely on the rebuild rules (output in Makeles) to rerun the right autotool when you change some input le. You only need a rough idea of the purpose of each tool to understand errors. (What tool complains and about what?) autoconf autoheader automake aclocal Creates congure from congure.ac. Creates cong.h.in from congure.ac. Creates Makele.ins from Makele.ams and congure.ac. Scans congure.ac for uses of third-party macros, and gather denitions in aclocal.m4 . autom4te Autoconf driver for M4. All tools that process congure.ac do so through autom4te.
A. Duret-Lutz Using GNU Autotools May 16, 2010 47 / 162

Hello World Explained

Hello World Explained

Hello World Introducing Core Autotools Hello World Explained Using Autoconf Using Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

48 / 162

Hello World Explained

amhellos congure.ac explained


congure.ac
AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

49 / 162

Hello World Explained

amhellos congure.ac explained


congure.ac
AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT Initialize Autoconf. Specify packages name, version number, and bug-report address.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

49 / 162

Hello World Explained

amhellos congure.ac explained


congure.ac
AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT Initialize Autoconf. Specify packages name, version number, and bug-report address. Initialize Automake. Turn on all Automake warnings and report them as errors. This is a foreign package.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

49 / 162

Hello World Explained

foreign Ignores some GNU Coding Standards


congure.ac
... AM_INIT_AUTOMAKE([foreign -Wall -Werror]) ... ~/amhello % autoreconf --install configure.ac:2: installing ./install-sh configure.ac:2: installing ./missing src/Makefile.am: installing ./depcomp

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

50 / 162

Hello World Explained

foreign Ignores some GNU Coding Standards


congure.ac without the foreign option
... AM_INIT_AUTOMAKE([ -Wall -Werror]) ... ~/amhello % autoreconf --install configure.ac:2: installing ./install-sh configure.ac:2: installing ./missing src/Makefile.am: installing ./depcomp Makefile.am: installing ./INSTALL Makefile.am: required file ./NEWS not found Makefile.am: required file ./README not found Makefile.am: required file ./AUTHORS not found Makefile.am: required file ./ChangeLog not found Makefile.am: installing ./COPYING autoreconf: automake failed with exit status: 1
A. Duret-Lutz Using GNU Autotools May 16, 2010 50 / 162

Hello World Explained

amhellos congure.ac explained


congure.ac
AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT Initialize Autoconf. Specify packages name, version number, and bug-report address. Initialize Automake. Turn on all Automake warnings and report them as errors. This is a foreign package.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

51 / 162

Hello World Explained

amhellos congure.ac explained


congure.ac
AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT Initialize Autoconf. Specify packages name, version number, and bug-report address. Initialize Automake. Turn on all Automake warnings and report them as errors. This is a foreign package. Check for a C compiler.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

51 / 162

Hello World Explained

amhellos congure.ac explained


congure.ac
AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT Initialize Autoconf. Specify packages name, version number, and bug-report address. Initialize Automake. Turn on all Automake warnings and report them as errors. This is a foreign package. Check for a C compiler. Declare cong.h as output header.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

51 / 162

Hello World Explained

amhellos congure.ac explained


congure.ac
AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT Initialize Autoconf. Specify packages name, version number, and bug-report address. Initialize Automake. Turn on all Automake warnings and report them as errors. This is a foreign package. Check for a C compiler. Declare cong.h as output header. Declare Makele and src/ Makele as output les.
A. Duret-Lutz Using GNU Autotools May 16, 2010 51 / 162

Hello World Explained

amhellos congure.ac explained


congure.ac
AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT Initialize Autoconf. Specify packages name, version number, and bug-report address. Initialize Automake. Turn on all Automake warnings and report them as errors. This is a foreign package. Check for a C compiler. Declare cong.h as output header. Declare Makele and src/ Makele as output les. Actually output all declared les.
A. Duret-Lutz Using GNU Autotools May 16, 2010 51 / 162

Hello World Explained

amhellos Makele.am explained

Makele.am
SUBDIRS = src Build recursively in src/ .

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

52 / 162

Hello World Explained

amhellos Makele.am explained

Makele.am
SUBDIRS = src Build recursively in src/ . Nothing else is declared for the current directory. (The top-level Makele.am is usually short.)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

52 / 162

Hello World Explained

amhellos src/ Makele.am explained

src/ Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c We are building some programs.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

53 / 162

Hello World Explained

amhellos src/ Makele.am explained

src/ Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c We are building some programs. These programs will be installed in bindir.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

53 / 162

Hello World Explained

Standard File System Hierarchy


Directory variable prex exec-prex bindir libdir ... includedir datarootdir datadir mandir infodir ... Default value /usr/ local prex exec-prex/bin exec-prex/lib prex/include prex/share datarootdir datarootdir/man datarootdir/info

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

54 / 162

Hello World Explained

amhellos src/ Makele.am explained

src/ Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c We are building some programs. These programs will be installed in bindir.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

55 / 162

Hello World Explained

amhellos src/ Makele.am explained

src/ Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c We are building some programs. These programs will be installed in bindir. There is only one program to build: hello.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

55 / 162

Hello World Explained

amhellos src/ Makele.am explained

src/ Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c We are building some programs. These programs will be installed in bindir. There is only one program to build: hello. To create hello, just compile main.c.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

55 / 162

Using Autoconf

Using Autoconf

Hello World Introducing Core Autotools Hello World Explained Using Autoconf Using Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

56 / 162

Using Autoconf

From congure.ac to congure and cong.h.in


autoconf is a macro processor. It converts congure.ac, which is a shell script using macro instructions, into congure, a full-edged shell script.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

57 / 162

Using Autoconf

From congure.ac to congure and cong.h.in


autoconf is a macro processor. It converts congure.ac, which is a shell script using macro instructions, into congure, a full-edged shell script. Autoconf oers many macros to perform common conguration checks. It is not uncommon to have a congure.ac without shell constructs, using only macros.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

57 / 162

Using Autoconf

From congure.ac to congure and cong.h.in


autoconf is a macro processor. It converts congure.ac, which is a shell script using macro instructions, into congure, a full-edged shell script. Autoconf oers many macros to perform common conguration checks. It is not uncommon to have a congure.ac without shell constructs, using only macros. While processing congure.ac it is also possible to trace the occurrences of macros. This is how autoheader creates cong.h.in. It just looks for the macros that #dene symbols.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

57 / 162

Using Autoconf

From congure.ac to congure and cong.h.in


autoconf is a macro processor. It converts congure.ac, which is a shell script using macro instructions, into congure, a full-edged shell script. Autoconf oers many macros to perform common conguration checks. It is not uncommon to have a congure.ac without shell constructs, using only macros. While processing congure.ac it is also possible to trace the occurrences of macros. This is how autoheader creates cong.h.in. It just looks for the macros that #dene symbols. The real macro processor actually is GNU M4. Autoconf oers some infrastructure on top of that, plus the pool of macros.
A. Duret-Lutz Using GNU Autotools May 16, 2010 57 / 162

Using Autoconf

Discovering M4

example.m4
m4_define(NAME1, Harry) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4
m4_define(NAME1, Harry) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4
m4_define(NAME1, Harry) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4
m4_define(NAME1, Harry) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4
m4_define(NAME1, Harry) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

MET(Harry, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

MET(Harry, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

MET(Harry, NAME2) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

MET(Harry, Sally) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

MET(Harry, Sally) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

MET(Harry, Sally) ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

Harry met Sally ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

Harry met Sally ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

Harry met Sally ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

Harry met Sally ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

Discovering M4

example.m4

Harry met Sally ~ % m4 -P example.m4

Harry met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

58 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

MET(NAME1, NAME2) Can you guess the output of the above?


A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

MET(Harry, Jr., NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

MET(Harry, Jr., NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

MET(Harry, Jr., NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

MET(Harry, Jr., NAME2) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

MET(Harry, Jr., Sally) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

MET(Harry, Jr., Sally) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

MET(Harry, Jr., Sally) Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

Harry met Jr. Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

Harry met Jr. Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

Harry met Jr. Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

Harry met Jr. Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting
The macros arguments are processed Then the macro is expanded Finally the output of the macro is processed too A string can be protected from processing using quotes. This is a source of many mistakes for the unwary.

example.m4

Harry met Jr. Can you guess the output of the above?
A. Duret-Lutz Using GNU Autotools May 16, 2010 59 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4
m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

m4_define(MET, $1 met $2) MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

MET(NAME1, NAME2)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

NAME1 met NAME2

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

NAME1 met NAME2

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

Harry, Jr. met NAME2

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

Harry, Jr. met NAME2

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

Harry, Jr. met NAME2

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

Harry, Jr. met NAME2

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

Harry, Jr. met NAME2

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

Harry, Jr. met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

Harry, Jr. met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

M4 Quoting Rule of the Thumb

Quote each macro argument once. So it is processed only after it has been output.

example.m4

Harry, Jr. met Sally

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

60 / 162

Using Autoconf

Spacing Matters

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET(NAME1, NAME2) ~ % m4 -P example.m4

Harry, Jr. met Sally


A. Duret-Lutz Using GNU Autotools May 16, 2010 61 / 162

Using Autoconf

Spacing Matters
The parenthesis must stick to the macro name.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET (NAME1, NAME2) ~ % m4 -P example.m4

met (NAME1, NAME2)


A. Duret-Lutz Using GNU Autotools May 16, 2010 61 / 162

Using Autoconf

Spacing Matters
The parenthesis must stick to the macro name. Spaces after or inside quotes are part of the arguments.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET( NAME1 , NAME2) ~ % m4 -P example.m4

Harry, Jr.
A. Duret-Lutz

met Sally
Using GNU Autotools May 16, 2010 61 / 162

Using Autoconf

Spacing Matters
The parenthesis must stick to the macro name. Spaces after or inside quotes are part of the arguments. Spaces before quotes are ignored.

example.m4
m4_define(NAME1, Harry, Jr.) m4_define(NAME2, Sally) m4_define(MET, $1 met $2) MET( NAME1, NAME2) ~ % m4 -P example.m4

Harry, Jr. met Sally


A. Duret-Lutz Using GNU Autotools May 16, 2010 61 / 162

Using Autoconf

Autoconf on Top of M4
Autoconf = M4 with more machinery, and many predened macros.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

62 / 162

Using Autoconf

Autoconf on Top of M4
Autoconf = M4 with more machinery, and many predened macros. The quotes are [ and ] (instead of and ).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

62 / 162

Using Autoconf

Autoconf on Top of M4
Autoconf = M4 with more machinery, and many predened macros. The quotes are [ and ] (instead of and ). For this reason we use the test command instead of [ in shell fragments: if [ "$x" = "$y" ]; then ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

62 / 162

Using Autoconf

Autoconf on Top of M4
Autoconf = M4 with more machinery, and many predened macros. The quotes are [ and ] (instead of and ). For this reason we use the test command instead of [ in shell fragments: if test "$x" = "$y"; then ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

62 / 162

Using Autoconf

Autoconf on Top of M4
Autoconf = M4 with more machinery, and many predened macros. The quotes are [ and ] (instead of and ). For this reason we use the test command instead of [ in shell fragments: if test "$x" = "$y"; then ... Macros are dened with AC DEFUN. AC_DEFUN([NAME1], [Harry, Jr.]) AC_DEFUN([NAME2], [Sally]) AC_DEFUN([MET], [$1 met $2]) MET([NAME1], [NAME2])

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

62 / 162

Using Autoconf

The Structure of a congure.ac


congure.ac
# Prelude. AC_INIT([PACKAGE], [VERSION], [BUG-REPORT-ADDRESS]) # Checks for programs. # # # # # Checks for libraries. Checks for header les. Checks for typedefs, structures, and compiler characteristics. Checks for library functions. Output les.

AC_CONFIG_FILES([FILES]) AC_OUTPUT
A. Duret-Lutz Using GNU Autotools May 16, 2010 63 / 162

Using Autoconf

The Structure of a congure.ac


congure.ac
# Prelude. AC_INIT([amhello], [1.0], [bug-report@address]) # Checks for programs. # # # # # Checks for libraries. Checks for header les. Checks for typedefs, structures, and compiler characteristics. Checks for library functions. Output les.

AC_CONFIG_FILES([FILES]) AC_OUTPUT
A. Duret-Lutz Using GNU Autotools May 16, 2010 63 / 162

Using Autoconf

The Structure of a congure.ac


congure.ac
# Prelude. AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) # Checks for programs. # # # # # Checks for libraries. Checks for header les. Checks for typedefs, structures, and compiler characteristics. Checks for library functions. Output les.

AC_CONFIG_FILES([FILES]) AC_OUTPUT
A. Duret-Lutz Using GNU Autotools May 16, 2010 63 / 162

Using Autoconf

The Structure of a congure.ac


congure.ac
# Prelude. AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) # Checks for programs. AC_PROG_CC # Checks for libraries. # Checks for header les. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. # Output les. AC_CONFIG_FILES([FILES]) AC_OUTPUT
A. Duret-Lutz Using GNU Autotools May 16, 2010 63 / 162

Using Autoconf

The Structure of a congure.ac


congure.ac
# Prelude. AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) # Checks for programs. AC_PROG_CC # Checks for libraries. # Checks for header les. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. # Output les. AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT
A. Duret-Lutz Using GNU Autotools May 16, 2010 63 / 162

Using Autoconf

The Structure of a congure.ac


congure.ac
# Prelude. AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) # Checks for programs. AC_PROG_CC # Checks for libraries. # Checks for header les. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. # Output les. AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT
A. Duret-Lutz Using GNU Autotools May 16, 2010 63 / 162

Using Autoconf

Useful Autoconf Macros for Prelude

AC INIT(PACKAGE, VERSION, BUG-REPORT-ADDRESS) Mandatory Autoconf initialization.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

64 / 162

Using Autoconf

Useful Autoconf Macros for Prelude

AC INIT(PACKAGE, VERSION, BUG-REPORT-ADDRESS) Mandatory Autoconf initialization. AC PREREQ(VERSION) Require a minimum Autoconf version. E.g. AC PREREQ([2.65])

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

64 / 162

Using Autoconf

Useful Autoconf Macros for Prelude

AC INIT(PACKAGE, VERSION, BUG-REPORT-ADDRESS) Mandatory Autoconf initialization. AC PREREQ(VERSION) Require a minimum Autoconf version. E.g. AC PREREQ([2.65]) AC CONFIG SRCDIR(FILE) A safety check. FILE should be a distributed source le, and this makes sure that configure is not run from outer space. E.g. AC CONFIG SRCDIR([src/main.c]).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

64 / 162

Using Autoconf

Useful Autoconf Macros for Prelude

AC INIT(PACKAGE, VERSION, BUG-REPORT-ADDRESS) Mandatory Autoconf initialization. AC PREREQ(VERSION) Require a minimum Autoconf version. E.g. AC PREREQ([2.65]) AC CONFIG SRCDIR(FILE) A safety check. FILE should be a distributed source le, and this makes sure that configure is not run from outer space. E.g. AC CONFIG SRCDIR([src/main.c]). AC CONFIG AUX DIR(DIRECTORY) Auxiliary scripts such as install-sh and depcomp should be in DIRECTORY. E.g. AC CONFIG AUX DIR([build-aux]).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

64 / 162

Using Autoconf

Preparing the Package

~/amhello % ls -R .: Makefile.am configure.ac Makefile.in depcomp* aclocal.m4 install-sh* autom4te.cache/ missing* config.h.in src/ auxiliary tools configure* used during the build ./autom4te.cache: output.0 requests output.1 traces.0
A. ./src: Duret-Lutz

traces.1

Using GNU Autotools

May 16, 2010

65 / 162

Using Autoconf

AC CONFIG AUX DIR Example


congure.ac
AC_INIT([amhello], [1.1], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT % autoreconf --install configure.ac:3: installing missing configure.ac:3: installing install-sh src/Makefile.am: installing depcomp

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

66 / 162

Using Autoconf

AC CONFIG AUX DIR Example


congure.ac
AC_INIT([amhello], [1.1], [bug-report@address]) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT % autoreconf --install configure.ac:3: installing build-aux/missing configure.ac:3: installing build-aux/install-sh src/Makefile.am: installing build-aux/depcomp

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

66 / 162

Using Autoconf

Useful Program Checks


AC PROG CC, AC PROG CXX, AC PROG F77, ... Compiler checks. (Handle search cross-compilers if needed.)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

67 / 162

Using Autoconf

Useful Program Checks


AC PROG CC, AC PROG CXX, AC PROG F77, ... Compiler checks. (Handle search cross-compilers if needed.) AC PROG SED, AC PROG YACC, AC PROG LEX, ... Find good implementations and set $SED, $YACC, $LEX, etc.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

67 / 162

Using Autoconf

Useful Program Checks


AC PROG CC, AC PROG CXX, AC PROG F77, ... Compiler checks. (Handle search cross-compilers if needed.) AC PROG SED, AC PROG YACC, AC PROG LEX, ... Find good implementations and set $SED, $YACC, $LEX, etc. AC CHECK PROGS(VAR, PROGS, [VAL-IF-NOT-FOUND]) Dene VAR to the rst PROGS found, or to VAL-IF-NOT-FOUND otherwise. AC_CHECK_PROGS([TAR], [tar gtar], [:]) if test "$TAR" = :; then AC_MSG_ERROR([This package needs tar.]) fi ... and many more
A. Duret-Lutz Using GNU Autotools May 16, 2010 67 / 162

Using Autoconf

Useful Program Checks


AC PROG CC, AC PROG CXX, AC PROG F77, ... Compiler checks. (Handle search cross-compilers if needed.) AC PROG SED, AC PROG YACC, AC PROG LEX, ... Find good implementations and set $SED, $YACC, $LEX, etc. AC CHECK PROGS(VAR, PROGS, [VAL-IF-NOT-FOUND]) Dene VAR to the rst PROGS found, or to VAL-IF-NOT-FOUND otherwise. AC_CHECK_PROGS([TAR], [tar gtar], [:]) if test "$TAR" = :; then AC_MSG_ERROR([This package needs tar.]) fi ... and many more
A. Duret-Lutz Using GNU Autotools May 16, 2010 67 / 162

Using Autoconf

Useful Autoconf Action Macros


AC MSG ERROR(ERROR-DESCRIPTION, [EXIT-STATUS]) Print ERROR-DESCRIPTION (also to cong.log ) and abort configure. AC MSG WARN(ERROR-DESCRIPTION) Likewise, but dont abort.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

68 / 162

Using Autoconf

Useful Autoconf Action Macros


AC MSG ERROR(ERROR-DESCRIPTION, [EXIT-STATUS]) Print ERROR-DESCRIPTION (also to cong.log ) and abort configure. AC MSG WARN(ERROR-DESCRIPTION) Likewise, but dont abort. AC DEFINE(VARIABLE, VALUE, DESCRIPTION) Output the following to cong.h. /* DESCRIPTION */ #define VARIABLE VALUE

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

68 / 162

Using Autoconf

Useful Autoconf Action Macros


AC MSG ERROR(ERROR-DESCRIPTION, [EXIT-STATUS]) Print ERROR-DESCRIPTION (also to cong.log ) and abort configure. AC MSG WARN(ERROR-DESCRIPTION) Likewise, but dont abort. AC DEFINE(VARIABLE, VALUE, DESCRIPTION) Output the following to cong.h. /* DESCRIPTION */ #define VARIABLE VALUE AC SUBST(VARIABLE, [VALUE]) Dene $(VARIABLE) as VALUE in Makele. AC_SUBST([FOO], [foo]) All equivalent.
A. Duret-Lutz Using GNU Autotools May 16, 2010 68 / 162

FOO=foo AC_SUBST([FOO])

AC_SUBST([FOO]) FOO=foo

Using Autoconf

Checking for Libraries


AC CHECK LIB(LIBRARY, FUNCT, [ACT-IF-FOUND], [ACT-IF-NOT]) Check whether LIBRARY exists and contains FUNCT. Execute ACT-IF-FOUND if it does, ACT-IF-NOT otherwise.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

69 / 162

Using Autoconf

Checking for Libraries


AC CHECK LIB(LIBRARY, FUNCT, [ACT-IF-FOUND], [ACT-IF-NOT]) Check whether LIBRARY exists and contains FUNCT. Execute ACT-IF-FOUND if it does, ACT-IF-NOT otherwise. AC_CHECK_LIB([efence], [malloc], [EFENCELIB=-lefence]) AC_SUBST([EFENCELIB]) ... we would later use $(EFENCELIB) in the link rule.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

69 / 162

Using Autoconf

Checking for Libraries


AC CHECK LIB(LIBRARY, FUNCT, [ACT-IF-FOUND], [ACT-IF-NOT]) Check whether LIBRARY exists and contains FUNCT. Execute ACT-IF-FOUND if it does, ACT-IF-NOT otherwise. AC_CHECK_LIB([efence], [malloc], [EFENCELIB=-lefence]) AC_SUBST([EFENCELIB]) ... we would later use $(EFENCELIB) in the link rule. If ACT-IF-FOUND is not set and the library is found, AC CHECK LIB will do LIBS="-lLIBRARY $LIBS" and #define HAVE LIBLIBRARY. (Automake uses $LIBS for linking everything.)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

69 / 162

Using Autoconf

Checking for Headers


AC CHECK HEADERS(HEADERS...) Check for HEADERS and #define HAVE HEADER H for each header found.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

70 / 162

Using Autoconf

Checking for Headers


AC CHECK HEADERS(HEADERS...) Check for HEADERS and #define HAVE HEADER H for each header found. AC_CHECK_HEADERS([sys/param.h unistd.h]) AC_CHECK_HEADERS([wchar.h]) Might #dene HAVE SYS PARAM H, HAVE UNISTD H, and HAVE WCHAR H.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

70 / 162

Using Autoconf

Checking for Headers


AC CHECK HEADERS(HEADERS...) Check for HEADERS and #define HAVE HEADER H for each header found. AC_CHECK_HEADERS([sys/param.h unistd.h]) AC_CHECK_HEADERS([wchar.h]) Might #dene HAVE SYS PARAM H, HAVE UNISTD H, and HAVE WCHAR H. #i f HAVE UNISTD H # i n c l u d e <u n i s t d . h> #e n d i f

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

70 / 162

Using Autoconf

Checking for Headers


AC CHECK HEADERS(HEADERS...) Check for HEADERS and #define HAVE HEADER H for each header found. AC_CHECK_HEADERS([sys/param.h unistd.h]) AC_CHECK_HEADERS([wchar.h]) Might #dene HAVE SYS PARAM H, HAVE UNISTD H, and HAVE WCHAR H. #i f HAVE UNISTD H # i n c l u d e <u n i s t d . h> #e n d i f AC CHECK HEADER(HEADER, [ACT-IF-FOUND], [ACT-IF-NOT]) Check only one header.
A. Duret-Lutz Using GNU Autotools May 16, 2010 70 / 162

Using Autoconf

Output Commands
AC CONFIG HEADERS(HEADERS...) Create HEADER for all HEADER.in. Use only one such header unless you know what you are doing (autoheader creates HEADER.in only for the rst HEADER). HEADERS contain denitions made with AC DEFINE.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

71 / 162

Using Autoconf

Output Commands
AC CONFIG HEADERS(HEADERS...) Create HEADER for all HEADER.in. Use only one such header unless you know what you are doing (autoheader creates HEADER.in only for the rst HEADER). HEADERS contain denitions made with AC DEFINE. AC_CONFIG_HEADERS([config.h]) Will create cong.h from cong.h.in

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

71 / 162

Using Autoconf

Output Commands
AC CONFIG HEADERS(HEADERS...) Create HEADER for all HEADER.in. Use only one such header unless you know what you are doing (autoheader creates HEADER.in only for the rst HEADER). HEADERS contain denitions made with AC DEFINE. AC_CONFIG_HEADERS([config.h:config.hin]) Will create cong.h from cong.hin (DJGPP supports only 1 dot).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

71 / 162

Using Autoconf

Output Commands
AC CONFIG HEADERS(HEADERS...) Create HEADER for all HEADER.in. Use only one such header unless you know what you are doing (autoheader creates HEADER.in only for the rst HEADER). HEADERS contain denitions made with AC DEFINE. AC_CONFIG_HEADERS([config.h:config.hin]) Will create cong.h from cong.hin (DJGPP supports only 1 dot). AC CONFIG FILES(FILES...) Create FILE for all FILE.in. FILES contain denitions made with AC SUBST.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

71 / 162

Using Autoconf

Output Commands
AC CONFIG HEADERS(HEADERS...) Create HEADER for all HEADER.in. Use only one such header unless you know what you are doing (autoheader creates HEADER.in only for the rst HEADER). HEADERS contain denitions made with AC DEFINE. AC_CONFIG_HEADERS([config.h:config.hin]) Will create cong.h from cong.hin (DJGPP supports only 1 dot). AC CONFIG FILES(FILES...) Create FILE for all FILE.in. FILES contain denitions made with AC SUBST. AC_CONFIG_FILES([Makefile sub/Makefile script.sh:script.in])

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

71 / 162

Using Autoconf

Output Commands
AC CONFIG HEADERS(HEADERS...) Create HEADER for all HEADER.in. Use only one such header unless you know what you are doing (autoheader creates HEADER.in only for the rst HEADER). HEADERS contain denitions made with AC DEFINE. AC_CONFIG_HEADERS([config.h:config.hin]) Will create cong.h from cong.hin (DJGPP supports only 1 dot). AC CONFIG FILES(FILES...) Create FILE for all FILE.in. FILES contain denitions made with AC SUBST. AC_CONFIG_FILES([Makefile sub/Makefile script.sh:script.in]) Automake creates FILE.in for each FILE that has a FILE.am.
A. Duret-Lutz Using GNU Autotools May 16, 2010 71 / 162

Using Autoconf

Output Commands
AC CONFIG HEADERS(HEADERS...) Create HEADER for all HEADER.in. Use only one such header unless you know what you are doing (autoheader creates HEADER.in only for the rst HEADER). HEADERS contain denitions made with AC DEFINE. AC_CONFIG_HEADERS([config.h:config.hin]) Will create cong.h from cong.hin (DJGPP supports only 1 dot). AC CONFIG FILES(FILES...) Create FILE for all FILE.in. FILES contain denitions made with AC SUBST. AC_CONFIG_FILES([Makefile sub/Makefile script.sh:script.in]) Automake creates FILE.in for each FILE that has a FILE.am. Its legitimate to process non-Makeles too.
A. Duret-Lutz Using GNU Autotools May 16, 2010 71 / 162

Using Autoconf

AC CONFIG FILES([script.sh:script.in]) Example


script.in
#!/bin/sh SED=@SED@ TAR=@TAR@ d=$1; shift; mkdir "$d" for f; do "$SED" s/#.*// "$f" \ >"$d/$f" done "$TAR" cf "$d.tar" "$d" .in les are templates

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

72 / 162

Using Autoconf

AC CONFIG FILES([script.sh:script.in]) Example


script.in
#!/bin/sh SED=@SED@ TAR=@TAR@ d=$1; shift; mkdir "$d" for f; do "$SED" s/#.*// "$f" \ >"$d/$f" done "$TAR" cf "$d.tar" "$d" .in les are templates where @XYZ@ are placeholders for AC SUBST([XYZ]) denitions.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

72 / 162

Using Autoconf

AC CONFIG FILES([script.sh:script.in]) Example


script.in
#!/bin/sh SED=@SED@ TAR=@TAR@ d=$1; shift; mkdir "$d" for f; do "$SED" s/#.*// "$f" \ >"$d/$f" done "$TAR" cf "$d.tar" "$d"

script.sh
#!/bin/sh SED=/usr/xpg4/bin/sed TAR=/usr/bin/tar d=$1; shift; mkdir "$d" for f; do "$SED" s/#.*// "$f" \ >"$d/$f" done "$TAR" cf "$d.tar" "$d"

.in les are templates where @XYZ@ are placeholders for AC SUBST([XYZ]) denitions. config.status substitutes them.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

72 / 162

Using Autoconf

AC CONFIG FILES([script.sh:script.in]) Example


script.in
#!/bin/sh SED=@SED@ TAR=@TAR@ d=$1; shift; mkdir "$d" for f; do "$SED" s/#.*// "$f" \ >"$d/$f" done "$TAR" cf "$d.tar" "$d"

script.sh
#!/bin/sh SED=/usr/xpg4/bin/sed TAR=/usr/bin/tar d=$1; shift; mkdir "$d" for f; do "$SED" s/#.*// "$f" \ >"$d/$f" done "$TAR" cf "$d.tar" "$d"

.in les are templates where @XYZ@ are placeholders for AC SUBST([XYZ]) denitions. config.status substitutes them. Makele.ins also use @XYZ@ as placeholders but Automake makes all XYZ=@XYZ@ denitions and you may simply use $(XYZ) as needed.
A. Duret-Lutz Using GNU Autotools May 16, 2010 72 / 162

Using Automake

Using Automake

Hello World Introducing Core Autotools Hello World Explained Using Autoconf Using Automake

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

73 / 162

Using Automake

Automake Principles
Automake helps creating portable and GNU-standard compliant Makeles.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

74 / 162

Using Automake

Automake Principles
Automake helps creating portable and GNU-standard compliant Makeles.
You may be used to other kinds of build systems. (E.g., no VPATH builds, but all objects go into obj/ .)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

74 / 162

Using Automake

Automake Principles
Automake helps creating portable and GNU-standard compliant Makeles.
You may be used to other kinds of build systems. (E.g., no VPATH builds, but all objects go into obj/ .) Do not use Automake if you do not like the GNU Build System: Automake will get in your way if you dont t the mold.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

74 / 162

Using Automake

Automake Principles
Automake helps creating portable and GNU-standard compliant Makeles.
You may be used to other kinds of build systems. (E.g., no VPATH builds, but all objects go into obj/ .) Do not use Automake if you do not like the GNU Build System: Automake will get in your way if you dont t the mold.

automake creates complex Makele.ins from simple Makele.ams.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

74 / 162

Using Automake

Automake Principles
Automake helps creating portable and GNU-standard compliant Makeles.
You may be used to other kinds of build systems. (E.g., no VPATH builds, but all objects go into obj/ .) Do not use Automake if you do not like the GNU Build System: Automake will get in your way if you dont t the mold.

automake creates complex Makele.ins from simple Makele.ams.


Consider Makele.ins as internal details.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

74 / 162

Using Automake

Automake Principles
Automake helps creating portable and GNU-standard compliant Makeles.
You may be used to other kinds of build systems. (E.g., no VPATH builds, but all objects go into obj/ .) Do not use Automake if you do not like the GNU Build System: Automake will get in your way if you dont t the mold.

automake creates complex Makele.ins from simple Makele.ams.


Consider Makele.ins as internal details.

Makele.ams follow roughly the same syntax as Makeles however they usually contains only variable denitions.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

74 / 162

Using Automake

Automake Principles
Automake helps creating portable and GNU-standard compliant Makeles.
You may be used to other kinds of build systems. (E.g., no VPATH builds, but all objects go into obj/ .) Do not use Automake if you do not like the GNU Build System: Automake will get in your way if you dont t the mold.

automake creates complex Makele.ins from simple Makele.ams.


Consider Makele.ins as internal details.

Makele.ams follow roughly the same syntax as Makeles however they usually contains only variable denitions.
automake creates build rules from these denitions.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

74 / 162

Using Automake

Automake Principles
Automake helps creating portable and GNU-standard compliant Makeles.
You may be used to other kinds of build systems. (E.g., no VPATH builds, but all objects go into obj/ .) Do not use Automake if you do not like the GNU Build System: Automake will get in your way if you dont t the mold.

automake creates complex Makele.ins from simple Makele.ams.


Consider Makele.ins as internal details.

Makele.ams follow roughly the same syntax as Makeles however they usually contains only variable denitions.
automake creates build rules from these denitions. Its OK to add extra Makele rules in Makele.am: automake will preserve them in the output.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

74 / 162

Using Automake

Declaring Automake in congure.ac


AM INIT AUTOMAKE([OPTIONS...]) Check for tools needed by automake-generated Makeles.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

75 / 162

Using Automake

The Structure of a congure.ac


congure.ac
# Prelude. AC_INIT([amhello], [1.0], [bug-report@address]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) # Checks for programs. # # # # # Checks for libraries. Checks for header les. Checks for typedefs, structures, and compiler characteristics. Checks for library functions. Output les.

AC_CONFIG_FILES([FILES]) AC_OUTPUT
A. Duret-Lutz Using GNU Autotools May 16, 2010 76 / 162

Using Automake

Declaring Automake in congure.ac


AM INIT AUTOMAKE([OPTIONS...]) Check for tools needed by automake-generated Makeles. Useful options: -Wall Turn all warnings on. -Werror Report warnings as errors. foreign Relax some GNU standard requirements. 1.11.1 Require a minimum version of automake. dist-bzip2 Also create tar.bz2 archives during make dist and make distcheck. tar-ustar Create tar archives using the ustar format.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

77 / 162

Using Automake

Declaring Automake in congure.ac


AM INIT AUTOMAKE([OPTIONS...]) Check for tools needed by automake-generated Makeles. Useful options: -Wall Turn all warnings on. -Werror Report warnings as errors. foreign Relax some GNU standard requirements. 1.11.1 Require a minimum version of automake. dist-bzip2 Also create tar.bz2 archives during make dist and make distcheck. tar-ustar Create tar archives using the ustar format. AC CONFIG FILES(FILES...) Automake creates FILE.in for each FILE that has a FILE.am. AC_CONFIG_FILES([Makefile sub/Makefile]) ... and write Makele.am and sub/ Makele.am.
A. Duret-Lutz Using GNU Autotools May 16, 2010 77 / 162

Using Automake

where PRIMARY Convention for Declaring Targets


Makele.am
where_PRIMARY = targets ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

78 / 162

Using Automake

where PRIMARY Convention for Declaring Targets


Makele.am
where_PRIMARY = targets ... targets should be built as... PROGRAMS LIBRARIES LTLIBRARIES (Libtool libraries) HEADERS SCRIPTS DATA

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

78 / 162

Using Automake

where PRIMARY Convention for Declaring Targets


Makele.am
where_PRIMARY = targets ... targets should be installed in... bin $(bindir) lib $(libdir) ... targets should be built as... PROGRAMS LIBRARIES LTLIBRARIES (Libtool libraries) HEADERS SCRIPTS DATA

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

78 / 162

Using Automake

Standard File System Hierarchy


Directory variable prex exec-prex bindir libdir ... includedir datarootdir datadir mandir infodir ... Default value /usr/ local prex exec-prex/bin exec-prex/lib prex/include prex/share datarootdir datarootdir/man datarootdir/info

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

79 / 162

Using Automake

where PRIMARY Convention for Declaring Targets


Makele.am
where_PRIMARY = targets ... targets should be installed in... bin $(bindir) lib $(libdir) ... targets should be built as... PROGRAMS LIBRARIES LTLIBRARIES (Libtool libraries) HEADERS SCRIPTS DATA

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

80 / 162

Using Automake

where PRIMARY Convention for Declaring Targets


Makele.am
where_PRIMARY = targets ... targets should be installed in... bin $(bindir) lib $(libdir) ... custom $(customdir ) You dene customdir. targets should be built as... PROGRAMS LIBRARIES LTLIBRARIES (Libtool libraries) HEADERS SCRIPTS DATA

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

80 / 162

Using Automake

where PRIMARY Convention for Declaring Targets


Makele.am
where_PRIMARY = targets ... targets should be installed in... bin $(bindir) lib $(libdir) ... custom $(customdir ) You dene customdir. targets should be built as... PROGRAMS LIBRARIES LTLIBRARIES (Libtool libraries) HEADERS SCRIPTS DATA

noinst Not installed.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

80 / 162

Using Automake

where PRIMARY Convention for Declaring Targets


Makele.am
where_PRIMARY = targets ... targets should be installed in... bin $(bindir) lib $(libdir) ... custom $(customdir ) You dene customdir. targets should be built as... PROGRAMS LIBRARIES LTLIBRARIES (Libtool libraries) HEADERS SCRIPTS DATA

noinst Not installed. check Built by make check.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

80 / 162

Using Automake

where PRIMARY Convention for Declaring Targets


Makele.am
option_where_PRIMARY = targets ... targets should be installed in... bin $(bindir) lib $(libdir) ... custom $(customdir ) You dene customdir. targets should be built as... PROGRAMS LIBRARIES LTLIBRARIES (Libtool libraries) HEADERS SCRIPTS DATA

noinst Not installed. check Built by make check. Optionally:


A. Duret-Lutz

dist Distribute targets (if not the default) nodist Dont.


Using GNU Autotools May 16, 2010 80 / 162

Using Automake

Declaring Sources
Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c These programs will be installed in $(bindir).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

81 / 162

Using Automake

Declaring Sources
Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c These programs will be installed in $(bindir). The sources of each program go into program SOURCES.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

81 / 162

Using Automake

Declaring Sources
Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c These programs will be installed in $(bindir). The sources of each program go into program SOURCES. Non-alphanumeric characters are mapped to .

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

81 / 162

Using Automake

Declaring Sources
Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c These programs will be installed in $(bindir). The sources of each program go into program SOURCES. Non-alphanumeric characters are mapped to . Automake automatically computes the list of objects to build and link from these les.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

81 / 162

Using Automake

Declaring Sources
Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c These programs will be installed in $(bindir). The sources of each program go into program SOURCES. Non-alphanumeric characters are mapped to . Automake automatically computes the list of objects to build and link from these les. Header les are not compiled. We list them only so they get distributed (Automake does not distribute les it does not know about).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

81 / 162

Using Automake

Declaring Sources
Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c These programs will be installed in $(bindir). The sources of each program go into program SOURCES. Non-alphanumeric characters are mapped to . Automake automatically computes the list of objects to build and link from these les. Header les are not compiled. We list them only so they get distributed (Automake does not distribute les it does not know about). Its OK to use the same source for two programs.
A. Duret-Lutz Using GNU Autotools May 16, 2010 81 / 162

Using Automake

Declaring Sources
Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c These programs will be installed in $(bindir). The sources of each program go into program SOURCES. Non-alphanumeric characters are mapped to . Automake automatically computes the list of objects to build and link from these les. Header les are not compiled. We list them only so they get distributed (Automake does not distribute les it does not know about). Its OK to use the same source for two programs. Compiler and linker are inferred from the extensions.
A. Duret-Lutz Using GNU Autotools May 16, 2010 81 / 162

Using Automake

(Static) Libraries

Add AC PROG RANLIB to congure.ac.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

82 / 162

Using Automake

(Static) Libraries

Add AC PROG RANLIB to congure.ac.

Makele.am
lib_LIBRARIES = libfoo.a libbar.a libfoo_a_SOURCES = foo.c privfoo.h libbar_a_SOURCES = bar.c privbar.h include_HEADERS = foo.h bar.h

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

82 / 162

Using Automake

(Static) Libraries

Add AC PROG RANLIB to congure.ac.

Makele.am
lib_LIBRARIES = libfoo.a libbar.a libfoo_a_SOURCES = foo.c privfoo.h libbar_a_SOURCES = bar.c privbar.h include_HEADERS = foo.h bar.h These libraries will be installed in $(libdir).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

82 / 162

Using Automake

(Static) Libraries

Add AC PROG RANLIB to congure.ac.

Makele.am
lib_LIBRARIES = libfoo.a libbar.a libfoo_a_SOURCES = foo.c privfoo.h libbar_a_SOURCES = bar.c privbar.h include_HEADERS = foo.h bar.h These libraries will be installed in $(libdir). Library names must match lib*.a.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

82 / 162

Using Automake

(Static) Libraries

Add AC PROG RANLIB to congure.ac.

Makele.am
lib_LIBRARIES = libfoo.a libbar.a libfoo_a_SOURCES = foo.c privfoo.h libbar_a_SOURCES = bar.c privbar.h include_HEADERS = foo.h bar.h These libraries will be installed in $(libdir). Library names must match lib*.a. Public headers will be installed in $(includedir).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

82 / 162

Using Automake

(Static) Libraries

Add AC PROG RANLIB to congure.ac.

Makele.am
lib_LIBRARIES = libfoo.a libbar.a libfoo_a_SOURCES = foo.c privfoo.h libbar_a_SOURCES = bar.c privbar.h include_HEADERS = foo.h bar.h These libraries will be installed in $(libdir). Library names must match lib*.a. Public headers will be installed in $(includedir). Private headers are not installed, like ordinary source les.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

82 / 162

Using Automake

Directory Layout
You may have one Makele (hence one Makele.am) per directory.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

83 / 162

Using Automake

Directory Layout
You may have one Makele (hence one Makele.am) per directory. They must all be declared in congure.ac.

congure.ac
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile src/dira/Makefile src/dirb/Makefile])

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

83 / 162

Using Automake

Directory Layout
You may have one Makele (hence one Makele.am) per directory. They must all be declared in congure.ac.

congure.ac
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile src/dira/Makefile src/dirb/Makefile]) make is run at the top-level. Makele.ams should x the order in which to recurse directories using the SUBDIRS variable.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

83 / 162

Using Automake

Directory Layout
You may have one Makele (hence one Makele.am) per directory. They must all be declared in congure.ac.

congure.ac
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile src/dira/Makefile src/dirb/Makefile]) make is run at the top-level. Makele.ams should x the order in which to recurse directories using the SUBDIRS variable.

Makele.am
SUBDIRS = lib src

src/ Makele.am
SUBDIRS = dira dirb

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

83 / 162

Using Automake

Directory Layout
You may have one Makele (hence one Makele.am) per directory. They must all be declared in congure.ac.

congure.ac
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile src/dira/Makefile src/dirb/Makefile]) make is run at the top-level. Makele.ams should x the order in which to recurse directories using the SUBDIRS variable.

Makele.am
SUBDIRS = lib src

src/ Makele.am

SUBDIRS = dira dirb The current directory is implicitly built after subdirectories.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

83 / 162

Using Automake

Directory Layout
You may have one Makele (hence one Makele.am) per directory. They must all be declared in congure.ac.

congure.ac
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile src/dira/Makefile src/dirb/Makefile]) make is run at the top-level. Makele.ams should x the order in which to recurse directories using the SUBDIRS variable.

Makele.am
SUBDIRS = lib src

src/ Makele.am

SUBDIRS = dira dirb . The current directory is implicitly built after subdirectories. You can put . where you want to override this.
A. Duret-Lutz Using GNU Autotools May 16, 2010 83 / 162

Using Automake

Directory Layout
You may have one Makele (hence one Makele.am) per directory. They must all be declared in congure.ac.

congure.ac
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile src/dira/Makefile src/dirb/Makefile]) make is run at the top-level. Makele.ams should x the order in which to recurse directories using the SUBDIRS variable.

Makele.am
SUBDIRS = lib src

src/ Makele.am

SUBDIRS = dira . dirb The current directory is implicitly built after subdirectories. You can put . where you want to override this.
A. Duret-Lutz Using GNU Autotools May 16, 2010 83 / 162

Using Automake

Directory Layout
You may have one Makele (hence one Makele.am) per directory. They must all be declared in congure.ac.

congure.ac
AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile src/dira/Makefile src/dirb/Makefile]) make is run at the top-level. Makele.ams should x the order in which to recurse directories using the SUBDIRS variable.

Makele.am
SUBDIRS = lib src

src/ Makele.am

SUBDIRS = . dira dirb The current directory is implicitly built after subdirectories. You can put . where you want to override this.
A. Duret-Lutz Using GNU Autotools May 16, 2010 83 / 162

Using Automake

$(srcdir) and VPATH Builds


Remember VPATH builds: a source le is not necessary in the current directory.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

84 / 162

Using Automake

Parallel Build Trees (a.k.a. VPATH Builds)

Objects les, programs, and libraries are built where congure was run. ~ % tar zxf ~/amhello-1.0.tar.gz ~ % cd amhello-1.0 ~/amhello-1.0 % mkdir build && cd build ~/amhello-1.0/build % ../configure ~/amhello-1.0/build % make ... Sources les are in / amhello-1.0/ , built les are all in / amhello-1.0/ build/ .

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

85 / 162

Using Automake

$(srcdir) and VPATH Builds


Remember VPATH builds: a source le is not necessary in the current directory. There are two twin trees: the build tree, and the source tree.
Makele and objects les are in the build tree. Makele.in, Makele.am, and source les are in the source tree. If ./configure is run in the current directory, the two trees are one.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

86 / 162

Using Automake

$(srcdir) and VPATH Builds


Remember VPATH builds: a source le is not necessary in the current directory. There are two twin trees: the build tree, and the source tree.
Makele and objects les are in the build tree. Makele.in, Makele.am, and source les are in the source tree. If ./configure is run in the current directory, the two trees are one.

In each Makele, config.status will dene $(srcdir): the path to the matching source directory.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

86 / 162

Using Automake

$(srcdir) and VPATH Builds


Remember VPATH builds: a source le is not necessary in the current directory. There are two twin trees: the build tree, and the source tree.
Makele and objects les are in the build tree. Makele.in, Makele.am, and source les are in the source tree. If ./configure is run in the current directory, the two trees are one.

In each Makele, config.status will dene $(srcdir): the path to the matching source directory. When referring to sources les or targets in Automake variables, you do not have to worry about source vs. build, because make will check both directories.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

86 / 162

Using Automake

$(srcdir) and VPATH Builds


Remember VPATH builds: a source le is not necessary in the current directory. There are two twin trees: the build tree, and the source tree.
Makele and objects les are in the build tree. Makele.in, Makele.am, and source les are in the source tree. If ./configure is run in the current directory, the two trees are one.

In each Makele, config.status will dene $(srcdir): the path to the matching source directory. When referring to sources les or targets in Automake variables, you do not have to worry about source vs. build, because make will check both directories. You may need $(srcdir) when specifying ags for tools, or writing custom commands. E.g., to tell the compiler to include headers from dir/ , you should write -I$(srcdir)/dir, not -Idir. (-Idir would fetch headers from the build tree.)
A. Duret-Lutz Using GNU Autotools May 16, 2010 86 / 162

Using Automake

Convenience Libraries
lib/ Makele.am
noinst_LIBRARIES = libcompat.a libcompat_a_SOURCES = xalloc.c xalloc.h

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

87 / 162

Using Automake

Convenience Libraries
lib/ Makele.am
noinst_LIBRARIES = libcompat.a libcompat_a_SOURCES = xalloc.c xalloc.h This is a convenience library, used only when building the package.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

87 / 162

Using Automake

Convenience Libraries
lib/ Makele.am
noinst_LIBRARIES = libcompat.a libcompat_a_SOURCES = xalloc.c xalloc.h This is a convenience library, used only when building the package.

src/ Makele.am
LDADD = ../lib/libcompat.a AM_CPPFLAGS = -I$(srcdir)/../lib bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

87 / 162

Using Automake

Convenience Libraries
lib/ Makele.am
noinst_LIBRARIES = libcompat.a libcompat_a_SOURCES = xalloc.c xalloc.h This is a convenience library, used only when building the package.

src/ Makele.am
LDADD = ../lib/libcompat.a AM_CPPFLAGS = -I$(srcdir)/../lib bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c LDADD is added when linking all programs.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

87 / 162

Using Automake

Convenience Libraries
lib/ Makele.am
noinst_LIBRARIES = libcompat.a libcompat_a_SOURCES = xalloc.c xalloc.h This is a convenience library, used only when building the package.

src/ Makele.am
LDADD = ../lib/libcompat.a AM_CPPFLAGS = -I$(srcdir)/../lib bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c LDADD is added when linking all programs. AM CPPFLAGS contains additional preprocessor ags.
A. Duret-Lutz Using GNU Autotools May 16, 2010 87 / 162

Using Automake

Convenience Libraries
lib/ Makele.am
noinst_LIBRARIES = libcompat.a libcompat_a_SOURCES = xalloc.c xalloc.h This is a convenience library, used only when building the package.

src/ Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c run_me_LDADD = ../lib/libcompat.a run_me_CPPFLAGS = -I$(srcdir)/../lib LDADD is added when linking all programs. AM CPPFLAGS contains additional preprocessor ags. You can use per-target variables: they apply to a single program.
A. Duret-Lutz Using GNU Autotools May 16, 2010 87 / 162

Using Automake

Per-Target Flags
Assuming foo is a program or library: foo CFLAGS Additional C compiler ags foo CPPFLAGS Additional preprocessor ags (-Is and -Ds)

The default value for foo XXXFLAGS is $(AM XXXFLAGS).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

88 / 162

Using Automake

Per-Target Flags
Assuming foo is a program or library: foo CFLAGS Additional C compiler ags foo CPPFLAGS Additional preprocessor ags (-Is and -Ds) foo LDADD Additional link objects, -ls and -Ls (if foo is a program) foo LIBADD Additional link objects, -ls and -Ls (if foo is a library) foo LDFLAGS Additional linker ags The default value for foo XXXFLAGS is $(AM XXXFLAGS).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

88 / 162

Using Automake

Per-Target Flags
Assuming foo is a program or library: foo CFLAGS Additional C compiler ags foo CPPFLAGS Additional preprocessor ags (-Is and -Ds) foo LDADD Additional link objects, -ls and -Ls (if foo is a program) foo LIBADD Additional link objects, -ls and -Ls (if foo is a library) foo LDFLAGS Additional linker ags The default value for foo XXXFLAGS is $(AM XXXFLAGS). Use plain le names to refer to libraries inside your package (keep -ls and -Ls for external libraries only).

src/ Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c run_me_CPPFLAGS = -I$(srcdir)/../lib run_me_LDADD = ../lib/libcompat.a
A. Duret-Lutz Using GNU Autotools May 16, 2010 88 / 162

Using Automake

Checking for Libraries


AC CHECK LIB(LIBRARY, FUNCT, [ACT-IF-FOUND], [ACT-IF-NOT]) Check whether LIBRARY exists and contains FUNCT. Execute ACT-IF-FOUND if it does, ACT-IF-NOT otherwise. AC_CHECK_LIB([efence], [malloc], [EFENCELIB=-lefence]) AC_SUBST([EFENCELIB]) ... we would later use $(EFENCELIB) in the link rule.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

89 / 162

Using Automake

Per-Target Flags
Assuming foo is a program or library: foo CFLAGS Additional C compiler ags foo CPPFLAGS Additional preprocessor ags (-Is and -Ds) foo LDADD Additional link objects, -ls and -Ls (if foo is a program) foo LIBADD Additional link objects, -ls and -Ls (if foo is a library) foo LDFLAGS Additional linker ags The default value for foo XXXFLAGS is $(AM XXXFLAGS). Use plain le names to refer to libraries inside your package (keep -ls and -Ls for external libraries only).

src/ Makele.am
bin_PROGRAMS = foo run-me foo_SOURCES = foo.c foo.h print.c print.h run_me_SOURCES = run.c run.h print.c run_me_CPPFLAGS = -I$(srcdir)/../lib run_me_LDADD = ../lib/libcompat.a $(EFENCELIB)
A. Duret-Lutz Using GNU Autotools May 16, 2010 90 / 162

Using Automake

What Gets Distributed


make dist and make distcheck create a tarball containing: All sources declared using ... SOURCES All headers declared using ... HEADERS

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

91 / 162

Using Automake

What Gets Distributed


make dist and make distcheck create a tarball containing: All sources declared using ... SOURCES All headers declared using ... HEADERS All scripts declared with dist ... SCRIPTS All data les declared with dist ... DATA ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

91 / 162

Using Automake

What Gets Distributed


make dist and make distcheck create a tarball containing: All sources declared using ... SOURCES All headers declared using ... HEADERS All scripts declared with dist ... SCRIPTS All data les declared with dist ... DATA ... Common les such as ChangeLog , NEWS, etc. See automake --help for a list of those les.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

91 / 162

Using Automake

What Gets Distributed


make dist and make distcheck create a tarball containing: All sources declared using ... SOURCES All headers declared using ... HEADERS All scripts declared with dist ... SCRIPTS All data les declared with dist ... DATA ... Common les such as ChangeLog , NEWS, etc. See automake --help for a list of those les. Extra les or directories listed into EXTRA DIST.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

91 / 162

Using Automake

What Gets Distributed


make dist and make distcheck create a tarball containing: All sources declared using ... SOURCES All headers declared using ... HEADERS All scripts declared with dist ... SCRIPTS All data les declared with dist ... DATA ... Common les such as ChangeLog , NEWS, etc. See automake --help for a list of those les. Extra les or directories listed into EXTRA DIST.

Makele.am
SUBDIRS = lib src EXTRA_DIST = HACKING ... will additionally distribute HACKING .
A. Duret-Lutz Using GNU Autotools May 16, 2010 91 / 162

Using Automake

Conditionals: Usage
Conditionals allow for conditional builds and unconditional distribution.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

92 / 162

Using Automake

Conditionals: Usage
Conditionals allow for conditional builds and unconditional distribution.

Conditional Programs
bin_PROGRAMS = foo if WANT_BAR bin_PROGRAMS += bar endif foo_SOURCES = foo.c bar_SOURCES = bar.c

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

92 / 162

Using Automake

Conditionals: Usage
Conditionals allow for conditional builds and unconditional distribution.

Conditional Programs
bin_PROGRAMS = foo if WANT_BAR bin_PROGRAMS += bar endif foo_SOURCES = foo.c bar_SOURCES = bar.c

Conditional Sources
bin_PROGRAMS = foo foo_SOURCES = foo.c if WANT_BAR foo_SOURCES += bar.c endif

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

92 / 162

Using Automake

Conditionals: Usage
Conditionals allow for conditional builds and unconditional distribution.

Conditional Programs

bin_PROGRAMS = foo bin_PROGRAMS = foo if WANT_BAR foo_SOURCES = foo.c bin_PROGRAMS += bar if WANT_BAR endif foo_SOURCES += bar.c foo_SOURCES = foo.c endif bar_SOURCES = bar.c bar is built i WANT BAR is true.

Conditional Sources

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

92 / 162

Using Automake

Conditionals: Usage
Conditionals allow for conditional builds and unconditional distribution.

Conditional Programs

bin_PROGRAMS = foo bin_PROGRAMS = foo if WANT_BAR foo_SOURCES = foo.c bin_PROGRAMS += bar if WANT_BAR endif foo_SOURCES += bar.c foo_SOURCES = foo.c endif bar_SOURCES = bar.c bar is built i WANT BAR is true. bar.o is linked in foo i WANT BAR is true.

Conditional Sources

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

92 / 162

Using Automake

Conditionals: Usage
Conditionals allow for conditional builds and unconditional distribution.

Conditional Programs

bin_PROGRAMS = foo bin_PROGRAMS = foo if WANT_BAR foo_SOURCES = foo.c bin_PROGRAMS += bar if WANT_BAR endif foo_SOURCES += bar.c foo_SOURCES = foo.c endif bar_SOURCES = bar.c bar is built i WANT BAR is true. bar.o is linked in foo i WANT BAR is true. In all cases foo.c and bar.c are distributed regardless of WANT BAR.

Conditional Sources

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

92 / 162

Using Automake

Conditionals: Usage
Conditionals allow for conditional builds and unconditional distribution.

Conditional Programs

bin_PROGRAMS = foo bin_PROGRAMS = foo if WANT_BAR foo_SOURCES = foo.c bin_PROGRAMS += bar if WANT_BAR endif foo_SOURCES += bar.c foo_SOURCES = foo.c endif bar_SOURCES = bar.c bar is built i WANT BAR is true. bar.o is linked in foo i WANT BAR is true. In all cases foo.c and bar.c are distributed regardless of WANT BAR. This is portable. config.status will comment rules of Makele.in that must be disabled.
A. Duret-Lutz Using GNU Autotools May 16, 2010 92 / 162

Conditional Sources

Using Automake

Conditionals: Usage
Conditionals allow for conditional builds and unconditional distribution.

Conditional Programs

bin_PROGRAMS = foo bin_PROGRAMS = foo if WANT_BAR foo_SOURCES = foo.c bin_PROGRAMS += bar if WANT_BAR endif foo_SOURCES += bar.c foo_SOURCES = foo.c endif bar_SOURCES = bar.c bar is built i WANT BAR is true. bar.o is linked in foo i WANT BAR is true. In all cases foo.c and bar.c are distributed regardless of WANT BAR. This is portable. config.status will comment rules of Makele.in that must be disabled. WANT BAR must be declared and valued in congure.ac.
A. Duret-Lutz Using GNU Autotools May 16, 2010 92 / 162

Conditional Sources

Using Automake

Conditionals: Declaration

AM CONDITIONAL(NAME, CONDITION) Declare conditional NAME. CONDITION should be a shell instruction that succeeds i NAME should be enabled.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

93 / 162

Using Automake

Conditionals: Declaration

AM CONDITIONAL(NAME, CONDITION) Declare conditional NAME. CONDITION should be a shell instruction that succeeds i NAME should be enabled.

congure.ac
AC_CHECK_HEADER([bar.h], [use_bar=yes]) AM_CONDITIONAL([WANT_BAR], [test "$use_bar" = yes]) Will enable WANT BAR only if bar.h is present on the system.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

93 / 162

Using Automake

Extending Automake Rules


The contents of Makele.am are copied almost verbatim to Makele.in. automake adds new rules and variables in Makele.in, to achieve the semantics of the special variables you have dened. Some minor rewriting is done to handle constructs like conditionals or += portably.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

94 / 162

Using Automake

Extending Automake Rules


The contents of Makele.am are copied almost verbatim to Makele.in. automake adds new rules and variables in Makele.in, to achieve the semantics of the special variables you have dened. Some minor rewriting is done to handle constructs like conditionals or += portably. Its OK to dene your own rules in Makele.am.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

94 / 162

Using Automake

Extending Automake Rules


The contents of Makele.am are copied almost verbatim to Makele.in. automake adds new rules and variables in Makele.in, to achieve the semantics of the special variables you have dened. Some minor rewriting is done to handle constructs like conditionals or += portably. Its OK to dene your own rules in Makele.am.
Helpful maintenance targets (make style-check) Build idiosyncratic les (generate a FAQ from some random source) ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

94 / 162

Using Automake

Extending Automake Rules


The contents of Makele.am are copied almost verbatim to Makele.in. automake adds new rules and variables in Makele.in, to achieve the semantics of the special variables you have dened. Some minor rewriting is done to handle constructs like conditionals or += portably. Its OK to dene your own rules in Makele.am.
Helpful maintenance targets (make style-check) Build idiosyncratic les (generate a FAQ from some random source) ...

Its OK to dene variables that are meaningless to Automake.


For use in custom rules.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

94 / 162

Using Automake

Extending Automake Rules


The contents of Makele.am are copied almost verbatim to Makele.in. automake adds new rules and variables in Makele.in, to achieve the semantics of the special variables you have dened. Some minor rewriting is done to handle constructs like conditionals or += portably. Its OK to dene your own rules in Makele.am.
Helpful maintenance targets (make style-check) Build idiosyncratic les (generate a FAQ from some random source) ...

Its OK to dene variables that are meaningless to Automake.


For use in custom rules.

Beware of conicts: your denitions (of variables or rules) will override those of Automake.
-Wall will diagnose these.
A. Duret-Lutz Using GNU Autotools May 16, 2010 94 / 162

Using Automake

Recommendations

Use -Wall -Werror.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

95 / 162

Using Automake

Recommendations

Use -Wall -Werror. Keep Your Setup Simple (KYSS!).


You will spend a large part of time debugging your cunning tricks if you try to automatize too much.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

95 / 162

Using Automake

Recommendations

Use -Wall -Werror. Keep Your Setup Simple (KYSS!).


You will spend a large part of time debugging your cunning tricks if you try to automatize too much.

Do not lie to Automake.


Automake can be annoying, but when you lie it gets worse!

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

95 / 162

Using Automake

Lost? autoreconf is Still Your Friend


If make fails to rebuild conguration les, run autoreconf manually. ~/amhello % autoreconf --install

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

96 / 162

Using Automake

Lost? autoreconf is Still Your Friend


If make fails to rebuild conguration les, run autoreconf manually. ~/amhello % autoreconf --install If this does not help, try harder. ~/amhello % autoreconf --install --force

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

96 / 162

Using Automake

Lost? autoreconf is Still Your Friend


If make fails to rebuild conguration les, run autoreconf manually. ~/amhello % autoreconf --install If this does not help, try harder. ~/amhello % autoreconf --install --force If this still does not help, try even harder. ~/amhello % make -k maintainer-clean ~/amhello % autoreconf --install --force Do this only when necessary. Each of these commands will cause your package to take longer to recongure and recompile.
A. Duret-Lutz Using GNU Autotools May 16, 2010 96 / 162

Part III More Autotools


10

Writing and Managing Custom Macros Writing Autoconf Macros Managing Custom Macros with aclocal Libtool Gettext Introducing Gettext Internationalizing a Package, Start to Finish Localizing a Package Nested Packages The End
A. Duret-Lutz Using GNU Autotools May 16, 2010 97 / 162

11 12

13 14

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing Autoconf Macros


10

Writing and Managing Custom Macros Writing Autoconf Macros Managing Custom Macros with aclocal Libtool Gettext Introducing Gettext Internationalizing a Package, Start to Finish Localizing a Package Nested Packages The End

11 12

13 14

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

98 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing an Autoconf Macro? Why? How?

Two fundamentally dierent types of new macros: Macros that factor related tests in a single reusable entity.

Macros that implements new tests.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

99 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing an Autoconf Macro? Why? How?

Two fundamentally dierent types of new macros: Macros that factor related tests in a single reusable entity.
High-level. Combination of existing lower-level macros. May not use shell code at all.

Macros that implements new tests.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

99 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing an Autoconf Macro? Why? How?

Two fundamentally dierent types of new macros: Macros that factor related tests in a single reusable entity.
High-level. Combination of existing lower-level macros. May not use shell code at all.

Macros that implements new tests.


Low-level. Actually code the check. Need to bother with caching values.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

99 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Dening Macros
AC DEFUN(MACRO-NAME, MACRO-BODY) Dene MACRO-NAME as MACRO-BODY. Avoid names that may conict.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

100 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Dening Macros
AC DEFUN(MACRO-NAME, MACRO-BODY) Dene MACRO-NAME as MACRO-BODY. Avoid names that may conict. Macro name spaces: m4 Original M4 macros, plus M4sugar macros. AS M4sh macros (macroized shell constructs) AH Autoheader macros AC Autoconf macros (written on top of the above layers)

AM Automake macros AT Autotest macros


A. Duret-Lutz Using GNU Autotools May 16, 2010 100 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Dening Macros
AC DEFUN(MACRO-NAME, MACRO-BODY) Dene MACRO-NAME as MACRO-BODY. Avoid names that may conict. Macro name spaces: m4 Original M4 macros, plus M4sugar macros. AS M4sh macros (macroized shell constructs) AH Autoheader macros AC Autoconf macros (written on top of the above layers) AC CHECK Generic checks. AC FUNC Specic function checks. AC HEADER Specic header checks. AC PROG Specic program checks. ... AM Automake macros AT Autotest macros
A. Duret-Lutz Using GNU Autotools May 16, 2010 100 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

mkdir() Example
POSIX systems dene mkdir() with two arguments. On Mingw32 (at least), mkdir() takes only one argument. On Win32 (at least), the name is mkdir() with one argument.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

101 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

mkdir() Example
POSIX systems dene mkdir() with two arguments. On Mingw32 (at least), mkdir() takes only one argument. On Win32 (at least), the name is mkdir() with one argument. #if HAVE_MKDIR # if MKDIR_ONE_ARG # define mkdir(a,b) mkdir(a) # endif #else # if HAVE__MKDIR # define mkdir(a,b) _mkdir(a) # else # error "Dont know how to create a directory." # endif #endif
A. Duret-Lutz Using GNU Autotools May 16, 2010 101 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

mkdir() Example
POSIX systems dene mkdir() with two arguments. On Mingw32 (at least), mkdir() takes only one argument. On Win32 (at least), the name is mkdir() with one argument. #if HAVE_MKDIR # if MKDIR_ONE_ARG # define mkdir(a,b) mkdir(a) # endif #else # if HAVE__MKDIR # define mkdir(a,b) _mkdir(a) # else # error "Dont know how to create a directory." # endif #endif Lets write an Autoconf macro to dene these C macros.
A. Duret-Lutz Using GNU Autotools May 16, 2010 101 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a High-Level Macro: AX FUNC MKDIR


AC_DEFUN([AX_FUNC_MKDIR], [AC_CHECK_FUNCS([mkdir _mkdir]) AC_CHECK_HEADERS([io.h]) AX_FUNC_MKDIR_ONE_ARG ])

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

102 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a High-Level Macro: AX FUNC MKDIR


AC_DEFUN([AX_FUNC_MKDIR], [AC_CHECK_FUNCS([mkdir _mkdir]) AC_CHECK_HEADERS([io.h]) AX_FUNC_MKDIR_ONE_ARG ]) Suggested name space for extension macros.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

102 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a High-Level Macro: AX FUNC MKDIR


AC_DEFUN([AX_FUNC_MKDIR], [AC_CHECK_FUNCS([mkdir _mkdir]) AC_CHECK_HEADERS([io.h]) AX_FUNC_MKDIR_ONE_ARG ]) Suggested name space for extension macros. Use same convention as Autoconf for categorizing macros.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

102 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a High-Level Macro: AX FUNC MKDIR


AC_DEFUN([AX_FUNC_MKDIR], [AC_CHECK_FUNCS([mkdir _mkdir]) AC_CHECK_HEADERS([io.h]) AX_FUNC_MKDIR_ONE_ARG ]) Suggested name space for extension macros. Use same convention as Autoconf for categorizing macros. Denes HAVE MKDIR and HAVE MKDIR.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

102 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a High-Level Macro: AX FUNC MKDIR


AC_DEFUN([AX_FUNC_MKDIR], [AC_CHECK_FUNCS([mkdir _mkdir]) AC_CHECK_HEADERS([io.h]) AX_FUNC_MKDIR_ONE_ARG ]) Suggested name space for extension macros. Use same convention as Autoconf for categorizing macros. Denes HAVE MKDIR and HAVE MKDIR. Denes HAVE IO H if io.h exists. (mkdir() may also be dened there, and sys/ stat.h and unistd.h are always tested by AC PROG CC)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

102 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a High-Level Macro: AX FUNC MKDIR


AC_DEFUN([AX_FUNC_MKDIR], [AC_CHECK_FUNCS([mkdir _mkdir]) AC_CHECK_HEADERS([io.h]) AX_FUNC_MKDIR_ONE_ARG ]) Suggested name space for extension macros. Use same convention as Autoconf for categorizing macros. Denes HAVE MKDIR and HAVE MKDIR. Denes HAVE IO H if io.h exists. (mkdir() may also be dened there, and sys/ stat.h and unistd.h are always tested by AC PROG CC) Will dene MKDIR ONE ARG... once written.
A. Duret-Lutz Using GNU Autotools May 16, 2010 102 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Checking mkdir()s number of arguments


# _AX_FUNC_MKDIR_ONE_ARG(IF-ONE-ARG, IF-TWO-ARGS) # ----------------------------------------------# Execute IF-TWO-ARGS if mkdir() accepts two # arguments; execute IF-ONE-ARG otherwise. AC_DEFUN([_AX_FUNC_MKDIR_ONE_ARG], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <sys/stat.h> #if HAVE_UNISTD_H # include <unistd.h> #endif #if HAVE_IO_H # include <io.h> #endif ]], [[mkdir (".", 0700);]])], [$2], [$1])])

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

103 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Checking mkdir()s number of arguments


# _AX_FUNC_MKDIR_ONE_ARG(IF-ONE-ARG, IF-TWO-ARGS) # ----------------------------------------------# Execute IF-TWO-ARGS if mkdir() accepts two # arguments; execute IF-ONE-ARG otherwise. AC_DEFUN([_AX_FUNC_MKDIR_ONE_ARG], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <sys/stat.h> Comments #if HAVE_UNISTD_H # include <unistd.h> Showcase of the traditional style used to #endif document autoconf macros. #if HAVE_IO_H # include <io.h> #endif ]], [[mkdir (".", 0700);]])], [$2], [$1])])

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

103 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Checking mkdir()s number of arguments


# _AX_FUNC_MKDIR_ONE_ARG(IF-ONE-ARG, IF-TWO-ARGS) # ----------------------------------------------# Execute IF-TWO-ARGS if mkdir() accepts two # arguments; execute IF-ONE-ARG otherwise. AC_DEFUN([_AX_FUNC_MKDIR_ONE_ARG], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <sys/stat.h> AC COMPILE IFELSE #if HAVE_UNISTD_H # include <unistd.h> Creates a small program and attempt to compile #endif it. In our case it will execute one of #if HAVE_IO_H AX FUNC MKDIR ONE ARGs arguments # include <io.h> depending on whether compilation succeeded. #endif ]], [[mkdir (".", 0700);]])], [$2], [$1])])

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

103 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Checking mkdir()s number of arguments


# _AX_FUNC_MKDIR_ONE_ARG(IF-ONE-ARG, IF-TWO-ARGS) # ----------------------------------------------# Execute IF-TWO-ARGS if mkdir() accepts two # arguments; execute IF-ONE-ARG otherwise. AC_DEFUN([_AX_FUNC_MKDIR_ONE_ARG], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <sys/stat.h> #if HAVE_UNISTD_H # include <unistd.h> #endif #if HAVE_IO_H # include <io.h> #endif ]], [[mkdir (".", 0700);]])], [$2], [$1])])

Wait! Thats not enough for an Autoconf check: we should also add some checking whether... message on top of this.
A. Duret-Lutz Using GNU Autotools May 16, 2010 103 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Checking mkdir()s number of arguments


# _AX_FUNC_MKDIR_ONE_ARG(IF-ONE-ARG, IF-TWO-ARGS) # ----------------------------------------------# Execute IF-TWO-ARGS if mkdir() accepts two # arguments; execute IF-ONE-ARG otherwise. AC_DEFUN([_AX_FUNC_MKDIR_ONE_ARG], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <sys/stat.h> #if HAVE_UNISTD_H # include <unistd.h> #endif #if HAVE_IO_H # include <io.h> #endif ]], [[mkdir (".", 0700);]])], [$2], [$1])])

Wait! Thats not enough for an Autoconf check: we should also add some checking whether... message on top of this. We use the AX prex for helper macros not meant to be used directly.
A. Duret-Lutz Using GNU Autotools May 16, 2010 103 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a Low-Level Macro


Low-level macros need to print a checking whether... message do the actual check cache the result of the check

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

104 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

The (real) congure process

Makele.in congure

src/ Makele.in

cong.h.in

cong.status cong.cache Makele cong.log src/ Makele cong.h

configure -C caches results in cong.cache to speed up recongurations


A. Duret-Lutz Using GNU Autotools May 16, 2010 105 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a Low-Level Macro


Low-level macros need to print a checking whether... message do the actual check cache the result of the check Most of this is achieved via the AC CACHE CHECK macro. AC_DEFUN(MACRO-NAME, [AC_CACHE_CHECK(WHETHER-MESSAGE, CACHE-VARIABLE, CODE-TO-SET-CACHE-VARIABLE) CODE-USING-CACHE-VARIABLE])

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

106 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a Low-Level Macro


Low-level macros need to print a checking whether... message do the actual check cache the result of the check Most of this is achieved via the AC CACHE CHECK macro. AC_DEFUN(MACRO-NAME, [AC_CACHE_CHECK(WHETHER-MESSAGE, CACHE-VARIABLE, CODE-TO-SET-CACHE-VARIABLE) CODE-USING-CACHE-VARIABLE]) The CACHE-VARIABLE should match * cv *.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

106 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a Low-Level Macro


Low-level macros need to print a checking whether... message do the actual check cache the result of the check Most of this is achieved via the AC CACHE CHECK macro. AC_DEFUN(MACRO-NAME, [AC_CACHE_CHECK(WHETHER-MESSAGE, CACHE-VARIABLE, CODE-TO-SET-CACHE-VARIABLE) CODE-USING-CACHE-VARIABLE]) The CACHE-VARIABLE should match * cv *. CODE-TO-SET-CACHE-VARIABLE should contain the check. It will be skipped when the cache is used.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

106 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Writing a Low-Level Macro


Low-level macros need to print a checking whether... message do the actual check cache the result of the check Most of this is achieved via the AC CACHE CHECK macro. AC_DEFUN(MACRO-NAME, [AC_CACHE_CHECK(WHETHER-MESSAGE, CACHE-VARIABLE, CODE-TO-SET-CACHE-VARIABLE) CODE-USING-CACHE-VARIABLE]) The CACHE-VARIABLE should match * cv *. CODE-TO-SET-CACHE-VARIABLE should contain the check. It will be skipped when the cache is used. CODE-USING-CACHE-VARIABLE is always executed, use AC SUBST and AC DEFINE here.
A. Duret-Lutz Using GNU Autotools May 16, 2010 106 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

A Low-Level Macro: AX FUNC MKDIR ONE ARG


AC_DEFUN([AX_FUNC_MKDIR_ONE_ARG], [AC_CACHE_CHECK([whether mkdir takes one argument], [ax_cv_mkdir_one_arg], [_AX_FUNC_MKDIR_ONE_ARG([ax_cv_mkdir_one_arg=yes], [ax_cv_mkdir_one_arg=no])]) if test x"$ax_cv_mkdir_one_arg" = xyes; then AC_DEFINE([MKDIR_ONE_ARG], 1, [Define if mkdir takes only one argument.]) fi]) # AX_FUNC_MKDIR_ONE_ARG

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

107 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

A Low-Level Macro: AX FUNC MKDIR ONE ARG


AC_DEFUN([AX_FUNC_MKDIR_ONE_ARG], [AC_CACHE_CHECK([whether mkdir takes one argument], [ax_cv_mkdir_one_arg], [_AX_FUNC_MKDIR_ONE_ARG([ax_cv_mkdir_one_arg=yes], [ax_cv_mkdir_one_arg=no])]) if test x"$ax_cv_mkdir_one_arg" = xyes; then AC_DEFINE([MKDIR_ONE_ARG], 1, [Define if mkdir takes only one argument.]) fi]) # AX_FUNC_MKDIR_ONE_ARG AC CACHE CHECK
prints checking whether mkdir... does the check (unless already done) cache the result in ax cv mkdir one arg

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

107 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

A Low-Level Macro: AX FUNC MKDIR ONE ARG


AC_DEFUN([AX_FUNC_MKDIR_ONE_ARG], [AC_CACHE_CHECK([whether mkdir takes one argument], [ax_cv_mkdir_one_arg], [_AX_FUNC_MKDIR_ONE_ARG([ax_cv_mkdir_one_arg=yes], [ax_cv_mkdir_one_arg=no])]) if test x"$ax_cv_mkdir_one_arg" = xyes; then AC_DEFINE([MKDIR_ONE_ARG], 1, [Define if mkdir takes only one argument.]) fi]) # AX_FUNC_MKDIR_ONE_ARG AC CACHE CHECK
prints checking whether mkdir... does the check (unless already done) cache the result in ax cv mkdir one arg

Keep conguration actions outside AC CACHE CHECK: they have to be executed whether the check is run or cached.
A. Duret-Lutz Using GNU Autotools May 16, 2010 107 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Recommendations for Writing Autoconf Macros


Test for features, not for systems.
E.g., check whether mkdir() takes one argument, not whether you are compiling for Win32. Your package will be more likely to adapt to untested systems.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

108 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Recommendations for Writing Autoconf Macros


Test for features, not for systems.
E.g., check whether mkdir() takes one argument, not whether you are compiling for Win32. Your package will be more likely to adapt to untested systems.

Avoid writing tests that are conditional on previous tests.


Have unconditional tests, with conditional actions. E.g., check for mkdir() even if mkdir() exists.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

108 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Recommendations for Writing Autoconf Macros


Test for features, not for systems.
E.g., check whether mkdir() takes one argument, not whether you are compiling for Win32. Your package will be more likely to adapt to untested systems.

Avoid writing tests that are conditional on previous tests.


Have unconditional tests, with conditional actions. E.g., check for mkdir() even if mkdir() exists.

Do not reinvent the wheel.


Autoconf comes with a lot of well-tested macros. Use them.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

108 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Recommendations for Writing Autoconf Macros


Test for features, not for systems.
E.g., check whether mkdir() takes one argument, not whether you are compiling for Win32. Your package will be more likely to adapt to untested systems.

Avoid writing tests that are conditional on previous tests.


Have unconditional tests, with conditional actions. E.g., check for mkdir() even if mkdir() exists.

Do not reinvent the wheel.


Autoconf comes with a lot of well-tested macros. Use them.

Remember to [quote]. Read the Portable Shell section of the Autoconf manual, before writing shell code.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

108 / 162

Writing and Managing Custom Macros

Writing Autoconf Macros

Recommendations for Writing Autoconf Macros


Test for features, not for systems.
E.g., check whether mkdir() takes one argument, not whether you are compiling for Win32. Your package will be more likely to adapt to untested systems.

Avoid writing tests that are conditional on previous tests.


Have unconditional tests, with conditional actions. E.g., check for mkdir() even if mkdir() exists.

Do not reinvent the wheel.


Autoconf comes with a lot of well-tested macros. Use them.

Remember to [quote]. Read the Portable Shell section of the Autoconf manual, before writing shell code. Test your macros on dierent systems.
Check test results in cong.log . Get accounts on foreign systems (Google for free shell account).
A. Duret-Lutz Using GNU Autotools May 16, 2010 108 / 162

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

Managing Custom Macros with aclocal


10

Writing and Managing Custom Macros Writing Autoconf Macros Managing Custom Macros with aclocal Libtool Gettext Introducing Gettext Internationalizing a Package, Start to Finish Localizing a Package Nested Packages The End

11 12

13 14

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

109 / 162

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

aclocal.m4 and Third-Party Macros


autoconf knows only the macros it provides. (m4 *, AS *, AH *, AC *, AT *). autoconf knows nothing about macro supplied by third-party tools (e.g., Automakes AM * macros).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

110 / 162

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

aclocal.m4 and Third-Party Macros


autoconf knows only the macros it provides. (m4 *, AS *, AH *, AC *, AT *). autoconf knows nothing about macro supplied by third-party tools (e.g., Automakes AM * macros). autoconf reads aclocal.m4 in addition to congure.ac. aclocal.m4 should dene the extra macros required by congure.ac.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

110 / 162

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

aclocal.m4 and Third-Party Macros


autoconf knows only the macros it provides. (m4 *, AS *, AH *, AC *, AT *). autoconf knows nothing about macro supplied by third-party tools (e.g., Automakes AM * macros). autoconf reads aclocal.m4 in addition to congure.ac. aclocal.m4 should dene the extra macros required by congure.ac. aclocal automates the construction of aclocal.m4 from various sources.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

110 / 162

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

Behind autoreconf
congure.ac aclocal.m4 Makele.am src/ Makele.am

aclocal automake autoheader autoconf

congure
A. Duret-Lutz

cong.h.in

Makele.in

src/ Makele.in
May 16, 2010 111 / 162

Using GNU Autotools

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

aclocal.m4 and Third-Party Macros


autoconf knows only the macros it provides. (m4 *, AS *, AH *, AC *, AT *). autoconf knows nothing about macro supplied by third-party tools (e.g., Automakes AM * macros). autoconf reads aclocal.m4 in addition to congure.ac. aclocal.m4 should dene the extra macros required by congure.ac. aclocal automates the construction of aclocal.m4 from various sources. aclocal searches macros in directories specied with -I options a system-wide directory (usually /usr/ share/ aclocal/ ) where third-party packages may install their macros Automakes own private macro directory
A. Duret-Lutz Using GNU Autotools May 16, 2010 112 / 162

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

Managing Custom Macros in Your Package


Create a m4/ subdirectory. Put your macros there. E.g., dene AX FUNC MKDIR and AX FUNC MKDIR ONE ARG in m4/ mkdir.m4 . (The extension must be *.m4 )

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

113 / 162

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

Managing Custom Macros in Your Package


Create a m4/ subdirectory. Put your macros there. E.g., dene AX FUNC MKDIR and AX FUNC MKDIR ONE ARG in m4/ mkdir.m4 . (The extension must be *.m4 ) Add ACLOCAL AMFLAGS = -I m4 to the top-level Makele.am. Add AC CONFIG MACRO DIR([m4]) to congure.ac. The ACLOCAL AMFLAGS are used by autoreconf and by the Makele rebuild rule when they need to run aclocal.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

113 / 162

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

Managing Custom Macros in Your Package


Create a m4/ subdirectory. Put your macros there. E.g., dene AX FUNC MKDIR and AX FUNC MKDIR ONE ARG in m4/ mkdir.m4 . (The extension must be *.m4 ) Add ACLOCAL AMFLAGS = -I m4 to the top-level Makele.am. Add AC CONFIG MACRO DIR([m4]) to congure.ac. Use your macros in congure.ac. The ACLOCAL AMFLAGS are used by autoreconf and by the Makele rebuild rule when they need to run aclocal. Local macros that are used are automatically distributed. (Those that are not used are simply ignored.)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

113 / 162

Writing and Managing Custom Macros

Managing Custom Macros with aclocal

Managing Custom Macros in Your Package


Create a m4/ subdirectory. Put your macros there. E.g., dene AX FUNC MKDIR and AX FUNC MKDIR ONE ARG in m4/ mkdir.m4 . (The extension must be *.m4 ) Add ACLOCAL AMFLAGS = -I m4 to the top-level Makele.am. Add AC CONFIG MACRO DIR([m4]) to congure.ac. Use your macros in congure.ac. The ACLOCAL AMFLAGS are used by autoreconf and by the Makele rebuild rule when they need to run aclocal. Local macros that are used are automatically distributed. (Those that are not used are simply ignored.) You need such a setup to use Gettext, and Libtool.
A. Duret-Lutz Using GNU Autotools May 16, 2010 113 / 162

Libtool

Libtool
10

Writing and Managing Custom Macros Writing Autoconf Macros Managing Custom Macros with aclocal Libtool Gettext Introducing Gettext Internationalizing a Package, Start to Finish Localizing a Package Nested Packages The End

11 12

13 14

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

114 / 162

Libtool

Shared Libraries: A Portability Hell


Almost each system has its own format of shared library
libhello.so libhello.dll libhello.sl libhello.dylib ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

115 / 162

Libtool

Shared Libraries: A Portability Hell


Almost each system has its own format of shared library
libhello.so libhello.dll libhello.sl libhello.dylib ...

Building will require dierent ags


-fPIC, -shared -KPIC, -G -bM:SRE ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

115 / 162

Libtool

Shared Libraries: A Portability Hell


Almost each system has its own format of shared library
libhello.so libhello.dll libhello.sl libhello.dylib ...

Building will require dierent ags


-fPIC, -shared -KPIC, -G -bM:SRE ...

Linking against the library may also require specic ags.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

115 / 162

Libtool

Shared Libraries: A Portability Hell


Almost each system has its own format of shared library
libhello.so libhello.dll libhello.sl libhello.dylib ...

Building will require dierent ags


-fPIC, -shared -KPIC, -G -bM:SRE ...

Linking against the library may also require specic ags. There is no way for a developer to keep track of all these details.
Quiz: match each of the above example with its OS.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

115 / 162

Libtool

Shared Libraries: A Portability Hell


Almost each system has its own format of shared library
libhello.so libhello.dll libhello.sl libhello.dylib ...

Building will require dierent ags


-fPIC, -shared -KPIC, -G -bM:SRE ...

Linking against the library may also require specic ags. There is no way for a developer to keep track of all these details.
Quiz: match each of the above example with its OS.

Not all systems support shared libraries.


A. Duret-Lutz Using GNU Autotools May 16, 2010 115 / 162

Libtool

Shared Libraries: Libtools Solution

A new library format that abstracts all the others


libhello.la (libtool archive)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

116 / 162

Libtool

Shared Libraries: Libtools Solution

A new library format that abstracts all the others


libhello.la (libtool archive)

A wrapper script for the compiler and linker


translates operations involving libhello.la into the correct operation for the current system using the real library

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

116 / 162

Libtool

Shared Libraries: Libtools Solution

A new library format that abstracts all the others


libhello.la (libtool archive)

A wrapper script for the compiler and linker


translates operations involving libhello.la into the correct operation for the current system using the real library

In a Makele.am, you simply create and link against *.la les. These operations are translated appropriately.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

116 / 162

Libtool

Setting Up Libtool: Roadmap


Libtool will require some local Autoconf macros for all the checks it has to perform. Use an m4/ subdirectory as explained earlier.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

117 / 162

Libtool

Setting Up Libtool: Roadmap


Libtool will require some local Autoconf macros for all the checks it has to perform. Use an m4/ subdirectory as explained earlier. Call LT INIT in congure.ac.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

117 / 162

Libtool

Setting Up Libtool: Roadmap


Libtool will require some local Autoconf macros for all the checks it has to perform. Use an m4/ subdirectory as explained earlier. Call LT INIT in congure.ac. Use LTLIBRARIES to declare libtool archives in Makele.am

Makele.am
lib_LTLIBRARIES = libfoo.la libfoo_la_SOURCES = foo.c foo.h etc.c

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

117 / 162

Libtool

Setting Up Libtool: Roadmap


Libtool will require some local Autoconf macros for all the checks it has to perform. Use an m4/ subdirectory as explained earlier. Call LT INIT in congure.ac. Use LTLIBRARIES to declare libtool archives in Makele.am Use LDADD to link against local libtool archives.

Makele.am
lib_LTLIBRARIES = libfoo.la libfoo_la_SOURCES = foo.c foo.h etc.c bin_PROGRAMS = runme runme_SOURCES = main.c runme_LDADD = libfoo.la
A. Duret-Lutz Using GNU Autotools May 16, 2010 117 / 162

Libtool

Hello World Using Libtool: C Files


lib/ say.c
#include <config.h> #include <stdio.h> void say_hello (void) { puts ("Hello World!"); puts ("This is " PACKAGE_STRING "."); }

src/ main.c
#include "say.h" int main (void) { say_hello (); return 0; }

lib/ say.h
void say_hello (void);

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

118 / 162

Libtool

Hello World Using Libtool: Makele.ams


lib/ Makele.am
lib_LTLIBRARIES = libhello.la libhello_la_SOURCES = say.c say.h

src/ Makele.am
AM_CPPFLAGS = -I$(srcdir)/../lib bin_PROGRAMS = hello hello_SOURCES = main.c hello_LDADD = ../lib/libhello.la

Makele.am
SUBDIRS = lib src ACLOCAL_AMFLAGS = -I m4
A. Duret-Lutz Using GNU Autotools May 16, 2010 119 / 162

Libtool

Hello World Using Libtool: congure.ac

congure.ac
AC_INIT([amhello], [2.0], [bug-report@address]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) LT_INIT AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile lib/Makefile src/Makefile]) AC_OUTPUT

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

120 / 162

Libtool

Hello World Using Libtool: autoreconf

~/amhello % ls -R

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

121 / 162

Libtool

Hello World Using Libtool: autoreconf

~/amhello % ls -R .: Makefile.am configure.ac ./lib: Makefile.am ./src: Makefile.am

lib/

src/

say.c

say.h

main.c

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

121 / 162

Libtool

Hello World Using Libtool: autoreconf

~/amhello % mkdir m4 ~/amhello % autoreconf --install

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

121 / 162

Libtool

Hello World Using Libtool: autoreconf

~/amhello % mkdir m4 ~/amhello % autoreconf --install libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, bui libtoolize: copying file build-aux/ltmain.sh libtoolize: putting macros in AC_CONFIG_MACRO_DIR, m4. libtoolize: copying file m4/libtool.m4 libtoolize: copying file m4/ltoptions.m4 libtoolize: copying file m4/ltsugar.m4 libtoolize: copying file m4/ltversion.m4 libtoolize: copying file m4/lt~obsolete.m4 configure.ac:5: installing build-aux/config.guess configure.ac:5: installing build-aux/config.sub configure.ac:4: installing build-aux/install-sh configure.ac:4: installing build-aux/missing lib/Makefile.am: installing build-aux/depcomp ~/amhello %
A. Duret-Lutz Using GNU Autotools May 16, 2010 121 / 162

Libtool

Hello World Using Libtool: autoreconf

~/amhello ~/amhello ... ~/amhello ... ~/amhello

% mkdir m4 % autoreconf --install % ./configure --prefix ~/test %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

121 / 162

Libtool

Hello World Using Libtool: autoreconf

~/amhello ~/amhello ... ~/amhello ... ~/amhello ... ~/amhello

% mkdir m4 % autoreconf --install % ./configure --prefix ~/test % make && make install %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

121 / 162

Libtool

Hello World Using Libtool: autoreconf

~/amhello % mkdir m4 ~/amhello % autoreconf --install ... ~/amhello % ./configure --prefix ~/test ... ~/amhello % make && make install ... ~/amhello % ~/test/bin/hello Hello World! This is amhello 2.0. ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

121 / 162

Libtool

What Was Built and Installed


~/amhello % ls -R ~/test /home/adl/test: bin/ lib/ /home/adl/test/bin: hello* /home/adl/test/lib: libhello.a libhello.so@ libhello.la* libhello.so.0@ ~/amhello %

libhello.so.0.0.0*

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

122 / 162

Libtool

What Was Built and Installed

~/amhello % ls -R ~/test /home/adl/test: bin/ lib/ /home/adl/test/bin: hello* /home/adl/test/lib: libhello.a libhello.so@ libhello.so.0.0.0* libhello.la* libhello.so.0@ ~/amhello % ldd ~/test/bin/hello libhello.so.0 => /home/adl/test/lib/libhello.so.0 (0xb7fe7000) libc.so.6 => /lib/tls/libc.so.6 (0xb7e9c000) lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7fea000) ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

122 / 162

Libtool

What Was Built and Installed

~/amhello % ls -R ~/test /home/adl/test: bin/ lib/ /home/adl/test/bin: hello* /home/adl/test/lib: libhello.a libhello.so@ libhello.so.0.0.0* libhello.la* libhello.so.0@ ~/amhello % ldd ~/test/bin/hello libhello.so.0 => /home/adl/test/lib/libhello.so.0 (0xb7fe7000) libc.so.6 => /lib/tls/libc.so.6 (0xb7e9c000) lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7fea000) ~/amhello % ldd src/hello not a dynamic executable ~/amhello %
A. Duret-Lutz Using GNU Autotools May 16, 2010 122 / 162

Libtool

What Was Built and Installed

~/amhello % ls -R ~/test /home/adl/test: bin/ lib/ /home/adl/test/bin: hello* /home/adl/test/lib: libhello.a libhello.so@ libhello.so.0.0.0* libhello.la* libhello.so.0@ ~/amhello % ldd ~/test/bin/hello libhello.so.0 => /home/adl/test/lib/libhello.so.0 (0xb7fe7000) libc.so.6 => /lib/tls/libc.so.6 (0xb7e9c000) lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7fea000) ~/amhello % ldd src/hello not a dynamic executable ~/amhello % file src/hello src/hello: Bourne shell script text executable
A. Duret-Lutz Using GNU Autotools May 16, 2010 122 / 162

Libtool

Building Shared or Static Libraries


By default, both static and shared libraries are built. This default can be changed in a package using options passed to LT INIT(options...): disable-shared do not build shared libraries by default disable-static do not build static libraries by default

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

123 / 162

Libtool

Building Shared or Static Libraries


By default, both static and shared libraries are built. This default can be changed in a package using options passed to LT INIT(options...): disable-shared do not build shared libraries by default disable-static do not build static libraries by default The installer can override these settings using congure options. --enable-shared build shared libraries --disable-shared dont --enable-static build static libraries --disable-static dont

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

123 / 162

Libtool

Building Shared or Static Libraries


By default, both static and shared libraries are built. This default can be changed in a package using options passed to LT INIT(options...): disable-shared do not build shared libraries by default disable-static do not build static libraries by default The installer can override these settings using congure options. --enable-shared build shared libraries --disable-shared dont --enable-static build static libraries --disable-static dont At least one avor is built, always. Some systems dont leave any choice.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

123 / 162

Libtool

The src/ hello Wrapper Script


src/ hello can be a wrapper script
Depending on Libtools conguration.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

124 / 162

Libtool

The src/ hello Wrapper Script


src/ hello can be a wrapper script
Depending on Libtools conguration.

The real binary has been built elsewhere


Libtool hides it in the build tree (dont bother about it)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

124 / 162

Libtool

The src/ hello Wrapper Script


src/ hello can be a wrapper script
Depending on Libtools conguration.

The real binary has been built elsewhere


Libtool hides it in the build tree (dont bother about it)

This wrapper script runs the real binary, and arranges so it nds the not-yet-installed libraries
This way src/ hello can be run, for instance in a test suite

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

124 / 162

Libtool

The src/ hello Wrapper Script


src/ hello can be a wrapper script
Depending on Libtools conguration.

The real binary has been built elsewhere


Libtool hides it in the build tree (dont bother about it)

This wrapper script runs the real binary, and arranges so it nds the not-yet-installed libraries
This way src/ hello can be run, for instance in a test suite

Do not debug the shell script!


~/amhello % gdb -q src/hello
"src/hello": not in executable format: File format not recognized

(gdb)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

124 / 162

Libtool

The src/ hello Wrapper Script


src/ hello can be a wrapper script
Depending on Libtools conguration.

The real binary has been built elsewhere


Libtool hides it in the build tree (dont bother about it)

This wrapper script runs the real binary, and arranges so it nds the not-yet-installed libraries
This way src/ hello can be run, for instance in a test suite

Do not debug the shell script!


~/amhello % gdb -q src/hello
"src/hello": not in executable format: File format not recognized

(gdb)

Prex such commands with libtool --mode=execute


~/amhello % libtool --mode=execute gdb -q src/hello
A. Duret-Lutz Using GNU Autotools May 16, 2010 124 / 162

Libtool

Versioning Libtool Libraries: Interfaces


Versioning libraries allow several versions to coexist. It ensures programs use the library that implements the interface they require. Interface = public variables and functions, I/O, formats, protocols, ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

125 / 162

Libtool

Versioning Libtool Libraries: Interfaces


Versioning libraries allow several versions to coexist. It ensures programs use the library that implements the interface they require. Interface = public variables and functions, I/O, formats, protocols, ... Interfaces are identied using integers. A program remembers the interface numbers of the libraries it was linked against.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

125 / 162

Libtool

Versioning Libtool Libraries: Interfaces


Versioning libraries allow several versions to coexist. It ensures programs use the library that implements the interface they require. Interface = public variables and functions, I/O, formats, protocols, ... Interfaces are identied using integers. A program remembers the interface numbers of the libraries it was linked against. A library can implement several interfaces.
E.g., adding new functions changes the interface, but does not break old interfaces.

Hence libtools versioning format encodes a range of supported interfaces.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

125 / 162

Libtool

Versioning Libtool Libraries: Interfaces


Versioning libraries allow several versions to coexist. It ensures programs use the library that implements the interface they require. Interface = public variables and functions, I/O, formats, protocols, ... Interfaces are identied using integers. A program remembers the interface numbers of the libraries it was linked against. A library can implement several interfaces.
E.g., adding new functions changes the interface, but does not break old interfaces.

Hence libtools versioning format encodes a range of supported interfaces. Interface numbers are not release numbers.
A. Duret-Lutz Using GNU Autotools May 16, 2010 125 / 162

Libtool

Versioning Libtool Libraries: Version Triplets


CURRENT The latest interface implemented. REVISION The implementation number of CURRENT (read: number of bugs xed...) AGE The number of interfaces implemented, minus one. The library supports all interfaces between CURRENT AGE and CURRENT.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

126 / 162

Libtool

Versioning Libtool Libraries: Version Triplets


CURRENT The latest interface implemented. REVISION The implementation number of CURRENT (read: number of bugs xed...) AGE The number of interfaces implemented, minus one. The library supports all interfaces between CURRENT AGE and CURRENT. These numbers should be specied using -version-info.

lib/Makele.am
lib_LTLIBRARIES = libhello.la libhello_la_SOURCES = say.c say.h libhello_la_LDFLAGS = -version-info CURRENT:REVISION:AGE

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

126 / 162

Libtool

Versioning Libtool Libraries: Version Triplets


CURRENT The latest interface implemented. REVISION The implementation number of CURRENT (read: number of bugs xed...) AGE The number of interfaces implemented, minus one. The library supports all interfaces between CURRENT AGE and CURRENT. These numbers should be specied using -version-info.

lib/Makele.am
lib_LTLIBRARIES = libhello.la libhello_la_SOURCES = say.c say.h libhello_la_LDFLAGS = -version-info 0:0:0 The default version is 0:0:0. Its also a good initial version.
A. Duret-Lutz Using GNU Autotools May 16, 2010 126 / 162

Libtool

Versioning Libtool Libraries: Bumping Versions

Remember to bump library versions before a release. Suppose the old version was CURRENT:REVISION:AGE. If you have not changed the interface (bug xes) augmented the interface (new functions) broken old interface (e.g. removed functions) bump the version to CURRENT : REVISION+1 : AGE CURRENT+1 : 0 : AGE+1 CURRENT+1 : 0 : 0

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

127 / 162

Gettext

Introducing Gettext

Introducing Gettext
10

Writing and Managing Custom Macros Writing Autoconf Macros Managing Custom Macros with aclocal Libtool Gettext Introducing Gettext Internationalizing a Package, Start to Finish Localizing a Package Nested Packages The End

11 12

13 14

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

128 / 162

Gettext

Introducing Gettext

Introducing Gettext
Internationalization

Localization

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

129 / 162

Gettext

Introducing Gettext

Introducing Gettext
Internationalization Changing a program to support for multiple languages and cultural habits.

Localization

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

129 / 162

Gettext

Introducing Gettext

Introducing Gettext
Internationalization Changing a program to support for multiple languages and cultural habits.

Localization Providing an internationalized package the necessary bits to support ones native language and cultural habits.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

129 / 162

Gettext

Introducing Gettext

Introducing Gettext
Internationalization = I18n Changing a program to support for multiple languages and cultural habits.

Localization = L10n Providing an internationalized package the necessary bits to support ones native language and cultural habits.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

129 / 162

Gettext

Introducing Gettext

Introducing Gettext
Internationalization = I18n Changing a program to support for multiple languages and cultural habits.
Character handling (unicode...) Locale awareness (date formats, currencies, numbers, time zones, etc.) Localizability
Isolate localizable items (messages, pictures, etc.) Implement infrastructure necessary for localizing above items.

Localization = L10n Providing an internationalized package the necessary bits to support ones native language and cultural habits.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

129 / 162

Gettext

Introducing Gettext

Introducing Gettext
Internationalization = I18n Changing a program to support for multiple languages and cultural habits.
Character handling (unicode...) Locale awareness (date formats, currencies, numbers, time zones, etc.) Localizability
Isolate localizable items (messages, pictures, etc.) Implement infrastructure necessary for localizing above items.

Localization = L10n Providing an internationalized package the necessary bits to support ones native language and cultural habits.
Translate localizable items (messages, pictures, etc.) for one language.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

129 / 162

Gettext

Introducing Gettext

Introducing Gettext
Internationalization = I18n Changing a program to support for multiple languages and cultural habits.
Character handling (unicode...) Locale awareness (date formats, currencies, numbers, time zones, etc.) Localizability
Isolate localizable items (messages, pictures, etc.) Implement infrastructure necessary for localizing above items.

The programmers work. Localization = L10n Providing an internationalized package the necessary bits to support ones native language and cultural habits.
Translate localizable items (messages, pictures, etc.) for one language.

The translators work.


A. Duret-Lutz Using GNU Autotools May 16, 2010 129 / 162

Gettext

Introducing Gettext

Introducing Gettext
Internationalization = I18n Changing a program to support for multiple languages and cultural habits.
Character handling (unicode...) Locale awareness (date formats, currencies, numbers, time zones, etc.) Localizability
Isolate localizable items (messages, pictures, etc.) Implement infrastructure necessary for localizing above items.

The programmers work. Localization = L10n Providing an internationalized package the necessary bits to support ones native language and cultural habits.
Translate localizable items (messages, pictures, etc.) for one language.

The translators work. Gettext = complete toolset for translating messages output by programs.
A. Duret-Lutz Using GNU Autotools May 16, 2010 129 / 162

Gettext

Introducing Gettext

Translating Messages Made Easy


#include <config.h> #include <stdio.h>

void say_hello (void) { puts ("Hello World!"); puts ("This is " PACKAGE_STRING "."); } The program is written in English.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

130 / 162

Gettext

Introducing Gettext

Translating Messages Made Easy


#include <config.h> #include <stdio.h> #include "gettext.h" #define _(string) gettext (string) void say_hello (void) { puts (_("Hello World!")); printf (_("This is %s.\n"), PACKAGE_STRING); } The program is written in English. Messages that must be translated are marked with (...).
xgettext builds catalogs of translatable messages from such strings. Translators will provide translated catalogs for their locale.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

130 / 162

Gettext

Introducing Gettext

Translating Messages Made Easy


#include <config.h> #include <stdio.h> #include "gettext.h" #define _(string) gettext (string) void say_hello (void) { puts (_("Hello World!")); printf (_("This is %s.\n"), PACKAGE_STRING); } The program is written in English. Messages that must be translated are marked with (...).
xgettext builds catalogs of translatable messages from such strings. Translators will provide translated catalogs for their locale.

gettext looks up the translation of the English message in the current locales catalog.
A. Duret-Lutz Using GNU Autotools May 16, 2010 130 / 162

Gettext

Internationalizing a Package, Start to Finish

Internationalizing a Package, Start to Finish


10

Writing and Managing Custom Macros Writing Autoconf Macros Managing Custom Macros with aclocal Libtool Gettext Introducing Gettext Internationalizing a Package, Start to Finish Localizing a Package Nested Packages The End

11 12

13 14

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

131 / 162

Gettext

Internationalizing a Package, Start to Finish

Internationalizing a Package, Start to Finish


Roadmap:
1 2 3 4 5 6

Start with a non-internationalized Hello World. Invoke AM GNU GETTEXT from congure.ac Run gettextize to provide the basic infrastructure. Fill in the conguration les left by gettextize. Update src/ Makele.am to link hello with the necessary library. Update the code:
Initialize Gettext in main() Mark translatable strings.

Generate messages catalogs automatically.

Well talk about localization once this is done.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

132 / 162

Gettext

Internationalizing a Package, Start to Finish

Non Internationalized Hello World (1/2)


src/ say.h
#ifndef AMHELLO_SAY_H # define AMHELLO_SAY_H void say_hello (void); #endif

src/ main.c
#include "say.h" int main (void) { say_hello (); return 0; }

src/ say.c
#include <config.h> #include <stdio.h> void say_hello (void) { puts ("Hello World!"); puts ("This is " PACKAGE_STRING "."); }
Using GNU Autotools May 16, 2010 133 / 162

A. Duret-Lutz

Gettext

Internationalizing a Package, Start to Finish

Non Internationalized Hello World (2/2)


congure.ac
AC_INIT([amhello], [3.0], [bug-report@address]) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT

Makele.am
SUBDIRS = src

src/ Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c say.c say.h

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

134 / 162

Gettext

Internationalizing a Package, Start to Finish

Update congure.ac for Gettext


congure.ac
AC_INIT([amhello], [3.0], [bug-report@address]) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AM_GNU_GETTEXT_VERSION([0.17]) AM_GNU_GETTEXT([external]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

135 / 162

Gettext

Internationalizing a Package, Start to Finish

Update congure.ac for Gettext


congure.ac
AC_INIT([amhello], [3.0], [bug-report@address]) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AM_GNU_GETTEXT_VERSION([0.17]) AM_GNU_GETTEXT([external]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT AM GNU GETTEXT VERSION = exactly which Gettext version to use.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

135 / 162

Gettext

Internationalizing a Package, Start to Finish

Update congure.ac for Gettext


congure.ac
AC_INIT([amhello], [3.0], [bug-report@address]) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AM_GNU_GETTEXT_VERSION([0.17]) AM_GNU_GETTEXT([external]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT AM GNU GETTEXT VERSION = exactly which Gettext version to use. AM GNU GETTEXT([external])
the GNU libc or an external (= not distributed) Gettext library will be used if found NLS (Native Language System) will be disabled otherwise
A. Duret-Lutz Using GNU Autotools May 16, 2010 135 / 162

Gettext

Internationalizing a Package, Start to Finish

Running gettextize

You should run gettextize: A rst time, to install the Gettext infrastructure in your package. Each time you upgrade Gettext to a new version. ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

136 / 162

Gettext

Internationalizing a Package, Start to Finish

Running gettextize

You should run gettextize: A rst time, to install the Gettext infrastructure in your package. Each time you upgrade Gettext to a new version. ~/amhello % gettextize --copy --no-changelog [...] ~/amhello % Install most of the Gettext infrastructure.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

136 / 162

Gettext

Internationalizing a Package, Start to Finish

Running gettextize

You should run gettextize: A rst time, to install the Gettext infrastructure in your package. Each time you upgrade Gettext to a new version. ~/amhello % gettextize --copy --no-changelog [...] ~/amhello % cp /usr/share/gettext/gettext.h src Install most of the Gettext infrastructure. Copy gettext.h in the source tree, it will be distributed.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

136 / 162

Gettext

Internationalizing a Package, Start to Finish

Gettextize Updated Some Files


congure.ac
AC_INIT([amhello], [3.0], [bug-report@address]) AC_CONFIG_AUX_DIR([build-aux]) AM_GNU_GETTEXT_VERSION([0.17]) AM_GNU_GETTEXT([external]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([Makefile src/Makefile po/Makefile.in]) AC_OUTPUT

Makele.am

SUBDIRS = po src bin_PROGRAMS = hello ACLOCAL_AMFLAGS = -I m4 hello_SOURCES = main.c say.c say.h EXTRA_DIST = ...
A. Duret-Lutz Using GNU Autotools May 16, 2010 137 / 162

src/ Makele.am

Gettext

Internationalizing a Package, Start to Finish

po/ Makevars and po/ POTFILES.in


Fill po/ Makevars.template and rename it as po/ Makevars:

po/ Makevars
DOMAIN = $(PACKAGE) subdir = po top_builddir = .. XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ COPYRIGHT_HOLDER = Your Name or Your Employer MSGID_BUGS_ADDRESS = $(PACKAGE BUGREPORT) EXTRA_LOCALE_CATEGORIES =

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

138 / 162

Gettext

Internationalizing a Package, Start to Finish

po/ Makevars and po/ POTFILES.in


Fill po/ Makevars.template and rename it as po/ Makevars: $(PACKAGE BUGREPORT) is the po/ Makevars third argument of AC INIT. Some DOMAIN = $(PACKAGE) packages use a mailing list subdir = po dedicated to translation issues top_builddir = .. instead. XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ COPYRIGHT_HOLDER = Your Name or Your Employer MSGID_BUGS_ADDRESS = $(PACKAGE BUGREPORT) EXTRA_LOCALE_CATEGORIES =

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

138 / 162

Gettext

Internationalizing a Package, Start to Finish

po/ Makevars and po/ POTFILES.in


Fill po/ Makevars.template and rename it as po/ Makevars:

po/ Makevars
DOMAIN = $(PACKAGE) subdir = po top_builddir = .. XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ COPYRIGHT_HOLDER = Your Name or Your Employer MSGID_BUGS_ADDRESS = $(PACKAGE BUGREPORT) EXTRA_LOCALE_CATEGORIES = List sources les that (may) contain translatable strings in POTFILES.in.

po/ POTFILES.in
src/main.c src/say.c
A. Duret-Lutz Using GNU Autotools May 16, 2010 138 / 162

Gettext

Internationalizing a Package, Start to Finish

Whats Next?
Done:
1 2 3 4

Start with a non-internationalized Hello World. Invoke AM GNU GETTEXT from congure.ac Run gettextize to provide the basic infrastructure. Fill in the conguration les left by gettextize.

Now, autoreconf --install; ./configure; make should work.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

139 / 162

Gettext

Internationalizing a Package, Start to Finish

Whats Next?
Done:
1 2 3 4

Start with a non-internationalized Hello World. Invoke AM GNU GETTEXT from congure.ac Run gettextize to provide the basic infrastructure. Fill in the conguration les left by gettextize.

Now, autoreconf --install; ./configure; make should work. To do:


5 6

Update src/ Makele.am to link hello with the necessary library. Update the code:
Initialize Gettext in main() Mark translatable strings.

Generate messages catalogs automatically.


A. Duret-Lutz Using GNU Autotools May 16, 2010 139 / 162

Gettext

Internationalizing a Package, Start to Finish

Updating src/ Makele.am


src/Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c say.c say.h

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

140 / 162

Gettext

Internationalizing a Package, Start to Finish

Updating src/ Makele.am


src/Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c say.c say.h hello_LDADD = $(LIBINTL) $(LIBINTL) lists the libraries any internationalized program should be linked against.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

140 / 162

Gettext

Internationalizing a Package, Start to Finish

Updating src/ Makele.am


src/Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c say.c say.h LDADD = $(LIBINTL) $(LIBINTL) lists the libraries any internationalized program should be linked against. We can strip the leading hello and use the global LDADD instead.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

140 / 162

Gettext

Internationalizing a Package, Start to Finish

Updating src/ Makele.am


src/Makele.am
bin_PROGRAMS = hello hello_SOURCES = main.c say.c say.h gettext.h LDADD = $(LIBINTL) $(LIBINTL) lists the libraries any internationalized program should be linked against. We can strip the leading hello and use the global LDADD instead. Mention gettext.h (we will use it shortly) so it is distributed.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

140 / 162

Gettext

Internationalizing a Package, Start to Finish

Updating src/ Makele.am


src/Makele.am
AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" bin_PROGRAMS = hello hello_SOURCES = main.c say.c say.h gettext.h LDADD = $(LIBINTL) $(LIBINTL) lists the libraries any internationalized program should be linked against. We can strip the leading hello and use the global LDADD instead. Mention gettext.h (we will use it shortly) so it is distributed. $(LOCALEDIR) is the place where message catalogs are installed. This is needed during initialization.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

140 / 162

Gettext

Internationalizing a Package, Start to Finish

Initializing Gettext
src/ main.c

#include "say.h" int main (void) {

say_hello(); return 0; }
A. Duret-Lutz Using GNU Autotools May 16, 2010 141 / 162

Gettext

Internationalizing a Package, Start to Finish

Initializing Gettext
src/ main.c
#include <locale.h> #include "say.h" int main (void) { setlocale (LC_ALL, ""); Initialize the locale as specied in the environment. (E.g., the user sets LANG=fr FR in the environment to get French messages.)

say_hello(); return 0; }
A. Duret-Lutz Using GNU Autotools May 16, 2010 141 / 162

Gettext

Internationalizing a Package, Start to Finish

Initializing Gettext
src/ main.c
#include <config.h> #include <locale.h> #include "gettext.h" #include "say.h" int main (void) { setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); say_hello(); return 0; }
A. Duret-Lutz Using GNU Autotools

Initialize the locale as specied in the environment. (E.g., the user sets LANG=fr FR in the environment to get French messages.) Tell Gettext where to nd message catalogs for this program. (All programs in the same package usually share the same message catalog.)
May 16, 2010 141 / 162

Gettext

Internationalizing a Package, Start to Finish

Marking Strings for Translation


src/ say.c
#include <config.h> #include <stdio.h>

void say_hello (void) { puts ("Hello World!"); puts ("This is " PACKAGE_STRING "."); }

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

142 / 162

Gettext

Internationalizing a Package, Start to Finish

Marking Strings for Translation


src/ say.c
#include <config.h> #include <stdio.h> #include "gettext.h" #define _(string) gettext (string) void say_hello (void) { puts (_("Hello World!")); printf (_("This is %s.\n"), PACKAGE_STRING); } Messages that must be translated are marked with (...).

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

142 / 162

Gettext

Internationalizing a Package, Start to Finish

Marking Strings for Translation


src/ say.c
#include <config.h> #include <stdio.h> #include "gettext.h" #define _(string) gettext (string) void say_hello (void) { puts (_("Hello World!")); printf (_("This is %s.\n"), PACKAGE_STRING); } Messages that must be translated are marked with (...). NLS (Native Language System) can be disabled.
Explicitly with ./configure --disable-nls Implicitly if no gettext implementation is installed.

Then gettext.h denes gettext(), textdomain(), . . . , as no-ops.


A. Duret-Lutz Using GNU Autotools May 16, 2010 142 / 162

Gettext

Internationalizing a Package, Start to Finish

Building the Whole Shebang


Our Hello World is now internationalized. ~/amhello % autoreconf --install ... ~/amhello % ./configure ... ~/amhello % make ...

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

143 / 162

Gettext

Internationalizing a Package, Start to Finish

Building the Whole Shebang


Our Hello World is now internationalized. ~/amhello % autoreconf --install ... ~/amhello % ./configure ... ~/amhello % make ... Making all in po make amhello.pot-update ... The po/ directory contains messages catalogs. po/ amhello.pot is the template message catalog. Updating po/ amhello.pot is costly and occurs only before releases (e.g., during make distcheck) or if the le did not exist (our case above). It can be updated explicitly with cd po; make update-po.
A. Duret-Lutz Using GNU Autotools May 16, 2010 143 / 162

Gettext

Localizing a Package

Localizing a Package
10

Writing and Managing Custom Macros Writing Autoconf Macros Managing Custom Macros with aclocal Libtool Gettext Introducing Gettext Internationalizing a Package, Start to Finish Localizing a Package Nested Packages The End

11 12

13 14

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

144 / 162

Gettext

Localizing a Package

po/ amhello.pot: The PO Template File


# ... COMMENTS ... #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: bug-report@address\n" "POT-Creation-Date: 2005-03-05 00:27+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <[email protected]>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr ""
A. Duret-Lutz Using GNU Autotools May 16, 2010 145 / 162

Gettext

Localizing a Package

po/ amhello.pot: The PO Template File


# ... COMMENTS ... #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: bug-report@address\n" "POT-Creation-Date: 2005-03-05 00:27+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <[email protected]>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr ""
A. Duret-Lutz Using GNU Autotools May 16, 2010 145 / 162

Gettext

Localizing a Package

po/ amhello.pot: List of Messages


#: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr ""

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

146 / 162

Gettext

Localizing a Package

po/ amhello.pot: List of Messages


#: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr "" msgids identify all strings in the package

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

146 / 162

Gettext

Localizing a Package

po/ amhello.pot: List of Messages


#: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr "" msgids identify all strings in the package empty msgstrs are placeholders for translations

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

146 / 162

Gettext

Localizing a Package

po/ amhello.pot: List of Messages


#: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr "" msgids identify all strings in the package empty msgstrs are placeholders for translations the location of each string is shown, so the translator can check the context if needed

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

146 / 162

Gettext

Localizing a Package

po/ amhello.pot: List of Messages


#: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr "" msgids identify all strings in the package empty msgstrs are placeholders for translations the location of each string is shown, so the translator can check the context if needed additional ags can be used
A. Duret-Lutz Using GNU Autotools May 16, 2010 146 / 162

Gettext

Localizing a Package

po/ amhello.pot: The PO Template File


# ... COMMENTS ... #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: bug-report@address\n" "POT-Creation-Date: 2005-03-05 00:27+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <[email protected]>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr ""
A. Duret-Lutz Using GNU Autotools May 16, 2010 147 / 162

Gettext

Localizing a Package

po/ amhello.pot: The PO Template File


# ... COMMENTS ... #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: bug-report@address\n" "POT-Creation-Date: 2005-03-05 00:27+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <[email protected]>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr ""
A. Duret-Lutz Using GNU Autotools May 16, 2010 147 / 162

Gettext

Localizing a Package

po/ amhello.pot: The Header Entry


msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: bug-report@address\n" "POT-Creation-Date: 2005-03-05 00:27+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <[email protected]>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" The translation of the empty string is a special entry that will be lled with administrative information.
A. Duret-Lutz Using GNU Autotools May 16, 2010 148 / 162

Gettext

Localizing a Package

How to Add a New Language?

Initialize po/ LL.po or po/ LL CC.po from po/ amhello.pot, using msginit. LL is your language code, and CC is your country code pt is Portuguese pt BR is Brazilian Portuguese (The annexes of the Gettext manual show lists of LLs and CCs.) Fill in po/ LL.po (or po/ LL CC.po) List the new translation in po/ LINGUAS

2 3

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

149 / 162

Gettext

Localizing a Package

How to Add a New Language?

Initialize po/ LL.po or po/ LL CC.po from po/ amhello.pot, using msginit. LL is your language code, and CC is your country code pt is Portuguese pt BR is Brazilian Portuguese (The annexes of the Gettext manual show lists of LLs and CCs.) Fill in po/ LL.po (or po/ LL CC.po) List the new translation in po/ LINGUAS

2 3

Lets add a French translation for amhello.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

149 / 162

Gettext

Localizing a Package

Preparing po/ fr.po


~/amhello % cd po ~/amhello/po % msginit -l fr ... ~/amhello/po % emacs fr.po &

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

150 / 162

Gettext

Localizing a Package

Preparing po/ fr.po


~/amhello % cd po ~/amhello/po % msginit -l fr ... ~/amhello/po % emacs fr.po & The PO mode of emacs (
M-x

po-mode):

The buer is modied only indirectly.


Enter

on a message will open a buer to edit the translation.

Use C-c C-c after you have completed the translation, to get back to the updated amhello.pot buer. Once all strings are translated, use Use
Tab V

to save and check the le.

to remove fuzzy attributes.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

150 / 162

Gettext

Localizing a Package

po/ fr.po: Message Translations

#: src/say.c:9 msgid "Hello World!" msgstr "" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr ""

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

151 / 162

Gettext

Localizing a Package

po/ fr.po: Message Translations

#: src/say.c:9 msgid "Hello World!" msgstr "Bonjour Monde !" #: src/say.c:10 #, c-format msgid "This is %s.\n" msgstr "Ceci est %s.\n"

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

151 / 162

Gettext

Localizing a Package

po/ fr.po: Header


msgid "" msgstr "" "Project-Id-Version: amhello 3.0\n" "Report-Msgid-Bugs-To: bug-report@address\n" "POT-Creation-Date: 2005-03-05 00:27+0100\n" "PO-Revision-Date: 2005-03-15 20:54+0100\n" "Last-Translator: Alexandre Duret-Lutz <[email protected]>\n" "Language-Team: French\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=ASCII\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" msginit lled these elds.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

152 / 162

Gettext

Localizing a Package

po/ fr.po: Header


msgid "" msgstr "" "Project-Id-Version: amhello 3.0\n" "Report-Msgid-Bugs-To: bug-report@address\n" "POT-Creation-Date: 2005-03-05 00:27+0100\n" "PO-Revision-Date: 2005-03-15 20:54+0100\n" "Last-Translator: Alexandre Duret-Lutz <[email protected]>\n" "Language-Team: French\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=ASCII\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" msginit lled these elds.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

152 / 162

Gettext

Localizing a Package

po/ fr.po: Header


msgid "" msgstr "" "Project-Id-Version: amhello 3.0\n" "Report-Msgid-Bugs-To: bug-report@address\n" "POT-Creation-Date: 2005-03-05 00:27+0100\n" "PO-Revision-Date: 2005-03-15 20:54+0100\n" "Last-Translator: Alexandre Duret-Lutz <[email protected]>\n" "Language-Team: French\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=iso-8859-1\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" msginit lled these elds. You may have to customize it a bit.
A. Duret-Lutz Using GNU Autotools May 16, 2010 152 / 162

Gettext

Localizing a Package

po/ fr.po: Header


msgid "" msgstr "" "Project-Id-Version: amhello 3.0\n" "Report-Msgid-Bugs-To: bug-report@address\n" "POT-Creation-Date: 2005-03-05 00:27+0100\n" "PO-Revision-Date: 2005-03-15 20:54+0100\n" "Last-Translator: Alexandre Duret-Lutz <[email protected]>\n" "Language-Team: French\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=iso-8859-1\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" msginit lled these elds. You may have to customize it a bit. The revision date will also be updated on save.
A. Duret-Lutz Using GNU Autotools May 16, 2010 152 / 162

Gettext

Localizing a Package

po/ fr.po: Validation and Addition

Once po/ fr.po is completed, hit


1 2 3

. This will:

Update the revision date Save the le Run msgfmt --statistics --check on po/ fr.po, to validate it.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

153 / 162

Gettext

Localizing a Package

po/ fr.po: Validation and Addition

Once po/ fr.po is completed, hit


1 2 3

. This will:

Update the revision date Save the le Run msgfmt --statistics --check on po/ fr.po, to validate it.

We can now register the language. ~/amhello/po % echo fr >> LINGUAS

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

153 / 162

Gettext

Localizing a Package

hello now Speaks French!


~/amhello % ./configure --prefix ~/test ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

154 / 162

Gettext

Localizing a Package

hello now Speaks French!


~/amhello % ./configure --prefix ~/test ~/amhello % make ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

154 / 162

Gettext

Localizing a Package

hello now Speaks French!


~/amhello % ./configure --prefix ~/test ~/amhello % make ~/amhello % cd po ~/amhello/po %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

154 / 162

Gettext

Localizing a Package

hello now Speaks French!


~/amhello % ./configure --prefix ~/test ~/amhello % make ~/amhello % cd po update-po ~/amhello/po % make update-po This step is needed because we ~/amhello/po % just created fr.po, and it has to be compiled. This happens automatically during make dist.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

154 / 162

Gettext

Localizing a Package

hello now Speaks French!


~/amhello % ./configure --prefix ~/test ~/amhello % make ~/amhello % cd po ~/amhello/po % make update-po ~/amhello/po % cd .. ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

154 / 162

Gettext

Localizing a Package

hello now Speaks French!


~/amhello % ./configure --prefix ~/test ~/amhello % make ~/amhello % cd po ~/amhello/po % make update-po ~/amhello/po % cd .. ~/amhello % make install ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

154 / 162

Gettext

Localizing a Package

hello now Speaks French!


~/amhello % ./configure --prefix ~/test ~/amhello % make ~/amhello % cd po ~/amhello/po % make update-po ~/amhello/po % cd .. ~/amhello % make install ~/amhello % ~/test/bin/hello Hello World! This is amhello 3.0. ~/amhello %

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

154 / 162

Gettext

Localizing a Package

hello now Speaks French!


~/amhello % ./configure --prefix ~/test ~/amhello % make ~/amhello % cd po ~/amhello/po % make update-po ~/amhello/po % cd .. ~/amhello % make install ~/amhello % ~/test/bin/hello Hello World! This is amhello 3.0. ~/amhello % LANG=fr_FR ~/test/bin/hello Bonjour Monde ! Ceci est amhello 3.0.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

154 / 162

Gettext

Localizing a Package

Updating Message Catalogs


Because maintainers can change the strings marked for translation, the messages catalogs are varying, and are not always up-to-date.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

155 / 162

Gettext

Localizing a Package

Updating Message Catalogs


Because maintainers can change the strings marked for translation, the messages catalogs are varying, and are not always up-to-date. Varying messages. update-po modify *.po le: New messages are added with a blank translation. Obsolete translations, not used anymore, are commented. Messages with tiny changes keep their translation, but are marked fuzzy. Translators remove fuzzy attributes ( Tab ) after verication.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

155 / 162

Gettext

Localizing a Package

Updating Message Catalogs


Because maintainers can change the strings marked for translation, the messages catalogs are varying, and are not always up-to-date. Varying messages. update-po modify *.po le: New messages are added with a blank translation. Obsolete translations, not used anymore, are commented. Messages with tiny changes keep their translation, but are marked fuzzy. Translators remove fuzzy attributes ( Tab ) after verication. Not up-to-date. gettext copes with incomplete translations as follows. Untranslated messages are output untranslated. Fuzzy messages are also output untranslated. (Better output the original sentence, rather than an inappropriate translation.)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

155 / 162

Gettext

Localizing a Package

Updating Message Catalogs


Because maintainers can change the strings marked for translation, the messages catalogs are varying, and are not always up-to-date. Varying messages. update-po modify *.po le: New messages are added with a blank translation. Obsolete translations, not used anymore, are commented. Messages with tiny changes keep their translation, but are marked fuzzy. Translators remove fuzzy attributes ( Tab ) after verication. Not up-to-date. gettext copes with incomplete translations as follows. Untranslated messages are output untranslated. Fuzzy messages are also output untranslated. (Better output the original sentence, rather than an inappropriate translation.) Good practice: the string freeze. Two weeks before a release, run make update-po and send the *.pot le to translators. Dont change or add strings from this point on. Let translators send you updated *.po les.
A. Duret-Lutz Using GNU Autotools May 16, 2010 155 / 162

Gettext

Localizing a Package

Language Teams & The Translation Project

http://www.iro.umontreal.ca/translation/ The Translation Project provides an infrastructure for package maintainers and translators to exchange messages catalogs.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

156 / 162

Gettext

Localizing a Package

Language Teams & The Translation Project

http://www.iro.umontreal.ca/translation/ The Translation Project provides an infrastructure for package maintainers and translators to exchange messages catalogs. Translators gather in Language Teams (consider joining the team of your own language) to discuss issues. Maintainer submit *.pot les and are notied when *.po les are updated. Pages in The Translation Project will show where work is needed (consider adopting an orphan *.po le.)

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

156 / 162

Gettext

Localizing a Package

Language Teams & The Translation Project

http://www.iro.umontreal.ca/translation/ The Translation Project provides an infrastructure for package maintainers and translators to exchange messages catalogs. Translators gather in Language Teams (consider joining the team of your own language) to discuss issues. Maintainer submit *.pot les and are notied when *.po les are updated. Pages in The Translation Project will show where work is needed (consider adopting an orphan *.po le.) This is only one way of getting a project translated. A lot of packages have dedicated translators and deal with them directly.
A. Duret-Lutz Using GNU Autotools May 16, 2010 156 / 162

Nested Packages

Nested Packages
10

Writing and Managing Custom Macros Writing Autoconf Macros Managing Custom Macros with aclocal Libtool Gettext Introducing Gettext Internationalizing a Package, Start to Finish Localizing a Package Nested Packages The End

11 12

13 14

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

157 / 162

Nested Packages

Nested Packages

Autoconscated packages can be nested to arbitrary depth.


A package can distribute a third-party library it uses in a subdirectory. Its possible to gather many packages this way to distribute a set of tools.

For installers:
A single package to congure, build, and install. configure options are passed recursively to sub-packages. configure --help=recursive shows the help of all sub-packages.

For maintainers:
Easier integration. The sub-package is autonomous.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

158 / 162

Nested Packages

Setting Up Nested Packages

A sub-package should appear as an ordinary directory.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

159 / 162

Nested Packages

Setting Up Nested Packages

A sub-package should appear as an ordinary directory. In Makele.am, this directory must appear in SUBDIRS so make recurses into it.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

159 / 162

Nested Packages

Setting Up Nested Packages

A sub-package should appear as an ordinary directory. In Makele.am, this directory must appear in SUBDIRS so make recurses into it. congure.ac should also declare this directory AC_CONFIG_SUBDIRS([subdir]) so configure calls subdir/ congure recursively.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

159 / 162

Nested Packages

Nested Packages Example


The arm program links with an hand library, a nested package in hand/ .

arms congure.ac
AC_INIT([arm], [1.0]) AM_INIT_AUTOMAKE([foreign -Wall -Werror]) arms Makele.am AC_PROG_CC SUBDIRS = hand src AC_CONFIG_FILES([Makefile src/Makefile]) AC_CONFIG_SUBDIRS([hand]) AC_OUTPUT

arms src/ Makele.am


AM_CPPFLAGS = -I$(top_srcdir)/hand bin_PROGRAMS = arm arm_SOURCES = arm.c arm_LDADD = ../hand/libhand.a
A. Duret-Lutz Using GNU Autotools May 16, 2010 160 / 162

The End

The End
10

Writing and Managing Custom Macros Writing Autoconf Macros Managing Custom Macros with aclocal Libtool Gettext Introducing Gettext Internationalizing a Package, Start to Finish Localizing a Package Nested Packages The End

11 12

13 14

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

161 / 162

The End

Where to go Now?

Locate the reference manuals in your preferred format.


Autoconf, Automake, Libtool, and Gettext all install reference manuals in the Info format. (Try info Autoconf, info Automake, etc.) The web pages of these tools also have .html or .pdf versions. These manuals may not be easy introductions to the tools, but they make good and up-to-date references.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

162 / 162

The End

Where to go Now?

Locate the reference manuals in your preferred format.


Autoconf, Automake, Libtool, and Gettext all install reference manuals in the Info format. (Try info Autoconf, info Automake, etc.) The web pages of these tools also have .html or .pdf versions. These manuals may not be easy introductions to the tools, but they make good and up-to-date references.

Subscribe to these tools mailing lists, to see other peoples uses of the tools.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

162 / 162

The End

Where to go Now?

Locate the reference manuals in your preferred format.


Autoconf, Automake, Libtool, and Gettext all install reference manuals in the Info format. (Try info Autoconf, info Automake, etc.) The web pages of these tools also have .html or .pdf versions. These manuals may not be easy introductions to the tools, but they make good and up-to-date references.

Subscribe to these tools mailing lists, to see other peoples uses of the tools. Pick a package that uses these tools and dissect its setup.
Try picking something written by somebody who isnt just another neophyte! I recommend looking at GNU Coreutils.

A. Duret-Lutz

Using GNU Autotools

May 16, 2010

162 / 162

You might also like