Autotools: An Overview

Autotools: An Overview

Danny Robson

2014-09-24

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools Autotools: An Overview automake

pkg-config

Final Words Danny Robson

2014-09-24 Autotools: An Overview About Me

Performance systems programming About Me , C++ GNU autotools Self-taught. Slowly. caveat emptor About Me Ask lots of questions

2014-09-24 Autotools: An Overview

Danny Robson

Overview Performance systems programming Autotools C, C++ autoconf Linux automake GNU pkg-config autotools Final Words Self-taught. Slowly. caveat emptor Ask lots of questions Autotools: An Overview About Me

Performance systems programming About Me C, C++ Linux GNU autotools Self-taught. Slowly. caveat emptor About Me Ask lots of questions

2014-09-24 Autotools: An Overview

Danny Robson

Overview Performance systems programming Autotools C, C++ autoconf Linux automake GNU pkg-config autotools Final Words Self-taught. Slowly. caveat emptor Ask lots of questions Autotools: An Overview About Me

Performance systems programming About Me C, C++ Linux GNU autotools Self-taught. Slowly. caveat emptor About Me Ask lots of questions

2014-09-24 Autotools: An Overview

Danny Robson

Overview Performance systems programming Autotools C, C++ autoconf Linux automake GNU pkg-config autotools Final Words Self-taught. Slowly. caveat emptor Ask lots of questions Autotools: An Overview What You’re In For 1 Overview What You’re In For 2 Autotools

3 autoconf What You’re In For 4 automake 5 pkg-config

2014-09-24 6 Final Words Autotools: An Overview

Danny Robson 1 Overview Overview Autotools 2 Autotools autoconf

automake 3 pkg-config autoconf

Final Words 4 automake

5 pkg-config

6 Final Words Autotools: An Overview Overview Section 1

Overview

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools autoconf Section 1 automake

pkg-config

Final Words Overview Autotools: An Overview Overview Build automation Automate for consistency, tedium: compilation packaging Build automation testing

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools autoconf Automate for consistency, tedium: automake compilation pkg-config packaging Final Words testing Autotools: An Overview Prominent Systems Overview Prominent Systems bjam, SCons, autotools CMake, , Prominent Systems Many IDEs: Visual Studio, Eclipse, Netbeans, ...

2014-09-24 Autotools: An Overview

Danny Robson • manual dependencies Overview • replicate existing functionality Autotools autoconf make automake bjam, SCons, Waf pkg-config autotools Final Words CMake, gyp, premake Many IDEs: Visual Studio, Eclipse, Netbeans, ... Autotools: An Overview Prominent Systems Overview Prominent Systems make bjam, SCons, Waf autotools CMake, gyp, premake Prominent Systems Many IDEs: Visual Studio, Eclipse, Netbeans, ...

2014-09-24 Autotools: An Overview

Danny Robson • build your own systems Overview • less well known and supported Autotools make • many similar flaws autoconf automake bjam, SCons, Waf – speed pkg-config autotools – complexity Final Words – systems supported CMake, gyp, premake Many IDEs: Visual Studio, Eclipse, Netbeans, ... Autotools: An Overview Prominent Systems Overview Prominent Systems make bjam, SCons, Waf autotools CMake, gyp, premake Prominent Systems Many IDEs: Visual Studio, Eclipse, Netbeans, ...

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools

autoconf make automake bjam, SCons, Waf pkg-config autotools Final Words CMake, gyp, premake Many IDEs: Visual Studio, Eclipse, Netbeans, ... Autotools: An Overview Prominent Systems Overview Prominent Systems make bjam, SCons, Waf autotools CMake, gyp, premake Prominent Systems Many IDEs: Visual Studio, Eclipse, Netbeans, ...

2014-09-24 Autotools: An Overview

Danny Robson • Multiple target backends Overview • Newer languages Autotools make • Faster backends: autoconf automake bjam, SCons, Waf • IDE backends, useful for Windows pkg-config autotools Final Words CMake, gyp, premake Many IDEs: Visual Studio, Eclipse, Netbeans, ... Autotools: An Overview Prominent Systems Overview Prominent Systems make bjam, SCons, Waf autotools CMake, gyp, premake Prominent Systems Many IDEs: Visual Studio, Eclipse, Netbeans, ...

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools

autoconf make automake bjam, SCons, Waf pkg-config autotools Final Words CMake, gyp, premake Many IDEs: Visual Studio, Eclipse, Netbeans, ... Autotools: An Overview Why autotools Overview Why autotools Features for downstream VPATH, DESTDIR, standard targets, config.site, cross compilation, ... Portability Why autotools Just works: configure && make && make install

