* doc/automake.texi (Releases): Update statistics until 1.9.6.
[automake.git] / doc / automake.texi
blob870869e1637e0014b032d0aaf863c1cfd9375364
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @setchapternewpage off
6 @c %**end of header
8 @include version.texi
10 @copying
12 This manual is for @acronym{GNU} Automake (version @value{VERSION},
13 @value{UPDATED}), a program that creates GNU standards-compliant
14 Makefiles from template files.
16 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
17 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
19 @quotation
20 Permission is granted to copy, distribute and/or modify this document
21 under the terms of the @acronym{GNU} Free Documentation License,
22 Version 1.2 or any later version published by the Free Software
23 Foundation; with no Invariant Sections, with the Front-Cover texts
24 being ``A @acronym{GNU} Manual,'' and with the Back-Cover Texts as in
25 (a) below.  A copy of the license is included in the section entitled
26 ``@acronym{GNU} Free Documentation License.''
28 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and
29 modify this @acronym{GNU} Manual, like @acronym{GNU} software.  Copies
30 published by the Free Software Foundation raise funds for
31 @acronym{GNU} development.''
32 @end quotation
33 @end copying
35 @c info Automake  points to the Automake package's documentation
36 @c info automake  points to the automake script's documentation
37 @c (Autoconf has a similar setup.)
38 @dircategory Software development
39 @direntry
40 * Automake: (automake).         Making GNU standards-compliant Makefiles.
41 @end direntry
43 @dircategory Individual utilities
44 @direntry
45 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4.
46 * automake: (automake)Invoking Automake.        Generating Makefile.in.
47 @end direntry
49 @titlepage
50 @title GNU Automake
51 @subtitle For version @value{VERSION}, @value{UPDATED}
52 @author David MacKenzie
53 @author Tom Tromey
54 @author Alexandre Duret-Lutz
55 @page
56 @vskip 0pt plus 1filll
57 @insertcopying
58 @end titlepage
61 @c We use the following macros to define indices:
62 @c   @cindex   concepts, and anything that does not fit elsewhere
63 @c   @vindex   Makefile variables
64 @c   @trindex  targets
65 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
66 @c   @opindex  tool options
68 @c Define an index of configure macros.
69 @defcodeindex ac
70 @c Define an index of options.
71 @defcodeindex op
72 @c Define an index of targets.
73 @defcodeindex tr
74 @c Define an index of commands.
75 @defcodeindex cm
77 @c Put the macros in the function index.
78 @syncodeindex ac fn
80 @c Put everything else into one index (arbitrarily chosen to be the concept index).
81 @syncodeindex op cp
82 @syncodeindex tr cp
83 @syncodeindex cm cp
85 @ifnottex
86 @node Top
87 @comment  node-name,  next,  previous,  up
88 @top GNU Automake
90 @insertcopying
92 @menu
93 * Introduction::                Automake's purpose
94 * Autotools Introduction::      An Introduction to the Autotools
95 * Generalities::                General ideas
96 * Examples::                    Some example packages
97 * Invoking Automake::           Creating a Makefile.in
98 * configure::                   Scanning configure.ac or configure.in
99 * Directories::                 Declaring subdirectories
100 * Programs::                    Building programs and libraries
101 * Other objects::               Other derived objects
102 * Other GNU Tools::             Other GNU Tools
103 * Documentation::               Building documentation
104 * Install::                     What gets installed
105 * Clean::                       What gets cleaned
106 * Dist::                        What goes in a distribution
107 * Tests::                       Support for test suites
108 * Rebuilding::                  Automatic rebuilding of Makefile
109 * Options::                     Changing Automake's behavior
110 * Miscellaneous::               Miscellaneous rules
111 * Include::                     Including extra files in an Automake template.
112 * Conditionals::                Conditionals
113 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
114 * Cygnus::                      The effect of @option{--cygnus}
115 * Not Enough::                  When Automake is not Enough
116 * Distributing::                Distributing the Makefile.in
117 * API versioning::              About compatibility between Automake versions
118 * Upgrading::                   Upgrading to a Newer Automake Version
119 * FAQ::                         Frequently Asked Questions
120 * History::                     Notes about the history of Automake
121 * Copying This Manual::         How to make copies of this manual
122 * Indices::                     Indices of variables, macros, and concepts
124 @detailmenu
125  --- The Detailed Node Listing ---
127 An Introduction to the Autotools
129 * GNU Build System::            Introducing the GNU Build System
130 * Use Cases::                   Use Cases for the GNU Build System
131 * Why Autotools::               How Autotools Help
132 * Hello World::                 A Small Hello World Package
134 Use Cases for the GNU Build System
136 * Basic Installation::          Common installation procedure
137 * Standard Targets::            A list of standard Makefile targets
138 * Standard Directory Variables::  A list of standard directory variables
139 * Standard Configuration Variables::  Using configuration variables
140 * config.site::                 Using a config.site file
141 * VPATH Builds::                Parallel build trees
142 * Two-Part Install::            Installing data and programs separately
143 * Cross-Compilation::           Building for other architectures
144 * Renaming::                    Renaming programs at install time
145 * DESTDIR::                     Building binary packages with DESTDIR
146 * Preparing Distributions::     Rolling out tarballs
147 * Dependency Tracking::         Automatic dependency tracking
148 * Nested Packages::             The GNU Build Systems can be nested
150 A Small Hello World
152 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
153 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
155 General ideas
157 * General Operation::           General operation of Automake
158 * Strictness::                  Standards conformance checking
159 * Uniform::                     The Uniform Naming Scheme
160 * Canonicalization::            How derived variables are named
161 * User Variables::              Variables reserved for the user
162 * Auxiliary Programs::          Programs automake might require
164 Some example packages
166 * Complete::                    A simple example, start to finish
167 * Hello::                       A classic program
168 * true::                        Building true and false
170 Scanning @file{configure.ac}
172 * Requirements::                Configuration requirements
173 * Optional::                    Other things Automake recognizes
174 * Invoking aclocal::            Auto-generating aclocal.m4
175 * Macros::                      Autoconf macros supplied with Automake
177 Auto-generating aclocal.m4
179 * aclocal options::             Options supported by aclocal
180 * Macro search path::           How aclocal finds .m4 files
181 * Extending aclocal::           Writing your own aclocal macros
182 * Local Macros::                Organizing local macros
183 * Serials::                     Serial lines in Autoconf macros
184 * Future of aclocal::           aclocal's scheduled death
186 Autoconf macros supplied with Automake
188 * Public macros::               Macros that you can use.
189 * Obsolete macros::             Macros that you should stop using.
190 * Private macros::              Macros that you should not use.
192 Directories
194 * Subdirectories::              Building subdirectories recursively
195 * Conditional Subdirectories::  Conditionally not building directories
196 * Alternative::                 Subdirectories without recursion
197 * Subpackages::                 Nesting packages
199 Building Programs and Libraries
201 * A Program::                   Building a program
202 * A Library::                   Building a library
203 * A Shared Library::            Building a Libtool library
204 * Program and Library Variables::  Variables controlling program and
205                                 library builds
206 * Default _SOURCES::            Default source files
207 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
208 * Program variables::           Variables used when building a program
209 * Yacc and Lex::                Yacc and Lex support
210 * C++ Support::                 Compiling C++ sources
211 * Objective C Support::         Compiling Objective C sources
212 * Unified Parallel C Support::  Compiling Unified Parallel C sources
213 * Assembly Support::            Compiling assembly sources
214 * Fortran 77 Support::          Compiling Fortran 77 sources
215 * Fortran 9x Support::          Compiling Fortran 9x sources
216 * Java Support::                Compiling Java sources
217 * Support for Other Languages::  Compiling other languages
218 * ANSI::                        Automatic de-ANSI-fication
219 * Dependencies::                Automatic dependency tracking
220 * EXEEXT::                      Support for executable extensions
222 Building a program
224 * Program Sources::             Defining program sources
225 * Linking::                     Linking with libraries or extra objects
226 * Conditional Sources::         Handling conditional sources
227 * Conditional Programs::        Building program conditionally
229 Building a Shared Library
231 * Libtool Concept::             Introducing Libtool
232 * Libtool Libraries::           Declaring Libtool Libraries
233 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
234 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
235 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
236 * Libtool Modules::             Building Libtool Modules
237 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
238 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
239 * Libtool Issues::              Common Issues Related to Libtool's Use
241 Fortran 77 Support
243 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
244 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
245 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
247 Mixing Fortran 77 With C and C++
249 * How the Linker is Chosen::    Automatic linker selection
251 Fortran 9x Support
253 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
255 Other Derived Objects
257 * Scripts::                     Executable scripts
258 * Headers::                     Header files
259 * Data::                        Architecture-independent data files
260 * Sources::                     Derived sources
262 Built sources
264 * Built sources example::       Several ways to handle built sources.
266 Other GNU Tools
268 * Emacs Lisp::                  Emacs Lisp
269 * gettext::                     Gettext
270 * Libtool::                     Libtool
271 * Java::                        Java
272 * Python::                      Python
274 Building documentation
276 * Texinfo::                     Texinfo
277 * Man pages::                   Man pages
279 Miscellaneous Rules
281 * Tags::                        Interfacing to etags and mkid
282 * Suffixes::                    Handling new file extensions
283 * Multilibs::                   Support for multilibs.
285 When Automake Isn't Enough
287 * Extending::                   Adding new rules or overriding existing ones.
288 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
290 Frequently Asked Questions about Automake
292 * CVS::                         CVS and generated files
293 * maintainer-mode::             missing and AM_MAINTAINER_MODE
294 * wildcards::                   Why doesn't Automake support wildcards?
295 * limitations on file names::   Limitations on source and installed file names
296 * distcleancheck::              Files left in build directory after distclean
297 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
298 * renamed objects::             Why are object files sometimes renamed?
299 * Per-Object Flags::            How to simulate per-object flags?
300 * Multiple Outputs::            Writing rules for tools with many output files
301 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
303 History of Automake
305 * Timeline::                    The Automake story.
306 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
307 * Releases::                    Statistics about Automake Releases
309 Copying This Manual
311 * GNU Free Documentation License::  License for copying this manual
313 Indices
315 * Macro Index::                 Index of Autoconf macros
316 * Variable Index::              Index of Makefile variables
317 * General Index::               General index
319 @end detailmenu
320 @end menu
322 @end ifnottex
325 @node Introduction
326 @chapter Introduction
328 Automake is a tool for automatically generating @file{Makefile.in}s
329 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
330 basically a series of @command{make} variable
331 definitions@footnote{These variables are also called @dfn{make macros}
332 in Make terminology, however in this manual we reserve the term
333 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
334 occasionally.  The generated @file{Makefile.in}s are compliant with
335 the GNU Makefile standards.
337 @cindex GNU Makefile standards
339 The GNU Makefile Standards Document
340 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
341 is long, complicated, and subject to change.  The goal of Automake is to
342 remove the burden of Makefile maintenance from the back of the
343 individual GNU maintainer (and put it on the back of the Automake
344 maintainers).
346 The typical Automake input file is simply a series of variable definitions.
347 Each such file is processed to create a @file{Makefile.in}.  There
348 should generally be one @file{Makefile.am} per directory of a project.
350 @cindex Constraints of Automake
351 @cindex Automake constraints
353 Automake does constrain a project in certain ways; for instance, it
354 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
355 autoconf, The Autoconf Manual}), and enforces certain restrictions on
356 the @file{configure.ac} contents@footnote{Older Autoconf versions used
357 @file{configure.in}.  Autoconf 2.50 and greater promotes
358 @file{configure.ac} over @file{configure.in}.  The rest of this
359 documentation will refer to @file{configure.ac}, but Automake also
360 supports @file{configure.in} for backward compatibility.}.
362 @cindex Automake requirements
363 @cindex Requirements, Automake
365 Automake requires @command{perl} in order to generate the
366 @file{Makefile.in}s.  However, the distributions created by Automake are
367 fully GNU standards-compliant, and do not require @command{perl} in order
368 to be built.
370 @cindex Bugs, reporting
371 @cindex Reporting bugs
372 @cindex E-mail, bug reports
374 Mail suggestions and bug reports for Automake to
375 @email{bug-automake@@gnu.org}.
377 @node Autotools Introduction
378 @chapter An Introduction to the Autotools
380 If you are new to Automake, maybe you know that it is part of a set of
381 tools called @emph{The Autotools}.  Maybe you've already delved into a
382 package full of files named @file{configure}, @file{configure.ac},
383 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
384 some of them claiming to be @emph{generated by} Autoconf or Automake.
385 But the exact purpose of these files and their relations is probably
386 fuzzy.  The goal of this chapter is to introduce you to this machinery,
387 to show you how it works and how powerful it is.  If you've never
388 installed or seen such a package, do not worry: this chapter will walk
389 you through it.
391 If you need some teaching material, more illustrations, or a less
392 @command{automake}-centered continuation, some slides for this
393 introduction are available in Alexandre Duret-Lutz's
394 @uref{http://www-src.lip6.fr/@/~Alexandre.Duret-Lutz/@/autotools.html,
395 Autotools Tutorial}.
396 This chapter is the written version of the first part of his tutorial.
398 @menu
399 * GNU Build System::            Introducing the GNU Build System
400 * Use Cases::                   Use Cases for the GNU Build System
401 * Why Autotools::               How Autotools Help
402 * Hello World::                 A Small Hello World Package
403 @end menu
405 @node GNU Build System
406 @section Introducing the GNU Build System
407 @cindex GNU Build System, introduction
409 It is a truth universally acknowledged, that a developer in
410 possession of a new package, must be in want of a build system.
412 In the Unix world, such a build system is traditionally achieved using
413 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
414 Manual}).  The developer expresses the recipe to build his package in
415 a @file{Makefile}.  This file is a set of rules to build the files in
416 the package.  For instance the program @file{prog} may be built by
417 running the linker on the files @file{main.o}, @file{foo.o}, and
418 @file{bar.o}; the file @file{main.o} may be built by running the
419 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
420 reads @file{Makefile}, checks the existence and modification time of
421 the files mentioned, decides what files need to be built (or rebuilt),
422 and runs the associated commands.
424 When a package needs to be built on a different platform than the one
425 it was developed on, its @file{Makefile} usually needs to be adjusted.
426 For instance the compiler may have another name or require more
427 options.  In 1991, David J. MacKenzie got tired of customizing
428 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
429 handcrafted a little shell script called @file{configure} to
430 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
431 autoconf, The Autoconf Manual}).  Compiling his package was now
432 as simple as running @code{./configure && make}.
434 @cindex GNU Coding Standards
436 Today this process has been standardized in the GNU project.  The GNU
437 Coding Standards (@pxref{Managing Releases, The Release Process, ,
438 standards, The GNU Coding Standards}) explains how each package of the
439 GNU project should have a @file{configure} script, and the minimal
440 interface it should have.  The @file{Makefile} too should follow some
441 established conventions.  The result?  A unified build system that
442 makes all packages almost indistinguishable by the installer.  In its
443 simplest scenario, all the installer has to do is to unpack the
444 package, run @code{./configure && make && make install}, and repeat
445 with the next package to install.
447 We call this build system the @dfn{GNU Build System}, since it was
448 grown out of the GNU project.  However it is used by a vast number of
449 other packages: following any existing convention has its advantages.
451 @cindex Autotools, introduction
453 The Autotools are tools that will create a GNU Build System for your
454 package.  Autoconf mostly focuses on @file{configure} and Automake on
455 @file{Makefile}s.  It is entirely possible to create a GNU Build
456 System without the help of these tools.  However it is rather
457 burdensome and error-prone.  We will discuss this again after some
458 illustration of the GNU Build System in action.
460 @node Use Cases
461 @section Use Cases for the GNU Build System
462 @cindex GNU Build System, use cases
463 @cindex GNU Build System, features
464 @cindex Features of the GNU Build System
465 @cindex Use Cases for the GNU Build System
466 @cindex @file{amhello-1.0.tar.gz}, location
467 @cindex @file{amhello-1.0.tar.gz}, use cases
469 In this section we explore several use cases for the GNU Build System.
470 You can replay all these examples on the @file{amhello-1.0.tar.gz}
471 package distributed with Automake.  If Automake is installed on your
472 system, you should find a copy of this file in
473 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
474 @var{prefix} is the installation prefix specified during configuration
475 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
476 installed by some GNU/Linux distribution it most likely has been set
477 to @file{/usr}).  If you do not have a copy of Automake installed,
478 you can find a copy of this file inside the @file{doc/} directory of
479 the Automake package.
481 Some of the following use cases present features that are in fact
482 extensions to the GNU Build System.  Read: they are not specified by
483 the GNU Coding Standards, but they are nonetheless part of the build
484 system created by the Autotools.  To keep things simple, we do not
485 point out the difference.  Our objective is to show you many of the
486 features that the build system created by the Autotools will offer to
487 you.
489 @menu
490 * Basic Installation::          Common installation procedure
491 * Standard Targets::            A list of standard Makefile targets
492 * Standard Directory Variables::  A list of standard directory variables
493 * Standard Configuration Variables::  Using configuration variables
494 * config.site::                 Using a config.site file
495 * VPATH Builds::                Parallel build trees
496 * Two-Part Install::            Installing data and programs separately
497 * Cross-Compilation::           Building for other architectures
498 * Renaming::                    Renaming programs at install time
499 * DESTDIR::                     Building binary packages with DESTDIR
500 * Preparing Distributions::     Rolling out tarballs
501 * Dependency Tracking::         Automatic dependency tracking
502 * Nested Packages::             The GNU Build Systems can be nested
503 @end menu
505 @node Basic Installation
506 @subsection Basic Installation
507 @cindex Configuration, basics
508 @cindex Installation, basics
509 @cindex GNU Build System, basics
511 The most common installation procedure looks as follows.
513 @example
514 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
515 ~ % @kbd{cd amhello-1.0}
516 ~/amhello-1.0 % @kbd{./configure}
517 @dots{}
518 config.status: creating Makefile
519 config.status: creating src/Makefile
520 @dots{}
521 ~/amhello-1.0 % @kbd{make}
522 @dots{}
523 ~/amhello-1.0 % @kbd{make check}
524 @dots{}
525 ~/amhello-1.0 % @kbd{su}
526 Password:
527 /home/adl/amhello-1.0 # @kbd{make install}
528 @dots{}
529 /home/adl/amhello-1.0 # @kbd{exit}
530 ~/amhello-1.0 % @kbd{make installcheck}
531 @dots{}
532 @end example
534 @cindex Unpacking
536 The user first unpacks the package.  Here, and in the following
537 examples, we will use the non-portable @code{tar zxf} command for
538 simplicity.  On a system without GNU @command{tar} installed, this
539 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
541 The user then enters the newly created directory to run the
542 @file{configure} script.  This script probes the system for various
543 features, and finally creates the @file{Makefile}s.  In this toy
544 example there are only two @file{Makefile}s, but in real-world project
545 there may be many more, usually one @file{Makefile} per directory.
547 It is now possible to run @code{make}.  This will construct all the
548 programs, libraries, and scripts that need to be constructed for the
549 package.  In our example, this compiles the @file{hello} program.
550 All files are constructed in place, in the source tree; we will see
551 later how this can be changed.
553 @code{make check} causes the package's tests to be run.  This step is
554 not mandatory, but it is often good to make sure the programs that
555 have been built behave as they should, before you decide to install
556 them.  Our example does not contain any tests, so running @code{make
557 check} is a no-op.
559 @cindex su, before @code{make install}
560 After everything has been built, and maybe tested, it is time to
561 install it on the system.  That means copying the programs,
562 libraries, header files, scripts, and other data files from the
563 source directory to their final destination on the system.  The
564 command @code{make install} will do that.  However, by default
565 everything will be installed in subdirectories of @file{/usr/local}:
566 binaries will go into @file{/usr/local/bin}, libraries will end up in
567 @file{/usr/local/lib}, etc.  This destination is usually not writable
568 by any user, so we assume that we have to become root before we can
569 run @code{make install}.  In our example, running @code{make install}
570 will copy the program @file{hello} into @file{/usr/local/bin}
571 and @file{README} into @file{/usr/local/share/doc/amhello}.
573 A last and optional step is to run @code{make installcheck}.  This
574 command may run tests on the installed files.  @code{make check} tests
575 the files in the source tree, while @code{make installcheck} tests
576 their installed copies.  The tests run by the latter can be different
577 from those run by the former.  For instance, there are tests that
578 cannot be run in the source tree.  Conversely, some packages are set
579 up so that @code{make installcheck} will run the very same tests as
580 @code{make check}, only on different files (non-installed
581 vs.@: installed).  It can make a difference, for instance when the
582 source tree's layout is different from that of the installation.
583 Furthermore it may help to diagnose an incomplete installation.
585 Presently most packages do not have any @code{installcheck} tests
586 because the existence of @code{installcheck} is little known, and its
587 usefulness is neglected.  Our little toy package is no better: @code{make
588 installcheck} does nothing.
590 @node Standard Targets
591 @subsection Standard @file{Makefile} Targets
593 So far we have come across four ways to run @command{make} in the GNU
594 Build System: @code{make}, @code{make check}, @code{make install}, and
595 @code{make installcheck}.  The words @code{check}, @code{install}, and
596 @code{installcheck}, passed as arguments to @command{make}, are called
597 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
598 @code{all} being the default target in the GNU Build System.
600 Here is a list of the most useful targets that the GNU Coding Standards
601 specify.
603 @table @code
604 @item make all
605 @trindex all
606 Build programs, libraries, documentation, etc.@: (same as @code{make}).
607 @item make install
608 @trindex install
609 Install what needs to be installed, copying the files from the
610 package's tree to system-wide directories.
611 @item make install-strip
612 @trindex install-strip
613 Same as @code{make install}, then strip debugging symbols.  Some
614 users like to trade space for useful bug reports@enddots{}
615 @item make uninstall
616 @trindex uninstall
617 The opposite of @code{make install}: erase the installed files.
618 (This needs to be run from the same build tree that was installed.)
619 @item make clean
620 @trindex clean
621 Erase from the build tree the files built by @code{make all}.
622 @item make distclean
623 @trindex distclean
624 Additionally erase anything @code{./configure} created.
625 @item make check
626 @trindex check
627 Run the test suite, if any.
628 @item make installcheck
629 @trindex installcheck
630 Check the installed programs or libraries, if supported.
631 @item make dist
632 @trindex dist
633 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
634 files.
635 @end table
637 @node Standard Directory Variables
638 @subsection Standard Directory Variables
639 @cindex directory variables
641 The GNU Coding Standards also specify a hierarchy of variables to
642 denote installation directories.  Some of these are:
644 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
645 @headitem Directory variable    @tab Default value
646 @item @code{prefix}              @tab @code{/usr/local}
647 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
648 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
649 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
650 @item @w{@ @ @ @ @dots{}}
651 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
652 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
653 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
654 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
655 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
656 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
657 @item @w{@ @ @dots{}}
658 @end multitable
660 @c We should provide a complete table somewhere, but not here.  The
661 @c complete list of directory variables it too confusing as-is.  It
662 @c requires some explanations that are too complicated for this
663 @c introduction.  Besides listing directories like localstatedir
664 @c would make the explanations in ``Two-Part Install'' harder.
666 Each of these directories has a role which is often obvious from its
667 name.  In a package, any installable file will be installed in one of
668 these directories.  For instance in @code{amhello-1.0}, the program
669 @file{hello} is to be installed in @var{bindir}, the directory for
670 binaries.  The default value for this directory is
671 @file{/usr/local/bin}, but the user can supply a different value when
672 calling @command{configure}.  Also the file @file{README} will be
673 installed into @var{docdir}, which defaults to
674 @file{/usr/local/share/doc/amhello}.
676 @opindex --prefix
678 A user who wishes to install a package on his own account could proceed
679 as follows:
681 @example
682 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
683 @dots{}
684 ~/amhello-1.0 % @kbd{make}
685 @dots{}
686 ~/amhello-1.0 % @kbd{make install}
687 @dots{}
688 @end example
690 This would install @file{~/usr/bin/hello} and
691 @file{~/usr/share/doc/amhello/README}.
693 The list of all such directory options is shown by
694 @code{./configure --help}.
696 @node Standard Configuration Variables
697 @subsection Standard Configuration Variables
698 @cindex configuration variables, overriding
700 The GNU Coding Standards also define a set of standard configuration
701 variables used during the build.  Here are some:
703 @table @asis
704 @item @code{CC}
705 C compiler command
706 @item @code{CFLAGS}
707 C compiler flags
708 @item @code{CXX}
709 C++ compiler command
710 @item @code{CXXFLAGS}
711 C++ compiler flags
712 @item @code{LDFLAGS}
713 linker flags
714 @item @code{CPPFLAGS}
715 C/C++ preprocessor flags
716 @item @dots{}
717 @end table
719 @command{configure} usually does a good job at setting appropriate
720 values for these variables, but there are cases where you may want to
721 override them.  For instance you may have several versions of a
722 compiler installed and would like to use another one, you may have
723 header files installed outside the default search path of the
724 compiler, or even libraries out of the way of the linker.
726 Here is how one would call @command{configure} to force it to use
727 @command{gcc-3} as C compiler, use header files from
728 @file{~/usr/include} when compiling, and libraries from
729 @file{~/usr/lib} when linking.
731 @example
732 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
733 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
734 @end example
736 Again, a full list of these variables appears in the output of
737 @code{./configure --help}.
739 @node config.site
740 @subsection Overriding Default Configuration Setting with @file{config.site}
741 @cindex @file{config.site} example
743 When installing several packages using the same setup, it can be
744 convenient to create a file to capture common settings.
745 If a file named @file{@var{prefix}/share/config.site} exists,
746 @command{configure} will source it at the beginning of its execution.
748 Recall the command from the previous section:
750 @example
751 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
752 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
753 @end example
755 Assuming we are installing many package in @file{~/usr}, and will
756 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
757 @code{LDFLAGS}, we can automate this by creating the following
758 @file{~/usr/share/config.site} file:
760 @example
761 test -z "$CC" && CC=gcc-3
762 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
763 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
764 @end example
766 Now, any time a @file{configure} script is using the @file{~/usr}
767 prefix, it will execute the above @file{config.site} and define
768 these three variables.
770 @example
771 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
772 configure: loading site script /home/adl/usr/share/config.site
773 @dots{}
774 @end example
776 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
777 Manual}, for more information about this feature.
780 @node VPATH Builds
781 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
782 @cindex Parallel build trees
783 @cindex VPATH builds
784 @cindex source tree and build tree
785 @cindex build tree and source tree
786 @cindex trees, source vs.@: build
788 The GNU Build System distinguishes two trees: the source tree, and
789 the build tree.
791 The source tree is rooted in the directory containing
792 @file{configure}.  It contains all the sources files (those that are
793 distributed), and may be arranged using several subdirectories.
795 The build tree is rooted in the directory in which @file{configure}
796 was run, and is populated with all object files, programs, libraries,
797 and other derived files built from the sources (and hence not
798 distributed).  The build tree usually has the same subdirectory layout
799 as the source tree; its subdirectories are created automatically by
800 the build system.
802 If @file{configure} is executed in its own directory, the source and
803 build trees are combined: derived files are constructed in the same
804 directories as their sources.  This was the case in our first
805 installation example (@pxref{Basic Installation}).
807 A common request from users is that they want to confine all derived
808 files to a single directory, to keep their source directories
809 uncluttered.  Here is how we could run @file{configure} to build
810 everything in a subdirectory called @file{build/}.
812 @example
813 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
814 ~ % @kbd{cd amhello-1.0}
815 ~/amhello-1.0 % @kbd{mkdir build && cd build}
816 ~/amhello-1.0/build % @kbd{../configure}
817 @dots{}
818 ~/amhello-1.0/build % @kbd{make}
819 @dots{}
820 @end example
822 These setups, where source and build trees are different, are often
823 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
824 @emph{parallel build} is misleading: the word @emph{parallel} is a
825 reference to the way the build tree shadows the source tree, it is not
826 about some concurrency in the way build commands are run.  For this
827 reason we refer to such setups using the name @emph{VPATH builds} in
828 the sequel.  @emph{VPATH} is the name of the @command{make} feature
829 used by the @file{Makefile}s to allow these builds (@pxref{General
830 Search, , @code{VPATH}: Search Path for All Prerequisites, make, The
831 GNU Make Manual}).
833 @cindex multiple configurations, example
834 @cindex debug build, example
835 @cindex optimized build, example
837 VPATH builds have other interesting uses.  One is to build the same
838 sources with multiple configurations.  For instance:
840 @example
841 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
842 ~ % @kbd{cd amhello-1.0}
843 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
844 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
845 @dots{}
846 ~/amhello-1.0/debug % @kbd{make}
847 @dots{}
848 ~/amhello-1.0/debug % cd ../optim
849 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
850 @dots{}
851 ~/amhello-1.0/optim % @kbd{make}
852 @dots{}
853 @end example
855 With network file systems, a similar approach can be used to build the
856 same sources on different machines.  For instance, suppose that the
857 sources are installed on a directory shared by two hosts: @code{HOST1}
858 and @code{HOST2}, which may be different platforms.
860 @example
861 ~ % @kbd{cd /nfs/src}
862 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
863 @end example
865 On the first host, you could create a local build directory:
866 @example
867 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
868 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
870 [HOST1] /tmp/amh % @kbd{make && sudo make install}
872 @end example
874 @noindent
875 (Here we assume the that installer has configured @command{sudo} so it
876 can execute @code{make install} with root privileges; it is more convenient
877 than using @command{su} like in @ref{Basic Installation}).
879 On the second host, you would do exactly the same, possibly at
880 the same time:
881 @example
882 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
883 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
885 [HOST2] /tmp/amh % @kbd{make && sudo make install}
887 @end example
889 @cindex read-only source tree
890 @cindex source tree, read-only
892 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
893 directory from being read-only.  In fact VPATH builds are also a means
894 of building packages from a read-only medium such as a CD-ROM.  (The
895 FSF used to sell CD-ROM with unpacked source code, before the GNU
896 project grew so big.)
898 @node Two-Part Install
899 @subsection Two-Part Installation
901 In our last example (@pxref{VPATH Builds}), a source tree was shared
902 by two hosts, but compilation and installation were done separately on
903 each host.
905 The GNU Build System also supports networked setups where part of the
906 installed files should be shared amongst multiple hosts.  It does so
907 by distinguishing architecture-dependent files from
908 architecture-independent files, and providing two @file{Makefile}
909 targets to install each of these classes of files.
911 @trindex install-exec
912 @trindex install-data
914 These targets are @code{install-exec} for architecture-dependent files
915 and @code{install-data} for architecture-independent files.
916 The command we used up to now, @code{make install}, can be thought of
917 as a shorthand for @code{make install-exec install-data}.
919 From the GNU Build System point of view, the distinction between
920 architecture-dependent files and architecture-independent files is
921 based exclusively on the directory variable used to specify their
922 installation destination.  In the list of directory variables we
923 provided earlier (@pxref{Standard Directory Variables}), all the
924 variables based on @var{exec-prefix} designate architecture-dependent
925 directories whose files will be installed by @code{make install-exec}.
926 The others designate architecture-independent directories and will
927 serve files installed by @code{make install-data}.  @xref{Install},
928 for more details.
930 Here is how we could revisit our two-host installation example,
931 assuming that (1) we want to install the package directly in
932 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
933 two hosts.
935 On the first host we would run
936 @example
937 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
938 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
940 [HOST1] /tmp/amh % @kbd{make && sudo make install}
942 @end example
944 On the second host, however, we need only install the
945 architecture-specific files.
946 @example
947 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
948 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
950 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
952 @end example
954 In packages that have installation checks, it would make sense to run
955 @code{make installcheck} (@pxref{Basic Installation}) to verify that
956 the package works correctly despite the apparent partial installation.
958 @node Cross-Compilation
959 @subsection Cross-Compilation
960 @cindex cross-compilation
962 To @dfn{cross-compile} is to build on one platform a binary that will
963 run on another platform.  When speaking of cross-compilation, it is
964 important to distinguish between the @dfn{build platform} on which
965 the compilation is performed, and the @dfn{host platform} on which the
966 resulting executable is expected to run.  The following
967 @command{configure} options are used to specify each of them:
969 @table @option
970 @item --build=@var{BUILD}
971 @opindex --build=@var{BUILD}
972 The system on which the package is built.
973 @item --host=@var{HOST}
974 @opindex --host=@var{HOST}
975 The system where built programs and libraries will run.
976 @end table
978 When the @option{--host} is used, @command{configure} will search for
979 the cross-compiling suite for this platform.  Cross-compilation tools
980 commonly have their target architecture as prefix of their name.  For
981 instance my cross-compiler for MinGW32 has its binaries called
982 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
983 @code{i586-mingw32msvc-as}, etc.
985 @cindex MinGW cross-compilation example
986 @cindex cross-compilation example
988 Here is how we could build @code{amhello-1.0} for
989 @code{i586-mingw32msvc} on a GNU/Linux PC.
991 @smallexample
992 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
993 checking for a BSD-compatible install... /usr/bin/install -c
994 checking whether build environment is sane... yes
995 checking for gawk... gawk
996 checking whether make sets $(MAKE)... yes
997 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
998 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
999 checking for C compiler default output file name... a.exe
1000 checking whether the C compiler works... yes
1001 checking whether we are cross compiling... yes
1002 checking for suffix of executables... .exe
1003 checking for suffix of object files... o
1004 checking whether we are using the GNU C compiler... yes
1005 checking whether i586-mingw32msvc-gcc accepts -g... yes
1006 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1007 @dots{}
1008 ~/amhello-1.0 % @kbd{make}
1009 @dots{}
1010 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1011 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1012 @end smallexample
1014 The @option{--host} and @option{--build} options are usually all we
1015 need for cross-compiling.  The only exception is if the package being
1016 built is itself a cross-compiler: we need a third option to specify
1017 its target architecture.
1019 @table @option
1020 @item --target=@var{TARGET}
1021 @opindex --target=@var{TARGET}
1022 When building compiler tools: the system for which the tools will
1023 create output.
1024 @end table
1026 For instance when installing GCC, the GNU Compiler Collection, we can
1027 use @option{--target=@var{TARGET}} to specify that we want to build
1028 GCC as a cross-compiler for @var{TARGET}.  Mixing @option{--build} and
1029 @option{--target}, we can actually cross-compile a cross-compiler;
1030 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1032 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1033 Autoconf Manual}, for more information about these @command{configure}
1034 options.
1036 @node Renaming
1037 @subsection Renaming Programs at Install Time
1038 @cindex Renaming programs
1039 @cindex Transforming program names
1040 @cindex Programs, renaming during installation
1042 The GNU Build System provides means to automatically rename
1043 executables before they are installed.  This is especially convenient
1044 when installing a GNU package on a system that already has a
1045 proprietary implementation you do not want to overwrite.  For instance,
1046 you may want to install GNU @command{tar} as @command{gtar} so you can
1047 distinguish it from your vendor's @command{tar}.
1049 This can be done using one of these three @command{configure} options.
1051 @table @option
1052 @item --program-prefix=@var{PREFIX}
1053 @opindex --program-prefix=@var{PREFIX}
1054 Prepend @var{PREFIX} to installed program names.
1055 @item --program-suffix=@var{SUFFIX}
1056 @opindex --program-suffix=@var{SUFFIX}
1057 Append @var{SUFFIX} to installed program names.
1058 @item --program-transform-name=@var{PROGRAM}
1059 @opindex --program-transform-name=@var{PROGRAM}
1060 Run @code{sed @var{PROGRAM}} on installed program names.
1061 @end table
1063 The following commands would install @file{hello}
1064 as @file{/usr/local/bin/test-hello}, for instance.
1066 @example
1067 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1068 @dots{}
1069 ~/amhello-1.0 % @kbd{make}
1070 @dots{}
1071 ~/amhello-1.0 % @kbd{sudo make install}
1072 @dots{}
1073 @end example
1075 @node DESTDIR
1076 @subsection Building Binary Packages Using DESTDIR
1077 @vindex DESTDIR
1079 The GNU Build System's @code{make install} and @code{make uninstall}
1080 interface does not exactly fit the needs of a system administrator
1081 who has to deploy and upgrade packages on lots of hosts.  In other
1082 words, the GNU Build System does not replace a package manager.
1084 Such package managers usually need to know which files have been
1085 installed by a package, so a mere @code{make install} is
1086 inappropriate.
1088 @cindex Staged installation
1090 The @code{DESTDIR} variable can be used to perform a staged
1091 installation.  The package should be configured as if it was going to
1092 be installed in its final location (e.g., @code{--prefix /usr}), but
1093 when running @code{make install} the @code{DESTDIR} should be set to
1094 the absolute name of a directory in which all the installation will be
1095 diverted.  From this directory it is easy to review which files are
1096 being installed where, and finally copy them to their final location
1097 by any means.
1099 @cindex Binary package
1101 For instance here is how we could create a binary package containing a
1102 snapshot of all the files to be installed.
1104 @example
1105 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1106 @dots{}
1107 ~/amhello-1.0 % @kbd{make}
1108 @dots{}
1109 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1110 @dots{}
1111 ~/amhello-1.0 % @kbd{cd ~/inst}
1112 ~/inst % @kbd{find . -type f -print > ../files.lst}
1113 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../file.lst`}
1114 ./usr/bin/hello
1115 ./usr/share/doc/amhello/README
1116 @end example
1118 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1119 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../file.lst`}
1120 instead of @samp{.} as argument for @command{tar} avoids entries for
1121 each subdirectory in the archive: we would not like @command{tar} to
1122 restore the modification time of @file{/}, @file{/usr/}, etc.)
1124 Note that when building packages for several architectures, it might
1125 be convenient to use @code{make install-data} and @code{make
1126 install-exec} (@pxref{Two-Part Install}) to gather
1127 architecture-independent files in a single package.
1129 @xref{Install}, for more information.
1131 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1132 @c UNINSTALL counterparts.
1134 @node Preparing Distributions
1135 @subsection Preparing Distributions
1136 @cindex Preparing distributions
1137 @cindex Packages, preparation
1138 @cindex Distributions, preparation
1140 We have already mentioned @code{make dist}.  This target collects all
1141 your source files and the necessary parts of the build system to
1142 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1144 @cindex @code{distcheck} better than @code{dist}
1146 Another, more useful command is @code{make distcheck}.  The
1147 @code{distcheck} target constructs
1148 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1149 but it additionally ensures most of the use cases presented so far
1150 work:
1152 @itemize @bullet
1153 @item
1154 It attempts a full compilation of the package (@pxref{Basic
1155 Installation}), unpacking the newly constructed tarball, running
1156 @code{make}, @code{make check}, @code{make install}, as well as
1157 @code{make installcheck}, and even @code{make dist},
1158 @item
1159 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1160 @item
1161 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1162 uninstall} do not omit any file (@pxref{Standard Targets}),
1163 @item
1164 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1165 @end itemize
1167 All of these actions are performed in a temporary subdirectory, so
1168 that no root privileges are required.
1170 Releasing a package that fails @code{make distcheck} means that one of
1171 the scenarios we presented will not work and some users will be
1172 disappointed.  Therefore it is a good practice to release a package
1173 only after a successful @code{make distcheck}.  This of course does
1174 not imply that the package will be flawless, but at least it will
1175 prevent some of the embarrassing errors you may find in packages
1176 released by people who have never heard about @code{distcheck} (like
1177 @code{DESTDIR} not working because of a typo, or a distributed file
1178 being erased by @code{make clean}, or even @code{VPATH} builds not
1179 working).
1181 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1182 @code{make distcheck}.  @xref{Dist}, for more information about
1183 @code{distcheck}.
1185 @node Dependency Tracking
1186 @subsection Automatic Dependency Tracking
1187 @cindex Dependency tracking
1189 Dependency tracking is performed as a side-effect of compilation.
1190 Each time the build system compiles a source file, it computes its
1191 list of dependencies (in C these are the header files included by the
1192 source being compiled).  Later, any time @command{make} is run and a
1193 dependency appears to have changed, the dependent files will be
1194 rebuilt.
1196 When @command{configure} is executed, you can see it probing each
1197 compiler for the dependency mechanism it supports (several mechanisms
1198 can be used):
1200 @example
1201 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1202 @dots{}
1203 checking dependency style of gcc... gcc3
1204 @dots{}
1205 @end example
1207 Because dependencies are only computed as a side-effect of the
1208 compilation, no dependency information exists the first time a package
1209 is built.  This is OK because all the files need to be built anyway:
1210 @code{make} does not have to decide which files need to be rebuilt.
1211 In fact, dependency tracking is completely useless for one-time builds
1212 and there is a @command{configure} option to disable this:
1214 @table @option
1215 @item --disable-dependency-tracking
1216 @opindex --disable-dependency-tracking
1217 Speed up one-time builds.
1218 @end table
1220 Some compilers do not offer any practical way to derive the list of
1221 dependencies as a side-effect of the compilation, requiring a separate
1222 run (maybe of another tool) to compute these dependencies.  The
1223 performance penalty implied my these methods is important enough to
1224 disable them by default.  The option @option{--enable-dependency-tracking}
1225 must be passed to @command{configure} to activate them.
1227 @table @option
1228 @item --enable-dependency-tracking
1229 @opindex --enable-dependency-tracking
1230 Do not reject slow dependency extractors.
1231 @end table
1233 @xref{Dependency Tracking Evolution}, for some discussion about the
1234 different dependency tracking schemes used by Automake over the years.
1236 @node Nested Packages
1237 @subsection Nested Packages
1238 @cindex Nested packages
1239 @cindex Packages, nested
1240 @cindex Subpackages
1242 Although nesting packages isn't something we would recommend to
1243 someone who is discovering the Autotools, it is a nice feature worthy
1244 of mention in this small advertising tour.
1246 Autoconfiscated packages (that means packages whose build system have
1247 been created by Autoconf and friends) can be nested to arbitrary
1248 depth.
1250 A typical setup is that a package A will distribute one of the libraries
1251 it needs in a subdirectory.  This library B is a complete package with
1252 its own GNU Build System.  The @command{configure} script of A will
1253 run the @command{configure} script of B as part of its execution,
1254 building and installing A will also build and install B.  Generating a
1255 distribution for A will also include B.
1257 It is possible to gather several package like this.  GCC is a heavy
1258 user of this feature.  This gives installers a single package to
1259 configure, build and install, while it allows developers to work on
1260 subpackages independently.
1262 When configuring nested packages, the @command{configure} options
1263 given to the top-level @command{configure} are passed recursively to
1264 nested @command{configure}s.  A package that does not understand an
1265 option will ignore it, assuming it is meaningful to some other
1266 package.
1268 @opindex --help=recursive
1270 The command @code{configure --help=recursive} can be used to display
1271 the options supported by all the included packages.
1273 @xref{Subpackages}, for an example setup.
1275 @node Why Autotools
1276 @section How Autotools Help
1277 @cindex Autotools, purpose
1279 There are several reasons why you may not want to implement the GNU
1280 Build System yourself (read: write a @file{configure} script and
1281 @file{Makefile}s yourself).
1283 @itemize @bullet
1284 @item
1285 As we have seen, the GNU Build System has a lot of
1286 features (@pxref{Use Cases}).
1287 Some users may expect features you have not implemented because
1288 you did not need them.
1289 @item
1290 Implementing these features portably is difficult and exhausting.
1291 Think of writing portable shell scripts, and portable
1292 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1293 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1294 convince yourself.
1295 @item
1296 You will have to upgrade your setup to follow changes to the GNU
1297 Coding Standards.
1298 @end itemize
1300 The GNU Autotools take all this burden off your back and provide:
1302 @itemize @bullet
1303 @item
1304 Tools to create a portable, complete, and self-contained GNU Build
1305 System, from simple instructions.
1306 @emph{Self-contained} meaning the resulting build system does not
1307 require the GNU Autotools.
1308 @item
1309 A central place where fixes and improvements are made:
1310 a bug-fix for a portability issue will benefit every package.
1311 @end itemize
1313 Yet there also exist reasons why you may want NOT to use the
1314 Autotools@enddots{} For instance you may be already using (or used to)
1315 another incompatible build system.  Autotools will only be useful if
1316 you do accept the concepts of the GNU Build System.  People who have their
1317 own idea of how a build system should work will feel frustrated by the
1318 Autotools.
1320 @node Hello World
1321 @section A Small Hello World
1322 @cindex Example Hello World
1323 @cindex Hello World example
1324 @cindex @file{amhello-1.0.tar.gz}, creation
1326 In this section we recreate the @file{amhello-1.0} package from
1327 scratch.  The first subsection shows how to call the Autotools to
1328 instantiate the GNU Build System, while the second explains the
1329 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1330 by the Autotools.
1332 @menu
1333 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1334 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
1335 @end menu
1337 @node Creating amhello
1338 @subsection Creating @file{amhello-1.0.tar.gz}
1340 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1341 The package is simple enough so that we will only need to write 5
1342 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1343 that is distributed with Automake if you do not want to write them.)
1345 Create the following files in an empty directory.
1347 @itemize @bullet
1349 @item
1350 @file{src/main.c} is the source file for the @file{hello} program.  We
1351 store it in the @file{src/} subdirectory, because later, when the package
1352 evolves, it will ease the addition of a @file{man/} directory for man
1353 pages, a @file{data/} directory for data files, etc.
1354 @example
1355 ~/amhello % @kbd{cat src/main.c}
1356 #include <config.h>
1357 #include <stdio.h>
1360 main (void)
1362   puts ("Hello World!");
1363   puts ("This is " PACKAGE_STRING ".");
1364   return 0;
1366 @end example
1368 @item
1369 @file{README} contains some very limited documentation for our little
1370 package.
1371 @example
1372 ~/amhello % @kbd{cat README}
1373 This is a demonstration package for GNU Automake.
1374 Type `info Automake' to read the Automake manual.
1375 @end example
1377 @item
1378 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1379 instructions for these two directories.
1381 @example
1382 ~/amhello % @kbd{cat src/Makefile.am}
1383 bin_PROGRAMS = hello
1384 hello_SOURCES = main.c
1385 ~/amhello % @kbd{cat Makefile.am}
1386 SUBDIRS = src
1387 dist_doc_DATA = README
1388 @end example
1390 @item
1391 Finally, @file{configure.ac} contains Autoconf instructions to
1392 create the @command{configure} script.
1394 @example
1395 ~/amhello % @kbd{cat configure.ac}
1396 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1397 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1398 AC_PROG_CC
1399 AC_CONFIG_HEADERS([config.h])
1400 AC_CONFIG_FILES([
1401  Makefile
1402  src/Makefile
1404 AC_OUTPUT
1405 @end example
1406 @end itemize
1408 @cindex @command{autoreconf}, example
1410 Once you have these five files, it is time to run the Autotools to
1411 instantiate the build system.  Do this using the @command{autoreconf}
1412 command as follows:
1414 @example
1415 ~/amhello % @kbd{autoreconf --install}
1416 configure.ac: installing `./install-sh'
1417 configure.ac: installing `./missing'
1418 src/Makefile.am: installing `./depcomp'
1419 @end example
1421 At this point the build system is complete.
1423 In addition to the three scripts mentioned in its output, you can see
1424 that @command{autoreconf} created four other files: @file{configure},
1425 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1426 The latter three files are templates that will be adapted to the
1427 system by @command{configure} under the names @file{config.h},
1428 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1430 @example
1431 ~/amhello % @kbd{./configure}
1432 checking for a BSD-compatible install... /usr/bin/install -c
1433 checking whether build environment is sane... yes
1434 checking for gawk... no
1435 checking for mawk... mawk
1436 checking whether make sets $(MAKE)... yes
1437 checking for gcc... gcc
1438 checking for C compiler default output file name... a.out
1439 checking whether the C compiler works... yes
1440 checking whether we are cross compiling... no
1441 checking for suffix of executables...
1442 checking for suffix of object files... o
1443 checking whether we are using the GNU C compiler... yes
1444 checking whether gcc accepts -g... yes
1445 checking for gcc option to accept ISO C89... none needed
1446 checking for style of include used by make... GNU
1447 checking dependency style of gcc... gcc3
1448 configure: creating ./config.status
1449 config.status: creating Makefile
1450 config.status: creating src/Makefile
1451 config.status: creating config.h
1452 config.status: executing depfiles commands
1453 @end example
1455 @trindex distcheck
1456 @cindex @code{distcheck} example
1458 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1459 being created at the end after @command{configure} has probed the
1460 system.  It is now possible to run all the targets we wish
1461 (@pxref{Standard Targets}).  For instance:
1463 @example
1464 ~/amhello % @kbd{make}
1465 @dots{}
1466 ~/amhello % @kbd{src/hello}
1467 Hello World!
1468 This is amhello 1.0.
1469 ~/amhello % @kbd{make distcheck}
1470 @dots{}
1471 =============================================
1472 amhello-1.0 archives ready for distribution:
1473 amhello-1.0.tar.gz
1474 =============================================
1475 @end example
1477 Note that running @command{autoreconf} is only needed initially when
1478 the GNU Build System does not exist.  When you later change some
1479 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1480 relevant part of the build system will be regenerated automatically
1481 when you execute @command{make}.
1483 @command{autoreconf} is a script that calls @command{autoconf},
1484 @command{automake}, and a bunch of other commands in the right order.
1485 If you are beginning with these tools, it is not important to figure
1486 out in which order all these tools should be invoked and why.  However,
1487 because Autoconf and Automake have separate manuals, the important
1488 point to understand is that @command{autoconf} is in charge of
1489 creating @file{configure} from @file{configure.ac}, while
1490 @command{automake} is in charge of creating @file{Makefile.in}s from
1491 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1492 direct you to the right manual when seeking answers.
1495 @node amhello Explained
1496 @subsection @file{amhello-1.0} Explained
1498 Let us begin with the contents of @file{configure.ac}.
1500 @example
1501 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1502 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1503 AC_PROG_CC
1504 AC_CONFIG_HEADERS([config.h])
1505 AC_CONFIG_FILES([
1506  Makefile
1507  src/Makefile
1509 AC_OUTPUT
1510 @end example
1512 This file is read by both @command{autoconf} (to create
1513 @file{configure.ac}) and @command{automake} (to create the various
1514 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1515 expanded as shell code to finally form the @file{configure} script.
1516 We will not elaborate on the syntax of this file, because the Autoconf
1517 manual has a whole section about it (@pxref{Writing configure.ac, ,
1518 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1520 The macros prefixed with @code{AC_} are Autoconf macros, documented
1521 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1522 Index, autoconf, The Autoconf Manual}).  The macros that start with
1523 @code{AM_} are Automake macros, documented later in this manual
1524 (@pxref{Macro Index}).
1526 The first two lines of @file{configure.ac} initialize Autoconf and
1527 Automake.  @code{AC_INIT} takes in parameters the name of the package,
1528 its version number, and a contact address for bug-reports about the
1529 package (this address is output at the end of @code{./configure
1530 --help}, for instance).  When adapting this setup to your own package,
1531 by all means please do not blindly copy Automake's address: use the
1532 mailing list of your package, or your own mail address.
1534 @opindex -Wall
1535 @opindex -Werror
1536 @opindex foreign
1538 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1539 @command{automake} (@pxref{Options}).  @option{-Wall} and
1540 @option{-Werror} ask @command{automake} to turn on all warnings and
1541 report them as errors.  We are speaking of @strong{Automake} warnings
1542 here, such as dubious instructions in @file{Makefile.am}.  This has
1543 absolutely nothing to do with how the compiler will be called, even
1544 though it may support options with similar names.  Using @option{-Wall
1545 -Werror} is a safe setting when starting to work on a package: you do
1546 not want to miss any issues.  Later you may decide to relax things a
1547 bit.  The @option{foreign} option tells Automake that this package
1548 will not follow the GNU Standards.  GNU packages should always
1549 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1550 etc.  We do not want @command{automake} to complain about these
1551 missing files in our small example.
1553 The @code{AC_PROG_CC} line causes the @command{configure} script to
1554 search for a C compiler and define the variable @code{CC} with its
1555 name.  The @file{src/Makefile.in} file generated by Automake uses the
1556 variable @code{CC} to build @file{hello}, so when @command{configure}
1557 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1558 @code{CC} with the value it has found.  If Automake is asked to create
1559 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1560 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1562 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1563 @command{configure} script to create a @file{config.h} file gathering
1564 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1565 case, the @code{AC_INIT} macro already defined a few of them.  Here
1566 is an excerpt of @file{config.h} after @command{configure} has run:
1568 @smallexample
1569 @dots{}
1570 /* Define to the address where bug reports for this package should be sent. */
1571 #define PACKAGE_BUGREPORT "bug-automake@@gnu.org"
1573 /* Define to the full name and version of this package. */
1574 #define PACKAGE_STRING "amhello 1.0"
1575 @dots{}
1576 @end smallexample
1578 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1579 it can use @code{PACKAGE_STRING}.  In a real-world project,
1580 @file{config.h} can grow really big, with one @samp{#define} per
1581 feature probed on the system.
1583 The @code{AC_CONFIG_FILES} macro declares the list of files that
1584 @command{configure} should create from their @file{*.in} templates.
1585 Automake also scans this list to find the @file{Makefile.am} files it must
1586 process.  (This is important to remember: when adding a new directory
1587 to your project, you should add its @file{Makefile} to this list,
1588 otherwise Automake will never process the new @file{Makefile.am} you
1589 wrote in that directory.)
1591 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1592 produces the part of the script in charge of creating the files
1593 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1595 @cindex @command{autoscan}
1597 When starting a new project, we suggest you start with such a simple
1598 @file{configure.ac}, and gradually add the other tests it requires.
1599 The command @command{autoscan} can also suggest a few of the tests
1600 your package may need (@pxref{autoscan Invocation, , Using
1601 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1602 Autoconf Manual}).
1604 @cindex @file{Makefile.am}, Hello World
1606 We now turn to @file{src/Makefile.am}.  This file contains
1607 Automake instructions to build and install @file{hello}.
1609 @example
1610 bin_PROGRAMS = hello
1611 hello_SOURCES = main.c
1612 @end example
1614 A @file{Makefile.am} has the same syntax as an ordinary
1615 @file{Makefile}.  When @command{automake} processes a
1616 @file{Makefile.am} it copies the entire file into the output
1617 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1618 @command{configure}) but will react to certain variable definitions
1619 by generating some build rules and other variables.
1620 Often @file{Makefile.am}s contain only a list of variable definitions as
1621 above, but they can also contain other variable and rule definitions that
1622 @command{automake} will pass along without interpretation.
1624 Variables that end with @code{_PROGRAMS} are special variables
1625 that list programs that the resulting @file{Makefile} should build.
1626 In Automake speak, this @code{_PROGRAMS} suffix is called a
1627 @dfn{primary}; Automake recognizes other primaries such as
1628 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1629 to different types of files.
1631 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1632 @command{automake} that the resulting programs should be installed in
1633 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1634 to denote destination directories and allow users to customize these
1635 locations (@pxref{Standard Directory Variables}).  Any such directory
1636 variable can be put in front of a primary (omitting the @code{dir}
1637 suffix) to tell @command{automake} where to install the listed files.
1639 Programs need to be built from source files, so for each program
1640 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1641 @command{automake} will look for another variable named
1642 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1643 than one source file: they will all be compiled and linked together.
1645 Automake also knows that source files need to be distributed when
1646 creating a tarball (unlike built programs).  So a side-effect of this
1647 @code{hello_SOURCES} declaration is that @file{main.c} will be
1648 part of the tarball created by @code{make dist}.
1650 Finally here are some explanations regarding the top-level
1651 @file{Makefile.am}.
1653 @example
1654 SUBDIRS = src
1655 dist_doc_DATA = README
1656 @end example
1658 @code{SUBDIRS} is a special variable listing all directories that
1659 @command{make} should recurse into before processing the current
1660 directory.  So this line is responsible for @command{make} building
1661 @file{src/hello} even though we run it from the top-level.  This line
1662 also causes @code{make install} to install @file{src/hello} before
1663 installing @file{README} (not that this order matters).
1665 The line @code{dist_doc_DATA = README} causes @file{README} to be
1666 distributed and installed in @var{docdir}.  Files listed with the
1667 @code{_DATA} primary are not automatically part of the tarball built
1668 with @code{make dist}, so we add the @code{dist_} prefix so they get
1669 distributed.  However, for @file{README} it would not have been
1670 necessary: @command{automake} automatically distributes any
1671 @file{README} file it encounters (the list of other files
1672 automatically distributed is presented by @code{automake --help}).
1673 The only important effect of this second line is therefore to install
1674 @file{README} during @code{make install}.
1677 @node Generalities
1678 @chapter General ideas
1680 The following sections cover a few basic ideas that will help you
1681 understand how Automake works.
1683 @menu
1684 * General Operation::           General operation of Automake
1685 * Strictness::                  Standards conformance checking
1686 * Uniform::                     The Uniform Naming Scheme
1687 * Canonicalization::            How derived variables are named
1688 * User Variables::              Variables reserved for the user
1689 * Auxiliary Programs::          Programs automake might require
1690 @end menu
1693 @node General Operation
1694 @section General Operation
1696 Automake works by reading a @file{Makefile.am} and generating a
1697 @file{Makefile.in}.  Certain variables and rules defined in the
1698 @file{Makefile.am} instruct Automake to generate more specialized code;
1699 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1700 for compiling and linking programs to be generated.
1702 @cindex Non-standard targets
1703 @cindex @code{cvs-dist}, non-standard example
1704 @trindex cvs-dist
1706 The variable definitions and rules in the @file{Makefile.am} are
1707 copied verbatim into the generated file.  This allows you to add
1708 arbitrary code into the generated @file{Makefile.in}.  For instance,
1709 the Automake distribution includes a non-standard rule for the
1710 @code{cvs-dist} target, which the Automake maintainer uses to make
1711 distributions from his source control system.
1713 @cindex GNU make extensions
1715 Note that most GNU make extensions are not recognized by Automake.  Using
1716 such extensions in a @file{Makefile.am} will lead to errors or confusing
1717 behavior.
1719 @cindex Append operator
1720 @cmindex +=
1721 A special exception is that the GNU make append operator, @samp{+=}, is
1722 supported.  This operator appends its right hand argument to the variable
1723 specified on the left.  Automake will translate the operator into
1724 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1726 Automake tries to keep comments grouped with any adjoining rules or
1727 variable definitions.
1729 @cindex Make targets, overriding
1730 @cindex Make rules, overriding
1731 @cindex Overriding make rules
1732 @cindex Overriding make targets
1734 A rule defined in @file{Makefile.am} generally overrides any such
1735 rule of a similar name that would be automatically generated by
1736 @command{automake}.  Although this is a supported feature, it is generally
1737 best to avoid making use of it, as sometimes the generated rules are
1738 very particular.
1740 @cindex Variables, overriding
1741 @cindex Overriding make variables
1743 Similarly, a variable defined in @file{Makefile.am} or
1744 @code{AC_SUBST}ed from @file{configure.ac} will override any
1745 definition of the variable that @command{automake} would ordinarily
1746 create.  This feature is more often useful than the ability to
1747 override a rule.  Be warned that many of the variables generated by
1748 @command{automake} are considered to be for internal use only, and their
1749 names might change in future releases.
1751 @cindex Recursive operation of Automake
1752 @cindex Automake, recursive operation
1753 @cindex Example of recursive operation
1755 When examining a variable definition, Automake will recursively examine
1756 variables referenced in the definition.  For example, if Automake is
1757 looking at the content of @code{foo_SOURCES} in this snippet
1759 @example
1760 xs = a.c b.c
1761 foo_SOURCES = c.c $(xs)
1762 @end example
1764 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1765 contents of @code{foo_SOURCES}.
1767 @cindex @code{##} (special Automake comment)
1768 @cindex Special Automake comment
1769 @cindex Comment, special to Automake
1771 Automake also allows a form of comment that is @emph{not} copied into
1772 the output; all lines beginning with @samp{##} (leading spaces allowed)
1773 are completely ignored by Automake.
1775 It is customary to make the first line of @file{Makefile.am} read:
1777 @cindex Makefile.am, first line
1778 @cindex First line of Makefile.am
1780 @example
1781 ## Process this file with automake to produce Makefile.in
1782 @end example
1784 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1785 @c I don't know quite what to say.
1787 @c FIXME document customary ordering of Makefile.am here!
1790 @node Strictness
1791 @section Strictness
1793 @cindex Non-GNU packages
1795 While Automake is intended to be used by maintainers of GNU packages, it
1796 does make some effort to accommodate those who wish to use it, but do
1797 not want to use all the GNU conventions.
1799 @cindex Strictness, defined
1800 @cindex Strictness, @option{foreign}
1801 @cindex @option{foreign} strictness
1802 @cindex Strictness, @option{gnu}
1803 @cindex @option{gnu} strictness
1804 @cindex Strictness, @option{gnits}
1805 @cindex @option{gnits} strictness
1807 To this end, Automake supports three levels of @dfn{strictness}---the
1808 strictness indicating how stringently Automake should check standards
1809 conformance.
1811 The valid strictness levels are:
1813 @table @option
1814 @item foreign
1815 Automake will check for only those things that are absolutely
1816 required for proper operations.  For instance, whereas GNU standards
1817 dictate the existence of a @file{NEWS} file, it will not be required in
1818 this mode.  The name comes from the fact that Automake is intended to be
1819 used for GNU programs; these relaxed rules are not the standard mode of
1820 operation.
1822 @item gnu
1823 Automake will check---as much as possible---for compliance to the GNU
1824 standards for packages.  This is the default.
1826 @item gnits
1827 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1828 standards}.  These are based on the GNU standards, but are even more
1829 detailed.  Unless you are a Gnits standards contributor, it is
1830 recommended that you avoid this option until such time as the Gnits
1831 standard is actually published (which may never happen).
1832 @end table
1834 @xref{Gnits}, for more information on the precise implications of the
1835 strictness level.
1837 Automake also has a special ``cygnus'' mode that is similar to
1838 strictness but handled differently.  This mode is useful for packages
1839 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
1840 @xref{Cygnus}, for more information on this mode.
1843 @node Uniform
1844 @section The Uniform Naming Scheme
1846 @cindex Uniform naming scheme
1848 Automake variables generally follow a @dfn{uniform naming scheme} that
1849 makes it easy to decide how programs (and other derived objects) are
1850 built, and how they are installed.  This scheme also supports
1851 @command{configure} time determination of what should be built.
1853 @cindex @code{_PROGRAMS} primary variable
1854 @cindex @code{PROGRAMS} primary variable
1855 @cindex Primary variable, @code{PROGRAMS}
1856 @cindex Primary variable, defined
1857 @vindex _PROGRAMS
1859 At @command{make} time, certain variables are used to determine which
1860 objects are to be built.  The variable names are made of several pieces
1861 that are concatenated together.
1863 The piece that tells automake what is being built is commonly called
1864 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1865 list of programs that are to be compiled and linked.
1866 @vindex PROGRAMS
1868 @cindex @code{pkglibdir}, defined
1869 @cindex @code{pkgincludedir}, defined
1870 @cindex @code{pkgdatadir}, defined
1872 @vindex pkglibdir
1873 @vindex pkgincludedir
1874 @vindex pkgdatadir
1876 @cindex @code{PACKAGE}, directory
1877 A different set of names is used to decide where the built objects
1878 should be installed.  These names are prefixes to the primary, and they
1879 indicate which standard directory should be used as the installation
1880 directory.  The standard directory names are given in the GNU standards
1881 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1882 Automake extends this list with @code{pkglibdir}, @code{pkgincludedir},
1883 and @code{pkgdatadir}; these are the same as the non-@samp{pkg}
1884 versions, but with @samp{$(PACKAGE)} appended.  For instance,
1885 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
1887 @cindex @code{EXTRA_}, prepending
1888 For each primary, there is one additional variable named by prepending
1889 @samp{EXTRA_} to the primary name.  This variable is used to list
1890 objects that may or may not be built, depending on what
1891 @command{configure} decides.  This variable is required because Automake
1892 must statically know the entire list of objects that may be built in
1893 order to generate a @file{Makefile.in} that will work in all cases.
1895 @cindex @code{EXTRA_PROGRAMS}, defined
1896 @cindex Example, @code{EXTRA_PROGRAMS}
1897 @cindex @command{cpio} example
1899 For instance, @command{cpio} decides at configure time which programs
1900 should be built.  Some of the programs are installed in @code{bindir},
1901 and some are installed in @code{sbindir}:
1903 @example
1904 EXTRA_PROGRAMS = mt rmt
1905 bin_PROGRAMS = cpio pax
1906 sbin_PROGRAMS = $(MORE_PROGRAMS)
1907 @end example
1909 Defining a primary without a prefix as a variable, e.g.,
1910 @samp{PROGRAMS}, is an error.
1912 Note that the common @samp{dir} suffix is left off when constructing the
1913 variable names; thus one writes @samp{bin_PROGRAMS} and not
1914 @samp{bindir_PROGRAMS}.
1916 Not every sort of object can be installed in every directory.  Automake
1917 will flag those attempts it finds in error.
1918 Automake will also diagnose obvious misspellings in directory names.
1920 @cindex Extending list of installation directories
1921 @cindex Installation directories, extending list
1923 Sometimes the standard directories---even as augmented by
1924 Automake---are not enough.  In particular it is sometimes useful, for
1925 clarity, to install objects in a subdirectory of some predefined
1926 directory.  To this end, Automake allows you to extend the list of
1927 possible installation directories.  A given prefix (e.g., @samp{zar})
1928 is valid if a variable of the same name with @samp{dir} appended is
1929 defined (e.g., @samp{zardir}).
1931 For instance, the following snippet will install @file{file.xml} into
1932 @samp{$(datadir)/xml}.
1934 @example
1935 xmldir = $(datadir)/xml
1936 xml_DATA = file.xml
1937 @end example
1939 @cindex @samp{noinst_} primary prefix, definition
1940 @vindex noinst_
1942 The special prefix @samp{noinst_} indicates that the objects in question
1943 should be built but not installed at all.  This is usually used for
1944 objects required to build the rest of your package, for instance static
1945 libraries (@pxref{A Library}), or helper scripts.
1947 @cindex @samp{check_} primary prefix, definition
1948 @vindex check_
1950 The special prefix @samp{check_} indicates that the objects in question
1951 should not be built until the @samp{make check} command is run.  Those
1952 objects are not installed either.
1954 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
1955 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
1956 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
1957 @vindex PROGRAMS
1958 @vindex LIBRARIES
1959 @vindex LISP
1960 @vindex PYTHON
1961 @vindex JAVA
1962 @vindex SCRIPTS
1963 @vindex DATA
1964 @vindex HEADERS
1965 @vindex MANS
1966 @vindex TEXINFOS
1968 Some primaries also allow additional prefixes that control other
1969 aspects of @command{automake}'s behavior.  The currently defined prefixes
1970 are @samp{dist_}, @samp{nodist_}, and @samp{nobase_}.  These prefixes
1971 are explained later (@pxref{Program and Library Variables}).
1974 @node Canonicalization
1975 @section How derived variables are named
1977 @cindex canonicalizing Automake variables
1979 Sometimes a Makefile variable name is derived from some text the
1980 maintainer supplies.  For instance, a program name listed in
1981 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
1982 variable.  In cases like this, Automake canonicalizes the text, so that
1983 program names and the like do not have to follow Makefile variable naming
1984 rules.  All characters in the name except for letters, numbers, the
1985 strudel (@@), and the underscore are turned into underscores when making
1986 variable references.
1988 For example, if your program is named @file{sniff-glue}, the derived
1989 variable name would be @samp{sniff_glue_SOURCES}, not
1990 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
1991 @file{libmumble++.a} should be listed in the
1992 @samp{libmumble___a_SOURCES} variable.
1994 The strudel is an addition, to make the use of Autoconf substitutions in
1995 variable names less obfuscating.
1998 @node User Variables
1999 @section Variables reserved for the user
2001 @cindex variables, reserved for the user
2002 @cindex user variables
2004 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2005 for the use of the ``user''---the person building the package.  For
2006 instance, @code{CFLAGS} is one such variable.
2008 Sometimes package developers are tempted to set user variables such as
2009 @code{CFLAGS} because it appears to make their job easier.  However,
2010 the package itself should never set a user variable, particularly not
2011 to include switches that are required for proper compilation of the
2012 package.  Since these variables are documented as being for the
2013 package builder, that person rightfully expects to be able to override
2014 any of these variables at build time.
2016 To get around this problem, Automake introduces an automake-specific
2017 shadow variable for each user flag variable.  (Shadow variables are
2018 not introduced for variables like @code{CC}, where they would make no
2019 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2020 user variable's name.  For instance, the shadow variable for
2021 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2022 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2023 files---may adjust these shadow variables however necessary.
2025 @xref{Flag Variables Ordering}, for more discussion about these
2026 variables and how they interact with per-target variables.
2028 @node Auxiliary Programs
2029 @section Programs automake might require
2031 @cindex Programs, auxiliary
2032 @cindex Auxiliary programs
2034 Automake sometimes requires helper programs so that the generated
2035 @file{Makefile} can do its work properly.  There are a fairly large
2036 number of them, and we list them here.
2038 Although all of these files are distributed and installed with
2039 Automake, a couple of them are maintained separately.  The Automake
2040 copies are updated before each release, but we mention the original
2041 source in case you need more recent versions.
2043 @table @code
2044 @item ansi2knr.c
2045 @itemx ansi2knr.1
2046 These two files are used by the automatic de-ANSI-fication support
2047 (@pxref{ANSI}).
2049 @item compile
2050 This is a wrapper for compilers that do not accept options @option{-c}
2051 and @option{-o} at the same time.  It is only used when absolutely
2052 required.  Such compilers are rare.
2054 @item config.guess
2055 @itemx config.sub
2056 These two programs compute the canonical triplets for the given build,
2057 host, or target architecture.  These programs are updated regularly to
2058 support new architectures and fix probes broken by changes in new
2059 kernel versions.  Each new release of Automake comes with up-to-date
2060 copies of these programs.  If your copy of Automake is getting old,
2061 you are encouraged to fetch the latest versions of these files from
2062 @url{http://savannah.gnu.org/cvs/?group=config} before making a
2063 release.
2065 @item config-ml.in
2066 This file is not a program, it is a @file{configure} fragment used for
2067 multilib support (@pxref{Multilibs}).  This file is maintained in the
2068 GCC tree at @url{http://gcc.gnu.org/svn.html}.
2070 @item depcomp
2071 This program understands how to run a compiler so that it will
2072 generate not only the desired output but also dependency information
2073 that is then used by the automatic dependency tracking feature
2074 (@pxref{Dependencies}).
2076 @item elisp-comp
2077 This program is used to byte-compile Emacs Lisp code.
2079 @item install-sh
2080 This is a replacement for the @command{install} program that works on
2081 platforms where @command{install} is unavailable or unusable.
2083 @item mdate-sh
2084 This script is used to generate a @file{version.texi} file.  It examines
2085 a file and prints some date information about it.
2087 @item missing
2088 This wraps a number of programs that are typically only required by
2089 maintainers.  If the program in question doesn't exist,
2090 @command{missing} prints an informative warning and attempts to fix
2091 things so that the build can continue.
2093 @item mkinstalldirs
2094 This script used to be a wrapper around @samp{mkdir -p}, which is not
2095 portable.  Now we prefer to use @samp{install-sh -d} when configure
2096 finds that @samp{mkdir -p} does not work, this makes one less script to
2097 distribute.
2099 For backward compatibility @file{mkinstalldirs} is still used and
2100 distributed when @command{automake} finds it in a package.  But it is no
2101 longer installed automatically, and it should be safe to remove it.
2103 @item py-compile
2104 This is used to byte-compile Python scripts.
2106 @item symlink-tree
2107 This program duplicates a tree of directories, using symbolic links
2108 instead of copying files.  Such operation is performed when building
2109 multilibs (@pxref{Multilibs}).  This file is maintained in the GCC
2110 tree at @url{http://gcc.gnu.org/svn.html}.
2112 @item texinfo.tex
2113 Not a program, this file is required for @samp{make dvi}, @samp{make
2114 ps} and @samp{make pdf} to work when Texinfo sources are in the
2115 package.  The latest version can be downloaded from
2116 @url{http://www.gnu.org/software/texinfo/}.
2118 @item ylwrap
2119 This program wraps @command{lex} and @command{yacc} and ensures that,
2120 for instance, multiple @command{yacc} instances can be invoked in a
2121 single directory in parallel.
2123 @end table
2126 @node Examples
2127 @chapter Some example packages
2129 @menu
2130 * Complete::                    A simple example, start to finish
2131 * Hello::                       A classic program
2132 * true::                        Building true and false
2133 @end menu
2136 @node Complete
2137 @section A simple example, start to finish
2139 @cindex Complete example
2141 Let's suppose you just finished writing @code{zardoz}, a program to make
2142 your head float from vortex to vortex.  You've been using Autoconf to
2143 provide a portability framework, but your @file{Makefile.in}s have been
2144 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2146 @cindex @code{AM_INIT_AUTOMAKE}, example use
2148 The first step is to update your @file{configure.ac} to include the
2149 commands that @command{automake} needs.  The way to do this is to add an
2150 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2152 @example
2153 AC_INIT([zardoz], [1.0])
2154 AM_INIT_AUTOMAKE
2155 @dots{}
2156 @end example
2158 Since your program doesn't have any complicating factors (e.g., it
2159 doesn't use @code{gettext}, it doesn't want to build a shared library),
2160 you're done with this part.  That was easy!
2162 @cindex @command{aclocal} program, introduction
2163 @cindex @file{aclocal.m4}, preexisting
2164 @cindex @file{acinclude.m4}, defined
2166 Now you must regenerate @file{configure}.  But to do that, you'll need
2167 to tell @command{autoconf} how to find the new macro you've used.  The
2168 easiest way to do this is to use the @command{aclocal} program to
2169 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2170 already have an @file{aclocal.m4}, because you had to write some hairy
2171 macros for your program.  The @command{aclocal} program lets you put
2172 your own macros into @file{acinclude.m4}, so simply rename and then
2173 run:
2175 @example
2176 mv aclocal.m4 acinclude.m4
2177 aclocal
2178 autoconf
2179 @end example
2181 @cindex @command{zardoz} example
2183 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2184 Since @code{zardoz} is a user program, you want to install it where the
2185 rest of the user programs go: @code{bindir}.  Additionally,
2186 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2187 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2188 @samp{$(LIBOBJS)}.  So here's what you'd write:
2190 @example
2191 bin_PROGRAMS = zardoz
2192 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2193 zardoz_LDADD = $(LIBOBJS)
2195 info_TEXINFOS = zardoz.texi
2196 @end example
2198 Now you can run @samp{automake --add-missing} to generate your
2199 @file{Makefile.in} and grab any auxiliary files you might need, and
2200 you're done!
2203 @node Hello
2204 @section A classic program
2206 @cindex Example, GNU Hello
2207 @cindex Hello example
2208 @cindex GNU Hello, example
2210 @uref{ftp://prep.ai.mit.edu/pub/gnu/hello-1.3.tar.gz, GNU hello} is
2211 renowned for its classic simplicity and versatility.  This section shows
2212 how Automake could be used with the GNU Hello package.  The examples
2213 below are from the latest beta version of GNU Hello, but with all of the
2214 maintainer-only code stripped out, as well as all copyright comments.
2216 Of course, GNU Hello is somewhat more featureful than your traditional
2217 two-liner.  GNU Hello is internationalized, does option processing, and
2218 has a manual and a test suite.
2220 @cindex @file{configure.ac}, from GNU Hello
2221 @cindex GNU Hello, @file{configure.ac}
2222 @cindex Hello, @file{configure.ac}
2224 Here is the @file{configure.ac} from GNU Hello.
2225 @strong{Please note:} The calls to @code{AC_INIT} and @code{AM_INIT_AUTOMAKE}
2226 in this example use a deprecated syntax.  For the current approach,
2227 see the description of @code{AM_INIT_AUTOMAKE} in @ref{Public macros}.
2229 @c FIXME: This definitely requires an update, e.g., to GNU Hello 2.1.1.
2231 @example
2232 dnl Process this file with autoconf to produce a configure script.
2233 AC_INIT(src/hello.c)
2234 AM_INIT_AUTOMAKE(hello, 1.3.11)
2235 AM_CONFIG_HEADER(config.h)
2237 dnl Set of available languages.
2238 ALL_LINGUAS="de fr es ko nl no pl pt sl sv"
2240 dnl Checks for programs.
2241 AC_PROG_CC
2242 AC_ISC_POSIX
2244 dnl Checks for libraries.
2246 dnl Checks for header files.
2247 AC_STDC_HEADERS
2248 AC_HAVE_HEADERS(string.h fcntl.h sys/file.h sys/param.h)
2250 dnl Checks for library functions.
2251 AC_FUNC_ALLOCA
2253 dnl Check for st_blksize in struct stat
2254 AC_ST_BLKSIZE
2256 dnl internationalization macros
2257 AM_GNU_GETTEXT
2258 AC_OUTPUT([Makefile doc/Makefile intl/Makefile po/Makefile.in \
2259            src/Makefile tests/Makefile tests/hello],
2260    [chmod +x tests/hello])
2261 @end example
2263 The @samp{AM_} macros are provided by Automake (or the Gettext library);
2264 the rest are standard Autoconf macros.
2267 The top-level @file{Makefile.am}:
2269 @example
2270 EXTRA_DIST = BUGS ChangeLog.O
2271 SUBDIRS = doc intl po src tests
2272 @end example
2274 As you can see, all the work here is really done in subdirectories.
2276 The @file{po} and @file{intl} directories are automatically generated
2277 using @command{gettextize}; they will not be discussed here.
2279 @cindex Texinfo file handling example
2280 @cindex Example, handling Texinfo files
2282 In @file{doc/Makefile.am} we see:
2284 @example
2285 info_TEXINFOS = hello.texi
2286 hello_TEXINFOS = gpl.texi
2287 @end example
2289 This is sufficient to build, install, and distribute the GNU Hello
2290 manual.
2292 @cindex Regression test example
2293 @cindex Example, regression test
2295 Here is @file{tests/Makefile.am}:
2297 @example
2298 TESTS = hello
2299 EXTRA_DIST = hello.in testdata
2300 @end example
2302 The script @file{hello} is generated by @command{configure}, and is the
2303 only test case.  @samp{make check} will run this test.
2305 @cindex @code{INCLUDES}, example usage
2306 @vindex INCLUDES
2308 Last we have @file{src/Makefile.am}, where all the real work is done:
2309 @c FIXME: As all the Hello World excerpts in this manual, this
2310 @c shows deprecated features (here: $(INCLUDES)).
2312 @example
2313 bin_PROGRAMS = hello
2314 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
2315 hello_LDADD = $(INTLLIBS) $(ALLOCA)
2316 localedir = $(datadir)/locale
2317 INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\"
2318 @end example
2321 @node true
2322 @section Building true and false
2324 @cindex Example, @command{false} and @command{true}
2325 @cindex @command{false} Example
2326 @cindex @command{true} Example
2328 Here is another, trickier example.  It shows how to generate two
2329 programs (@code{true} and @code{false}) from the same source file
2330 (@file{true.c}).  The difficult part is that each compilation of
2331 @file{true.c} requires different @code{cpp} flags.
2333 @example
2334 bin_PROGRAMS = true false
2335 false_SOURCES =
2336 false_LDADD = false.o
2338 true.o: true.c
2339         $(COMPILE) -DEXIT_CODE=0 -c true.c
2341 false.o: true.c
2342         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2343 @end example
2345 Note that there is no @code{true_SOURCES} definition.  Automake will
2346 implicitly assume that there is a source file named @file{true.c}, and
2347 define rules to compile @file{true.o} and link @file{true}.  The
2348 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2349 will override the Automake generated rule to build @file{true.o}.
2351 @code{false_SOURCES} is defined to be empty---that way no implicit value
2352 is substituted.  Because we have not listed the source of
2353 @file{false}, we have to tell Automake how to link the program.  This is
2354 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2355 variable, holding the dependencies of the @file{false} target will be
2356 automatically generated by Automake from the content of
2357 @code{false_LDADD}.
2359 The above rules won't work if your compiler doesn't accept both
2360 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2361 bogus dependency (to avoid problems with a parallel @command{make}):
2363 @example
2364 true.o: true.c false.o
2365         $(COMPILE) -DEXIT_CODE=0 -c true.c
2367 false.o: true.c
2368         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2369 @end example
2371 Also, these explicit rules do not work if the de-ANSI-fication feature
2372 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
2373 more work:
2375 @example
2376 true_.o: true_.c false_.o
2377         $(COMPILE) -DEXIT_CODE=0 -c true_.c
2379 false_.o: true_.c
2380         $(COMPILE) -DEXIT_CODE=1 -c true_.c && mv true_.o false_.o
2381 @end example
2383 As it turns out, there is also a much easier way to do this same task.
2384 Some of the above techniques are useful enough that we've kept the
2385 example in the manual.  However if you were to build @code{true} and
2386 @code{false} in real life, you would probably use per-program
2387 compilation flags, like so:
2389 @example
2390 bin_PROGRAMS = false true
2392 false_SOURCES = true.c
2393 false_CPPFLAGS = -DEXIT_CODE=1
2395 true_SOURCES = true.c
2396 true_CPPFLAGS = -DEXIT_CODE=0
2397 @end example
2399 In this case Automake will cause @file{true.c} to be compiled twice,
2400 with different flags.  De-ANSI-fication will work automatically.  In
2401 this instance, the names of the object files would be chosen by
2402 automake; they would be @file{false-true.o} and @file{true-true.o}.
2403 (The name of the object files rarely matters.)
2406 @node Invoking Automake
2407 @chapter Creating a @file{Makefile.in}
2409 @cindex Multiple @file{configure.ac} files
2410 @cindex Invoking @command{automake}
2411 @cindex @command{automake}, invoking
2413 To create all the @file{Makefile.in}s for a package, run the
2414 @command{automake} program in the top level directory, with no
2415 arguments.  @command{automake} will automatically find each
2416 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2417 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2418 Note that @command{automake} has a rather simplistic view of what
2419 constitutes a package; it assumes that a package has only one
2420 @file{configure.ac}, at the top.  If your package has multiple
2421 @file{configure.ac}s, then you must run @command{automake} in each
2422 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2423 on Autoconf's @command{autoreconf}, which is able to recurse your
2424 package tree and run @command{automake} where appropriate.)
2426 You can optionally give @command{automake} an argument; @file{.am} is
2427 appended to the argument and the result is used as the name of the
2428 input file.  This feature is generally only used to automatically
2429 rebuild an out-of-date @file{Makefile.in}.  Note that
2430 @command{automake} must always be run from the topmost directory of a
2431 project, even if being used to regenerate the @file{Makefile.in} in
2432 some subdirectory.  This is necessary because @command{automake} must
2433 scan @file{configure.ac}, and because @command{automake} uses the
2434 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2435 behavior in some cases.
2437 @vindex AUTOCONF
2438 Automake will run @command{autoconf} to scan @file{configure.ac} and
2439 its dependencies (i.e., @file{aclocal.m4} and any included file),
2440 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2441 an @env{AUTOCONF} variable in your environment it will be used
2442 instead of @command{autoconf}, this allows you to select a particular
2443 version of Autoconf.  By the way, don't misunderstand this paragraph:
2444 @command{automake} runs @command{autoconf} to @strong{scan} your
2445 @file{configure.ac}, this won't build @file{configure} and you still
2446 have to run @command{autoconf} yourself for this purpose.
2448 @cindex @command{automake} options
2449 @cindex Options, @command{automake}
2450 @cindex Strictness, command line
2452 @command{automake} accepts the following options:
2454 @cindex Extra files distributed with Automake
2455 @cindex Files distributed with Automake
2456 @cindex @file{config.guess}
2458 @table @code
2459 @item -a
2460 @itemx --add-missing
2461 @opindex -a
2462 @opindex --add-missing
2463 Automake requires certain common files to exist in certain situations;
2464 for instance, @file{config.guess} is required if @file{configure.ac} runs
2465 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2466 files (@pxref{Auxiliary Programs}); this option will cause the missing
2467 ones to be automatically added to the package, whenever possible.  In
2468 general if Automake tells you a file is missing, try using this option.
2469 By default Automake tries to make a symbolic link pointing to its own
2470 copy of the missing file; this can be changed with @option{--copy}.
2472 Many of the potentially-missing files are common scripts whose
2473 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2474 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2475 file is considered missing, and where the missing file is added
2476 (@pxref{Optional}).
2478 @item --libdir=@var{dir}
2479 @opindex --libdir
2480 Look for Automake data files in directory @var{dir} instead of in the
2481 installation directory.  This is typically used for debugging.
2483 @item -c
2484 @opindex -c
2485 @itemx --copy
2486 @opindex --copy
2487 When used with @option{--add-missing}, causes installed files to be
2488 copied.  The default is to make a symbolic link.
2490 @item --cygnus
2491 @opindex --cygnus
2492 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2493 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2495 @item -f
2496 @opindex -f
2497 @itemx --force-missing
2498 @opindex --force-missing
2499 When used with @option{--add-missing}, causes standard files to be reinstalled
2500 even if they already exist in the source tree.  This involves removing
2501 the file from the source tree before creating the new symlink (or, with
2502 @option{--copy}, copying the new file).
2504 @item --foreign
2505 @opindex --foreign
2506 Set the global strictness to @option{foreign}.  For more information, see
2507 @ref{Strictness}.
2509 @item --gnits
2510 @opindex --gnits
2511 Set the global strictness to @option{gnits}.  For more information, see
2512 @ref{Gnits}.
2514 @item --gnu
2515 @opindex --gnu
2516 Set the global strictness to @option{gnu}.  For more information, see
2517 @ref{Gnits}.  This is the default strictness.
2519 @item --help
2520 @opindex --help
2521 Print a summary of the command line options and exit.
2523 @item -i
2524 @itemx --ignore-deps
2525 @opindex -i
2526 This disables the dependency tracking feature in generated
2527 @file{Makefile}s; see @ref{Dependencies}.
2529 @item --include-deps
2530 @opindex --include-deps
2531 This enables the dependency tracking feature.  This feature is enabled
2532 by default.  This option is provided for historical reasons only and
2533 probably should not be used.
2535 @item --no-force
2536 @opindex --no-force
2537 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2538 @file{configure.ac}.  This option causes it to only update those
2539 @file{Makefile.in}s that are out of date with respect to one of their
2540 dependents.
2542 @item -o @var{dir}
2543 @itemx --output-dir=@var{dir}
2544 @opindex -o
2545 @opindex --output-dir
2546 Put the generated @file{Makefile.in} in the directory @var{dir}.
2547 Ordinarily each @file{Makefile.in} is created in the directory of the
2548 corresponding @file{Makefile.am}.  This option is deprecated and will be
2549 removed in a future release.
2551 @item -v
2552 @itemx --verbose
2553 @opindex -v
2554 @opindex --verbose
2555 Cause Automake to print information about which files are being read or
2556 created.
2558 @item --version
2559 @opindex --version
2560 Print the version number of Automake and exit.
2562 @item -W CATEGORY
2563 @item --warnings=@var{category}
2564 @opindex -W
2565 @opindex --warnings
2566 Output warnings falling in @var{category}.  @var{category} can be
2567 one of:
2568 @table @code
2569 @item gnu
2570 warnings related to the GNU Coding Standards
2571 (@pxref{Top, , , standards, The GNU Coding Standards}).
2572 @item obsolete
2573 obsolete features or constructions
2574 @item override
2575 user redefinitions of Automake rules or variables
2576 @item portability
2577 portability issues (e.g., use of @command{make} features that are
2578 known to be not portable)
2579 @item syntax
2580 weird syntax, unused variables, typos
2581 @item unsupported
2582 unsupported or incomplete features
2583 @item all
2584 all the warnings
2585 @item none
2586 turn off all the warnings
2587 @item error
2588 treat warnings as errors
2589 @end table
2591 A category can be turned off by prefixing its name with @samp{no-}.  For
2592 instance, @option{-Wno-syntax} will hide the warnings about unused
2593 variables.
2595 The categories output by default are @samp{syntax} and
2596 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2597 are enabled in @option{--gnu} and @option{--gnits} strictness.
2599 @vindex WARNINGS
2600 The environment variable @env{WARNINGS} can contain a comma separated
2601 list of categories to enable.  It will be taken into account before the
2602 command-line switches, this way @option{-Wnone} will also ignore any
2603 warning category enabled by @env{WARNINGS}.  This variable is also used
2604 by other tools like @command{autoconf}; unknown categories are ignored
2605 for this reason.
2607 @end table
2610 @node configure
2611 @chapter Scanning @file{configure.ac}
2613 @cindex @file{configure.ac}, scanning
2614 @cindex Scanning @file{configure.ac}
2616 Automake scans the package's @file{configure.ac} to determine certain
2617 information about the package.  Some @command{autoconf} macros are required
2618 and some variables must be defined in @file{configure.ac}.  Automake
2619 will also use information from @file{configure.ac} to further tailor its
2620 output.
2622 Automake also supplies some Autoconf macros to make the maintenance
2623 easier.  These macros can automatically be put into your
2624 @file{aclocal.m4} using the @command{aclocal} program.
2626 @menu
2627 * Requirements::                Configuration requirements
2628 * Optional::                    Other things Automake recognizes
2629 * Invoking aclocal::            Auto-generating aclocal.m4
2630 * Macros::                      Autoconf macros supplied with Automake
2631 @end menu
2634 @node Requirements
2635 @section Configuration requirements
2637 @cindex Automake requirements
2638 @cindex Requirements of Automake
2640 @acindex AM_INIT_AUTOMAKE
2641 The one real requirement of Automake is that your @file{configure.ac}
2642 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2643 required for proper Automake operation (@pxref{Macros}).
2645 Here are the other macros that Automake requires but which are not run
2646 by @code{AM_INIT_AUTOMAKE}:
2648 @table @code
2649 @item AC_CONFIG_FILES
2650 @itemx AC_OUTPUT
2651 @acindex AC_CONFIG_FILES
2652 @acindex AC_OUTPUT
2653 These two macros are usually invoked as follows near the end of
2654 @file{configure.ac}.
2656 @example
2657 @dots{}
2658 AC_CONFIG_FILES([
2659   Makefile
2660   doc/Makefile
2661   src/Makefile
2662   src/lib/Makefile
2663   @dots{}
2665 AC_OUTPUT
2666 @end example
2668 Automake uses these to determine which files to create (@pxref{Output, ,
2669 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2670 is considered to be an Automake generated @file{Makefile} if there
2671 exists a file with the same name and the @file{.am} extension appended.
2672 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2673 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2675 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2677 @example
2678 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2679 @end example
2681 @noindent
2682 @command{automake} will generate the first @file{.in} input file for
2683 which a @file{.am} file exists.  If no such file exists the output
2684 file is not considered to be Automake generated.
2686 Files created by @code{AC_CONFIG_FILES}, be they Automake
2687 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2688 Their inputs are automatically distributed, except for inputs that
2689 turn out the be outputs of prior @code{AC_CONFIG_FILES} commands.
2690 Finally, rebuild rules are generated in the Automake @file{Makefile}
2691 existing in the subdirectory of the output file, if there is one, or
2692 in the top-level @file{Makefile} otherwise.
2694 The above machinery (cleaning, distributing, and rebuilding) works
2695 fine if the @code{AC_CONFIG_FILES} specifications contain only
2696 literals.  If part of the specification uses shell variables,
2697 @command{automake} will not be able to fulfill this setup, and you will
2698 have to complete the missing bits by hand.  For instance, on
2700 @example
2701 file=input
2702 @dots{}
2703 AC_CONFIG_FILES([output:$file],, [file=$file])
2704 @end example
2706 @noindent
2707 @command{automake} will output rules to clean @file{output}, and
2708 rebuild it.  However the rebuild rule will not depend on @file{input},
2709 and this file will not be distributed either.  (You must add
2710 @samp{EXTRA_DIST = input} to your @file{Makefile} if @file{input} is a
2711 source file.)
2713 Similarly
2715 @example
2716 file=output
2717 file2=out:in
2718 @dots{}
2719 AC_CONFIG_FILES([$file:input],, [file=$file])
2720 AC_CONFIG_FILES([$file2],, [file2=$file2])
2721 @end example
2723 @noindent
2724 will only cause @file{input} to be distributed.  No file will be
2725 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2726 yourself), and no rebuild rule will be output.
2728 Obviously @command{automake} cannot guess what value @samp{$file} is
2729 going to hold later when @file{configure} is run, and it cannot use
2730 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2731 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2732 that is compatible with @command{make}'s syntax) and furthermore use
2733 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2734 @file{Makefile}, then @command{automake} will be able to use
2735 @samp{$@{file@}} to generate all these rules.  For instance, here is
2736 how the Automake package itself generates versioned scripts for its
2737 test suite:
2739 @example
2740 AC_SUBST([APIVERSION], @dots{})
2741 @dots{}
2742 AC_CONFIG_FILES(
2743   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2744   [chmod +x tests/aclocal-$@{APIVERSION@}],
2745   [APIVERSION=$APIVERSION])
2746 AC_CONFIG_FILES(
2747   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2748   [chmod +x tests/automake-$@{APIVERSION@}])
2749 @end example
2751 @noindent
2752 Here cleaning, distributing, and rebuilding are done automatically,
2753 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2755 Note that you should not use shell variables to declare
2756 @file{Makefile} files for which @command{automake} must create
2757 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2758 @command{automake} needs to know the file name when it runs in order
2759 to check whether @file{Makefile.am} exists.  (In the very hairy case
2760 that your setup requires such use of variables, you will have to tell
2761 Automake which @file{Makefile.in}s to generate on the command-line.)
2763 To summarize:
2764 @itemize @bullet
2765 @item
2766 Use literals for @file{Makefile}s, and for other files whenever possible.
2767 @item
2768 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2769 for files that @command{automake} should ignore.
2770 @item
2771 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2772 that @command{automake} should not ignore.
2773 @end itemize
2775 @end table
2778 @node Optional
2779 @section Other things Automake recognizes
2781 @cindex Macros Automake recognizes
2782 @cindex Recognized macros by Automake
2784 Every time Automake is run it calls Autoconf to trace
2785 @file{configure.ac}.  This way it can recognize the use of certain
2786 macros and tailor the generated @file{Makefile.in} appropriately.
2787 Currently recognized macros and their effects are:
2789 @ftable @code
2790 @item AC_CANONICAL_BUILD
2791 @itemx AC_CANONICAL_HOST
2792 @itemx AC_CANONICAL_TARGET
2793 @vindex build_triplet
2794 @vindex host_triplet
2795 @vindex target_triplet
2796 Automake will ensure that @file{config.guess} and @file{config.sub}
2797 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2798 @code{host_triplet} and @code{target_triplet} are introduced.  See
2799 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2800 The Autoconf Manual}.
2802 @item AC_CONFIG_AUX_DIR
2803 Automake will look for various helper scripts, such as
2804 @file{install-sh}, in the directory named in this macro invocation.
2805 @c This list is accurate relative to version 1.8
2806 (The full list of scripts is: @file{config.guess}, @file{config.sub},
2807 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
2808 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
2809 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
2810 scripts are always searched for; some scripts will only be sought if the
2811 generated @file{Makefile.in} requires them.
2813 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2814 their standard locations.  For @file{mdate-sh},
2815 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2816 source directory corresponding to the current @file{Makefile.am}.  For
2817 the rest, the standard location is the first one of @file{.}, @file{..},
2818 or @file{../..} (relative to the top source directory) that provides any
2819 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2820 autoconf, The Autoconf Manual}.
2822 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2823 distributed, even if there is no @file{Makefile.am} in this directory.
2825 @item AC_CONFIG_LIBOBJ_DIR
2826 Automake will require the sources file declared with
2827 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2828 macro.
2830 @item AC_CONFIG_HEADERS
2831 Automake will generate rules to rebuild these headers.  Older versions
2832 of Automake required the use of @code{AM_CONFIG_HEADER}
2833 (@pxref{Macros}); this is no longer the case today.
2835 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2836 specification using shell variables will be ignored as far as
2837 cleaning, distributing, and rebuilding is concerned.
2839 @item AC_CONFIG_LINKS
2840 Automake will generate rules to remove @file{configure} generated
2841 links on @samp{make distclean} and to distribute named source files as
2842 part of @samp{make dist}.
2844 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2845 specification using shell variables will be ignored as far as cleaning
2846 and distributing is concerned.  (There is no rebuild rules for links.)
2848 @item AC_LIBOBJ
2849 @itemx AC_LIBSOURCE
2850 @itemx AC_LIBSOURCES
2851 @vindex LIBOBJS
2852 Automake will automatically distribute any file listed in
2853 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2855 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2856 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2857 @file{file.c} will be distributed automatically by Automake.  This
2858 encompasses many macros like @code{AC_FUNC_ALLOCA},
2859 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2861 By the way, direct assignments to @code{LIBOBJS} are no longer
2862 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2863 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2864 autoconf, The Autoconf Manual}.
2866 @item AC_PROG_RANLIB
2867 This is required if any libraries are built in the package.
2868 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2869 Autoconf Manual}.
2871 @item AC_PROG_CXX
2872 This is required if any C++ source is included.  @xref{Particular
2873 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2875 @item AC_PROG_OBJC
2876 This is required if any Objective C source is included.  @xref{Particular
2877 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2879 @item AC_PROG_F77
2880 This is required if any Fortran 77 source is included.  This macro is
2881 distributed with Autoconf version 2.13 and later.  @xref{Particular
2882 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2884 @item AC_F77_LIBRARY_LDFLAGS
2885 This is required for programs and shared libraries that are a mixture of
2886 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
2887 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
2889 @item AC_PROG_FC
2890 This is required if any Fortran 90/95 source is included.  This macro is
2891 distributed with Autoconf version 2.58 and later.  @xref{Particular
2892 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2894 @item AC_PROG_LIBTOOL
2895 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
2896 Introduction, libtool, The Libtool Manual}).
2898 @item AC_PROG_YACC
2899 @vindex YACC
2900 If a Yacc source file is seen, then you must either use this macro or
2901 define the variable @code{YACC} in @file{configure.ac}.  The former is
2902 preferred (@pxref{Particular Programs, , Particular Program Checks,
2903 autoconf, The Autoconf Manual}).
2905 @item AC_PROG_LEX
2906 If a Lex source file is seen, then this macro must be used.
2907 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2908 Autoconf Manual}.
2910 @item AC_REQUIRE_AUX_FILE
2911 @command{automake} will ensure each file for which this macro is
2912 called exists in the aux directory, and will complain otherwise.  It
2913 will also automatically distribute the file.  This macro should be
2914 used by third-party Autoconf macros that requires some supporting
2915 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
2916 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
2917 The Autoconf Manual}.
2919 @item AC_SUBST
2920 The first argument is automatically defined as a variable in each
2921 generated @file{Makefile.in}.  @xref{Setting Output Variables, , Setting
2922 Output Variables, autoconf, The Autoconf Manual}.
2924 If the Autoconf manual says that a macro calls @code{AC_SUBST} for
2925 @var{var}, or defines the output variable @var{var} then @var{var} will
2926 be defined in each @file{Makefile.in} generated by Automake.
2927 E.g.@: @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and @code{X_LIBS}, so
2928 you can use these variables in any @file{Makefile.am} if
2929 @code{AC_PATH_XTRA} is called.
2931 @item AM_C_PROTOTYPES
2932 This is required when using automatic de-ANSI-fication; see @ref{ANSI}.
2934 @item AM_GNU_GETTEXT
2935 This macro is required for packages that use GNU gettext
2936 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
2937 this macro it ensures that the package meets some of gettext's
2938 requirements.
2940 @item AM_MAINTAINER_MODE
2941 @opindex --enable-maintainer-mode
2942 This macro adds a @option{--enable-maintainer-mode} option to
2943 @command{configure}.  If this is used, @command{automake} will cause
2944 ``maintainer-only'' rules to be turned off by default in the
2945 generated @file{Makefile.in}s.  This macro defines the
2946 @code{MAINTAINER_MODE} conditional, which you can use in your own
2947 @file{Makefile.am}.  @xref{maintainer-mode}.
2949 @item m4_include
2950 Files included by @file{configure.ac} using this macro will be
2951 detected by Automake and automatically distributed.  They will also
2952 appear as dependencies in @file{Makefile} rules.
2954 @code{m4_include} is seldom used by @file{configure.ac} authors, but
2955 can appear in @file{aclocal.m4} when @command{aclocal} detects that
2956 some required macros come from files local to your package (as opposed
2957 to macros installed in a system-wide directory, @pxref{Invoking
2958 aclocal}).
2960 @end ftable
2963 @node Invoking aclocal
2964 @section Auto-generating aclocal.m4
2966 @cindex Invoking @command{aclocal}
2967 @cindex @command{aclocal}, Invoking
2969 Automake includes a number of Autoconf macros that can be used in
2970 your package (@pxref{Macros}); some of them are actually required by
2971 Automake in certain situations.  These macros must be defined in your
2972 @file{aclocal.m4}; otherwise they will not be seen by
2973 @command{autoconf}.
2975 The @command{aclocal} program will automatically generate
2976 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
2977 This provides a convenient way to get Automake-provided macros,
2978 without having to search around.  The @command{aclocal} mechanism
2979 allows other packages to supply their own macros (@pxref{Extending
2980 aclocal}).  You can also use it to maintain your own set of custom
2981 macros (@pxref{Local Macros}).
2983 At startup, @command{aclocal} scans all the @file{.m4} files it can
2984 find, looking for macro definitions (@pxref{Macro search path}).  Then
2985 it scans @file{configure.ac}.  Any mention of one of the macros found
2986 in the first step causes that macro, and any macros it in turn
2987 requires, to be put into @file{aclocal.m4}.
2989 @emph{Putting} the file that contains the macro definition into
2990 @file{aclocal.m4} is usually done by copying the entire text of this
2991 file, including unused macro definitions as well as both @samp{#} and
2992 @samp{dnl} comments.  If you want to make a comment that will be
2993 completely ignored by @command{aclocal}, use @samp{##} as the comment
2994 leader.
2996 When a file selected by @command{aclocal} is located in a subdirectory
2997 specified as a relative search path with @command{aclocal}'s @option{-I}
2998 argument, @command{aclocal} assumes the file belongs to the package
2999 and uses @code{m4_include} instead of copying it into
3000 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3001 tracking, and cause the file to be distributed automatically.
3002 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3003 system-wide directory, or via an absolute search path will be copied.
3004 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3005 some relative directory need to be considered outside the package.
3007 The contents of @file{acinclude.m4}, if this file exists, are also
3008 automatically included in @file{aclocal.m4}.  We recommend against
3009 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3011 @vindex AUTOM4TE
3012 @cindex autom4te
3013 While computing @file{aclocal.m4}, @command{aclocal} runs
3014 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3015 autoconf, The Autoconf Manual}) in order to trace the macros that are
3016 really used, and omit from @file{aclocal.m4} all macros that are
3017 mentioned but otherwise unexpanded (this can happen when a macro is
3018 called conditionally).  @command{autom4te} is expected to be in the
3019 @env{PATH}, just as @command{autoconf}.  Its location can be
3020 overridden using the @env{AUTOM4TE} environment variable.
3022 @menu
3023 * aclocal options::             Options supported by aclocal
3024 * Macro search path::           How aclocal finds .m4 files
3025 * Extending aclocal::           Writing your own aclocal macros
3026 * Local Macros::                Organizing local macros
3027 * Serials::                     Serial lines in Autoconf macros
3028 * Future of aclocal::           aclocal's scheduled death
3029 @end menu
3031 @node aclocal options
3032 @subsection aclocal options
3034 @cindex @command{aclocal}, Options
3035 @cindex Options, @command{aclocal}
3037 @command{aclocal} accepts the following options:
3039 @table @code
3040 @item --acdir=@var{dir}
3041 @opindex --acdir
3042 Look for the macro files in @var{dir} instead of the installation
3043 directory.  This is typically used for debugging.
3045 @item --diff[=@var{command}]
3046 @opindex --diff
3047 Run @var{command} on M4 file that would be installed or overwritten
3048 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3049 This option implies @option{--install} and @option{--dry-run}.
3051 @item --dry-run
3052 @opindex --dry-run
3053 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3054 files installed by @option{--install}.
3056 @item --help
3057 @opindex --help
3058 Print a summary of the command line options and exit.
3060 @item -I @var{dir}
3061 @opindex -I
3062 Add the directory @var{dir} to the list of directories searched for
3063 @file{.m4} files.
3065 @item --install
3066 @opindex --install
3067 Install system-wide third-party macros into the first directory
3068 specified with @samp{-I @var{dir}} instead of copying them in the
3069 output file.
3071 @cindex serial number and @option{--install}
3072 When this option is used, and only when this option is used,
3073 @command{aclocal} will also honor @samp{#serial @var{NUMBER}} lines
3074 that appear in macros: an M4 file is ignored if there exists another
3075 M4 file with the same basename and a greater serial number in the
3076 search path (@pxref{Serials}).
3078 @item --force
3079 @opindex --force
3080 Always overwrite the output file.  The default is to overwrite the output
3081 file only when really needed, i.e., when its contents changes or if one
3082 of its dependencies is younger.
3084 This option forces the update of @file{aclocal.m4} (or the file
3085 specified with @file{--output} below) and only this file, it has
3086 absolutely no influence on files that may need to be installed by
3087 @option{--install}.
3089 @item --output=@var{file}
3090 @opindex --output
3091 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3093 @item --print-ac-dir
3094 @opindex --print-ac-dir
3095 Prints the name of the directory that @command{aclocal} will search to
3096 find third-party @file{.m4} files.  When this option is given, normal
3097 processing is suppressed.  This option can be used by a package to
3098 determine where to install a macro file.
3100 @item --verbose
3101 @opindex --verbose
3102 Print the names of the files it examines.
3104 @item --version
3105 @opindex --version
3106 Print the version number of Automake and exit.
3108 @item -W CATEGORY
3109 @item --warnings=@var{category}
3110 @opindex -W
3111 @opindex --warnings
3112 Output warnings falling in @var{category}.  @var{category} can be
3113 one of:
3114 @table @code
3115 @item syntax
3116 dubious syntactic constructs, underquoted macros, unused macros, etc.
3117 @item unsupported
3118 unknown macros
3119 @item all
3120 all the warnings, this is the default
3121 @item none
3122 turn off all the warnings
3123 @item error
3124 treat warnings as errors
3125 @end table
3127 All warnings are output by default.
3129 @vindex WARNINGS
3130 The environment variable @env{WARNINGS} is honored in the same
3131 way as it is for @command{automake} (@pxref{Invoking Automake}).
3133 @end table
3135 @node Macro search path
3136 @subsection Macro search path
3138 @cindex Macro search path
3139 @cindex @command{aclocal} search path
3141 By default, @command{aclocal} searches for @file{.m4} files in the following
3142 directories, in this order:
3144 @table @code
3145 @item @var{acdir-APIVERSION}
3146 This is where the @file{.m4} macros distributed with automake itself
3147 are stored.  @var{APIVERSION} depends on the automake release used;
3148 for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
3150 @item @var{acdir}
3151 This directory is intended for third party @file{.m4} files, and is
3152 configured when @command{automake} itself is built.  This is
3153 @file{@@datadir@@/aclocal/}, which typically
3154 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3155 value of @var{acdir}, use the @option{--print-ac-dir} option
3156 (@pxref{aclocal options}).
3157 @end table
3159 As an example, suppose that @command{automake-1.6.2} was configured with
3160 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3162 @enumerate
3163 @item @file{/usr/local/share/aclocal-1.6/}
3164 @item @file{/usr/local/share/aclocal/}
3165 @end enumerate
3167 As explained in (@pxref{aclocal options}), there are several options that
3168 can be used to change or extend this search path.
3170 @subsubsection Modifying the macro search path: @option{--acdir}
3172 The most erroneous option to modify the search path is
3173 @option{--acdir=@var{dir}}, which changes default directory and
3174 drops the @var{APIVERSION} directory.  For example, if one specifies
3175 @samp{--acdir=/opt/private/}, then the search path becomes:
3177 @enumerate
3178 @item @file{/opt/private/}
3179 @end enumerate
3181 This option, @option{--acdir}, is intended for use by the internal
3182 automake test suite only; it is not ordinarily needed by end-users.
3184 @subsubsection Modifying the macro search path: @samp{-I @var{dir}}
3186 Any extra directories specified using @option{-I} options
3187 (@pxref{aclocal options}) are @emph{prepended} to this search list.  Thus,
3188 @samp{aclocal -I /foo -I /bar} results in the following search path:
3190 @enumerate
3191 @item @file{/foo}
3192 @item @file{/bar}
3193 @item @var{acdir}-@var{APIVERSION}
3194 @item @var{acdir}
3195 @end enumerate
3197 @subsubsection Modifying the macro search path: @file{dirlist}
3198 @cindex @file{dirlist}
3200 There is a third mechanism for customizing the search path.  If a
3201 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3202 contain a list of directory patterns, one per line.  @command{aclocal}
3203 expands these patterns to directory names, and adds them to the search
3204 list @emph{after} all other directories.  @file{dirlist} entries may
3205 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3207 For example, suppose
3208 @file{@var{acdir}/dirlist} contains the following:
3210 @example
3211 /test1
3212 /test2
3213 /test3*
3214 @end example
3216 @noindent
3217 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3218 Then, the search path would be
3220 @c @code looks better than @file here
3221 @enumerate
3222 @item @code{/foo}
3223 @item @code{/bar}
3224 @item @var{acdir}-@var{APIVERSION}
3225 @item @var{acdir}
3226 @item @code{/test1}
3227 @item @code{/test2}
3228 @end enumerate
3230 @noindent
3231 and all directories with path names starting with @code{/test3}.
3233 If the @option{--acdir=@var{dir}} option is used, then @command{aclocal}
3234 will search for the @file{dirlist} file in @var{dir}.  In the
3235 @samp{--acdir=/opt/private/} example above, @command{aclocal} would look
3236 for @file{/opt/private/dirlist}.  Again, however, the @option{--acdir}
3237 option is intended for use by the internal automake test suite only;
3238 @option{--acdir} is not ordinarily needed by end-users.
3240 @file{dirlist} is useful in the following situation: suppose that
3241 @command{automake} version @code{1.6.2} is installed with
3242 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3243 directories are
3245 @c @code looks better than @file here
3246 @enumerate
3247 @item @code{/usr/share/aclocal-1.6/}
3248 @item @code{/usr/share/aclocal/}
3249 @end enumerate
3251 However, suppose further that many packages have been manually
3252 installed on the system, with $prefix=/usr/local, as is typical.  In
3253 that case, many of these ``extra'' @file{.m4} files are in
3254 @file{/usr/local/share/aclocal}.  The only way to force
3255 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3256 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3257 inconvenient.  With @file{dirlist}, one may create a file
3258 @file{/usr/share/aclocal/dirlist} containing only the single line
3260 @example
3261 /usr/local/share/aclocal
3262 @end example
3264 Now, the ``default'' search path on the affected system is
3266 @c @code looks better than @file here
3267 @enumerate
3268 @item @code{/usr/share/aclocal-1.6/}
3269 @item @code{/usr/share/aclocal/}
3270 @item @code{/usr/local/share/aclocal/}
3271 @end enumerate
3273 without the need for @option{-I} options; @option{-I} options can be reserved
3274 for project-specific needs (@file{my-source-dir/m4/}), rather than
3275 using it to work around local system-dependent tool installation
3276 directories.
3278 Similarly, @file{dirlist} can be handy if you have installed a local
3279 copy Automake on your account and want @command{aclocal} to look for
3280 macros installed at other places on the system.
3283 @node Extending aclocal
3284 @subsection Writing your own aclocal macros
3286 @cindex @command{aclocal}, extending
3287 @cindex Extending @command{aclocal}
3289 The @command{aclocal} program doesn't have any built-in knowledge of any
3290 macros, so it is easy to extend it with your own macros.
3292 This can be used by libraries that want to supply their own Autoconf
3293 macros for use by other programs.  For instance, the @command{gettext}
3294 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3295 any package using @command{gettext}.  When the library is installed, it
3296 installs this macro so that @command{aclocal} will find it.
3298 A macro file's name should end in @file{.m4}.  Such files should be
3299 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3301 @example
3302 aclocaldir = $(datadir)/aclocal
3303 aclocal_DATA = mymacro.m4 myothermacro.m4
3304 @end example
3306 @noindent
3307 Please do use @file{$(datadir)/aclocal}, and not something based on
3308 the result of @samp{aclocal --print-ac-dir}.  @xref{Hard-Coded Install
3309 Paths}, for arguments.
3311 A file of macros should be a series of properly quoted
3312 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3313 Autoconf Manual}).  The @command{aclocal} programs also understands
3314 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3315 Autoconf Manual}), so it is safe to put each macro in a separate file.
3316 Each file should have no side effects but macro definitions.
3317 Especially, any call to @code{AC_PREREQ} should be done inside the
3318 defined macro, not at the beginning of the file.
3320 @cindex underquoted @code{AC_DEFUN}
3321 @acindex AC_DEFUN
3322 @acindex AC_PREREQ
3324 Starting with Automake 1.8, @command{aclocal} will warn about all
3325 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3326 lot of people, because @command{aclocal} was not so strict in the past
3327 and many third party macros are underquoted; and we have to apologize
3328 for this temporary inconvenience.  The reason we have to be stricter
3329 is that a future implementation of @command{aclocal} (@pxref{Future of
3330 aclocal}) will have to temporarily include all these third party
3331 @file{.m4} files, maybe several times, including even files that are
3332 not actually needed.  Doing so should alleviate many problems of the
3333 current implementation, however it requires a stricter style from the
3334 macro authors.  Hopefully it is easy to revise the existing macros.
3335 For instance,
3336 @example
3337 # bad style
3338 AC_PREREQ(2.57)
3339 AC_DEFUN(AX_FOOBAR,
3340 [AC_REQUIRE([AX_SOMETHING])dnl
3341 AX_FOO
3342 AX_BAR
3344 @end example
3345 @noindent
3346 should be rewritten as
3347 @example
3348 AC_DEFUN([AX_FOOBAR],
3349 [AC_PREREQ([2.57])dnl
3350 AC_REQUIRE([AX_SOMETHING])dnl
3351 AX_FOO
3352 AX_BAR
3354 @end example
3356 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3357 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
3358 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3359 allows the macro to be redefined or included twice (otherwise this
3360 first argument would be expanded during the second definition).  For
3361 consistency we like to quote even arguments such as @code{2.57} that
3362 do not require it.
3364 If you have been directed here by the @command{aclocal} diagnostic but
3365 are not the maintainer of the implicated macro, you will want to
3366 contact the maintainer of that macro.  Please make sure you have the
3367 last version of the macro and that the problem already hasn't been
3368 reported before doing so: people tend to work faster when they aren't
3369 flooded by mails.
3371 Another situation where @command{aclocal} is commonly used is to
3372 manage macros that are used locally by the package, @ref{Local
3373 Macros}.
3375 @node Local Macros
3376 @subsection Handling Local Macros
3378 Feature tests offered by Autoconf do not cover all needs.  People
3379 often have to supplement existing tests with their own macros, or
3380 with third-party macros.
3382 There are two ways to organize custom macros in a package.
3384 The first possibility (the historical practice) is to list all your
3385 macros in @file{acinclude.m4}.  This file will be included in
3386 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3387 henceforth be visible to @command{autoconf}.  However if it contains
3388 numerous macros, it will rapidly become difficult to maintain, and it
3389 will be almost impossible to share macros between packages.
3391 @vindex ACLOCAL_AMFLAGS
3392 The second possibility, which we do recommend, is to write each macro
3393 in its own file and gather all these files in a directory.  This
3394 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3395 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3396 From the command line, this is done with @samp{aclocal -I m4}.  The
3397 top-level @file{Makefile.am} should also be updated to define
3399 @example
3400 ACLOCAL_AMFLAGS = -I m4
3401 @end example
3403 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3404 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3405 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3406 Using @command{autoreconf} to Update @file{configure} Scripts,
3407 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3408 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3409 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3410 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3411 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3412 the place where Gettext's macros should be installed.  So even if you
3413 do not really care about the rebuild rules, you should define
3414 @code{ACLOCAL_AMFLAGS}.
3416 When @samp{aclocal -I m4} is run, it will build a @file{aclocal.m4}
3417 that @code{m4_include}s any file from @file{m4/} that defines a
3418 required macro.  Macros not found locally will still be searched in
3419 system-wide directories, as explained in @ref{Macro search path}.
3421 Custom macros should be distributed for the same reason that
3422 @file{configure.ac} is: so that other people have all the sources of
3423 your package if they want to work on it.  Actually, this distribution
3424 happens automatically because all @code{m4_include}d files are
3425 distributed.
3427 However there is no consensus on the distribution of third-party
3428 macros that your package may use.  Many libraries install their own
3429 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3430 aclocal}).  For instance, Guile ships with a file called
3431 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3432 be used to define setup compiler and linker flags appropriate for
3433 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3434 cause @command{aclocal} to copy @file{guile.m4} into
3435 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3436 it will not be distributed.  Technically, that means a user who
3437 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3438 This is probably OK, if Guile already is a requirement to build the
3439 package.  However, if Guile is only an optional feature, or if your
3440 package might run on architectures where Guile cannot be installed,
3441 this requirement will hinder development.  An easy solution is to copy
3442 such third-party macros in your local @file{m4/} directory so they get
3443 distributed.
3445 Since Automake 1.10, @command{aclocal} offers an option to copy these
3446 system-wide third-party macros in your local macro directory, solving
3447 the above problem.  Simply use:
3449 @example
3450 ACLOCAL_AMFLAGS = -I m4 --install
3451 @end example
3453 @noindent
3454 With this setup, system-wide macros will be copied to @file{m4/}
3455 the first time you run @command{autoreconf}.  Then the locally
3456 installed macros will have precedence over the system-wide installed
3457 macros each time @command{aclocal} is run again.
3459 One reason why you should keep @option{--install} in the flags even
3460 after the first run is that when you later edit @file{configure.ac}
3461 and depend on a new macro, this macro will be installed in your
3462 @file{m4/} automatically.  Another one is that serial numbers
3463 (@pxref{Serials}) can be used to update the macros in your source tree
3464 automatically when new system-wide versions are installed.  A serial
3465 number should be a single line of the form
3467 @example
3468 #serial @var{NNN}
3469 @end example
3471 @noindent
3472 where @var{NNN} contains only digits and dots.  It should appear in
3473 the M4 file before any macro definition.  It is a good practice to
3474 maintain a serial number for each macro you distribute, even if you do
3475 not use the @option{--install} option of @command{aclocal}: this allows
3476 other people to use it.
3479 @node Serials
3480 @subsection Serial Numbers
3481 @cindex serial numbers in macros
3482 @cindex macro serial numbers
3483 @cindex @code{#serial} syntax
3484 @cindex @command{aclocal} and serial numbers
3486 Because third-party macros defined in @file{*.m4} files are naturally
3487 shared between multiple projects, some people like to version them.
3488 This makes it easier to tell which of two M4 files is newer.  Since at
3489 least 1996, the tradition is to use a @samp{#serial} line for this.
3491 A serial number should be a single line of the form
3493 @example
3494 # serial @var{version}
3495 @end example
3497 @noindent
3498 where @var{version} is a version number containing only digits and
3499 dots.  Usually people use a single integer, and they increment it each
3500 time they change the macro (hence the name of ``serial'').  Such a
3501 line should appear in the M4 file before any macro definition.
3503 The @samp{#} must be the first character on the line,
3504 and it is OK to have extra words after the version, as in
3506 @example
3507 #serial @var{version} @var{garbage}
3508 @end example
3510 Normally these serial numbers are completely ignored by
3511 @command{aclocal} and @command{autoconf}, like any genuine comment.
3512 However when using @command{aclocal}'s @option{--install} feature, these
3513 serial numbers will modify the way @command{aclocal} selects the
3514 macros to install in the package: if two files with the same basename
3515 exists in your search path, and if at least one of them use a
3516 @samp{#serial} line, @command{aclocal} will ignore the file that has
3517 the older @samp{#serial} line (or the file that has none).
3519 Note that a serial number applies to a whole M4 file, not to any macro
3520 it contains.  A file can contains multiple macros, but only one
3521 serial.
3523 Here is a use case that illustrate the use of @option{--install} and
3524 its interaction with serial numbers.  Let's assume we maintain a
3525 package called MyPackage, the @file{configure.ac} of which requires a
3526 third-party macro @code{AX_THIRD_PARTY} defined in
3527 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3529 @example
3530 # serial 1
3531 AC_DEFUN([AX_THIRD_PARTY], [...])
3532 @end example
3534 MyPackage uses an @file{m4/} directory to store local macros as
3535 explained in @ref{Local Macros}, and has
3537 @example
3538 ACLOCAL_AMFLAGS = -I m4 --install
3539 @end example
3541 @noindent
3542 in its top-level @file{Makefile.am}.
3544 Initially the @file{m4/} directory is empty.  The first time we run
3545 @command{autoreconf}, it will fetch the options to pass to
3546 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3547 --install}.  @command{aclocal} will notice that
3549 @itemize @bullet
3550 @item
3551 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3552 @item
3553 No local macros define @code{AX_THIRD_PARTY}
3554 @item
3555 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3556 with serial 1.
3557 @end itemize
3559 @noindent
3560 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3561 and @command{aclocal} was given the @option{--install} option, it will
3562 copy this file in @file{m4/thirdparty.m4}, and output an
3563 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3565 The next time @samp{aclocal -I m4 --install} is run (either via
3566 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3567 rules) something different happens.  @command{aclocal} notices that
3569 @itemize @bullet
3570 @item
3571 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3572 @item
3573 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3574 with serial 1.
3575 @item
3576 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3577 with serial 1.
3578 @end itemize
3580 @noindent
3581 Because both files have the same serial number, @command{aclocal} uses
3582 the first it found in its search path order (@pxref{Macro search
3583 path}).  @command{aclocal} therefore ignores
3584 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3585 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3587 Local directories specified with @option{-I} are always searched before
3588 system-wide directories, so a local file will always be preferred to
3589 the system-wide file in case of equal serial numbers.
3591 Now suppose the system-wide third-party macro is changed.  This can
3592 happen if the package installing this macro is updated.  Let's suppose
3593 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3594 --install} is run the situation is the following:
3596 @itemize @bullet
3597 @item
3598 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3599 @item
3600 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3601 with serial 1.
3602 @item
3603 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3604 with serial 2.
3605 @end itemize
3607 @noindent
3608 When @command{aclocal} sees a greater serial number, it immediately
3609 forgets anything it knows from files that have the same basename and a
3610 smaller serial number.  So after it has found
3611 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3612 @command{aclocal} will proceed as if it had never seen
3613 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3614 to that at the beginning of our example, where no local file defined
3615 the macro.  @command{aclocal} will install the new version of the
3616 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3617 version.  MyPackage just had its macro updated as a side effect of
3618 running @command{aclocal}.
3620 If you are leery of letting @command{aclocal} update your local macro,
3621 you can run @samp{aclocal -I m4 --diff} to review the changes
3622 @samp{aclocal -I m4 --install} would perform on these macros.
3624 Finally, note that the @option{--force} option of @command{aclocal} has
3625 absolutely no effect on the files installed by @option{--install}.  For
3626 instance, if you have modified your local macros, do not expect
3627 @option{--install --force} to replace the local macros by their
3628 system-wide versions.  If you want to do so, simply erase the local
3629 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3632 @node Future of aclocal
3633 @subsection The Future of @command{aclocal}
3634 @cindex @command{aclocal}'s scheduled death
3636 @command{aclocal} is expected to disappear.  This feature really
3637 should not be offered by Automake.  Automake should focus on
3638 generating @file{Makefile}s; dealing with M4 macros really is
3639 Autoconf's job.  That some people install Automake just to use
3640 @command{aclocal}, but do not use @command{automake} otherwise is an
3641 indication of how that feature is misplaced.
3643 The new implementation will probably be done slightly differently.
3644 For instance, it could enforce the @file{m4/}-style layout discussed in
3645 @ref{Local Macros}.
3647 We have no idea when and how this will happen.  This has been
3648 discussed several times in the past, but someone still has to commit
3649 itself to that non-trivial task.
3651 From the user point of view, @command{aclocal}'s removal might turn
3652 out to be painful.  There is a simple precaution that you may take to
3653 make that switch more seamless: never call @command{aclocal} yourself.
3654 Keep this guy under the exclusive control of @command{autoreconf} and
3655 Automake's rebuild rules.  Hopefully you won't need to worry about
3656 things breaking, when @command{aclocal} disappears, because everything
3657 will have been taken care of.  If otherwise you used to call
3658 @command{aclocal} directly yourself or from some script, you will
3659 quickly notice the change.
3661 Many packages come with a script called @file{bootstrap.sh} or
3662 @file{autogen.sh}, that will just call @command{aclocal},
3663 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3664 @command{autoconf}, @command{autoheader}, and @command{automake} in
3665 the right order.  Actually this is precisely what @command{autoreconf}
3666 can do for you.  If your package has such a @file{bootstrap.sh} or
3667 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3668 should simplify its logic a lot (less things to maintain, yum!), it's
3669 even likely you will not need the script anymore, and more to the point
3670 you will not call @command{aclocal} directly anymore.
3672 For the time being, third-party packages should continue to install
3673 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3674 is replaced by another tool it might make sense to rename the
3675 directory, but supporting @file{/usr/share/aclocal/} for backward
3676 compatibility should be really easy provided all macros are properly
3677 written (@pxref{Extending aclocal}).
3681 @node Macros
3682 @section Autoconf macros supplied with Automake
3684 Automake ships with several Autoconf macros that you can use from your
3685 @file{configure.ac}.  When you use one of them it will be included by
3686 @command{aclocal} in @file{aclocal.m4}.
3688 @menu
3689 * Public macros::               Macros that you can use.
3690 * Obsolete macros::             Macros that you should stop using.
3691 * Private macros::              Macros that you should not use.
3692 @end menu
3694 @c consider generating the following subsections automatically from m4 files.
3696 @node Public macros
3697 @subsection Public macros
3699 @table @code
3700 @item AM_C_PROTOTYPES
3701 @acindex AM_C_PROTOTYPES
3702 @vindex ANSI2KNR
3703 @vindex U
3704 Check to see if function prototypes are understood by the compiler.  If
3705 so, define @samp{PROTOTYPES} and set the output variables @code{U} and
3706 @code{ANSI2KNR} to the empty string.  Otherwise, set @code{U} to
3707 @samp{_} and @code{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
3708 values to implement automatic de-ANSI-fication.
3710 @item AM_ENABLE_MULTILIB
3711 @acindex AM_ENABLE_MULTILIB
3712 This is used when a ``multilib'' library is being built.  The first
3713 optional argument is the name of the @file{Makefile} being generated; it
3714 defaults to @samp{Makefile}.  The second option argument is used to find
3715 the top source directory; it defaults to the empty string (generally
3716 this should not be used unless you are familiar with the internals).
3717 @xref{Multilibs}.
3719 @item AM_INIT_AUTOMAKE([OPTIONS])
3720 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
3721 @acindex AM_INIT_AUTOMAKE
3722 Runs many macros required for proper operation of the generated Makefiles.
3724 @vindex AUTOMAKE_OPTIONS
3725 This macro has two forms, the first of which is preferred.
3726 In this form, @code{AM_INIT_AUTOMAKE} is called with a
3727 single argument: a space-separated list of Automake options that should
3728 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3729 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3731 @acindex AC_INIT
3732 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
3733 arguments: the package and the version number.  This form is
3734 obsolete because the @var{package} and @var{version} can be obtained
3735 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
3736 form).
3738 If your @file{configure.ac} has:
3740 @example
3741 AC_INIT([src/foo.c])
3742 AM_INIT_AUTOMAKE([mumble], [1.5])
3743 @end example
3745 @noindent
3746 you can modernize it as follows:
3748 @example
3749 AC_INIT([mumble], [1.5])
3750 AC_CONFIG_SRCDIR([src/foo.c])
3751 AM_INIT_AUTOMAKE
3752 @end example
3754 Note that if you're upgrading your @file{configure.ac} from an earlier
3755 version of Automake, it is not always correct to simply move the
3756 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3757 @code{AC_INIT}, as in the example above.  The first argument to
3758 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3759 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3760 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3761 tarball name from the package name, which should work for most but not
3762 all package names.  (If it doesn't work for yours, you can use the
3763 four-argument form of @code{AC_INIT} to provide the tarball name
3764 explicitly).
3766 @cindex @code{PACKAGE}, prevent definition
3767 @cindex @code{VERSION}, prevent definition
3768 @opindex no-define
3769 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3770 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3771 option, as in:
3772 @example
3773 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3774 @end example
3775 or by passing a third non-empty argument to the obsolete form.
3777 @item AM_PATH_LISPDIR
3778 @acindex AM_PATH_LISPDIR
3779 @vindex EMACS
3780 @vindex lispdir
3781 Searches for the program @command{emacs}, and, if found, sets the
3782 output variable @code{lispdir} to the full path to Emacs' site-lisp
3783 directory.
3785 Note that this test assumes the @command{emacs} found to be a version
3786 that supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other
3787 emacsen can cause this test to hang (some, like old versions of
3788 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3789 exit, which is hardly obvious for a non-emacs user).  In most cases,
3790 however, you should be able to use @kbd{C-c} to kill the test.  In
3791 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3792 environment, or use the @option{--with-lispdir} option to
3793 @command{configure} to explicitly set the correct path (if you're sure
3794 you have an @command{emacs} that supports Emacs Lisp.
3796 @item AM_PROG_AS
3797 @acindex AM_PROG_AS
3798 @vindex CCAS
3799 @vindex CCASFLAGS
3800 Use this macro when you have assembly code in your project.  This will
3801 choose the assembler for you (by default the C compiler) and set
3802 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
3804 @item AM_PROG_CC_C_O
3805 @acindex AM_PROG_CC_C_O
3806 @acindex AC_PROG_CC_C_O
3807 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
3808 the manner required by automake.  You must use this instead of
3809 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
3810 using per-target flags or subdir-objects with C sources.
3812 @item AM_PROG_LEX
3813 @acindex AM_PROG_LEX
3814 @acindex AC_PROG_LEX
3815 @cindex HP-UX 10, @command{lex} problems
3816 @cindex @command{lex} problems with HP-UX 10
3817 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
3818 Program Checks, autoconf, The Autoconf Manual}), but uses the
3819 @command{missing} script on systems that do not have @command{lex}.
3820 HP-UX 10 is one such system.
3822 @item AM_PROG_GCJ
3823 @acindex AM_PROG_GCJ
3824 @vindex GCJ
3825 @vindex GCJFLAGS
3826 This macro finds the @command{gcj} program or causes an error.  It sets
3827 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
3828 GNU Compiler Collection.
3830 @item AM_PROG_UPC([@var{compiler-search-list}])
3831 @acindex AM_PROG_UPC
3832 @vindex UPC
3833 Find a compiler for Unified Parallel C and define the @code{UPC}
3834 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
3835 This macro will abort @command{configure} if no Unified Parallel C
3836 compiler is found.
3838 @item AM_WITH_DMALLOC
3839 @acindex AM_WITH_DMALLOC
3840 @cindex @command{dmalloc}, support for
3841 @vindex WITH_DMALLOC
3842 @opindex --with-dmalloc
3843 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
3844 the user runs @command{configure} with @option{--with-dmalloc}, then
3845 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
3847 @item AM_WITH_REGEX
3848 @acindex AM_WITH_REGEX
3849 @vindex WITH_REGEX
3850 @opindex --with-regex
3851 @cindex regex package
3852 @cindex rx package
3853 Adds @option{--with-regex} to the @command{configure} command line.  If
3854 specified (the default), then the @samp{regex} regular expression
3855 library is used, @file{regex.o} is put into @code{LIBOBJS}, and
3856 @code{WITH_REGEX} is defined.  If @option{--without-regex} is given, then
3857 the @code{rx} regular expression library is used, and @file{rx.o} is put
3858 into @code{LIBOBJS}.
3860 @end table
3863 @node Obsolete macros
3864 @subsection Obsolete macros
3865 @cindex obsolete macros
3866 @cindex autoupdate
3868 Although using some of the following macros was required in past
3869 releases, you should not used any of them in new code.  Running
3870 @command{autoupdate} should adjust your @file{configure.ac}
3871 automatically (@pxref{autoupdate Invocation, , Using
3872 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
3873 Autoconf Manual}).
3875 @table @code
3876 @item AM_CONFIG_HEADER
3877 @acindex AM_CONFIG_HEADER
3878 Automake will generate rules to automatically regenerate the config
3879 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
3880 today (@pxref{Optional}).
3882 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3883 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3884 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
3885 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
3886 found in @file{<termios.h>}.  This macro is obsolete, you should
3887 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
3889 @item AM_PROG_MKDIR_P
3890 @acindex AM_PROG_MKDIR_P
3891 @cindex @code{mkdir -p}, macro check
3892 @vindex MKDIR_P
3893 @vindex mkdir_p
3895 From Automake 1.8 to 1.9.6 this macro used to define the output
3896 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install.sh
3897 -d}, or @code{mkinstalldirs}.
3899 Nowadays Autoconf provides a similar functionality with
3900 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
3901 Program Checks, autoconf, The Autoconf Manual}), however this defines
3902 the output variable @code{MKDIR_P} instead.  Therefore
3903 @code{AM_PROG_MKDIR_P} has been rewritten as a thin wrapper around
3904 @code{AC_PROG_MKDIR_P} to define @code{mkdir_p} to the same value as
3905 @code{MKDIR_P} for backward compatibility.
3907 If you are using Automake, there is normally no reason to call this
3908 macro, because @code{AM_INIT_AUTOMAKE} already does so.  However, make
3909 sure that the custom rules in your @file{Makefile}s use
3910 @code{$(MKDIR_P)} and not @code{$(mkdir_p)}.  Even if both variables
3911 still work, the latter should be considered obsolete.
3913 If you are not using Automake, please call @code{AC_PROG_MKDIR_P}
3914 instead of @code{AM_PROG_MKDIR_P}.
3916 @item AM_SYS_POSIX_TERMIOS
3917 @acindex AM_SYS_POSIX_TERMIOS
3918 @cindex POSIX termios headers
3919 @cindex termios POSIX headers
3920 Check to see if POSIX termios headers and functions are available on the
3921 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
3922 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
3923 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
3925 @end table
3928 @node Private macros
3929 @subsection Private macros
3931 The following macros are private macros you should not call directly.
3932 They are called by the other public macros when appropriate.  Do not
3933 rely on them, as they might be changed in a future version.  Consider
3934 them as implementation details; or better, do not consider them at all:
3935 skip this section!
3937 @ftable @code
3938 @item _AM_DEPENDENCIES
3939 @itemx AM_SET_DEPDIR
3940 @itemx AM_DEP_TRACK
3941 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
3942 These macros are used to implement Automake's automatic dependency
3943 tracking scheme.  They are called automatically by automake when
3944 required, and there should be no need to invoke them manually.
3946 @item AM_MAKE_INCLUDE
3947 This macro is used to discover how the user's @command{make} handles
3948 @code{include} statements.  This macro is automatically invoked when
3949 needed; there should be no need to invoke it manually.
3951 @item AM_PROG_INSTALL_STRIP
3952 This is used to find a version of @code{install} that can be used to
3953 strip a program at installation time.  This macro is automatically
3954 included when required.
3956 @item AM_SANITY_CHECK
3957 This checks to make sure that a file created in the build directory is
3958 newer than a file in the source directory.  This can fail on systems
3959 where the clock is set incorrectly.  This macro is automatically run
3960 from @code{AM_INIT_AUTOMAKE}.
3962 @end ftable
3965 @node Directories
3966 @chapter Directories
3968 For simple projects that distributes all files in the same directory
3969 it is enough to have a single @file{Makefile.am} that builds
3970 everything in place.
3972 In larger projects it is common to organize files in different
3973 directories, in a tree.  For instance one directory per program, per
3974 library or per module.  The traditional approach is to build these
3975 subdirectory recursively: each directory contains its @file{Makefile}
3976 (generated from @file{Makefile.am}), and when @command{make} is run
3977 from the top level directory it enters each subdirectory in turn to
3978 build its contents.
3980 @menu
3981 * Subdirectories::              Building subdirectories recursively
3982 * Conditional Subdirectories::  Conditionally not building directories
3983 * Alternative::                 Subdirectories without recursion
3984 * Subpackages::                 Nesting packages
3985 @end menu
3987 @node Subdirectories
3988 @section Recursing subdirectories
3990 @cindex @code{SUBDIRS}, explained
3992 In packages with subdirectories, the top level @file{Makefile.am} must
3993 tell Automake which subdirectories are to be built.  This is done via
3994 the @code{SUBDIRS} variable.
3995 @vindex SUBDIRS
3997 The @code{SUBDIRS} variable holds a list of subdirectories in which
3998 building of various sorts can occur.  The rules for many targets
3999 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4000 both locally and in all specified subdirectories.  Note that the
4001 directories listed in @code{SUBDIRS} are not required to contain
4002 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4003 This allows inclusion of libraries from packages that do not use
4004 Automake (such as @code{gettext}; see also @ref{Third-Party
4005 Makefiles}).
4007 In packages that use subdirectories, the top-level @file{Makefile.am} is
4008 often very short.  For instance, here is the @file{Makefile.am} from the
4009 GNU Hello distribution:
4011 @example
4012 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4013 SUBDIRS = doc intl po src tests
4014 @end example
4016 When Automake invokes @command{make} in a subdirectory, it uses the value
4017 of the @code{MAKE} variable.  It passes the value of the variable
4018 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4019 @file{Makefile.am} if there are flags you must always pass to
4020 @command{make}.
4021 @vindex MAKE
4022 @vindex AM_MAKEFLAGS
4024 The directories mentioned in @code{SUBDIRS} are usually direct
4025 children of the current directory, each subdirectory containing its
4026 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4027 subdirectories.  Automake can be used to construct packages of
4028 arbitrary depth this way.
4030 By default, Automake generates @file{Makefiles} that work depth-first
4031 in postfix order: the subdirectories are built before the current
4032 directory.  However, it is possible to change this ordering.  You can
4033 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4034 putting @samp{.} first will cause a prefix ordering of
4035 directories.
4037 Using
4039 @example
4040 SUBDIRS = lib src . test
4041 @end example
4043 @noindent
4044 will cause @file{lib/} to be built before @file{src/}, then the
4045 current directory will be built, finally the @file{test/} directory
4046 will be built.  It is customary to arrange test directories to be
4047 built after everything else since they are meant to test what has
4048 been constructed.
4050 All @code{clean} rules are run in reverse order of build rules.
4052 @node Conditional Subdirectories
4053 @section Conditional Subdirectories
4054 @cindex Subdirectories, building conditionally
4055 @cindex Conditional subdirectories
4056 @cindex @code{SUBDIRS}, conditional
4057 @cindex Conditional @code{SUBDIRS}
4059 It is possible to define the @code{SUBDIRS} variable conditionally if,
4060 like in the case of GNU Inetutils, you want to only build a subset of
4061 the entire package.
4063 To illustrate how this works, let's assume we have two directories
4064 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4065 want to decide in @command{configure} whether @file{opt/} will be built
4066 or not.  (For this example we will assume that @file{opt/} should be
4067 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4069 Running @command{make} should thus recurse into @file{src/} always, and
4070 then maybe in @file{opt/}.
4072 However @samp{make dist} should always recurse into both @file{src/}
4073 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4074 is not needed in the current configuration.  This means
4075 @file{opt/Makefile} should be created @emph{unconditionally}.
4077 There are two ways to setup a project like this.  You can use Automake
4078 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4079 variables (@pxref{Setting Output Variables, , Setting Output
4080 Variables, autoconf, The Autoconf Manual}).  Using Automake
4081 conditionals is the preferred solution.  Before we illustrate these
4082 two possibility, let's introduce @code{DIST_SUBDIRS}.
4084 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4085 @cindex @code{DIST_SUBDIRS}, explained
4087 Automake considers two sets of directories, defined by the variables
4088 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4090 @code{SUBDIRS} contains the subdirectories of the current directory
4091 that must be built (@pxref{Subdirectories}).  It must be defined
4092 manually; Automake will never guess a directory is to be built.  As we
4093 will see in the next two sections, it is possible to define it
4094 conditionally so that some directory will be omitted from the build.
4096 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4097 directories, even those that have been conditionally left out of the
4098 build.  Recall our example where we may not want to build subdirectory
4099 @file{opt/}, but yet we want to distribute it?  This is where
4100 @code{DIST_SUBDIRS} come into play: @samp{opt} may not appear in
4101 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4103 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4104 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4105 other recursive rules use @code{SUBDIRS}.
4107 If @code{SUBDIRS} is defined conditionally using Automake
4108 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4109 from the possibles values of @code{SUBDIRS} in all conditions.
4111 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4112 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4113 does not know the possible values of these variables.  In this case
4114 @code{DIST_SUBDIRS} needs to be defined manually.
4116 @subsection Conditional subdirectories with @code{AM_CONDITIONAL}
4117 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4118 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4120 @c The test case for the setup described here is
4121 @c     test/subdircond2.test
4122 @c Try to keep it in sync.
4124 @file{configure} should output the @file{Makefile} for each directory
4125 and define a condition into which @file{opt/} should be built.
4127 @example
4128 @dots{}
4129 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4130 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4131 @dots{}
4132 @end example
4134 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4135 as follows.
4137 @example
4138 if COND_OPT
4139   MAYBE_OPT = opt
4140 endif
4141 SUBDIRS = src $(MAYBE_OPT)
4142 @end example
4144 As you can see, running @command{make} will rightly recurse into
4145 @file{src/} and maybe @file{opt/}.
4147 @vindex DIST_SUBDIRS
4148 As you can't see, running @samp{make dist} will recurse into both
4149 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4150 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4151 @code{DIST_SUBDIRS} variable.
4153 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4154 automatically because it knows that @code{MAYBE_OPT} can contain
4155 @samp{opt} in some condition.
4157 @subsection Conditional Subdirectories with @code{AC_SUBST}
4158 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4159 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4161 @c The test case for the setup described here is
4162 @c     test/subdircond3.test
4163 @c Try to keep it in sync.
4165 Another possibility is to define @code{MAYBE_OPT} from
4166 @file{./configure} using @code{AC_SUBST}:
4168 @example
4169 @dots{}
4170 if test "$want_opt" = yes; then
4171   MAYBE_OPT=opt
4172 else
4173   MAYBE_OPT=
4175 AC_SUBST([MAYBE_OPT])
4176 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4177 @dots{}
4178 @end example
4180 In this case the top-level @file{Makefile.am} should look as follows.
4182 @example
4183 SUBDIRS = src $(MAYBE_OPT)
4184 DIST_SUBDIRS = src opt
4185 @end example
4187 The drawback is that since Automake cannot guess what the possible
4188 values of @code{MAYBE_OPT} are, it is necessary to define
4189 @code{DIST_SUBDIRS}.
4191 @subsection Non-configured Subdirectories
4192 @cindex Subdirectories, configured conditionally
4194 The semantic of @code{DIST_SUBDIRS} is often misunderstood by some
4195 users that try to @emph{configure and build} subdirectories
4196 conditionally.  Here by configuring we mean creating the
4197 @file{Makefile} (it might also involve running a nested
4198 @command{configure} script: this is a costly operation that explains
4199 why people want to do it conditionally, but only the @file{Makefile}
4200 is relevant to the discussion).
4202 The above examples all assume that every @file{Makefile} is created,
4203 even in directories that are not going to be built.  The simple reason
4204 is that we want @samp{make dist} to distribute even the directories
4205 that are not being built (e.g., platform-dependent code), hence
4206 @file{make dist} must recurse into the subdirectory, hence this
4207 directory must be configured and appear in @code{DIST_SUBDIRS}.
4209 Building packages that do not configure every subdirectory is a tricky
4210 business, and we do not recommend it to the novice as it is easy to
4211 produce an incomplete tarball by mistake.  We will not discuss this
4212 topic in depth here, yet for the adventurous here are a few rules to
4213 remember.
4215 @cartouche
4216 @itemize
4217 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4219 It makes little sense to have a directory in @code{SUBDIRS} that
4220 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4221 which directories listed in the latter should be built.
4222 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4223 must be configured.
4225 I.e., the @file{Makefile} must exists or the recursive @command{make}
4226 rules will not be able to process the directory.
4227 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4229 So that the cleaning rule remove the generated @file{Makefile}s.
4230 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4231 lists all the directories that have been configured.
4232 @end itemize
4233 @end cartouche
4235 In order to prevent recursion in some non-configured directory you
4236 must therefore ensure that this directory does not appear in
4237 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4238 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4239 @code{DIST_SUBDIRS} explicitly, it will be default to
4240 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4241 = $(SUBDIRS)}.
4243 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4244 not be distributed unless you make other arrangements for this to
4245 happen (for instance, always running @samp{make dist} in a
4246 configuration where all directories are known to appear in
4247 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4248 distribute these directories).
4250 @cindex Subdirectories, not distributed
4251 In few packages, non-configured directories are not even expected to
4252 be distributed.  Although these packages do not require the
4253 aforementioned extra arrangements, there is another pitfall.  If the
4254 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4255 @command{automake} will make sure the directory exists.  Consequently
4256 @command{automake} cannot be run on such a distribution when one
4257 directory has been omitted.  One way to avoid this check is to use the
4258 @code{AC_SUBST} method to declare conditional directories; since
4259 @command{automake} does not know the values of @code{AC_SUBST}
4260 variables it cannot ensure the corresponding directory exist.
4262 @node Alternative
4263 @section An Alternative Approach to Subdirectories
4265 If you've ever read Peter Miller's excellent paper,
4266 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
4267 Recursive Make Considered Harmful}, the preceding sections on the use of
4268 subdirectories will probably come as unwelcome advice.  For those who
4269 haven't read the paper, Miller's main thesis is that recursive
4270 @command{make} invocations are both slow and error-prone.
4272 Automake provides sufficient cross-directory support @footnote{We
4273 believe.  This work is new and there are probably warts.
4274 @xref{Introduction}, for information on reporting bugs.} to enable you
4275 to write a single @file{Makefile.am} for a complex multi-directory
4276 package.
4279 By default an installable file specified in a subdirectory will have its
4280 directory name stripped before installation.  For instance, in this
4281 example, the header file will be installed as
4282 @file{$(includedir)/stdio.h}:
4284 @example
4285 include_HEADERS = inc/stdio.h
4286 @end example
4288 @vindex nobase_
4289 @cindex @code{nobase_} prefix
4290 @cindex Path stripping, avoiding
4291 @cindex Avoiding path stripping
4293 However, the @samp{nobase_} prefix can be used to circumvent this path
4294 stripping.  In this example, the header file will be installed as
4295 @file{$(includedir)/sys/types.h}:
4297 @example
4298 nobase_include_HEADERS = sys/types.h
4299 @end example
4301 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4302 @cindex @code{dist_} and @code{nobase_}
4303 @cindex @code{nodist_} and @code{nobase_}
4304 @vindex dist_
4305 @vindex nodist_
4307 @samp{nobase_} should be specified first when used in conjunction with
4308 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
4310 @example
4311 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4312 @end example
4314 Finally, note that a variable using the @samp{nobase_} prefix can
4315 always be replaced by several variables, one for each destination
4316 directory (@pxref{Uniform}).  For instance, the last example could be
4317 rewritten as follows:
4319 @example
4320 imagesdir = $(pkgdatadir)/images
4321 soundsdir = $(pkgdatadir)/sounds
4322 dist_images_DATA = images/vortex.pgm
4323 dist_sounds_DATA = sounds/whirl.ogg
4324 @end example
4326 @noindent
4327 This latter syntax makes it possible to change one destination
4328 directory without changing the layout of the source tree.
4330 @node Subpackages
4331 @section Nesting Packages
4332 @cindex Nesting packages
4333 @cindex Subpackages
4334 @acindex AC_CONFIG_SUBDIRS
4335 @acindex AC_CONFIG_AUX_DIR
4338 In the GNU Build System, packages can be nested to arbitrary depth.
4339 This means that a package can embedded other packages with their own
4340 @file{configure}, @file{Makefile}s, etc.
4342 These other packages should just appear as subdirectories of their
4343 parent package.  They must be listed in @code{SUBDIRS} like other
4344 ordinary directories.  However the subpackage's @file{Makefile}s
4345 should be output by its own @file{configure} script, not by the
4346 parent's @file{configure}.  This is achieved using the
4347 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4348 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4349 autoconf, The Autoconf Manual}).
4351 Here is an example package for an @code{arm} program that links with
4352 an @code{hand} library that is a nested package in subdirectory
4353 @file{hand/}.
4355 @code{arm}'s @file{configure.ac}:
4357 @example
4358 AC_INIT([arm], [1.0])
4359 AC_CONFIG_AUX_DIR([.])
4360 AM_INIT_AUTOMAKE
4361 AC_PROG_CC
4362 AC_CONFIG_FILES([Makefile])
4363 # Call hand's ./configure script recursively.
4364 AC_CONFIG_SUBDIRS([hand])
4365 AC_OUTPUT
4366 @end example
4368 @code{arm}'s @file{Makefile.am}:
4370 @example
4371 # Build the library in the hand subdirectory first.
4372 SUBDIRS = hand
4374 # Include hand's header when compiling this directory.
4375 AM_CPPFLAGS = -I$(srcdir)/hand
4377 bin_PROGRAMS = arm
4378 arm_SOURCES = arm.c
4379 # link with the hand library.
4380 arm_LDADD = hand/libhand.a
4381 @end example
4383 Now here is @code{hand}'s @file{hand/configure.ac}:
4385 @example
4386 AC_INIT([hand], [1.2])
4387 AC_CONFIG_AUX_DIR([.])
4388 AM_INIT_AUTOMAKE
4389 AC_PROG_CC
4390 AC_PROG_RANLIB
4391 AC_CONFIG_FILES([Makefile])
4392 AC_OUTPUT
4393 @end example
4395 @noindent
4396 and its @file{hand/Makefile.am}:
4398 @example
4399 lib_LIBRARIES = libhand.a
4400 libhand_a_SOURCES = hand.c
4401 @end example
4403 When @samp{make dist} is run from the top-level directory it will
4404 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4405 code as well as the @file{hand} subdirectory.  This package can be
4406 built and installed like any ordinary package, with the usual
4407 @samp{./configure && make && make install} sequence (the @code{hand}
4408 subpackage will be built and installed by the process).
4410 When @samp{make dist} is run from the hand directory, it will create a
4411 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4412 to be embedded in another package, it can still be used separately.
4414 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4415 force Automake and Autoconf into search auxiliary script in the
4416 current directory.  For instance, this means that there will be two
4417 copies of @file{install-sh}: one in the top-level of the @code{arm}
4418 package, and another one in the @file{hand/} subdirectory for the
4419 @code{hand} package.
4421 The historical default is to search these auxiliary scripts in the
4422 immediate parent and grand-parent directories.  So if the
4423 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4424 @file{hand/configure.ac}, that subpackage would share the auxiliary
4425 script of the @code{arm} package.  This may looks like a gain in size
4426 (a few kilobytes), but it is actually a loss of modularity as the
4427 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4428 in the subdirectory will not work anymore).
4430 Packages that do not use Automake need more work to be integrated this
4431 way.  @xref{Third-Party Makefiles}.
4433 @node Programs
4434 @chapter Building Programs and Libraries
4436 A large part of Automake's functionality is dedicated to making it easy
4437 to build programs and libraries.
4439 @menu
4440 * A Program::                   Building a program
4441 * A Library::                   Building a library
4442 * A Shared Library::            Building a Libtool library
4443 * Program and Library Variables::  Variables controlling program and
4444                                 library builds
4445 * Default _SOURCES::            Default source files
4446 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4447 * Program variables::           Variables used when building a program
4448 * Yacc and Lex::                Yacc and Lex support
4449 * C++ Support::                 Compiling C++ sources
4450 * Objective C Support::         Compiling Objective C sources
4451 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4452 * Assembly Support::            Compiling assembly sources
4453 * Fortran 77 Support::          Compiling Fortran 77 sources
4454 * Fortran 9x Support::          Compiling Fortran 9x sources
4455 * Java Support::                Compiling Java sources
4456 * Support for Other Languages::  Compiling other languages
4457 * ANSI::                        Automatic de-ANSI-fication
4458 * Dependencies::                Automatic dependency tracking
4459 * EXEEXT::                      Support for executable extensions
4460 @end menu
4463 @node A Program
4464 @section Building a program
4466 In order to build a program, you need to tell Automake which sources
4467 are part of it, and which libraries it should be linked with.
4469 This section also covers conditional compilation of sources or
4470 programs.  Most of the comments about these also apply to libraries
4471 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4473 @menu
4474 * Program Sources::             Defining program sources
4475 * Linking::                     Linking with libraries or extra objects
4476 * Conditional Sources::         Handling conditional sources
4477 * Conditional Programs::        Building program conditionally
4478 @end menu
4480 @node Program Sources
4481 @subsection Defining program sources
4483 @cindex @code{PROGRAMS}, @code{bindir}
4484 @vindex _PROGRAMS
4485 @vindex bin_PROGRAMS
4486 @vindex sbin_PROGRAMS
4487 @vindex libexec_PROGRAMS
4488 @vindex pkglib_PROGRAMS
4489 @vindex noinst_PROGRAMS
4490 @vindex check_PROGRAMS
4492 In a directory containing source that gets built into a program (as
4493 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4494 Programs can be installed in @code{bindir}, @code{sbindir},
4495 @code{libexecdir}, @code{pkglibdir}, or not at all (@code{noinst_}).
4496 They can also be built only for @samp{make check}, in which case the
4497 prefix is @samp{check_}.
4499 For instance:
4501 @example
4502 bin_PROGRAMS = hello
4503 @end example
4505 In this simple case, the resulting @file{Makefile.in} will contain code
4506 to generate a program named @code{hello}.
4508 Associated with each program are several assisting variables that are
4509 named after the program.  These variables are all optional, and have
4510 reasonable defaults.  Each variable, its use, and default is spelled out
4511 below; we use the ``hello'' example throughout.
4513 The variable @code{hello_SOURCES} is used to specify which source files
4514 get built into an executable:
4516 @example
4517 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4518 @end example
4520 This causes each mentioned @file{.c} file to be compiled into the
4521 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4523 @cindex @code{_SOURCES} primary, defined
4524 @cindex @code{SOURCES} primary, defined
4525 @cindex Primary variable, @code{SOURCES}
4526 @vindex _SOURCES
4528 If @code{hello_SOURCES} is not specified, then it defaults to the single
4529 file @file{hello.c} (@pxref{Default _SOURCES}).
4530 @vindex _SOURCES
4531 @vindex SOURCES
4533 Multiple programs can be built in a single directory.  Multiple programs
4534 can share a single source file, which must be listed in each
4535 @code{_SOURCES} definition.
4537 @cindex Header files in @code{_SOURCES}
4538 @cindex @code{_SOURCES} and header files
4540 Header files listed in a @code{_SOURCES} definition will be included in
4541 the distribution but otherwise ignored.  In case it isn't obvious, you
4542 should not include the header file generated by @file{configure} in a
4543 @code{_SOURCES} variable; this file should not be distributed.  Lex
4544 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4545 and Lex}.
4548 @node Linking
4549 @subsection Linking the program
4551 If you need to link against libraries that are not found by
4552 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4553 used to specify additional objects or libraries to link with; it is
4554 inappropriate for specifying specific linker flags, you should use
4555 @code{AM_LDFLAGS} for this purpose.
4556 @vindex LDADD
4557 @vindex AM_LDFLAGS
4559 @cindex @code{prog_LDADD}, defined
4561 Sometimes, multiple programs are built in one directory but do not share
4562 the same link-time requirements.  In this case, you can use the
4563 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4564 program as it appears in some @code{_PROGRAMS} variable, and usually
4565 written in lowercase) to override the global @code{LDADD}.  If this
4566 variable exists for a given program, then that program is not linked
4567 using @code{LDADD}.
4568 @vindex maude_LDADD
4570 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4571 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4572 built in the same directory, and has no such link requirement.  Also,
4573 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4574 is what cpio's @file{src/Makefile.am} looks like (abridged):
4576 @example
4577 bin_PROGRAMS = cpio pax $(MT)
4578 libexec_PROGRAMS = $(RMT)
4579 EXTRA_PROGRAMS = mt rmt
4581 LDADD = ../lib/libcpio.a $(INTLLIBS)
4582 rmt_LDADD =
4584 cpio_SOURCES = @dots{}
4585 pax_SOURCES = @dots{}
4586 mt_SOURCES = @dots{}
4587 rmt_SOURCES = @dots{}
4588 @end example
4590 @cindex @code{_LDFLAGS}, defined
4591 @vindex maude_LDFLAGS
4592 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4593 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4594 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4595 this purpose.
4597 @cindex @code{_DEPENDENCIES}, defined
4598 @vindex maude_DEPENDENCIES
4599 It is also occasionally useful to have a program depend on some other
4600 target that is not actually part of that program.  This can be done
4601 using the @code{@var{prog}_DEPENDENCIES} variable.  Each program
4602 depends on the contents of such a variable, but no further
4603 interpretation is done.
4605 Since these dependencies are associated to the link rule used to
4606 create the programs they should normally list files used by the link
4607 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4608 files.  In rare cases you may need to add other kinds of files such as
4609 linker scripts, but @emph{listing a source file in
4610 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4611 before all the components of a program are built, consider using the
4612 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4614 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4615 Automake.  The automatically-assigned value is the contents of
4616 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4617 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4618 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4619 @samp{$(ALLOCA)}; these are left because it is known that they will not
4620 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4621 generated.
4623 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4624 is useful.
4626 @cindex @code{LDADD} and @option{-l}
4627 @cindex @option{-l} and @code{LDADD}
4628 We recommend that you avoid using @option{-l} options in @code{LDADD}
4629 or @code{@var{prog}_LDADD} when referring to libraries built by your
4630 package.  Instead, write the file name of the library explicitly as in
4631 the above @code{cpio} example.  Use @option{-l} only to list
4632 third-party libraries.  If you follow this rule, the default value of
4633 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4634 omit the other ones.
4637 @node Conditional Sources
4638 @subsection Conditional compilation of sources
4640 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4641 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4642 @code{_SOURCES} variable.  The reason for this is a bit hard to
4643 explain, but suffice to say that it simply won't work.  Automake will
4644 give an error if you try to do this.
4646 Fortunately there are two other ways to achieve the same result.  One is
4647 to use configure substitutions in @code{_LDADD} variables, the other is
4648 to use an Automake conditional.
4650 @subsubsection Conditional compilation using @code{_LDADD} substitutions
4652 @cindex @code{EXTRA_prog_SOURCES}, defined
4654 Automake must know all the source files that could possibly go into a
4655 program, even if not all the files are built in every circumstance.  Any
4656 files that are only conditionally built should be listed in the
4657 appropriate @code{EXTRA_} variable.  For instance, if
4658 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4659 in @code{hello}, the @file{Makefile.am} would contain:
4661 @example
4662 bin_PROGRAMS = hello
4663 hello_SOURCES = hello-common.c
4664 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4665 hello_LDADD = $(HELLO_SYSTEM)
4666 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4667 @end example
4669 @noindent
4670 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4671 @file{configure.ac}:
4673 @example
4674 @dots{}
4675 case $host in
4676   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4677   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4678 esac
4679 AC_SUBST([HELLO_SYSTEM])
4680 @dots{}
4681 @end example
4683 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4684 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4685 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4686 built and linked in.
4688 @subsubsection Conditional compilation using Automake conditionals
4690 An often simpler way to compile source files conditionally is to use
4691 Automake conditionals.  For instance, you could use this
4692 @file{Makefile.am} construct to build the same @file{hello} example:
4694 @example
4695 bin_PROGRAMS = hello
4696 if LINUX
4697 hello_SOURCES = hello-linux.c hello-common.c
4698 else
4699 hello_SOURCES = hello-generic.c hello-common.c
4700 endif
4701 @end example
4703 In this case, @file{configure.ac} should setup the @code{LINUX}
4704 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4706 When using conditionals like this you don't need to use the
4707 @code{EXTRA_} variable, because Automake will examine the contents of
4708 each variable to construct the complete list of source files.
4710 If your program uses a lot of files, you will probably prefer a
4711 conditional @samp{+=}.
4713 @example
4714 bin_PROGRAMS = hello
4715 hello_SOURCES = hello-common.c
4716 if LINUX
4717 hello_SOURCES += hello-linux.c
4718 else
4719 hello_SOURCES += hello-generic.c
4720 endif
4721 @end example
4723 @node Conditional Programs
4724 @subsection Conditional compilation of programs
4725 @cindex Conditional programs
4726 @cindex Programs, conditional
4728 Sometimes it is useful to determine the programs that are to be built
4729 at configure time.  For instance, GNU @code{cpio} only builds
4730 @code{mt} and @code{rmt} under special circumstances.  The means to
4731 achieve conditional compilation of programs are the same you can use
4732 to compile source files conditionally: substitutions or conditionals.
4734 @subsubsection Conditional programs using @command{configure} substitutions
4736 @vindex EXTRA_PROGRAMS
4737 @cindex @code{EXTRA_PROGRAMS}, defined
4738 In this case, you must notify Automake of all the programs that can
4739 possibly be built, but at the same time cause the generated
4740 @file{Makefile.in} to use the programs specified by @command{configure}.
4741 This is done by having @command{configure} substitute values into each
4742 @code{_PROGRAMS} definition, while listing all optionally built programs
4743 in @code{EXTRA_PROGRAMS}.
4745 @example
4746 bin_PROGRAMS = cpio pax $(MT)
4747 libexec_PROGRAMS = $(RMT)
4748 EXTRA_PROGRAMS = mt rmt
4749 @end example
4751 As explained in @ref{EXEEXT}, Automake will rewrite
4752 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4753 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4754 Obviously it cannot rewrite values obtained at run-time through
4755 @command{configure} substitutions, therefore you should take care of
4756 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4757 ['mt$@{EXEEXT@}'])}.
4759 @subsubsection Conditional programs using Automake conditionals
4761 You can also use Automake conditionals (@pxref{Conditionals}) to
4762 select programs to be built.  In this case you don't have to worry
4763 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4765 @example
4766 bin_PROGRAMS = cpio pax
4767 if WANT_MT
4768   bin_PROGRAMS += mt
4769 endif
4770 if WANT_RMT
4771   libexec_PROGRAMS = rmt
4772 endif
4773 @end example
4776 @node A Library
4777 @section Building a library
4779 @cindex @code{_LIBRARIES} primary, defined
4780 @cindex @code{LIBRARIES} primary, defined
4781 @cindex Primary variable, @code{LIBRARIES}
4782 @vindex _LIBRARIES
4784 @vindex lib_LIBRARIES
4785 @vindex pkglib_LIBRARIES
4786 @vindex noinst_LIBRARIES
4788 Building a library is much like building a program.  In this case, the
4789 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
4790 @code{libdir} or @code{pkglibdir}.
4792 @xref{A Shared Library}, for information on how to build shared
4793 libraries using libtool and the @code{LTLIBRARIES} primary.
4795 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
4796 For instance, to create a library named @file{libcpio.a}, but not install
4797 it, you would write:
4799 @example
4800 noinst_LIBRARIES = libcpio.a
4801 libcpio_a_SOURCES = @dots{}
4802 @end example
4804 The sources that go into a library are determined exactly as they are
4805 for programs, via the @code{_SOURCES} variables.  Note that the library
4806 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
4807 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
4808 not @samp{libcpio.a_SOURCES}.
4810 @vindex maude_LIBADD
4811 Extra objects can be added to a library using the
4812 @code{@var{library}_LIBADD} variable.  This should be used for objects
4813 determined by @command{configure}.  Again from @code{cpio}:
4815 @example
4816 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4817 @end example
4819 In addition, sources for extra objects that will not exist until
4820 configure-time must be added to the @code{BUILT_SOURCES} variable
4821 (@pxref{Sources}).
4823 Building a static library is done by compiling all object files, then
4824 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
4825 library and the list of objects, and finally by calling
4826 @samp{$(RANLIB)} on that library.  You should call
4827 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
4828 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
4829 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
4830 can override these two variables my setting them in your
4831 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
4832 @file{configure.ac}, or by defining a per-library @code{maude_AR}
4833 variable (@pxref{Program and Library Variables}).
4835 @cindex Empty libraries
4836 Be careful when selecting library components conditionally.  Because
4837 building an empty library is not portable, you should ensure that any
4838 library contains always at least one object.
4840 To use a static library when building a program, add it to
4841 @code{LDADD} for this program.  In the following example, the program
4842 @file{cpio} is statically linked with the library @file{libcpio.a}.
4844 @example
4845 noinst_LIBRARIES = libcpio.a
4846 libcpio_a_SOURCES = @dots{}
4848 bin_PROGRAMS = cpio
4849 cpio_SOURCES = cpio.c @dots{}
4850 cpio_LDADD = libcpio.a
4851 @end example
4854 @node A Shared Library
4855 @section Building a Shared Library
4857 @cindex Shared libraries, support for
4859 Building shared libraries portably is a relatively complex matter.
4860 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
4861 Libtool Manual}) was created to help build shared libraries in a
4862 platform-independent way.
4864 @menu
4865 * Libtool Concept::             Introducing Libtool
4866 * Libtool Libraries::           Declaring Libtool Libraries
4867 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
4868 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
4869 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
4870 * Libtool Modules::             Building Libtool Modules
4871 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
4872 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
4873 * Libtool Issues::              Common Issues Related to Libtool's Use
4874 @end menu
4876 @node Libtool Concept
4877 @subsection The Libtool Concept
4879 @cindex @command{libtool}, introduction
4880 @cindex libtool library, definition
4881 @cindex suffix @file{.la}, defined
4882 @cindex @file{.la} suffix, defined
4884 Libtool abstracts shared and static libraries into a unified concept
4885 henceforth called @dfn{libtool libraries}.  Libtool libraries are
4886 files using the @file{.la} suffix, and can designate a static library,
4887 a shared library, or maybe both.  Their exact nature cannot be
4888 determined until @file{./configure} is run: not all platforms support
4889 all kinds of libraries, and users can explicitly select which
4890 libraries should be built.  (However the package's maintainers can
4891 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
4892 macro, libtool, The Libtool Manual}.)
4894 @cindex suffix @file{.lo}, defined
4895 Because object files for shared and static libraries must be compiled
4896 differently, libtool is also used during compilation.  Object files
4897 built by libtool are called @dfn{libtool objects}: these are files
4898 using the @file{.lo} suffix.  Libtool libraries are built from these
4899 libtool objects.
4901 You should not assume anything about the structure of @file{.la} or
4902 @file{.lo} files and how libtool constructs them: this is libtool's
4903 concern, and the last thing one wants is to learn about libtool's
4904 guts.  However the existence of these files matters, because they are
4905 used as targets and dependencies in @file{Makefile}s rules when
4906 building libtool libraries.  There are situations where you may have
4907 to refer to these, for instance when expressing dependencies for
4908 building source files conditionally (@pxref{Conditional Libtool
4909 Sources}).
4911 @cindex @file{libltdl}, introduction
4913 People considering writing a plug-in system, with dynamically loaded
4914 modules, should look into @file{libltdl}: libtool's dlopening library
4915 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
4916 This offers a portable dlopening facility to load libtool libraries
4917 dynamically, and can also achieve static linking where unavoidable.
4919 Before we discuss how to use libtool with Automake in details, it
4920 should be noted that the libtool manual also has a section about how
4921 to use Automake with libtool (@pxref{Using Automake, , Using Automake
4922 with Libtool, libtool, The Libtool Manual}).
4924 @node Libtool Libraries
4925 @subsection Building Libtool Libraries
4927 @cindex @code{_LTLIBRARIES} primary, defined
4928 @cindex @code{LTLIBRARIES} primary, defined
4929 @cindex Primary variable, @code{LTLIBRARIES}
4930 @cindex Example of shared libraries
4931 @vindex lib_LTLIBRARIES
4932 @vindex pkglib_LTLIBRARIES
4933 @vindex _LTLIBRARIES
4935 Automake uses libtool to build libraries declared with the
4936 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
4937 list of libtool libraries to build.  For instance, to create a libtool
4938 library named @file{libgettext.la}, and install it in @code{libdir},
4939 write:
4941 @example
4942 lib_LTLIBRARIES = libgettext.la
4943 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
4944 @end example
4946 Automake predefines the variable @code{pkglibdir}, so you can use
4947 @code{pkglib_LTLIBRARIES} to install libraries in
4948 @samp{$(libdir)/@@PACKAGE@@/}.
4950 If @file{gettext.h} is a public header file that needs to be installed
4951 in order for people to use the library, it should be declared using a
4952 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
4953 Headers listed in the latter should be internal headers that are not
4954 part of the public interface.
4956 @example
4957 lib_LTLIBRARIES = libgettext.la
4958 libgettext_la_SOURCES = gettext.c @dots{}
4959 include_HEADERS = gettext.h @dots{}
4960 @end example
4962 A package can build and install such a library along with other
4963 programs that use it.  This dependency should be specified using
4964 @code{LDADD}.  The following example builds a program named
4965 @file{hello} that is linked with @file{libgettext.la}.
4967 @example
4968 lib_LTLIBRARIES = libgettext.la
4969 libgettext_la_SOURCES = gettext.c @dots{}
4971 bin_PROGRAMS = hello
4972 hello_SOURCES = hello.c @dots{}
4973 hello_LDADD = libgettext.la
4974 @end example
4976 @noindent
4977 Whether @file{hello} is statically or dynamically linked with
4978 @file{libgettext.la} is not yet known: this will depend on the
4979 configuration of libtool and the capabilities of the host.
4982 @node Conditional Libtool Libraries
4983 @subsection Building Libtool Libraries Conditionally
4984 @cindex libtool libraries, conditional
4985 @cindex conditional libtool libraries
4987 Like conditional programs (@pxref{Conditional Programs}), there are
4988 two main ways to build conditional libraries: using Automake
4989 conditionals or using Autoconf @code{AC_SUBST}itutions.
4991 The important implementation detail you have to be aware of is that
4992 the place where a library will be installed matters to libtool: it
4993 needs to be indicated @emph{at link-time} using the @option{-rpath}
4994 option.
4996 For libraries whose destination directory is known when Automake runs,
4997 Automake will automatically supply the appropriate @option{-rpath}
4998 option to libtool.  This is the case for libraries listed explicitly in
4999 some installable @code{_LTLIBRARIES} variables such as
5000 @code{lib_LTLIBRARIES}.
5002 However, for libraries determined at configure time (and thus
5003 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5004 final installation directory.  For such libraries you must add the
5005 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5006 hand.
5008 The examples below illustrate the differences between these two methods.
5010 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5011 variable set at @file{./configure}-time to either @file{libfoo.la},
5012 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5013 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5014 relates to @file{libfoo.la} or @file{libbar.la} by the time it creates
5015 the link rule for these two libraries.  Therefore the @option{-rpath}
5016 argument must be explicitly supplied.
5018 @example
5019 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5020 lib_LTLIBRARIES = $(WANTEDLIBS)
5021 libfoo_la_SOURCES = foo.c @dots{}
5022 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5023 libbar_la_SOURCES = bar.c @dots{}
5024 libbar_la_LDFLAGS = -rpath '$(libdir)'
5025 @end example
5027 Here is how the same @file{Makefile.am} would look using Automake
5028 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5029 Automake is able to compute the @option{-rpath} setting itself, because
5030 it's clear that both libraries will end up in @samp{$(libdir)} if they
5031 are installed.
5033 @example
5034 lib_LTLIBRARIES =
5035 if WANT_LIBFOO
5036 lib_LTLIBRARIES += libfoo.la
5037 endif
5038 if WANT_LIBBAR
5039 lib_LTLIBRARIES += libbar.la
5040 endif
5041 libfoo_la_SOURCES = foo.c @dots{}
5042 libbar_la_SOURCES = bar.c @dots{}
5043 @end example
5045 @node Conditional Libtool Sources
5046 @subsection Libtool Libraries with Conditional Sources
5048 Conditional compilation of sources in a library can be achieved in the
5049 same way as conditional compilation of sources in a program
5050 (@pxref{Conditional Sources}).  The only difference is that
5051 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5052 should mention libtool objects (@file{.lo} files).
5054 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5055 we could build a @file{libhello.la} library using either
5056 @file{hello-linux.c} or @file{hello-generic.c} with the following
5057 @file{Makefile.am}.
5059 @example
5060 lib_LTLIBRARIES = libhello.la
5061 libhello_la_SOURCES = hello-common.c
5062 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5063 libhello_la_LIBADD = $(HELLO_SYSTEM)
5064 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5065 @end example
5067 @noindent
5068 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5069 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5071 Or we could simply use an Automake conditional as follows.
5073 @example
5074 lib_LTLIBRARIES = libhello.la
5075 libhello_la_SOURCES = hello-common.c
5076 if LINUX
5077 libhello_la_SOURCES += hello-linux.c
5078 else
5079 libhello_la_SOURCES += hello-generic.c
5080 endif
5081 @end example
5083 @node Libtool Convenience Libraries
5084 @subsection Libtool Convenience Libraries
5085 @cindex convenience libraries, libtool
5086 @cindex libtool convenience libraries
5087 @vindex noinst_LTLIBRARIES
5088 @vindex check_LTLIBRARIES
5090 Sometimes you want to build libtool libraries that should not be
5091 installed.  These are called @dfn{libtool convenience libraries} and
5092 are typically used to encapsulate many sublibraries, later gathered
5093 into one big installed library.
5095 Libtool convenience libraries are declared by directory-less variables
5096 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5097 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5098 not need an @option{-rpath} flag at link time (actually this is the only
5099 difference).
5101 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5102 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5103 @samp{make check}.  Finally, libraries listed in
5104 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5105 rules to build them, but if the library does not appear as a Makefile
5106 dependency anywhere it won't be built (this is why
5107 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5109 Here is a sample setup merging libtool convenience libraries from
5110 subdirectories into one main @file{libtop.la} library.
5112 @example
5113 # -- Top-level Makefile.am --
5114 SUBDIRS = sub1 sub2 @dots{}
5115 lib_LTLIBRARIES = libtop.la
5116 libtop_la_SOURCES =
5117 libtop_la_LIBADD = \
5118   sub1/libsub1.la \
5119   sub2/libsub2.la \
5120   @dots{}
5122 # -- sub1/Makefile.am --
5123 noinst_LTLIBRARIES = libsub1.la
5124 libsub1_la_SOURCES = @dots{}
5126 # -- sub2/Makefile.am --
5127 # showing nested convenience libraries
5128 SUBDIRS = sub2.1 sub2.2 @dots{}
5129 noinst_LTLIBRARIES = libsub2.la
5130 libsub2_la_SOURCES =
5131 libsub2_la_LIBADD = \
5132   sub21/libsub21.la \
5133   sub22/libsub22.la \
5134   @dots{}
5135 @end example
5137 When using such setup, beware that @command{automake} will assume
5138 @file{libtop.la} is to be linked with the C linker.  This is because
5139 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5140 default language.  If @code{libtop_la_SOURCES} was not empty,
5141 @command{automake} would select the linker as explained in @ref{How
5142 the Linker is Chosen}.
5144 If one of the sublibraries contains non-C source, it is important that
5145 the appropriate linker be chosen.  One way to achieve this is to
5146 pretend that there is such a non-C file among the sources of the
5147 library, thus forcing @command{automake} to select the appropriate
5148 linker.  Here is the top-level @file{Makefile} of our example updated
5149 to force C++ linking.
5151 @example
5152 SUBDIRS = sub1 sub2 @dots{}
5153 lib_LTLIBRARIES = libtop.la
5154 libtop_la_SOURCES =
5155 # Dummy C++ source to cause C++ linking.
5156 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5157 libtop_la_LIBADD = \
5158   sub1/libsub1.la \
5159   sub2/libsub2.la \
5160   @dots{}
5161 @end example
5163 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5164 files that might be compiled (this is mostly useful when doing
5165 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5166 Libtool Sources}), and the @code{nodist_} prefix means the listed
5167 sources are not to be distributed (@pxref{Program and Library
5168 Variables}).  In effect the file @file{dummy.cxx} does not need to
5169 exist in the source tree.  Of course if you have some real source file
5170 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5171 @code{nodist_EXTRA_libtop_la_SOURCES}.
5174 @node Libtool Modules
5175 @subsection Libtool Modules
5176 @cindex modules, libtool
5177 @cindex libtool modules
5178 @cindex @option{-module}, libtool
5180 These are libtool libraries meant to be dlopened.  They are
5181 indicated to libtool by passing @option{-module} at link-time.
5183 @example
5184 pkglib_LTLIBRARIES = mymodule.la
5185 mymodule_la_SOURCES = doit.c
5186 mymodule_la_LDFLAGS = -module
5187 @end example
5189 Ordinarily, Automake requires that a library's name starts with
5190 @code{lib}.  However, when building a dynamically loadable module you
5191 might wish to use a "nonstandard" name.  Automake will not complain
5192 about such nonstandard name if it knows the library being built is a
5193 libtool module, i.e., if @option{-module} explicitly appears in the
5194 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5195 variable when no per-library @code{_LDFLAGS} variable is defined).
5197 As always, @code{AC_SUBST} variables are black boxes to Automake since
5198 their values are not yet known when @command{automake} is run.
5199 Therefore if @option{-module} is set via such a variable, Automake
5200 cannot notice it and will proceed as if the library was an ordinary
5201 libtool library, with strict naming.
5203 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5204 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5206 @node Libtool Flags
5207 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5208 @cindex @code{_LIBADD}, libtool
5209 @cindex @code{_LDFLAGS}, libtool
5210 @cindex @code{_LIBTOOLFLAGS}, libtool
5211 @vindex AM_LIBTOOLFLAGS
5212 @vindex LIBTOOLFLAGS
5213 @vindex maude_LIBTOOLFLAGS
5215 As shown in previous sections, the @samp{@var{library}_LIBADD}
5216 variable should be used to list extra libtool objects (@file{.lo}
5217 files) or libtool libraries (@file{.la}) to add to @var{library}.
5219 The @samp{@var{library}_LDFLAGS} variable is the place to list
5220 additional libtool linking flags, such as @option{-version-info},
5221 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5222 libtool, The Libtool Manual}.
5224 The @command{libtool} command has two kinds of options: mode-specific
5225 options and generic options.  Mode-specific options such as the
5226 aforementioned linking flags should be lumped with the other flags
5227 passed to the tool invoked by @command{libtool} (hence the use of
5228 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5229 options include @option{--tag=@var{TAG}} and @option{--silent}
5230 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5231 Libtool Manual} for more options) should appear before the mode
5232 selection on the command line; in @file{Makefile.am}s they should
5233 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5235 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, the global
5236 @code{AM_LIBTOOLFLAGS} variable is used instead.
5238 These flags are passed to libtool after the @option{--tag=@var{TAG}}
5239 option computed by Automake (if any), so
5240 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is the
5241 good place to override or supplement the @option{--tag=@var{TAG}}
5242 setting.
5244 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5245 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5246 Variables Ordering}.  It allows users to run @samp{make
5247 LIBTOOLFLAGS=--silent}, for instance.
5250 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5251 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5252 @cindex @code{LTLIBOBJS}, special handling
5253 @cindex @code{LIBOBJS}, and Libtool
5254 @cindex @code{LTALLOCA}, special handling
5255 @cindex @code{ALLOCA}, and Libtool
5256 @vindex LTLIBOBJS
5257 @vindex LIBOBJS
5258 @vindex LTALLOCA
5259 @vindex ALLOCA
5260 @acindex AC_LIBOBJ
5262 Where an ordinary library might include @samp{$(LIBOBJS)} or
5263 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5264 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5265 the object files that libtool operates on do not necessarily end in
5266 @file{.o}.
5268 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5269 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5270 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5272 @node Libtool Issues
5273 @subsection Common Issues Related to Libtool's Use
5275 @subsubsection @samp{required file `./ltmain.sh' not found}
5276 @cindex @file{ltmain.sh} not found
5277 @cindex @command{libtoolize}, no longer run by @command{automake}
5278 @cindex @command{libtoolize} and @command{autoreconf}
5279 @cindex @command{autoreconf} and @command{libtoolize}
5280 @cindex @file{bootstrap.sh} and @command{autoreconf}
5281 @cindex @file{autogen.sh} and @command{autoreconf}
5283 Libtool comes with a tool called @command{libtoolize} that will
5284 install libtool's supporting files into a package.  Running this
5285 command will install @file{ltmain.sh}.  You should execute it before
5286 @command{aclocal} and @command{automake}.
5288 People upgrading old packages to newer autotools are likely to face
5289 this issue because older Automake versions used to call
5290 @command{libtoolize}.  Therefore old build scripts do not call
5291 @command{libtoolize}.
5293 Since Automake 1.6, it has been decided that running
5294 @command{libtoolize} was none of Automake's business.  Instead, that
5295 functionality has been moved into the @command{autoreconf} command
5296 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5297 The Autoconf Manual}).  If you do not want to remember what to run and
5298 when, just learn the @command{autoreconf} command.  Hopefully,
5299 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5300 a call to @command{autoreconf} should also free you from any similar
5301 incompatible change in the future.
5303 @subsubsection Objects @samp{created with both libtool and without}
5305 Sometimes, the same source file is used both to build a libtool
5306 library and to build another non-libtool target (be it a program or
5307 another library).
5309 Let's consider the following @file{Makefile.am}.
5311 @example
5312 bin_PROGRAMS = prog
5313 prog_SOURCES = prog.c foo.c @dots{}
5315 lib_LTLIBRARIES = libfoo.la
5316 libfoo_la_SOURCES = foo.c @dots{}
5317 @end example
5319 @noindent
5320 (In this trivial case the issue could be avoided by linking
5321 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5322 @code{prog_SOURCES}.  But let's assume we really want to keep
5323 @file{prog} and @file{libfoo.la} separate.)
5325 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5326 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5327 that in the course of creating @file{foo.lo}, libtool may erase (or
5328 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5330 Therefore, when Automake detects this situation it will complain
5331 with a message such as
5332 @example
5333 object `foo.$(OBJEXT)' created both with libtool and without
5334 @end example
5336 A workaround for this issue is to ensure that these two objects get
5337 different basenames.  As explained in @ref{renamed objects}, this
5338 happens automatically when per-targets flags are used.
5340 @example
5341 bin_PROGRAMS = prog
5342 prog_SOURCES = prog.c foo.c @dots{}
5343 prog_CFLAGS = $(AM_CFLAGS)
5345 lib_LTLIBRARIES = libfoo.la
5346 libfoo_la_SOURCES = foo.c @dots{}
5347 @end example
5349 @noindent
5350 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5351 when the @code{prog_CFLAGS} is defined, it is used instead of
5352 @code{AM_CFLAGS}.  However as a side effect it will cause
5353 @file{prog.c} and @file{foo.c} to be compiled as
5354 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5355 the issue.
5357 @node Program and Library Variables
5358 @section Program and Library Variables
5360 Associated with each program are a collection of variables that can be
5361 used to modify how that program is built.  There is a similar list of
5362 such variables for each library.  The canonical name of the program (or
5363 library) is used as a base for naming these variables.
5365 In the list below, we use the name ``maude'' to refer to the program or
5366 library.  In your @file{Makefile.am} you would replace this with the
5367 canonical name of your program.  This list also refers to ``maude'' as a
5368 program, but in general the same rules apply for both static and dynamic
5369 libraries; the documentation below notes situations where programs and
5370 libraries differ.
5372 @vtable @code
5373 @item maude_SOURCES
5374 This variable, if it exists, lists all the source files that are
5375 compiled to build the program.  These files are added to the
5376 distribution by default.  When building the program, Automake will cause
5377 each source file to be compiled to a single @file{.o} file (or
5378 @file{.lo} when using libtool).  Normally these object files are named
5379 after the source file, but other factors can change this.  If a file in
5380 the @code{_SOURCES} variable has an unrecognized extension, Automake
5381 will do one of two things with it.  If a suffix rule exists for turning
5382 files with the unrecognized extension into @file{.o} files, then
5383 automake will treat this file as it will any other source file
5384 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5385 ignored as though it were a header file.
5387 The prefixes @code{dist_} and @code{nodist_} can be used to control
5388 whether files listed in a @code{_SOURCES} variable are distributed.
5389 @code{dist_} is redundant, as sources are distributed by default, but it
5390 can be specified for clarity if desired.
5392 It is possible to have both @code{dist_} and @code{nodist_} variants of
5393 a given @code{_SOURCES} variable at once; this lets you easily
5394 distribute some files and not others, for instance:
5396 @example
5397 nodist_maude_SOURCES = nodist.c
5398 dist_maude_SOURCES = dist-me.c
5399 @end example
5401 By default the output file (on Unix systems, the @file{.o} file) will
5402 be put into the current build directory.  However, if the option
5403 @option{subdir-objects} is in effect in the current directory then the
5404 @file{.o} file will be put into the subdirectory named after the
5405 source file.  For instance, with @option{subdir-objects} enabled,
5406 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5407 people prefer this mode of operation.  You can specify
5408 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5409 @cindex Subdirectory, objects in
5410 @cindex Objects in subdirectory
5413 @item EXTRA_maude_SOURCES
5414 Automake needs to know the list of files you intend to compile
5415 @emph{statically}.  For one thing, this is the only way Automake has of
5416 knowing what sort of language support a given @file{Makefile.in}
5417 requires.  @footnote{There are other, more obscure reasons for
5418 this limitation as well.}  This means that, for example, you can't put a
5419 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5420 variable.  If you intend to conditionally compile source files and use
5421 @file{configure} to substitute the appropriate object names into, e.g.,
5422 @code{_LDADD} (see below), then you should list the corresponding source
5423 files in the @code{EXTRA_} variable.
5425 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5426 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5427 sources that may need to be built, but should not be distributed.
5429 @item maude_AR
5430 A static library is created by default by invoking @samp{$(AR)
5431 $(ARFLAGS)} followed by the name of the library and then the objects
5432 being put into the library.  You can override this by setting the
5433 @code{_AR} variable.  This is usually used with C++; some C++
5434 compilers require a special invocation in order to instantiate all the
5435 templates that should go into a library.  For instance, the SGI C++
5436 compiler likes this variable set like so:
5437 @example
5438 libmaude_a_AR = $(CXX) -ar -o
5439 @end example
5441 @item maude_LIBADD
5442 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5443 variable.  For instance, this should be used for objects determined by
5444 @command{configure} (@pxref{A Library}).
5446 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5447 to other libtool libraries.
5449 @item maude_LDADD
5450 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5451 @file{*.la}) can be added to a @emph{program} by listing them in the
5452 @code{_LDADD} variable.  For instance, this should be used for objects
5453 determined by @command{configure} (@pxref{Linking}).
5455 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5456 program-specific linker flags (except for @option{-l}, @option{-L},
5457 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5458 for this purpose.
5460 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5461 could link your program against the X libraries like so:
5463 @example
5464 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5465 @end example
5467 We recommend that you use @option{-l} and @option{-L} only when
5468 referring to third-party libraries, and give the explicit file names
5469 of any library built by your package.  Doing so will ensure that
5470 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5472 @item maude_LDFLAGS
5473 This variable is used to pass extra flags to the link step of a program
5474 or a shared library.  It overrides the global @code{AM_LDFLAGS} variable.
5476 @item maude_LIBTOOLFLAGS
5477 This variable is used to pass extra options to @command{libtool}.
5478 It overrides the global @code{AM_LIBTOOLFLAGS} variable.
5479 These options are output before @command{libtool}'s @option{--mode=@var{MODE}}
5480 option, so they should not be mode-specific options (those belong to
5481 the compiler or linker flags).  @xref{Libtool Flags}.
5483 @item maude_DEPENDENCIES
5484 It is also occasionally useful to have a target (program or library)
5485 depend on some other file that is not actually part of that target.
5486 This can be done using the @code{_DEPENDENCIES} variable.  Each
5487 targets depends on the contents of such a variable, but no further
5488 interpretation is done.
5490 Since these dependencies are associated to the link rule used to
5491 create the programs they should normally list files used by the link
5492 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5493 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5494 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5495 may need to add other kinds of files such as linker scripts, but
5496 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5497 some source file needs to be built before all the components of a
5498 program are built, consider using the @code{BUILT_SOURCES} variable
5499 (@pxref{Sources}).
5501 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5502 The automatically-assigned value is the contents of @code{_LDADD} or
5503 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5504 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5505 substitutions that are left in are only @samp{$(LIBOBJS)} and
5506 @samp{$(ALLOCA)}; these are left because it is known that they will not
5507 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5509 @code{_DEPENDENCIES} is more likely used to perform conditional
5510 compilation using an @code{AC_SUBST} variable that contains a list of
5511 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5512 Sources}.
5514 @item maude_LINK
5515 You can override the linker on a per-program basis.  By default the
5516 linker is chosen according to the languages used by the program.  For
5517 instance, a program that includes C++ source code would use the C++
5518 compiler to link.  The @code{_LINK} variable must hold the name of a
5519 command that can be passed all the @file{.o} file names as arguments.
5520 Note that the name of the underlying program is @emph{not} passed to
5521 @code{_LINK}; typically one uses @samp{$@@}:
5523 @example
5524 maude_LINK = $(CCLD) -magic -o $@@
5525 @end example
5527 @item maude_CCASFLAGS
5528 @itemx maude_CFLAGS
5529 @itemx maude_CPPFLAGS
5530 @itemx maude_CXXFLAGS
5531 @itemx maude_FFLAGS
5532 @itemx maude_GCJFLAGS
5533 @itemx maude_LFLAGS
5534 @itemx maude_OBJCFLAGS
5535 @itemx maude_RFLAGS
5536 @itemx maude_UPCFLAGS
5537 @itemx maude_YFLAGS
5538 @cindex per-target compilation flags, defined
5539 Automake allows you to set compilation flags on a per-program (or
5540 per-library) basis.  A single source file can be included in several
5541 programs, and it will potentially be compiled with different flags for
5542 each program.  This works for any language directly supported by
5543 Automake.  These @dfn{per-target compilation flags} are
5544 @samp{_CCASFLAGS},
5545 @samp{_CFLAGS},
5546 @samp{_CPPFLAGS},
5547 @samp{_CXXFLAGS},
5548 @samp{_FFLAGS},
5549 @samp{_GCJFLAGS},
5550 @samp{_LFLAGS},
5551 @samp{_OBJCFLAGS},
5552 @samp{_RFLAGS},
5553 @samp{_UPCFLAGS}, and
5554 @samp{_YFLAGS}.
5556 When using a per-target compilation flag, Automake will choose a
5557 different name for the intermediate object files.  Ordinarily a file
5558 like @file{sample.c} will be compiled to produce @file{sample.o}.
5559 However, if the program's @code{_CFLAGS} variable is set, then the
5560 object file will be named, for instance, @file{maude-sample.o}.  (See
5561 also @ref{renamed objects}.)  The use of per-target compilation flags
5562 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5563 from @file{configure.ac}.
5565 In compilations with per-target flags, the ordinary @samp{AM_} form of
5566 the flags variable is @emph{not} automatically included in the
5567 compilation (however, the user form of the variable @emph{is} included).
5568 So for instance, if you want the hypothetical @file{maude} compilations
5569 to also use the value of @code{AM_CFLAGS}, you would need to write:
5571 @example
5572 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5573 @end example
5575 @xref{Flag Variables Ordering}, for more discussion about the
5576 interaction between user variables, @samp{AM_} shadow variables, and
5577 per-target variables.
5579 @item maude_SHORTNAME
5580 On some platforms the allowable file names are very short.  In order to
5581 support these systems and per-target compilation flags at the same
5582 time, Automake allows you to set a ``short name'' that will influence
5583 how intermediate object files are named.  For instance, in the following
5584 example,
5586 @example
5587 bin_PROGRAMS = maude
5588 maude_CPPFLAGS = -DSOMEFLAG
5589 maude_SHORTNAME = m
5590 maude_SOURCES = sample.c @dots{}
5591 @end example
5593 @noindent
5594 the object file would be named @file{m-sample.o} rather than
5595 @file{maude-sample.o}.
5597 This facility is rarely needed in practice,
5598 and we recommend avoiding it until you find it is required.
5599 @end vtable
5601 @node Default _SOURCES
5602 @section Default @code{_SOURCES}
5604 @vindex _SOURCES
5605 @vindex SOURCES
5606 @cindex @code{_SOURCES}, default
5607 @cindex default @code{_SOURCES}
5609 @code{_SOURCES} variables are used to specify source files of programs
5610 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5611 libraries (@pxref{A Shared Library}).
5613 When no such variable is specified for a target, Automake will define
5614 one itself.  The default is to compile a single C file whose base name
5615 is the name of the target itself, with any extension replaced by
5616 @file{.c}.  (Defaulting to C is terrible but we are stuck with it for
5617 historical reasons.)
5619 For example if you have the following somewhere in your
5620 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5622 @example
5623 lib_LIBRARIES = libfoo.a sub/libc++.a
5624 @end example
5626 @noindent
5627 @file{libfoo.a} will be built using a default source file named
5628 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5629 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5630 would be built from @file{sub_libc___a.c}, i.e., the default source
5631 was the canonized name of the target, with @file{.c} appended.
5632 We believe the new behavior is more sensible, but for backward
5633 compatibility automake will use the old name if a file or a rule
5634 with that name exist.)
5636 @cindex @code{check_PROGRAMS} example
5637 @vindex check_PROGRAMS
5638 Default sources are mainly useful in test suites, when building many
5639 tests programs each from a single source.  For instance, in
5641 @example
5642 check_PROGRAMS = test1 test2 test3
5643 @end example
5645 @noindent
5646 @file{test1}, @file{test2}, and @file{test3} will be built
5647 from @file{test1.c}, @file{test2.c}, and @file{test3.c}.
5649 @cindex Libtool modules, default source example
5650 @cindex default source, Libtool modules example
5651 Another case where is this convenient is building many Libtool modules
5652 (@file{moduleN.la}), each defined in its own file (@file{moduleN.c}).
5654 @example
5655 AM_LDFLAGS = -module
5656 lib_LTLIBRARIES = module1.la module2.la module3.la
5657 @end example
5659 @cindex empty @code{_SOURCES}
5660 @cindex @code{_SOURCES}, empty
5661 Finally, there is one situation where this default source computation
5662 needs to be avoided: when a target should not be built from sources.
5663 We already saw such an example in @ref{true}; this happens when all
5664 the constituents of a target have already been compiled and need just
5665 to be combined using a @code{_LDADD} variable.  Then it is necessary
5666 to define an empty @code{_SOURCES} variable, so that automake does not
5667 compute a default.
5669 @example
5670 bin_PROGRAMS = target
5671 target_SOURCES =
5672 target_LDADD = libmain.a libmisc.a
5673 @end example
5675 @node LIBOBJS
5676 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5678 @cindex @code{LIBOBJS}, example
5679 @cindex @code{ALLOCA}, example
5680 @cindex @code{LIBOBJS}, special handling
5681 @cindex @code{ALLOCA}, special handling
5682 @vindex LTLIBOBJS
5683 @vindex LIBOBJS
5684 @vindex LTALLOCA
5685 @vindex ALLOCA
5687 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5688 files that should be compiled into the project to provide an
5689 implementation for functions that are missing or broken on the host
5690 system.  They are substituted by @file{configure}.
5692 @acindex AC_LIBOBJ
5694 These variables are defined by Autoconf macros such as
5695 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5696 Generic Function Checks, autoconf, The Autoconf Manual}), or
5697 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5698 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5699 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5700 populate @samp{$(LIBOBJS)}.
5702 @acindex AC_LIBSOURCE
5704 Using these variables is very similar to doing conditional compilation
5705 using @code{AC_SUBST} variables, as described in @ref{Conditional
5706 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5707 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5708 variable, or to the @samp{*_LIBADD} variable when building a library.
5709 However there is no need to list the corresponding sources in
5710 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5711 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5712 dependencies, and it will discover the list of corresponding source
5713 files automatically (by tracing the invocations of the
5714 @code{AC_LIBSOURCE} Autoconf macros).
5716 These variables are usually used to build a portability library that
5717 is linked with all the programs of the project.  We now review a
5718 sample setup.  First, @file{configure.ac} contains some checks that
5719 affect either @code{LIBOBJS} or @code{ALLOCA}.
5721 @example
5722 # configure.ac
5723 @dots{}
5724 AC_CONFIG_LIBOBJ_DIR([lib])
5725 @dots{}
5726 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5727 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5728 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5729 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5730 @dots{}
5731 AC_CONFIG_FILES([
5732   lib/Makefile
5733   src/Makefile
5735 AC_OUTPUT
5736 @end example
5738 @acindex AC_CONFIG_LIBOBJ_DIR
5740 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
5741 of these object files are to be found in the @file{lib/} directory.
5742 Automake can also use this information, otherwise it expects the
5743 source files are to be in the directory where the @samp{$(LIBOBJS)}
5744 and @samp{$(ALLOCA)} variables are used.
5746 The @file{lib/} directory should therefore contain @file{malloc.c},
5747 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
5748 @file{Makefile.am}:
5750 @example
5751 # lib/Makefile.am
5753 noinst_LIBRARIES = libcompat.a
5754 libcompat_a_SOURCES =
5755 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5756 @end example
5758 The library can have any name, of course, and anyway it is not going
5759 to be installed: it just holds the replacement versions of the missing
5760 or broken functions so we can later link them in.  In many projects
5761 also include extra functions, specific to the project, in that
5762 library: they are simply added on the @code{_SOURCES} line.
5764 @cindex Empty libraries and @samp{$(LIBOBJS)}
5765 @cindex @samp{$(LIBOBJS)} and empty libraries
5766 There is a small trap here, though: @samp{$(LIBOBJS)} and
5767 @samp{$(ALLOCA)} might be empty, and building an empty library is not
5768 portable.  You should ensure that there is always something to put in
5769 @file{libcompat.a}.  Most projects will also add some utility
5770 functions in that directory, and list them in
5771 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
5772 be empty.
5774 Finally here is how this library could be used from the @file{src/}
5775 directory.
5777 @example
5778 # src/Makefile.am
5780 # Link all programs in this directory with libcompat.a
5781 LDADD = ../lib/libcompat.a
5783 bin_PROGRAMS = tool1 tool2 @dots{}
5784 tool1_SOURCES = @dots{}
5785 tool2_SOURCES = @dots{}
5786 @end example
5788 When option @option{subdir-objects} is not used, as in the above
5789 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
5790 be used in the directory where their sources lie.  E.g., here it would
5791 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
5792 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
5793 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
5794 in other directories.  For instance @file{src/Makefile.am} could be
5795 changed as follows.
5797 @example
5798 # src/Makefile.am
5800 AUTOMAKE_OPTIONS = subdir-objects
5801 LDADD = $(LIBOBJS) $(ALLOCA)
5803 bin_PROGRAMS = tool1 tool2 @dots{}
5804 tool1_SOURCES = @dots{}
5805 tool2_SOURCES = @dots{}
5806 @end example
5808 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
5809 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
5810 Libtool libraries (where the expected object extension is @file{.lo}):
5811 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
5813 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
5814 be defined by hand (as in the past), however at the time of writing
5815 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
5816 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
5817 autoconf, The Autoconf Manual}.
5820 @node Program variables
5821 @section Variables used when building a program
5823 Occasionally it is useful to know which @file{Makefile} variables
5824 Automake uses for compilations; for instance, you might need to do your
5825 own compilation in some special cases.
5827 Some variables are inherited from Autoconf; these are @code{CC},
5828 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
5829 @code{LIBS}.
5830 @vindex CC
5831 @vindex CFLAGS
5832 @vindex CPPFLAGS
5833 @vindex DEFS
5834 @vindex LDFLAGS
5835 @vindex LIBS
5837 There are some additional variables that Automake defines on its own:
5839 @vtable @code
5840 @item AM_CPPFLAGS
5841 The contents of this variable are passed to every compilation that invokes
5842 the C preprocessor; it is a list of arguments to the preprocessor.  For
5843 instance, @option{-I} and @option{-D} options should be listed here.
5845 Automake already provides some @option{-I} options automatically.  In
5846 particular it generates @samp{-I$(srcdir)}, @samp{-I.}, and a
5847 @option{-I} pointing to the directory holding @file{config.h} (if
5848 you've used @code{AC_CONFIG_HEADERS} or @code{AM_CONFIG_HEADER}).  You
5849 can disable the default @option{-I} options using the
5850 @option{nostdinc} option.
5852 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
5853 per-library) @code{_CPPFLAGS} variable if it is defined.
5855 @item INCLUDES
5856 This does the same job as @code{AM_CPPFLAGS} (or any per-target
5857 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
5858 same functionality.  This variable is deprecated; we suggest using
5859 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
5861 @item AM_CFLAGS
5862 This is the variable the @file{Makefile.am} author can use to pass
5863 in additional C compiler flags.  It is more fully documented elsewhere.
5864 In some situations, this is not used, in preference to the
5865 per-executable (or per-library) @code{_CFLAGS}.
5867 @item COMPILE
5868 This is the command used to actually compile a C source file.  The
5869 file name is appended to form the complete command line.
5871 @item AM_LDFLAGS
5872 This is the variable the @file{Makefile.am} author can use to pass
5873 in additional linker flags.  In some situations, this is not used, in
5874 preference to the per-executable (or per-library) @code{_LDFLAGS}.
5876 @item LINK
5877 This is the command used to actually link a C program.  It already
5878 includes @samp{-o $@@} and the usual variable references (for instance,
5879 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
5880 and libraries to link in.
5881 @end vtable
5884 @node Yacc and Lex
5885 @section Yacc and Lex support
5887 Automake has somewhat idiosyncratic support for Yacc and Lex.
5889 Automake assumes that the @file{.c} file generated by @command{yacc}
5890 (or @command{lex}) should be named using the basename of the input
5891 file.  That is, for a yacc source file @file{foo.y}, Automake will
5892 cause the intermediate file to be named @file{foo.c} (as opposed to
5893 @file{y.tab.c}, which is more traditional).
5895 The extension of a yacc source file is used to determine the extension
5896 of the resulting C or C++ file.  Files with the extension @file{.y}
5897 will be turned into @file{.c} files; likewise, @file{.yy} will become
5898 @file{.cc}; @file{.y++}, @file{c++}; @file{.yxx}, @file{.cxx}; and
5899 @file{.ypp}, @file{.cpp}.
5901 Likewise, lex source files can be used to generate C or C++; the
5902 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
5903 @file{.lpp} are recognized.
5905 You should never explicitly mention the intermediate (C or C++) file
5906 in any @code{SOURCES} variable; only list the source file.
5908 The intermediate files generated by @command{yacc} (or @command{lex})
5909 will be included in any distribution that is made.  That way the user
5910 doesn't need to have @command{yacc} or @command{lex}.
5912 If a @command{yacc} source file is seen, then your @file{configure.ac} must
5913 define the variable @code{YACC}.  This is most easily done by invoking
5914 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
5915 Program Checks, autoconf, The Autoconf Manual}).
5917 @vindex YFLAGS
5918 @vindex AM_YFLAGS
5919 When @code{yacc} is invoked, it is passed @code{YFLAGS} and
5920 @code{AM_YFLAGS}.  The former is a user variable and the latter is
5921 intended for the @file{Makefile.am} author.
5923 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
5924 @command{yacc}.  Automake knows what this means and will automatically
5925 adjust its rules to update and distribute the header file built by
5926 @samp{yacc -d}.  What Automake cannot guess, though, is where this
5927 header will be used: it is up to you to ensure the header gets built
5928 before it is first used.  Typically this is necessary in order for
5929 dependency tracking to work when the header is included by another
5930 file.  The common solution is listing the header file in
5931 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
5933 @example
5934 BUILT_SOURCES = parser.h
5935 AM_YFLAGS = -d
5936 bin_PROGRAMS = foo
5937 foo_SOURCES = @dots{} parser.y @dots{}
5938 @end example
5940 If a @command{lex} source file is seen, then your @file{configure.ac}
5941 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
5942 to do this (@pxref{Particular Programs, , Particular Program Checks,
5943 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
5944 (@pxref{Macros}) is recommended.
5946 @vindex LFLAGS
5947 @vindex AM_LFLAGS
5948 When @command{lex} is invoked, it is passed @code{LFLAGS} and
5949 @code{AM_LFLAGS}.  The former is a user variable and the latter is
5950 intended for the @file{Makefile.am} author.
5952 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
5953 rebuild rule for distributed Yacc and Lex sources are only used when
5954 @code{maintainer-mode} is enabled, or when the files have been erased.
5957 @cindex @command{ylwrap}
5958 @cindex @command{yacc}, multiple parsers
5959 @cindex Multiple @command{yacc} parsers
5960 @cindex Multiple @command{lex} lexers
5961 @cindex @command{lex}, multiple lexers
5964 Automake makes it possible to include multiple @command{yacc} (or
5965 @command{lex}) source files in a single program.  When there is more
5966 than one distinct @command{yacc} (or @command{lex}) source file in a
5967 directory, Automake uses a small program called @command{ylwrap} to run
5968 @command{yacc} (or @command{lex}) in a subdirectory.  This is
5969 necessary because yacc's output file name is fixed, and a parallel
5970 make could conceivably invoke more than one instance of @command{yacc}
5971 simultaneously.  The @command{ylwrap} program is distributed with
5972 Automake.  It should appear in the directory specified by
5973 @code{AC_CONFIG_AUX_DIR}, or one of its default locations
5974 (@pxref{Input, , Finding `configure' Input, autoconf, The Autoconf
5975 Manual}).
5977 For @command{yacc}, simply managing locking is insufficient.  The output of
5978 @command{yacc} always uses the same symbol names internally, so it isn't
5979 possible to link two @command{yacc} parsers into the same executable.
5981 We recommend using the following renaming hack used in @command{gdb}:
5982 @example
5983 #define yymaxdepth c_maxdepth
5984 #define yyparse c_parse
5985 #define yylex   c_lex
5986 #define yyerror c_error
5987 #define yylval  c_lval
5988 #define yychar  c_char
5989 #define yydebug c_debug
5990 #define yypact  c_pact
5991 #define yyr1    c_r1
5992 #define yyr2    c_r2
5993 #define yydef   c_def
5994 #define yychk   c_chk
5995 #define yypgo   c_pgo
5996 #define yyact   c_act
5997 #define yyexca  c_exca
5998 #define yyerrflag c_errflag
5999 #define yynerrs c_nerrs
6000 #define yyps    c_ps
6001 #define yypv    c_pv
6002 #define yys     c_s
6003 #define yy_yys  c_yys
6004 #define yystate c_state
6005 #define yytmp   c_tmp
6006 #define yyv     c_v
6007 #define yy_yyv  c_yyv
6008 #define yyval   c_val
6009 #define yylloc  c_lloc
6010 #define yyreds  c_reds
6011 #define yytoks  c_toks
6012 #define yylhs   c_yylhs
6013 #define yylen   c_yylen
6014 #define yydefred c_yydefred
6015 #define yydgoto c_yydgoto
6016 #define yysindex c_yysindex
6017 #define yyrindex c_yyrindex
6018 #define yygindex c_yygindex
6019 #define yytable  c_yytable
6020 #define yycheck  c_yycheck
6021 #define yyname   c_yyname
6022 #define yyrule   c_yyrule
6023 @end example
6025 For each define, replace the @samp{c_} prefix with whatever you like.
6026 These defines work for @command{bison}, @command{byacc}, and
6027 traditional @code{yacc}s.  If you find a parser generator that uses a
6028 symbol not covered here, please report the new name so it can be added
6029 to the list.
6032 @node C++ Support
6033 @section C++ Support
6035 @cindex C++ support
6036 @cindex Support for C++
6038 Automake includes full support for C++.
6040 Any package including C++ code must define the output variable
6041 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6042 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6043 Program Checks, autoconf, The Autoconf Manual}).
6045 A few additional variables are defined when a C++ source file is seen:
6047 @vtable @code
6048 @item CXX
6049 The name of the C++ compiler.
6051 @item CXXFLAGS
6052 Any flags to pass to the C++ compiler.
6054 @item AM_CXXFLAGS
6055 The maintainer's variant of @code{CXXFLAGS}.
6057 @item CXXCOMPILE
6058 The command used to actually compile a C++ source file.  The file name
6059 is appended to form the complete command line.
6061 @item CXXLINK
6062 The command used to actually link a C++ program.
6063 @end vtable
6066 @node Objective C Support
6067 @section Objective C Support
6069 @cindex Objective C support
6070 @cindex Support for Objective C
6072 Automake includes some support for Objective C.
6074 Any package including Objective C code must define the output variable
6075 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6076 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6077 Program Checks, autoconf, The Autoconf Manual}).
6079 A few additional variables are defined when an Objective C source file
6080 is seen:
6082 @vtable @code
6083 @item OBJC
6084 The name of the Objective C compiler.
6086 @item OBJCFLAGS
6087 Any flags to pass to the Objective C compiler.
6089 @item AM_OBJCFLAGS
6090 The maintainer's variant of @code{OBJCFLAGS}.
6092 @item OBJCCOMPILE
6093 The command used to actually compile a Objective C source file.  The
6094 file name is appended to form the complete command line.
6096 @item OBJCLINK
6097 The command used to actually link a Objective C program.
6098 @end vtable
6101 @node Unified Parallel C Support
6102 @section Unified Parallel C Support
6104 @cindex Unified Parallel C support
6105 @cindex Support for Unified Parallel C
6107 Automake includes some support for Unified Parallel C.
6109 Any package including Unified Parallel C code must define the output
6110 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6111 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public macros}).
6113 A few additional variables are defined when an Unified Parallel C
6114 source file is seen:
6116 @vtable @code
6117 @item UPC
6118 The name of the Unified Parallel C compiler.
6120 @item UPCFLAGS
6121 Any flags to pass to the Unified Parallel C compiler.
6123 @item AM_UPCFLAGS
6124 The maintainer's variant of @code{UPCFLAGS}.
6126 @item UPCCOMPILE
6127 The command used to actually compile a Unified Parallel C source file.
6128 The file name is appended to form the complete command line.
6130 @item UPCLINK
6131 The command used to actually link a Unified Parallel C program.
6132 @end vtable
6135 @node Assembly Support
6136 @section Assembly Support
6138 Automake includes some support for assembly code.  There are two forms
6139 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6140 (@file{*.S}).
6142 @vindex CCAS
6143 @vindex CCASFLAGS
6144 @vindex CPPFLAGS
6145 @vindex AM_CCASFLAGS
6146 @vindex AM_CPPFLAGS
6147 The variable @code{CCAS} holds the name of the compiler used to build
6148 assembly code.  This compiler must work a bit like a C compiler; in
6149 particular it must accept @option{-c} and @option{-o}.  The values of
6150 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6151 definition) is passed to the compilation.  For preprocessed files,
6152 @code{CPPFLAGS} and @code{AM_CPPFLAGS} are also used.
6154 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6155 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6156 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6157 flags), but you are free to define these variables by other means.
6159 Only the suffixes @file{.s} and @file{.S} are recognized by
6160 @command{automake} as being files containing assembly code.
6163 @node Fortran 77 Support
6164 @comment  node-name,  next,  previous,  up
6165 @section Fortran 77 Support
6167 @cindex Fortran 77 support
6168 @cindex Support for Fortran 77
6170 Automake includes full support for Fortran 77.
6172 Any package including Fortran 77 code must define the output variable
6173 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6174 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6175 Program Checks, autoconf, The Autoconf Manual}).
6177 A few additional variables are defined when a Fortran 77 source file is
6178 seen:
6180 @vtable @code
6182 @item F77
6183 The name of the Fortran 77 compiler.
6185 @item FFLAGS
6186 Any flags to pass to the Fortran 77 compiler.
6188 @item AM_FFLAGS
6189 The maintainer's variant of @code{FFLAGS}.
6191 @item RFLAGS
6192 Any flags to pass to the Ratfor compiler.
6194 @item AM_RFLAGS
6195 The maintainer's variant of @code{RFLAGS}.
6197 @item F77COMPILE
6198 The command used to actually compile a Fortran 77 source file.  The file
6199 name is appended to form the complete command line.
6201 @item FLINK
6202 The command used to actually link a pure Fortran 77 program or shared
6203 library.
6205 @end vtable
6207 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6208 addition to compiling them@footnote{Much, if not most, of the
6209 information in the following sections pertaining to preprocessing
6210 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6211 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6212 also contains some support for creating programs and shared libraries
6213 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6214 Fortran 77 With C and C++}).
6216 These issues are covered in the following sections.
6218 @menu
6219 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6220 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6221 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6222 @end menu
6225 @node Preprocessing Fortran 77
6226 @comment  node-name,  next,  previous,  up
6227 @subsection Preprocessing Fortran 77
6229 @cindex Preprocessing Fortran 77
6230 @cindex Fortran 77, Preprocessing
6231 @cindex Ratfor programs
6233 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6234 rule runs just the preprocessor to convert a preprocessable Fortran 77
6235 or Ratfor source file into a strict Fortran 77 source file.  The precise
6236 command used is as follows:
6238 @table @file
6240 @item .F
6241 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6242 $(AM_FFLAGS) $(FFLAGS)}
6244 @item .r
6245 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6247 @end table
6250 @node Compiling Fortran 77 Files
6251 @comment  node-name,  next,  previous,  up
6252 @subsection Compiling Fortran 77 Files
6254 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6255 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6256 is as follows:
6258 @table @file
6260 @item .f
6261 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6263 @item .F
6264 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6265 $(AM_FFLAGS) $(FFLAGS)}
6267 @item .r
6268 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6270 @end table
6273 @node Mixing Fortran 77 With C and C++
6274 @comment  node-name,  next,  previous,  up
6275 @subsection Mixing Fortran 77 With C and C++
6277 @cindex Fortran 77, mixing with C and C++
6278 @cindex Mixing Fortran 77 with C and C++
6279 @cindex Linking Fortran 77 with C and C++
6280 @cindex cfortran
6281 @cindex Mixing Fortran 77 with C and/or C++
6283 Automake currently provides @emph{limited} support for creating programs
6284 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6285 However, there are many other issues related to mixing Fortran 77 with
6286 other languages that are @emph{not} (currently) handled by Automake, but
6287 that are handled by other packages@footnote{For example,
6288 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6289 addresses all of these inter-language issues, and runs under nearly all
6290 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6291 @command{cfortran} is not yet Free Software, but it will be in the next
6292 major release.}.
6294 @page
6295 Automake can help in two ways:
6297 @enumerate
6298 @item
6299 Automatic selection of the linker depending on which combinations of
6300 source code.
6302 @item
6303 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6304 @option{-l}) to pass to the automatically selected linker in order to link
6305 in the appropriate Fortran 77 intrinsic and run-time libraries.
6307 @cindex @code{FLIBS}, defined
6308 @vindex FLIBS
6309 These extra Fortran 77 linker flags are supplied in the output variable
6310 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
6311 supplied with newer versions of Autoconf (Autoconf version 2.13 and
6312 later).  @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
6313 Autoconf}.
6314 @end enumerate
6316 If Automake detects that a program or shared library (as mentioned in
6317 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6318 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6319 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6320 @file{configure.ac}, and that either @code{$(FLIBS)}
6321 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6322 (for shared libraries) variables.  It is the responsibility of the
6323 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6324 appears in the appropriate @code{_LDADD} or
6325 @code{_LIBADD} variable.
6327 @cindex Mixed language example
6328 @cindex Example, mixed language
6330 For example, consider the following @file{Makefile.am}:
6332 @example
6333 bin_PROGRAMS = foo
6334 foo_SOURCES  = main.cc foo.f
6335 foo_LDADD    = libfoo.la $(FLIBS)
6337 pkglib_LTLIBRARIES = libfoo.la
6338 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6339 libfoo_la_LIBADD   = $(FLIBS)
6340 @end example
6342 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6343 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6344 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6345 Automake would have issued a warning.
6348 @page
6349 @menu
6350 * How the Linker is Chosen::    Automatic linker selection
6351 @end menu
6353 @node How the Linker is Chosen
6354 @comment  node-name,  next,  previous,  up
6355 @subsubsection How the Linker is Chosen
6357 @cindex Automatic linker selection
6358 @cindex Selecting the linker automatically
6360 When a program or library mixes several languages, Automake choose the
6361 linker according to the following priorities.  (The names in
6362 parentheses are the variables containing the link command.)
6364 @enumerate
6365 @item
6366 @vindex GCJLINK
6367 Native Java (@code{GCJLINK})
6368 @item
6369 @vindex CXXLINK
6370 C++ (@code{CXXLINK})
6371 @item
6372 @vindex F77LINK
6373 Fortran 77 (@code{F77LINK})
6374 @item
6375 @vindex FCLINK
6376 Fortran (@code{FCLINK})
6377 @item
6378 @vindex OBJCLINK
6379 Objective C (@code{OBJCLINK})
6380 @item
6381 @vindex UPCLINK
6382 Unified Parallel C (@code{UPCLINK})
6383 @item
6384 @vindex LINK
6385 C (@code{LINK})
6386 @end enumerate
6388 For example, if Fortran 77, C and C++ source code is compiled
6389 into a program, then the C++ linker will be used.  In this case, if the
6390 C or Fortran 77 linkers required any special libraries that weren't
6391 included by the C++ linker, then they must be manually added to an
6392 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6393 @file{Makefile.am}.
6395 Automake only looks at the file names listed in @file{_SOURCES}
6396 variables to choose the linker, and defaults to the C linker.
6397 Sometimes this is inconvenient because you are linking against a
6398 library written in another language and would like to set the linker
6399 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6400 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6403 @node Fortran 9x Support
6404 @comment  node-name,  next,  previous,  up
6405 @section Fortran 9x Support
6407 @cindex Fortran 9x support
6408 @cindex Support for Fortran 9x
6410 Automake includes full support for Fortran 9x.
6412 Any package including Fortran 9x code must define the output variable
6413 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6414 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6415 Program Checks, autoconf, The Autoconf Manual}).
6417 A few additional variables are defined when a Fortran 9x source file is
6418 seen:
6420 @vtable @code
6422 @item FC
6423 The name of the Fortran 9x compiler.
6425 @item FCFLAGS
6426 Any flags to pass to the Fortran 9x compiler.
6428 @item AM_FCFLAGS
6429 The maintainer's variant of @code{FCFLAGS}.
6431 @item FCCOMPILE
6432 The command used to actually compile a Fortran 9x source file.  The file
6433 name is appended to form the complete command line.
6435 @item FCLINK
6436 The command used to actually link a pure Fortran 9x program or shared
6437 library.
6439 @end vtable
6441 @menu
6442 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6443 @end menu
6445 @node Compiling Fortran 9x Files
6446 @comment  node-name,  next,  previous,  up
6447 @subsection Compiling Fortran 9x Files
6449 @file{N.o} is made automatically from @file{N.f90} or @file{N.f95}
6450 by running the Fortran 9x compiler.  The precise command used
6451 is as follows:
6453 @table @file
6455 @item .f9x
6456 @code{$(FC) -c $(AM_FCFLAGS) $(FCFLAGS)}
6458 @end table
6460 @node Java Support
6461 @comment  node-name,  next,  previous,  up
6462 @section Java Support
6464 @cindex Java support
6465 @cindex Support for Java
6467 Automake includes support for compiled Java, using @command{gcj}, the Java
6468 front end to the GNU Compiler Collection.
6470 Any package including Java code to be compiled must define the output
6471 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6472 must also be defined somehow (either in @file{configure.ac} or
6473 @file{Makefile.am}).  The simplest way to do this is to use the
6474 @code{AM_PROG_GCJ} macro.
6476 @vindex GCJFLAGS
6478 By default, programs including Java source files are linked with
6479 @command{gcj}.
6481 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6482 compilation invoking @command{gcj} (in its role as an ahead-of-time
6483 compiler, when invoking it to create @file{.class} files,
6484 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6485 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6486 the user variable @code{GCJFLAGS}, should be used.
6488 @vindex AM_GCJFLAGS
6490 @command{gcj} can be used to compile @file{.java}, @file{.class},
6491 @file{.zip}, or @file{.jar} files.
6493 When linking, @command{gcj} requires that the main class be specified
6494 using the @option{--main=} option.  The easiest way to do this is to use
6495 the @code{_LDFLAGS} variable for the program.
6498 @node Support for Other Languages
6499 @comment  node-name,  next,  previous,  up
6500 @section Support for Other Languages
6502 Automake currently only includes full support for C, C++ (@pxref{C++
6503 Support}), Objective C (@pxref{Objective C Support}), Fortran 77
6504 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6505 and Java (@pxref{Java Support}).  There is only rudimentary support for other
6506 languages, support for which will be improved based on user demand.
6508 Some limited support for adding your own languages is available via the
6509 suffix rule handling (@pxref{Suffixes}).
6512 @node ANSI
6513 @section Automatic de-ANSI-fication
6515 @cindex de-ANSI-fication, defined
6517 Although the GNU standards allow the use of ANSI C, this can have the
6518 effect of limiting portability of a package to some older compilers
6519 (notably the SunOS C compiler).
6521 Automake allows you to work around this problem on such machines by
6522 @dfn{de-ANSI-fying} each source file before the actual compilation takes
6523 place.
6525 @vindex AUTOMAKE_OPTIONS
6526 @opindex ansi2knr
6528 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
6529 (@pxref{Options}) contains the option @option{ansi2knr} then code to
6530 handle de-ANSI-fication is inserted into the generated
6531 @file{Makefile.in}.
6533 This causes each C source file in the directory to be treated as ANSI C@.
6534 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
6535 is available, the @command{ansi2knr} program is used to convert the source
6536 files into K&R C, which is then compiled.
6538 The @command{ansi2knr} program is simple-minded.  It assumes the source
6539 code will be formatted in a particular way; see the @command{ansi2knr} man
6540 page for details.
6542 @acindex AM_C_PROTOTYPES
6543 Support for de-ANSI-fication requires the source files @file{ansi2knr.c}
6544 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
6545 these files are distributed with Automake.  Also, the package
6546 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
6547 (@pxref{Macros}).
6549 Automake also handles finding the @command{ansi2knr} support files in some
6550 other directory in the current package.  This is done by prepending the
6551 relative path to the appropriate directory to the @command{ansi2knr}
6552 option.  For instance, suppose the package has ANSI C code in the
6553 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
6554 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
6555 @file{src/Makefile.am}:
6557 @example
6558 AUTOMAKE_OPTIONS = ../lib/ansi2knr
6559 @end example
6561 If no directory prefix is given, the files are assumed to be in the
6562 current directory.
6564 Note that automatic de-ANSI-fication will not work when the package is
6565 being built for a different host architecture.  That is because automake
6566 currently has no way to build @command{ansi2knr} for the build machine.
6568 @c FIXME: this paragraph might be better moved to an `upgrading' section.
6569 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
6570 @cindex @code{LIBOBJS} and @code{ansi2knr}
6571 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
6572 @cindex @code{ansi2knr} and @code{LIBOBJS}
6573 Using @code{LIBOBJS} with source de-ANSI-fication used to require
6574 hand-crafted code in @file{configure} to append @samp{$U} to basenames
6575 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
6576 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
6577 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
6578 vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual})
6580 @node Dependencies
6581 @section Automatic dependency tracking
6583 As a developer it is often painful to continually update the
6584 @file{Makefile.in} whenever the include-file dependencies change in a
6585 project.  Automake supplies a way to automatically track dependency
6586 changes (@pxref{Dependency Tracking}).
6588 @cindex Dependency tracking
6589 @cindex Automatic dependency tracking
6591 Automake always uses complete dependencies for a compilation,
6592 including system headers.  Automake's model is that dependency
6593 computation should be a side effect of the build.  To this end,
6594 dependencies are computed by running all compilations through a
6595 special wrapper program called @command{depcomp}.  @command{depcomp}
6596 understands how to coax many different C and C++ compilers into
6597 generating dependency information in the format it requires.
6598 @samp{automake -a} will install @command{depcomp} into your source
6599 tree for you.  If @command{depcomp} can't figure out how to properly
6600 invoke your compiler, dependency tracking will simply be disabled for
6601 your build.
6603 @cindex @command{depcomp}
6605 Experience with earlier versions of Automake (@pxref{Dependency
6606 Tracking Evolution}) taught us that it is not reliable to generate
6607 dependencies only on the maintainer's system, as configurations vary
6608 too much.  So instead Automake implements dependency tracking at build
6609 time.
6611 Automatic dependency tracking can be suppressed by putting
6612 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6613 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6614 (this should be the preferred way).  Or, you can invoke @command{automake}
6615 with the @option{-i} option.  Dependency tracking is enabled by default.
6617 @vindex AUTOMAKE_OPTIONS
6618 @opindex no-dependencies
6620 The person building your package also can choose to disable dependency
6621 tracking by configuring with @option{--disable-dependency-tracking}.
6623 @cindex Disabling dependency tracking
6624 @cindex Dependency tracking, disabling
6627 @node EXEEXT
6628 @section Support for executable extensions
6630 @cindex Executable extension
6631 @cindex Extension, executable
6632 @cindex Windows
6634 On some platforms, such as Windows, executables are expected to have an
6635 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6636 among them) will automatically generate @file{foo.exe} when asked to
6637 generate @file{foo}.
6639 Automake provides mostly-transparent support for this.  Unfortunately
6640 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6641 dictionary is revised, you will have to assist Automake if your package
6642 must support those platforms.
6644 One thing you must be aware of is that, internally, Automake rewrites
6645 something like this:
6647 @example
6648 bin_PROGRAMS = liver
6649 @end example
6651 to this:
6653 @example
6654 bin_PROGRAMS = liver$(EXEEXT)
6655 @end example
6657 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6658 extension.
6660 The variable @code{TESTS} (@pxref{Tests}) is also rewritten if it
6661 contains filenames that have been declared as programs in the same
6662 @file{Makefile}.  (This is mostly useful when some programs from
6663 @code{check_PROGRAMS} are listed in @code{TESTS}.)
6665 However, Automake cannot apply this rewriting to @command{configure}
6666 substitutions.  This means that if you are conditionally building a
6667 program using such a substitution, then your @file{configure.ac} must
6668 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6670 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
6671 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
6672 automatically if you configure a compiler (say, through
6673 @code{AC_PROG_CC}).
6675 Sometimes maintainers like to write an explicit link rule for their
6676 program.  Without executable extension support, this is easy---you
6677 simply write a rule whose target is the name of the program.  However,
6678 when executable extension support is enabled, you must instead add the
6679 @samp{$(EXEEXT)} suffix.
6681 Unfortunately, due to the change in Autoconf 2.50, this means you must
6682 always add this extension.  However, this is a problem for maintainers
6683 who know their package will never run on a platform that has
6684 executable extensions.  For those maintainers, the @option{no-exeext}
6685 option (@pxref{Options}) will disable this feature.  This works in a
6686 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6687 rule for a target named @code{foo} in @file{Makefile.am} will override
6688 an automake-generated rule for @samp{foo$(EXEEXT)}.  Without
6689 the @option{no-exeext} option, this use will give a diagnostic.
6692 @node Other objects
6693 @chapter Other Derived Objects
6695 Automake can handle derived objects that are not C programs.  Sometimes
6696 the support for actually building such objects must be explicitly
6697 supplied, but Automake will still automatically handle installation and
6698 distribution.
6700 @menu
6701 * Scripts::                     Executable scripts
6702 * Headers::                     Header files
6703 * Data::                        Architecture-independent data files
6704 * Sources::                     Derived sources
6705 @end menu
6708 @node Scripts
6709 @section Executable Scripts
6711 @cindex @code{_SCRIPTS} primary, defined
6712 @cindex @code{SCRIPTS} primary, defined
6713 @cindex Primary variable, @code{SCRIPTS}
6714 @vindex _SCRIPTS
6715 @cindex Installing scripts
6717 It is possible to define and install programs that are scripts.  Such
6718 programs are listed using the @code{SCRIPTS} primary name.  When the
6719 script is distributed in its final, installable form, the
6720 @file{Makefile} usually looks as follows:
6721 @vindex SCRIPTS
6723 @example
6724 # Install my_script in $(bindir) and distribute it.
6725 dist_bin_SCRIPTS = my_script
6726 @end example
6728 Script are not distributed by default; as we have just seen, those
6729 that should be distributed can be specified using a @code{dist_}
6730 prefix as with other primaries.
6732 @cindex @code{SCRIPTS}, installation directories
6733 @vindex bin_SCRIPTS
6734 @vindex sbin_SCRIPTS
6735 @vindex libexec_SCRIPTS
6736 @vindex pkgdata_SCRIPTS
6737 @vindex noinst_SCRIPTS
6738 @vindex check_SCRIPTS
6740 Scripts can be installed in @code{bindir}, @code{sbindir},
6741 @code{libexecdir}, or @code{pkgdatadir}.
6743 Scripts that need not being installed can be listed in
6744 @code{noinst_SCRIPTS}, and among them, those which are needed only by
6745 @samp{make check} should go in @code{check_SCRIPTS}.
6747 When a script needs to be built, the @file{Makefile.am} should include
6748 the appropriate rules.  For instance the @command{automake} program
6749 itself is a Perl script that is generated from @file{automake.in}.
6750 Here is how this is handled:
6752 @example
6753 bin_SCRIPTS = automake
6754 CLEANFILES = $(bin_SCRIPTS)
6755 EXTRA_DIST = automake.in
6757 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
6758             -e 's,[@@]PERL[@@],$(PERL),g' \
6759             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
6760             -e 's,[@@]VERSION[@@],$(VERSION),g' \
6761             @dots{}
6763 automake: automake.in Makefile
6764         $(do_subst) < $(srcdir)/automake.in > automake
6765         chmod +x automake
6766 @end example
6768 Such scripts for which a build rule has been supplied need to be
6769 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
6770 sources have to be distributed, usually with @code{EXTRA_DIST}
6771 (@pxref{Dist}).
6773 Another common way to build scripts is to process them from
6774 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
6775 Automake knows which files should be cleaned and distributed, and what
6776 the rebuild rules should look like.
6778 For instance if @file{configure.ac} contains
6780 @example
6781 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
6782 @end example
6784 @noindent
6785 to build @file{src/my_script} from @file{src/my_script.in}, then an
6786 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
6787 be as simple as
6789 @example
6790 bin_SCRIPTS = my_script
6791 CLEANFILES = $(bin_SCRIPTS)
6792 @end example
6794 @noindent
6795 There is no need for @code{EXTRA_DIST} or any build rule: Automake
6796 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
6797 @code{CLEANFILES} is still useful, because by default Automake will
6798 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
6799 @code{clean}.
6801 Although this looks simpler, building scripts this way has one
6802 drawback: directory variables such as @code{$(datadir)} are not fully
6803 expanded and may refer to other directory variables.
6805 @node Headers
6806 @section Header files
6808 @cindex @code{_HEADERS} primary, defined
6809 @cindex @code{HEADERS} primary, defined
6810 @cindex Primary variable, @code{HEADERS}
6811 @vindex _HEADERS
6812 @vindex noinst_HEADERS
6813 @cindex @code{HEADERS}, installation directories
6814 @cindex Installing headers
6815 @vindex include_HEADERS
6816 @vindex oldinclude_HEADERS
6817 @vindex pkginclude_HEADERS
6820 Header files that must be installed are specified by the
6821 @code{HEADERS} family of variables.  Headers can be installed in
6822 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
6823 other directory you may have defined (@pxref{Uniform}).  For instance,
6825 @example
6826 include_HEADERS = foo.h bar/bar.h
6827 @end example
6829 @noindent
6830 will install the two files as @file{$(includedir)/foo.h} and
6831 @file{$(includedir)/bar.h}.
6833 The @code{nobase_} prefix is also supported,
6835 @example
6836 nobase_include_HEADERS = foo.h bar/bar.h
6837 @end example
6839 @noindent
6840 will install the two files as @file{$(includedir)/foo.h} and
6841 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
6843 @vindex noinst_HEADERS
6844 Usually, only header files that accompany installed libraries need to
6845 be installed.  Headers used by programs or convenience libraries are
6846 not installed.  The @code{noinst_HEADERS} variable can be used for
6847 such headers.  However when the header actually belongs to one
6848 convenient library or program, we recommend listing it in the
6849 program's or library's @code{_SOURCES} variable (@pxref{Program
6850 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
6851 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
6852 right variable to use in a directory containing only headers and no
6853 associated library or program.
6855 All header files must be listed somewhere; in a @code{_SOURCES}
6856 variable or in a @code{_HEADERS} variable.  Missing ones will not
6857 appear in the distribution.
6859 For header files that are built and must not be distributed, use the
6860 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
6861 @code{nodist_prog_SOURCES}.  If these generated headers are needed
6862 during the build, you must also ensure they exist before they are
6863 used (@pxref{Sources}).
6866 @node Data
6867 @section Architecture-independent data files
6869 @cindex @code{_DATA} primary, defined
6870 @cindex @code{DATA} primary, defined
6871 @cindex Primary variable, @code{DATA}
6872 @vindex _DATA
6874 Automake supports the installation of miscellaneous data files using the
6875 @code{DATA} family of variables.
6876 @vindex DATA
6878 @vindex data_DATA
6879 @vindex sysconf_DATA
6880 @vindex sharedstate_DATA
6881 @vindex localstate_DATA
6882 @vindex pkgdata_DATA
6884 Such data can be installed in the directories @code{datadir},
6885 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
6886 @code{pkgdatadir}.
6888 By default, data files are @emph{not} included in a distribution.  Of
6889 course, you can use the @code{dist_} prefix to change this on a
6890 per-variable basis.
6892 Here is how Automake declares its auxiliary data files:
6894 @example
6895 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
6896 @end example
6899 @node Sources
6900 @section Built sources
6902 Because Automake's automatic dependency tracking works as a side-effect
6903 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
6904 target should not be compiled before its dependencies are made, but
6905 these dependencies are unknown until the target is first compiled.
6907 Ordinarily this is not a problem, because dependencies are distributed
6908 sources: they preexist and do not need to be built.  Suppose that
6909 @file{foo.c} includes @file{foo.h}.  When it first compiles
6910 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
6911 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
6912 records the @file{foo.h} dependency so that following invocations of
6913 @command{make} will honor it.  In these conditions, it's clear there is
6914 no problem: either @file{foo.o} doesn't exist and has to be built
6915 (regardless of the dependencies), or accurate dependencies exist and
6916 they can be used to decide whether @file{foo.o} should be rebuilt.
6918 It's a different story if @file{foo.h} doesn't exist by the first
6919 @command{make} run.  For instance, there might be a rule to build
6920 @file{foo.h}.  This time @file{file.o}'s build will fail because the
6921 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
6922 rule to build @file{foo.h} first by lack of dependency information.
6924 @vindex BUILT_SOURCES
6925 @cindex @code{BUILT_SOURCES}, defined
6927 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
6928 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
6929 or @samp{make check} (or even @samp{make install}) before other
6930 targets are processed.  However, such a source file is not
6931 @emph{compiled} unless explicitly requested by mentioning it in some
6932 other @code{_SOURCES} variable.
6934 So, to conclude our introductory example, we could use
6935 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
6936 any other target (including @file{foo.o}) during @samp{make all} or
6937 @samp{make check}.
6939 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
6940 must be created early in the build process can be listed in this
6941 variable.  Moreover, all built sources do not necessarily have to be
6942 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
6943 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
6944 another source), because it's a known dependency of the associated
6945 object.
6947 It might be important to emphasize that @code{BUILT_SOURCES} is
6948 honored only by @samp{make all}, @samp{make check} and @samp{make
6949 install}.  This means you cannot build a specific target (e.g.,
6950 @samp{make foo}) in a clean tree if it depends on a built source.
6951 However it will succeed if you have run @samp{make all} earlier,
6952 because accurate dependencies are already available.
6954 The next section illustrates and discusses the handling of built sources
6955 on a toy example.
6957 @menu
6958 * Built sources example::       Several ways to handle built sources.
6959 @end menu
6961 @node Built sources example
6962 @subsection Built sources example
6964 Suppose that @file{foo.c} includes @file{bindir.h}, which is
6965 installation-dependent and not distributed: it needs to be built.  Here
6966 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
6967 value of the @command{make} variable @code{bindir} (inherited from
6968 @file{configure}).
6970 We suggest several implementations below.  It's not meant to be an
6971 exhaustive listing of all ways to handle built sources, but it will give
6972 you a few ideas if you encounter this issue.
6974 @unnumberedsubsec First try
6976 This first implementation will illustrate the bootstrap issue mentioned
6977 in the previous section (@pxref{Sources}).
6979 Here is a tentative @file{Makefile.am}.
6981 @example
6982 # This won't work.
6983 bin_PROGRAMS = foo
6984 foo_SOURCES = foo.c
6985 nodist_foo_SOURCES = bindir.h
6986 CLEANFILES = bindir.h
6987 bindir.h: Makefile
6988         echo '#define bindir "$(bindir)"' >$@@
6989 @end example
6991 This setup doesn't work, because Automake doesn't know that @file{foo.c}
6992 includes @file{bindir.h}.  Remember, automatic dependency tracking works
6993 as a side-effect of compilation, so the dependencies of @file{foo.o} will
6994 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
6995 The symptom is as follows.
6997 @example
6998 % make
6999 source='foo.c' object='foo.o' libtool=no \
7000 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7001 depmode=gcc /bin/sh ./depcomp \
7002 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7003 foo.c:2: bindir.h: No such file or directory
7004 make: *** [foo.o] Error 1
7005 @end example
7007 In this example @file{bindir.h} is not distributed, not installed, and
7008 it is not even being built on-time.  One may wonder what the
7009 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7010 line simply states that @file{bindir.h} is a source of @code{foo}, so
7011 for instance, it should be inspected while generating tags
7012 (@pxref{Tags}).  In other words, it does not help our present problem,
7013 and the build would fail identically without it.
7015 @unnumberedsubsec Using @code{BUILT_SOURCES}
7017 A solution is to require @file{bindir.h} to be built before anything
7018 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7020 @example
7021 bin_PROGRAMS = foo
7022 foo_SOURCES = foo.c
7023 nodist_foo_SOURCES = bindir.h
7024 BUILT_SOURCES = bindir.h
7025 CLEANFILES = bindir.h
7026 bindir.h: Makefile
7027         echo '#define bindir "$(bindir)"' >$@@
7028 @end example
7030 See how @file{bindir.h} get built first:
7032 @example
7033 % make
7034 echo '#define bindir "/usr/local/bin"' >bindir.h
7035 make  all-am
7036 make[1]: Entering directory `/home/adl/tmp'
7037 source='foo.c' object='foo.o' libtool=no \
7038 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7039 depmode=gcc /bin/sh ./depcomp \
7040 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7041 gcc  -g -O2   -o foo  foo.o
7042 make[1]: Leaving directory `/home/adl/tmp'
7043 @end example
7045 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7046 @code{all}, @code{check}, and @code{install} targets.  It still fails
7047 if you try to run @samp{make foo} explicitly:
7049 @example
7050 % make clean
7051 test -z "bindir.h" || rm -f bindir.h
7052 test -z "foo" || rm -f foo
7053 rm -f *.o
7054 % : > .deps/foo.Po # Suppress previously recorded dependencies
7055 % make foo
7056 source='foo.c' object='foo.o' libtool=no \
7057 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7058 depmode=gcc /bin/sh ./depcomp \
7059 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7060 foo.c:2: bindir.h: No such file or directory
7061 make: *** [foo.o] Error 1
7062 @end example
7064 @unnumberedsubsec Recording dependencies manually
7066 Usually people are happy enough with @code{BUILT_SOURCES} because they
7067 never build targets such as @samp{make foo} before @samp{make all}, as
7068 in the previous example.  However if this matters to you, you can
7069 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7070 the @file{Makefile.am}.
7072 @example
7073 bin_PROGRAMS = foo
7074 foo_SOURCES = foo.c
7075 nodist_foo_SOURCES = bindir.h
7076 foo.$(OBJEXT): bindir.h
7077 CLEANFILES = bindir.h
7078 bindir.h: Makefile
7079         echo '#define bindir "$(bindir)"' >$@@
7080 @end example
7082 You don't have to list @emph{all} the dependencies of @file{foo.o}
7083 explicitly, only those that might need to be built.  If a dependency
7084 already exists, it will not hinder the first compilation and will be
7085 recorded by the normal dependency tracking code.  (Note that after
7086 this first compilation the dependency tracking code will also have
7087 recorded the dependency between @file{foo.o} and
7088 @file{bindir.h}; so our explicit dependency is really useful to
7089 the first build only.)
7091 Adding explicit dependencies like this can be a bit dangerous if you are
7092 not careful enough.  This is due to the way Automake tries not to
7093 overwrite your rules (it assumes you know better than it).
7094 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7095 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7096 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7097 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7098 Always check the generated @file{Makefile.in} if you do this.
7100 @unnumberedsubsec Build @file{bindir.h} from @file{configure}
7102 It's possible to define this preprocessor macro from @file{configure},
7103 either in @file{config.h} (@pxref{Defining Directories, , Defining
7104 Directories, autoconf, The Autoconf Manual}), or by processing a
7105 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7106 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7107 Autoconf Manual}).
7109 At this point it should be clear that building @file{bindir.h} from
7110 @file{configure} work well for this example.  @file{bindir.h} will exist
7111 before you build any target, hence will not cause any dependency issue.
7113 The Makefile can be shrunk as follows.  We do not even have to mention
7114 @file{bindir.h}.
7116 @example
7117 bin_PROGRAMS = foo
7118 foo_SOURCES = foo.c
7119 @end example
7121 However, it's not always possible to build sources from
7122 @file{configure}, especially when these sources are generated by a tool
7123 that needs to be built first...
7125 @unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
7127 Another attractive idea is to define @code{bindir} as a variable or
7128 function exported from @file{bindir.o}, and build @file{bindir.c}
7129 instead of @file{bindir.h}.
7131 @example
7132 noinst_PROGRAMS = foo
7133 foo_SOURCES = foo.c bindir.h
7134 nodist_foo_SOURCES = bindir.c
7135 CLEANFILES = bindir.c
7136 bindir.c: Makefile
7137         echo 'const char bindir[] = "$(bindir)";' >$@@
7138 @end example
7140 @file{bindir.h} contains just the variable's declaration and doesn't
7141 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7142 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7143 first.
7145 @unnumberedsubsec Which is best?
7147 There is no panacea, of course.  Each solution has its merits and
7148 drawbacks.
7150 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7151 foo} on a clean tree is important to you.
7153 You won't add explicit dependencies if you are leery of overriding
7154 an Automake rule by mistake.
7156 Building files from @file{./configure} is not always possible, neither
7157 is converting @file{.h} files into @file{.c} files.
7160 @node Other GNU Tools
7161 @chapter Other GNU Tools
7163 Since Automake is primarily intended to generate @file{Makefile.in}s for
7164 use in GNU programs, it tries hard to interoperate with other GNU tools.
7166 @menu
7167 * Emacs Lisp::                  Emacs Lisp
7168 * gettext::                     Gettext
7169 * Libtool::                     Libtool
7170 * Java::                        Java
7171 * Python::                      Python
7172 @end menu
7175 @node Emacs Lisp
7176 @section Emacs Lisp
7178 @cindex @code{_LISP} primary, defined
7179 @cindex @code{LISP} primary, defined
7180 @cindex Primary variable, @code{LISP}
7182 @vindex _LISP
7183 @vindex lisp_LISP
7184 @vindex noinst_LISP
7186 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7187 is used to hold a list of @file{.el} files.  Possible prefixes for this
7188 primary are @code{lisp_} and @code{noinst_}.  Note that if
7189 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7190 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7192 @vindex dist_lisp_LISP
7193 @vindex dist_noinst_LISP
7194 Lisp sources are not distributed by default.  You can prefix the
7195 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7196 @code{dist_noinst_LISP}, to indicate that these files should be
7197 distributed.
7199 Automake will byte-compile all Emacs Lisp source files using the Emacs
7200 found by @code{AM_PATH_LISPDIR}, if any was found.
7202 Byte-compiled Emacs Lisp files are not portable among all versions of
7203 Emacs, so it makes sense to turn this off if you expect sites to have
7204 more than one version of Emacs installed.  Furthermore, many packages
7205 don't actually benefit from byte-compilation.  Still, we recommend
7206 that you byte-compile your Emacs Lisp sources.  It is probably better
7207 for sites with strange setups to cope for themselves than to make the
7208 installation less nice for everybody else.
7210 There are two ways to avoid byte-compiling.  Historically, we have
7211 recommended the following construct.
7212 @example
7213 lisp_LISP = file1.el file2.el
7214 ELCFILES =
7215 @end example
7216 @noindent
7217 @code{ELCFILES} is an internal Automake variable that normally lists
7218 all @file{.elc} files that must be byte-compiled.  Automake defines
7219 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7220 variable explicitly prevents byte-compilation to occur.
7222 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead.  As
7224 @example
7225 lisp_DATA = file1.el file2.el
7226 @end example
7228 Note that these two constructs are not equivalent.  @code{_LISP} will
7229 not install a file if Emacs is not installed, while @code{_DATA} will
7230 always install its files.
7232 @node gettext
7233 @section Gettext
7235 @cindex GNU Gettext support
7236 @cindex Gettext support
7237 @cindex Support for GNU Gettext
7239 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7240 turns on support for GNU gettext, a message catalog system for
7241 internationalization
7242 (@pxref{GNU Gettext, , , gettext, GNU gettext utilities}).
7244 The @code{gettext} support in Automake requires the addition of two
7245 subdirectories to the package, @file{intl} and @file{po}.  Automake
7246 insures that these directories exist and are mentioned in
7247 @code{SUBDIRS}.
7249 @node Libtool
7250 @section Libtool
7252 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7253 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7254 @xref{A Shared Library}.
7257 @node Java
7258 @section Java
7260 @cindex @code{_JAVA} primary, defined
7261 @cindex @code{JAVA} primary, defined
7262 @cindex Primary variable, @code{JAVA}
7264 Automake provides some minimal support for Java compilation with the
7265 @code{JAVA} primary.
7267 Any @file{.java} files listed in a @code{_JAVA} variable will be
7268 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7269 files are not included in the distribution, you should use the
7270 @code{dist_} prefix to distribute them.
7272 Here is a typical setup for distributing @file{.java} files and
7273 installing the @file{.class} files resulting from their compilation.
7275 @example
7276 javadir = $(datadir)/java
7277 dist_java_JAVA = a.java b.java @dots{}
7278 @end example
7280 @cindex @code{JAVA} restrictions
7281 @cindex Restrictions for @code{JAVA}
7283 Currently Automake enforces the restriction that only one @code{_JAVA}
7284 primary can be used in a given @file{Makefile.am}.  The reason for this
7285 restriction is that, in general, it isn't possible to know which
7286 @file{.class} files were generated from which @file{.java} files, so
7287 it would be impossible to know which files to install where.  For
7288 instance, a @file{.java} file can define multiple classes; the resulting
7289 @file{.class} file names cannot be predicted without parsing the
7290 @file{.java} file.
7292 There are a few variables that are used when compiling Java sources:
7294 @vtable @code
7295 @item JAVAC
7296 The name of the Java compiler.  This defaults to @samp{javac}.
7298 @item JAVACFLAGS
7299 The flags to pass to the compiler.  This is considered to be a user
7300 variable (@pxref{User Variables}).
7302 @item AM_JAVACFLAGS
7303 More flags to pass to the Java compiler.  This, and not
7304 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7305 compiler flags into @file{Makefile.am}.
7307 @item JAVAROOT
7308 The value of this variable is passed to the @option{-d} option to
7309 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7311 @item CLASSPATH_ENV
7312 This variable is an @code{sh} expression that is used to set the
7313 @env{CLASSPATH} environment variable on the @code{javac} command line.
7314 (In the future we will probably handle class path setting differently.)
7315 @end vtable
7318 @node Python
7319 @section Python
7321 @cindex @code{_PYTHON} primary, defined
7322 @cindex @code{PYTHON} primary, defined
7323 @cindex Primary variable, @code{PYTHON}
7324 @vindex _PYTHON
7326 Automake provides support for Python compilation with the
7327 @code{PYTHON} primary.  A typical setup is to call
7328 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7329 following in @file{Makefile.am}:
7331 @example
7332 python_PYTHON = tree.py leave.py
7333 @end example
7335 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7336 with @command{py-compile} at install time.  @command{py-compile}
7337 actually creates both standard (@file{.pyc}) and optimized
7338 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7339 because byte-compilation occurs at install time, any files listed in
7340 @code{noinst_PYTHON} will not be compiled.  Python source files are
7341 included in the distribution by default, prepend @code{nodist_} (as in
7342 @code{nodist_python_PYTHON}) to omit them.
7344 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7345 that will determine some Python-related directory variables (see
7346 below).  If you have called @code{AM_PATH_PYTHON} from
7347 @file{configure.ac}, then you may use the variables
7348 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7349 files in your @file{Makefile.am}, depending where you want your files
7350 installed (see the definitions of @code{pythondir} and
7351 @code{pkgpythondir} below).
7353 @defmac AM_PATH_PYTHON ([@var{VERSION}], [@var{ACTION-IF-FOUND}], [@var{ACTION-IF-NOT-FOUND}])
7355 Search a Python interpreter on the system.  This macro takes three
7356 optional arguments.  The first argument, if present, is the minimum
7357 version of Python required for this package: @code{AM_PATH_PYTHON}
7358 will skip any Python interpreter that is older than @var{VERSION}.
7359 If an interpreter is found and satisfies @var{VERSION}, then
7360 @var{ACTION-IF-FOUND} is run.  Otherwise, @var{ACTION-IF-NOT-FOUND} is
7361 run.
7363 If @var{ACTION-IF-NOT-FOUND} is not specified, as in the following
7364 example, the default is to abort @command{configure}.
7366 @example
7367 AM_PATH_PYTHON([2.2])
7368 @end example
7370 @noindent
7371 This is fine when Python is an absolute requirement for the package.
7372 If Python >= 2.2 was only @emph{optional} to the package,
7373 @code{AM_PATH_PYTHON} could be called as follows.
7375 @example
7376 AM_PATH_PYTHON([2.2],, [:])
7377 @end example
7379 @code{AM_PATH_PYTHON} creates the following output variables based on
7380 the Python installation found during configuration.
7381 @end defmac
7383 @vtable @code
7384 @item PYTHON
7385 The name of the Python executable, or @samp{:} if no suitable
7386 interpreter could be found.
7388 Assuming @var{ACTION-IF-NOT-FOUND} is used (otherwise @file{./configure}
7389 will abort if Python is absent), the value of @code{PYTHON} can be used
7390 to setup a conditional in order to disable the relevant part of a build
7391 as follows.
7393 @example
7394   AM_PATH_PYTHON(,, [:])
7395   AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7396 @end example
7398 @item PYTHON_VERSION
7399 The Python version number, in the form @var{major}.@var{minor}
7400 (e.g., @samp{1.5}).  This is currently the value of
7401 @samp{sys.version[:3]}.
7403 @item PYTHON_PREFIX
7404 The string @samp{$@{prefix@}}.  This term may be used in future work
7405 that needs the contents of Python's @samp{sys.prefix}, but general
7406 consensus is to always use the value from configure.
7408 @item PYTHON_EXEC_PREFIX
7409 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7410 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7411 consensus is to always use the value from configure.
7413 @item PYTHON_PLATFORM
7414 The canonical name used by Python to describe the operating system, as
7415 given by @samp{sys.platform}.  This value is sometimes needed when
7416 building Python extensions.
7418 @item pythondir
7419 The directory name for the @file{site-packages} subdirectory of the
7420 standard Python install tree.
7422 @item pkgpythondir
7423 This is the directory under @code{pythondir} that is named after the
7424 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7425 as a convenience.
7427 @item pyexecdir
7428 This is the directory where Python extension modules (shared libraries)
7429 should be installed.  An extension module written in C could be declared
7430 as follows to Automake:
7432 @example
7433 pyexec_LTLIBRARIES = quaternion.la
7434 quaternion_SOURCES = quaternion.c support.c support.h
7435 quaternion_la_LDFLAGS = -avoid-version -module
7436 @end example
7438 @item pkgpyexecdir
7439 This is a convenience variable that is defined as
7440 @samp{$(pyexecdir)/$(PACKAGE)}.
7441 @end vtable
7443 All these directory variables have values that start with either
7444 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7445 fine in @file{Makefiles}, but it makes these variables hard to use in
7446 @file{configure}.  This is mandated by the GNU coding standards, so
7447 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7448 manual has a section with more details on this topic
7449 (@pxref{Installation Directory Variables, , Installation Directory
7450 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7451 Install Paths}.
7454 @node Documentation
7455 @chapter Building documentation
7457 Currently Automake provides support for Texinfo and man pages.
7459 @menu
7460 * Texinfo::                     Texinfo
7461 * Man pages::                   Man pages
7462 @end menu
7465 @node Texinfo
7466 @section Texinfo
7468 @cindex @code{_TEXINFOS} primary, defined
7469 @cindex @code{TEXINFOS} primary, defined
7470 @cindex Primary variable, @code{TEXINFOS}
7471 @cindex HTML output using Texinfo
7472 @cindex PDF output using Texinfo
7473 @cindex PS output using Texinfo
7474 @cindex DVI output using Texinfo
7475 @vindex _TEXINFOS
7476 @vindex info_TEXINFOS
7478 If the current directory contains Texinfo source, you must declare it
7479 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7480 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7481 here.  Any Texinfo source file must end in the @file{.texi},
7482 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7483 for new manuals.
7485 Automake generates rules to build @file{.info}, @file{.dvi},
7486 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7487 sources.  Following the GNU Coding Standards, only the @file{.info}
7488 files are built by @samp{make all} and installed by @samp{make
7489 install} (unless you use @option{no-installinfo}, see below).
7490 Furthermore, @file{.info} files are automatically distributed so that
7491 Texinfo is not a prerequisite for installing your package.
7493 @trindex dvi
7494 @trindex html
7495 @trindex pdf
7496 @trindex ps
7497 @trindex install-dvi
7498 @trindex install-html
7499 @trindex install-pdf
7500 @trindex install-ps
7501 Other documentation formats can be built on request by @samp{make
7502 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7503 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7504 @samp{make install-pdf} and @samp{make install-html} explicitly.
7505 @samp{make uninstall} will remove everything: the Texinfo
7506 documentation installed by default as well as all the above optional
7507 formats.
7509 All these targets can be extended using @samp{-local} rules
7510 (@pxref{Extending}).
7512 @cindex Texinfo flag, @code{VERSION}
7513 @cindex Texinfo flag, @code{UPDATED}
7514 @cindex Texinfo flag, @code{EDITION}
7515 @cindex Texinfo flag, @code{UPDATED-MONTH}
7517 @cindex @code{VERSION} Texinfo flag
7518 @cindex @code{UPDATED} Texinfo flag
7519 @cindex @code{EDITION} Texinfo flag
7520 @cindex @code{UPDATED-MONTH} Texinfo flag
7522 @cindex @file{mdate-sh}
7524 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7525 that file will be automatically generated.  The file @file{version.texi}
7526 defines four Texinfo flag you can reference using
7527 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7528 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7530 @table @code
7531 @item EDITION
7532 @itemx VERSION
7533 Both of these flags hold the version number of your program.  They are
7534 kept separate for clarity.
7536 @item UPDATED
7537 This holds the date the primary @file{.texi} file was last modified.
7539 @item UPDATED-MONTH
7540 This holds the name of the month in which the primary @file{.texi} file
7541 was last modified.
7542 @end table
7544 The @file{version.texi} support requires the @command{mdate-sh}
7545 script; this script is supplied with Automake and automatically
7546 included when @command{automake} is invoked with the
7547 @option{--add-missing} option.
7549 If you have multiple Texinfo files, and you want to use the
7550 @file{version.texi} feature, then you have to have a separate version
7551 file for each Texinfo file.  Automake will treat any include in a
7552 Texinfo file that matches @file{vers*.texi} just as an automatically
7553 generated version file.
7555 Sometimes an info file actually depends on more than one @file{.texi}
7556 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7557 @file{gpl.texi}.  You can tell Automake about these dependencies using
7558 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7559 @vindex TEXINFOS
7560 @vindex _TEXINFOS
7562 @example
7563 info_TEXINFOS = hello.texi
7564 hello_TEXINFOS = gpl.texi
7565 @end example
7567 @cindex @file{texinfo.tex}
7569 By default, Automake requires the file @file{texinfo.tex} to appear in
7570 the same directory as the Texinfo source (this can be changed using the
7571 @code{TEXINFO_TEX} variable, see below).  However, if you used
7572 @code{AC_CONFIG_AUX_DIR} in @file{configure.ac} (@pxref{Input, , Finding
7573 `configure' Input, autoconf, The Autoconf Manual}), then
7574 @file{texinfo.tex} is looked for there.  Automake supplies
7575 @file{texinfo.tex} if @option{--add-missing} is given.
7577 @opindex no-texinfo.tex
7579 The option @option{no-texinfo.tex} can be used to eliminate the
7580 requirement for the file @file{texinfo.tex}.  Use of the variable
7581 @code{TEXINFO_TEX} is preferable, however, because that allows the
7582 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7584 @cindex Option, @code{no-installinfo}
7585 @cindex Target, @code{install-info}
7586 @cindex @code{install-info} target
7587 @cindex @code{no-installinfo} option
7589 @opindex no-installinfo
7590 @trindex install-info
7592 Automake generates an @code{install-info} rule; some people apparently
7593 use this.  By default, info pages are installed by @samp{make
7594 install}, so running @code{make install-info} is pointless.  This can
7595 be prevented via the @code{no-installinfo} option.  In this case,
7596 @file{.info} files are not installed by default, and user must
7597 request this explicitly using @samp{make install-info}
7599 The following variables are used by the Texinfo build rules.
7601 @vtable @code
7602 @item MAKEINFO
7603 The name of the program invoked to build @file{.info} files.  This
7604 variable is defined by Automake.  If the @command{makeinfo} program is
7605 found on the system then it will be used by default; otherwise
7606 @command{missing} will be used instead.
7608 @item MAKEINFOHTML
7609 The command invoked to build @file{.html} files.  Automake
7610 defines this to @samp{$(MAKEINFO) --html}.
7612 @item MAKEINFOFLAGS
7613 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7614 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7615 not expected to be defined in any @file{Makefile}; it can be used by
7616 users to pass extra flags to suit their needs.
7618 @item AM_MAKEINFOFLAGS
7619 @itemx AM_MAKEINFOHTMLFLAGS
7620 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7621 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7622 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7623 passed to @code{makeinfo} when building @file{.info} files; and
7624 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7625 files.
7627 For instance, the following setting can be used to obtain one single
7628 @file{.html} file per manual, without node separators.
7629 @example
7630 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7631 @end example
7633 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7634 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7635 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7636 and @file{.html} files.
7638 @item TEXI2DVI
7639 The name of the command that converts a @file{.texi} file into a
7640 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7641 with the Texinfo package.
7643 @item TEXI2PDF
7644 The name of the command that translates a @file{.texi} file into a
7645 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7647 @item DVIPS
7648 The name of the command that build a @file{.ps} file out of a
7649 @file{.dvi} file.  This defaults to @samp{dvips}.
7651 @item TEXINFO_TEX
7653 If your package has Texinfo files in many directories, you can use the
7654 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7655 @file{texinfo.tex} for your package.  The value of this variable should
7656 be the relative path from the current @file{Makefile.am} to
7657 @file{texinfo.tex}:
7659 @example
7660 TEXINFO_TEX = ../doc/texinfo.tex
7661 @end example
7662 @end vtable
7665 @node Man pages
7666 @section Man pages
7668 @cindex @code{_MANS} primary, defined
7669 @cindex @code{MANS} primary, defined
7670 @cindex Primary variable, @code{MANS}
7672 @vindex _MANS
7673 @vindex man_MANS
7674 A package can also include man pages (but see the GNU standards on this
7675 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7676 pages are declared using the @code{MANS} primary.  Generally the
7677 @code{man_MANS} variable is used.  Man pages are automatically installed in
7678 the correct subdirectory of @code{mandir}, based on the file extension.
7680 File extensions such as @file{.1c} are handled by looking for the valid
7681 part of the extension and using that to determine the correct
7682 subdirectory of @code{mandir}.  Valid section names are the digits
7683 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7685 Sometimes developers prefer to name a man page something like
7686 @file{foo.man} in the source, and then rename it to have the correct
7687 suffix, for example @file{foo.1}, when installing the file.  Automake
7688 also supports this mode.  For a valid section named @var{SECTION},
7689 there is a corresponding directory named @samp{man@var{SECTION}dir},
7690 and a corresponding @code{_MANS} variable.  Files listed in such a
7691 variable are installed in the indicated section.  If the file already
7692 has a valid suffix, then it is installed as-is; otherwise the file
7693 suffix is changed to match the section.
7695 For instance, consider this example:
7696 @example
7697 man1_MANS = rename.man thesame.1 alsothesame.1c
7698 @end example
7700 In this case, @file{rename.man} will be renamed to @file{rename.1} when
7701 installed, but the other files will keep their names.
7703 @cindex Target, @code{install-man}
7704 @cindex Option, @option{no-installman}
7705 @cindex @code{install-man} target
7706 @cindex @option{no-installman} option
7707 @opindex no-installman
7708 @trindex install-man
7710 By default, man pages are installed by @samp{make install}.  However,
7711 since the GNU project does not require man pages, many maintainers do
7712 not expend effort to keep the man pages up to date.  In these cases, the
7713 @option{no-installman} option will prevent the man pages from being
7714 installed by default.  The user can still explicitly install them via
7715 @samp{make install-man}.
7717 Man pages are not currently considered to be source, because it is not
7718 uncommon for man pages to be automatically generated.  Therefore they
7719 are not automatically included in the distribution.  However, this can
7720 be changed by use of the @code{dist_} prefix.  For instance here is
7721 how to distribute and install the two man pages of GNU @command{cpio}
7722 (which includes both Texinfo documentation and man pages):
7724 @example
7725 dist_man_MANS = cpio.1 mt.1
7726 @end example
7728 The @code{nobase_} prefix is meaningless for man pages and is
7729 disallowed.
7732 @node Install
7733 @chapter What Gets Installed
7735 @cindex Installation support
7736 @cindex @samp{make install} support
7738 @section Basics of installation
7740 Naturally, Automake handles the details of actually installing your
7741 program once it has been built.  All files named by the various
7742 primaries are automatically installed in the appropriate places when the
7743 user runs @samp{make install}.
7745 A file named in a primary is installed by copying the built file into
7746 the appropriate directory.  The base name of the file is used when
7747 installing.
7749 @example
7750 bin_PROGRAMS = hello subdir/goodbye
7751 @end example
7753 In this example, both @samp{hello} and @samp{goodbye} will be installed
7754 in @samp{$(bindir)}.
7756 Sometimes it is useful to avoid the basename step at install time.  For
7757 instance, you might have a number of header files in subdirectories of
7758 the source tree that are laid out precisely how you want to install
7759 them.  In this situation you can use the @code{nobase_} prefix to
7760 suppress the base name step.  For example:
7762 @example
7763 nobase_include_HEADERS = stdio.h sys/types.h
7764 @end example
7766 Will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
7767 in @samp{$(includedir)/sys}.
7769 @section The two parts of install
7771 Automake generates separate @code{install-data} and @code{install-exec}
7772 rules, in case the installer is installing on multiple machines that
7773 share directory structure---these targets allow the machine-independent
7774 parts to be installed only once.  @code{install-exec} installs
7775 platform-dependent files, and @code{install-data} installs
7776 platform-independent files.  The @code{install} target depends on both
7777 of these targets.  While Automake tries to automatically segregate
7778 objects into the correct category, the @file{Makefile.am} author is, in
7779 the end, responsible for making sure this is done correctly.
7780 @trindex install-data
7781 @trindex install-exec
7782 @trindex install
7783 @cindex Install, two parts of
7785 Variables using the standard directory prefixes @samp{data},
7786 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
7787 @samp{pkgdata}, or @samp{pkginclude} are installed by
7788 @code{install-data}.
7790 Variables using the standard directory prefixes @samp{bin},
7791 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
7792 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
7794 For instance, @code{data_DATA} files are installed by @code{install-data},
7795 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
7797 Any variable using a user-defined directory prefix with @samp{exec} in
7798 the name (e.g., @code{myexecbin_PROGRAMS}) is installed by
7799 @code{install-exec}.  All other user-defined prefixes are installed by
7800 @code{install-data}.
7802 @section Extending installation
7804 It is possible to extend this mechanism by defining an
7805 @code{install-exec-local} or @code{install-data-local} rule.  If these
7806 rules exist, they will be run at @samp{make install} time.  These
7807 rules can do almost anything; care is required.
7808 @trindex install-exec-local
7809 @trindex install-data-local
7811 Automake also supports two install hooks, @code{install-exec-hook} and
7812 @code{install-data-hook}.  These hooks are run after all other install
7813 rules of the appropriate type, exec or data, have completed.  So, for
7814 instance, it is possible to perform post-installation modifications
7815 using an install hook.  @ref{Extending} gives some examples.
7816 @cindex Install hook
7818 @section Staged installs
7820 @vindex DESTDIR
7821 Automake generates support for the @code{DESTDIR} variable in all
7822 install rules.  @code{DESTDIR} is used during the @samp{make install}
7823 step to relocate install objects into a staging area.  Each object and
7824 path is prefixed with the value of @code{DESTDIR} before being copied
7825 into the install area.  Here is an example of typical DESTDIR usage:
7827 @example
7828 mkdir /tmp/staging &&
7829 make DESTDIR=/tmp/staging install
7830 @end example
7832 The @command{mkdir} command avoids a security problem if the attacker
7833 creates a symbolic link from @file{/tmp/staging} to a victim area;
7834 then @command{make} places install objects in a directory tree built under
7835 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
7836 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
7837 would install @file{/tmp/staging/gnu/bin/foo} and
7838 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
7840 This feature is commonly used to build install images and packages
7841 (@pxref{DESTDIR}).
7843 Support for @code{DESTDIR} is implemented by coding it directly into
7844 the install rules.  If your @file{Makefile.am} uses a local install
7845 rule (e.g., @code{install-exec-local}) or an install hook, then you
7846 must write that code to respect @code{DESTDIR}.
7848 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
7849 for another usage example.
7851 @section Rules for the user
7853 Automake also generates rules for targets @code{uninstall},
7854 @code{installdirs}, and @code{install-strip}.
7855 @trindex uninstall
7856 @trindex installdirs
7857 @trindex install-strip
7859 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
7860 There is no notion of separate uninstalls for ``exec'' and ``data'', as
7861 these features would not provide additional functionality.
7863 Note that @code{uninstall} is not meant as a replacement for a real
7864 packaging tool.
7867 @node Clean
7868 @chapter What Gets Cleaned
7870 @cindex @samp{make clean} support
7872 The GNU Makefile Standards specify a number of different clean rules.
7873 @xref{Standard Targets, , Standard Targets for Users, standards,
7874 The GNU Coding Standards}.
7876 Generally the files that can be cleaned are determined automatically by
7877 Automake.  Of course, Automake also recognizes some variables that can
7878 be defined to specify additional files to clean.  These variables are
7879 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
7880 @code{MAINTAINERCLEANFILES}.
7881 @vindex MOSTLYCLEANFILES
7882 @vindex CLEANFILES
7883 @vindex DISTCLEANFILES
7884 @vindex MAINTAINERCLEANFILES
7886 @trindex mostlyclean-local
7887 @trindex clean-local
7888 @trindex distclean-local
7889 @trindex maintainer-clean-local
7890 When cleaning involves more than deleting some hard-coded list of
7891 files, it is also possible to supplement the cleaning rules with your
7892 own commands.  Simply define a rule for any of the
7893 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
7894 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
7895 case is deleting a directory, for instance, a directory created by the
7896 test suite:
7898 @example
7899 clean-local:
7900         -rm -rf testSubDir
7901 @end example
7903 As the GNU Standards aren't always explicit as to which files should
7904 be removed by which rule, we've adopted a heuristic that we believe
7905 was first formulated by Fran@,{c}ois Pinard:
7907 @itemize @bullet
7908 @item
7909 If @command{make} built it, and it is commonly something that one would
7910 want to rebuild (for instance, a @file{.o} file), then
7911 @code{mostlyclean} should delete it.
7913 @item
7914 Otherwise, if @command{make} built it, then @code{clean} should delete it.
7916 @item
7917 If @command{configure} built it, then @code{distclean} should delete it.
7919 @item
7920 If the maintainer built it (for instance, a @file{.info} file), then
7921 @code{maintainer-clean} should delete it.  However
7922 @code{maintainer-clean} should not delete anything that needs to exist
7923 in order to run @samp{./configure && make}.
7924 @end itemize
7926 We recommend that you follow this same set of heuristics in your
7927 @file{Makefile.am}.
7930 @node Dist
7931 @chapter What Goes in a Distribution
7933 @section Basics of distribution
7935 @cindex @samp{make dist}
7937 @vindex PACKAGE
7938 @vindex VERSION
7939 @trindex dist
7940 The @code{dist} rule in the generated @file{Makefile.in} can be used
7941 to generate a gzipped @code{tar} file and other flavors of archive for
7942 distribution.  The files is named based on the @code{PACKAGE} and
7943 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
7944 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
7945 @samp{@var{package}-@var{version}.tar.gz}.
7946 @vindex GZIP_ENV
7947 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
7948 is run.  The default setting is @option{--best}.
7950 @cindex @code{m4_include}, distribution
7951 @cindex @code{include}, distribution
7952 @acindex m4_include
7953 @cmindex include
7954 For the most part, the files to distribute are automatically found by
7955 Automake: all source files are automatically included in a distribution,
7956 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
7957 has a built-in list of commonly used files that are automatically
7958 included if they are found in the current directory (either physically,
7959 or as the target of a @file{Makefile.am} rule).  This list is printed by
7960 @samp{automake --help}.  Also, files that are read by @command{configure}
7961 (i.e.@: the source files corresponding to the files specified in various
7962 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
7963 automatically distributed.  Files included in @file{Makefile.am}s (using
7964 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
7965 helper scripts installed with @samp{automake --add-missing} are also
7966 distributed.
7968 @vindex EXTRA_DIST
7969 Still, sometimes there are files that must be distributed, but which
7970 are not covered in the automatic rules.  These files should be listed in
7971 the @code{EXTRA_DIST} variable.  You can mention files from
7972 subdirectories in @code{EXTRA_DIST}.
7974 You can also mention a directory in @code{EXTRA_DIST}; in this case the
7975 entire directory will be recursively copied into the distribution.
7976 Please note that this will also copy @emph{everything} in the directory,
7977 including CVS/RCS version control files.  We recommend against using
7978 this feature.
7980 @vindex SUBDIRS
7981 @vindex DIST_SUBDIRS
7982 If you define @code{SUBDIRS}, Automake will recursively include the
7983 subdirectories in the distribution.  If @code{SUBDIRS} is defined
7984 conditionally (@pxref{Conditionals}), Automake will normally include
7985 all directories that could possibly appear in @code{SUBDIRS} in the
7986 distribution.  If you need to specify the set of directories
7987 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
7988 exact list of subdirectories to include in the distribution
7989 (@pxref{Conditional Subdirectories}).
7992 @section Fine-grained distribution control
7994 @vindex dist_
7995 @vindex nodist_
7996 Sometimes you need tighter control over what does @emph{not} go into the
7997 distribution; for instance, you might have source files that are
7998 generated and that you do not want to distribute.  In this case
7999 Automake gives fine-grained control using the @code{dist} and
8000 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8001 prefixed with @code{dist_} to add the listed files to the distribution.
8002 Similarly, @code{nodist_} can be used to omit the files from the
8003 distribution.
8005 As an example, here is how you would cause some data to be distributed
8006 while leaving some source code out of the distribution:
8008 @example
8009 dist_data_DATA = distribute-this
8010 bin_PROGRAMS = foo
8011 nodist_foo_SOURCES = do-not-distribute.c
8012 @end example
8014 @section The dist hook
8016 @trindex dist-hook
8018 Occasionally it is useful to be able to change the distribution before
8019 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8020 after the distribution directory is filled, but before the actual tar
8021 (or shar) file is created.  One way to use this is for distributing
8022 files in subdirectories for which a new @file{Makefile.am} is overkill:
8024 @example
8025 dist-hook:
8026         mkdir $(distdir)/random
8027         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
8028 @end example
8030 Another way to to use this is for removing unnecessary files that get
8031 recursively included by specifying a directory in EXTRA_DIST:
8033 @example
8034 EXTRA_DIST = doc
8036 dist-hook:
8037         rm -rf `find $(distdir)/doc -name CVS`
8038 @end example
8040 @vindex distdir
8041 @vindex top_distdir
8042 Two variables that come handy when writing @code{dist-hook} rules are
8043 @samp{$(distdir)} and @samp{$(top_distdir)}.
8045 @samp{$(distdir)} points to the directory where the @code{dist} rule
8046 will copy files from the current directory before creating the
8047 tarball.  If you are at the top-level directory, then @samp{distdir =
8048 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8049 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8050 @samp{$(distdir)} can be a relative or absolute path, do not assume
8051 any form.
8053 @samp{$(top_distdir)} always points to the root directory of the
8054 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8055 In the @file{foo/} subdirectory
8056 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8057 @samp{$(top_distdir)} too can be a relative or absolute path.
8059 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8060 (@pxref{Subpackages}), then @samp{$(distdir)} and
8061 @samp{$(top_distdir)} are relative to the package where @samp{make
8062 dist} was run, not to any sub-packages involved.
8064 @section Checking the distribution
8066 @cindex @samp{make distcheck}
8067 @cindex @samp{make distcleancheck}
8068 @vindex distcleancheck_listfiles
8069 @cindex @samp{make distuninstallcheck}
8070 @vindex distuninstallcheck_listfiles
8072 @trindex distcheck
8073 Automake also generates a @code{distcheck} rule that can be of help to
8074 ensure that a given distribution will actually work.  @code{distcheck}
8075 makes a distribution, then tries to do a @code{VPATH} build
8076 (@pxref{VPATH Builds}), run the test suite, and finally make another
8077 tarball to ensure the distribution is self-contained.
8079 @vindex DISTCHECK_CONFIGURE_FLAGS
8080 Building the package involves running @samp{./configure}.  If you need
8081 to supply additional flags to @command{configure}, define them in the
8082 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
8083 @file{Makefile.am}, or on the command line when invoking @command{make}.
8085 @trindex distcheck-hook
8086 If the @code{distcheck-hook} rule is defined in your top-level
8087 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8088 the new distribution has been unpacked, but before the unpacked copy
8089 is configured and built.  Your @code{distcheck-hook} can do almost
8090 anything, though as always caution is advised.  Generally this hook is
8091 used to check for potential distribution errors not caught by the
8092 standard mechanism.  Note that @code{distcheck-hook} as well as
8093 @code{DISTCHECK_CONFIGURE_FLAGS} are not honored in a subpackage
8094 @file{Makefile.am}, but the @code{DISTCHECK_CONFIGURE_FLAGS} are
8095 passed down to the @command{configure} script of the subpackage.
8097 @trindex distcleancheck
8098 @vindex DISTCLEANFILES
8099 @vindex distcleancheck_listfiles
8100 Speaking of potential distribution errors, @code{distcheck} also
8101 ensures that the @code{distclean} rule actually removes all built
8102 files.  This is done by running @samp{make distcleancheck} at the end of
8103 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8104 @code{distclean} and then make sure the build tree has been emptied by
8105 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8106 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8107 variable (@pxref{Clean}).
8109 The @code{distcleancheck} behavior should be OK for most packages,
8110 otherwise you have the possibility to override the definition of
8111 either the @code{distcleancheck} rule, or the
8112 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8113 @code{distcleancheck} completely, add the following rule to your
8114 top-level @file{Makefile.am}:
8116 @example
8117 distcleancheck:
8118         @@:
8119 @end example
8121 If you want @code{distcleancheck} to ignore built files that have not
8122 been cleaned because they are also part of the distribution, add the
8123 following definition instead:
8125 @example
8126 distcleancheck_listfiles = \
8127   find -type f -exec sh -c 'test -f $(srcdir)/@{@} || echo @{@}' ';'
8128 @end example
8130 The above definition is not the default because it's usually an error if
8131 your Makefiles cause some distributed files to be rebuilt when the user
8132 build the package.  (Think about the user missing the tool required to
8133 build the file; or if the required tool is built by your package,
8134 consider the cross-compilation case where it can't be run.)  There is
8135 a FAQ entry about this (@pxref{distcleancheck}), make sure you read it
8136 before playing with @code{distcleancheck_listfiles}.
8138 @code{distcheck} also checks that the @code{uninstall} rule works
8139 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8140 by invoking @samp{make uninstall}, and then it checks the install tree
8141 to see if any files are left over.  This check will make sure that you
8142 correctly coded your @code{uninstall}-related rules.
8144 By default, the checking is done by the @code{distuninstallcheck} rule,
8145 and the list of files in the install tree is generated by
8146 @samp{$(distuninstallcheck_listfiles}) (this is a variable whose value is
8147 a shell command to run that prints the list of files to stdout).
8149 Either of these can be overridden to modify the behavior of
8150 @code{distcheck}.  For instance, to disable this check completely, you
8151 would write:
8153 @example
8154 distuninstallcheck:
8155         @@:
8156 @end example
8158 @section The types of distributions
8160 Automake generates rules to provide archives of the project for
8161 distributions in various formats.  Their targets are:
8163 @table @asis
8164 @item @code{dist-bzip2}
8165 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8166 frequently smaller than gzipped archives.
8167 @trindex dist-bzip2
8169 @item @code{dist-gzip}
8170 Generate a gzip tar archive of the distribution.
8171 @trindex dist-gzip
8173 @item @code{dist-shar}
8174 Generate a shar archive of the distribution.
8175 @trindex dist-shar
8177 @item @code{dist-zip}
8178 Generate a zip archive of the distribution.
8179 @trindex dist-zip
8181 @item @code{dist-tarZ}
8182 Generate a compressed tar archive of
8183 the distribution.
8184 @trindex dist-tarZ
8185 @end table
8187 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8188 create archives in all the enabled formats, @ref{Options}.  By
8189 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8192 @node Tests
8193 @chapter Support for test suites
8195 @cindex Test suites
8196 @cindex @code{make check}
8197 @trindex check
8199 Automake supports two forms of test suites.
8201 @section Simple Tests
8203 If the variable @code{TESTS} is defined, its value is taken to be a
8204 list of programs or scripts to run in order to do the testing.
8205 Programs needing data files should look for them in @code{srcdir}
8206 (which is both an environment variable and a make variable) so they
8207 work when building in a separate directory (@pxref{Build Directories,
8208 , Build Directories , autoconf, The Autoconf Manual}), and in
8209 particular for the @code{distcheck} rule (@pxref{Dist}).
8211 @cindex Exit status 77, special interpretation
8213 The number of failures will be printed at the end of the run.  If a
8214 given test program exits with a status of 77, then its result is ignored
8215 in the final count.  This feature allows non-portable tests to be
8216 ignored in environments where they don't make sense.
8218 @vindex TESTS
8219 @vindex TESTS_ENVIRONMENT
8220 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
8221 variables for the test run; the environment variable @code{srcdir} is
8222 set in the rule.  If all your test programs are scripts, you can also
8223 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
8224 @samp{$(SHELL) -x} can be useful for debugging the tests), or any other
8225 interpreter.  For instance the following setup is used by the Automake
8226 package to run four tests in Perl.
8227 @example
8228 TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
8229 TESTS = Condition.pl DisjConditions.pl Version.pl Wrap.pl
8230 @end example
8233 @cindex Tests, expected failure
8234 @cindex Expected test failure
8236 You may define the variable @code{XFAIL_TESTS} to a list of tests
8237 (usually a subset of @code{TESTS}) that are expected to fail.  This will
8238 reverse the result of those tests.
8239 @vindex XFAIL_TESTS
8241 Automake ensures that each file listed in @code{TESTS} is built before
8242 any tests are run; you can list both source and derived programs (or
8243 scripts) in @code{TESTS}; the generated rule will look both in
8244 @code{srcdir} and @file{.}.  For instance, you might want to run a C
8245 program as a test.  To do this you would list its name in @code{TESTS}
8246 and also in @code{check_PROGRAMS}, and then specify it as you would
8247 any other program.
8249 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8250 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8251 not during @code{make all}.  You should list there any program needed
8252 by your tests that does not need to be built by @code{make all}.  Note
8253 that @code{check_PROGRAMS} are @emph{not} automatically added to
8254 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8255 by the tests, not the tests themselves.  Of course you can set
8256 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8258 @section DejaGnu Tests
8260 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
8261 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
8262 assumed.  The variable @code{DEJATOOL} is a list of names that are
8263 passed, one at a time, as the @option{--tool} argument to
8264 @command{runtest} invocations; it defaults to the name of the package.
8266 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
8267 @option{--srcdir} flags that are passed to dejagnu by default; this can be
8268 overridden if necessary.
8269 @vindex RUNTESTDEFAULTFLAGS
8271 The variables @code{EXPECT} and @code{RUNTEST} can
8272 also be overridden to provide project-specific values.  For instance,
8273 you will need to do this if you are testing a compiler toolchain,
8274 because the default values do not take into account host and target
8275 names.
8276 @opindex dejagnu
8277 @vindex DEJATOOL
8278 @vindex EXPECT
8279 @vindex RUNTEST
8281 The contents of the variable @code{RUNTESTFLAGS} are passed to the
8282 @code{runtest} invocation.  This is considered a ``user variable''
8283 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
8284 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
8285 @vindex RUNTESTFLAGS
8286 @vindex AM_RUNTESTFLAGS
8288 @cindex @file{site.exp}
8289 Automake will generate rules to create a local @file{site.exp} file,
8290 defining various variables detected by @command{configure}.  This file
8291 is automatically read by DejaGnu.  It is OK for the user of a package
8292 to edit this file in order to tune the test suite.  However this is
8293 not the place where the test suite author should define new variables:
8294 this should be done elsewhere in the real test suite code.
8295 Especially, @file{site.exp} should not be distributed.
8297 For more information regarding DejaGnu test suites, see @ref{Top, , ,
8298 dejagnu, The DejaGnu Manual}.
8300 In either case, the testing is done via @samp{make check}.
8302 @section Install Tests
8304 The @code{installcheck} target is available to the user as a way to
8305 run any tests after the package has been installed.  You can add tests
8306 to this by writing an @code{installcheck-local} rule.
8309 @node Rebuilding
8310 @chapter Rebuilding Makefiles
8311 @cindex rebuild rules
8313 Automake generates rules to automatically rebuild @file{Makefile}s,
8314 @file{configure}, and other derived files like @file{Makefile.in}.
8316 @acindex AM_MAINTAINER_MODE
8317 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
8318 these automatic rebuilding rules are only enabled in maintainer mode.
8320 @vindex ACLOCAL_AMFLAGS
8321 Sometimes you need to run @command{aclocal} with an argument like
8322 @option{-I} to tell it where to find @file{.m4} files.  Since
8323 sometimes @command{make} will automatically run @command{aclocal}, you
8324 need a way to specify these arguments.  You can do this by defining
8325 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
8326 to @command{aclocal}.  This variable is only useful in the top-level
8327 @file{Makefile.am}.
8329 @vindex CONFIG_STATUS_DEPENDENCIES
8330 @vindex CONFIGURE_DEPENDENCIES
8331 @cindex @file{version.sh}, example
8332 @cindex @file{version.m4}, example
8334 Sometimes it is convenient to supplement the rebuild rules for
8335 @file{configure} or @file{config.status} with additional dependencies.
8336 The variables @code{CONFIGURE_DEPENDENCIES} and
8337 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
8338 dependencies.  These variable should be defined in all
8339 @file{Makefile}s of the tree (because these two rebuild rules are
8340 output in all them), so it is safer and easier to @code{AC_SUBST} them
8341 from @file{configure.ac}.  For instance, the following statement will
8342 cause @file{configure} to be rerun each time @file{version.sh} is
8343 changed.
8344 @example
8345 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
8346 @end example
8347 @noindent
8348 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
8349 is to be used in all @file{Makefile}s, its value must be sensible at
8350 any level in the build hierarchy.
8352 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
8353 @code{CONFIG_STATUS_DEPENDENCIES}.
8355 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
8356 @file{configure} rule, whose effect is to run @command{autoconf}.  This
8357 variable should be seldom used, because @command{automake} already tracks
8358 @code{m4_include}d files.  However it can be useful when playing
8359 tricky games with @code{m4_esyscmd} or similar non-recommendable
8360 macros with side effects.
8362 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
8363 @file{config.status} rule, whose effect is to run @file{configure}.
8364 This variable should therefore carry any non-standard source that may
8365 be read as a side effect of running configure, like @file{version.sh}
8366 in the example above.
8368 Speaking of @file{version.sh} scripts, we recommend against them
8369 today.  They are mainly used when the version of a package is updated
8370 automatically by a script (e.g., in daily builds).  Here is what some
8371 old-style @file{configure.ac}s may look like:
8372 @example
8373 AC_INIT
8374 . $srcdir/version.sh
8375 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
8376 @dots{}
8377 @end example
8378 @noindent
8379 Here, @file{version.sh} is a shell fragment that sets
8380 @code{VERSION_NUMBER}.  The problem with this example is that
8381 @command{automake} cannot track dependencies (listing @file{version.sh}
8382 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
8383 to the user), and that it uses the obsolete form of @code{AC_INIT} and
8384 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
8385 straightforward, because shell variables are not allowed in
8386 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
8387 replaced by an M4 file that is included by @file{configure.ac}:
8388 @example
8389 m4_include([version.m4])
8390 AC_INIT([name], VERSION_NUMBER)
8391 AM_INIT_AUTOMAKE
8392 @dots{}
8393 @end example
8394 @noindent
8395 Here @file{version.m4} could contain something like
8396 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
8397 second form is that @command{automake} will take care of the
8398 dependencies when defining the rebuild rule, and will also distribute
8399 the file automatically.  An inconvenience is that @command{autoconf}
8400 will now be rerun each time the version number is bumped, when only
8401 @file{configure} had to be rerun in the previous setup.
8404 @node Options
8405 @chapter Changing Automake's Behavior
8407 Various features of Automake can be controlled by options in the
8408 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
8409 basis when listed in a special @file{Makefile} variable named
8410 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
8411 @file{Makefiles} when listed in the first argument of
8412 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}.  Currently understood
8413 options are:
8414 @vindex AUTOMAKE_OPTIONS
8416 @table @asis
8417 @item @option{gnits}
8418 @itemx @option{gnu}
8419 @itemx @option{foreign}
8420 @itemx @option{cygnus}
8421 @cindex Option, @option{gnits}
8422 @cindex Option, @option{gnu}
8423 @cindex Option, @option{foreign}
8424 @cindex Option, @option{cygnus}
8425 @opindex gnits
8426 @opindex gnu
8427 @opindex foreign
8428 @opindex cygnus
8430 Set the strictness as appropriate.  The @option{gnits} option also
8431 implies options @option{readme-alpha} and @option{check-news}.
8433 @item @option{ansi2knr}
8434 @itemx @option{@var{path}/ansi2knr}
8435 @cindex Option, @option{ansi2knr}
8436 @opindex ansi2knr
8437 Turn on automatic de-ANSI-fication.  @xref{ANSI}.  If preceded by a
8438 path, the generated @file{Makefile.in} will look in the specified
8439 directory to find the @file{ansi2knr} program.  The path should be a
8440 relative path to another directory in the same distribution (Automake
8441 currently does not check this).
8443 @item @option{check-news}
8444 @cindex Option, @option{check-news}
8445 @opindex check-news
8446 Cause @samp{make dist} to fail unless the current version number appears
8447 in the first few lines of the @file{NEWS} file.
8449 @item @option{dejagnu}
8450 @cindex Option, @option{dejagnu}
8451 @opindex dejagnu
8452 Cause @command{dejagnu}-specific rules to be generated.  @xref{Tests}.
8454 @item @option{dist-bzip2}
8455 @cindex Option, @option{dist-bzip2}
8456 @opindex dist-bzip2
8457 Hook @code{dist-bzip2} to @code{dist}.
8458 @trindex dist-bzip2
8460 @item @option{dist-shar}
8461 @cindex Option, @option{dist-shar}
8462 @opindex dist-shar
8463 Hook @code{dist-shar} to @code{dist}.
8464 @trindex dist-shar
8466 @item @option{dist-zip}
8467 @cindex Option, @option{dist-zip}
8468 @opindex dist-zip
8469 Hook @code{dist-zip} to @code{dist}.
8470 @trindex dist-zip
8472 @item @option{dist-tarZ}
8473 @cindex Option, @option{dist-tarZ}
8474 @opindex dist-tarZ
8475 Hook @code{dist-tarZ} to @code{dist}.
8476 @trindex dist-tarZ
8478 @item @option{filename-length-max=99}
8479 @cindex Option, @option{filename-length-max=99}
8480 @opindex filename-length-max=99
8481 Abort if file names longer than 99 characters are found during
8482 @samp{make dist}.  Such long file names are generally considered not to
8483 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
8484 options below.  This option should be used in the top-level
8485 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
8486 @file{configure.ac}, it will be ignored otherwise.
8488 @item @option{no-define}
8489 @cindex Option, @option{no-define}
8490 @opindex no-define
8491 This options is meaningful only when passed as an argument to
8492 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
8493 @code{VERSION} variables to be @code{AC_DEFINE}d.
8495 @item @option{no-dependencies}
8496 @cindex Option, @option{no-dependencies}
8497 @opindex no-dependencies
8498 This is similar to using @option{--include-deps} on the command line,
8499 but is useful for those situations where you don't have the necessary
8500 bits to make automatic dependency tracking work
8501 (@pxref{Dependencies}).  In this case the effect is to effectively
8502 disable automatic dependency tracking.
8504 @item @option{no-dist}
8505 @cindex Option, @option{no-dist}
8506 @opindex no-dist
8507 Don't emit any code related to @code{dist} target.  This is useful
8508 when a package has its own method for making distributions.
8510 @item @option{no-dist-gzip}
8511 @cindex Option, @option{no-dist-gzip}
8512 @opindex no-dist-gzip
8513 Do not hook @code{dist-gzip} to @code{dist}.
8514 @trindex no-dist-gzip
8516 @item @option{no-exeext}
8517 @cindex Option, @option{no-exeext}
8518 @opindex no-exeext
8519 If your @file{Makefile.am} defines a rule for target @code{foo}, it
8520 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
8521 necessary when @code{EXEEXT} is found to be empty.  However, by
8522 default automake will generate an error for this use.  The
8523 @option{no-exeext} option will disable this error.  This is intended for
8524 use only where it is known in advance that the package will not be
8525 ported to Windows, or any other operating system using extensions on
8526 executables.
8528 @item @option{no-installinfo}
8529 @cindex Option, @option{no-installinfo}
8530 @opindex no-installinfo
8531 The generated @file{Makefile.in} will not cause info pages to be built
8532 or installed by default.  However, @code{info} and @code{install-info}
8533 targets will still be available.  This option is disallowed at
8534 @option{gnu} strictness and above.
8535 @trindex info
8536 @trindex install-info
8538 @item @option{no-installman}
8539 @cindex Option, @option{no-installman}
8540 @opindex no-installman
8541 The generated @file{Makefile.in} will not cause man pages to be
8542 installed by default.  However, an @code{install-man} target will still
8543 be available for optional installation.  This option is disallowed at
8544 @option{gnu} strictness and above.
8545 @trindex install-man
8547 @item @option{nostdinc}
8548 @cindex Option, @option{nostdinc}
8549 @opindex nostdinc
8550 This option can be used to disable the standard @option{-I} options that
8551 are ordinarily automatically provided by Automake.
8553 @item @option{no-texinfo.tex}
8554 @cindex Option, @option{no-texinfo.tex}
8555 @opindex no-texinfo.tex
8556 Don't require @file{texinfo.tex}, even if there are texinfo files in
8557 this directory.
8559 @item @option{readme-alpha}
8560 @cindex Option, @option{readme-alpha}
8561 @opindex readme-alpha
8562 If this release is an alpha release, and the file @file{README-alpha}
8563 exists, then it will be added to the distribution.  If this option is
8564 given, version numbers are expected to follow one of two forms.  The
8565 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
8566 element is a number; the final period and number should be left off for
8567 non-alpha releases.  The second form is
8568 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
8569 letter; it should be omitted for non-alpha releases.
8571 @item @option{std-options}
8572 @cindex Options, @option{std-options}
8573 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
8574 @cindex @option{--help} check
8575 @cindex @option{--version} check
8576 @opindex std-options
8578 Make the @code{installcheck} rule check that installed scripts and
8579 programs support the @option{--help} and @option{--version} options.
8580 This also provides a basic check that the program's
8581 run-time dependencies are satisfied after installation.
8583 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
8584 In a few situations, programs (or scripts) have to be exempted from this
8585 test.  For instance, @command{false} (from GNU sh-utils) is never
8586 successful, even for @option{--help} or @option{--version}.  You can list
8587 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
8588 Programs (not scripts) listed in this variable should be suffixed by
8589 @samp{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance, suppose we
8590 build @file{false} as a program but @file{true.sh} as a script, and that
8591 neither of them support @option{--help} or @option{--version}:
8593 @example
8594 AUTOMAKE_OPTIONS = std-options
8595 bin_PROGRAMS = false ...
8596 bin_SCRIPTS = true.sh ...
8597 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
8598 @end example
8600 @item @option{subdir-objects}
8601 @cindex Options, @option{subdir-objects}
8602 @opindex subdir-objects
8603 If this option is specified, then objects are placed into the
8604 subdirectory of the build directory corresponding to the subdirectory of
8605 the source file.  For instance, if the source file is
8606 @file{subdir/file.cxx}, then the output file would be
8607 @file{subdir/file.o}.
8609 In order to use this option with C sources, you should add
8610 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
8612 @anchor{tar-formats}
8613 @item @option{tar-v7}
8614 @itemx @option{tar-ustar}
8615 @itemx @option{tar-pax}
8616 @cindex Option, @option{tar-v7}
8617 @cindex Option, @option{tar-ustar}
8618 @cindex Option, @option{tar-pax}
8619 @cindex @command{tar} formats
8620 @cindex v7 @command{tar} format
8621 @cindex ustar format
8622 @cindex pax format
8623 @opindex tar-v7
8624 @opindex tar-ustar
8625 @opindex tar-pax
8627 These three mutually exclusive options select the tar format to use
8628 when generating tarballs with @samp{make dist}.  (The tar file created
8629 is then compressed according to the set of @option{no-dist-gzip},
8630 @option{dist-bzip2} and @option{dist-tarZ} options in use.)
8632 These options must be passed as argument to @code{AM_INIT_AUTOMAKE}
8633 (@pxref{Macros}) because they can require additional configure checks.
8634 Automake will complain if it sees such options in an
8635 @code{AUTOMAKE_OPTIONS} variable.
8637 @option{tar-v7} selects the old V7 tar format.  This is the historical
8638 default.  This antiquated format is understood by all tar
8639 implementations and supports file names with up to 99 characters.  When
8640 given longer file names some tar implementations will diagnose the
8641 problem while other will generate broken tarballs or use non-portable
8642 extensions.  Furthermore, the V7 format cannot store empty
8643 directories.  When using this format, consider using the
8644 @option{filename-length-max=99} option to catch file names too long.
8646 @option{tar-ustar} selects the ustar format defined by POSIX
8647 1003.1-1988.  This format is believed to be old enough to be portable.
8648 It fully supports empty directories.  It can store file names with up
8649 to 256 characters, provided that the file name can be split at
8650 directory separator in two parts, first of them being at most 155
8651 bytes long.  So, in most cases the maximum file name length will be
8652 shorter than 256 characters.  However you may run against broken tar
8653 implementations that incorrectly handle file names longer than 99
8654 characters (please report them to @email{bug-automake@@gnu.org} so we
8655 can document this accurately).
8657 @option{tar-pax} selects the new pax interchange format defined by POSIX
8658 1003.1-2001.  It does not limit the length of file names.  However,
8659 this format is very young and should probably be restricted to
8660 packages that target only very modern platforms.  There are moves to
8661 change the pax format in an upward-compatible way, so this option may
8662 refer to a more recent version in the future.
8664 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
8665 further discussion about tar formats.
8667 @command{configure} knows several ways to construct these formats.  It
8668 will not abort if it cannot find a tool up to the task (so that the
8669 package can still be built), but @samp{make dist} will fail.
8671 @item @var{version}
8672 @cindex Option, @var{version}
8673 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
8674 newer than the version specified, creation of the @file{Makefile.in}
8675 will be suppressed.
8677 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
8678 @cindex Option, warnings
8679 @cindex Option, @option{-W@var{category}}
8680 @cindex Option, @option{--warnings=@var{category}}
8681 These options behave exactly like their command-line counterpart
8682 (@pxref{Invoking Automake}).  This allows you to enable or disable some
8683 warning categories on a per-file basis.  You can also setup some warnings
8684 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
8685 in your @file{configure.ac}.
8687 @end table
8689 Unrecognized options are diagnosed by @command{automake}.
8691 If you want an option to apply to all the files in the tree, you can use
8692 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
8693 @xref{Macros}.
8696 @node Miscellaneous
8697 @chapter Miscellaneous Rules
8699 There are a few rules and variables that didn't fit anywhere else.
8701 @menu
8702 * Tags::                        Interfacing to etags and mkid
8703 * Suffixes::                    Handling new file extensions
8704 * Multilibs::                   Support for multilibs.
8705 @end menu
8708 @node Tags
8709 @section Interfacing to @command{etags}
8711 @cindex @file{TAGS} support
8713 Automake will generate rules to generate @file{TAGS} files for use with
8714 GNU Emacs under some circumstances.
8716 @trindex tags
8717 If any C, C++ or Fortran 77 source code or headers are present, then
8718 @code{tags} and @code{TAGS} rules will be generated for the directory.
8719 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
8720 @code{_LISP} primaries will be used to generate tags.  Note that
8721 generated source files that are not distributed must be declared in
8722 variables like @code{nodist_noinst_HEADERS} or
8723 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
8725 A @code{tags} rule will be output at the topmost directory of a
8726 multi-directory package.  When run from this topmost directory,
8727 @samp{make tags} will generate a @file{TAGS} file that includes by
8728 reference all @file{TAGS} files from subdirectories.
8730 The @code{tags} rule will also be generated if the variable
8731 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
8732 directories that contain taggable source that @command{etags} does
8733 not understand.  The user can use the @code{ETAGSFLAGS} to pass
8734 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
8735 available for use in @file{Makefile.am}.
8736 @vindex ETAGS_ARGS
8737 @vindex ETAGSFLAGS
8738 @vindex AM_ETAGSFLAGS
8740 Here is how Automake generates tags for its source, and for nodes in its
8741 Texinfo file:
8743 @example
8744 ETAGS_ARGS = automake.in --lang=none \
8745  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
8746 @end example
8748 If you add file names to @code{ETAGS_ARGS}, you will probably also
8749 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
8750 are added directly to the dependencies for the @code{tags} rule.
8751 @vindex TAGS_DEPENDENCIES
8753 Automake also generates a @code{ctags} rule that can be used to
8754 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
8755 is the name of the program to invoke (by default @command{ctags});
8756 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
8757 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
8759 Automake will also generate an @code{ID} rule that will run
8760 @command{mkid} on the source.  This is only supported on a
8761 directory-by-directory basis.
8762 @trindex id
8764 Finally, Automake also emit rules to support the
8765 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
8766 The @code{GTAGS} rule runs Global Tags and puts the
8767 result in the top build directory.  The variable @code{GTAGS_ARGS}
8768 holds arguments that are passed to @command{gtags}.
8769 @vindex GTAGS_ARGS
8772 @node Suffixes
8773 @section Handling new file extensions
8775 @cindex Adding new @code{SUFFIXES}
8776 @cindex @code{SUFFIXES}, adding
8777 @vindex SUFFIXES
8779 It is sometimes useful to introduce a new implicit rule to handle a file
8780 type that Automake does not know about.
8782 For instance, suppose you had a compiler that could compile @file{.foo}
8783 files to @file{.o} files.  You would simply define an suffix rule for
8784 your language:
8786 @example
8787 .foo.o:
8788         foocc -c -o $@@ $<
8789 @end example
8791 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
8792 variable and expect the correct results:
8794 @example
8795 bin_PROGRAMS = doit
8796 doit_SOURCES = doit.foo
8797 @end example
8799 This was the simpler and more common case.  In other cases, you will
8800 have to help Automake to figure which extensions you are defining your
8801 suffix rule for.  This usually happens when your extensions does not
8802 start with a dot.  Then, all you have to do is to put a list of new
8803 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
8804 implicit rule.
8806 For instance, the following definition prevents Automake to misinterpret
8807 @samp{.idlC.cpp:} as an attempt to transform @file{.idlC} files into
8808 @file{.cpp} files.
8810 @example
8811 SUFFIXES = .idl C.cpp
8812 .idlC.cpp:
8813         # whatever
8814 @end example
8816 As you may have noted, the @code{SUFFIXES} variable behaves like the
8817 @code{.SUFFIXES} special target of @command{make}.  You should not touch
8818 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
8819 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
8820 @code{SUFFIXES} go at the start of the generated suffixes list, followed
8821 by Automake generated suffixes not already in the list.
8823 @node Multilibs
8824 @section Support for Multilibs
8826 Automake has support for an obscure feature called multilibs.  A
8827 @dfn{multilib} is a library that is built for multiple different ABIs
8828 at a single time; each time the library is built with a different target
8829 flag combination.  This is only useful when the library is intended to
8830 be cross-compiled, and it is almost exclusively used for compiler
8831 support libraries.
8833 The multilib support is still experimental.  Only use it if you are
8834 familiar with multilibs and can debug problems you might encounter.
8837 @node Include
8838 @chapter Include
8840 @cmindex include
8841 @cindex Including @file{Makefile} fragment
8842 @cindex @file{Makefile} fragment, including
8844 Automake supports an @code{include} directive that  can be used to
8845 include other @file{Makefile} fragments when @command{automake} is run.
8846 Note that these fragments are read and interpreted by @command{automake},
8847 not by @command{make}.  As with conditionals, @command{make} has no idea that
8848 @code{include} is in use.
8850 There are two forms of @code{include}:
8852 @table @code
8853 @item include $(srcdir)/file
8854 Include a fragment that is found relative to the current source
8855 directory.
8857 @item include $(top_srcdir)/file
8858 Include a fragment that is found relative to the top source directory.
8859 @end table
8861 Note that if a fragment is included inside a conditional, then the
8862 condition applies to the entire contents of that fragment.
8864 Makefile fragments included this way are always distributed because
8865 they are needed to rebuild @file{Makefile.in}.
8867 @node Conditionals
8868 @chapter Conditionals
8870 @cindex Conditionals
8872 Automake supports a simple type of conditionals.
8874 @unnumberedsec Usage
8876 @acindex AM_CONDITIONAL
8877 Before using a conditional, you must define it by using
8878 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
8880 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
8881 The conditional name, @var{conditional}, should be a simple string
8882 starting with a letter and containing only letters, digits, and
8883 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
8884 that are reserved by Automake.
8886 The shell @var{condition} (suitable for use in a shell @code{if}
8887 statement) is evaluated when @command{configure} is run.  Note that you
8888 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
8889 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
8890 conditionally (e.g., in a shell @code{if} statement), then the result
8891 will confuse automake.
8892 @end defmac
8894 @cindex @option{--enable-debug}, example
8895 @cindex Example conditional @option{--enable-debug}
8896 @cindex Conditional example, @option{--enable-debug}
8898 Conditionals typically depend upon options that the user provides to
8899 the @command{configure} script.  Here is an example of how to write a
8900 conditional that is true if the user uses the @option{--enable-debug}
8901 option.
8903 @example
8904 AC_ARG_ENABLE([debug],
8905 [  --enable-debug    Turn on debugging],
8906 [case "$@{enableval@}" in
8907   yes) debug=true ;;
8908   no)  debug=false ;;
8909   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
8910 esac],[debug=false])
8911 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
8912 @end example
8914 Here is an example of how to use that conditional in @file{Makefile.am}:
8916 @cmindex if
8917 @cmindex endif
8918 @cmindex else
8920 @example
8921 if DEBUG
8922 DBG = debug
8923 else
8924 DBG =
8925 endif
8926 noinst_PROGRAMS = $(DBG)
8927 @end example
8929 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
8930 (@pxref{Conditional Programs}).
8932 You may only test a single variable in an @code{if} statement, possibly
8933 negated using @samp{!}.  The @code{else} statement may be omitted.
8934 Conditionals may be nested to any depth.  You may specify an argument to
8935 @code{else} in which case it must be the negation of the condition used
8936 for the current @code{if}.  Similarly you may specify the condition
8937 that is closed by an @code{end}:
8939 @example
8940 if DEBUG
8941 DBG = debug
8942 else !DEBUG
8943 DBG =
8944 endif !DEBUG
8945 @end example
8947 @noindent
8948 Unbalanced conditions are errors.
8950 The @code{else} branch of the above two examples could be omitted,
8951 since assigning the empty string to an otherwise undefined variable
8952 makes no difference.
8954 @unnumberedsec Portability
8956 Note that conditionals in Automake are not the same as conditionals in
8957 GNU Make.  Automake conditionals are checked at configure time by the
8958 @file{configure} script, and affect the translation from
8959 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
8960 to @file{configure} and on results that @file{configure} has discovered
8961 about the host system.  GNU Make conditionals are checked at @command{make}
8962 time, and are based on variables passed to the make program or defined
8963 in the @file{Makefile}.
8965 Automake conditionals will work with any make program.
8967 @unnumberedsec Limits
8969 Conditionals should enclose complete statements like variables or
8970 rules definitions.  Automake cannot deal with conditionals used inside
8971 a variable definition, for instance, and is not even able to diagnose
8972 this situation.  The following example would not work:
8974 @example
8975 # This syntax is not understood by Automake
8976 AM_CPPFLAGS = \
8977   -DFEATURE_A \
8978 if WANT_DEBUG
8979   -DDEBUG \
8980 endif
8981   -DFEATURE_B
8982 @end example
8984 However the intended definition of @code{AM_CPPFLAGS} can be achieved
8985 with
8987 @example
8988 if WANT_DEBUG
8989   DEBUGFLAGS = -DDEBUG
8990 endif
8991 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
8992 @end example
8994 @noindent or
8996 @example
8997 AM_CPPFLAGS = -DFEATURE_A
8998 if WANT_DEBUG
8999 AM_CPPFLAGS += -DDEBUG
9000 endif
9001 AM_CPPFLAGS += -DFEATURE_B
9002 @end example
9004 @node Gnits
9005 @chapter The effect of @option{--gnu} and @option{--gnits}
9007 @cindex @option{--gnu}, required files
9008 @cindex @option{--gnu}, complete description
9010 The @option{--gnu} option (or @option{gnu} in the
9011 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
9012 the following:
9014 @itemize @bullet
9015 @item
9016 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
9017 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
9018 or @file{COPYING}, are required at the topmost directory of the package.
9020 @item
9021 The options @option{no-installman} and @option{no-installinfo} are
9022 prohibited.
9023 @end itemize
9025 Note that this option will be extended in the future to do even more
9026 checking; it is advisable to be familiar with the precise requirements
9027 of the GNU standards.  Also, @option{--gnu} can require certain
9028 non-standard GNU programs to exist for use by various maintainer-only
9029 rules; for instance, in the future @command{pathchk} might be required for
9030 @samp{make dist}.
9032 @cindex @option{--gnits}, complete description
9034 The @option{--gnits} option does everything that @option{--gnu} does, and
9035 checks the following as well:
9037 @itemize @bullet
9038 @item
9039 @samp{make installcheck} will check to make sure that the @option{--help}
9040 and @option{--version} really print a usage message and a version string,
9041 respectively.  This is the @option{std-options} option (@pxref{Options}).
9043 @item
9044 @samp{make dist} will check to make sure the @file{NEWS} file has been
9045 updated to the current version.
9047 @item
9048 @code{VERSION} is checked to make sure its format complies with Gnits
9049 standards.
9050 @c FIXME xref when standards are finished
9052 @item
9053 @cindex @file{README-alpha}
9054 If @code{VERSION} indicates that this is an alpha release, and the file
9055 @file{README-alpha} appears in the topmost directory of a package, then
9056 it is included in the distribution.  This is done in @option{--gnits}
9057 mode, and no other, because this mode is the only one where version
9058 number formats are constrained, and hence the only mode where Automake
9059 can automatically determine whether @file{README-alpha} should be
9060 included.
9062 @item
9063 The file @file{THANKS} is required.
9064 @end itemize
9067 @node Cygnus
9068 @chapter The effect of @option{--cygnus}
9070 @cindex @option{cygnus} strictness
9072 Some packages, notably GNU GCC and GNU gdb, have a build environment
9073 originally written at Cygnus Support (subsequently renamed Cygnus
9074 Solutions, and then later purchased by Red Hat).  Packages with this
9075 ancestry are sometimes referred to as ``Cygnus'' trees.
9077 A Cygnus tree has slightly different rules for how a
9078 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
9079 @command{automake} will cause any generated @file{Makefile.in} to
9080 comply with Cygnus rules.
9082 Here are the precise effects of @option{--cygnus}:
9084 @itemize @bullet
9085 @item
9086 Info files are always created in the build directory, and not in the
9087 source directory.
9089 @item
9090 @file{texinfo.tex} is not required if a Texinfo source file is
9091 specified.  The assumption is that the file will be supplied, but in a
9092 place that Automake cannot find.  This assumption is an artifact of how
9093 Cygnus packages are typically bundled.
9095 @item
9096 @samp{make dist} is not supported, and the rules for it are not
9097 generated.  Cygnus-style trees use their own distribution mechanism.
9099 @item
9100 Certain tools will be searched for in the build tree as well as in the
9101 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
9102 @command{makeinfo} and @command{texi2dvi}.
9104 @item
9105 @option{--foreign} is implied.
9107 @item
9108 The options @option{no-installinfo} and @option{no-dependencies} are
9109 implied.
9111 @item
9112 The macros @code{AM_MAINTAINER_MODE} and @code{AM_CYGWIN32} are
9113 required.
9115 @item
9116 The @code{check} target doesn't depend on @code{all}.
9117 @end itemize
9119 GNU maintainers are advised to use @option{gnu} strictness in preference
9120 to the special Cygnus mode.  Some day, perhaps, the differences between
9121 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
9122 more standards compliant).  At that time the special Cygnus mode will be
9123 removed.
9126 @node Not Enough
9127 @chapter When Automake Isn't Enough
9129 In some situations, where Automake is not up to one task, one has to
9130 resort to handwritten rules or even handwritten @file{Makefile}s.
9132 @menu
9133 * Extending::                   Adding new rules or overriding existing ones.
9134 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
9135 @end menu
9137 @node Extending
9138 @section Extending Automake Rules
9140 With some minor exceptions (like @code{_PROGRAMS} variables being
9141 rewritten to append @samp{$(EXEEXT)}), the contents of a
9142 @file{Makefile.am} is copied to @file{Makefile.in} verbatim.
9144 @cindex copying semantics
9146 These copying semantics means that many problems can be worked around
9147 by simply adding some @command{make} variables and rules to
9148 @file{Makefile.am}.  Automake will ignore these additions.
9150 @cindex conflicting definitions
9151 @cindex rules, conflicting
9152 @cindex variables, conflicting
9153 @cindex definitions, conflicts
9155 Since a @file{Makefile.in} is built from data gathered from three
9156 different places (@file{Makefile.am}, @file{configure.ac}, and
9157 @command{automake} itself), it is possible to have conflicting
9158 definitions of rules or variables.  When building @file{Makefile.in}
9159 the following priorities are respected by @command{automake} to ensure
9160 the user always have the last word.  User defined variables in
9161 @file{Makefile.am} have priority over variables @code{AC_SUBST}ed from
9162 @file{configure.ac}, and @code{AC_SUBST}ed variables have priority
9163 over @command{automake}-defined variables.  As far rules are
9164 concerned, a user-defined rule overrides any
9165 @command{automake}-defined rule for the same target.
9167 @cindex overriding rules
9168 @cindex overriding semantics
9169 @cindex rules, overriding
9171 These overriding semantics make it possible to fine tune some default
9172 settings of Automake, or replace some of its rules.  Overriding
9173 Automake rules is often inadvisable, particularly in the topmost
9174 directory of a package with subdirectories.  The @option{-Woverride}
9175 option (@pxref{Invoking Automake}) comes handy to catch overridden
9176 definitions.
9178 Note that Automake does not make any difference between rules with
9179 commands and rules that only specify dependencies.  So it is not
9180 possible to append new dependencies to an @command{automake}-defined
9181 target without redefining the entire rule.
9183 @cindex @option{-local} targets
9184 @cindex local targets
9186 However, various useful targets have a @samp{-local} version you can
9187 specify in your @file{Makefile.am}.  Automake will supplement the
9188 standard target with these user-supplied targets.
9190 @trindex  all
9191 @trindex  all-local
9192 @trindex  info
9193 @trindex  info-local
9194 @trindex  dvi
9195 @trindex  dvi-local
9196 @trindex  ps
9197 @trindex  ps-local
9198 @trindex  pdf
9199 @trindex  pdf-local
9200 @trindex  html
9201 @trindex  html-local
9202 @trindex  check
9203 @trindex  check-local
9204 @trindex  install
9205 @trindex  install-data
9206 @trindex  install-data-local
9207 @trindex  install-dvi
9208 @trindex  install-dvi-local
9209 @trindex  install-exec
9210 @trindex  install-exec-local
9211 @trindex  install-html
9212 @trindex  install-html-local
9213 @trindex  install-info
9214 @trindex  install-info-local
9215 @trindex  install-pdf
9216 @trindex  install-pdf-local
9217 @trindex  install-ps
9218 @trindex  install-ps-local
9219 @trindex  uninstall
9220 @trindex  uninstall-local
9221 @trindex  mostlyclean
9222 @trindex  mostlyclean-local
9223 @trindex  clean
9224 @trindex  clean-local
9225 @trindex  distclean
9226 @trindex  distclean-local
9227 @trindex  installdirs
9228 @trindex  installdirs-local
9229 @trindex  installcheck
9230 @trindex  installcheck-local
9232 The targets that support a local version are @code{all}, @code{info},
9233 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
9234 @code{install-data}, @code{install-dvi}, @code{install-exec},
9235 @code{install-html}, @code{install-info}, @code{install-pdf},
9236 @code{install-ps}, @code{uninstall}, @code{installdirs},
9237 @code{installcheck} and the various @code{clean} targets
9238 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
9239 @code{maintainer-clean}).
9241 Note that there are no @code{uninstall-exec-local} or
9242 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
9243 It doesn't make sense to uninstall just data or just executables.
9245 For instance, here is one way to erase a subdirectory during
9246 @samp{make clean} (@pxref{Clean}).
9248 @example
9249 clean-local:
9250         -rm -rf testSubDir
9251 @end example
9253 Older version of this manual used to show how to use
9254 @code{install-data-local} to install a file to some hard-coded
9255 location, but you should avoid this.  (@pxref{Hard-Coded Install Paths})
9257 @cindex @option{-hook} targets
9258 @cindex hook targets
9260 Some rule also have a way to run another rule, called a @dfn{hook},
9261 after their work is done.  The hook is named after the principal target,
9262 with @samp{-hook} appended.  The targets allowing hooks are
9263 @code{install-data}, @code{install-exec}, @code{uninstall}, @code{dist},
9264 and @code{distcheck}.
9265 @trindex install-data-hook
9266 @trindex install-exec-hook
9267 @trindex uninstall-hook
9268 @trindex dist-hook
9270 For instance, here is how to create a hard link to an installed program:
9272 @example
9273 install-exec-hook:
9274         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
9275            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
9276 @end example
9278 Although cheaper and more portable than symbolic links, hard links
9279 will not work everywhere (for instance, OS/2 does not have
9280 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
9281 @command{ln} does not work.  An easy way, if symbolic links are
9282 acceptable to you, is to add @code{AC_PROG_LN_S} to
9283 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
9284 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
9285 @file{Makefile.am}.
9287 @cindex versioned binaries, installing
9288 @cindex installing versioned binaries
9289 @cindex @code{LN_S} example
9290 For instance, here is how you could install a versioned copy of a
9291 program using @samp{$(LN_S)}:
9293 @example
9294 install-exec-hook:
9295         cd $(DESTDIR)$(bindir) && \
9296           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
9297           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
9298 @end example
9300 Note that we rename the program so that a new version will erase the
9301 symbolic link, not the real binary.  Also we @command{cd} into the
9302 destination directory in order to create relative links.
9304 When writing @code{install-exec-hook} or @code{install-data-hook},
9305 please bear in mind that the exec/data distinction is based on the
9306 installation directory, not on the primary used (@pxref{Install}).  So
9307 a @code{foo_SCRIPTS} will be installed by @code{install-data}, and a
9308 @code{barexec_SCRIPTS} will be installed by @code{install-exec}.  You
9309 should define your hooks consequently.
9311 @c FIXME should include discussion of variables you can use in these
9312 @c rules
9314 @node Third-Party Makefiles
9315 @section Third-Party @file{Makefile}s
9317 @cindex Third-party packages, interfacing with
9318 @cindex Interfacing with third-party packages
9320 In most projects all @file{Makefile}s are generated by Automake.  In
9321 some cases, however, projects need to embed subdirectories with
9322 handwritten @file{Makefile}s.  For instance, one subdirectory could be
9323 a third-party project with its own build system, not using Automake.
9325 It is possible to list arbitrary directories in @code{SUBDIRS} or
9326 @code{DIST_SUBDIRS} provided each of these directories has a
9327 @file{Makefile} that recognizes all the following recursive targets.
9329 @cindex recursive targets and third-party @file{Makefile}s
9330 When a user runs one of these targets, that target is run recursively
9331 in all subdirectories.  This is why it is important that even
9332 third-party @file{Makefile}s support them.
9334 @table @code
9335 @item all
9336 Compile the entire package.  This is the default target in
9337 Automake-generated @file{Makefile}s, but it does not need to be the
9338 default in third-party @file{Makefile}s.
9340 @item distdir
9341 @trindex distdir
9342 @vindex distdir
9343 @vindex top_distdir
9344 Copy files to distribute into @samp{$(distdir)}, before a tarball is
9345 constructed.  Of course this target is not required if the
9346 @option{no-dist} option (@pxref{Options}) is used.
9348 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
9349 (@pxref{Dist}) will be passed from the outer package to the subpackage
9350 when the @code{distdir} target is invoked.  These two variables have
9351 been adjusted for the directory that is being recursed into, so they
9352 are ready to use.
9354 @item install
9355 @itemx install-data
9356 @itemx install-exec
9357 @itemx uninstall
9358 Install or uninstall files (@pxref{Install}).
9360 @item install-dvi
9361 @itemx install-html
9362 @itemx install-info
9363 @itemx install-ps
9364 @itemx install-pdf
9365 Install only some specific documentation format (@pxref{Texinfo}).
9367 @item installdirs
9368 Create install directories, but do not install any files.
9370 @item check
9371 @itemx installcheck
9372 Check the package (@pxref{Tests}).
9374 @item mostlyclean
9375 @itemx clean
9376 @itemx distclean
9377 @itemx maintainer-clean
9378 Cleaning rules (@pxref{Clean}).
9380 @item dvi
9381 @itemx pdf
9382 @itemx ps
9383 @itemx info
9384 @itemx html
9385 Build the documentation in various formats (@pxref{Texinfo}).
9387 @item tags
9388 @itemx ctags
9389 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
9390 @end table
9392 If you have ever used Gettext in a project, this is a good example of
9393 how third-party @file{Makefile}s can be used with Automake.  The
9394 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
9395 @file{intl/} directories are handwritten @file{Makefile}s that
9396 implement all these targets.  That way they can be added to
9397 @code{SUBDIRS} in Automake packages.
9399 Directories that are only listed in @code{DIST_SUBDIRS} but not in
9400 @code{SUBDIRS} need only the @code{distclean},
9401 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
9402 Subdirectories}).
9404 Usually, many of these rules are irrelevant to the third-party
9405 subproject, but they are required for the whole package to work.  It's
9406 OK to have a rule that does nothing, so if you are integrating a
9407 third-party project with no documentation or tag support, you could
9408 simply augment its @file{Makefile} as follows:
9410 @example
9411 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
9412 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
9413 $(EMPTY_AUTOMAKE_TARGETS):
9414 @end example
9416 Another aspect of integrating third-party build systems is whether
9417 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
9418 subpackage does not support VPATH builds the whole package will not
9419 support VPATH builds.  This in turns means that @samp{make distcheck}
9420 will not work, because it relies on VPATH builds.  Some people can
9421 live without this (actually, many Automake users have never heard of
9422 @samp{make distcheck}).  Other people may prefer to revamp the
9423 existing @file{Makefile}s to support VPATH@.  Doing so does not
9424 necessarily require Automake, only Autoconf is needed (@pxref{Build
9425 Directories, , Build Directories, autoconf, The Autoconf Manual}).
9426 The necessary substitutions: @samp{@@scrdir@@}, @samp{@@top_srcdir@@},
9427 and @samp{@@top_builddir@@} are defined by @file{configure} when it
9428 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
9429 Output Variables, autoconf, The Autoconf Manual}), they are not
9430 computed by the Makefile like the aforementioned @samp{$(distdir)} and
9431 @samp{$(top_distdir)} variables..
9433 It is sometimes inconvenient to modify a third-party @file{Makefile}
9434 to introduce the above required targets.  For instance, one may want to
9435 keep the third-party sources untouched to ease upgrades to new
9436 versions.
9438 @cindex @file{GNUmakefile} including @file{Makefile}
9439 Here are two other ideas.  If GNU make is assumed, one possibility is
9440 to add to that subdirectory a @file{GNUmakefile} that defines the
9441 required targets and include the third-party @file{Makefile}.  For
9442 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
9443 directory; the easiest way to do this is to write a
9444 @file{GNUmakefile.in} instead, and have it processed with
9445 @code{AC_CONFIG_FILES} from the outer package.  For example if we
9446 assume @file{Makefile} defines all targets except the documentation
9447 targets, and that the @code{check} target is actually called
9448 @code{test}, we could write @file{GNUmakefile} (or
9449 @file{GNUmakefile.in}) like this:
9451 @example
9452 # First, include the real Makefile
9453 include Makefile
9454 # Then, define the other targets needed by Automake Makefiles.
9455 .PHONY: dvi pdf ps info html check
9456 dvi pdf ps info html:
9457 check: test
9458 @end example
9460 @cindex Proxy @file{Makefile} for third-party packages
9461 A similar idea that does not use @code{include} is to write a proxy
9462 @file{Makefile} that dispatches rules to the real @file{Makefile},
9463 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
9464 it's OK to rename the original @file{Makefile}) or with @samp{cd
9465 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
9466 subdirectory project one directory deeper).  The good news is that
9467 this proxy @file{Makefile} can be generated with Automake.  All we
9468 need are @option{-local} targets (@pxref{Extending}) that perform the
9469 dispatch.  Of course the other Automake features are available, so you
9470 could decide to let Automake perform distribution or installation.
9471 Here is a possible @file{Makefile.am}:
9473 @example
9474 all-local:
9475         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
9476 check-local:
9477         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
9478 clean-local:
9479         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
9481 # Assuming the package knows how to install itself
9482 install-data-local:
9483         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
9484 install-exec-local:
9485         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
9486 uninstall-local:
9487         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
9489 # Distribute files from here.
9490 EXTRA_DIST = subdir/Makefile subdir/program.c ...
9491 @end example
9493 Pushing this idea to the extreme, it is also possible to ignore the
9494 subproject build system and build everything from this proxy
9495 @file{Makefile.am}.  This might sounds very sensible if you need VPATH
9496 builds but the subproject does not support them.
9498 @node Distributing
9499 @chapter Distributing @file{Makefile.in}s
9501 Automake places no restrictions on the distribution of the resulting
9502 @file{Makefile.in}s.  We still encourage software authors to
9503 distribute their work under terms like those of the GPL, but doing so
9504 is not required to use Automake.
9506 Some of the files that can be automatically installed via the
9507 @option{--add-missing} switch do fall under the GPL@.  However, these also
9508 have a special exception allowing you to distribute them with your
9509 package, regardless of the licensing you choose.
9512 @node API versioning
9513 @chapter Automake API versioning
9515 New Automake releases usually include bug fixes and new features.
9516 Unfortunately they may also introduce new bugs and incompatibilities.
9517 This makes four reasons why a package may require a particular Automake
9518 version.
9520 Things get worse when maintaining a large tree of packages, each one
9521 requiring a different version of Automake.  In the past, this meant that
9522 any developer (and sometime users) had to install several versions of
9523 Automake in different places, and switch @samp{$PATH} appropriately for
9524 each package.
9526 Starting with version 1.6, Automake installs versioned binaries.  This
9527 means you can install several versions of Automake in the same
9528 @samp{$prefix}, and can select an arbitrary Automake version by running
9529 @command{automake-1.6} or @command{automake-1.7} without juggling with
9530 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
9531 will use @command{automake-1.6} explicitly in their rebuild rules.
9533 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
9534 not Automake's version.  If a bug fix release is made, for instance
9535 Automake 1.6.1, the API version will remain 1.6.  This means that a
9536 package that works with Automake 1.6 should also work with 1.6.1; after
9537 all, this is what people expect from bug fix releases.
9539 If your package relies on a feature or a bug fix introduced in
9540 a release, you can pass this version as an option to Automake to ensure
9541 older releases will not be used.  For instance, use this in your
9542 @file{configure.ac}:
9544 @example
9545   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
9546 @end example
9547 @noindent
9548 or, in a particular @file{Makefile.am}:
9550 @example
9551   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
9552 @end example
9553 @noindent
9554 Automake will print an error message if its version is
9555 older than the requested version.
9558 @heading What is in the API
9560 Automake's programming interface is not easy to define.  Basically it
9561 should include at least all @strong{documented} variables and targets
9562 that a @file{Makefile.am} author can use, any behavior associated with
9563 them (e.g., the places where @samp{-hook}'s are run), the command line
9564 interface of @command{automake} and @command{aclocal}, @dots{}
9566 @heading What is not in the API
9568 Every undocumented variable, target, or command line option, is not part
9569 of the API@.  You should avoid using them, as they could change from one
9570 version to the other (even in bug fix releases, if this helps to fix a
9571 bug).
9573 If it turns out you need to use such a undocumented feature, contact
9574 @email{automake@@gnu.org} and try to get it documented and exercised by
9575 the test-suite.
9577 @node Upgrading
9578 @chapter Upgrading a Package to a Newer Automake Version
9580 Automake maintains three kind of files in a package.
9582 @itemize
9583 @item @file{aclocal.m4}
9584 @item @file{Makefile.in}s
9585 @item auxiliary tools like @file{install-sh} or @file{py-compile}
9586 @end itemize
9588 @file{aclocal.m4} is generated by @command{aclocal} and contains some
9589 Automake-supplied M4 macros.  Auxiliary tools are installed by
9590 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
9591 built from @file{Makefile.am} by @command{automake}, and rely on the
9592 definitions of the M4 macros put in @file{aclocal.m4} as well as the
9593 behavior of the auxiliary tools installed.
9595 Because all these files are closely related, it is important to
9596 regenerate all of them when upgrading to a newer Automake release.
9597 The usual way to do that is
9599 @example
9600 aclocal # with any option needed (such a -I m4)
9601 autoconf
9602 automake --add-missing --force-missing
9603 @end example
9605 @noindent
9606 or more conveniently:
9608 @example
9609 autoreconf -vfi
9610 @end example
9612 The use of @option{--force-missing} ensures that auxiliary tools will be
9613 overridden by new versions (@pxref{Invoking Automake}).
9615 It is important to regenerate all these files each time Automake is
9616 upgraded, even between bug fixes releases.  For instance, it is not
9617 unusual for a bug fix to involve changes to both the rules generated
9618 in @file{Makefile.in} and the supporting M4 macros copied to
9619 @file{aclocal.m4}.
9621 Presently @command{automake} is able to diagnose situations where
9622 @file{aclocal.m4} has been generated with another version of
9623 @command{aclocal}.  However it never checks whether auxiliary scripts
9624 are up-to-date.  In other words, @command{automake} will tell you when
9625 @command{aclocal} needs to be rerun, but it will never diagnose a
9626 missing @option{--force-missing}.
9628 Before upgrading to a new major release, it is a good idea to read the
9629 file @file{NEWS}.  This file lists all changes between releases: new
9630 features, obsolete constructs, known incompatibilities, and
9631 workarounds.
9633 @node FAQ
9634 @chapter Frequently Asked Questions about Automake
9636 This chapter covers some questions that often come up on the mailing
9637 lists.
9639 @menu
9640 * CVS::                         CVS and generated files
9641 * maintainer-mode::             missing and AM_MAINTAINER_MODE
9642 * wildcards::                   Why doesn't Automake support wildcards?
9643 * limitations on file names::   Limitations on source and installed file names
9644 * distcleancheck::              Files left in build directory after distclean
9645 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
9646 * renamed objects::             Why are object files sometimes renamed?
9647 * Per-Object Flags::            How to simulate per-object flags?
9648 * Multiple Outputs::            Writing rules for tools with many output files
9649 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
9650 @end menu
9652 @node CVS
9653 @section CVS and generated files
9655 @subsection Background: distributed generated files
9656 @cindex generated files, distributed
9657 @cindex rebuild rules
9659 Packages made with Autoconf and Automake ship with some generated
9660 files like @file{configure} or @file{Makefile.in}.  These files were
9661 generated on the developer's host and are distributed so that
9662 end-users do not have to install the maintainer tools required to
9663 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
9664 or Info documentation, are usually distributed on similar grounds.
9666 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
9667 instance, @command{make} will run @command{autoconf} to rebuild
9668 @file{configure} whenever @file{configure.ac} is changed.  This makes
9669 development safer by ensuring a @file{configure} is never out-of-date
9670 with respect to @file{configure.ac}.
9672 As generated files shipped in packages are up-to-date, and because
9673 @command{tar} preserves times-tamps, these rebuild rules are not
9674 triggered when a user unpacks and builds a package.
9676 @subsection Background: CVS and timestamps
9677 @cindex timestamps and CVS
9678 @cindex CVS and timestamps
9680 Unless you use CVS keywords (in which case files must be updated at
9681 commit time), CVS preserves timestamp during @samp{cvs commit} and
9682 @samp{cvs import -d} operations.
9684 When you check out a file using @samp{cvs checkout} its timestamp is
9685 set to that of the revision that is being checked out.
9687 However, during @command{cvs update}, files will have the date of the
9688 update, not the original timestamp of this revision.  This is meant to
9689 make sure that @command{make} notices sources files have been updated.
9691 This timestamp shift is troublesome when both sources and generated
9692 files are kept under CVS@.  Because CVS processes files in alphabetical
9693 order, @file{configure.ac} will appear older than @file{configure}
9694 after a @command{cvs update} that updates both files, even if
9695 @file{configure} was newer than @file{configure.ac} when it was
9696 checked in.  Calling @command{make} will then trigger a spurious rebuild
9697 of @file{configure}.
9699 @subsection Living with CVS in Autoconfiscated projects
9700 @cindex CVS and generated files
9701 @cindex generated files and CVS
9703 There are basically two clans amongst maintainers: those who keep all
9704 distributed files under CVS, including generated files, and those who
9705 keep generated files @emph{out} of CVS.
9707 @subsubheading All files in CVS
9709 @itemize @bullet
9710 @item
9711 The CVS repository contains all distributed files so you know exactly
9712 what is distributed, and you can checkout any prior version entirely.
9714 @item
9715 Maintainers can see how generated files evolve (for instance, you can
9716 see what happens to your @file{Makefile.in}s when you upgrade Automake
9717 and make sure they look OK).
9719 @item
9720 Users do not need the autotools to build a checkout of the project, it
9721 works just like a released tarball.
9723 @item
9724 If users use @command{cvs update} to update their copy, instead of
9725 @command{cvs checkout} to fetch a fresh one, timestamps will be
9726 inaccurate.  Some rebuild rules will be triggered and attempt to
9727 run developer tools such as @command{autoconf} or @command{automake}.
9729 Actually, calls to such tools are all wrapped into a call to the
9730 @command{missing} script discussed later (@pxref{maintainer-mode}).
9731 @command{missing} will take care of fixing the timestamps when these
9732 tools are not installed, so that the build can continue.
9734 @item
9735 In distributed development, developers are likely to have different
9736 version of the maintainer tools installed.  In this case rebuilds
9737 triggered by timestamp lossage will lead to spurious changes
9738 to generated files.  There are several solutions to this:
9740 @itemize
9741 @item
9742 All developers should use the same versions, so that the rebuilt files
9743 are identical to files in CVS@.  (This starts to be difficult when each
9744 project you work on uses different versions.)
9745 @item
9746 Or people use a script to fix the timestamp after a checkout (the GCC
9747 folks have such a script).
9748 @item
9749 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
9750 disable all these rebuild rules by default.  This is further discussed
9751 in @ref{maintainer-mode}.
9752 @end itemize
9754 @item
9755 Although we focused on spurious rebuilds, the converse can also
9756 happen.  CVS's timestamp handling can also let you think an
9757 out-of-date file is up-to-date.
9759 For instance, suppose a developer has modified @file{Makefile.am} and
9760 has rebuilt @file{Makefile.in}.  He then decide to do a last-minute
9761 change to @file{Makefile.am} right before checking in both files
9762 (without rebuilding @file{Makefile.in} to account for the change).
9764 This last change to @file{Makefile.am} make the copy of
9765 @file{Makefile.in} out-of-date.  Since CVS processes files
9766 alphabetically, when another developer @samp{cvs update} his or her
9767 tree, @file{Makefile.in} will happen to be newer than
9768 @file{Makefile.am}.  This other developer will not see
9769 @file{Makefile.in} is out-of-date.
9771 @end itemize
9773 @subsubheading Generated files out of CVS
9775 One way to get CVS and @command{make} working peacefully is to never
9776 store generated files in CVS, i.e., do not CVS-control files that
9777 are @file{Makefile} targets (also called @emph{derived} files).
9779 This way developers are not annoyed by changes to generated files.  It
9780 does not matter if they all have different versions (assuming they are
9781 compatible, of course).  And finally, timestamps are not lost, changes
9782 to sources files can't be missed as in the
9783 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
9785 The drawback is that the CVS repository is not an exact copy of what
9786 is distributed and that users now need to install various development
9787 tools (maybe even specific versions) before they can build a checkout.
9788 But, after all, CVS's job is versioning, not distribution.
9790 Allowing developers to use different versions of their tools can also
9791 hide bugs during distributed development.  Indeed, developers will be
9792 using (hence testing) their own generated files, instead of the
9793 generated files that will be released actually.  The developer who
9794 prepares the tarball might be using a version of the tool that
9795 produces bogus output (for instance a non-portable C file), something
9796 other developers could have noticed if they weren't using their own
9797 versions of this tool.
9799 @subsection Third-party files
9800 @cindex CVS and third-party files
9801 @cindex third-party files and CVS
9803 Another class of files not discussed here (because they do not cause
9804 timestamp issues) are files that are shipped with a package, but
9805 maintained elsewhere.  For instance, tools like @command{gettextize}
9806 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
9807 Libtool), will install or update files in your package.
9809 These files, whether they are kept under CVS or not, raise similar
9810 concerns about version mismatch between developers' tools.  The
9811 Gettext manual has a section about this, see @ref{CVS Issues, CVS
9812 Issues, Integrating with CVS, gettext, GNU gettext tools}.
9814 @node maintainer-mode
9815 @section @command{missing} and @code{AM_MAINTAINER_MODE}
9817 @subsection @command{missing}
9818 @cindex @command{missing}, purpose
9820 The @command{missing} script is a wrapper around several maintainer
9821 tools, designed to warn users if a maintainer tool is required but
9822 missing.  Typical maintainer tools are @command{autoconf},
9823 @command{automake}, @command{bison}, etc.  Because file generated by
9824 these tools are shipped with the other sources of a package, these
9825 tools shouldn't be required during a user build and they are not
9826 checked for in @file{configure}.
9828 However, if for some reason a rebuild rule is triggered and involves a
9829 missing tool, @command{missing} will notice it and warn the user.
9830 Besides the warning, when a tool is missing, @command{missing} will
9831 attempt to fix timestamps in a way that allows the build to continue.
9832 For instance, @command{missing} will touch @file{configure} if
9833 @command{autoconf} is not installed.  When all distributed files are
9834 kept under CVS, this feature of @command{missing} allows user
9835 @emph{with no maintainer tools} to build a package off CVS, bypassing
9836 any timestamp inconsistency implied by @samp{cvs update}.
9838 If the required tool is installed, @command{missing} will run it and
9839 won't attempt to continue after failures.  This is correct during
9840 development: developers love fixing failures.  However, users with
9841 wrong versions of maintainer tools may get an error when the rebuild
9842 rule is spuriously triggered, halting the build.  This failure to let
9843 the build continue is one of the arguments of the
9844 @code{AM_MAINTAINER_MODE} advocates.
9846 @subsection @code{AM_MAINTAINER_MODE}
9847 @cindex @code{AM_MAINTAINER_MODE}, purpose
9848 @acindex AM_MAINTAINER_MODE
9850 @code{AM_MAINTAINER_MODE} disables the so called "rebuild rules" by
9851 default.  If you have @code{AM_MAINTAINER_MODE} in
9852 @file{configure.ac}, and run @samp{./configure && make}, then
9853 @command{make} will *never* attempt to rebuilt @file{configure},
9854 @file{Makefile.in}s, Lex or Yacc outputs, etc.  I.e., this disables
9855 build rules for files that are usually distributed and that users
9856 should normally not have to update.
9858 If you run @samp{./configure --enable-maintainer-mode}, then these
9859 rebuild rules will be active.
9861 People use @code{AM_MAINTAINER_MODE} either because they do want their
9862 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
9863 because they simply can't stand the rebuild rules and prefer running
9864 maintainer tools explicitly.
9866 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
9867 rules conditionally.  Some developers use this feature to disable
9868 rules that need exotic tools that users may not have available.
9870 Several years ago Fran@,{c}ois Pinard pointed out several arguments
9871 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
9872 insecurity.  By removing dependencies you get non-dependable builds:
9873 change to sources files can have no effect on generated files and this
9874 can be very confusing when unnoticed.  He adds that security shouldn't
9875 be reserved to maintainers (what @option{--enable-maintainer-mode}
9876 suggests), on the contrary.  If one user has to modify a
9877 @file{Makefile.am}, then either @file{Makefile.in} should be updated
9878 or a warning should be output (this is what Automake uses
9879 @command{missing} for) but the last thing you want is that nothing
9880 happens and the user doesn't notice it (this is what happens when
9881 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
9883 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
9884 swayed by Fran@,{c}ois's arguments, and got rid of
9885 @code{AM_MAINTAINER_MODE} in all of his packages.
9887 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
9888 it helps them working on projects where all files are kept under CVS,
9889 and because @command{missing} isn't enough if you have the wrong
9890 version of the tools.
9893 @node wildcards
9894 @section Why doesn't Automake support wildcards?
9895 @cindex wildcards
9897 Developers are lazy.  They often would like to use wildcards in
9898 @file{Makefile.am}s, so they don't need to remember they have to
9899 update @file{Makefile.am}s every time they add, delete, or rename a
9900 file.
9902 There are several objections to this:
9903 @itemize
9904 @item
9905 When using CVS (or similar) developers need to remember they have to
9906 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
9907 @file{Makefile.am} accordingly quickly becomes a reflex.
9909 Conversely, if your application doesn't compile
9910 because you forgot to add a file in @file{Makefile.am}, it will help
9911 you remember to @samp{cvs add} it.
9913 @item
9914 Using wildcards makes easy to distribute files by mistake.  For
9915 instance, some code a developer is experimenting with (a test case,
9916 say) but that should not be part of the distribution.
9918 @item
9919 Using wildcards it's easy to omit some files by mistake.  For
9920 instance, one developer creates a new file, uses it at many places,
9921 but forget to commit it.  Another developer then checkout the
9922 incomplete project and is able to run `make dist' successfully,
9923 even though a file is missing.
9925 @item
9926 Listing files, you control *exactly* what you distribute.
9927 If some file that should be distributed is missing from your
9928 tree, @samp{make dist} will complain.  Besides, you don't distribute
9929 more than what you listed.
9931 @item
9932 Finally it's really hard to @file{forget} adding a file to
9933 @file{Makefile.am}, because if you don't add it, it doesn't get
9934 compiled nor installed, so you can't even test it.
9935 @end itemize
9937 Still, these are philosophical objections, and as such you may disagree,
9938 or find enough value in wildcards to dismiss all of them.  Before you
9939 start writing a patch against Automake to teach it about wildcards,
9940 let's see the main technical issue: portability.
9942 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
9943 not portable to other @command{make} implementations.
9945 The only way Automake could support @command{$(wildcard ...)} is by
9946 expending @command{$(wildcard ...)} when @command{automake} is run.
9947 Resulting @file{Makefile.in}s would be portable since they would
9948 list all files and not use @samp{$(wildcard ...)}.  However that
9949 means developers need to remember they must run @command{automake} each
9950 time they add, delete, or rename files.
9952 Compared to editing @file{Makefile.am}, this is really little win.  Sure,
9953 it's easier and faster to type @samp{automake; make} than to type
9954 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
9955 patch add support for this syntax.  Some people use scripts to
9956 generated file lists in @file{Makefile.am} or in separate
9957 @file{Makefile} fragments.
9959 Even if you don't care about portability, and are tempted to use
9960 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
9961 should know there are many places where Automake need to know exactly
9962 which files should be processed.  As Automake doesn't know how to
9963 expand @samp{$(wildcard ...)}, you cannot use it in these places.
9964 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
9965 variables as far Automake is concerned.
9967 You can get warnings about @samp{$(wildcard ...}) constructs using the
9968 @option{-Wportability} flag.
9970 @node limitations on file names
9971 @section Limitations on file names
9972 @cindex file names, limitations on
9974 Automake attempts to support all kinds of file names, even those that
9975 contain unusual characters or are unusually long.  However, some
9976 limitations are imposed by the underlying operating system and tools.
9978 Most operating systems prohibit the use of the null byte in file
9979 names, and reserve @samp{/} as a directory separator.  Also, they
9980 require that file names are properly encoded for the user's locale.
9981 Automake is subject to these limits.
9983 Portable packages should limit themselves to @acronym{POSIX} file
9984 names.  These can contain @acronym{ASCII} letters and digits,
9985 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
9986 separated by @samp{/}.  File name components cannot begin with
9987 @samp{-}.
9989 Portable POSIX file names cannot contain components that exceed a
9990 14-byte limit, but nowadays it's normally safe to assume the
9991 more-generous @acronym{XOPEN} limit of 255 bytes.  @acronym{POSIX}
9992 limits file names to 255 bytes (@acronym{XOPEN} allows 1023 bytes),
9993 but you may want to limit a source tarball to file names to 99 bytes
9994 to avoid interoperability problems with old versions of @command{tar}.
9996 If you depart from these rules (e.g., by using non-@acronym{ASCII}
9997 characters in file names, or by using lengthy file names), your
9998 installers may have problems for reasons unrelated to Automake.
9999 However, if this does not concern you, you should know about the
10000 limitations imposed by Automake itself.  These limitations are
10001 undesirable, but some of them seem to be inherent to underlying tools
10002 like Autoconf, Make, M4, and the shell.  They fall into three
10003 categories: install directories, build directories, and file names.
10005 The following characters:
10007 @example
10008 @r{newline} " # $ ' `
10009 @end example
10011 should not appear in the names of install directories.  For example,
10012 the operand of @command{configure}'s @option{--prefix} option should
10013 not contain these characters.
10015 Build directories suffer the same limitations as install directories,
10016 and in addition should not contain the following characters:
10018 @example
10019 & @@ \
10020 @end example
10022 For example, the full name of the directory containing the source
10023 files should not contain these characters.
10025 Source and installation file names like @file{main.c} are limited even
10026 further: they should conform to the @acronym{POSIX}/@acronym{XOPEN}
10027 rules described above.  In addition, if you plan to port to
10028 non-@acronym{POSIX} environments, you should avoid file names that
10029 differ only in case (e.g., @file{makefile} and @file{Makefile}).
10030 Nowadays it is no longer worth worrying about the 8.3 limits of
10031 @acronym{DOS} file systems.
10033 @node distcleancheck
10034 @section Files left in build directory after distclean
10035 @cindex @code{distclean}, diagnostic
10036 @cindex @samp{make distclean}, diagnostic
10037 @cindex dependencies and distributed files
10038 @trindex distclean
10039 @trindex distcleancheck
10041 This is a diagnostic you might encounter while running @samp{make
10042 distcheck}.
10044 As explained in @ref{Dist}, @samp{make distcheck} attempts to build
10045 and check your package for errors like this one.
10047 @samp{make distcheck} will perform a @code{VPATH} build of your
10048 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
10049 Files left in the build directory after @samp{make distclean} has run
10050 are listed after this error.
10052 This diagnostic really covers two kinds of errors:
10054 @itemize @bullet
10055 @item
10056 files that are forgotten by distclean;
10057 @item
10058 distributed files that are erroneously rebuilt.
10059 @end itemize
10061 The former left-over files are not distributed, so the fix is to mark
10062 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
10063 more explanations.
10065 The latter bug is not always easy to understand and fix, so let's
10066 proceed with an example.  Suppose our package contains a program for
10067 which we want to build a man page using @command{help2man}.  GNU
10068 @command{help2man} produces simple manual pages from the @option{--help}
10069 and @option{--version} output of other commands (@pxref{Top, , Overview,
10070 help2man, The Help2man Manual}).  Because we don't to force want our
10071 users to install @command{help2man}, we decide to distribute the
10072 generated man page using the following setup.
10074 @example
10075 # This Makefile.am is bogus.
10076 bin_PROGRAMS = foo
10077 foo_SOURCES = foo.c
10078 dist_man_MANS = foo.1
10080 foo.1: foo$(EXEEXT)
10081         help2man --output=foo.1 ./foo$(EXEEXT)
10082 @end example
10084 This will effectively distribute the man page.  However,
10085 @samp{make distcheck} will fail with:
10087 @example
10088 ERROR: files left in build directory after distclean:
10089 ./foo.1
10090 @end example
10092 Why was @file{foo.1} rebuilt?  Because although distributed,
10093 @file{foo.1} depends on a non-distributed built file:
10094 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
10095 will always appear to be newer than the distributed @file{foo.1}.
10097 @samp{make distcheck} caught an inconsistency in our package.  Our
10098 intent was to distribute @file{foo.1} so users do not need installing
10099 @command{help2man}, however since this our rule causes this file to be
10100 always rebuilt, users @emph{do} need @command{help2man}.  Either we
10101 should ensure that @file{foo.1} is not rebuilt by users, or there is
10102 no point in distributing @file{foo.1}.
10104 More generally, the rule is that distributed files should never depend
10105 on non-distributed built files.  If you distribute something
10106 generated, distribute its sources.
10108 One way to fix the above example, while still distributing
10109 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
10110 assuming @command{foo --version} and @command{foo --help} do not
10111 change unless @file{foo.c} or @file{configure.ac} change, we could
10112 write the following @file{Makefile.am}:
10114 @example
10115 bin_PROGRAMS = foo
10116 foo_SOURCES = foo.c
10117 dist_man_MANS = foo.1
10119 foo.1: foo.c $(top_srcdir)/configure.ac
10120         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
10121         help2man --output=foo.1 ./foo$(EXEEXT)
10122 @end example
10124 This way, @file{foo.1} will not get rebuilt every time
10125 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
10126 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
10127 way to ensure this would be to use separate directories for binaries
10128 and man pages, and set @code{SUBDIRS} so that binaries are built
10129 before man pages.
10131 We could also decide not to distribute @file{foo.1}.  In
10132 this case it's fine to have @file{foo.1} dependent upon
10133 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
10134 However it would be impossible to build the package in a
10135 cross-compilation, because building @file{foo.1} involves
10136 an @emph{execution} of @file{foo$(EXEEXT)}.
10138 Another context where such errors are common is when distributed files
10139 are built by tools that are built by the package.  The pattern is
10140 similar:
10142 @example
10143 distributed-file: built-tools distributed-sources
10144         build-command
10145 @end example
10147 @noindent
10148 should be changed to
10150 @example
10151 distributed-file: distributed-sources
10152         $(MAKE) $(AM_MAKEFLAGS) built-tools
10153         build-command
10154 @end example
10156 @noindent
10157 or you could choose not to distribute @file{distributed-file}, if
10158 cross-compilation does not matter.
10160 The points made through these examples are worth a summary:
10162 @cartouche
10163 @itemize
10164 @item
10165 Distributed files should never depend upon non-distributed built
10166 files.
10167 @item
10168 Distributed files should be distributed with all their dependencies.
10169 @item
10170 If a file is @emph{intended} to be rebuilt by users, then there is no point
10171 in distributing it.
10172 @end itemize
10173 @end cartouche
10175 @vrindex distcleancheck_listfiles
10176 For desperate cases, it's always possible to disable this check by
10177 setting @code{distcleancheck_listfiles} as documented in @ref{Dist}.
10178 Make sure you do understand the reason why @samp{make distcheck}
10179 complains before you do this.  @code{distcleancheck_listfiles} is a
10180 way to @emph{hide} errors, not to fix them.  You can always do better.
10182 @node Flag Variables Ordering
10183 @section Flag Variables Ordering
10184 @cindex Ordering flag variables
10185 @cindex Flag variables, ordering
10187 @display
10188 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
10189 @code{mumble_CFLAGS}?
10190 @end display
10192 @display
10193 Why does @command{automake} output @code{CPPFLAGS} after
10194 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
10195 @end display
10197 @display
10198 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
10199 one @file{Makefile.am} I would like to append a new flag, however if I
10200 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
10201 flags, not appended.
10202 @end display
10204 @subsection Compile Flag Variables
10205 @cindex Flag Variables, Ordering
10206 @cindex Compile Flag Variables
10207 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
10208 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
10209 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
10210 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
10211 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
10212 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
10213 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
10214 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
10215 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
10216 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
10217 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
10218 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
10219 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
10220 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
10221 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
10222 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
10223 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
10224 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
10225 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
10226 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
10227 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
10228 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
10229 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
10230 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
10231 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
10232 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
10233 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
10234 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
10236 This section attempts to answer all the above questions.  We will
10237 mostly discuss @code{CPPFLAGS} in our examples, but actually the
10238 answer holds for all the compile flags used in Automake:
10239 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
10240 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
10241 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
10242 @code{UPCFLAGS}, and @code{YFLAGS}.
10244 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
10245 three variables that can be used to pass flags to the C preprocessor
10246 (actually these variables are also used for other languages like C++
10247 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
10248 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
10249 and @code{mumble_CPPFLAGS} is the variable specific to the
10250 @code{mumble} target (we call this a per-target variable,
10251 @pxref{Program and Library Variables}).
10253 Automake always uses two of these variables when compiling C sources
10254 files.  When compiling an object file for the @code{mumble} target,
10255 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
10256 @code{AM_CPPFLAGS} otherwise.  The second variable is always
10257 @code{CPPFLAGS}.
10259 In the following example,
10261 @example
10262 bin_PROGRAMS = foo bar
10263 foo_SOURCES = xyz.c
10264 bar_SOURCES = main.c
10265 foo_CPPFLAGS = -DFOO
10266 AM_CPPFLAGS = -DBAZ
10267 @end example
10269 @noindent
10270 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
10271 (because @file{xyz.o} is part of the @code{foo} target), while
10272 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
10273 (because there is no per-target variable for target @code{bar}).
10275 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
10276 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
10277 is a user variable, i.e., a variable that users are entitled to modify
10278 in order to compile the package.  This variable, like many others,
10279 is documented at the end of the output of @samp{configure --help}.
10281 For instance, someone who needs to add @file{/home/my/usr/include} to
10282 the C compiler's search path would configure a package with
10284 @example
10285 ./configure CPPFLAGS='-I /home/my/usr/include'
10286 @end example
10288 @noindent
10289 and this flag would be propagated to the compile rules of all
10290 @file{Makefile}s.
10292 It is also not uncommon to override a user variable at
10293 @command{make}-time.  Many installers do this with @code{prefix}, but
10294 this can be useful with compiler flags too.  For instance, if, while
10295 debugging a C++ project, you need to disable optimization in one
10296 specific object file, you can run something like
10298 @example
10299 rm file.o
10300 make CXXFLAGS=-O0 file.o
10301 make
10302 @end example
10304 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
10305 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
10306 should always have the last say.  It probably makes more sense if you
10307 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
10308 should supersede any other switch from @code{AM_CXXFLAGS} or
10309 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
10310 of @code{CXXFLAGS}).
10312 You should never redefine a user variable such as @code{CPPFLAGS} in
10313 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
10314 mistakes.  Even something like
10316 @example
10317 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
10318 @end example
10320 @noindent
10321 is erroneous.  Although this preserves @file{configure}'s value of
10322 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
10323 user attempts to override @code{CPPFLAGS} from the @command{make}
10324 command line.
10326 @example
10327 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
10328 @end example
10330 @noindent
10331 is all what is needed here if no per-target flags are used.
10333 You should not add options to these user variables within
10334 @file{configure} either, for the same reason.  Occasionally you need
10335 to modify these variables to perform a test, but you should reset
10336 their values afterwards.  In contrast, it is OK to modify the
10337 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
10338 them, but it is rather rare that you need to do this, unless you
10339 really want to change the default definitions of the @samp{AM_}
10340 variables in all @file{Makefile}s.
10342 What we recommend is that you define extra flags in separate
10343 variables.  For instance, you may write an Autoconf macro that computes
10344 a set of warning options for the C compiler, and @code{AC_SUBST} them
10345 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
10346 determines which compiler and which linker flags should be used to
10347 link with library @file{libfoo}, and @code{AC_SUBST} these in
10348 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
10349 @file{Makefile.am} could use these variables as follows:
10351 @example
10352 AM_CFLAGS = $(WARNINGCFLAGS)
10353 bin_PROGRAMS = prog1 prog2
10354 prog1_SOURCES = @dots{}
10355 prog2_SOURCES = @dots{}
10356 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
10357 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
10358 @end example
10360 In this example both programs will be compiled with the flags
10361 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
10362 additionally be compiled with the flags required to link with
10363 @file{libfoo}.
10365 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
10366 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
10367 every target in a @file{Makefile.in}.
10369 Using variables like this gives you full control over the ordering of
10370 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
10371 you want to negate for a particular target, you can use something like
10372 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
10373 been forcefully appended to @code{CFLAGS}, there would be no way to
10374 disable one flag.  Yet another reason to leave user variables to
10375 users.
10377 Finally, we have avoided naming the variable of the example
10378 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
10379 Automake to think that this is actually a per-target variable (like
10380 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
10382 @subsection Other Variables
10384 There are other variables in Automake that follow similar principles
10385 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
10386 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
10387 DejaGnu tests (@pxref{Tests}) use @code{RUNTESTDEFAULTFLAGS} and
10388 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
10389 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
10390 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
10391 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
10392 of these rules do support per-target flags (yet).
10394 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
10395 obeys this naming scheme.  The slight difference is that
10396 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
10397 @command{make} itself.
10399 However you should not think that all variables ending with
10400 @code{FLAGS} follow this convention.  For instance,
10401 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Dist}),
10402 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
10403 are two variables that are only useful to the maintainer and have no
10404 user counterpart.
10406 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
10407 has neither @code{AM_} nor per-target cousin.
10409 Finally you should not think either that the existence of a per-target
10410 variable implies that of an @code{AM_} variable or that of a user
10411 variable.  For instance, the @code{mumble_LDADD} per-target variable
10412 overrides the global @code{LDADD} variable (which is not a user
10413 variable), and @code{mumble_LIBADD} exists only as a per-target
10414 variable.  @xref{Program and Library Variables}.
10417 @node renamed objects
10418 @section Why are object files sometimes renamed?
10420 This happens when per-target compilation flags are used.  Object
10421 files need to be renamed just in case they would clash with object
10422 files compiled from the same sources, but with different flags.
10423 Consider the following example.
10425 @example
10426 bin_PROGRAMS = true false
10427 true_SOURCES = generic.c
10428 true_CPPFLAGS = -DEXIT_CODE=0
10429 false_SOURCES = generic.c
10430 false_CPPFLAGS = -DEXIT_CODE=1
10431 @end example
10432 @noindent
10433 Obviously the two programs are built from the same source, but it
10434 would be bad if they shared the same object, because @file{generic.o}
10435 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
10436 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
10437 build two different objects: @file{true-generic.o} and
10438 @file{false-generic.o}.
10440 @command{automake} doesn't actually look whether source files are
10441 shared to decide if it must rename objects.  It will just rename all
10442 objects of a target as soon as it sees per-target compilation flags
10443 are used.
10445 It's OK to share object files when per-target compilation flags are not
10446 used.  For instance, @file{true} and @file{false} will both use
10447 @file{version.o} in the following example.
10449 @example
10450 AM_CPPFLAGS = -DVERSION=1.0
10451 bin_PROGRAMS = true false
10452 true_SOURCES = true.c version.c
10453 false_SOURCES = false.c version.c
10454 @end example
10456 Note that the renaming of objects is also affected by the
10457 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
10460 @node Per-Object Flags
10461 @section Per-Object Flags Emulation
10462 @cindex Per-object flags, emulated
10464 @display
10465 One of my source files needs to be compiled with different flags.  How
10466 do I do?
10467 @end display
10469 Automake supports per-program and per-library compilation flags (see
10470 @ref{Program and Library Variables} and @ref{Flag Variables
10471 Ordering}).  With this you can define compilation flags that apply to
10472 all files compiled for a target.  For instance, in
10474 @example
10475 bin_PROGRAMS = foo
10476 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
10477 foo_CFLAGS = -some -flags
10478 @end example
10480 @noindent
10481 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
10482 compiled with @samp{-some -flags}.  (If you wonder about the names of
10483 these object files, see @ref{renamed objects}.)  Note that
10484 @code{foo_CFLAGS} gives the flags to use when compiling all the C
10485 sources of the @emph{program} @code{foo}, it has nothing to do with
10486 @file{foo.c} or @file{foo-foo.o} specifically.
10488 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
10489 specific flags, that none of the other files require?  Obviously
10490 per-program flags are not directly applicable here.  Something like
10491 per-object flags are expected, i.e., flags that would be used only
10492 when creating @file{foo-foo.o}.  Automake does not support that,
10493 however this is easy to simulate using a library that contains only
10494 that object, and compiling this library with per-library flags.
10496 @example
10497 bin_PROGRAMS = foo
10498 foo_SOURCES = bar.c bar.h main.c
10499 foo_CFLAGS = -some -flags
10500 foo_LDADD = libfoo.a
10501 noinst_LIBRARIES = libfoo.a
10502 libfoo_a_SOURCES = foo.c foo.h
10503 libfoo_a_CFLAGS = -some -other -flags
10504 @end example
10506 Here @file{foo-bar.o} and @file{foo-main.o} will all be
10507 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
10508 be compiled using @samp{-some -other -flags}.  Eventually, all
10509 three objects will be linked to form @file{foo}.
10511 This trick can also be achieved using Libtool convenience libraries,
10512 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
10513 Convenience Libraries}).
10515 Another tempting idea to implement per-object flags is to override the
10516 compile rules @command{automake} would output for these files.
10517 Automake will not define a rule for a target you have defined, so you
10518 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
10519 We recommend against this, because this is error prone.  For instance,
10520 if you add such a rule to the first example, it will break the day you
10521 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
10522 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{renamed
10523 objects}).  Also in order to support dependency tracking, the two
10524 @file{.o}/@file{.obj} extensions, and all the other flags variables
10525 involved in a compilation, you will end up modifying a copy of the
10526 rule previously output by @command{automake} for this file.  If a new
10527 release of Automake generates a different rule, your copy will need to
10528 be updated by hand.
10530 @node Multiple Outputs
10531 @section Handling Tools that Produce Many Outputs
10532 @cindex multiple outputs, rules with
10533 @cindex many outputs, rules with
10534 @cindex rules with multiple outputs
10536 This section describes a @command{make} idiom that can be used when a
10537 tool produces multiple output files.  It is not specific to Automake
10538 and can be used in ordinary @file{Makefile}s.
10540 Suppose we have a program called @command{foo} that will read one file
10541 called @file{data.foo} and produce two files named @file{data.c} and
10542 @file{data.h}.  We want to write a @file{Makefile} rule that captures
10543 this one-to-two dependency.
10545 The naive rule is incorrect:
10547 @example
10548 # This is incorrect.
10549 data.c data.h: data.foo
10550         foo data.foo
10551 @end example
10553 @noindent
10554 What the above rule really says is that @file{data.c} and
10555 @file{data.h} each depend on @file{data.foo}, and can each be built by
10556 running @samp{foo data.foo}.  In other words it is equivalent to:
10558 @example
10559 # We do not want this.
10560 data.c: data.foo
10561         foo data.foo
10562 data.h: data.foo
10563         foo data.foo
10564 @end example
10566 @noindent
10567 which means that @command{foo} can be run twice.  Usually it will not
10568 be run twice, because @command{make} implementations are smart enough
10569 to check for the existence of the second file after the first one has
10570 been built; they will therefore detect that it already exists.
10571 However there are a few situations where it can run twice anyway:
10573 @itemize
10574 @item
10575 The most worrying case is when running a parallel @command{make}.  If
10576 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
10577 data.foo} commands will run concurrently.  This is harmful.
10578 @item
10579 Another case is when the dependency (here @file{data.foo}) is
10580 (or depends upon) a phony target.
10581 @end itemize
10583 A solution that works with parallel @command{make} but not with
10584 phony dependencies is the following:
10586 @example
10587 data.c data.h: data.foo
10588         foo data.foo
10589 data.h: data.c
10590 @end example
10592 @noindent
10593 The above rules are equivalent to
10595 @example
10596 data.c: data.foo
10597         foo data.foo
10598 data.h: data.foo data.c
10599         foo data.foo
10600 @end example
10601 @noindent
10602 therefore a parallel @command{make} will have to serialize the builds
10603 of @file{data.c} and @file{data.h}, and will detect that the second is
10604 no longer needed once the first is over.
10606 Using this pattern is probably enough for most cases.  However it does
10607 not scale easily to more output files (in this scheme all output files
10608 must be totally ordered by the dependency relation), so we will
10609 explore a more complicated solution.
10611 Another idea is to write the following:
10613 @example
10614 # There is still a problem with this one.
10615 data.c: data.foo
10616         foo data.foo
10617 data.h: data.c
10618 @end example
10620 @noindent
10621 The idea is that @samp{foo data.foo} is run only when @file{data.c}
10622 needs to be updated, but we further state that @file{data.h} depends
10623 upon @file{data.c}.  That way, if @file{data.h} is required and
10624 @file{data.foo} is out of date, the dependency on @file{data.c} will
10625 trigger the build.
10627 This is almost perfect, but suppose we have built @file{data.h} and
10628 @file{data.c}, and then we erase @file{data.h}.  Then, running
10629 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
10630 just state that @file{data.c} must be up-to-date with respect to
10631 @file{data.foo}, and this is already the case.
10633 What we need is a rule that forces a rebuild when @file{data.h} is
10634 missing.  Here it is:
10636 @example
10637 data.c: data.foo
10638         foo data.foo
10639 data.h: data.c
10640 ## Recover from the removal of $@@
10641         @@if test -f $@@; then :; else \
10642           rm -f data.c; \
10643           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10644         fi
10645 @end example
10647 The above scheme can be extended to handle more outputs and more
10648 inputs.  One of the outputs is selected to serve as a witness to the
10649 successful completion of the command, it depends upon all inputs, and
10650 all other outputs depend upon it.  For instance, if @command{foo}
10651 should additionally read @file{data.bar} and also produce
10652 @file{data.w} and @file{data.x}, we would write:
10654 @example
10655 data.c: data.foo data.bar
10656         foo data.foo data.bar
10657 data.h data.w data.x: data.c
10658 ## Recover from the removal of $@@
10659         @@if test -f $@@; then :; else \
10660           rm -f data.c; \
10661           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10662         fi
10663 @end example
10665 However there are now two minor problems in this setup.  One is related
10666 to the timestamp ordering of @file{data.h}, @file{data.w},
10667 @file{data.x}, and @file{data.c}.  The other one is a race condition
10668 if a parallel @command{make} attempts to run multiple instances of the
10669 recover block at once.
10671 Let us deal with the first problem.  @command{foo} outputs four files,
10672 but we do not know in which order these files are created.  Suppose
10673 that @file{data.h} is created before @file{data.c}.  Then we have a
10674 weird situation.  The next time @command{make} is run, @file{data.h}
10675 will appear older than @file{data.c}, the second rule will be
10676 triggered, a shell will be started to execute the @samp{if@dots{}fi}
10677 command, but actually it will just execute the @code{then} branch,
10678 that is: nothing.  In other words, because the witness we selected is
10679 not the first file created by @command{foo}, @command{make} will start
10680 a shell to do nothing each time it is run.
10682 A simple riposte is to fix the timestamps when this happens.
10684 @example
10685 data.c: data.foo data.bar
10686         foo data.foo data.bar
10687 data.h data.w data.x: data.c
10688         @@if test -f $@@; then \
10689           touch $@@; \
10690         else \
10691 ## Recover from the removal of $@@
10692           rm -f data.c; \
10693           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10694         fi
10695 @end example
10697 Another solution is to use a different and dedicated file as witness,
10698 rather than using any of @command{foo}'s outputs.
10700 @example
10701 data.stamp: data.foo data.bar
10702         @@rm -f data.tmp
10703         @@touch data.tmp
10704         foo data.foo data.bar
10705         @@mv -f data.tmp $@@
10706 data.c data.h data.w data.x: data.stamp
10707 ## Recover from the removal of $@@
10708         @@if test -f $@@; then :; else \
10709           rm -f data.stamp; \
10710           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10711         fi
10712 @end example
10714 @file{data.tmp} is created before @command{foo} is run, so it has a
10715 timestamp older than output files output by @command{foo}.  It is then
10716 renamed to @file{data.stamp} after @command{foo} has run, because we
10717 do not want to update @file{data.stamp} if @command{foo} fails.
10719 This solution still suffers from the second problem: the race
10720 condition in the recover rule.  If, after a successful build, a user
10721 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
10722 @command{make} may start both recover rules in parallel.  If the two
10723 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
10724 data.stamp} concurrently the build is likely to fail (for instance, the
10725 two rules will create @file{data.tmp}, but only one can rename it).
10727 Admittedly, such a weird situation does not arise during ordinary
10728 builds.  It occurs only when the build tree is mutilated.  Here
10729 @file{data.c} and @file{data.h} have been explicitly removed without
10730 also removing @file{data.stamp} and the other output files.
10731 @code{make clean; make} will always recover from these situations even
10732 with parallel makes, so you may decide that the recover rule is solely
10733 to help non-parallel make users and leave things as-is.  Fixing this
10734 requires some locking mechanism to ensure only one instance of the
10735 recover rule rebuilds @file{data.stamp}.  One could imagine something
10736 along the following lines.
10738 @example
10739 data.c data.h data.w data.x: data.stamp
10740 ## Recover from the removal of $@@
10741         @@if test -f $@@; then :; else \
10742           trap 'rm -rf data.lock data.stamp 1 2 13 15; \
10743 ## mkdir is a portable test-and-set
10744           if mkdir data.lock 2>/dev/null; then \
10745 ## This code is being executed by the first process.
10746             rm -f data.stamp; \
10747             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10748           else \
10749 ## This code is being executed by the follower processes.
10750 ## Wait until the first process is done.
10751             while test -d data.lock; do sleep 1; done; \
10752 ## Succeed if and only if the first process succeeded.
10753             test -f data.stamp; exit $$?; \
10754           fi; \
10755         fi
10756 @end example
10758 Using a dedicated witness, like @file{data.stamp}, is very handy when
10759 the list of output files is not known beforehand.  As an illustration,
10760 consider the following rules to compile many @file{*.el} files into
10761 @file{*.elc} files in a single command.  It does not matter how
10762 @code{ELFILES} is defined (as long as it is not empty: empty targets
10763 are not accepted by POSIX).
10765 @example
10766 ELFILES = one.el two.el three.el @dots{}
10767 ELCFILES = $(ELFILES:=c)
10769 elc-stamp: $(ELFILES)
10770         @@rm -f elc-temp
10771         @@touch elc-temp
10772         $(elisp_comp) $(ELFILES)
10773         @@mv -f elc-temp $@@
10775 $(ELCFILES): elc-stamp
10776 ## Recover from the removal of $@@
10777         @@if test -f $@@; then :; else \
10778           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
10779           if mkdir elc-lock 2>/dev/null; then \
10780 ## This code is being executed by the first process.
10781             rm -f elc-stamp; \
10782             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
10783             rmdir elc-lock; \
10784           else \
10785 ## This code is being executed by the follower processes.
10786 ## Wait until the first process is done.
10787             while test -d elc-lock; do sleep 1; done; \
10788 ## Succeed if and only if the first process succeeded.
10789             test -f elc-stamp; exit $$?; \
10790           fi; \
10791         fi
10792 @end example
10794 For completeness it should be noted that GNU @command{make} is able to
10795 express rules with multiple output files using pattern rules
10796 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
10797 Manual}).  We do not discuss pattern rules here because they are not
10798 portable, but they can be convenient in packages that assume GNU
10799 @command{make}.
10802 @node Hard-Coded Install Paths
10803 @section Installing to Hard-Coded Locations
10805 @display
10806 My package needs to install some configuration file.  I tried to use
10807 the following rule, but @samp{make distcheck} fails.  Why?
10809 @example
10810 # Do not do this.
10811 install-data-local:
10812         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
10813 @end example
10814 @end display
10816 @display
10817 My package needs to populate the installation directory of another
10818 package at install-time.  I can easily compute that installation
10819 directory in @file{configure}, but if I install files therein,
10820 @samp{make distcheck} fails.  How else should I do?
10821 @end display
10823 These two setups share their symptoms: @samp{make distcheck} fails
10824 because they are installing files to hard-coded paths.  In the later
10825 case the path is not really hard-coded in the package, but we can
10826 consider it to be hard-coded in the system (or in whichever tool that
10827 supplies the path).  As long as the path does not use any of the
10828 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
10829 @samp{$(datadir)}, etc.), the effect will be the same:
10830 user-installations are impossible.
10832 When a (non-root) user wants to install a package, he usually has no
10833 right to install anything in @file{/usr} or @file{/usr/local}.  So he
10834 does something like @samp{./configure --prefix ~/usr} to install
10835 package in his own @file{~/usr} tree.
10837 If a package attempts to install something to some hard-coded path
10838 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
10839 then the installation will fail.  @samp{make distcheck} performs such
10840 a @option{--prefix} installation, hence it will fail too.
10842 Now, there are some easy solutions.
10844 The above @code{install-data-local} example for installing
10845 @file{/etc/afile} would be better replaced by
10847 @example
10848 sysconf_DATA = afile
10849 @end example
10851 @noindent
10852 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
10853 this is what the GNU Standards require.  When such a package is
10854 installed on a FHS compliant system, the installer will have to set
10855 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
10856 should not be concerned by such site policies: use the appropriate
10857 standard directory variable to install your files so that installer
10858 can easily redefine these variables to match their site conventions.
10860 Installing files that should be used by another package, is slightly
10861 more involved.  Let's take an example and assume you want to install
10862 shared library that is a Python extension module.  If you ask Python
10863 where to install the library, it will answer something like this:
10865 @example
10866 % @kbd{python -c 'from distutils import sysconfig;
10867              print sysconfig.get_python_lib(1,0)'}
10868 /usr/lib/python2.3/site-packages
10869 @end example
10871 If you indeed use this absolute path to install your shared library,
10872 non-root users will not be able to install the package, hence
10873 distcheck fails.
10875 Let's do better.  The @samp{sysconfig.get_python_lib()} function
10876 actually accepts a third argument that will replace Python's
10877 installation prefix.
10879 @example
10880 % @kbd{python -c 'from distutils import sysconfig;
10881              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
10882 $@{exec_prefix@}/lib/python2.3/site-packages
10883 @end example
10885 You can also use this new path.  If you do
10886 @itemize @bullet
10887 @item
10888 root users can install your package with the same @option{--prefix}
10889 as Python (you get the behavior of the previous attempt)
10891 @item
10892 non-root users can install your package too, they will have the
10893 extension module in a place that is not searched by Python but they
10894 can work around this using environment variables (and if you installed
10895 scripts that use this shared library, it's easy to tell Python were to
10896 look in the beginning of your script, so the script works in both
10897 cases).
10898 @end itemize
10900 The @code{AM_PATH_PYTHON} macro uses similar commands to define
10901 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
10903 Of course not all tools are as advanced as Python regarding that
10904 substitution of @var{prefix}.  So another strategy is to figure the
10905 part of the of the installation directory that must be preserved.  For
10906 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
10907 computes @samp{$(lispdir)}:
10909 @example
10910 $EMACS -batch -q -eval '(while load-path
10911   (princ (concat (car load-path) "\n"))
10912   (setq load-path (cdr load-path)))' >conftest.out
10913 lispdir=`sed -n
10914   -e 's,/$,,'
10915   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
10916         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
10917       @}'
10918   -e '/.*\/share\/x*emacs\/site-lisp$/@{
10919         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
10920       @}'
10921   conftest.out`
10922 @end example
10924 I.e., it just picks the first directory that looks like
10925 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
10926 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
10927 @samp{$@{datadir@}} appropriately.
10929 The emacs case looks complicated because it processes a list and
10930 expect two possible layouts, otherwise it's easy, and the benefit for
10931 non-root users are really worth the extra @command{sed} invocation.
10934 @node History
10935 @chapter History of Automake
10937 This chapter presents various aspects of the history of Automake.  The
10938 exhausted reader can safely skip it; this will be more of interest to
10939 nostalgic people, or to those curious to learn about the evolution of
10940 Automake.
10942 @menu
10943 * Timeline::                    The Automake story.
10944 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
10945 * Releases::                    Statistics about Automake Releases
10946 @end menu
10948 @node Timeline
10949 @section Timeline
10951 @table @asis
10952 @item 1994-09-19 First CVS commit.
10954 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
10955 working on Automake (or AutoMake, as it was spelt then) this Monday.
10957 The first version of the @command{automake} script looks as follows.
10959 @example
10960 #!/bin/sh
10962 status=0
10964 for makefile
10966   if test ! -f $@{makefile@}.am; then
10967     echo "automake: $@{makefile@}.am: No such honkin' file"
10968     status=1
10969     continue
10970   fi
10972   exec 4> $@{makefile@}.in
10974 done
10975 @end example
10977 From this you can already see that Automake will be about reading
10978 @file{*.am} file and producing @file{*.in} files.  You cannot see
10979 anything else, but if you also know that David is the one who created
10980 Autoconf two years before you can guess the rest.
10982 Several commits follow, and by the end of the day Automake is
10983 reported to work for GNU fileutils and GNU m4.
10985 The modus operandi is the one that is still used today: variables
10986 assignments in @file{Makefile.am} files trigger injections of
10987 precanned @file{Makefile} fragments into the generated
10988 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
10989 by the 4.4BSD @command{make} and include files, however Automake aims
10990 to be portable and to conform to the GNU standards for @file{Makefile}
10991 variables and targets.
10993 At this point, the most recent release of Autoconf is version 1.11,
10994 and David is preparing to release Autoconf 2.0 in late October.  As a
10995 matter of fact, he will barely touch Automake after September.
10997 @item 1994-11-05 David MacKenzie's last commit.
10999 At this point Automake is a 200 line portable shell script, plus 332
11000 lines of @file{Makefile} fragments.  In the @file{README}, David
11001 states his ambivalence between ``portable shell'' and ``more
11002 appropriate language'':
11004 @quotation
11005 I wrote it keeping in mind the possibility of it becoming an Autoconf
11006 macro, so it would run at configure-time.  That would slow
11007 configuration down a bit, but allow users to modify the Makefile.am
11008 without needing to fetch the AutoMake package.  And, the Makefile.in
11009 files wouldn't need to be distributed.  But all of AutoMake would.  So
11010 I might reimplement AutoMake in Perl, m4, or some other more
11011 appropriate language.
11012 @end quotation
11014 Automake is described as ``an experimental Makefile generator''.
11015 There is no documentation.  Adventurous users are referred to the
11016 examples and patches needed to use Automake with GNU m4 1.3, fileutils
11017 3.9, time 1.6, and development versions of find and indent.
11019 These examples seem to have been lost.  However at the time of writing
11020 (10 years later in September, 2004) the FSF still distributes a
11021 package that uses this version of Automake: check out GNU termutils
11022 2.0.
11024 @item 1995-11-12 Tom Tromey's first commit.
11026 After one year of inactivity, Tom Tromey takes over the package.
11027 Tom was working on GNU cpio back then, and doing this just for fun,
11028 having trouble finding a project to contribute to.  So while hacking
11029 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
11030 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
11031 grabbed it and tried it out.
11033 Tom didn't talk to djm about it until later, just to make sure he
11034 didn't mind if he made a release.  He did a bunch of early releases to
11035 the Gnits folks.
11037 Gnits was (and still is) totally informal, just a few GNU friends who
11038 Fran@,cois Pinard knew, who were all interested in making a common
11039 infrastructure for GNU projects, and shared a similar outlook on how
11040 to do it.  So they were able to make some progress.  It came along
11041 with Autoconf and extensions thereof, and then Automake from David and
11042 Tom (who were both gnitsians).  One of their ideas was to write a
11043 document paralleling the GNU standards, that was more strict in some
11044 ways and more detailed.  They never finished the GNITS standards, but
11045 the ideas mostly made their way into Automake.
11047 @item 1995-11-23 Automake 0.20
11049 Besides introducing automatic dependency tracking (@pxref{Dependency
11050 Tracking Evolution}), this version also supplies a 9-page manual.
11052 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
11053 exist, so many things had to be done by hand.  For instance, here is
11054 what a configure.in (this is the former name of the
11055 @file{configure.ac} we use today) must contain in order to use
11056 Automake 0.20:
11058 @example
11059 PACKAGE=cpio
11060 VERSION=2.3.911
11061 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
11062 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
11063 AC_SUBST(PACKAGE)
11064 AC_SUBST(VERSION)
11065 AC_ARG_PROGRAM
11066 AC_PROG_INSTALL
11067 @end example
11069 (Today all of the above is achieved by @code{AC_INIT} and
11070 @code{AM_INIT_AUTOMAKE}.)
11072 Here is how programs are specified in @file{Makefile.am}:
11074 @example
11075 PROGRAMS = hello
11076 hello_SOURCES = hello.c
11077 @end example
11079 This looks pretty much like what we do today, except the
11080 @code{PROGRAMS} variable has no directory prefix specifying where
11081 @file{hello} should be installed: all programs are installed in
11082 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
11083 that must be built but not installed (it is called
11084 @code{noinst_PROGRAMS} nowadays).
11086 Programs can be built conditionally using @code{AC_SUBST}itutions:
11088 @example
11089 PROGRAMS = @@progs@@
11090 AM_PROGRAMS = foo bar baz
11091 @end example
11093 (@code{AM_PROGRAMS} has since then been renamed to
11094 @code{EXTRA_PROGRAMS}.)
11096 Similarly scripts, static libraries, and data can built and installed
11097 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
11098 However @code{LIBRARIES} were treated a bit specially in that Automake
11099 did automatically supply the @file{lib} and @file{.a} prefixes.
11100 Therefore to build @file{libcpio.a}, one had to write
11102 @example
11103 LIBRARIES = cpio
11104 cpio_SOURCES = ...
11105 @end example
11107 Extra files to distribute must be listed in @code{DIST_OTHER} (the
11108 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
11109 distributed should appear in @code{DIST_SUBDIRS}, but the manual
11110 describes this as a temporary ugly hack (today extra directories should
11111 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
11112 for another purpose, @pxref{Conditional Subdirectories}).
11114 @item 1995-11-26 Automake 0.21
11116 In less time that it takes to cook a frozen pizza, Tom rewrites
11117 Automake using Perl.  At this time Perl 5 is only one year old, and
11118 Perl 4.036 is in use at many sites.  Supporting several Perl versions
11119 has been a source of problems through the whole history of Automake.
11121 If you never used Perl 4, imagine Perl 5 without objects, without
11122 @samp{my} variables (only dynamically scoped @samp{local} variables),
11123 without function prototypes, with function calls that needs to be
11124 prefixed with @samp{&}, etc.  Traces of this old style can still be
11125 found in today's @command{automake}.
11127 @item 1995-11-28 Automake 0.22
11128 @itemx 1995-11-29 Automake 0.23
11130 Bug fixes.
11132 @item 1995-12-08 Automake 0.24
11133 @itemx 1995-12-10 Automake 0.25
11135 Releases are raining.  0.24 introduces the uniform naming scheme we
11136 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
11137 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
11138 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
11139 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
11140 prefixes.)  Adding support for prefixes like that was one of the major
11141 ideas in automake; it has lasted pretty well.
11143 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
11144 Pinard's doing).
11146 0.25 fixes a Perl 4 portability bug.
11148 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
11149 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
11151 @item 1996-01-03 Automake 0.26
11152 @itemx 1996-01-03 Automake 0.27
11154 Of the many change and suggestions sent by Fran@,cois Pinard and
11155 included in 0.26, the most important is perhaps the advise that to
11156 ease customization a user rule or variable definition should always
11157 override an Automake rule or definition.
11159 Gordon Matzigkeit and Jim Meyering are two other early contributors
11160 that have been sending fixes.
11162 0.27 fixes yet another Perl 4 portability bug.
11164 @item 1996-01-13 Automake 0.28
11166 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
11167 support.  This is an important step because until this version
11168 Automake did only know about the @file{Makefile.am}s it processed.
11169 @file{configure.in} was Autoconf's world and the link between Autoconf
11170 and Automake had to be done by the @file{Makefile.am} author.  For
11171 instance, if @file{config.h} was generated by @file{configure}, it was the
11172 package maintainer's responsibility to define the @code{CONFIG_HEADER}
11173 variable in each @file{Makefile.am}.
11175 Succeeding releases will rely more and more on scanning
11176 @file{configure.in} to better automate the Autoconf integration.
11178 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
11179 @option{--gnu} and @option{--gnits} options, the latter being stricter.
11181 @item 1996-02-07 Automake 0.29
11183 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
11184 and rebuild rules for @file{configure}-generated file are
11185 automatically output.
11187 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
11188 scheme.
11190 @item 1996-02-24 Automake 0.30
11192 The test suite is born.  It contains 9 tests.  From now on test cases
11193 will be added pretty regularly (@pxref{Releases}), and this proved to
11194 be really helpful later on.
11196 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
11198 All the third-party Autoconf macros, written mostly by Fran@,cois
11199 Pinard (and later Jim Meyering), are distributed in Automake's
11200 hand-written @file{aclocal.m4} file.  Package maintainers are expected
11201 to extract the necessary macros from this file.  (In previous version
11202 you had to copy and paste them from the manual...)
11204 @item 1996-03-11 Automake 0.31
11206 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
11207 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
11208 whenever the @code{TESTS} variable is defined.
11210 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
11211 prefix is introduced.  The syntax is now the same as today.
11213 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
11215 @item 1996-04-27 Automake 0.32
11217 @code{-hook} targets are introduced; an idea from Dieter Baron.
11219 @file{*.info} files, which were output in the build directory are
11220 now built in the source directory, because they are distributed.  It
11221 seems these files like to move back and forth as that will happen
11222 again in future versions.
11224 @item 1996-05-18 Automake 0.33
11226 Gord Matzigkeit's main two contributions:
11228 @itemize
11229 @item very preliminary libtool support
11230 @item the distcheck rule
11231 @end itemize
11233 Although they were very basic at this point, these are probably
11234 among the top features for Automake today.
11236 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
11237 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
11238 author (@pxref{maintainer-mode}).
11240 @item 1996-05-28 Automake 1.0
11242 After only six months of heavy development, the automake script is
11243 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
11244 package has 30 pages of documentation, and 38 test cases.
11245 @file{aclocal.m4} contains 4 macros.
11247 From now on and until version 1.4, new releases will occur at a rate
11248 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
11249 been the name of beta releases for 1.2.  This is the first time
11250 Automake uses suffix letters to designate beta releases, an habit that
11251 lasts.
11253 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
11255 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
11257 Between June and October, the Autoconf development is almost staled.
11258 Roland McGrath has been working at the beginning of the year.  David
11259 comes back in November to release 2.12, but he won't touch Autoconf
11260 anymore after this year, and Autoconf then really stagnates.  The
11261 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
11263 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
11265 The mailing list is announced as follows:
11266 @smallexample
11267 I've created the "automake" mailing list.  It is
11268 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
11269 automake-request@@gnu.ai.mit.edu.
11271 The charter of this list is discussion of automake, autoconf, and
11272 other configuration/portability tools (e.g., libtool).  It is expected
11273 that discussion will range from pleas for help all the way up to
11274 patches.
11276 This list is archived on the FSF machines.  Offhand I don't know if
11277 you can get the archive without an account there.
11279 This list is open to anybody who wants to join.  Tell all your
11280 friends!
11281 -- Tom Tromey
11282 @end smallexample
11284 Before that people were discussing Automake privately, on the Gnits
11285 mailing list (which is not public either), and less frequently on
11286 @code{gnu.misc.discuss}.
11288 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
11289 noticed.  The archives of the early years of the
11290 @code{automake@@gnu.org} list have been lost, so today it is almost
11291 impossible to find traces of discussions that occurred before 1999.
11292 This has been annoying more than once, as such discussions can be
11293 useful to understand the rationale behind a piece of uncommented code
11294 that was introduced back then.
11296 @item 1997-06-22 Automake 1.2
11298 Automake developments continues, and more and more new Autoconf macros
11299 are required.  Distributing them in @file{aclocal.m4} and requiring
11300 people to browse this file to extract the relevant macros becomes
11301 uncomfortable.  Ideally, some of them should be contributed to
11302 Autoconf so that they can be used directly, however Autoconf is
11303 currently inactive.  Automake 1.2 consequently introduces
11304 @command{aclocal} (@command{aclocal} was actually started on
11305 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
11306 file from a repository of third-party macros.  Because Autoconf has
11307 stalled, Automake also becomes a kind of repository for such
11308 third-party macros, even macros completely unrelated to Automake (for
11309 instance macros that fix broken Autoconf macros).
11311 The 1.2 release contains 20 macros, among which the
11312 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
11313 @file{configure.in}.
11315 Libtool is fully supported using @code{*_LTLIBRARIES}.
11317 The missing script is introduced by Fran@,cois Pinard; it is meant to be
11318 a better solution than @code{AM_MAINTAINER_MODE}
11319 (@pxref{maintainer-mode}).
11321 Conditionals support was implemented by Ian Lance Taylor.  At the
11322 time, Tom and Ian were working on an internal project at Cygnus.  They
11323 were using ILU, which is pretty similar to CORBA@.  They wanted to
11324 integrate ILU into their build, which was all @file{configure}-based,
11325 and Ian thought that adding conditionals to @command{automake} was
11326 simpler than doing all the work in @file{configure} (which was the
11327 standard at the time).  So this was actually funded by Cygnus.
11329 This very useful but tricky feature will take a lot of time to
11330 stabilize.  (At the time this text is written, there are still
11331 primaries that have not been updated to support conditional
11332 definitions in Automake 1.9.)
11334 The @command{automake} script has almost doubled: 6089 lines of Perl,
11335 plus 1294 lines of @file{Makefile} fragments.
11337 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
11339 @item 1998-04-05 Automake 1.3
11341 This is a small advance compared to 1.2.
11342 It add support for assembly, and preliminary support for Java.
11344 Perl 5.004_04 is out, but fixes to support Perl 4 are still
11345 regularly submitted whenever Automake breaks it.
11347 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
11349 Sourceware was setup by Jason Molenda to host open source projects.
11351 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
11352 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake
11353 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
11354 publicly accessible CVS repository.  This CVS repository is a copy of
11355 the one Tom was using on his machine, which in turn is based on
11356 a copy of the CVS repository of David MacKenzie.  This is why we still
11357 have to full source history.  (Automake is still on Sourceware today,
11358 but the host has been renamed to @code{sources.redhat.com}.)
11360 The oldest file in the administrative directory of the CVS repository
11361 that was created on Sourceware is dated 1998-09-19, while the
11362 announcement that @command{automake} and @command{autoconf} had joined
11363 @command{sourceware} was made on 1998-10-26.  They were among the
11364 first projects to be hosted there.
11366 The heedful reader will have noticed Automake was exactly 4-year-old
11367 on 1998-09-19.
11369 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
11371 @item 1999-01-14 Automake 1.4
11373 This release adds support for Fortran 77 and for the @code{include}
11374 statement.  Also, @samp{+=} assignments are introduced, but it is
11375 still quite easy to fool Automake when mixing this with conditionals.
11377 These two releases, Automake 1.4 and Autoconf 2.13 makes a duo that
11378 will be used together for years.
11380 @command{automake} is 7228 lines, plus 1591 lines of Makefile
11381 fragment, 20 macros (some 1.3 macros were finally contributed back to
11382 Autoconf), 197 test cases, and 51 pages of documentation.
11384 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
11386 This implements a new dependency tracking schemed that should be
11387 able to handle automatic dependency tracking using any compiler (not
11388 just gcc) and any make (not just GNU @command{make}).  In addition,
11389 the new scheme should be more reliable than the old one, as
11390 dependencies are generated on the end user's machine.  Alexandre Oliva
11391 creates depcomp for this purpose.
11393 @xref{Dependency Tracking Evolution}, for more details about the
11394 evolution of automatic dependency tracking in Automake.
11396 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
11398 This was a huge problem since we also had patches going in on the
11399 trunk.  The merge took a long time and was very painful.
11401 @item 2000-05-10
11403 Since September 1999 and until 2003, Akim Demaille will be zealously
11404 revamping Autoconf.
11406 @quotation
11407 I think the next release should be called "3.0".@*
11408 Let's face it: you've basically rewritten autoconf.@*
11409 Every weekend there are 30 new patches.@*
11410 I don't see how we could call this "2.15" with a straight face.@*
11411 -- Tom Tromey on @email{autoconf@@gnu.org}
11412 @end quotation
11414 Actually Akim works like a submarine: he will pile up patches while he
11415 works off-line during the weekend, and flush them in batch when he
11416 resurfaces on Monday.
11418 @item 2001-01-24
11420 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
11421 is out, and Akim has to find something to do during his week-end :)
11423 @item 2001-01-28
11425 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
11427 @quotation
11428 Aiieeee!  I was dreading the day that the Demaillator turned his
11429 sights on automake@dots{} and now it has arrived! -- Tom Tromey
11430 @end quotation
11432 It's only the beginning: in two months he will send 192 patches.  Then
11433 he would slow down so Tom can catch up and review all this.  Initially
11434 Tom actually read all these patches, then he probably trustingly
11435 answered OK to most of them, and finally gave up and let Akim apply
11436 whatever he wanted.  There was no way to keep up with that patch rate.
11438 @quotation
11439 Anyway the patch below won't apply since it predates Akim's
11440 sourcequake; I have yet to figure where the relevant passage has
11441 been moved :) -- Alexandre Duret-Lutz
11442 @end quotation
11444 All these patches were sent to and discussed on
11445 @email{automake@@gnu.org}, so subscribed users were literally drown in
11446 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
11447 mailing list was created in May.
11449 Year after year, Automake had drifted away from its initial design:
11450 construct @file{Makefile.in} by assembling various @file{Makefile}
11451 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
11452 various places in the @command{automake} script itself; this does not
11453 help ensuring a consistent treatment of these rules (for instance
11454 making sure that user-defined rules override Automake's own rules).
11455 One of Akim's goal was moving all these hard-coded rules to separate
11456 @file{Makefile} fragments, so the logic could be centralized in a
11457 @file{Makefile} fragment processor.
11459 Another significant contribution of Akim is the interface with the
11460 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
11461 this time was to read the file and grep the various macro of interest
11462 to Automake.  Doing so could break in many unexpected ways; automake
11463 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
11464 where the arguments are known only when M4 is run), or conversely it
11465 could detect some macro that was not expanded (because it is called
11466 conditionally).  In the CVS version of Autoconf, Akim had implemented
11467 the @option{--trace} option, which provides accurate information about
11468 where macros are actually called and with what arguments.  Akim will
11469 equip Automake with a second @file{configure.in} scanner that uses
11470 this @option{--trace} interface.  Since it was not sensible to drop the
11471 Autoconf 2.13 compatibility yet, this experimental scanner was only
11472 used when an environment variable was set, the traditional
11473 grep-scanner being still the default.
11475 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
11477 It has been more than two years since Automake 1.4, CVS Automake has
11478 suffered lot's of heavy changes and still is not ready for release.
11479 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
11481 @item 2001-05-08 Automake 1.4-p1
11482 @itemx 2001-05-24 Automake 1.4-p2
11484 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
11485 release'' of Automake:
11487 @quotation
11488 The main purpose of this release is to have a stable automake
11489 which is compatible with the latest stable libtool.
11490 @end quotation
11492 The release also contains obvious fixes for bugs in Automake 1.4,
11493 some of which were reported almost monthly.
11495 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
11497 @item 2001-06-07 Automake 1.4-p3
11498 @itemx 2001-06-10 Automake 1.4-p4
11499 @itemx 2001-07-15 Automake 1.4-p5
11501 Gary continues his patch-release series.  These also add support for
11502 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
11503 @file{configure.ac} over @file{configure.in}, and it introduces a new
11504 syntax for @code{AC_OUTPUT}ing files.
11506 @item 2001-08-23 Automake 1.5
11508 A major and long-awaited release, that comes more than two years after
11509 1.4.  It brings many changes, among which:
11510 @itemize
11511 @item The new dependency tracking scheme that uses @command{depcomp}.
11512 Aside from the improvement on the dependency tracking itself
11513 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
11514 of automake generated @file{Makefile.in}s as the @file{Makefile.in}s
11515 used during development are now the same as those used in
11516 distributions.  Before that the @file{Makefile.in}s generated for
11517 maintainers required GNU @command{make} and GCC, they were different
11518 from the portable @file{Makefile} generated for distribution; this was
11519 causing some confusion.
11521 @item Support for per-target compilation flags.
11523 @item Support for reference to files in subdirectories in most
11524 @file{Makefile.am} variables.
11526 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
11527 prefixes.
11528 @item Perl 4 support is finally dropped.
11529 @end itemize
11531 1.5 did broke several packages that worked with 1.4.  Enough so that
11532 Linux distributions could not easily install the new Automake version
11533 without breaking many of the packages for which they had to run
11534 @command{automake}.
11536 Some of these breakages were effectively bugs that would eventually be
11537 fixed in the next release.  However, a lot of damage was caused by
11538 some changes made deliberately to render Automake stricter on some
11539 setup we did consider bogus.  For instance, @samp{make distcheck} was
11540 improved to check that @samp{make uninstall} did remove all the files
11541 @samp{make install} installed, that @samp{make distclean} did not omit
11542 some file, and that a VPATH build would work even if the source
11543 directory was read-only.  Similarly, Automake now rejects multiple
11544 definitions of the same variable (because that would mix very badly
11545 with conditionals), and @samp{+=} assignments with no previous
11546 definition.  Because these changes all occurred suddenly after 1.4 had
11547 been established for more than two years, it hurt users.
11549 To make matter worse, meanwhile Autoconf (now at version 2.52) was
11550 facing similar troubles, for similar reasons.
11552 @item 2002-03-05 Automake 1.6
11554 This release introduced versioned installation (@pxref{API
11555 versioning}).  This was mainly pushed by Havoc Pennington, taking the
11556 GNOME source tree as motive: due to incompatibilities between the
11557 autotools it's impossible for the GNOME packages to switch to Autoconf
11558 2.53 and Automake 1.5 all at once, so they are currently stuck with
11559 Autoconf 2.13 and Automake 1.4.
11561 The idea was to call this version @file{automake-1.6}, call all its
11562 bug-fix versions identically, and switch to @file{automake-1.7} for
11563 the next release that adds new features or changes some rules.  This
11564 scheme implies maintaining a bug-fix branch in addition to the
11565 development trunk, which means more work from the maintainer, but
11566 providing regular bug-fix releases proved to be really worthwhile.
11568 Like 1.5, 1.6 also introduced a bunch of incompatibilities, meant or
11569 not.  Perhaps the more annoying was the dependence on the newly
11570 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
11571 since its explosive 2.50 release, and included changes required to fix
11572 some bugs in Automake.  In order to upgrade to Automake 1.6, people
11573 now had to upgrade Autoconf too; for some packages it was no picnic.
11575 While versioned installation helped people to upgrade, it also
11576 unfortunately allowed people not to upgrade.  At the time of writing,
11577 some Linux distributions are shipping packages for Automake 1.4, 1.5,
11578 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
11579 Some distribution also call 1.4 the ``stable'' version, and present
11580 ``1.9'' as the development version; this does not really makes sense
11581 since 1.9 is way more solid than 1.4.  All this does not help the
11582 newcomer.
11584 @item 2002-04-11 Automake 1.6.1
11586 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
11587 This one and those following will be handled by Alexandre
11588 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
11589 but his interest into Automake is drifting away towards projects like
11590 @command{gcj}.
11592 Alexandre has been using Automake since 2000, and started to
11593 contribute mostly on Akim's incitement (Akim and Alexandre have been
11594 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
11595 a lot of free time to enjoy hacking Automake.
11597 @item 2002-06-14 Automake 1.6.2
11599 @item 2002-07-28 Automake 1.6.3
11600 @itemx 2002-07-28 Automake 1.4-p6
11602 Two releases on the same day.  1.6.3 is a bug-fix release.
11604 Tom Tromey backported the versioned installation mechanism on the 1.4
11605 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
11606 side by side.  Another request from the GNOME folks.
11608 @item 2002-09-25 Automake 1.7
11610 This release switches to the new @file{configure.ac} scanner Akim
11611 was experimenting in 1.5.
11613 @item 2002-10-16 Automake 1.7.1
11614 @itemx 2002-12-06 Automake 1.7.2
11615 @itemx 2003-02-20 Automake 1.7.3
11616 @itemx 2003-04-23 Automake 1.7.4
11617 @itemx 2003-05-18 Automake 1.7.5
11618 @itemx 2003-07-10 Automake 1.7.6
11619 @itemx 2003-09-07 Automake 1.7.7
11620 @itemx 2003-10-07 Automake 1.7.8
11622 Many bug-fix releases.  1.7 lasted because the development version
11623 (upcoming 1.8) was suffering some major internal revamping.
11625 @item 2003-10-26 Automake on screen
11627 Episode 49, `Repercussions', in the third season of the `Alias' TV
11628 show is first aired.
11630 Marshall, one of the character, is working on a computer virus that he
11631 has to modify before it gets into the wrong hands or something like
11632 that.  The screenshots you see do not show any program code, they show
11633 a @file{Makefile.in} @code{generated by automake}...
11635 @item 2003-11-09 Automake 1.7.9
11637 @item 2003-12-10 Automake 1.8
11639 The most striking update is probably that of @command{aclocal}.
11641 @command{aclocal} now uses @code{m4_include} in the produced
11642 @file{aclocal.m4} when the included macros are already distributed
11643 with the package (an idiom used in many packages), which reduces code
11644 duplication.  Many people liked that, but in fact this change was
11645 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
11646 must be rebuilt whenever a dependency of @file{configure} changes, but
11647 all the @file{m4} files included in @file{aclocal.m4} where unknown
11648 from @command{automake}.  Now @command{automake} can just trace the
11649 @code{m4_include}s to discover the dependencies.
11651 @command{aclocal} also starts using the @option{--trace} Autoconf option
11652 in order to discover used macros more accurately.  This will turn out
11653 to be very tricky (later releases will improve this) as people had
11654 devised many ways to cope with the limitation of previous
11655 @command{aclocal} versions, notably using handwritten
11656 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
11657 rule that is already included by such statement.
11659 Automake also has seen its guts rewritten.  Although this rewriting
11660 took a lot of efforts, it is only apparent to the users in that some
11661 constructions previously disallowed by the implementation now work
11662 nicely.  Conditionals, Locations, Variable and Rule definitions,
11663 Options: these items on which Automake works have been rewritten as
11664 separate Perl modules, and documented.
11666 @itemx 2004-01-11 Automake 1.8.1
11667 @itemx 2004-01-12 Automake 1.8.2
11668 @itemx 2004-03-07 Automake 1.8.3
11669 @itemx 2004-04-25 Automake 1.8.4
11670 @itemx 2004-05-16 Automake 1.8.5
11672 @item 2004-07-28 Automake 1.9
11674 This release tries to simplify the compilation rules it outputs to
11675 reduce the size of the Makefile.  The complaint initially come from
11676 the libgcj developers.  Their @file{Makefile.in} generated with
11677 Automake 1.4 and custom build rules (1.4 did not support compiled
11678 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
11679 down to 1.2MB@.
11681 Aside from this it contains mainly minor changes and bug-fixes.
11683 @itemx 2004-08-11 Automake 1.9.1
11684 @itemx 2004-09-19 Automake 1.9.2
11686 Automake has ten years.  This chapter of the manual was initially
11687 written for this occasion.
11689 @end table
11691 @node Dependency Tracking Evolution
11692 @section Dependency Tracking in Automake
11694 Over the years Automake has deployed three different dependency
11695 tracking methods.  Each method, including the current one, has had
11696 flaws of various sorts.  Here we lay out the different dependency
11697 tracking methods, their flaws, and their fixes.  We conclude with
11698 recommendations for tool writers, and by indicating future directions
11699 for dependency tracking work in Automake.
11701 @subsection First Take
11702 @unnumberedsubsubsec Description
11704 Our first attempt at automatic dependency tracking was based on the
11705 method recommended by GNU @command{make}.  (@pxref{Automatic
11706 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
11707 make Manual})
11709 This version worked by precomputing dependencies ahead of time.  For
11710 each source file, it had a special @file{.P} file that held the
11711 dependencies.  There was a rule to generate a @file{.P} file by
11712 invoking the compiler appropriately.  All such @file{.P} files were
11713 included by the @file{Makefile}, thus implicitly becoming dependencies
11714 of @file{Makefile}.
11716 @unnumberedsubsubsec Bugs
11718 This approach had several critical bugs.
11720 @itemize
11721 @item
11722 The code to generate the @file{.P} file relied on @command{gcc}.
11723 (A limitation, not technically a bug.)
11724 @item
11725 The dependency tracking mechanism itself relied on GNU @command{make}.
11726 (A limitation, not technically a bug.)
11727 @item
11728 Because each @file{.P} file was a dependency of @file{Makefile}, this
11729 meant that dependency tracking was done eagerly by @command{make}.
11730 For instance, @samp{make clean} would cause all the dependency files
11731 to be updated, and then immediately removed.  This eagerness also
11732 caused problems with some configurations; if a certain source file
11733 could not be compiled on a given architecture for some reason,
11734 dependency tracking would fail, aborting the entire build.
11735 @item
11736 As dependency tracking was done as a pre-pass, compile times were
11737 doubled--the compiler had to be run twice per source file.
11738 @item
11739 @samp{make dist} re-ran @command{automake} to generate a
11740 @file{Makefile} that did not have automatic dependency tracking (and
11741 that was thus portable to any version of @command{make}).  In order to
11742 do this portably, Automake had to scan the dependency files and remove
11743 any reference that was to a source file not in the distribution.
11744 This process was error-prone.  Also, if @samp{make dist} was run in an
11745 environment where some object file had a dependency on a source file
11746 that was only conditionally created, Automake would generate a
11747 @file{Makefile} that referred to a file that might not appear in the
11748 end user's build.  A special, hacky mechanism was required to work
11749 around this.
11750 @end itemize
11752 @unnumberedsubsubsec Historical Note
11754 The code generated by Automake is often inspired by the
11755 @file{Makefile} style of a particular author.  In the case of the first
11756 implementation of dependency tracking, I believe the impetus and
11757 inspiration was Jim Meyering.  (I could be mistaken.  If you know
11758 otherwise feel free to correct me.)
11760 @subsection Dependencies As Side Effects
11761 @unnumberedsubsubsec Description
11763 The next refinement of Automake's automatic dependency tracking scheme
11764 was to implement dependencies as side effects of the compilation.
11765 This was aimed at solving the most commonly reported problems with the
11766 first approach.  In particular we were most concerned with eliminating
11767 the weird rebuilding effect associated with make clean.
11769 In this approach, the @file{.P} files were included using the
11770 @code{-include} command, which let us create these files lazily.  This
11771 avoided the @samp{make clean} problem.
11773 We only computed dependencies when a file was actually compiled.  This
11774 avoided the performance penalty associated with scanning each file
11775 twice.  It also let us avoid the other problems associated with the
11776 first, eager, implementation.  For instance, dependencies would never
11777 be generated for a source file that was not compilable on a given
11778 architecture (because it in fact would never be compiled).
11780 @unnumberedsubsubsec Bugs
11782 @itemize
11783 @item
11784 This approach also relied on the existence of @command{gcc} and GNU
11785 @command{make}.  (A limitation, not technically a bug.)
11786 @item
11787 Dependency tracking was still done by the developer, so the problems
11788 from the first implementation relating to massaging of dependencies by
11789 @samp{make dist} were still in effect.
11790 @item
11791 This implementation suffered from the ``deleted header file'' problem.
11792 Suppose a lazily-created @file{.P} file includes a dependency on a
11793 given header file, like this:
11795 @example
11796 maude.o: maude.c something.h
11797 @end example
11799 Now suppose that the developer removes @file{something.h} and updates
11800 @file{maude.c} so that this include is no longer needed.  If he runs
11801 @command{make}, he will get an error because there is no way to create
11802 @file{something.h}.
11804 We fixed this problem in a later release by further massaging the
11805 output of @command{gcc} to include a dummy dependency for each header
11806 file.
11807 @end itemize
11809 @subsection Dependencies for the User
11810 @unnumberedsubsubsec Description
11812 The bugs associated with @samp{make dist}, over time, became a real
11813 problem.  Packages using Automake were being built on a large number
11814 of platforms, and were becoming increasingly complex.  Broken
11815 dependencies were distributed in ``portable'' @file{Makefile.in}s,
11816 leading to user complaints.  Also, the requirement for @command{gcc}
11817 and GNU @command{make} was a constant source of bug reports.  The next
11818 implementation of dependency tracking aimed to remove these problems.
11820 We realized that the only truly reliable way to automatically track
11821 dependencies was to do it when the package itself was built.  This
11822 meant discovering a method portable to any version of make and any
11823 compiler.  Also, we wanted to preserve what we saw as the best point
11824 of the second implementation: dependency computation as a side effect
11825 of compilation.
11827 In the end we found that most modern make implementations support some
11828 form of include directive.  Also, we wrote a wrapper script that let
11829 us abstract away differences between dependency tracking methods for
11830 compilers.  For instance, some compilers cannot generate dependencies
11831 as a side effect of compilation.  In this case we simply have the
11832 script run the compiler twice.  Currently our wrapper script
11833 (@command{depcomp}) knows about twelve different compilers (including
11834 a "compiler" that simply invokes @command{makedepend} and then the
11835 real compiler, which is assumed to be a standard Unix-like C compiler
11836 with no way to do dependency tracking).
11838 @unnumberedsubsubsec Bugs
11840 @itemize
11841 @item
11842 Running a wrapper script for each compilation slows down the build.
11843 @item
11844 Many users don't really care about precise dependencies.
11845 @item
11846 This implementation, like every other automatic dependency tracking
11847 scheme in common use today (indeed, every one we've ever heard of),
11848 suffers from the ``duplicated new header'' bug.
11850 This bug occurs because dependency tracking tools, such as the
11851 compiler, only generate dependencies on the successful opening of a
11852 file, and not on every probe.
11854 Suppose for instance that the compiler searches three directories for
11855 a given header, and that the header is found in the third directory.
11856 If the programmer erroneously adds a header file with the same name to
11857 the first directory, then a clean rebuild from scratch could fail
11858 (suppose the new header file is buggy), whereas an incremental rebuild
11859 will succeed.
11861 What has happened here is that people have a misunderstanding of what
11862 a dependency is.  Tool writers think a dependency encodes information
11863 about which files were read by the compiler.  However, a dependency
11864 must actually encode information about what the compiler tried to do.
11866 This problem is not serious in practice.  Programmers typically do not
11867 use the same name for a header file twice in a given project.  (At
11868 least, not in C or C++.  This problem may be more troublesome in
11869 Java.)  This problem is easy to fix, by modifying dependency
11870 generators to record every probe, instead of every successful open.
11872 @item
11873 Since automake generates dependencies as a side effect of compilation,
11874 there is a bootstrapping problem when header files are generated by
11875 running a program.  The problem is that, the first time the build is
11876 done, there is no way by default to know that the headers are
11877 required, so make might try to run a compilation for which the headers
11878 have not yet been built.
11880 This was also a problem in the previous dependency tracking implementation.
11882 The current fix is to use @code{BUILT_SOURCES} to list built headers
11883 (@pxref{Sources}).  This causes them to be built before any other
11884 other build rules are run.  This is unsatisfactory as a general
11885 solution, however in practice it seems sufficient for most actual
11886 programs.
11887 @end itemize
11889 This code is used since Automake 1.5.
11891 In GCC 3.0, we managed to convince the maintainers to add special
11892 command-line options to help Automake more efficiently do its job.  We
11893 hoped this would let us avoid the use of a wrapper script when
11894 Automake's automatic dependency tracking was used with @command{gcc}.
11896 Unfortunately, this code doesn't quite do what we want.  In
11897 particular, it removes the dependency file if the compilation fails;
11898 we'd prefer that it instead only touch the file in any way if the
11899 compilation succeeds.
11901 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
11902 detected at @command{configure} time, we inline the
11903 dependency-generation code and do not use the @command{depcomp}
11904 wrapper script.  This makes compilations faster for those using this
11905 compiler (probably our primary user base).  The counterpart is that
11906 because we have to encode two compilation rules in @file{Makefile}
11907 (with or without @command{depcomp}), the produced @file{Makefile}s are
11908 larger.
11910 @subsection Techniques for Computing Dependencies
11912 There are actually several ways for a build tool like Automake to
11913 cause tools to generate dependencies.
11915 @table @asis
11916 @item @command{makedepend}
11917 This was a commonly-used method in the past.  The idea is to run a
11918 special program over the source and have it generate dependency
11919 information.  Traditional implementations of @command{makedepend} are
11920 not completely precise; ordinarily they were conservative and
11921 discovered too many dependencies.
11922 @item The tool
11923 An obvious way to generate dependencies is to simply write the tool so
11924 that it can generate the information needed by the build tool.  This is
11925 also the most portable method.  Many compilers have an option to
11926 generate dependencies.  Unfortunately, not all tools provide such an
11927 option.
11928 @item The file system
11929 It is possible to write a special file system that tracks opens,
11930 reads, writes, etc, and then feed this information back to the build
11931 tool.  @command{clearmake} does this.  This is a very powerful
11932 technique, as it doesn't require cooperation from the
11933 tool.  Unfortunately it is also very difficult to implement and also
11934 not practical in the general case.
11935 @item @code{LD_PRELOAD}
11936 Rather than use the file system, one could write a special library to
11937 intercept @code{open} and other syscalls.  This technique is also quite
11938 powerful, but unfortunately it is not portable enough for use in
11939 @command{automake}.
11940 @end table
11942 @subsection Recommendations for Tool Writers
11944 We think that every compilation tool ought to be able to generate
11945 dependencies as a side effect of compilation.  Furthermore, at least
11946 while @command{make}-based tools are nearly universally in use (at
11947 least in the free software community), the tool itself should generate
11948 dummy dependencies for header files, to avoid the deleted header file
11949 bug.  Finally, the tool should generate a dependency for each probe,
11950 instead of each successful file open, in order to avoid the duplicated
11951 new header bug.
11953 @subsection Future Directions for Automake's Dependency Tracking
11955 Currently, only languages and compilers understood by Automake can
11956 have dependency tracking enabled.  We would like to see if it is
11957 practical (and worthwhile) to let this support be extended by the user
11958 to languages unknown to Automake.
11960 @node Releases
11961 @section Release Statistics
11963 The following table (inspired by @samp{perlhist(1)}) quantifies the
11964 evolution of Automake using these metrics:
11966 @table @asis
11967 @item Date, Rel
11968 The date and version of the release.
11969 @item am
11970 The number of lines of the @command{automake} script.
11971 @item acl
11972 The number of lines of the @command{aclocal} script.
11973 @item pm
11974 The number of lines of the @command{Perl} supporting modules.
11975 @item @file{*.am}
11976 The number of lines of the @file{Makefile} fragments.  The number in parenthesis
11977 is the number of files.
11978 @item m4
11979 The number of lines (and files) of Autoconf macros.
11980 @item doc
11981 The number of pages of the documentation (the Postscript version).
11982 @item t
11983 The number of test cases in the test suite.
11984 @end table
11986 @multitable {8888-88-88} {8.8-p8} {8888} {888} {8888} {8888 (88)} {8888 (88)} {888} {888}
11987 @headitem Date   @tab Rel @tab am @tab acl @tab pm @tab @file{*.am} @tab m4 @tab doc @tab t
11988 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
11989 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
11990 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
11991 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
11992 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
11993 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
11994 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
11995 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
11996 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
11997 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
11998 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
11999 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
12000 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
12001 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
12002 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
12003 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
12004 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
12005 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (23) @tab  37 @tab 126
12006 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (26) @tab  39 @tab 156
12007 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (23) @tab  51 @tab 197
12008 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (23) @tab  51 @tab 197
12009 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (23) @tab  49 @tab 197
12010 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (23) @tab  49 @tab 197
12011 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (23) @tab  49 @tab 198
12012 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (23) @tab  51 @tab 198
12013 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (32) @tab  63 @tab 327
12014 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (31) @tab  66 @tab 365
12015 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (31) @tab  66 @tab 372
12016 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (31) @tab  67 @tab 386
12017 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (31) @tab  67 @tab 391
12018 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (24) @tab  49 @tab 197
12019 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (33) @tab  73 @tab 430
12020 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (33) @tab  73 @tab 437
12021 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (33) @tab  77 @tab 445
12022 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (34) @tab  84 @tab 448
12023 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (34) @tab  85 @tab 458
12024 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (34) @tab  85 @tab 459
12025 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (34) @tab  85 @tab 461
12026 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (34) @tab  90 @tab 467
12027 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (34) @tab  90 @tab 468
12028 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (34) @tab  90 @tab 468
12029 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (36) @tab 104 @tab 521
12030 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (36) @tab 104 @tab 525
12031 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (36) @tab 104 @tab 526
12032 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (36) @tab 111 @tab 530
12033 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (36) @tab 112 @tab 531
12034 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (36) @tab 112 @tab 533
12035 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (37) @tab 115 @tab 551
12036 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (37) @tab 115 @tab 552
12037 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (37) @tab 132 @tab 554
12038 @item 2004-11-01 @tab 1.9.3  @tab 7507 @tab 718 @tab 7804 @tab 3354 (40) @tab 1812 (37) @tab 134 @tab 556
12039 @item 2004-12-18 @tab 1.9.4  @tab 7508 @tab 718 @tab 7856 @tab 3361 (40) @tab 1811 (37) @tab 140 @tab 560
12040 @item 2005-02-13 @tab 1.9.5  @tab 7523 @tab 719 @tab 7859 @tab 3373 (40) @tab 1453 (37) @tab 142 @tab 562
12041 @item 2005-07-10 @tab 1.9.6  @tab 7539 @tab 699 @tab 7867 @tab 3400 (40) @tab 1453 (37) @tab 144 @tab 570
12042 @end multitable
12045 @c ========================================================== Appendices
12047 @page
12048 @node Copying This Manual
12049 @appendix Copying This Manual
12051 @menu
12052 * GNU Free Documentation License::  License for copying this manual
12053 @end menu
12055 @include fdl.texi
12057 @page
12058 @node Indices
12059 @appendix Indices
12061 @menu
12062 * Macro Index::                 Index of Autoconf macros
12063 * Variable Index::              Index of Makefile variables
12064 * General Index::               General index
12065 @end menu
12067 @node Macro Index
12068 @appendixsec Macro Index
12070 @printindex fn
12072 @node Variable Index
12073 @appendixsec Variable Index
12075 @printindex vr
12077 @node General Index
12078 @appendixsec General Index
12080 @printindex cp
12083 @page
12084 @contents
12085 @bye
12087 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
12088 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
12089 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
12090 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
12091 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
12092 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
12093 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
12094 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
12095 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
12096 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
12097 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
12098 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
12099 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
12100 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
12101 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
12102 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
12103 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
12104 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
12105 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
12106 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
12107 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
12108 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
12109 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
12110 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
12111 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
12112 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
12113 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
12114 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
12115 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
12116 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
12117 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
12118 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
12119 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
12120 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
12121 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
12122 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
12123 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
12124 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
12125 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
12126 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
12127 @c  LocalWords:  unnumberedsubsec depfile tmpdepfile depmode const interoperate
12128 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
12129 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
12130 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
12131 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
12132 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
12133 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
12134 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
12135 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
12136 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
12137 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
12138 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
12139 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
12140 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
12141 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
12142 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
12143 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
12144 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
12145 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
12146 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
12147 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
12148 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
12149 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
12150 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
12151 @c  LocalWords:  tarballs Woverride scrdir vfi ELFILES djm AutoMake honkin FSF
12152 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
12153 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
12154 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
12155 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
12156 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
12157 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
12158 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
12159 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
12160 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
12161 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
12162 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
12163 @c  LocalWords:  barexec Pinard's automatize initialize