<<

GNU Autotools Are What Your Users Need

Ludovic Courtes` GNU Autotools Do What Your Users Need

Ludovic Courtes` agenda

1. intro 2. goals & design 3. on portability 4. action 5. wrap up

L. Courtes` – GNU Autotools Do What Your Users Need 2 1 intro

L. Courtes` – GNU Autotools Do What Your Users Need 3

is your software installable? --with-color --disable-shared CC=gcc-4.9

--prefix=$HOME/soft

what do users want?

• ./configure

• make check • make install

L. Courtes` – GNU Autotools Do What Your Users Need 7 --with-color --disable-shared CC=gcc-4.9

what do users want?

• ./configure --prefix=$HOME/soft

• make • make check • make install

L. Courtes` – GNU Autotools Do What Your Users Need 7 --disable-shared CC=gcc-4.9

what do users want?

• ./configure --prefix=$HOME/soft --with-color

• make • make check • make install

L. Courtes` – GNU Autotools Do What Your Users Need 7 CC=gcc-4.9

what do users want?

• ./configure --prefix=$HOME/soft --with-color --disable-shared • make • make check • make install

L. Courtes` – GNU Autotools Do What Your Users Need 7 what do users want?

• ./configure --prefix=$HOME/soft --with-color --disable-shared CC=gcc-4.9 • make • make check • make install

L. Courtes` – GNU Autotools Do What Your Users Need 7 2 goals & design

L. Courtes` – GNU Autotools Do What Your Users Need 8 - mostly among Unix variants

- easy way to install the software - standardized (GNU Coding Standards)

- only requires POSIX sh and make!

autotools goals

• portability aid

• friendly user interface

• no additional dependencies for the user

L. Courtes` – GNU Autotools Do What Your Users Need 9 - easy way to install the software - standardized (GNU Coding Standards)

- only requires POSIX sh and make!

autotools goals

• portability aid - mostly among Unix variants • friendly user interface

• no additional dependencies for the user

L. Courtes` – GNU Autotools Do What Your Users Need 9 - only requires POSIX sh and make!

autotools goals

• portability aid - mostly among Unix variants • friendly user interface - easy way to install the software - standardized (GNU Coding Standards) • no additional dependencies for the user

L. Courtes` – GNU Autotools Do What Your Users Need 9 autotools goals

• portability aid - mostly among Unix variants • friendly user interface - easy way to install the software - standardized (GNU Coding Standards) • no additional dependencies for the user - only requires POSIX sh and make!

L. Courtes` – GNU Autotools Do What Your Users Need 9 “The primary goal of is making the user’s life easier; making the maintainer’s life easier is only a secondary goal.”

— Autoconf manual

L. Courtes` – GNU Autotools Do What Your Users Need 10 “autotools”?

• Autoconf

• Libtool

L. Courtes` – GNU Autotools Do What Your Users Need 11 3 on portability

L. Courtes` – GNU Autotools Do What Your Users Need 12 being “portable” to different...

• shells • make implementations • features • C library quirks (non-conformance, bugs, etc.) • compilers • linkers • loaders • ...

L. Courtes` – GNU Autotools Do What Your Users Need 13 systemology

rm, mv, cp, ... grep, sed

shell compiler

stdlib.h libc.so math.h libc libm.so pthread.h libpthread.so dlfcn.h ld.so

kernel

L. Courtes` – GNU Autotools Do What Your Users Need 14 systemology

rm, mv, cp, ... GNU grep, sed GNU

shell compiler GCC

stdlib.h libc.so math.h libc libm.so pthread.h GNUlibpthread.so dlfcn.h ld.so

kernel

L. Courtes` – GNU Autotools Do What Your Users Need 14 systemology

rm, mv, cp, ... GNU grep, sed GNU

shell zsh compiler Clang

stdlib.h libc.so math.h libc libm.so pthread.h GNUlibpthread.so dlfcn.h ld.so

kernel Linux

L. Courtes` – GNU Autotools Do What Your Users Need 14 systemology

rm, mv, cp, ... Busybox grep, sed Busybox

shell zsh compiler Clang

stdlib.h libc.so math.h libc libm.so pthread.h GNUlibpthread.so dlfcn.h ld.so

kernel Linux

L. Courtes` – GNU Autotools Do What Your Users Need 14 systemology

rm, mv, cp, ... Busybox grep, sed Busybox

shell zsh compiler Clang

stdlib.h libc.so math.h libc libm.so pthread.h GNUlibpthread.so dlfcn.h ld.so

kernel kFreeBSD

L. Courtes` – GNU Autotools Do What Your Users Need 14 systemology

rm, mv, cp, ... Busybox grep, sed Busybox

shell zsh compiler Clang

stdlib.h libc.so math.h libc libm.so pthread.h Bioniclibpthread.so(Android) dlfcn.h ld.so

kernel Linux

L. Courtes` – GNU Autotools Do What Your Users Need 14 systemology

rm, mv, cp, ... Busybox grep, sed Busybox

shell zsh compiler Clang