2014-09-24 Autotools: An Overview

Danny Robson • More platforms than you have access to Overview • Will just work everywhere, solved problems already Autotools autoconf Features for downstream

automake VPATH, DESTDIR, standard targets, config.site, cross

pkg-config compilation, ... Final Words Portability Just works: configure && make && make install Autotools: An Overview Why autotools Overview Why autotools Features for downstream VPATH, DESTDIR, standard targets, config.site, cross compilation, ... Portability Why autotools Just works: configure && make && make install

2014-09-24 Autotools: An Overview

Danny Robson • More platforms than you have access to Overview • Will just work everywhere, solved problems already Autotools autoconf Features for downstream

automake VPATH, DESTDIR, standard targets, config.site, cross

pkg-config compilation, ... Final Words Portability Just works: configure && make && make install Autotools: An Overview Why autotools Overview Why autotools Features for downstream VPATH, DESTDIR, standard targets, config.site, cross compilation, ... Portability Why autotools Just works: configure && make && make install

2014-09-24 Autotools: An Overview

Danny Robson • More platforms than you have access to Overview • Will just work everywhere, solved problems already Autotools autoconf Features for downstream

automake VPATH, DESTDIR, standard targets, config.site, cross

pkg-config compilation, ... Final Words Portability Just works: configure && make && make install Autotools: An Overview Why not autotools Overview Why not autotools Targets UNIX systems Error prone in IDE heavy development Why not autotools Archaic toolsets

2014-09-24 Autotools: An Overview

Danny Robson • Windows support is possible, but painful. Overview • IDE integration is error prone, manual syncing is common Autotools • 70s tools autoconf automake Targets UNIX systems • 90s framework pkg-config Error prone in IDE heavy development • What Year Is It Final Words Archaic toolsets Autotools: An Overview Why not autotools Overview Why not autotools Targets UNIX systems Error prone in IDE heavy development Why not autotools Archaic toolsets

2014-09-24 Autotools: An Overview

Danny Robson • Windows support is possible, but painful. Overview • IDE integration is error prone, manual syncing is common Autotools • 70s tools autoconf automake Targets UNIX systems • 90s framework pkg-config Error prone in IDE heavy development • What Year Is It Final Words Archaic toolsets Autotools: An Overview Why not autotools Overview Why not autotools Targets UNIX systems Error prone in IDE heavy development Why not autotools Archaic toolsets

2014-09-24 Autotools: An Overview

Danny Robson • Windows support is possible, but painful. Overview • IDE integration is error prone, manual syncing is common Autotools • 70s tools autoconf automake Targets UNIX systems • 90s framework pkg-config Error prone in IDE heavy development • What Year Is It Final Words Archaic toolsets Autotools: An Overview Overview

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools

autoconf

automake

pkg-config

Final Words Autotools: An Overview Autotools Section 2

Autotools

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools autoconf Section 2 automake

pkg-config

Final Words Autotools Autotools: An Overview Philosophy Autotools Philosophy UNIX focused Extreme portability Probe, don’t ask Philosophy Convention

2014-09-24 Autotools: An Overview

Danny Robson • Probe avoids out of date , allows hacked systems Overview • GNITS, foreign. README, NEWS, COPYING, ... targets. Autotools autoconf UNIX focused automake Extreme portability pkg-config

Final Words Probe, don’t ask Convention Autotools: An Overview Language Support Autotools Language Support Primarily geared towards systems languages. C, C++, Objective-C, , Erlang Language Support Lisp, Python,

2014-09-24 Autotools: An Overview

Danny Robson • Java via gcj Overview • Scripts more suited to own tools Autotools Primarily geared towards systems languages. • Erlang... autoconf automake C, C++, Objective-C, Fortran pkg-config lex, yacc Final Words Erlang Lisp, Python, Java Autotools: An Overview Language Support Autotools Language Support Primarily geared towards systems languages. C, C++, Objective-C, Fortran lex, yacc Erlang Language Support Lisp, Python, Java

2014-09-24 Autotools: An Overview

Danny Robson • Java via gcj Overview • Scripts more suited to own tools Autotools Primarily geared towards systems languages. • Erlang... autoconf automake C, C++, Objective-C, Fortran pkg-config lex, yacc Final Words Erlang Lisp, Python, Java Autotools: An Overview Language Support Autotools Language Support Primarily geared towards systems languages. C, C++, Objective-C, Fortran lex, yacc Erlang Language Support Lisp, Python, Java

