13
NRCFOSS 1 Understanding Configuration and Build Systems

Build Systems

Embed Size (px)

DESCRIPTION

linux

Citation preview

Page 1: Build Systems

NRCFOSS 1

Understanding Configuration and Build Systems

Page 2: Build Systems

NRCFOSS 2

Overview of the compilation process

If the program consists of a number of source files, building is at least a two-stage process:• Each source file is compiled into a corresponding

object file• Finally, all the objects are linked together and with

any external libraries to create an executableThis simple model fails to generalise: sources may needsome configuring to tailor them to specific platforms. Wewill return to this problem.

Page 3: Build Systems

NRCFOSS 3

Goals and challenges

• Goals:• Modularity• Portability

• Challenges:• It is impossible for the developer to keep track of:

• Large numbers of source files with complicated dependencies

• Peculiarities of diverse target platforms

• How to reconcile these conflicting requirements?

Page 4: Build Systems

NRCFOSS 4

The Answer: Automate!Fundamental principle of program development I:

Cultivate laziness!or

Let the machine do the hard work!

• Enter make. Make• automatically determines which parts of a program need

recompilation, issues commands to recompile them • requires a `makefile' as input, specifying relationships among

sources and commands for compilation• uses makefile database and file modification times to

determine sources that need recompilation

Page 5: Build Systems

NRCFOSS 5

Some common options of make• make [option] ... target ...• make -f file - makefile• make -n - no action• make -C dir - change directory• make -d - debug• make -e - environment• make -i - ignore errors• make -k - continue• make -I dir - include directory• make -t - touch• make -p - print rule database• make -q - question mode

Page 6: Build Systems

NRCFOSS 6

A simple makefile exampleWe will follow the GNU Make syntax throughout.example: main.o foo.o bar.o

gcc -o example main.o foo.o bar.o

main.o: main.c example.hgcc -c main.c

foo.o: foo.c example.hgcc -c foo.c

bar.o: bar.c example.hgcc -c bar.c

clean:-rm *.o example

Page 7: Build Systems

NRCFOSS 7

When make alone is not enough• Different makefiles may be required for each target

platform, and • Complicated makefile syntax is tedious and error-

prone

But,• Many programs are built similarly, and • Makefiles have a reasonably strict grammatical

structure

Therefore, we may invoke Fundamental Principle I and ask, `Why not automate writing makefiles?'

Page 8: Build Systems

NRCFOSS 8

The GNU AutotoolsFundamental principle of program development II:

Cultivate laziness in the user!or

Make the author do the hard work!or

Let the author worry how to make the machine do thehard work!

• Autoconf, Automake and Libtool were designed to solve precisely this problem.

• Autoconf ­ configuration (portability).• Automake ­ dependency tracking, boilerplate, standard

targets• Libtool ­ creating, linking and loading shared and static

libraries.

Page 9: Build Systems

NRCFOSS 9

GNU Autotools

• A potted history of the autotools.• Cygnus and GCC configure• Imake• Metaconfig• GNU Autoconf

Result of running autotools: a configure script, a set of makefiles and config.h

Page 10: Build Systems

NRCFOSS 10

Demonstration of Autotools

• Autoconf configures through a set of feature tests

• Macro expansion is the basic technique• Portable Bourne shell scripts implement

tests

Page 11: Build Systems

NRCFOSS 11

How the autotools work together

Author:• Create two input files, configure.ac and• Makefile.am specifying feature tests and makefile

rules.• Create m4 macros and config.h template using

aclocal and autoheader.• Create Makefile.in's using automake.• Create configure and config.h using autoconf.

User:• Run configure, make, make install.

Page 12: Build Systems

NRCFOSS 12

Other helper tools

• m4 - the macro processor• aclocal - provides a bunch of automake

macros• Autoscan - generates basic configure.ac• Autoheader - template for config.h• Autogen - mechanism to generate

repetitive text

Page 13: Build Systems

NRCFOSS 13

Thank you!