stdlib.h how do I checklibc.so math.h for featurelibc X?libm.so pthread.h Bioniclibpthread.so(Android) dlfcn.h ld.so

kernel Linux

L. Courtes` – GNU Autotools Do What Your Users Need 14 if [ ‘uname‘ = Linux ] then CC=gcc ; SHELL=/bin/bash ... fi

gcc -DOS LINUX=1 ...

identity test

#ifdef __linux__ # include #endif

L. Courtes` – GNU Autotools Do What Your Users Need 15 gcc -DOS LINUX=1 ...

identity test

#ifdef __linux__ # include #endif if [ ‘uname‘ = Linux ] then CC=gcc ; SHELL=/bin/bash ... fi

L. Courtes` – GNU Autotools Do What Your Users Need 15 identity test

#ifdef __linux__ # include #endif if [ ‘uname‘ = Linux ] then CC=gcc ; SHELL=/bin/bash ... fi gcc -DOS LINUX=1 ...

L. Courtes` – GNU Autotools Do What Your Users Need 15 identity test

#ifdef __linux__ # include #endif wrong if [ ‘uname‘ = Linux ] then CC=gcc ; SHELL=/bin/bash ... fi gcc -DOS LINUX=1 ...

L. Courtes` – GNU Autotools Do What Your Users Need 15 solution: feature tests

• AC PATH PROG • AC CHECK LIB • AC CHECKcheckHEADER for specific features • AC COMPILE IFELSE • AC LINK IFELSE • ...

L. Courtes` – GNU Autotools Do What Your Users Need 16 solution: feature tests

• AC PATH PROG • AC CHECK LIB • AC CHECK HEADER • AC COMPILE IFELSE • AC LINK IFELSE • ...

L. Courtes` – GNU Autotools Do What Your Users Need 16 going further...

Gnulib: a portability library http://www.gnu.org/software/gnulib/

L. Courtes` – GNU Autotools Do What Your Users Need 17 4 action

L. Courtes` – GNU Autotools Do What Your Users Need 18 running example

git://scm.gforge.inria.fr/autotools-demo/ autotools-demo.git

• C program • requirements: GNU Scientific Library, GNU • computes an FFT, plots it

L. Courtes` – GNU Autotools Do What Your Users Need 19 road map

0. hand-written makefile 1. Autoconf + simple makefile template 2. Autoconf + Automake 3. + optional libplot support 4. + tests 5. + turn plotting into a Libtool library

each step has a corresponding branch in git://scm.gforge.inria.fr/.../autotools-demo.git

L. Courtes` – GNU Autotools Do What Your Users Need 20 road map

0. hand-written makefile 1. Autoconf + simple makefile template 2. Autoconf + Automakeall that in 25mn! 3. + optional libplot support 4. + tests 5. + turn plotting into a Libtool library

each step has a corresponding branch in git://scm.gforge.inria.fr/.../autotools-demo.git

L. Courtes` – GNU Autotools Do What Your Users Need 20 road map

0. hand-written makefile 1. Autoconf + simple makefile template 2. Autoconf + Automakeall that in 25mn! 3. + optional libplot support 4. + tests 5. + turn plotting into a Libtool library

each step has a corresponding branch in git://scm.gforge.inria.fr/.../autotools-demo.git

L. Courtes` – GNU Autotools Do What Your Users Need 20 step 0: hand-written makefile branch 0-hand-written-makefile

L. Courtes` – GNU Autotools Do What Your Users Need 21 step 0: hand-written makefile branch 0-hand-written-makefile

Yay it builds on my machine!

L. Courtes` – GNU Autotools Do What Your Users Need 21 • gains - user interface to specify installation directories - tools to check for programming environment features - template instantiation: foo.in → foo - config.h, config.log

step 1: our first configure.ac branch 1-autoconf+simple-makefile-template

• tools - commands: autoscan, autoconf - macros: AC CHECK LIB, AC CHECK HEADERS

L. Courtes` – GNU Autotools Do What Your Users Need 22 step 1: our first configure.ac branch 1-autoconf+simple-makefile-template

• tools - commands: autoscan, autoconf - macros: AC CHECK LIB, AC CHECK HEADERS • gains - user interface to specify installation directories - tools to check for programming environment features - template instantiation: foo.in → foo - config.h, config.log

L. Courtes` – GNU Autotools Do What Your Users Need 22 • gains - honor installation directories: bindir, etc. - honor user variables: CFLAGS, DESTDIR, etc. - rules: all, install, uninstall • bonuses! - distribution: dist & distcheck - --enable-silent-rules - dependency tracking among .c and .h - rules to rebuild configure & co. - out-of-source builds - cross-compilation support - ...

step 2: using Automake branch 2-autoconf+automake

• tools - commands: automake, autoreconf - naming of Makefile.am variables, installation directories

L. Courtes` – GNU Autotools Do What Your Users Need 23 • bonuses! - distribution: dist & distcheck - --enable-silent-rules - dependency tracking among .c and .h - rules to rebuild configure & co. - out-of-source builds - cross-compilation support - ...