2014-09-24 Autotools: An Overview

Danny Robson • Java via gcj Overview • Scripts more suited to own tools Autotools Primarily geared towards systems languages. • Erlang... autoconf automake C, C++, Objective-C, Fortran pkg-config lex, yacc Final Words Erlang Lisp, Python, Java Autotools: An Overview Language Support Autotools Language Support Primarily geared towards systems languages. C, C++, Objective-C, Fortran lex, yacc Erlang Language Support Lisp, Python, Java

2014-09-24 Autotools: An Overview

Danny Robson • Java via gcj Overview • Scripts more suited to own tools Autotools Primarily geared towards systems languages. • Erlang... autoconf automake C, C++, Objective-C, Fortran pkg-config lex, yacc Final Words Erlang Lisp, Python, Java Autotools: An Overview Languages Needed Autotools Languages Needed Useful, but not necessary, to know a little of: Makefile sh m4 Languages Needed Google

2014-09-24 Autotools: An Overview

Danny Robson Possible to avoid shell scripting, but useful Overview Autotools Useful, but not necessary, to know a little of: autoconf

automake Makefile pkg-config sh Final Words m4 Google Autotools: An Overview Languages Needed Autotools Languages Needed Useful, but not necessary, to know a little of: Makefile sh m4 Languages Needed Google

2014-09-24 Autotools: An Overview

Danny Robson Possible to avoid shell scripting, but useful Overview Autotools Useful, but not necessary, to know a little of: autoconf

automake Makefile pkg-config sh Final Words m4 Google Autotools: An Overview Languages Needed Autotools Languages Needed Useful, but not necessary, to know a little of: Makefile sh m4 Languages Needed Google

2014-09-24 Autotools: An Overview

Danny Robson Possible to avoid shell scripting, but useful Overview Autotools Useful, but not necessary, to know a little of: autoconf

automake Makefile pkg-config sh Final Words m4 Google Autotools: An Overview A Simple Makefile Autotools Makefile A Simple Makefile hello.o: hello.c gcc -c hello.c -o hello.o

hello: hello.o A Simple Makefile gcc hello.o -o hello

2014-09-24 Autotools: An Overview naive Danny Robson 1. naive Overview Autotools Makefile 2. dependency autoconf hello.o: hello.c 3. generalised rules automake gcc -c hello.c -o hello.o pkg-config 4. parameterised Final Words 5. parameterised flags. hello: hello.o gcc hello.o -o hello 6. what about extensions, install, test, clean, output/input paths, clang/icc/solaris, ... Autotools: An Overview A Simple Makefile Autotools Makefile A Simple Makefile hello.o: hello.c hello.h gcc -c hello.c -o hello.o

hello: hello.o A Simple Makefile gcc hello.o -o hello

2014-09-24 Autotools: An Overview

Danny Robson 1. naive Overview 2. dependency Autotools Makefile 3. generalised rules autoconf hello.o: hello.c hello.h automake gcc -c hello.c -o hello.o 4. parameterised compiler pkg-config

Final Words 5. parameterised flags. hello: hello.o 6. what about extensions, install, test, clean, output/input paths, gcc hello.o -o hello clang/icc/solaris, ... Autotools: An Overview A Simple Makefile Autotools Makefile A Simple Makefile hello.o: hello.c hello.h gcc -c$ < -o $@

hello: hello.o A Simple Makefile gcc $^ -o $@

2014-09-24 Autotools: An Overview

Danny Robson 1. naive Overview 2. dependency Autotools Makefile 3. generalised rules autoconf hello.o: hello.c hello.h automake gcc -c$ < -o $@ 4. parameterised compiler pkg-config

Final Words 5. parameterised flags. hello: hello.o 6. what about extensions, install, test, clean, output/input paths, gcc $^ -o $@ clang/icc/solaris, ... Autotools: An Overview A Simple Makefile Autotools Makefile A Simple Makefile hello.o: hello.c hello.h $(CC) -c$ < -o $@

hello: hello.o A Simple Makefile $(CC) $^ -o $@

2014-09-24 Autotools: An Overview

Danny Robson 1. naive Overview 2. dependency Autotools Makefile 3. generalised rules autoconf hello.o: hello.c hello.h automake $(CC) -c$ < -o $@ 4. parameterised compiler pkg-config

