Autotools
-
Upload
andres-maneiro -
Category
Technology
-
view
314 -
download
0
description
Transcript of Autotools
AutotoolsJosé Dapena Paz <[email protected]>
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.
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
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
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 -
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”.
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.
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.
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.
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).
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.
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.
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