Autotools

13
Autotools José Dapena Paz <[email protected]>

description

 

Transcript of Autotools

Page 1: Autotools

AutotoolsJosé Dapena Paz <[email protected]>

Page 2: Autotools

Introduction

Using gcc without help is not very “scalable”

Then we have Makefile.

And this isn't very “scalable”

Then we have autotools.

And this is “too much” scalable.

Page 3: Autotools

Makefilesall: foo

foo: foo.o bar.o baz.oIMPLICIT!!

.c.o: $(CC) $(CFLAGS) -c $< -o $@

.l.c: $(LEX) $< && mv lex.yy.c $@

BE CAREFUL WITH TABS

Page 4: Autotools

Makefiles

OBJECTS = data.o main.o io.oproject1: $(OBJECTS) cc $(OBJECTS) -o project1data.o: data.cmain.o: main.cio.o: io.c

Implicit rules for .o files

Page 5: Autotools

Makefiles

● Default rule: all● Standard cleaning rule: “clean”● Standard tests rule: “make check”● Behavior: check timestamps of files to create

the missing dependencies (only missing).● Special prefixes:

– Silent command: preceed with @

– Ignore error command: preceed with -

Page 6: Autotools

Autotools, what does it add

● Mainly, supports maintaining a structure for different targets.

● Extensibility and macros integration.● Libtool for helping building shared libraries.● Easy i18n and l10n.● But... when we tell “easy” about autotools, it's

really “not damming difficult”.

Page 7: Autotools

What do we need to write?

● Mainly two things:● configure.ac or configure.in: a macro script for detecting

environment (compiler, target, libraries available, etc). This becomes a configure script.

● Makefile.am in every directory. This will be processed to create Makefiles for specific environment.

● How do this work?● We create configure from configure.ac (using autoconf)● We generate Makefile.in from Makefile.am● When we run configure, we create the Makefiles.

Page 8: Autotools

An example of configure.ac

dnl Process this file with autoconf to produce a configure script.AC_INIT(main.c)AM_INIT_AUTOMAKE(foonly, 1.0)AC_PROG_CCAM_PROG_LEXAC_PROG_YACCAC_OUTPUT(Makefile)

The idea is simple. The macros detect things and fill variables with the results.

Page 9: Autotools

An example of Makefile.am

## Makefile.am -- Process this file with.... bin_PROGRAMS = foonlyfoonly_SOURCES = main.c foo.c foo.h nly.c scanner.l parser.yfoonly_LDADD = @LEXLIB@

We specify the result, the sources required to build it, and the shared libraries we need. LEXLIB is a variable obtained in configure script.

Page 10: Autotools

How to process

● configure.ac is created calling aclocal and autoconf.

● Then we can call automake to process Makefiles.

● automake –add-missing will add some common files to the project structure (NEWS, README, Changelog, COPYING, AUTHORS).

Page 11: Autotools

Maintainer mode

● By default, when you use make, autotools structure is not reviewed for new changes.

● You can add macro AM_MAINTAINER_MODE to configure.ac. – This macro adds a –enable-maintainer-mode option

to configure.

– With maintainer mode, every time you run make, it checks for new changes in autotools structure.

Page 12: Autotools

Hints

● In version control only configure.ac and Makefile.am files should be included.

● Maintain the Changelog file (following GNU standards).

● Be careful to write scripts using “standard sh”. For example, conditions evaluated with test, not with [. Goal: portability.

Page 13: Autotools

Parts of a configure.ac:

1.Standard init commands

2.Options available to user

3.Programs required

4.Libraries required

5.Headers

6.Typedefs and structures

7.Functions

8.Output