Final Words 5. parameterised flags. hello: hello.o 6. what about extensions, install, test, clean, output/input paths, $(CC) $^ -o $@ clang/icc/solaris, ... Autotools: An Overview A Simple Makefile Autotools Makefile A Simple Makefile hello.o: hello.c hello.h $(CC) $(CFLAGS) -c$ < -o $@

hello: hello.o A Simple Makefile $(CC) $(LDFLAGS) $^ -o $@

2014-09-24 Autotools: An Overview

Danny Robson 1. naive Overview 2. dependency Autotools Makefile 3. generalised rules autoconf hello.o: hello.c hello.h automake $(CC) $(CFLAGS) -c$ < -o $@ 4. parameterised compiler pkg-config

Final Words 5. parameterised flags. hello: hello.o 6. what about extensions, install, test, clean, output/input paths, $(CC) $(LDFLAGS) $^ -o $@ clang/icc/solaris, ... Autotools: An Overview A Naive Makefile Autotools Makefile A Naive Makefile hello.o: hello.c hello.h $(CC) $(CFLAGS) -c$ < -o $@

hello: hello.o A Naive Makefile $(CC) $(LDFLAGS) $^ -o $@

2014-09-24 Autotools: An Overview

Danny Robson 1. naive Overview 2. dependency Autotools Makefile 3. generalised rules autoconf hello.o: hello.c hello.h automake $(CC) $(CFLAGS) -c$ < -o $@ 4. parameterised compiler pkg-config

Final Words 5. parameterised flags. hello: hello.o 6. what about extensions, install, test, clean, output/input paths, $(CC) $(LDFLAGS) $^ -o $@ clang/icc/solaris, ... Autotools: An Overview How it fits together Autotools How it fits together

How it fits together

2014-09-24 Autotools: An Overview

Danny Robson 1. User provides configure.ac, Makefile.am Overview 2. aclocal collates required m4 macros Autotools autoconf 3. autoconf generates configure script Makefile.am automake Makefile.in automake config.status Makefile 4. autoheader generates template config.h pkg-config aclocal aclocal.m4 autoconf configure configure.ac 5. automake generates template Makefiles Final Words autoheader config.h.in 6. configure executes macros and writes config.status 7. config.status fills in the various templates Autotools: An Overview Flow of execution Autotools Flow of execution

Flow of execution

2014-09-24 Autotools: An Overview

Danny Robson 1. autoreconf Overview 2. configure Autotools autoconf 3. Makefile configure.ac automake pkg-config autoreconf configure Makefile Final Words Makefile.am Autotools: An Overview Initialisation Autotools Initialisation configure.ac autoscan autoproject Makefile.am Initialisation m4/ Commands autoreconf -i 2014-09-24 Autotools: An Overview

Danny Robson Files Overview Autotools configure.ac autoconf autoscan automake autoproject pkg-config

Final Words Makefile.am m4/

Commands autoreconf -i Autotools: An Overview autoconf Section 3

autoconf

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools autoconf Section 3 automake

pkg-config

Final Words autoconf Autotools: An Overview autoconf autoconf Discovers system characteristics autoconf autoconf-archive pkg-config gnulib Compute substitution values, variables Curious mixture of M4 and sh autoconf Vanilla shell more-or-less supported Easy to start, hard to master

2014-09-24 Autotools: An Overview

Danny Robson Substitution values for config.status Variables for automake Quoting is a common pitfall Overview Autotools Discovers system characteristics

autoconf autoconf-archive

automake pkg-config

pkg-config gnulib Final Words Compute substitution values, variables Curious mixture of M4 and sh Vanilla shell more-or-less supported Easy to start, hard to master Autotools: An Overview autoconf autoconf Discovers system characteristics autoconf autoconf-archive pkg-config gnulib Compute substitution values, variables Curious mixture of M4 and sh autoconf Vanilla shell more-or-less supported Easy to start, hard to master

2014-09-24 Autotools: An Overview

Danny Robson Substitution values for config.status Variables for automake Quoting is a common pitfall Overview Autotools Discovers system characteristics

autoconf autoconf-archive

automake pkg-config

pkg-config gnulib Final Words Compute substitution values, variables Curious mixture of M4 and sh Vanilla shell more-or-less supported Easy to start, hard to master Autotools: An Overview autoconf autoconf Discovers system characteristics autoconf autoconf-archive pkg-config gnulib Compute substitution values, variables Curious mixture of M4 and sh autoconf Vanilla shell more-or-less supported Easy to start, hard to master

2014-09-24 Autotools: An Overview