step 2: using Automake branch 2-autoconf+automake

• tools - commands: automake, autoreconf - naming of Makefile.am variables, installation directories • gains - honor installation directories: bindir, etc. - honor user variables: CFLAGS, DESTDIR, etc. - rules: all, install, uninstall

L. Courtes` – GNU Autotools Do What Your Users Need 23 step 2: using Automake branch 2-autoconf+automake

• tools - commands: automake, autoreconf - naming of Makefile.am variables, installation directories • gains - honor installation directories: bindir, etc. - honor user variables: CFLAGS, DESTDIR, etc. - rules: all, install, uninstall • bonuses! - distribution: dist & distcheck - --enable-silent-rules - dependency tracking among .c and .h - rules to rebuild configure & co. - out-of-source builds - cross-compilation support - ...

L. Courtes` – GNU Autotools Do What Your Users Need 23 • gains - optional part of the build - user can choose

step 3: making a dependency optional branch 3-autoconf+automake+conditional-libplot

• tools - in configure.ac: AM CONDITIONAL, AC ARG ENABLE - in Makefile.am: if, +=

L. Courtes` – GNU Autotools Do What Your Users Need 24 step 3: making a dependency optional branch 3-autoconf+automake+conditional-libplot

• tools - in configure.ac: AM CONDITIONAL, AC ARG ENABLE - in Makefile.am: if, += • gains - optional part of the build - user can choose

L. Courtes` – GNU Autotools Do What Your Users Need 24 -j4

- in configure.ac: color-tests • gains - portable makefile (GNU Make, BSD Make, etc.) - make check - test-suite.log and TEST.log • bonuses! - color! - parallel tests! - make recheck - reStructuredText logs

step 4: adding tests branch 4-autoconf+automake+tests

• tools - in Makefile.am: TESTS, SH LOG EXTENSIONS, SH LOG COMPILER

L. Courtes` – GNU Autotools Do What Your Users Need 25 - in configure.ac: color-tests

-j4

• bonuses! - color! - parallel tests! - make recheck - reStructuredText logs

step 4: adding tests branch 4-autoconf+automake+tests

• tools - in Makefile.am: TESTS, SH LOG EXTENSIONS, SH LOG COMPILER

• gains - portable makefile (GNU Make, BSD Make, etc.) - make check - test-suite.log and TEST.log

L. Courtes` – GNU Autotools Do What Your Users Need 25 step 4: adding tests branch 4-autoconf+automake+tests

• tools - in Makefile.am: TESTS, SH LOG EXTENSIONS, SH LOG COMPILER - in configure.ac: color-tests • gains - portable makefile (GNU Make, BSD Make, etc.) - make check -j4 - test-suite.log and TEST.log • bonuses! - color! - parallel tests! - make recheck - reStructuredText logs

L. Courtes` – GNU Autotools Do What Your Users Need 25 • gains - portable shared libraries (woow!) - --disabled-shared, --disable-static, etc. - shared lib usable before installation - shared lib relinked with RUNPATH set upon install - .la contains dependent libs (for static linking) - .la contains extra linker flags

step 5: building a library branch 5-autoconf+automake+libtool

• tools - commands: libtoolize, automake --add-missing - in Makefile.am: LT LIBRARIES, .la - in configure.ac: LT INIT

L. Courtes` – GNU Autotools Do What Your Users Need 26 step 5: building a library branch 5-autoconf+automake+libtool

• tools - commands: libtoolize, automake --add-missing - in Makefile.am: LT LIBRARIES, .la - in configure.ac: LT INIT • gains - portable shared libraries (woow!) - --disabled-shared, --disable-static, etc. - shared lib usable before installation - shared lib relinked with RUNPATH set upon install - .la contains dependent libs (for static linking) - .la contains extra linker flags

L. Courtes` – GNU Autotools Do What Your Users Need 26 the big picture

source: http://www.freesoftwaremagazine.com/articles/brief introduction to autotools

L. Courtes` – GNU Autotools Do What Your Users Need 27 the big picture

make and autoreconf know how to do that

source: http://www.freesoftwaremagazine.com/articles/brief introduction to

L. Courtes` – GNU Autotools Do What Your Users Need 27 5 wrap up

L. Courtes` – GNU Autotools Do What Your Users Need 28 “Those who do not understand Autoconf are condemned to reinvent it, poorly.”

— Autoconf manual

L. Courtes` – GNU Autotools Do What Your Users Need 29 • ... yet neatly support maintenance work • a lot of embedded portability & UI expertise

summary

• autotools make the user’s life easier

L. Courtes` – GNU Autotools Do What Your Users Need 30 • a lot of embedded portability & UI expertise

summary

• autotools make the user’s life easier • ... yet neatly support maintenance work

L. Courtes` – GNU Autotools Do What Your Users Need 30 summary

• autotools make the user’s life easier • ... yet neatly support maintenance work • a lot of embedded portability & UI expertise

L. Courtes` – GNU Autotools Do What Your Users Need 30 [email protected] http://sed.bordeaux.inria.fr/