Danny Robson Substitution values for config.status Variables for automake Quoting is a common pitfall Overview Autotools Discovers system characteristics

autoconf autoconf-archive

automake pkg-config

pkg-config gnulib Final Words Compute substitution values, variables Curious mixture of M4 and sh Vanilla shell more-or-less supported Easy to start, hard to master Autotools: An Overview autoconf autoconf Discovers system characteristics autoconf autoconf-archive pkg-config gnulib Compute substitution values, variables Curious mixture of M4 and sh autoconf Vanilla shell more-or-less supported Easy to start, hard to master

2014-09-24 Autotools: An Overview

Danny Robson Substitution values for config.status Variables for automake Quoting is a common pitfall Overview Autotools Discovers system characteristics

autoconf autoconf-archive

automake pkg-config

pkg-config gnulib Final Words Compute substitution values, variables Curious mixture of M4 and sh Vanilla shell more-or-less supported Easy to start, hard to master Autotools: An Overview autoconf autoconf Discovers system characteristics autoconf autoconf-archive pkg-config gnulib Compute substitution values, variables Curious mixture of M4 and sh autoconf Vanilla shell more-or-less supported Easy to start, hard to master

2014-09-24 Autotools: An Overview

Danny Robson Substitution values for config.status Variables for automake Quoting is a common pitfall Overview Autotools Discovers system characteristics

autoconf autoconf-archive

automake pkg-config

pkg-config gnulib Final Words Compute substitution values, variables Curious mixture of M4 and sh Vanilla shell more-or-less supported Easy to start, hard to master Autotools: An Overview autoconf autoconf Discovers system characteristics autoconf autoconf-archive pkg-config gnulib Compute substitution values, variables Curious mixture of M4 and sh autoconf Vanilla shell more-or-less supported Easy to start, hard to master

2014-09-24 Autotools: An Overview

Danny Robson Substitution values for config.status Variables for automake Quoting is a common pitfall Overview Autotools Discovers system characteristics

autoconf autoconf-archive

automake pkg-config

pkg-config gnulib Final Words Compute substitution values, variables Curious mixture of M4 and sh Vanilla shell more-or-less supported Easy to start, hard to master Autotools: An Overview autoconf autoconf Discovers system characteristics autoconf autoconf-archive pkg-config gnulib Compute substitution values, variables Curious mixture of M4 and sh autoconf Vanilla shell more-or-less supported Easy to start, hard to master

2014-09-24 Autotools: An Overview

Danny Robson Substitution values for config.status Variables for automake Quoting is a common pitfall Overview Autotools Discovers system characteristics

autoconf autoconf-archive

automake pkg-config

pkg-config gnulib Final Words Compute substitution values, variables Curious mixture of M4 and sh Vanilla shell more-or-less supported Easy to start, hard to master Autotools: An Overview autoconf autoconf Discovers system characteristics autoconf autoconf-archive pkg-config gnulib Compute substitution values, variables Curious mixture of M4 and sh autoconf Vanilla shell more-or-less supported Easy to start, hard to master

2014-09-24 Autotools: An Overview

Danny Robson Substitution values for config.status Variables for automake Quoting is a common pitfall Overview Autotools Discovers system characteristics

autoconf autoconf-archive

automake pkg-config

pkg-config gnulib Final Words Compute substitution values, variables Curious mixture of M4 and sh Vanilla shell more-or-less supported Easy to start, hard to master Autotools: An Overview A simple autoconf input autoconf A simple autoconf input configure.ac AC INIT([foo], [1.2.3], [[email protected]]) AC PROG CC AC CONFIG FILES([Makefile]) A simple autoconf input AC OUTPUT

2014-09-24 Autotools: An Overview One of two important input files. And M4sh script calling autoconf Danny Robson

macros squarebracket is quote Overview

Autotools • AC INIT first macro, initialises everything configure.ac autoconf • AC PROG FOO locate prog and init vars automake AC INIT([foo], [1.2.3], [[email protected]]) • AC CONFIG FILES paths we want to parameterise. Anything pkg-config AC PROG CC ending in .in Final Words AC CONFIG FILES([Makefile]) AC OUTPUT • AC OUTPUT interpolate the files Autotools: An Overview Example: Makefile autoconf Makefile.in Example: Makefile hello.o: hello.c hello.h @CC@ @CFLAGS@ -c $< -o $@

hello: hello.o Example: Makefile @CC@ @LDFLAGS@ $^ -o $@

2014-09-24 Autotools: An Overview

Danny Robson

Overview Makefile.in Autotools autoconf hello.o: hello.c hello.h automake @CC@ @CFLAGS@ -c $< -o $@ pkg-config Final Words hello: hello.o @CC@ @LDFLAGS@ $^ -o $@ Autotools: An Overview Example: Template Doxyfile autoconf Example: Template Doxyfile Doxyfile.in PROJECT NAME = @PACKAGE NAME@ PROJECT NUMBER = @PACKAGE VERSION@ Example: Template Doxyfile OUTPUT DIRECTORY = @top builddir@/doc

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools

autoconf Doxyfile.in automake PROJECT NAME = @PACKAGE NAME@ pkg-config PROJECT NUMBER = @PACKAGE VERSION@ Final Words OUTPUT DIRECTORY = @top builddir@/doc Autotools: An Overview Example: Library discovery autoconf configure.ac Example: Library discovery AC SEARCH LIBS( [glBegin], [OpenGL opengl32 GL], [], [AC MSG ERROR(["Can’t find OpenGL"])] Example: Library discovery )

2014-09-24 Autotools: An Overview

Danny Robson

Overview configure.ac Autotools autoconf AC SEARCH LIBS( automake [glBegin], pkg-config [OpenGL opengl32 GL], Final Words [], [AC MSG ERROR(["Can’t find OpenGL"])] ) Autotools: An Overview Example: conditional enable configure.ac AC ARG ENABLE( autoconf [debugging], [AS HELP STRING( Example: conditional enable [--enable-debugging], [enables developer debugging support] ) ]) Example: conditional enable AS IF([test "x${enable debugging}"= "xyes"], [ AX APPEND COMPILE FLAGS([-O0]) ], [ 2014-09-24 AX APPEND COMPILE FLAGS([-02]) Autotools: An ]) Overview configure.ac Danny Robson AC ARG ENABLE( Overview [debugging], Autotools [AS HELP STRING( autoconf [--enable-debugging], automake [enables developer debugging support] pkg-config ) Final Words ])

AS IF([test "x${enable debugging}"= "xyes"], [ AX APPEND COMPILE FLAGS([-O0]) ], [ AX APPEND COMPILE FLAGS([-02]) ]) Autotools: An Overview automake Section 4

automake

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools autoconf Section 4 automake

pkg-config

Final Words automake Autotools: An Overview automake automake automake Generates Makefile.in from Makefile.am Compiler derived dependency tracking automake make-syntax with magic variables

2014-09-24 Autotools: An Overview

Danny Robson • Fine to use make syntax everywhere, own variables, own rules Overview • Must avoid clashes with some key variables Autotools autoconf • Dependency tracking uses the compiler. Various iterations Generates Makefile.in from Makefile.am before, this is most robust. automake pkg-config Compiler derived dependency tracking Final Words make-syntax with magic variables Autotools: An Overview automake automake automake

automake

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools

autoconf

automake

pkg-config

Final Words Autotools: An Overview A simple automake input

Makefile.am automake bin PROGRAMS = hello A simple automake input hello SOURCES = hello.cpp hello.hpp hello LDADD = $(BOOST LDFLAGS) hello CXXFLAGS = $(BOOST CPPFLAGS)

A simple automake input Atoms target where PRIMARY 2014-09-24 source target WHAT Autotools: An Overview

Danny Robson Unsure if target/source is correct nomenclature Makefile.am Overview bin PROGRAMS = hello Autotools autoconf hello SOURCES = hello.cpp hello.hpp automake hello LDADD = $(BOOST LDFLAGS) pkg-config hello CXXFLAGS = $(BOOST CPPFLAGS) Final Words

Atoms

target where PRIMARY source target WHAT Autotools: An Overview Targets

automake Atom Targets bin PROGRAMS where PRIMARY

where

location bin, lib, include, share, man, info, ... Targets noinst Not installed. Used during build only. check Not installed. Only created for tests.

2014-09-24 Autotools: An Overview

Danny Robson • custom locations via foodir Overview Atom Autotools bin PROGRAMS autoconf where PRIMARY automake pkg-config where Final Words location bin, lib, include, share, man, info, ... noinst Not installed. Used during build only. check Not installed. Only created for tests. Autotools: An Overview Targets

Atom automake bin PROGRAMS Targets where PRIMARY

PRIMARY

PROGRAMS Executable binaries LIBRARIES Libraries Targets HEADERS Installable headers SCRIPTS Installable scripts

2014-09-24 DATA Architecture independant data Autotools: An Overview

Danny Robson LTLIBRARIES Atom Overview bin PROGRAMS Autotools where PRIMARY autoconf automake PRIMARY pkg-config Final Words PROGRAMS Executable binaries LIBRARIES Libraries HEADERS Installable headers SCRIPTS Installable scripts DATA Architecture independant data Autotools: An Overview Source

Atom automake hello SOURCES Source target WHAT

WHAT

SOURCES All source files; headers too. CFLAGS Compiler flags Source LDFLAGS Linker flags LIBADD Libraries; extra libs

2014-09-24 LDADD Programs; extra libs Autotools: An Overview Danny Robson Atom Overview hello SOURCES Autotools target WHAT autoconf automake WHAT pkg-config Final Words SOURCES All source files; headers too. CFLAGS Compiler flags LDFLAGS Linker flags LIBADD Libraries; extra libs LDADD Programs; extra libs Autotools: An Overview Example: Vanilla Make

automake Makefile.am SUFFIXES = .cpp .cpp.rl Example: Vanilla Make .cpp.rl.cpp: $(RAGEL) $(RAGELFLAGS)-C$ < -o $(builddir)/$@

bin PROGRAMS = hello Example: Vanilla Make hello SOURCES = hello.cpp hello.hpp parse.cpp hello LDADD = $(BOOST LDFLAGS) hello CXXFLAGS = $(BOOST CPPFLAGS) 2014-09-24 Autotools: An Overview

Danny Robson Ignoring EXTRA DIST and CLEANFILES Makefile.am Overview

Autotools SUFFIXES = .cpp .cpp.rl

autoconf .cpp.rl.cpp:

automake $(RAGEL) $(RAGELFLAGS)-C$ < -o $(builddir)/$@

pkg-config Final Words bin PROGRAMS = hello

hello SOURCES = hello.cpp hello.hpp parse.cpp hello LDADD = $(BOOST LDFLAGS) hello CXXFLAGS = $(BOOST CPPFLAGS) Autotools: An Overview Example: Conditionals

configure.ac automake AC ENABLE([network], [--enable-network]) AM CONDITIONAL( Example: Conditionals [ENABLE NETWORK], [test "x${enable network}"= "xyes"])

Makefile.am Example: Conditionals if ENABLE NETWORK foo SOURCES += network.c foo LDADD += $(NET LIBS) 2014-09-24 endif Autotools: An Overview

Danny Robson configure.ac AC HELP STRING Overview AC ENABLE([network], [--enable-network]) Autotools AM CONDITIONAL( autoconf [ENABLE NETWORK], automake [test "x${enable network}"= "xyes"]) pkg-config

Final Words Makefile.am if ENABLE NETWORK foo SOURCES += network.c foo LDADD += $(NET LIBS) endif Autotools: An Overview pkg-config Section 5

pkg-config

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools autoconf Section 5 automake

pkg-config

Final Words pkg-config Autotools: An Overview pkg-config A better query for installed libraries Compiler parameters Linker parameters Versioning Command line and autotools wrappers

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools

autoconf A better query for installed libraries

automake Compiler parameters

pkg-config Linker parameters

Final Words Versioning Command line and autotools wrappers Autotools: An Overview pkg-config: producers

libfoo.pc pkg-config prefix=@prefix@ exec prefix=@exec prefix@ pkg-config: producers libdir=@libdir@ includedir=@includedir@

Name: libfoo Description: A simple test library pkg-config: producers URL: http://example.com/ Version: @VERSION@ Cflags:-I$ {includedir} 2014-09-24 Libs:-L$ {libdir} -lfoo Autotools: An Overview Danny Robson libfoo.pc

Overview prefix=@prefix@ Autotools exec prefix=@exec prefix@ autoconf libdir=@libdir@ automake includedir=@includedir@ pkg-config Final Words Name: libfoo Description: A simple test library URL: http://example.com/ Version: @VERSION@ Cflags:-I$ {includedir} Libs:-L$ {libdir} -lfoo Autotools: An Overview pkg-config: consumers pkg-config configure.ac pkg-config: consumers PKG CHECK MODULES([FOO], [libfoo >= 0.2.0])

Makefile.am hello CFLAGS += FOO CFLAGS pkg-config: consumers hello LDADD += FOO LIBS

2014-09-24 Autotools: An Overview

Danny Robson

Overview configure.ac Autotools autoconf PKG CHECK MODULES([FOO], [libfoo >= 0.2.0]) automake

pkg-config Final Words Makefile.am hello CFLAGS += FOO CFLAGS hello LDADD += FOO LIBS Autotools: An Overview Final Words Section 6

Final Words

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools autoconf Section 6 automake

pkg-config

Final Words Final Words Autotools: An Overview Final Words I’m not going to pretend that autoconf is good [...] but it’s much better than the alternatives once you start needing to compile on many different platforms, cross compile, or integrate with Linux distro packaging systems. – Richard WM Jones

2014-09-24 Autotools: An Overview

Danny Robson

Overview

Autotools

autoconf I’m not going to pretend that autoconf is good [...]

automake but it’s much better than the alternatives once you

pkg-config start needing to compile on many different platforms,

Final Words cross compile, or integrate with Linux distro packaging systems. – Richard WM Jones Autotools: An Overview More Features Final Words More Features gnulib autoheader autoconf-archive libtool More Features ...

2014-09-24 Autotools: An Overview

Danny Robson

Overview Autotools gnulib autoconf autoheader automake

pkg-config autoconf-archive Final Words gettext libtool ... Autotools: An Overview Further Reading Final Words Goat book Further Reading GNU autoconf manual GNU automake manual GNU make manual man pkg-config Further Reading Autotools Mythbuster Alexandre Duret-Lutz’s tutorial

2014-09-24 Autotools: An Overview

Danny Robson • macro and variable indexes Overview

Autotools Goat book autoconf GNU autoconf manual automake GNU automake manual pkg-config GNU make manual Final Words man pkg-config Autotools Mythbuster Alexandre Duret-Lutz’s tutorial Autotools: An Overview Further Reading Final Words Goat book Further Reading GNU autoconf manual GNU automake manual GNU make manual man pkg-config Further Reading Autotools Mythbuster Alexandre Duret-Lutz’s tutorial

2014-09-24 Autotools: An Overview

Danny Robson • macro and variable indexes Overview

Autotools Goat book autoconf GNU autoconf manual automake GNU automake manual pkg-config GNU make manual Final Words man pkg-config Autotools Mythbuster Alexandre Duret-Lutz’s tutorial Autotools: An Overview Further Reading Final Words Goat book Further Reading GNU autoconf manual GNU automake manual GNU make manual man pkg-config Further Reading Autotools Mythbuster Alexandre Duret-Lutz’s tutorial

2014-09-24 Autotools: An Overview

Danny Robson • macro and variable indexes Overview

Autotools Goat book autoconf GNU autoconf manual automake GNU automake manual pkg-config GNU make manual Final Words man pkg-config Autotools Mythbuster Alexandre Duret-Lutz’s tutorial Autotools: An Overview Secret Level Section 7

Secret Level

2014-09-24 Autotools: An Overview

Danny Robson

Secret Level

Section 7

Secret Level Autotools: An Overview Example: host specific configuration

configure.ac Secret Level AC CANONICAL HOST Example: host specific configuration case $host os in mingw32) AC CHECK HEADERS([winsock2.h ws2tcpip.h]) AC SUBST([NET LIBS], [-lws2 32]) AX APPEND COMPLE FLAGS( Example: host specific configuration [-DBOOST THREAD USE LIB] ) ;; 2014-09-24 esac Autotools: An Overview Danny Robson configure.ac • vanilla shell embedded Secret Level AC CANONICAL HOST

case $host os in mingw32) AC CHECK HEADERS([winsock2.h ws2tcpip.h]) AC SUBST([NET LIBS], [-lws2 32]) AX APPEND COMPLE FLAGS( [-DBOOST THREAD USE LIB] ) ;; esac Autotools: An Overview Multi-source Makefile.am Secret Level noinst LIBRARIES = libclcruft.a libclcruft SOURCES = cl/base.cpp # etc.. Multi-source bin PROGRAMS = waif cl-info

waif SOURCES = waif.cpp waif LDADD = \ ${top builddir}/libclcruft.a \ Multi-source ${top builddir}/util/libutil.a

2014-09-24 cl info SOURCES = tools/cl-info.cpp cl info SOURCES =$ {top builddir}/libclcruft.a Autotools: An Overview Makefile.am Danny Robson noinst LIBRARIES = libclcruft.a Secret Level libclcruft SOURCES = cl/base.cpp # etc..

bin PROGRAMS = waif cl-info

waif SOURCES = waif.cpp waif LDADD = \ ${top builddir}/libclcruft.a \ ${top builddir}/util/libutil.a

cl info SOURCES = tools/cl-info.cpp cl info SOURCES =$ {top builddir}/libclcruft.a