Implement AM_MAINTAINER_MODE([DEFAULT-MODE]).
[automake/plouj.git] / doc / automake.texi
blob0ea578097052218fb8cb739483ee53f895f0d09d
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 @c @ovar(ARG, DEFAULT)
11 @c -------------------
12 @c The ARG is an optional argument.  To be used for macro arguments in
13 @c their documentation (@defmac).
14 @macro ovar{varname}
15 @r{[}@var{\varname\}@r{]}
16 @end macro
18 @copying
20 This manual is for @acronym{GNU} Automake (version @value{VERSION},
21 @value{UPDATED}), a program that creates GNU standards-compliant
22 Makefiles from template files.
24 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
25 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
27 @quotation
28 Permission is granted to copy, distribute and/or modify this document
29 under the terms of the @acronym{GNU} Free Documentation License,
30 Version 1.2 or any later version published by the Free Software
31 Foundation; with no Invariant Sections, with no Front-Cover texts,
32 and with no Back-Cover Texts.  A copy of the license is included in the
33 section entitled ``@acronym{GNU} Free Documentation License.''
35 @end quotation
36 @end copying
38 @c info Automake  points to the Automake package's documentation
39 @c info automake  points to the automake script's documentation
40 @c (Autoconf has a similar setup.)
41 @dircategory Software development
42 @direntry
43 * Automake: (automake).         Making GNU standards-compliant Makefiles.
44 @end direntry
46 @dircategory Individual utilities
47 @direntry
48 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4.
49 * automake: (automake)Invoking Automake.        Generating Makefile.in.
50 @end direntry
52 @titlepage
53 @title GNU Automake
54 @subtitle For version @value{VERSION}, @value{UPDATED}
55 @author David MacKenzie
56 @author Tom Tromey
57 @author Alexandre Duret-Lutz
58 @page
59 @vskip 0pt plus 1filll
60 @insertcopying
61 @end titlepage
64 @c We use the following macros to define indices:
65 @c   @cindex   concepts, and anything that does not fit elsewhere
66 @c   @vindex   Makefile variables
67 @c   @trindex  targets
68 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
69 @c   @opindex  tool options
71 @c Define an index of configure macros.
72 @defcodeindex ac
73 @c Define an index of options.
74 @defcodeindex op
75 @c Define an index of targets.
76 @defcodeindex tr
77 @c Define an index of commands.
78 @defcodeindex cm
80 @c Put the macros in the function index.
81 @syncodeindex ac fn
83 @c Put everything else into one index (arbitrarily chosen to be the concept index).
84 @syncodeindex op cp
85 @syncodeindex tr cp
86 @syncodeindex cm cp
88 @ifnottex
89 @node Top
90 @comment  node-name,  next,  previous,  up
91 @top GNU Automake
93 @insertcopying
95 @menu
96 * Introduction::                Automake's purpose
97 * Autotools Introduction::      An Introduction to the Autotools
98 * Generalities::                General ideas
99 * Examples::                    Some example packages
100 * Invoking Automake::           Creating a Makefile.in
101 * configure::                   Scanning configure.ac or configure.in
102 * Directories::                 Declaring subdirectories
103 * Programs::                    Building programs and libraries
104 * Other objects::               Other derived objects
105 * Other GNU Tools::             Other GNU Tools
106 * Documentation::               Building documentation
107 * Install::                     What gets installed
108 * Clean::                       What gets cleaned
109 * Dist::                        What goes in a distribution
110 * Tests::                       Support for test suites
111 * Rebuilding::                  Automatic rebuilding of Makefile
112 * Options::                     Changing Automake's behavior
113 * Miscellaneous::               Miscellaneous rules
114 * Include::                     Including extra files in an Automake template.
115 * Conditionals::                Conditionals
116 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
117 * Cygnus::                      The effect of @option{--cygnus}
118 * Not Enough::                  When Automake is not Enough
119 * Distributing::                Distributing the Makefile.in
120 * API versioning::              About compatibility between Automake versions
121 * Upgrading::                   Upgrading to a Newer Automake Version
122 * FAQ::                         Frequently Asked Questions
123 * History::                     Notes about the history of Automake
124 * Copying This Manual::         How to make copies of this manual
125 * Indices::                     Indices of variables, macros, and concepts
127 @detailmenu
128  --- The Detailed Node Listing ---
130 An Introduction to the Autotools
132 * GNU Build System::            Introducing the GNU Build System
133 * Use Cases::                   Use Cases for the GNU Build System
134 * Why Autotools::               How Autotools Help
135 * Hello World::                 A Small Hello World Package
137 Use Cases for the GNU Build System
139 * Basic Installation::          Common installation procedure
140 * Standard Targets::            A list of standard Makefile targets
141 * Standard Directory Variables::  A list of standard directory variables
142 * Standard Configuration Variables::  Using configuration variables
143 * config.site::                 Using a config.site file
144 * VPATH Builds::                Parallel build trees
145 * Two-Part Install::            Installing data and programs separately
146 * Cross-Compilation::           Building for other architectures
147 * Renaming::                    Renaming programs at install time
148 * DESTDIR::                     Building binary packages with DESTDIR
149 * Preparing Distributions::     Rolling out tarballs
150 * Dependency Tracking::         Automatic dependency tracking
151 * Nested Packages::             The GNU Build Systems can be nested
153 A Small Hello World
155 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
156 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
158 General ideas
160 * General Operation::           General operation of Automake
161 * Strictness::                  Standards conformance checking
162 * Uniform::                     The Uniform Naming Scheme
163 * Canonicalization::            How derived variables are named
164 * User Variables::              Variables reserved for the user
165 * Auxiliary Programs::          Programs automake might require
167 Some example packages
169 * Complete::                    A simple example, start to finish
170 * true::                        Building true and false
172 Scanning @file{configure.ac}
174 * Requirements::                Configuration requirements
175 * Optional::                    Other things Automake recognizes
176 * Invoking aclocal::            Auto-generating aclocal.m4
177 * Macros::                      Autoconf macros supplied with Automake
179 Auto-generating aclocal.m4
181 * aclocal options::             Options supported by aclocal
182 * Macro search path::           How aclocal finds .m4 files
183 * Extending aclocal::           Writing your own aclocal macros
184 * Local Macros::                Organizing local macros
185 * Serials::                     Serial lines in Autoconf macros
186 * Future of aclocal::           aclocal's scheduled death
188 Autoconf macros supplied with Automake
190 * Public macros::               Macros that you can use.
191 * Obsolete macros::             Macros that you should stop using.
192 * Private macros::              Macros that you should not use.
194 Directories
196 * Subdirectories::              Building subdirectories recursively
197 * Conditional Subdirectories::  Conditionally not building directories
198 * Alternative::                 Subdirectories without recursion
199 * Subpackages::                 Nesting packages
201 Building Programs and Libraries
203 * A Program::                   Building a program
204 * A Library::                   Building a library
205 * A Shared Library::            Building a Libtool library
206 * Program and Library Variables::  Variables controlling program and
207                                 library builds
208 * Default _SOURCES::            Default source files
209 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
210 * Program variables::           Variables used when building a program
211 * Yacc and Lex::                Yacc and Lex support
212 * C++ Support::                 Compiling C++ sources
213 * Objective C Support::         Compiling Objective C sources
214 * Unified Parallel C Support::  Compiling Unified Parallel C sources
215 * Assembly Support::            Compiling assembly sources
216 * Fortran 77 Support::          Compiling Fortran 77 sources
217 * Fortran 9x Support::          Compiling Fortran 9x sources
218 * Java Support::                Compiling Java sources
219 * Support for Other Languages::  Compiling other languages
220 * ANSI::                        Automatic de-ANSI-fication (obsolete)
221 * Dependencies::                Automatic dependency tracking
222 * EXEEXT::                      Support for executable extensions
224 Building a program
226 * Program Sources::             Defining program sources
227 * Linking::                     Linking with libraries or extra objects
228 * Conditional Sources::         Handling conditional sources
229 * Conditional Programs::        Building program conditionally
231 Building a Shared Library
233 * Libtool Concept::             Introducing Libtool
234 * Libtool Libraries::           Declaring Libtool Libraries
235 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
236 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
237 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
238 * Libtool Modules::             Building Libtool Modules
239 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
240 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
241 * Libtool Issues::              Common Issues Related to Libtool's Use
243 Fortran 77 Support
245 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
246 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
247 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
249 Mixing Fortran 77 With C and C++
251 * How the Linker is Chosen::    Automatic linker selection
253 Fortran 9x Support
255 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
257 Other Derived Objects
259 * Scripts::                     Executable scripts
260 * Headers::                     Header files
261 * Data::                        Architecture-independent data files
262 * Sources::                     Derived sources
264 Built sources
266 * Built sources example::       Several ways to handle built sources.
268 Other GNU Tools
270 * Emacs Lisp::                  Emacs Lisp
271 * gettext::                     Gettext
272 * Libtool::                     Libtool
273 * Java::                        Java
274 * Python::                      Python
276 Building documentation
278 * Texinfo::                     Texinfo
279 * Man pages::                   Man pages
281 Miscellaneous Rules
283 * Tags::                        Interfacing to etags and mkid
284 * Suffixes::                    Handling new file extensions
285 * Multilibs::                   Support for multilibs.
287 When Automake Isn't Enough
289 * Extending::                   Adding new rules or overriding existing ones.
290 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
292 Frequently Asked Questions about Automake
294 * CVS::                         CVS and generated files
295 * maintainer-mode::             missing and AM_MAINTAINER_MODE
296 * wildcards::                   Why doesn't Automake support wildcards?
297 * limitations on file names::   Limitations on source and installed file names
298 * distcleancheck::              Files left in build directory after distclean
299 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
300 * renamed objects::             Why are object files sometimes renamed?
301 * Per-Object Flags::            How to simulate per-object flags?
302 * Multiple Outputs::            Writing rules for tools with many output files
303 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
305 History of Automake
307 * Timeline::                    The Automake story.
308 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
309 * Releases::                    Statistics about Automake Releases
311 Copying This Manual
313 * GNU Free Documentation License::  License for copying this manual
315 Indices
317 * Macro Index::                 Index of Autoconf macros
318 * Variable Index::              Index of Makefile variables
319 * General Index::               General index
321 @end detailmenu
322 @end menu
324 @end ifnottex
327 @node Introduction
328 @chapter Introduction
330 Automake is a tool for automatically generating @file{Makefile.in}s
331 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
332 basically a series of @command{make} variable
333 definitions@footnote{These variables are also called @dfn{make macros}
334 in Make terminology, however in this manual we reserve the term
335 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
336 occasionally.  The generated @file{Makefile.in}s are compliant with
337 the GNU Makefile standards.
339 @cindex GNU Makefile standards
341 The GNU Makefile Standards Document
342 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
343 is long, complicated, and subject to change.  The goal of Automake is to
344 remove the burden of Makefile maintenance from the back of the
345 individual GNU maintainer (and put it on the back of the Automake
346 maintainers).
348 The typical Automake input file is simply a series of variable definitions.
349 Each such file is processed to create a @file{Makefile.in}.  There
350 should generally be one @file{Makefile.am} per directory of a project.
352 @cindex Constraints of Automake
353 @cindex Automake constraints
355 Automake does constrain a project in certain ways; for instance, it
356 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
357 autoconf, The Autoconf Manual}), and enforces certain restrictions on
358 the @file{configure.ac} contents@footnote{Older Autoconf versions used
359 @file{configure.in}.  Autoconf 2.50 and greater promotes
360 @file{configure.ac} over @file{configure.in}.  The rest of this
361 documentation will refer to @file{configure.ac}, but Automake also
362 supports @file{configure.in} for backward compatibility.}.
364 @cindex Automake requirements
365 @cindex Requirements, Automake
367 Automake requires @command{perl} in order to generate the
368 @file{Makefile.in}s.  However, the distributions created by Automake are
369 fully GNU standards-compliant, and do not require @command{perl} in order
370 to be built.
372 @cindex Bugs, reporting
373 @cindex Reporting bugs
374 @cindex E-mail, bug reports
376 Mail suggestions and bug reports for Automake to
377 @email{bug-automake@@gnu.org}.
379 @node Autotools Introduction
380 @chapter An Introduction to the Autotools
382 If you are new to Automake, maybe you know that it is part of a set of
383 tools called @emph{The Autotools}.  Maybe you've already delved into a
384 package full of files named @file{configure}, @file{configure.ac},
385 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
386 some of them claiming to be @emph{generated by} Autoconf or Automake.
387 But the exact purpose of these files and their relations is probably
388 fuzzy.  The goal of this chapter is to introduce you to this machinery,
389 to show you how it works and how powerful it is.  If you've never
390 installed or seen such a package, do not worry: this chapter will walk
391 you through it.
393 If you need some teaching material, more illustrations, or a less
394 @command{automake}-centered continuation, some slides for this
395 introduction are available in Alexandre Duret-Lutz's
396 @uref{http://www-src.lip6.fr/@/~Alexandre.Duret-Lutz/@/autotools.html,
397 Autotools Tutorial}.
398 This chapter is the written version of the first part of his tutorial.
400 @menu
401 * GNU Build System::            Introducing the GNU Build System
402 * Use Cases::                   Use Cases for the GNU Build System
403 * Why Autotools::               How Autotools Help
404 * Hello World::                 A Small Hello World Package
405 @end menu
407 @node GNU Build System
408 @section Introducing the GNU Build System
409 @cindex GNU Build System, introduction
411 It is a truth universally acknowledged, that a developer in
412 possession of a new package, must be in want of a build system.
414 In the Unix world, such a build system is traditionally achieved using
415 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
416 Manual}).  The developer expresses the recipe to build his package in
417 a @file{Makefile}.  This file is a set of rules to build the files in
418 the package.  For instance the program @file{prog} may be built by
419 running the linker on the files @file{main.o}, @file{foo.o}, and
420 @file{bar.o}; the file @file{main.o} may be built by running the
421 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
422 reads @file{Makefile}, checks the existence and modification time of
423 the files mentioned, decides what files need to be built (or rebuilt),
424 and runs the associated commands.
426 When a package needs to be built on a different platform than the one
427 it was developed on, its @file{Makefile} usually needs to be adjusted.
428 For instance the compiler may have another name or require more
429 options.  In 1991, David J. MacKenzie got tired of customizing
430 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
431 handcrafted a little shell script called @file{configure} to
432 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
433 autoconf, The Autoconf Manual}).  Compiling his package was now
434 as simple as running @code{./configure && make}.
436 @cindex GNU Coding Standards
438 Today this process has been standardized in the GNU project.  The GNU
439 Coding Standards (@pxref{Managing Releases, The Release Process, ,
440 standards, The GNU Coding Standards}) explains how each package of the
441 GNU project should have a @file{configure} script, and the minimal
442 interface it should have.  The @file{Makefile} too should follow some
443 established conventions.  The result?  A unified build system that
444 makes all packages almost indistinguishable by the installer.  In its
445 simplest scenario, all the installer has to do is to unpack the
446 package, run @code{./configure && make && make install}, and repeat
447 with the next package to install.
449 We call this build system the @dfn{GNU Build System}, since it was
450 grown out of the GNU project.  However it is used by a vast number of
451 other packages: following any existing convention has its advantages.
453 @cindex Autotools, introduction
455 The Autotools are tools that will create a GNU Build System for your
456 package.  Autoconf mostly focuses on @file{configure} and Automake on
457 @file{Makefile}s.  It is entirely possible to create a GNU Build
458 System without the help of these tools.  However it is rather
459 burdensome and error-prone.  We will discuss this again after some
460 illustration of the GNU Build System in action.
462 @node Use Cases
463 @section Use Cases for the GNU Build System
464 @cindex GNU Build System, use cases
465 @cindex GNU Build System, features
466 @cindex Features of the GNU Build System
467 @cindex Use Cases for the GNU Build System
468 @cindex @file{amhello-1.0.tar.gz}, location
469 @cindex @file{amhello-1.0.tar.gz}, use cases
471 In this section we explore several use cases for the GNU Build System.
472 You can replay all these examples on the @file{amhello-1.0.tar.gz}
473 package distributed with Automake.  If Automake is installed on your
474 system, you should find a copy of this file in
475 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
476 @var{prefix} is the installation prefix specified during configuration
477 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
478 installed by some GNU/Linux distribution it most likely has been set
479 to @file{/usr}).  If you do not have a copy of Automake installed,
480 you can find a copy of this file inside the @file{doc/} directory of
481 the Automake package.
483 Some of the following use cases present features that are in fact
484 extensions to the GNU Build System.  Read: they are not specified by
485 the GNU Coding Standards, but they are nonetheless part of the build
486 system created by the Autotools.  To keep things simple, we do not
487 point out the difference.  Our objective is to show you many of the
488 features that the build system created by the Autotools will offer to
489 you.
491 @menu
492 * Basic Installation::          Common installation procedure
493 * Standard Targets::            A list of standard Makefile targets
494 * Standard Directory Variables::  A list of standard directory variables
495 * Standard Configuration Variables::  Using configuration variables
496 * config.site::                 Using a config.site file
497 * VPATH Builds::                Parallel build trees
498 * Two-Part Install::            Installing data and programs separately
499 * Cross-Compilation::           Building for other architectures
500 * Renaming::                    Renaming programs at install time
501 * DESTDIR::                     Building binary packages with DESTDIR
502 * Preparing Distributions::     Rolling out tarballs
503 * Dependency Tracking::         Automatic dependency tracking
504 * Nested Packages::             The GNU Build Systems can be nested
505 @end menu
507 @node Basic Installation
508 @subsection Basic Installation
509 @cindex Configuration, basics
510 @cindex Installation, basics
511 @cindex GNU Build System, basics
513 The most common installation procedure looks as follows.
515 @example
516 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
517 ~ % @kbd{cd amhello-1.0}
518 ~/amhello-1.0 % @kbd{./configure}
519 @dots{}
520 config.status: creating Makefile
521 config.status: creating src/Makefile
522 @dots{}
523 ~/amhello-1.0 % @kbd{make}
524 @dots{}
525 ~/amhello-1.0 % @kbd{make check}
526 @dots{}
527 ~/amhello-1.0 % @kbd{su}
528 Password:
529 /home/adl/amhello-1.0 # @kbd{make install}
530 @dots{}
531 /home/adl/amhello-1.0 # @kbd{exit}
532 ~/amhello-1.0 % @kbd{make installcheck}
533 @dots{}
534 @end example
536 @cindex Unpacking
538 The user first unpacks the package.  Here, and in the following
539 examples, we will use the non-portable @code{tar zxf} command for
540 simplicity.  On a system without GNU @command{tar} installed, this
541 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
543 The user then enters the newly created directory to run the
544 @file{configure} script.  This script probes the system for various
545 features, and finally creates the @file{Makefile}s.  In this toy
546 example there are only two @file{Makefile}s, but in real-world projects,
547 there may be many more, usually one @file{Makefile} per directory.
549 It is now possible to run @code{make}.  This will construct all the
550 programs, libraries, and scripts that need to be constructed for the
551 package.  In our example, this compiles the @file{hello} program.
552 All files are constructed in place, in the source tree; we will see
553 later how this can be changed.
555 @code{make check} causes the package's tests to be run.  This step is
556 not mandatory, but it is often good to make sure the programs that
557 have been built behave as they should, before you decide to install
558 them.  Our example does not contain any tests, so running @code{make
559 check} is a no-op.
561 @cindex su, before @code{make install}
562 After everything has been built, and maybe tested, it is time to
563 install it on the system.  That means copying the programs,
564 libraries, header files, scripts, and other data files from the
565 source directory to their final destination on the system.  The
566 command @code{make install} will do that.  However, by default
567 everything will be installed in subdirectories of @file{/usr/local}:
568 binaries will go into @file{/usr/local/bin}, libraries will end up in
569 @file{/usr/local/lib}, etc.  This destination is usually not writable
570 by any user, so we assume that we have to become root before we can
571 run @code{make install}.  In our example, running @code{make install}
572 will copy the program @file{hello} into @file{/usr/local/bin}
573 and @file{README} into @file{/usr/local/share/doc/amhello}.
575 A last and optional step is to run @code{make installcheck}.  This
576 command may run tests on the installed files.  @code{make check} tests
577 the files in the source tree, while @code{make installcheck} tests
578 their installed copies.  The tests run by the latter can be different
579 from those run by the former.  For instance, there are tests that
580 cannot be run in the source tree.  Conversely, some packages are set
581 up so that @code{make installcheck} will run the very same tests as
582 @code{make check}, only on different files (non-installed
583 vs.@: installed).  It can make a difference, for instance when the
584 source tree's layout is different from that of the installation.
585 Furthermore it may help to diagnose an incomplete installation.
587 Presently most packages do not have any @code{installcheck} tests
588 because the existence of @code{installcheck} is little known, and its
589 usefulness is neglected.  Our little toy package is no better: @code{make
590 installcheck} does nothing.
592 @node Standard Targets
593 @subsection Standard @file{Makefile} Targets
595 So far we have come across four ways to run @command{make} in the GNU
596 Build System: @code{make}, @code{make check}, @code{make install}, and
597 @code{make installcheck}.  The words @code{check}, @code{install}, and
598 @code{installcheck}, passed as arguments to @command{make}, are called
599 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
600 @code{all} being the default target in the GNU Build System.
602 Here is a list of the most useful targets that the GNU Coding Standards
603 specify.
605 @table @code
606 @item make all
607 @trindex all
608 Build programs, libraries, documentation, etc.@: (same as @code{make}).
609 @item make install
610 @trindex install
611 Install what needs to be installed, copying the files from the
612 package's tree to system-wide directories.
613 @item make install-strip
614 @trindex install-strip
615 Same as @code{make install}, then strip debugging symbols.  Some
616 users like to trade space for useful bug reports@enddots{}
617 @item make uninstall
618 @trindex uninstall
619 The opposite of @code{make install}: erase the installed files.
620 (This needs to be run from the same build tree that was installed.)
621 @item make clean
622 @trindex clean
623 Erase from the build tree the files built by @code{make all}.
624 @item make distclean
625 @trindex distclean
626 Additionally erase anything @code{./configure} created.
627 @item make check
628 @trindex check
629 Run the test suite, if any.
630 @item make installcheck
631 @trindex installcheck
632 Check the installed programs or libraries, if supported.
633 @item make dist
634 @trindex dist
635 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
636 files.
637 @end table
639 @node Standard Directory Variables
640 @subsection Standard Directory Variables
641 @cindex directory variables
643 The GNU Coding Standards also specify a hierarchy of variables to
644 denote installation directories.  Some of these are:
646 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
647 @headitem Directory variable    @tab Default value
648 @item @code{prefix}              @tab @code{/usr/local}
649 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
650 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
651 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
652 @item @w{@ @ @ @ @dots{}}
653 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
654 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
655 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
656 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
657 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
658 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
659 @item @w{@ @ @dots{}}
660 @end multitable
662 @c We should provide a complete table somewhere, but not here.  The
663 @c complete list of directory variables it too confusing as-is.  It
664 @c requires some explanations that are too complicated for this
665 @c introduction.  Besides listing directories like localstatedir
666 @c would make the explanations in ``Two-Part Install'' harder.
668 Each of these directories has a role which is often obvious from its
669 name.  In a package, any installable file will be installed in one of
670 these directories.  For instance in @code{amhello-1.0}, the program
671 @file{hello} is to be installed in @var{bindir}, the directory for
672 binaries.  The default value for this directory is
673 @file{/usr/local/bin}, but the user can supply a different value when
674 calling @command{configure}.  Also the file @file{README} will be
675 installed into @var{docdir}, which defaults to
676 @file{/usr/local/share/doc/amhello}.
678 @opindex --prefix
680 A user who wishes to install a package on his own account could proceed
681 as follows:
683 @example
684 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
685 @dots{}
686 ~/amhello-1.0 % @kbd{make}
687 @dots{}
688 ~/amhello-1.0 % @kbd{make install}
689 @dots{}
690 @end example
692 This would install @file{~/usr/bin/hello} and
693 @file{~/usr/share/doc/amhello/README}.
695 The list of all such directory options is shown by
696 @code{./configure --help}.
698 @node Standard Configuration Variables
699 @subsection Standard Configuration Variables
700 @cindex configuration variables, overriding
702 The GNU Coding Standards also define a set of standard configuration
703 variables used during the build.  Here are some:
705 @table @asis
706 @item @code{CC}
707 C compiler command
708 @item @code{CFLAGS}
709 C compiler flags
710 @item @code{CXX}
711 C++ compiler command
712 @item @code{CXXFLAGS}
713 C++ compiler flags
714 @item @code{LDFLAGS}
715 linker flags
716 @item @code{CPPFLAGS}
717 C/C++ preprocessor flags
718 @item @dots{}
719 @end table
721 @command{configure} usually does a good job at setting appropriate
722 values for these variables, but there are cases where you may want to
723 override them.  For instance you may have several versions of a
724 compiler installed and would like to use another one, you may have
725 header files installed outside the default search path of the
726 compiler, or even libraries out of the way of the linker.
728 Here is how one would call @command{configure} to force it to use
729 @command{gcc-3} as C compiler, use header files from
730 @file{~/usr/include} when compiling, and libraries from
731 @file{~/usr/lib} when linking.
733 @example
734 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
735 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
736 @end example
738 Again, a full list of these variables appears in the output of
739 @code{./configure --help}.
741 @node config.site
742 @subsection Overriding Default Configuration Setting with @file{config.site}
743 @cindex @file{config.site} example
745 When installing several packages using the same setup, it can be
746 convenient to create a file to capture common settings.
747 If a file named @file{@var{prefix}/share/config.site} exists,
748 @command{configure} will source it at the beginning of its execution.
750 Recall the command from the previous section:
752 @example
753 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
754 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
755 @end example
757 Assuming we are installing many package in @file{~/usr}, and will
758 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
759 @code{LDFLAGS}, we can automate this by creating the following
760 @file{~/usr/share/config.site} file:
762 @example
763 test -z "$CC" && CC=gcc-3
764 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
765 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
766 @end example
768 Now, any time a @file{configure} script is using the @file{~/usr}
769 prefix, it will execute the above @file{config.site} and define
770 these three variables.
772 @example
773 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
774 configure: loading site script /home/adl/usr/share/config.site
775 @dots{}
776 @end example
778 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
779 Manual}, for more information about this feature.
782 @node VPATH Builds
783 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
784 @cindex Parallel build trees
785 @cindex VPATH builds
786 @cindex source tree and build tree
787 @cindex build tree and source tree
788 @cindex trees, source vs.@: build
790 The GNU Build System distinguishes two trees: the source tree, and
791 the build tree.
793 The source tree is rooted in the directory containing
794 @file{configure}.  It contains all the sources files (those that are
795 distributed), and may be arranged using several subdirectories.
797 The build tree is rooted in the directory in which @file{configure}
798 was run, and is populated with all object files, programs, libraries,
799 and other derived files built from the sources (and hence not
800 distributed).  The build tree usually has the same subdirectory layout
801 as the source tree; its subdirectories are created automatically by
802 the build system.
804 If @file{configure} is executed in its own directory, the source and
805 build trees are combined: derived files are constructed in the same
806 directories as their sources.  This was the case in our first
807 installation example (@pxref{Basic Installation}).
809 A common request from users is that they want to confine all derived
810 files to a single directory, to keep their source directories
811 uncluttered.  Here is how we could run @file{configure} to build
812 everything in a subdirectory called @file{build/}.
814 @example
815 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
816 ~ % @kbd{cd amhello-1.0}
817 ~/amhello-1.0 % @kbd{mkdir build && cd build}
818 ~/amhello-1.0/build % @kbd{../configure}
819 @dots{}
820 ~/amhello-1.0/build % @kbd{make}
821 @dots{}
822 @end example
824 These setups, where source and build trees are different, are often
825 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
826 @emph{parallel build} is misleading: the word @emph{parallel} is a
827 reference to the way the build tree shadows the source tree, it is not
828 about some concurrency in the way build commands are run.  For this
829 reason we refer to such setups using the name @emph{VPATH builds} in
830 the following.  @emph{VPATH} is the name of the @command{make} feature
831 used by the @file{Makefile}s to allow these builds (@pxref{General
832 Search, , @code{VPATH}: Search Path for All Prerequisites, make, The
833 GNU Make Manual}).
835 @cindex multiple configurations, example
836 @cindex debug build, example
837 @cindex optimized build, example
839 VPATH builds have other interesting uses.  One is to build the same
840 sources with multiple configurations.  For instance:
842 @example
843 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
844 ~ % @kbd{cd amhello-1.0}
845 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
846 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
847 @dots{}
848 ~/amhello-1.0/debug % @kbd{make}
849 @dots{}
850 ~/amhello-1.0/debug % cd ../optim
851 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
852 @dots{}
853 ~/amhello-1.0/optim % @kbd{make}
854 @dots{}
855 @end example
857 With network file systems, a similar approach can be used to build the
858 same sources on different machines.  For instance, suppose that the
859 sources are installed on a directory shared by two hosts: @code{HOST1}
860 and @code{HOST2}, which may be different platforms.
862 @example
863 ~ % @kbd{cd /nfs/src}
864 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
865 @end example
867 On the first host, you could create a local build directory:
868 @example
869 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
870 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
872 [HOST1] /tmp/amh % @kbd{make && sudo make install}
874 @end example
876 @noindent
877 (Here we assume the that installer has configured @command{sudo} so it
878 can execute @code{make install} with root privileges; it is more convenient
879 than using @command{su} like in @ref{Basic Installation}).
881 On the second host, you would do exactly the same, possibly at
882 the same time:
883 @example
884 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
885 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
887 [HOST2] /tmp/amh % @kbd{make && sudo make install}
889 @end example
891 @cindex read-only source tree
892 @cindex source tree, read-only
894 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
895 directory from being read-only.  In fact VPATH builds are also a means
896 of building packages from a read-only medium such as a CD-ROM.  (The
897 FSF used to sell CD-ROM with unpacked source code, before the GNU
898 project grew so big.)
900 @node Two-Part Install
901 @subsection Two-Part Installation
903 In our last example (@pxref{VPATH Builds}), a source tree was shared
904 by two hosts, but compilation and installation were done separately on
905 each host.
907 The GNU Build System also supports networked setups where part of the
908 installed files should be shared amongst multiple hosts.  It does so
909 by distinguishing architecture-dependent files from
910 architecture-independent files, and providing two @file{Makefile}
911 targets to install each of these classes of files.
913 @trindex install-exec
914 @trindex install-data
916 These targets are @code{install-exec} for architecture-dependent files
917 and @code{install-data} for architecture-independent files.
918 The command we used up to now, @code{make install}, can be thought of
919 as a shorthand for @code{make install-exec install-data}.
921 From the GNU Build System point of view, the distinction between
922 architecture-dependent files and architecture-independent files is
923 based exclusively on the directory variable used to specify their
924 installation destination.  In the list of directory variables we
925 provided earlier (@pxref{Standard Directory Variables}), all the
926 variables based on @var{exec-prefix} designate architecture-dependent
927 directories whose files will be installed by @code{make install-exec}.
928 The others designate architecture-independent directories and will
929 serve files installed by @code{make install-data}.  @xref{Install},
930 for more details.
932 Here is how we could revisit our two-host installation example,
933 assuming that (1) we want to install the package directly in
934 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
935 two hosts.
937 On the first host we would run
938 @example
939 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
940 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
942 [HOST1] /tmp/amh % @kbd{make && sudo make install}
944 @end example
946 On the second host, however, we need only install the
947 architecture-specific files.
948 @example
949 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
950 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
952 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
954 @end example
956 In packages that have installation checks, it would make sense to run
957 @code{make installcheck} (@pxref{Basic Installation}) to verify that
958 the package works correctly despite the apparent partial installation.
960 @node Cross-Compilation
961 @subsection Cross-Compilation
962 @cindex cross-compilation
964 To @dfn{cross-compile} is to build on one platform a binary that will
965 run on another platform.  When speaking of cross-compilation, it is
966 important to distinguish between the @dfn{build platform} on which
967 the compilation is performed, and the @dfn{host platform} on which the
968 resulting executable is expected to run.  The following
969 @command{configure} options are used to specify each of them:
971 @table @option
972 @item --build=@var{BUILD}
973 @opindex --build=@var{BUILD}
974 The system on which the package is built.
975 @item --host=@var{HOST}
976 @opindex --host=@var{HOST}
977 The system where built programs and libraries will run.
978 @end table
980 When the @option{--host} is used, @command{configure} will search for
981 the cross-compiling suite for this platform.  Cross-compilation tools
982 commonly have their target architecture as prefix of their name.  For
983 instance my cross-compiler for MinGW32 has its binaries called
984 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
985 @code{i586-mingw32msvc-as}, etc.
987 @cindex MinGW cross-compilation example
988 @cindex cross-compilation example
990 Here is how we could build @code{amhello-1.0} for
991 @code{i586-mingw32msvc} on a GNU/Linux PC.
993 @smallexample
994 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
995 checking for a BSD-compatible install... /usr/bin/install -c
996 checking whether build environment is sane... yes
997 checking for gawk... gawk
998 checking whether make sets $(MAKE)... yes
999 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1000 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1001 checking for C compiler default output file name... a.exe
1002 checking whether the C compiler works... yes
1003 checking whether we are cross compiling... yes
1004 checking for suffix of executables... .exe
1005 checking for suffix of object files... o
1006 checking whether we are using the GNU C compiler... yes
1007 checking whether i586-mingw32msvc-gcc accepts -g... yes
1008 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1009 @dots{}
1010 ~/amhello-1.0 % @kbd{make}
1011 @dots{}
1012 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1013 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1014 @end smallexample
1016 The @option{--host} and @option{--build} options are usually all we
1017 need for cross-compiling.  The only exception is if the package being
1018 built is itself a cross-compiler: we need a third option to specify
1019 its target architecture.
1021 @table @option
1022 @item --target=@var{TARGET}
1023 @opindex --target=@var{TARGET}
1024 When building compiler tools: the system for which the tools will
1025 create output.
1026 @end table
1028 For instance when installing GCC, the GNU Compiler Collection, we can
1029 use @option{--target=@var{TARGET}} to specify that we want to build
1030 GCC as a cross-compiler for @var{TARGET}.  Mixing @option{--build} and
1031 @option{--target}, we can actually cross-compile a cross-compiler;
1032 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1034 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1035 Autoconf Manual}, for more information about these @command{configure}
1036 options.
1038 @node Renaming
1039 @subsection Renaming Programs at Install Time
1040 @cindex Renaming programs
1041 @cindex Transforming program names
1042 @cindex Programs, renaming during installation
1044 The GNU Build System provides means to automatically rename
1045 executables and manpages before they are installed (@pxref{Man pages}).
1046 This is especially convenient
1047 when installing a GNU package on a system that already has a
1048 proprietary implementation you do not want to overwrite.  For instance,
1049 you may want to install GNU @command{tar} as @command{gtar} so you can
1050 distinguish it from your vendor's @command{tar}.
1052 This can be done using one of these three @command{configure} options.
1054 @table @option
1055 @item --program-prefix=@var{PREFIX}
1056 @opindex --program-prefix=@var{PREFIX}
1057 Prepend @var{PREFIX} to installed program names.
1058 @item --program-suffix=@var{SUFFIX}
1059 @opindex --program-suffix=@var{SUFFIX}
1060 Append @var{SUFFIX} to installed program names.
1061 @item --program-transform-name=@var{PROGRAM}
1062 @opindex --program-transform-name=@var{PROGRAM}
1063 Run @code{sed @var{PROGRAM}} on installed program names.
1064 @end table
1066 The following commands would install @file{hello}
1067 as @file{/usr/local/bin/test-hello}, for instance.
1069 @example
1070 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1071 @dots{}
1072 ~/amhello-1.0 % @kbd{make}
1073 @dots{}
1074 ~/amhello-1.0 % @kbd{sudo make install}
1075 @dots{}
1076 @end example
1078 @node DESTDIR
1079 @subsection Building Binary Packages Using DESTDIR
1080 @vindex DESTDIR
1082 The GNU Build System's @code{make install} and @code{make uninstall}
1083 interface does not exactly fit the needs of a system administrator
1084 who has to deploy and upgrade packages on lots of hosts.  In other
1085 words, the GNU Build System does not replace a package manager.
1087 Such package managers usually need to know which files have been
1088 installed by a package, so a mere @code{make install} is
1089 inappropriate.
1091 @cindex Staged installation
1093 The @code{DESTDIR} variable can be used to perform a staged
1094 installation.  The package should be configured as if it was going to
1095 be installed in its final location (e.g., @code{--prefix /usr}), but
1096 when running @code{make install}, the @code{DESTDIR} should be set to
1097 the absolute name of a directory into which the installation will be
1098 diverted.  From this directory it is easy to review which files are
1099 being installed where, and finally copy them to their final location
1100 by some means.
1102 @cindex Binary package
1104 For instance here is how we could create a binary package containing a
1105 snapshot of all the files to be installed.
1107 @example
1108 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1109 @dots{}
1110 ~/amhello-1.0 % @kbd{make}
1111 @dots{}
1112 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1113 @dots{}
1114 ~/amhello-1.0 % @kbd{cd ~/inst}
1115 ~/inst % @kbd{find . -type f -print > ../files.lst}
1116 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../file.lst`}
1117 ./usr/bin/hello
1118 ./usr/share/doc/amhello/README
1119 @end example
1121 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1122 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../file.lst`}
1123 instead of @samp{.} as argument for @command{tar} avoids entries for
1124 each subdirectory in the archive: we would not like @command{tar} to
1125 restore the modification time of @file{/}, @file{/usr/}, etc.)
1127 Note that when building packages for several architectures, it might
1128 be convenient to use @code{make install-data} and @code{make
1129 install-exec} (@pxref{Two-Part Install}) to gather
1130 architecture-independent files in a single package.
1132 @xref{Install}, for more information.
1134 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1135 @c UNINSTALL counterparts.
1137 @node Preparing Distributions
1138 @subsection Preparing Distributions
1139 @cindex Preparing distributions
1140 @cindex Packages, preparation
1141 @cindex Distributions, preparation
1143 We have already mentioned @code{make dist}.  This target collects all
1144 your source files and the necessary parts of the build system to
1145 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1147 @cindex @code{distcheck} better than @code{dist}
1149 Another, more useful command is @code{make distcheck}.  The
1150 @code{distcheck} target constructs
1151 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1152 but it additionally ensures most of the use cases presented so far
1153 work:
1155 @itemize @bullet
1156 @item
1157 It attempts a full compilation of the package (@pxref{Basic
1158 Installation}), unpacking the newly constructed tarball, running
1159 @code{make}, @code{make check}, @code{make install}, as well as
1160 @code{make installcheck}, and even @code{make dist},
1161 @item
1162 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1163 @item
1164 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1165 uninstall} do not omit any file (@pxref{Standard Targets}),
1166 @item
1167 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1168 @end itemize
1170 All of these actions are performed in a temporary subdirectory, so
1171 that no root privileges are required.
1173 Releasing a package that fails @code{make distcheck} means that one of
1174 the scenarios we presented will not work and some users will be
1175 disappointed.  Therefore it is a good practice to release a package
1176 only after a successful @code{make distcheck}.  This of course does
1177 not imply that the package will be flawless, but at least it will
1178 prevent some of the embarrassing errors you may find in packages
1179 released by people who have never heard about @code{distcheck} (like
1180 @code{DESTDIR} not working because of a typo, or a distributed file
1181 being erased by @code{make clean}, or even @code{VPATH} builds not
1182 working).
1184 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1185 @code{make distcheck}.  @xref{Dist}, for more information about
1186 @code{distcheck}.
1188 @node Dependency Tracking
1189 @subsection Automatic Dependency Tracking
1190 @cindex Dependency tracking
1192 Dependency tracking is performed as a side-effect of compilation.
1193 Each time the build system compiles a source file, it computes its
1194 list of dependencies (in C these are the header files included by the
1195 source being compiled).  Later, any time @command{make} is run and a
1196 dependency appears to have changed, the dependent files will be
1197 rebuilt.
1199 When @command{configure} is executed, you can see it probing each
1200 compiler for the dependency mechanism it supports (several mechanisms
1201 can be used):
1203 @example
1204 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1205 @dots{}
1206 checking dependency style of gcc... gcc3
1207 @dots{}
1208 @end example
1210 Because dependencies are only computed as a side-effect of the
1211 compilation, no dependency information exists the first time a package
1212 is built.  This is OK because all the files need to be built anyway:
1213 @code{make} does not have to decide which files need to be rebuilt.
1214 In fact, dependency tracking is completely useless for one-time builds
1215 and there is a @command{configure} option to disable this:
1217 @table @option
1218 @item --disable-dependency-tracking
1219 @opindex --disable-dependency-tracking
1220 Speed up one-time builds.
1221 @end table
1223 Some compilers do not offer any practical way to derive the list of
1224 dependencies as a side-effect of the compilation, requiring a separate
1225 run (maybe of another tool) to compute these dependencies.  The
1226 performance penalty implied by these methods is important enough to
1227 disable them by default.  The option @option{--enable-dependency-tracking}
1228 must be passed to @command{configure} to activate them.
1230 @table @option
1231 @item --enable-dependency-tracking
1232 @opindex --enable-dependency-tracking
1233 Do not reject slow dependency extractors.
1234 @end table
1236 @xref{Dependency Tracking Evolution}, for some discussion about the
1237 different dependency tracking schemes used by Automake over the years.
1239 @node Nested Packages
1240 @subsection Nested Packages
1241 @cindex Nested packages
1242 @cindex Packages, nested
1243 @cindex Subpackages
1245 Although nesting packages isn't something we would recommend to
1246 someone who is discovering the Autotools, it is a nice feature worthy
1247 of mention in this small advertising tour.
1249 Autoconfiscated packages (that means packages whose build system have
1250 been created by Autoconf and friends) can be nested to arbitrary
1251 depth.
1253 A typical setup is that a package A will distribute one of the libraries
1254 it needs in a subdirectory.  This library B is a complete package with
1255 its own GNU Build System.  The @command{configure} script of A will
1256 run the @command{configure} script of B as part of its execution,
1257 building and installing A will also build and install B.  Generating a
1258 distribution for A will also include B.
1260 It is possible to gather several package like this.  GCC is a heavy
1261 user of this feature.  This gives installers a single package to
1262 configure, build and install, while it allows developers to work on
1263 subpackages independently.
1265 When configuring nested packages, the @command{configure} options
1266 given to the top-level @command{configure} are passed recursively to
1267 nested @command{configure}s.  A package that does not understand an
1268 option will ignore it, assuming it is meaningful to some other
1269 package.
1271 @opindex --help=recursive
1273 The command @code{configure --help=recursive} can be used to display
1274 the options supported by all the included packages.
1276 @xref{Subpackages}, for an example setup.
1278 @node Why Autotools
1279 @section How Autotools Help
1280 @cindex Autotools, purpose
1282 There are several reasons why you may not want to implement the GNU
1283 Build System yourself (read: write a @file{configure} script and
1284 @file{Makefile}s yourself).
1286 @itemize @bullet
1287 @item
1288 As we have seen, the GNU Build System has a lot of
1289 features (@pxref{Use Cases}).
1290 Some users may expect features you have not implemented because
1291 you did not need them.
1292 @item
1293 Implementing these features portably is difficult and exhausting.
1294 Think of writing portable shell scripts, and portable
1295 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1296 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1297 convince yourself.
1298 @item
1299 You will have to upgrade your setup to follow changes to the GNU
1300 Coding Standards.
1301 @end itemize
1303 The GNU Autotools take all this burden off your back and provide:
1305 @itemize @bullet
1306 @item
1307 Tools to create a portable, complete, and self-contained GNU Build
1308 System, from simple instructions.
1309 @emph{Self-contained} meaning the resulting build system does not
1310 require the GNU Autotools.
1311 @item
1312 A central place where fixes and improvements are made:
1313 a bug-fix for a portability issue will benefit every package.
1314 @end itemize
1316 Yet there also exist reasons why you may want NOT to use the
1317 Autotools@enddots{} For instance you may be already using (or used to)
1318 another incompatible build system.  Autotools will only be useful if
1319 you do accept the concepts of the GNU Build System.  People who have their
1320 own idea of how a build system should work will feel frustrated by the
1321 Autotools.
1323 @node Hello World
1324 @section A Small Hello World
1325 @cindex Example Hello World
1326 @cindex Hello World example
1327 @cindex @file{amhello-1.0.tar.gz}, creation
1329 In this section we recreate the @file{amhello-1.0} package from
1330 scratch.  The first subsection shows how to call the Autotools to
1331 instantiate the GNU Build System, while the second explains the
1332 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1333 by the Autotools.
1335 @menu
1336 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1337 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
1338 @end menu
1340 @node Creating amhello
1341 @subsection Creating @file{amhello-1.0.tar.gz}
1343 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1344 The package is simple enough so that we will only need to write 5
1345 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1346 that is distributed with Automake if you do not want to write them.)
1348 Create the following files in an empty directory.
1350 @itemize @bullet
1352 @item
1353 @file{src/main.c} is the source file for the @file{hello} program.  We
1354 store it in the @file{src/} subdirectory, because later, when the package
1355 evolves, it will ease the addition of a @file{man/} directory for man
1356 pages, a @file{data/} directory for data files, etc.
1357 @example
1358 ~/amhello % @kbd{cat src/main.c}
1359 #include <config.h>
1360 #include <stdio.h>
1363 main (void)
1365   puts ("Hello World!");
1366   puts ("This is " PACKAGE_STRING ".");
1367   return 0;
1369 @end example
1371 @item
1372 @file{README} contains some very limited documentation for our little
1373 package.
1374 @example
1375 ~/amhello % @kbd{cat README}
1376 This is a demonstration package for GNU Automake.
1377 Type `info Automake' to read the Automake manual.
1378 @end example
1380 @item
1381 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1382 instructions for these two directories.
1384 @example
1385 ~/amhello % @kbd{cat src/Makefile.am}
1386 bin_PROGRAMS = hello
1387 hello_SOURCES = main.c
1388 ~/amhello % @kbd{cat Makefile.am}
1389 SUBDIRS = src
1390 dist_doc_DATA = README
1391 @end example
1393 @item
1394 Finally, @file{configure.ac} contains Autoconf instructions to
1395 create the @command{configure} script.
1397 @example
1398 ~/amhello % @kbd{cat configure.ac}
1399 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1400 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1401 AC_PROG_CC
1402 AC_CONFIG_HEADERS([config.h])
1403 AC_CONFIG_FILES([
1404  Makefile
1405  src/Makefile
1407 AC_OUTPUT
1408 @end example
1409 @end itemize
1411 @cindex @command{autoreconf}, example
1413 Once you have these five files, it is time to run the Autotools to
1414 instantiate the build system.  Do this using the @command{autoreconf}
1415 command as follows:
1417 @example
1418 ~/amhello % @kbd{autoreconf --install}
1419 configure.ac: installing `./install-sh'
1420 configure.ac: installing `./missing'
1421 src/Makefile.am: installing `./depcomp'
1422 @end example
1424 At this point the build system is complete.
1426 In addition to the three scripts mentioned in its output, you can see
1427 that @command{autoreconf} created four other files: @file{configure},
1428 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1429 The latter three files are templates that will be adapted to the
1430 system by @command{configure} under the names @file{config.h},
1431 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1433 @example
1434 ~/amhello % @kbd{./configure}
1435 checking for a BSD-compatible install... /usr/bin/install -c
1436 checking whether build environment is sane... yes
1437 checking for gawk... no
1438 checking for mawk... mawk
1439 checking whether make sets $(MAKE)... yes
1440 checking for gcc... gcc
1441 checking for C compiler default output file name... a.out
1442 checking whether the C compiler works... yes
1443 checking whether we are cross compiling... no
1444 checking for suffix of executables...
1445 checking for suffix of object files... o
1446 checking whether we are using the GNU C compiler... yes
1447 checking whether gcc accepts -g... yes
1448 checking for gcc option to accept ISO C89... none needed
1449 checking for style of include used by make... GNU
1450 checking dependency style of gcc... gcc3
1451 configure: creating ./config.status
1452 config.status: creating Makefile
1453 config.status: creating src/Makefile
1454 config.status: creating config.h
1455 config.status: executing depfiles commands
1456 @end example
1458 @trindex distcheck
1459 @cindex @code{distcheck} example
1461 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1462 being created at the end after @command{configure} has probed the
1463 system.  It is now possible to run all the targets we wish
1464 (@pxref{Standard Targets}).  For instance:
1466 @example
1467 ~/amhello % @kbd{make}
1468 @dots{}
1469 ~/amhello % @kbd{src/hello}
1470 Hello World!
1471 This is amhello 1.0.
1472 ~/amhello % @kbd{make distcheck}
1473 @dots{}
1474 =============================================
1475 amhello-1.0 archives ready for distribution:
1476 amhello-1.0.tar.gz
1477 =============================================
1478 @end example
1480 Note that running @command{autoreconf} is only needed initially when
1481 the GNU Build System does not exist.  When you later change some
1482 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1483 relevant part of the build system will be regenerated automatically
1484 when you execute @command{make}.
1486 @command{autoreconf} is a script that calls @command{autoconf},
1487 @command{automake}, and a bunch of other commands in the right order.
1488 If you are beginning with these tools, it is not important to figure
1489 out in which order all these tools should be invoked and why.  However,
1490 because Autoconf and Automake have separate manuals, the important
1491 point to understand is that @command{autoconf} is in charge of
1492 creating @file{configure} from @file{configure.ac}, while
1493 @command{automake} is in charge of creating @file{Makefile.in}s from
1494 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1495 direct you to the right manual when seeking answers.
1498 @node amhello Explained
1499 @subsection @file{amhello-1.0} Explained
1501 Let us begin with the contents of @file{configure.ac}.
1503 @example
1504 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1505 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1506 AC_PROG_CC
1507 AC_CONFIG_HEADERS([config.h])
1508 AC_CONFIG_FILES([
1509  Makefile
1510  src/Makefile
1512 AC_OUTPUT
1513 @end example
1515 This file is read by both @command{autoconf} (to create
1516 @file{configure}) and @command{automake} (to create the various
1517 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1518 expanded as shell code to finally form the @file{configure} script.
1519 We will not elaborate on the syntax of this file, because the Autoconf
1520 manual has a whole section about it (@pxref{Writing configure.ac, ,
1521 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1523 The macros prefixed with @code{AC_} are Autoconf macros, documented
1524 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1525 Index, autoconf, The Autoconf Manual}).  The macros that start with
1526 @code{AM_} are Automake macros, documented later in this manual
1527 (@pxref{Macro Index}).
1529 The first two lines of @file{configure.ac} initialize Autoconf and
1530 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1531 its version number, and a contact address for bug-reports about the
1532 package (this address is output at the end of @code{./configure
1533 --help}, for instance).  When adapting this setup to your own package,
1534 by all means please do not blindly copy Automake's address: use the
1535 mailing list of your package, or your own mail address.
1537 @opindex -Wall
1538 @opindex -Werror
1539 @opindex foreign
1541 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1542 @command{automake} (@pxref{Options}).  @option{-Wall} and
1543 @option{-Werror} ask @command{automake} to turn on all warnings and
1544 report them as errors.  We are speaking of @strong{Automake} warnings
1545 here, such as dubious instructions in @file{Makefile.am}.  This has
1546 absolutely nothing to do with how the compiler will be called, even
1547 though it may support options with similar names.  Using @option{-Wall
1548 -Werror} is a safe setting when starting to work on a package: you do
1549 not want to miss any issues.  Later you may decide to relax things a
1550 bit.  The @option{foreign} option tells Automake that this package
1551 will not follow the GNU Standards.  GNU packages should always
1552 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1553 etc.  We do not want @command{automake} to complain about these
1554 missing files in our small example.
1556 The @code{AC_PROG_CC} line causes the @command{configure} script to
1557 search for a C compiler and define the variable @code{CC} with its
1558 name.  The @file{src/Makefile.in} file generated by Automake uses the
1559 variable @code{CC} to build @file{hello}, so when @command{configure}
1560 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1561 @code{CC} with the value it has found.  If Automake is asked to create
1562 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1563 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1565 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1566 @command{configure} script to create a @file{config.h} file gathering
1567 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1568 case, the @code{AC_INIT} macro already defined a few of them.  Here
1569 is an excerpt of @file{config.h} after @command{configure} has run:
1571 @smallexample
1572 @dots{}
1573 /* Define to the address where bug reports for this package should be sent. */
1574 #define PACKAGE_BUGREPORT "bug-automake@@gnu.org"
1576 /* Define to the full name and version of this package. */
1577 #define PACKAGE_STRING "amhello 1.0"
1578 @dots{}
1579 @end smallexample
1581 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1582 it can use @code{PACKAGE_STRING}.  In a real-world project,
1583 @file{config.h} can grow really big, with one @samp{#define} per
1584 feature probed on the system.
1586 The @code{AC_CONFIG_FILES} macro declares the list of files that
1587 @command{configure} should create from their @file{*.in} templates.
1588 Automake also scans this list to find the @file{Makefile.am} files it must
1589 process.  (This is important to remember: when adding a new directory
1590 to your project, you should add its @file{Makefile} to this list,
1591 otherwise Automake will never process the new @file{Makefile.am} you
1592 wrote in that directory.)
1594 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1595 produces the part of the script in charge of creating the files
1596 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1598 @cindex @command{autoscan}
1600 When starting a new project, we suggest you start with such a simple
1601 @file{configure.ac}, and gradually add the other tests it requires.
1602 The command @command{autoscan} can also suggest a few of the tests
1603 your package may need (@pxref{autoscan Invocation, , Using
1604 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1605 Autoconf Manual}).
1607 @cindex @file{Makefile.am}, Hello World
1609 We now turn to @file{src/Makefile.am}.  This file contains
1610 Automake instructions to build and install @file{hello}.
1612 @example
1613 bin_PROGRAMS = hello
1614 hello_SOURCES = main.c
1615 @end example
1617 A @file{Makefile.am} has the same syntax as an ordinary
1618 @file{Makefile}.  When @command{automake} processes a
1619 @file{Makefile.am} it copies the entire file into the output
1620 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1621 @command{configure}) but will react to certain variable definitions
1622 by generating some build rules and other variables.
1623 Often @file{Makefile.am}s contain only a list of variable definitions as
1624 above, but they can also contain other variable and rule definitions that
1625 @command{automake} will pass along without interpretation.
1627 Variables that end with @code{_PROGRAMS} are special variables
1628 that list programs that the resulting @file{Makefile} should build.
1629 In Automake speak, this @code{_PROGRAMS} suffix is called a
1630 @dfn{primary}; Automake recognizes other primaries such as
1631 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1632 to different types of files.
1634 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1635 @command{automake} that the resulting programs should be installed in
1636 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1637 to denote destination directories and allow users to customize these
1638 locations (@pxref{Standard Directory Variables}).  Any such directory
1639 variable can be put in front of a primary (omitting the @code{dir}
1640 suffix) to tell @command{automake} where to install the listed files.
1642 Programs need to be built from source files, so for each program
1643 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1644 @command{automake} will look for another variable named
1645 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1646 than one source file: they will all be compiled and linked together.
1648 Automake also knows that source files need to be distributed when
1649 creating a tarball (unlike built programs).  So a side-effect of this
1650 @code{hello_SOURCES} declaration is that @file{main.c} will be
1651 part of the tarball created by @code{make dist}.
1653 Finally here are some explanations regarding the top-level
1654 @file{Makefile.am}.
1656 @example
1657 SUBDIRS = src
1658 dist_doc_DATA = README
1659 @end example
1661 @code{SUBDIRS} is a special variable listing all directories that
1662 @command{make} should recurse into before processing the current
1663 directory.  So this line is responsible for @command{make} building
1664 @file{src/hello} even though we run it from the top-level.  This line
1665 also causes @code{make install} to install @file{src/hello} before
1666 installing @file{README} (not that this order matters).
1668 The line @code{dist_doc_DATA = README} causes @file{README} to be
1669 distributed and installed in @var{docdir}.  Files listed with the
1670 @code{_DATA} primary are not automatically part of the tarball built
1671 with @code{make dist}, so we add the @code{dist_} prefix so they get
1672 distributed.  However, for @file{README} it would not have been
1673 necessary: @command{automake} automatically distributes any
1674 @file{README} file it encounters (the list of other files
1675 automatically distributed is presented by @code{automake --help}).
1676 The only important effect of this second line is therefore to install
1677 @file{README} during @code{make install}.
1680 @node Generalities
1681 @chapter General ideas
1683 The following sections cover a few basic ideas that will help you
1684 understand how Automake works.
1686 @menu
1687 * General Operation::           General operation of Automake
1688 * Strictness::                  Standards conformance checking
1689 * Uniform::                     The Uniform Naming Scheme
1690 * Canonicalization::            How derived variables are named
1691 * User Variables::              Variables reserved for the user
1692 * Auxiliary Programs::          Programs automake might require
1693 @end menu
1696 @node General Operation
1697 @section General Operation
1699 Automake works by reading a @file{Makefile.am} and generating a
1700 @file{Makefile.in}.  Certain variables and rules defined in the
1701 @file{Makefile.am} instruct Automake to generate more specialized code;
1702 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1703 for compiling and linking programs to be generated.
1705 @cindex Non-standard targets
1706 @cindex @code{cvs-dist}, non-standard example
1707 @trindex cvs-dist
1708 @trindex git-dist
1710 The variable definitions and rules in the @file{Makefile.am} are
1711 copied verbatim into the generated file.  This allows you to add
1712 arbitrary code into the generated @file{Makefile.in}.  For instance,
1713 the Automake distribution includes a non-standard rule for the
1714 @code{git-dist} target, which the Automake maintainer uses to make
1715 distributions from his source control system.
1717 @cindex GNU make extensions
1719 Note that most GNU make extensions are not recognized by Automake.  Using
1720 such extensions in a @file{Makefile.am} will lead to errors or confusing
1721 behavior.
1723 @cindex Append operator
1724 @cmindex +=
1725 A special exception is that the GNU make append operator, @samp{+=}, is
1726 supported.  This operator appends its right hand argument to the variable
1727 specified on the left.  Automake will translate the operator into
1728 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1730 Automake tries to keep comments grouped with any adjoining rules or
1731 variable definitions.
1733 @cindex Make targets, overriding
1734 @cindex Make rules, overriding
1735 @cindex Overriding make rules
1736 @cindex Overriding make targets
1738 A rule defined in @file{Makefile.am} generally overrides any such
1739 rule of a similar name that would be automatically generated by
1740 @command{automake}.  Although this is a supported feature, it is generally
1741 best to avoid making use of it, as sometimes the generated rules are
1742 very particular.
1744 @cindex Variables, overriding
1745 @cindex Overriding make variables
1747 Similarly, a variable defined in @file{Makefile.am} or
1748 @code{AC_SUBST}ed from @file{configure.ac} will override any
1749 definition of the variable that @command{automake} would ordinarily
1750 create.  This feature is more often useful than the ability to
1751 override a rule.  Be warned that many of the variables generated by
1752 @command{automake} are considered to be for internal use only, and their
1753 names might change in future releases.
1755 @cindex Recursive operation of Automake
1756 @cindex Automake, recursive operation
1757 @cindex Example of recursive operation
1759 When examining a variable definition, Automake will recursively examine
1760 variables referenced in the definition.  For example, if Automake is
1761 looking at the content of @code{foo_SOURCES} in this snippet
1763 @example
1764 xs = a.c b.c
1765 foo_SOURCES = c.c $(xs)
1766 @end example
1768 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1769 contents of @code{foo_SOURCES}.
1771 @cindex @code{##} (special Automake comment)
1772 @cindex Special Automake comment
1773 @cindex Comment, special to Automake
1775 Automake also allows a form of comment that is @emph{not} copied into
1776 the output; all lines beginning with @samp{##} (leading spaces allowed)
1777 are completely ignored by Automake.
1779 It is customary to make the first line of @file{Makefile.am} read:
1781 @cindex Makefile.am, first line
1782 @cindex First line of Makefile.am
1784 @example
1785 ## Process this file with automake to produce Makefile.in
1786 @end example
1788 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1789 @c I don't know quite what to say.
1791 @c FIXME document customary ordering of Makefile.am here!
1794 @node Strictness
1795 @section Strictness
1797 @cindex Non-GNU packages
1799 While Automake is intended to be used by maintainers of GNU packages, it
1800 does make some effort to accommodate those who wish to use it, but do
1801 not want to use all the GNU conventions.
1803 @cindex Strictness, defined
1804 @cindex Strictness, @option{foreign}
1805 @cindex @option{foreign} strictness
1806 @cindex Strictness, @option{gnu}
1807 @cindex @option{gnu} strictness
1808 @cindex Strictness, @option{gnits}
1809 @cindex @option{gnits} strictness
1811 To this end, Automake supports three levels of @dfn{strictness}---the
1812 strictness indicating how stringently Automake should check standards
1813 conformance.
1815 The valid strictness levels are:
1817 @table @option
1818 @item foreign
1819 Automake will check for only those things that are absolutely
1820 required for proper operations.  For instance, whereas GNU standards
1821 dictate the existence of a @file{NEWS} file, it will not be required in
1822 this mode.  The name comes from the fact that Automake is intended to be
1823 used for GNU programs; these relaxed rules are not the standard mode of
1824 operation.
1826 @item gnu
1827 Automake will check---as much as possible---for compliance to the GNU
1828 standards for packages.  This is the default.
1830 @item gnits
1831 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1832 standards}.  These are based on the GNU standards, but are even more
1833 detailed.  Unless you are a Gnits standards contributor, it is
1834 recommended that you avoid this option until such time as the Gnits
1835 standard is actually published (which may never happen).
1836 @end table
1838 @xref{Gnits}, for more information on the precise implications of the
1839 strictness level.
1841 Automake also has a special ``cygnus'' mode that is similar to
1842 strictness but handled differently.  This mode is useful for packages
1843 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
1844 @xref{Cygnus}, for more information on this mode.
1847 @node Uniform
1848 @section The Uniform Naming Scheme
1850 @cindex Uniform naming scheme
1852 Automake variables generally follow a @dfn{uniform naming scheme} that
1853 makes it easy to decide how programs (and other derived objects) are
1854 built, and how they are installed.  This scheme also supports
1855 @command{configure} time determination of what should be built.
1857 @cindex @code{_PROGRAMS} primary variable
1858 @cindex @code{PROGRAMS} primary variable
1859 @cindex Primary variable, @code{PROGRAMS}
1860 @cindex Primary variable, defined
1861 @vindex _PROGRAMS
1863 At @command{make} time, certain variables are used to determine which
1864 objects are to be built.  The variable names are made of several pieces
1865 that are concatenated together.
1867 The piece that tells automake what is being built is commonly called
1868 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1869 list of programs that are to be compiled and linked.
1870 @vindex PROGRAMS
1872 @cindex @code{pkgdatadir}, defined
1873 @cindex @code{pkgincludedir}, defined
1874 @cindex @code{pkglibdir}, defined
1875 @cindex @code{pkglibexecdir}, defined
1877 @vindex pkgdatadir
1878 @vindex pkgincludedir
1879 @vindex pkglibdir
1880 @vindex pkglibexecdir
1882 @cindex @code{PACKAGE}, directory
1883 A different set of names is used to decide where the built objects
1884 should be installed.  These names are prefixes to the primary, and they
1885 indicate which standard directory should be used as the installation
1886 directory.  The standard directory names are given in the GNU standards
1887 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1888 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
1889 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
1890 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
1891 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
1893 @cindex @code{EXTRA_}, prepending
1894 For each primary, there is one additional variable named by prepending
1895 @samp{EXTRA_} to the primary name.  This variable is used to list
1896 objects that may or may not be built, depending on what
1897 @command{configure} decides.  This variable is required because Automake
1898 must statically know the entire list of objects that may be built in
1899 order to generate a @file{Makefile.in} that will work in all cases.
1901 @cindex @code{EXTRA_PROGRAMS}, defined
1902 @cindex Example, @code{EXTRA_PROGRAMS}
1903 @cindex @command{cpio} example
1905 For instance, @command{cpio} decides at configure time which programs
1906 should be built.  Some of the programs are installed in @code{bindir},
1907 and some are installed in @code{sbindir}:
1909 @example
1910 EXTRA_PROGRAMS = mt rmt
1911 bin_PROGRAMS = cpio pax
1912 sbin_PROGRAMS = $(MORE_PROGRAMS)
1913 @end example
1915 Defining a primary without a prefix as a variable, e.g.,
1916 @samp{PROGRAMS}, is an error.
1918 Note that the common @samp{dir} suffix is left off when constructing the
1919 variable names; thus one writes @samp{bin_PROGRAMS} and not
1920 @samp{bindir_PROGRAMS}.
1922 Not every sort of object can be installed in every directory.  Automake
1923 will flag those attempts it finds in error.
1924 Automake will also diagnose obvious misspellings in directory names.
1926 @cindex Extending list of installation directories
1927 @cindex Installation directories, extending list
1929 Sometimes the standard directories---even as augmented by
1930 Automake---are not enough.  In particular it is sometimes useful, for
1931 clarity, to install objects in a subdirectory of some predefined
1932 directory.  To this end, Automake allows you to extend the list of
1933 possible installation directories.  A given prefix (e.g., @samp{zar})
1934 is valid if a variable of the same name with @samp{dir} appended is
1935 defined (e.g., @samp{zardir}).
1937 For instance, the following snippet will install @file{file.xml} into
1938 @samp{$(datadir)/xml}.
1940 @example
1941 xmldir = $(datadir)/xml
1942 xml_DATA = file.xml
1943 @end example
1945 @cindex @samp{noinst_} primary prefix, definition
1946 @vindex noinst_
1948 The special prefix @samp{noinst_} indicates that the objects in question
1949 should be built but not installed at all.  This is usually used for
1950 objects required to build the rest of your package, for instance static
1951 libraries (@pxref{A Library}), or helper scripts.
1953 @cindex @samp{check_} primary prefix, definition
1954 @vindex check_
1956 The special prefix @samp{check_} indicates that the objects in question
1957 should not be built until the @samp{make check} command is run.  Those
1958 objects are not installed either.
1960 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
1961 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
1962 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
1963 @vindex PROGRAMS
1964 @vindex LIBRARIES
1965 @vindex LISP
1966 @vindex PYTHON
1967 @vindex JAVA
1968 @vindex SCRIPTS
1969 @vindex DATA
1970 @vindex HEADERS
1971 @vindex MANS
1972 @vindex TEXINFOS
1974 Some primaries also allow additional prefixes that control other
1975 aspects of @command{automake}'s behavior.  The currently defined prefixes
1976 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
1977 These prefixes are explained later (@pxref{Program and Library Variables})
1978 (@pxref{Man pages}).
1981 @node Canonicalization
1982 @section How derived variables are named
1984 @cindex canonicalizing Automake variables
1986 Sometimes a Makefile variable name is derived from some text the
1987 maintainer supplies.  For instance, a program name listed in
1988 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
1989 variable.  In cases like this, Automake canonicalizes the text, so that
1990 program names and the like do not have to follow Makefile variable naming
1991 rules.  All characters in the name except for letters, numbers, the
1992 strudel (@@), and the underscore are turned into underscores when making
1993 variable references.
1995 For example, if your program is named @file{sniff-glue}, the derived
1996 variable name would be @samp{sniff_glue_SOURCES}, not
1997 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
1998 @file{libmumble++.a} should be listed in the
1999 @samp{libmumble___a_SOURCES} variable.
2001 The strudel is an addition, to make the use of Autoconf substitutions in
2002 variable names less obfuscating.
2005 @node User Variables
2006 @section Variables reserved for the user
2008 @cindex variables, reserved for the user
2009 @cindex user variables
2011 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2012 for the use of the ``user''---the person building the package.  For
2013 instance, @code{CFLAGS} is one such variable.
2015 Sometimes package developers are tempted to set user variables such as
2016 @code{CFLAGS} because it appears to make their job easier.  However,
2017 the package itself should never set a user variable, particularly not
2018 to include switches that are required for proper compilation of the
2019 package.  Since these variables are documented as being for the
2020 package builder, that person rightfully expects to be able to override
2021 any of these variables at build time.
2023 To get around this problem, Automake introduces an automake-specific
2024 shadow variable for each user flag variable.  (Shadow variables are
2025 not introduced for variables like @code{CC}, where they would make no
2026 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2027 user variable's name.  For instance, the shadow variable for
2028 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2029 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2030 files---may adjust these shadow variables however necessary.
2032 @xref{Flag Variables Ordering}, for more discussion about these
2033 variables and how they interact with per-target variables.
2035 @node Auxiliary Programs
2036 @section Programs automake might require
2038 @cindex Programs, auxiliary
2039 @cindex Auxiliary programs
2041 Automake sometimes requires helper programs so that the generated
2042 @file{Makefile} can do its work properly.  There are a fairly large
2043 number of them, and we list them here.
2045 Although all of these files are distributed and installed with
2046 Automake, a couple of them are maintained separately.  The Automake
2047 copies are updated before each release, but we mention the original
2048 source in case you need more recent versions.
2050 @table @code
2051 @item ansi2knr.c
2052 @itemx ansi2knr.1
2053 These two files are used by the obsolete de-ANSI-fication support
2054 (@pxref{ANSI}).
2056 @item compile
2057 This is a wrapper for compilers that do not accept options @option{-c}
2058 and @option{-o} at the same time.  It is only used when absolutely
2059 required.  Such compilers are rare.
2061 @item config.guess
2062 @itemx config.sub
2063 These two programs compute the canonical triplets for the given build,
2064 host, or target architecture.  These programs are updated regularly to
2065 support new architectures and fix probes broken by changes in new
2066 kernel versions.  Each new release of Automake comes with up-to-date
2067 copies of these programs.  If your copy of Automake is getting old,
2068 you are encouraged to fetch the latest versions of these files from
2069 @url{http://savannah.gnu.org/cvs/?group=config} before making a
2070 release.
2072 @item config-ml.in
2073 This file is not a program, it is a @file{configure} fragment used for
2074 multilib support (@pxref{Multilibs}).  This file is maintained in the
2075 GCC tree at @url{http://gcc.gnu.org/svn.html}.
2077 @item depcomp
2078 This program understands how to run a compiler so that it will
2079 generate not only the desired output but also dependency information
2080 that is then used by the automatic dependency tracking feature
2081 (@pxref{Dependencies}).
2083 @item elisp-comp
2084 This program is used to byte-compile Emacs Lisp code.
2086 @item install-sh
2087 This is a replacement for the @command{install} program that works on
2088 platforms where @command{install} is unavailable or unusable.
2090 @item mdate-sh
2091 This script is used to generate a @file{version.texi} file.  It examines
2092 a file and prints some date information about it.
2094 @item missing
2095 This wraps a number of programs that are typically only required by
2096 maintainers.  If the program in question doesn't exist,
2097 @command{missing} prints an informative warning and attempts to fix
2098 things so that the build can continue.
2100 @item mkinstalldirs
2101 This script used to be a wrapper around @samp{mkdir -p}, which is not
2102 portable.  Now we prefer to use @samp{install-sh -d} when configure
2103 finds that @samp{mkdir -p} does not work, this makes one less script to
2104 distribute.
2106 For backward compatibility @file{mkinstalldirs} is still used and
2107 distributed when @command{automake} finds it in a package.  But it is no
2108 longer installed automatically, and it should be safe to remove it.
2110 @item py-compile
2111 This is used to byte-compile Python scripts.
2113 @item symlink-tree
2114 This program duplicates a tree of directories, using symbolic links
2115 instead of copying files.  Such operation is performed when building
2116 multilibs (@pxref{Multilibs}).  This file is maintained in the GCC
2117 tree at @url{http://gcc.gnu.org/svn.html}.
2119 @item texinfo.tex
2120 Not a program, this file is required for @samp{make dvi}, @samp{make
2121 ps} and @samp{make pdf} to work when Texinfo sources are in the
2122 package.  The latest version can be downloaded from
2123 @url{http://www.gnu.org/software/texinfo/}.
2125 @item ylwrap
2126 This program wraps @command{lex} and @command{yacc} to rename their
2127 output files.  It also ensures that, for instance, multiple
2128 @command{yacc} instances can be invoked in a single directory in
2129 parallel.
2131 @end table
2134 @node Examples
2135 @chapter Some example packages
2137 This section contains two small examples.
2139 The first example (@pxref{Complete}) assumes you have an existing
2140 project already using Autoconf, with handcrafted @file{Makefile}s, and
2141 that you want to convert it to using Automake.  If you are discovering
2142 both tools, it is probably better that you look at the Hello World
2143 example presented earlier (@pxref{Hello World}).
2145 The second example (@pxref{true}) shows how two programs can be built
2146 from the same file, using different compilation parameters.  It
2147 contains some technical digressions that are probably best skipped on
2148 first read.
2150 @menu
2151 * Complete::                    A simple example, start to finish
2152 * true::                        Building true and false
2153 @end menu
2156 @node Complete
2157 @section A simple example, start to finish
2159 @cindex Complete example
2161 Let's suppose you just finished writing @code{zardoz}, a program to make
2162 your head float from vortex to vortex.  You've been using Autoconf to
2163 provide a portability framework, but your @file{Makefile.in}s have been
2164 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2166 @cindex @code{AM_INIT_AUTOMAKE}, example use
2168 The first step is to update your @file{configure.ac} to include the
2169 commands that @command{automake} needs.  The way to do this is to add an
2170 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2172 @example
2173 AC_INIT([zardoz], [1.0])
2174 AM_INIT_AUTOMAKE
2175 @dots{}
2176 @end example
2178 Since your program doesn't have any complicating factors (e.g., it
2179 doesn't use @code{gettext}, it doesn't want to build a shared library),
2180 you're done with this part.  That was easy!
2182 @cindex @command{aclocal} program, introduction
2183 @cindex @file{aclocal.m4}, preexisting
2184 @cindex @file{acinclude.m4}, defined
2186 Now you must regenerate @file{configure}.  But to do that, you'll need
2187 to tell @command{autoconf} how to find the new macro you've used.  The
2188 easiest way to do this is to use the @command{aclocal} program to
2189 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2190 already have an @file{aclocal.m4}, because you had to write some hairy
2191 macros for your program.  The @command{aclocal} program lets you put
2192 your own macros into @file{acinclude.m4}, so simply rename and then
2193 run:
2195 @example
2196 mv aclocal.m4 acinclude.m4
2197 aclocal
2198 autoconf
2199 @end example
2201 @cindex @command{zardoz} example
2203 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2204 Since @code{zardoz} is a user program, you want to install it where the
2205 rest of the user programs go: @code{bindir}.  Additionally,
2206 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2207 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2208 @samp{$(LIBOBJS)}.  So here's what you'd write:
2210 @example
2211 bin_PROGRAMS = zardoz
2212 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2213 zardoz_LDADD = $(LIBOBJS)
2215 info_TEXINFOS = zardoz.texi
2216 @end example
2218 Now you can run @samp{automake --add-missing} to generate your
2219 @file{Makefile.in} and grab any auxiliary files you might need, and
2220 you're done!
2223 @node true
2224 @section Building true and false
2226 @cindex Example, @command{false} and @command{true}
2227 @cindex @command{false} Example
2228 @cindex @command{true} Example
2230 Here is another, trickier example.  It shows how to generate two
2231 programs (@code{true} and @code{false}) from the same source file
2232 (@file{true.c}).  The difficult part is that each compilation of
2233 @file{true.c} requires different @code{cpp} flags.
2235 @example
2236 bin_PROGRAMS = true false
2237 false_SOURCES =
2238 false_LDADD = false.o
2240 true.o: true.c
2241         $(COMPILE) -DEXIT_CODE=0 -c true.c
2243 false.o: true.c
2244         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2245 @end example
2247 Note that there is no @code{true_SOURCES} definition.  Automake will
2248 implicitly assume that there is a source file named @file{true.c}, and
2249 define rules to compile @file{true.o} and link @file{true}.  The
2250 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2251 will override the Automake generated rule to build @file{true.o}.
2253 @code{false_SOURCES} is defined to be empty---that way no implicit value
2254 is substituted.  Because we have not listed the source of
2255 @file{false}, we have to tell Automake how to link the program.  This is
2256 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2257 variable, holding the dependencies of the @file{false} target will be
2258 automatically generated by Automake from the content of
2259 @code{false_LDADD}.
2261 The above rules won't work if your compiler doesn't accept both
2262 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2263 bogus dependency (to avoid problems with a parallel @command{make}):
2265 @example
2266 true.o: true.c false.o
2267         $(COMPILE) -DEXIT_CODE=0 -c true.c
2269 false.o: true.c
2270         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2271 @end example
2273 Also, these explicit rules do not work if the obsolete de-ANSI-fication feature
2274 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
2275 more work:
2277 @example
2278 true_.o: true_.c false_.o
2279         $(COMPILE) -DEXIT_CODE=0 -c true_.c
2281 false_.o: true_.c
2282         $(COMPILE) -DEXIT_CODE=1 -c true_.c && mv true_.o false_.o
2283 @end example
2285 As it turns out, there is also a much easier way to do this same task.
2286 Some of the above techniques are useful enough that we've kept the
2287 example in the manual.  However if you were to build @code{true} and
2288 @code{false} in real life, you would probably use per-program
2289 compilation flags, like so:
2291 @example
2292 bin_PROGRAMS = false true
2294 false_SOURCES = true.c
2295 false_CPPFLAGS = -DEXIT_CODE=1
2297 true_SOURCES = true.c
2298 true_CPPFLAGS = -DEXIT_CODE=0
2299 @end example
2301 In this case Automake will cause @file{true.c} to be compiled twice,
2302 with different flags.  De-ANSI-fication will work automatically.  In
2303 this instance, the names of the object files would be chosen by
2304 automake; they would be @file{false-true.o} and @file{true-true.o}.
2305 (The name of the object files rarely matters.)
2308 @node Invoking Automake
2309 @chapter Creating a @file{Makefile.in}
2311 @cindex Multiple @file{configure.ac} files
2312 @cindex Invoking @command{automake}
2313 @cindex @command{automake}, invoking
2315 To create all the @file{Makefile.in}s for a package, run the
2316 @command{automake} program in the top level directory, with no
2317 arguments.  @command{automake} will automatically find each
2318 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2319 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2320 Note that @command{automake} has a rather simplistic view of what
2321 constitutes a package; it assumes that a package has only one
2322 @file{configure.ac}, at the top.  If your package has multiple
2323 @file{configure.ac}s, then you must run @command{automake} in each
2324 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2325 on Autoconf's @command{autoreconf}, which is able to recurse your
2326 package tree and run @command{automake} where appropriate.)
2328 You can optionally give @command{automake} an argument; @file{.am} is
2329 appended to the argument and the result is used as the name of the
2330 input file.  This feature is generally only used to automatically
2331 rebuild an out-of-date @file{Makefile.in}.  Note that
2332 @command{automake} must always be run from the topmost directory of a
2333 project, even if being used to regenerate the @file{Makefile.in} in
2334 some subdirectory.  This is necessary because @command{automake} must
2335 scan @file{configure.ac}, and because @command{automake} uses the
2336 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2337 behavior in some cases.
2339 @vindex AUTOCONF
2340 Automake will run @command{autoconf} to scan @file{configure.ac} and
2341 its dependencies (i.e., @file{aclocal.m4} and any included file),
2342 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2343 an @env{AUTOCONF} variable in your environment it will be used
2344 instead of @command{autoconf}, this allows you to select a particular
2345 version of Autoconf.  By the way, don't misunderstand this paragraph:
2346 @command{automake} runs @command{autoconf} to @strong{scan} your
2347 @file{configure.ac}, this won't build @file{configure} and you still
2348 have to run @command{autoconf} yourself for this purpose.
2350 @cindex @command{automake} options
2351 @cindex Options, @command{automake}
2352 @cindex Strictness, command line
2354 @command{automake} accepts the following options:
2356 @cindex Extra files distributed with Automake
2357 @cindex Files distributed with Automake
2358 @cindex @file{config.guess}
2360 @table @code
2361 @item -a
2362 @itemx --add-missing
2363 @opindex -a
2364 @opindex --add-missing
2365 Automake requires certain common files to exist in certain situations;
2366 for instance, @file{config.guess} is required if @file{configure.ac} runs
2367 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2368 files (@pxref{Auxiliary Programs}); this option will cause the missing
2369 ones to be automatically added to the package, whenever possible.  In
2370 general if Automake tells you a file is missing, try using this option.
2371 By default Automake tries to make a symbolic link pointing to its own
2372 copy of the missing file; this can be changed with @option{--copy}.
2374 Many of the potentially-missing files are common scripts whose
2375 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2376 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2377 file is considered missing, and where the missing file is added
2378 (@pxref{Optional}).
2380 @item --libdir=@var{dir}
2381 @opindex --libdir
2382 Look for Automake data files in directory @var{dir} instead of in the
2383 installation directory.  This is typically used for debugging.
2385 @item -c
2386 @opindex -c
2387 @itemx --copy
2388 @opindex --copy
2389 When used with @option{--add-missing}, causes installed files to be
2390 copied.  The default is to make a symbolic link.
2392 @item --cygnus
2393 @opindex --cygnus
2394 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2395 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2397 @item -f
2398 @opindex -f
2399 @itemx --force-missing
2400 @opindex --force-missing
2401 When used with @option{--add-missing}, causes standard files to be reinstalled
2402 even if they already exist in the source tree.  This involves removing
2403 the file from the source tree before creating the new symlink (or, with
2404 @option{--copy}, copying the new file).
2406 @item --foreign
2407 @opindex --foreign
2408 Set the global strictness to @option{foreign}.  For more information, see
2409 @ref{Strictness}.
2411 @item --gnits
2412 @opindex --gnits
2413 Set the global strictness to @option{gnits}.  For more information, see
2414 @ref{Gnits}.
2416 @item --gnu
2417 @opindex --gnu
2418 Set the global strictness to @option{gnu}.  For more information, see
2419 @ref{Gnits}.  This is the default strictness.
2421 @item --help
2422 @opindex --help
2423 Print a summary of the command line options and exit.
2425 @item -i
2426 @itemx --ignore-deps
2427 @opindex -i
2428 This disables the dependency tracking feature in generated
2429 @file{Makefile}s; see @ref{Dependencies}.
2431 @item --include-deps
2432 @opindex --include-deps
2433 This enables the dependency tracking feature.  This feature is enabled
2434 by default.  This option is provided for historical reasons only and
2435 probably should not be used.
2437 @item --no-force
2438 @opindex --no-force
2439 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2440 @file{configure.ac}.  This option causes it to only update those
2441 @file{Makefile.in}s that are out of date with respect to one of their
2442 dependents.
2444 @item -o @var{dir}
2445 @itemx --output-dir=@var{dir}
2446 @opindex -o
2447 @opindex --output-dir
2448 Put the generated @file{Makefile.in} in the directory @var{dir}.
2449 Ordinarily each @file{Makefile.in} is created in the directory of the
2450 corresponding @file{Makefile.am}.  This option is deprecated and will be
2451 removed in a future release.
2453 @item -v
2454 @itemx --verbose
2455 @opindex -v
2456 @opindex --verbose
2457 Cause Automake to print information about which files are being read or
2458 created.
2460 @item --version
2461 @opindex --version
2462 Print the version number of Automake and exit.
2464 @item -W CATEGORY
2465 @item --warnings=@var{category}
2466 @opindex -W
2467 @opindex --warnings
2468 Output warnings falling in @var{category}.  @var{category} can be
2469 one of:
2470 @table @code
2471 @item gnu
2472 warnings related to the GNU Coding Standards
2473 (@pxref{Top, , , standards, The GNU Coding Standards}).
2474 @item obsolete
2475 obsolete features or constructions
2476 @item override
2477 user redefinitions of Automake rules or variables
2478 @item portability
2479 portability issues (e.g., use of @command{make} features that are
2480 known to be not portable)
2481 @item syntax
2482 weird syntax, unused variables, typos
2483 @item unsupported
2484 unsupported or incomplete features
2485 @item all
2486 all the warnings
2487 @item none
2488 turn off all the warnings
2489 @item error
2490 treat warnings as errors
2491 @end table
2493 A category can be turned off by prefixing its name with @samp{no-}.  For
2494 instance, @option{-Wno-syntax} will hide the warnings about unused
2495 variables.
2497 The categories output by default are @samp{syntax} and
2498 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2499 are enabled in @option{--gnu} and @option{--gnits} strictness.
2501 @vindex WARNINGS
2502 The environment variable @env{WARNINGS} can contain a comma separated
2503 list of categories to enable.  It will be taken into account before the
2504 command-line switches, this way @option{-Wnone} will also ignore any
2505 warning category enabled by @env{WARNINGS}.  This variable is also used
2506 by other tools like @command{autoconf}; unknown categories are ignored
2507 for this reason.
2509 @end table
2512 @node configure
2513 @chapter Scanning @file{configure.ac}
2515 @cindex @file{configure.ac}, scanning
2516 @cindex Scanning @file{configure.ac}
2518 Automake scans the package's @file{configure.ac} to determine certain
2519 information about the package.  Some @command{autoconf} macros are required
2520 and some variables must be defined in @file{configure.ac}.  Automake
2521 will also use information from @file{configure.ac} to further tailor its
2522 output.
2524 Automake also supplies some Autoconf macros to make the maintenance
2525 easier.  These macros can automatically be put into your
2526 @file{aclocal.m4} using the @command{aclocal} program.
2528 @menu
2529 * Requirements::                Configuration requirements
2530 * Optional::                    Other things Automake recognizes
2531 * Invoking aclocal::            Auto-generating aclocal.m4
2532 * Macros::                      Autoconf macros supplied with Automake
2533 @end menu
2536 @node Requirements
2537 @section Configuration requirements
2539 @cindex Automake requirements
2540 @cindex Requirements of Automake
2542 @acindex AM_INIT_AUTOMAKE
2543 The one real requirement of Automake is that your @file{configure.ac}
2544 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2545 required for proper Automake operation (@pxref{Macros}).
2547 Here are the other macros that Automake requires but which are not run
2548 by @code{AM_INIT_AUTOMAKE}:
2550 @table @code
2551 @item AC_CONFIG_FILES
2552 @itemx AC_OUTPUT
2553 @acindex AC_CONFIG_FILES
2554 @acindex AC_OUTPUT
2555 These two macros are usually invoked as follows near the end of
2556 @file{configure.ac}.
2558 @example
2559 @dots{}
2560 AC_CONFIG_FILES([
2561   Makefile
2562   doc/Makefile
2563   src/Makefile
2564   src/lib/Makefile
2565   @dots{}
2567 AC_OUTPUT
2568 @end example
2570 Automake uses these to determine which files to create (@pxref{Output, ,
2571 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2572 is considered to be an Automake generated @file{Makefile} if there
2573 exists a file with the same name and the @file{.am} extension appended.
2574 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2575 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2577 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2579 @example
2580 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2581 @end example
2583 @noindent
2584 @command{automake} will generate the first @file{.in} input file for
2585 which a @file{.am} file exists.  If no such file exists the output
2586 file is not considered to be generated by Automake.
2588 Files created by @code{AC_CONFIG_FILES}, be they Automake
2589 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2590 Their inputs are automatically distributed, except for inputs that
2591 turn out the be outputs of prior @code{AC_CONFIG_FILES} commands.
2592 Finally, rebuild rules are generated in the Automake @file{Makefile}
2593 existing in the subdirectory of the output file, if there is one, or
2594 in the top-level @file{Makefile} otherwise.
2596 The above machinery (cleaning, distributing, and rebuilding) works
2597 fine if the @code{AC_CONFIG_FILES} specifications contain only
2598 literals.  If part of the specification uses shell variables,
2599 @command{automake} will not be able to fulfill this setup, and you will
2600 have to complete the missing bits by hand.  For instance, on
2602 @example
2603 file=input
2604 @dots{}
2605 AC_CONFIG_FILES([output:$file],, [file=$file])
2606 @end example
2608 @noindent
2609 @command{automake} will output rules to clean @file{output}, and
2610 rebuild it.  However the rebuild rule will not depend on @file{input},
2611 and this file will not be distributed either.  (You must add
2612 @samp{EXTRA_DIST = input} to your @file{Makefile} if @file{input} is a
2613 source file.)
2615 Similarly
2617 @example
2618 file=output
2619 file2=out:in
2620 @dots{}
2621 AC_CONFIG_FILES([$file:input],, [file=$file])
2622 AC_CONFIG_FILES([$file2],, [file2=$file2])
2623 @end example
2625 @noindent
2626 will only cause @file{input} to be distributed.  No file will be
2627 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2628 yourself), and no rebuild rule will be output.
2630 Obviously @command{automake} cannot guess what value @samp{$file} is
2631 going to hold later when @file{configure} is run, and it cannot use
2632 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2633 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2634 that is compatible with @command{make}'s syntax) and furthermore use
2635 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2636 @file{Makefile}, then @command{automake} will be able to use
2637 @samp{$@{file@}} to generate all these rules.  For instance, here is
2638 how the Automake package itself generates versioned scripts for its
2639 test suite:
2641 @example
2642 AC_SUBST([APIVERSION], @dots{})
2643 @dots{}
2644 AC_CONFIG_FILES(
2645   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2646   [chmod +x tests/aclocal-$@{APIVERSION@}],
2647   [APIVERSION=$APIVERSION])
2648 AC_CONFIG_FILES(
2649   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2650   [chmod +x tests/automake-$@{APIVERSION@}])
2651 @end example
2653 @noindent
2654 Here cleaning, distributing, and rebuilding are done automatically,
2655 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2657 Note that you should not use shell variables to declare
2658 @file{Makefile} files for which @command{automake} must create
2659 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2660 @command{automake} needs to know the file name when it runs in order
2661 to check whether @file{Makefile.am} exists.  (In the very hairy case
2662 that your setup requires such use of variables, you will have to tell
2663 Automake which @file{Makefile.in}s to generate on the command-line.)
2665 It is possible to let @command{automake} emit conditional rules for
2666 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2667 (@pxref{Optional}).
2669 To summarize:
2670 @itemize @bullet
2671 @item
2672 Use literals for @file{Makefile}s, and for other files whenever possible.
2673 @item
2674 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2675 for files that @command{automake} should ignore.
2676 @item
2677 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2678 that @command{automake} should not ignore.
2679 @end itemize
2681 @end table
2684 @node Optional
2685 @section Other things Automake recognizes
2687 @cindex Macros Automake recognizes
2688 @cindex Recognized macros by Automake
2690 Every time Automake is run it calls Autoconf to trace
2691 @file{configure.ac}.  This way it can recognize the use of certain
2692 macros and tailor the generated @file{Makefile.in} appropriately.
2693 Currently recognized macros and their effects are:
2695 @ftable @code
2696 @item AC_CANONICAL_BUILD
2697 @itemx AC_CANONICAL_HOST
2698 @itemx AC_CANONICAL_TARGET
2699 @vindex build_triplet
2700 @vindex host_triplet
2701 @vindex target_triplet
2702 Automake will ensure that @file{config.guess} and @file{config.sub}
2703 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2704 @code{host_triplet} and @code{target_triplet} are introduced.  See
2705 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2706 The Autoconf Manual}.
2708 @item AC_CONFIG_AUX_DIR
2709 Automake will look for various helper scripts, such as
2710 @file{install-sh}, in the directory named in this macro invocation.
2711 @c This list is accurate relative to version 1.8
2712 (The full list of scripts is: @file{config.guess}, @file{config.sub},
2713 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
2714 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
2715 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
2716 scripts are always searched for; some scripts will only be sought if the
2717 generated @file{Makefile.in} requires them.
2719 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2720 their standard locations.  For @file{mdate-sh},
2721 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2722 source directory corresponding to the current @file{Makefile.am}.  For
2723 the rest, the standard location is the first one of @file{.}, @file{..},
2724 or @file{../..} (relative to the top source directory) that provides any
2725 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2726 autoconf, The Autoconf Manual}.
2728 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2729 distributed, even if there is no @file{Makefile.am} in this directory.
2731 @item AC_CONFIG_LIBOBJ_DIR
2732 Automake will require the sources file declared with
2733 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2734 macro.
2736 @item AC_CONFIG_HEADERS
2737 Automake will generate rules to rebuild these headers.  Older versions
2738 of Automake required the use of @code{AM_CONFIG_HEADER}
2739 (@pxref{Macros}); this is no longer the case today.
2741 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2742 specification using shell variables will be ignored as far as
2743 cleaning, distributing, and rebuilding is concerned.
2745 @item AC_CONFIG_LINKS
2746 Automake will generate rules to remove @file{configure} generated
2747 links on @samp{make distclean} and to distribute named source files as
2748 part of @samp{make dist}.
2750 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2751 specification using shell variables will be ignored as far as cleaning
2752 and distributing is concerned.  (There is no rebuild rules for links.)
2754 @item AC_LIBOBJ
2755 @itemx AC_LIBSOURCE
2756 @itemx AC_LIBSOURCES
2757 @vindex LIBOBJS
2758 Automake will automatically distribute any file listed in
2759 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2761 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2762 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2763 @file{file.c} will be distributed automatically by Automake.  This
2764 encompasses many macros like @code{AC_FUNC_ALLOCA},
2765 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2767 By the way, direct assignments to @code{LIBOBJS} are no longer
2768 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2769 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2770 autoconf, The Autoconf Manual}.
2772 @item AC_PROG_RANLIB
2773 This is required if any libraries are built in the package.
2774 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2775 Autoconf Manual}.
2777 @item AC_PROG_CXX
2778 This is required if any C++ source is included.  @xref{Particular
2779 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2781 @item AC_PROG_OBJC
2782 This is required if any Objective C source is included.  @xref{Particular
2783 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2785 @item AC_PROG_F77
2786 This is required if any Fortran 77 source is included.  This macro is
2787 distributed with Autoconf version 2.13 and later.  @xref{Particular
2788 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2790 @item AC_F77_LIBRARY_LDFLAGS
2791 This is required for programs and shared libraries that are a mixture of
2792 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
2793 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
2795 @item AC_FC_SRCEXT
2796 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
2797 of files with the respective source extension (@pxref{Fortran Compiler, ,
2798 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
2800 @item AC_PROG_FC
2801 This is required if any Fortran 90/95 source is included.  This macro is
2802 distributed with Autoconf version 2.58 and later.  @xref{Particular
2803 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2805 @item AC_PROG_LIBTOOL
2806 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
2807 Introduction, libtool, The Libtool Manual}).
2809 @item AC_PROG_YACC
2810 @vindex YACC
2811 If a Yacc source file is seen, then you must either use this macro or
2812 define the variable @code{YACC} in @file{configure.ac}.  The former is
2813 preferred (@pxref{Particular Programs, , Particular Program Checks,
2814 autoconf, The Autoconf Manual}).
2816 @item AC_PROG_LEX
2817 If a Lex source file is seen, then this macro must be used.
2818 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2819 Autoconf Manual}.
2821 @item AC_REQUIRE_AUX_FILE
2822 @command{automake} will ensure each file for which this macro is
2823 called exists in the aux directory, and will complain otherwise.  It
2824 will also automatically distribute the file.  This macro should be
2825 used by third-party Autoconf macros that requires some supporting
2826 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
2827 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
2828 The Autoconf Manual}.
2830 @item AC_SUBST
2831 The first argument is automatically defined as a variable in each
2832 generated @file{Makefile.in}.  @xref{Setting Output Variables, , Setting
2833 Output Variables, autoconf, The Autoconf Manual}.
2835 If the Autoconf manual says that a macro calls @code{AC_SUBST} for
2836 @var{var}, or defines the output variable @var{var} then @var{var} will
2837 be defined in each @file{Makefile.in} generated by Automake.
2838 E.g.@: @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and @code{X_LIBS}, so
2839 you can use these variables in any @file{Makefile.am} if
2840 @code{AC_PATH_XTRA} is called.
2842 @item AM_C_PROTOTYPES
2843 This is required when using the obsolete de-ANSI-fication feature; see
2844 @ref{ANSI}.
2846 @item AM_CONDITIONAL
2847 This introduces an Automake conditional (@pxref{Conditionals}).
2849 @item AM_COND_IF
2850 This macro allows @code{automake} to detect subsequent access within
2851 @file{configure.ac} to a conditional previously introduced with
2852 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
2853 (@pxref{Conditionals}).
2855 @item AM_GNU_GETTEXT
2856 This macro is required for packages that use GNU gettext
2857 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
2858 this macro it ensures that the package meets some of gettext's
2859 requirements.
2861 @item AM_GNU_GETTEXT_INTL_SUBDIR
2862 This macro specifies that the @file{intl/} subdirectory is to be built,
2863 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
2864 of @samp{external}.
2866 @item AM_MAINTAINER_MODE(@ovar{default-mode})
2867 @opindex --enable-maintainer-mode
2868 @opindex --disable-maintainer-mode
2869 This macro adds an @option{--enable-maintainer-mode} option to
2870 @command{configure}.  If this is used, @command{automake} will cause
2871 ``maintainer-only'' rules to be turned off by default in the
2872 generated @file{Makefile.in}s, unless @var{default-mode} is
2873 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
2874 conditional, which you can use in your own @file{Makefile.am}.
2875 @xref{maintainer-mode}.
2877 @item m4_include
2878 Files included by @file{configure.ac} using this macro will be
2879 detected by Automake and automatically distributed.  They will also
2880 appear as dependencies in @file{Makefile} rules.
2882 @code{m4_include} is seldom used by @file{configure.ac} authors, but
2883 can appear in @file{aclocal.m4} when @command{aclocal} detects that
2884 some required macros come from files local to your package (as opposed
2885 to macros installed in a system-wide directory, @pxref{Invoking
2886 aclocal}).
2888 @end ftable
2891 @node Invoking aclocal
2892 @section Auto-generating aclocal.m4
2894 @cindex Invoking @command{aclocal}
2895 @cindex @command{aclocal}, Invoking
2897 Automake includes a number of Autoconf macros that can be used in
2898 your package (@pxref{Macros}); some of them are actually required by
2899 Automake in certain situations.  These macros must be defined in your
2900 @file{aclocal.m4}; otherwise they will not be seen by
2901 @command{autoconf}.
2903 The @command{aclocal} program will automatically generate
2904 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
2905 This provides a convenient way to get Automake-provided macros,
2906 without having to search around.  The @command{aclocal} mechanism
2907 allows other packages to supply their own macros (@pxref{Extending
2908 aclocal}).  You can also use it to maintain your own set of custom
2909 macros (@pxref{Local Macros}).
2911 At startup, @command{aclocal} scans all the @file{.m4} files it can
2912 find, looking for macro definitions (@pxref{Macro search path}).  Then
2913 it scans @file{configure.ac}.  Any mention of one of the macros found
2914 in the first step causes that macro, and any macros it in turn
2915 requires, to be put into @file{aclocal.m4}.
2917 @emph{Putting} the file that contains the macro definition into
2918 @file{aclocal.m4} is usually done by copying the entire text of this
2919 file, including unused macro definitions as well as both @samp{#} and
2920 @samp{dnl} comments.  If you want to make a comment that will be
2921 completely ignored by @command{aclocal}, use @samp{##} as the comment
2922 leader.
2924 When a file selected by @command{aclocal} is located in a subdirectory
2925 specified as a relative search path with @command{aclocal}'s @option{-I}
2926 argument, @command{aclocal} assumes the file belongs to the package
2927 and uses @code{m4_include} instead of copying it into
2928 @file{aclocal.m4}.  This makes the package smaller, eases dependency
2929 tracking, and cause the file to be distributed automatically.
2930 (@xref{Local Macros}, for an example.)  Any macro that is found in a
2931 system-wide directory, or via an absolute search path will be copied.
2932 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
2933 some relative directory need to be considered outside the package.
2935 The contents of @file{acinclude.m4}, if this file exists, are also
2936 automatically included in @file{aclocal.m4}.  We recommend against
2937 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
2939 @vindex AUTOM4TE
2940 @cindex autom4te
2941 While computing @file{aclocal.m4}, @command{aclocal} runs
2942 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
2943 autoconf, The Autoconf Manual}) in order to trace the macros that are
2944 really used, and omit from @file{aclocal.m4} all macros that are
2945 mentioned but otherwise unexpanded (this can happen when a macro is
2946 called conditionally).  @command{autom4te} is expected to be in the
2947 @env{PATH}, just as @command{autoconf}.  Its location can be
2948 overridden using the @env{AUTOM4TE} environment variable.
2950 @menu
2951 * aclocal options::             Options supported by aclocal
2952 * Macro search path::           How aclocal finds .m4 files
2953 * Extending aclocal::           Writing your own aclocal macros
2954 * Local Macros::                Organizing local macros
2955 * Serials::                     Serial lines in Autoconf macros
2956 * Future of aclocal::           aclocal's scheduled death
2957 @end menu
2959 @node aclocal options
2960 @subsection aclocal options
2962 @cindex @command{aclocal}, Options
2963 @cindex Options, @command{aclocal}
2965 @command{aclocal} accepts the following options:
2967 @table @code
2968 @item --acdir=@var{dir}
2969 @opindex --acdir
2970 Look for the macro files in @var{dir} instead of the installation
2971 directory.  This is typically used for debugging.
2973 @item --diff[=@var{command}]
2974 @opindex --diff
2975 Run @var{command} on M4 file that would be installed or overwritten
2976 by @option{--install}.  The default @var{command} is @samp{diff -u}.
2977 This option implies @option{--install} and @option{--dry-run}.
2979 @item --dry-run
2980 @opindex --dry-run
2981 Do not actually overwrite (or create) @file{aclocal.m4} and M4
2982 files installed by @option{--install}.
2984 @item --help
2985 @opindex --help
2986 Print a summary of the command line options and exit.
2988 @item -I @var{dir}
2989 @opindex -I
2990 Add the directory @var{dir} to the list of directories searched for
2991 @file{.m4} files.
2993 @item --install
2994 @opindex --install
2995 Install system-wide third-party macros into the first directory
2996 specified with @samp{-I @var{dir}} instead of copying them in the
2997 output file.
2999 @cindex serial number and @option{--install}
3000 When this option is used, and only when this option is used,
3001 @command{aclocal} will also honor @samp{#serial @var{NUMBER}} lines
3002 that appear in macros: an M4 file is ignored if there exists another
3003 M4 file with the same basename and a greater serial number in the
3004 search path (@pxref{Serials}).
3006 @item --force
3007 @opindex --force
3008 Always overwrite the output file.  The default is to overwrite the output
3009 file only when really needed, i.e., when its contents changes or if one
3010 of its dependencies is younger.
3012 This option forces the update of @file{aclocal.m4} (or the file
3013 specified with @file{--output} below) and only this file, it has
3014 absolutely no influence on files that may need to be installed by
3015 @option{--install}.
3017 @item --output=@var{file}
3018 @opindex --output
3019 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3021 @item --print-ac-dir
3022 @opindex --print-ac-dir
3023 Prints the name of the directory that @command{aclocal} will search to
3024 find third-party @file{.m4} files.  When this option is given, normal
3025 processing is suppressed.  This option can be used by a package to
3026 determine where to install a macro file.
3028 @item --verbose
3029 @opindex --verbose
3030 Print the names of the files it examines.
3032 @item --version
3033 @opindex --version
3034 Print the version number of Automake and exit.
3036 @item -W CATEGORY
3037 @item --warnings=@var{category}
3038 @opindex -W
3039 @opindex --warnings
3040 Output warnings falling in @var{category}.  @var{category} can be
3041 one of:
3042 @table @code
3043 @item syntax
3044 dubious syntactic constructs, underquoted macros, unused macros, etc.
3045 @item unsupported
3046 unknown macros
3047 @item all
3048 all the warnings, this is the default
3049 @item none
3050 turn off all the warnings
3051 @item error
3052 treat warnings as errors
3053 @end table
3055 All warnings are output by default.
3057 @vindex WARNINGS
3058 The environment variable @env{WARNINGS} is honored in the same
3059 way as it is for @command{automake} (@pxref{Invoking Automake}).
3061 @end table
3063 @node Macro search path
3064 @subsection Macro search path
3066 @cindex Macro search path
3067 @cindex @command{aclocal} search path
3069 By default, @command{aclocal} searches for @file{.m4} files in the following
3070 directories, in this order:
3072 @table @code
3073 @item @var{acdir-APIVERSION}
3074 This is where the @file{.m4} macros distributed with automake itself
3075 are stored.  @var{APIVERSION} depends on the automake release used;
3076 for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
3078 @item @var{acdir}
3079 This directory is intended for third party @file{.m4} files, and is
3080 configured when @command{automake} itself is built.  This is
3081 @file{@@datadir@@/aclocal/}, which typically
3082 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3083 value of @var{acdir}, use the @option{--print-ac-dir} option
3084 (@pxref{aclocal options}).
3085 @end table
3087 As an example, suppose that @command{automake-1.6.2} was configured with
3088 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3090 @enumerate
3091 @item @file{/usr/local/share/aclocal-1.6/}
3092 @item @file{/usr/local/share/aclocal/}
3093 @end enumerate
3095 As explained in (@pxref{aclocal options}), there are several options that
3096 can be used to change or extend this search path.
3098 @subsubsection Modifying the macro search path: @option{--acdir}
3100 The most erroneous option to modify the search path is
3101 @option{--acdir=@var{dir}}, which changes default directory and
3102 drops the @var{APIVERSION} directory.  For example, if one specifies
3103 @samp{--acdir=/opt/private/}, then the search path becomes:
3105 @enumerate
3106 @item @file{/opt/private/}
3107 @end enumerate
3109 This option, @option{--acdir}, is intended for use by the internal
3110 automake test suite only; it is not ordinarily needed by end-users.
3112 @subsubsection Modifying the macro search path: @samp{-I @var{dir}}
3114 Any extra directories specified using @option{-I} options
3115 (@pxref{aclocal options}) are @emph{prepended} to this search list.  Thus,
3116 @samp{aclocal -I /foo -I /bar} results in the following search path:
3118 @enumerate
3119 @item @file{/foo}
3120 @item @file{/bar}
3121 @item @var{acdir}-@var{APIVERSION}
3122 @item @var{acdir}
3123 @end enumerate
3125 @subsubsection Modifying the macro search path: @file{dirlist}
3126 @cindex @file{dirlist}
3128 There is a third mechanism for customizing the search path.  If a
3129 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3130 contain a list of directory patterns, one per line.  @command{aclocal}
3131 expands these patterns to directory names, and adds them to the search
3132 list @emph{after} all other directories.  @file{dirlist} entries may
3133 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3135 For example, suppose
3136 @file{@var{acdir}/dirlist} contains the following:
3138 @example
3139 /test1
3140 /test2
3141 /test3*
3142 @end example
3144 @noindent
3145 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3146 Then, the search path would be
3148 @c @code looks better than @file here
3149 @enumerate
3150 @item @code{/foo}
3151 @item @code{/bar}
3152 @item @var{acdir}-@var{APIVERSION}
3153 @item @var{acdir}
3154 @item @code{/test1}
3155 @item @code{/test2}
3156 @end enumerate
3158 @noindent
3159 and all directories with path names starting with @code{/test3}.
3161 If the @option{--acdir=@var{dir}} option is used, then @command{aclocal}
3162 will search for the @file{dirlist} file in @var{dir}.  In the
3163 @samp{--acdir=/opt/private/} example above, @command{aclocal} would look
3164 for @file{/opt/private/dirlist}.  Again, however, the @option{--acdir}
3165 option is intended for use by the internal automake test suite only;
3166 @option{--acdir} is not ordinarily needed by end-users.
3168 @file{dirlist} is useful in the following situation: suppose that
3169 @command{automake} version @code{1.6.2} is installed with
3170 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3171 directories are
3173 @c @code looks better than @file here
3174 @enumerate
3175 @item @code{/usr/share/aclocal-1.6/}
3176 @item @code{/usr/share/aclocal/}
3177 @end enumerate
3179 However, suppose further that many packages have been manually
3180 installed on the system, with $prefix=/usr/local, as is typical.  In
3181 that case, many of these ``extra'' @file{.m4} files are in
3182 @file{/usr/local/share/aclocal}.  The only way to force
3183 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3184 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3185 inconvenient.  With @file{dirlist}, one may create a file
3186 @file{/usr/share/aclocal/dirlist} containing only the single line
3188 @example
3189 /usr/local/share/aclocal
3190 @end example
3192 Now, the ``default'' search path on the affected system is
3194 @c @code looks better than @file here
3195 @enumerate
3196 @item @code{/usr/share/aclocal-1.6/}
3197 @item @code{/usr/share/aclocal/}
3198 @item @code{/usr/local/share/aclocal/}
3199 @end enumerate
3201 without the need for @option{-I} options; @option{-I} options can be reserved
3202 for project-specific needs (@file{my-source-dir/m4/}), rather than
3203 using it to work around local system-dependent tool installation
3204 directories.
3206 Similarly, @file{dirlist} can be handy if you have installed a local
3207 copy Automake on your account and want @command{aclocal} to look for
3208 macros installed at other places on the system.
3211 @node Extending aclocal
3212 @subsection Writing your own aclocal macros
3214 @cindex @command{aclocal}, extending
3215 @cindex Extending @command{aclocal}
3217 The @command{aclocal} program doesn't have any built-in knowledge of any
3218 macros, so it is easy to extend it with your own macros.
3220 This can be used by libraries that want to supply their own Autoconf
3221 macros for use by other programs.  For instance, the @command{gettext}
3222 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3223 any package using @command{gettext}.  When the library is installed, it
3224 installs this macro so that @command{aclocal} will find it.
3226 A macro file's name should end in @file{.m4}.  Such files should be
3227 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3229 @example
3230 aclocaldir = $(datadir)/aclocal
3231 aclocal_DATA = mymacro.m4 myothermacro.m4
3232 @end example
3234 @noindent
3235 Please do use @file{$(datadir)/aclocal}, and not something based on
3236 the result of @samp{aclocal --print-ac-dir}.  @xref{Hard-Coded Install
3237 Paths}, for arguments.
3239 A file of macros should be a series of properly quoted
3240 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3241 Autoconf Manual}).  The @command{aclocal} programs also understands
3242 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3243 Autoconf Manual}), so it is safe to put each macro in a separate file.
3244 Each file should have no side effects but macro definitions.
3245 Especially, any call to @code{AC_PREREQ} should be done inside the
3246 defined macro, not at the beginning of the file.
3248 @cindex underquoted @code{AC_DEFUN}
3249 @acindex AC_DEFUN
3250 @acindex AC_PREREQ
3252 Starting with Automake 1.8, @command{aclocal} will warn about all
3253 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3254 lot of people, because @command{aclocal} was not so strict in the past
3255 and many third party macros are underquoted; and we have to apologize
3256 for this temporary inconvenience.  The reason we have to be stricter
3257 is that a future implementation of @command{aclocal} (@pxref{Future of
3258 aclocal}) will have to temporarily include all these third party
3259 @file{.m4} files, maybe several times, including even files that are
3260 not actually needed.  Doing so should alleviate many problems of the
3261 current implementation, however it requires a stricter style from the
3262 macro authors.  Hopefully it is easy to revise the existing macros.
3263 For instance,
3264 @example
3265 # bad style
3266 AC_PREREQ(2.57)
3267 AC_DEFUN(AX_FOOBAR,
3268 [AC_REQUIRE([AX_SOMETHING])dnl
3269 AX_FOO
3270 AX_BAR
3272 @end example
3273 @noindent
3274 should be rewritten as
3275 @example
3276 AC_DEFUN([AX_FOOBAR],
3277 [AC_PREREQ([2.57])dnl
3278 AC_REQUIRE([AX_SOMETHING])dnl
3279 AX_FOO
3280 AX_BAR
3282 @end example
3284 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3285 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
3286 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3287 allows the macro to be redefined or included twice (otherwise this
3288 first argument would be expanded during the second definition).  For
3289 consistency we like to quote even arguments such as @code{2.57} that
3290 do not require it.
3292 If you have been directed here by the @command{aclocal} diagnostic but
3293 are not the maintainer of the implicated macro, you will want to
3294 contact the maintainer of that macro.  Please make sure you have the
3295 last version of the macro and that the problem already hasn't been
3296 reported before doing so: people tend to work faster when they aren't
3297 flooded by mails.
3299 Another situation where @command{aclocal} is commonly used is to
3300 manage macros that are used locally by the package, @ref{Local
3301 Macros}.
3303 @node Local Macros
3304 @subsection Handling Local Macros
3306 Feature tests offered by Autoconf do not cover all needs.  People
3307 often have to supplement existing tests with their own macros, or
3308 with third-party macros.
3310 There are two ways to organize custom macros in a package.
3312 The first possibility (the historical practice) is to list all your
3313 macros in @file{acinclude.m4}.  This file will be included in
3314 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3315 henceforth be visible to @command{autoconf}.  However if it contains
3316 numerous macros, it will rapidly become difficult to maintain, and it
3317 will be almost impossible to share macros between packages.
3319 @vindex ACLOCAL_AMFLAGS
3320 The second possibility, which we do recommend, is to write each macro
3321 in its own file and gather all these files in a directory.  This
3322 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3323 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3324 From the command line, this is done with @samp{aclocal -I m4}.  The
3325 top-level @file{Makefile.am} should also be updated to define
3327 @example
3328 ACLOCAL_AMFLAGS = -I m4
3329 @end example
3331 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3332 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3333 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3334 Using @command{autoreconf} to Update @file{configure} Scripts,
3335 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3336 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3337 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3338 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3339 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3340 the place where Gettext's macros should be installed.  So even if you
3341 do not really care about the rebuild rules, you should define
3342 @code{ACLOCAL_AMFLAGS}.
3344 When @samp{aclocal -I m4} is run, it will build a @file{aclocal.m4}
3345 that @code{m4_include}s any file from @file{m4/} that defines a
3346 required macro.  Macros not found locally will still be searched in
3347 system-wide directories, as explained in @ref{Macro search path}.
3349 Custom macros should be distributed for the same reason that
3350 @file{configure.ac} is: so that other people have all the sources of
3351 your package if they want to work on it.  Actually, this distribution
3352 happens automatically because all @code{m4_include}d files are
3353 distributed.
3355 However there is no consensus on the distribution of third-party
3356 macros that your package may use.  Many libraries install their own
3357 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3358 aclocal}).  For instance, Guile ships with a file called
3359 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3360 be used to define setup compiler and linker flags appropriate for
3361 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3362 cause @command{aclocal} to copy @file{guile.m4} into
3363 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3364 it will not be distributed.  Technically, that means a user who
3365 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3366 This is probably OK, if Guile already is a requirement to build the
3367 package.  However, if Guile is only an optional feature, or if your
3368 package might run on architectures where Guile cannot be installed,
3369 this requirement will hinder development.  An easy solution is to copy
3370 such third-party macros in your local @file{m4/} directory so they get
3371 distributed.
3373 Since Automake 1.10, @command{aclocal} offers an option to copy these
3374 system-wide third-party macros in your local macro directory, solving
3375 the above problem.  Simply use:
3377 @example
3378 ACLOCAL_AMFLAGS = -I m4 --install
3379 @end example
3381 @noindent
3382 With this setup, system-wide macros will be copied to @file{m4/}
3383 the first time you run @command{autoreconf}.  Then the locally
3384 installed macros will have precedence over the system-wide installed
3385 macros each time @command{aclocal} is run again.
3387 One reason why you should keep @option{--install} in the flags even
3388 after the first run is that when you later edit @file{configure.ac}
3389 and depend on a new macro, this macro will be installed in your
3390 @file{m4/} automatically.  Another one is that serial numbers
3391 (@pxref{Serials}) can be used to update the macros in your source tree
3392 automatically when new system-wide versions are installed.  A serial
3393 number should be a single line of the form
3395 @example
3396 #serial @var{NNN}
3397 @end example
3399 @noindent
3400 where @var{NNN} contains only digits and dots.  It should appear in
3401 the M4 file before any macro definition.  It is a good practice to
3402 maintain a serial number for each macro you distribute, even if you do
3403 not use the @option{--install} option of @command{aclocal}: this allows
3404 other people to use it.
3407 @node Serials
3408 @subsection Serial Numbers
3409 @cindex serial numbers in macros
3410 @cindex macro serial numbers
3411 @cindex @code{#serial} syntax
3412 @cindex @command{aclocal} and serial numbers
3414 Because third-party macros defined in @file{*.m4} files are naturally
3415 shared between multiple projects, some people like to version them.
3416 This makes it easier to tell which of two M4 files is newer.  Since at
3417 least 1996, the tradition is to use a @samp{#serial} line for this.
3419 A serial number should be a single line of the form
3421 @example
3422 # serial @var{version}
3423 @end example
3425 @noindent
3426 where @var{version} is a version number containing only digits and
3427 dots.  Usually people use a single integer, and they increment it each
3428 time they change the macro (hence the name of ``serial'').  Such a
3429 line should appear in the M4 file before any macro definition.
3431 The @samp{#} must be the first character on the line,
3432 and it is OK to have extra words after the version, as in
3434 @example
3435 #serial @var{version} @var{garbage}
3436 @end example
3438 Normally these serial numbers are completely ignored by
3439 @command{aclocal} and @command{autoconf}, like any genuine comment.
3440 However when using @command{aclocal}'s @option{--install} feature, these
3441 serial numbers will modify the way @command{aclocal} selects the
3442 macros to install in the package: if two files with the same basename
3443 exists in your search path, and if at least one of them use a
3444 @samp{#serial} line, @command{aclocal} will ignore the file that has
3445 the older @samp{#serial} line (or the file that has none).
3447 Note that a serial number applies to a whole M4 file, not to any macro
3448 it contains.  A file can contains multiple macros, but only one
3449 serial.
3451 Here is a use case that illustrate the use of @option{--install} and
3452 its interaction with serial numbers.  Let's assume we maintain a
3453 package called MyPackage, the @file{configure.ac} of which requires a
3454 third-party macro @code{AX_THIRD_PARTY} defined in
3455 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3457 @example
3458 # serial 1
3459 AC_DEFUN([AX_THIRD_PARTY], [...])
3460 @end example
3462 MyPackage uses an @file{m4/} directory to store local macros as
3463 explained in @ref{Local Macros}, and has
3465 @example
3466 ACLOCAL_AMFLAGS = -I m4 --install
3467 @end example
3469 @noindent
3470 in its top-level @file{Makefile.am}.
3472 Initially the @file{m4/} directory is empty.  The first time we run
3473 @command{autoreconf}, it will fetch the options to pass to
3474 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3475 --install}.  @command{aclocal} will notice that
3477 @itemize @bullet
3478 @item
3479 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3480 @item
3481 No local macros define @code{AX_THIRD_PARTY}
3482 @item
3483 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3484 with serial 1.
3485 @end itemize
3487 @noindent
3488 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3489 and @command{aclocal} was given the @option{--install} option, it will
3490 copy this file in @file{m4/thirdparty.m4}, and output an
3491 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3493 The next time @samp{aclocal -I m4 --install} is run (either via
3494 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3495 rules) something different happens.  @command{aclocal} notices that
3497 @itemize @bullet
3498 @item
3499 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3500 @item
3501 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3502 with serial 1.
3503 @item
3504 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3505 with serial 1.
3506 @end itemize
3508 @noindent
3509 Because both files have the same serial number, @command{aclocal} uses
3510 the first it found in its search path order (@pxref{Macro search
3511 path}).  @command{aclocal} therefore ignores
3512 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3513 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3515 Local directories specified with @option{-I} are always searched before
3516 system-wide directories, so a local file will always be preferred to
3517 the system-wide file in case of equal serial numbers.
3519 Now suppose the system-wide third-party macro is changed.  This can
3520 happen if the package installing this macro is updated.  Let's suppose
3521 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3522 --install} is run the situation is the following:
3524 @itemize @bullet
3525 @item
3526 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3527 @item
3528 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3529 with serial 1.
3530 @item
3531 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3532 with serial 2.
3533 @end itemize
3535 @noindent
3536 When @command{aclocal} sees a greater serial number, it immediately
3537 forgets anything it knows from files that have the same basename and a
3538 smaller serial number.  So after it has found
3539 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3540 @command{aclocal} will proceed as if it had never seen
3541 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3542 to that at the beginning of our example, where no local file defined
3543 the macro.  @command{aclocal} will install the new version of the
3544 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3545 version.  MyPackage just had its macro updated as a side effect of
3546 running @command{aclocal}.
3548 If you are leery of letting @command{aclocal} update your local macro,
3549 you can run @samp{aclocal -I m4 --diff} to review the changes
3550 @samp{aclocal -I m4 --install} would perform on these macros.
3552 Finally, note that the @option{--force} option of @command{aclocal} has
3553 absolutely no effect on the files installed by @option{--install}.  For
3554 instance, if you have modified your local macros, do not expect
3555 @option{--install --force} to replace the local macros by their
3556 system-wide versions.  If you want to do so, simply erase the local
3557 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3560 @node Future of aclocal
3561 @subsection The Future of @command{aclocal}
3562 @cindex @command{aclocal}'s scheduled death
3564 @command{aclocal} is expected to disappear.  This feature really
3565 should not be offered by Automake.  Automake should focus on
3566 generating @file{Makefile}s; dealing with M4 macros really is
3567 Autoconf's job.  That some people install Automake just to use
3568 @command{aclocal}, but do not use @command{automake} otherwise is an
3569 indication of how that feature is misplaced.
3571 The new implementation will probably be done slightly differently.
3572 For instance, it could enforce the @file{m4/}-style layout discussed in
3573 @ref{Local Macros}.
3575 We have no idea when and how this will happen.  This has been
3576 discussed several times in the past, but someone still has to commit
3577 itself to that non-trivial task.
3579 From the user point of view, @command{aclocal}'s removal might turn
3580 out to be painful.  There is a simple precaution that you may take to
3581 make that switch more seamless: never call @command{aclocal} yourself.
3582 Keep this guy under the exclusive control of @command{autoreconf} and
3583 Automake's rebuild rules.  Hopefully you won't need to worry about
3584 things breaking, when @command{aclocal} disappears, because everything
3585 will have been taken care of.  If otherwise you used to call
3586 @command{aclocal} directly yourself or from some script, you will
3587 quickly notice the change.
3589 Many packages come with a script called @file{bootstrap.sh} or
3590 @file{autogen.sh}, that will just call @command{aclocal},
3591 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3592 @command{autoconf}, @command{autoheader}, and @command{automake} in
3593 the right order.  Actually this is precisely what @command{autoreconf}
3594 can do for you.  If your package has such a @file{bootstrap.sh} or
3595 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3596 should simplify its logic a lot (less things to maintain, yum!), it's
3597 even likely you will not need the script anymore, and more to the point
3598 you will not call @command{aclocal} directly anymore.
3600 For the time being, third-party packages should continue to install
3601 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3602 is replaced by another tool it might make sense to rename the
3603 directory, but supporting @file{/usr/share/aclocal/} for backward
3604 compatibility should be really easy provided all macros are properly
3605 written (@pxref{Extending aclocal}).
3609 @node Macros
3610 @section Autoconf macros supplied with Automake
3612 Automake ships with several Autoconf macros that you can use from your
3613 @file{configure.ac}.  When you use one of them it will be included by
3614 @command{aclocal} in @file{aclocal.m4}.
3616 @menu
3617 * Public macros::               Macros that you can use.
3618 * Obsolete macros::             Macros that you should stop using.
3619 * Private macros::              Macros that you should not use.
3620 @end menu
3622 @c consider generating the following subsections automatically from m4 files.
3624 @node Public macros
3625 @subsection Public macros
3627 @table @code
3629 @item AM_ENABLE_MULTILIB
3630 @acindex AM_ENABLE_MULTILIB
3631 This is used when a ``multilib'' library is being built.  The first
3632 optional argument is the name of the @file{Makefile} being generated; it
3633 defaults to @samp{Makefile}.  The second option argument is used to find
3634 the top source directory; it defaults to the empty string (generally
3635 this should not be used unless you are familiar with the internals).
3636 @xref{Multilibs}.
3638 @item AM_INIT_AUTOMAKE([OPTIONS])
3639 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
3640 @acindex AM_INIT_AUTOMAKE
3641 Runs many macros required for proper operation of the generated Makefiles.
3643 @vindex AUTOMAKE_OPTIONS
3644 This macro has two forms, the first of which is preferred.
3645 In this form, @code{AM_INIT_AUTOMAKE} is called with a
3646 single argument: a space-separated list of Automake options that should
3647 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3648 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3650 @acindex AC_INIT
3651 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
3652 arguments: the package and the version number.  This form is
3653 obsolete because the @var{package} and @var{version} can be obtained
3654 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
3655 form).
3657 If your @file{configure.ac} has:
3659 @example
3660 AC_INIT([src/foo.c])
3661 AM_INIT_AUTOMAKE([mumble], [1.5])
3662 @end example
3664 @noindent
3665 you can modernize it as follows:
3667 @example
3668 AC_INIT([mumble], [1.5])
3669 AC_CONFIG_SRCDIR([src/foo.c])
3670 AM_INIT_AUTOMAKE
3671 @end example
3673 Note that if you're upgrading your @file{configure.ac} from an earlier
3674 version of Automake, it is not always correct to simply move the
3675 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3676 @code{AC_INIT}, as in the example above.  The first argument to
3677 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3678 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3679 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3680 tarball name from the package name, which should work for most but not
3681 all package names.  (If it doesn't work for yours, you can use the
3682 four-argument form of @code{AC_INIT} to provide the tarball name
3683 explicitly).
3685 @cindex @code{PACKAGE}, prevent definition
3686 @cindex @code{VERSION}, prevent definition
3687 @opindex no-define
3688 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3689 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3690 option, as in:
3691 @example
3692 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3693 @end example
3694 or by passing a third non-empty argument to the obsolete form.
3696 @item AM_PATH_LISPDIR
3697 @acindex AM_PATH_LISPDIR
3698 @vindex EMACS
3699 @vindex lispdir
3700 Searches for the program @command{emacs}, and, if found, sets the
3701 output variable @code{lispdir} to the full path to Emacs' site-lisp
3702 directory.
3704 Note that this test assumes the @command{emacs} found to be a version
3705 that supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other
3706 emacsen can cause this test to hang (some, like old versions of
3707 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3708 exit, which is hardly obvious for a non-emacs user).  In most cases,
3709 however, you should be able to use @kbd{C-c} to kill the test.  In
3710 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3711 environment, or use the @option{--with-lispdir} option to
3712 @command{configure} to explicitly set the correct path (if you're sure
3713 you have an @command{emacs} that supports Emacs Lisp).
3715 @item AM_PROG_AS
3716 @acindex AM_PROG_AS
3717 @vindex CCAS
3718 @vindex CCASFLAGS
3719 Use this macro when you have assembly code in your project.  This will
3720 choose the assembler for you (by default the C compiler) and set
3721 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
3723 @item AM_PROG_CC_C_O
3724 @acindex AM_PROG_CC_C_O
3725 @acindex AC_PROG_CC_C_O
3726 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
3727 the manner required by automake.  You must use this instead of
3728 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
3729 using per-target flags or subdir-objects with C sources.
3731 @item AM_PROG_LEX
3732 @acindex AM_PROG_LEX
3733 @acindex AC_PROG_LEX
3734 @cindex HP-UX 10, @command{lex} problems
3735 @cindex @command{lex} problems with HP-UX 10
3736 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
3737 Program Checks, autoconf, The Autoconf Manual}), but uses the
3738 @command{missing} script on systems that do not have @command{lex}.
3739 HP-UX 10 is one such system.
3741 @item AM_PROG_GCJ
3742 @acindex AM_PROG_GCJ
3743 @vindex GCJ
3744 @vindex GCJFLAGS
3745 This macro finds the @command{gcj} program or causes an error.  It sets
3746 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
3747 GNU Compiler Collection.
3749 @item AM_PROG_UPC([@var{compiler-search-list}])
3750 @acindex AM_PROG_UPC
3751 @vindex UPC
3752 Find a compiler for Unified Parallel C and define the @code{UPC}
3753 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
3754 This macro will abort @command{configure} if no Unified Parallel C
3755 compiler is found.
3757 @item AM_WITH_DMALLOC
3758 @acindex AM_WITH_DMALLOC
3759 @cindex @command{dmalloc}, support for
3760 @vindex WITH_DMALLOC
3761 @opindex --with-dmalloc
3762 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
3763 the user runs @command{configure} with @option{--with-dmalloc}, then
3764 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
3766 @item AM_WITH_REGEX
3767 @acindex AM_WITH_REGEX
3768 @vindex WITH_REGEX
3769 @opindex --with-regex
3770 @cindex regex package
3771 @cindex rx package
3772 Adds @option{--with-regex} to the @command{configure} command line.  If
3773 specified (the default), then the @samp{regex} regular expression
3774 library is used, @file{regex.o} is put into @code{LIBOBJS}, and
3775 @code{WITH_REGEX} is defined.  If @option{--without-regex} is given, then
3776 the @code{rx} regular expression library is used, and @file{rx.o} is put
3777 into @code{LIBOBJS}.
3779 @end table
3782 @node Obsolete macros
3783 @subsection Obsolete macros
3784 @cindex obsolete macros
3785 @cindex autoupdate
3787 Although using some of the following macros was required in past
3788 releases, you should not use any of them in new code.  Running
3789 @command{autoupdate} should adjust your @file{configure.ac}
3790 automatically (@pxref{autoupdate Invocation, , Using
3791 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
3792 Autoconf Manual}).
3794 @table @code
3795 @item AM_C_PROTOTYPES
3796 @acindex AM_C_PROTOTYPES
3797 @vindex ANSI2KNR
3798 @vindex U
3799 Check to see if function prototypes are understood by the compiler.  If
3800 so, define @samp{PROTOTYPES} and set the output variables @code{U} and
3801 @code{ANSI2KNR} to the empty string.  Otherwise, set @code{U} to
3802 @samp{_} and @code{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
3803 values to implement the obsolete de-ANSI-fication feature.
3805 @item AM_CONFIG_HEADER
3806 @acindex AM_CONFIG_HEADER
3807 Automake will generate rules to automatically regenerate the config
3808 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
3809 today (@pxref{Optional}).
3811 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3812 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3813 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
3814 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
3815 found in @file{<termios.h>}.  This macro is obsolete, you should
3816 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
3818 @item AM_PROG_MKDIR_P
3819 @acindex AM_PROG_MKDIR_P
3820 @cindex @code{mkdir -p}, macro check
3821 @vindex MKDIR_P
3822 @vindex mkdir_p
3824 From Automake 1.8 to 1.9.6 this macro used to define the output
3825 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
3826 -d}, or @code{mkinstalldirs}.
3828 Nowadays Autoconf provides a similar functionality with
3829 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
3830 Program Checks, autoconf, The Autoconf Manual}), however this defines
3831 the output variable @code{MKDIR_P} instead.  Therefore
3832 @code{AM_PROG_MKDIR_P} has been rewritten as a thin wrapper around
3833 @code{AC_PROG_MKDIR_P} to define @code{mkdir_p} to the same value as
3834 @code{MKDIR_P} for backward compatibility.
3836 If you are using Automake, there is normally no reason to call this
3837 macro, because @code{AM_INIT_AUTOMAKE} already does so.  However, make
3838 sure that the custom rules in your @file{Makefile}s use
3839 @code{$(MKDIR_P)} and not @code{$(mkdir_p)}.  Even if both variables
3840 still work, the latter should be considered obsolete.
3842 If you are not using Automake, please call @code{AC_PROG_MKDIR_P}
3843 instead of @code{AM_PROG_MKDIR_P}.
3845 @item AM_SYS_POSIX_TERMIOS
3846 @acindex AM_SYS_POSIX_TERMIOS
3847 @cindex POSIX termios headers
3848 @cindex termios POSIX headers
3849 Check to see if POSIX termios headers and functions are available on the
3850 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
3851 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
3852 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
3854 @end table
3857 @node Private macros
3858 @subsection Private macros
3860 The following macros are private macros you should not call directly.
3861 They are called by the other public macros when appropriate.  Do not
3862 rely on them, as they might be changed in a future version.  Consider
3863 them as implementation details; or better, do not consider them at all:
3864 skip this section!
3866 @ftable @code
3867 @item _AM_DEPENDENCIES
3868 @itemx AM_SET_DEPDIR
3869 @itemx AM_DEP_TRACK
3870 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
3871 These macros are used to implement Automake's automatic dependency
3872 tracking scheme.  They are called automatically by automake when
3873 required, and there should be no need to invoke them manually.
3875 @item AM_MAKE_INCLUDE
3876 This macro is used to discover how the user's @command{make} handles
3877 @code{include} statements.  This macro is automatically invoked when
3878 needed; there should be no need to invoke it manually.
3880 @item AM_PROG_INSTALL_STRIP
3881 This is used to find a version of @code{install} that can be used to
3882 strip a program at installation time.  This macro is automatically
3883 included when required.
3885 @item AM_SANITY_CHECK
3886 This checks to make sure that a file created in the build directory is
3887 newer than a file in the source directory.  This can fail on systems
3888 where the clock is set incorrectly.  This macro is automatically run
3889 from @code{AM_INIT_AUTOMAKE}.
3891 @end ftable
3894 @node Directories
3895 @chapter Directories
3897 For simple projects that distributes all files in the same directory
3898 it is enough to have a single @file{Makefile.am} that builds
3899 everything in place.
3901 In larger projects it is common to organize files in different
3902 directories, in a tree.  For instance one directory per program, per
3903 library or per module.  The traditional approach is to build these
3904 subdirectory recursively: each directory contains its @file{Makefile}
3905 (generated from @file{Makefile.am}), and when @command{make} is run
3906 from the top level directory it enters each subdirectory in turn to
3907 build its contents.
3909 @menu
3910 * Subdirectories::              Building subdirectories recursively
3911 * Conditional Subdirectories::  Conditionally not building directories
3912 * Alternative::                 Subdirectories without recursion
3913 * Subpackages::                 Nesting packages
3914 @end menu
3916 @node Subdirectories
3917 @section Recursing subdirectories
3919 @cindex @code{SUBDIRS}, explained
3921 In packages with subdirectories, the top level @file{Makefile.am} must
3922 tell Automake which subdirectories are to be built.  This is done via
3923 the @code{SUBDIRS} variable.
3924 @vindex SUBDIRS
3926 The @code{SUBDIRS} variable holds a list of subdirectories in which
3927 building of various sorts can occur.  The rules for many targets
3928 (e.g., @code{all}) in the generated @file{Makefile} will run commands
3929 both locally and in all specified subdirectories.  Note that the
3930 directories listed in @code{SUBDIRS} are not required to contain
3931 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
3932 This allows inclusion of libraries from packages that do not use
3933 Automake (such as @code{gettext}; see also @ref{Third-Party
3934 Makefiles}).
3936 In packages that use subdirectories, the top-level @file{Makefile.am} is
3937 often very short.  For instance, here is the @file{Makefile.am} from the
3938 GNU Hello distribution:
3940 @example
3941 EXTRA_DIST = BUGS ChangeLog.O README-alpha
3942 SUBDIRS = doc intl po src tests
3943 @end example
3945 When Automake invokes @command{make} in a subdirectory, it uses the value
3946 of the @code{MAKE} variable.  It passes the value of the variable
3947 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
3948 @file{Makefile.am} if there are flags you must always pass to
3949 @command{make}.
3950 @vindex MAKE
3951 @vindex AM_MAKEFLAGS
3953 The directories mentioned in @code{SUBDIRS} are usually direct
3954 children of the current directory, each subdirectory containing its
3955 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
3956 subdirectories.  Automake can be used to construct packages of
3957 arbitrary depth this way.
3959 By default, Automake generates @file{Makefiles} that work depth-first
3960 in postfix order: the subdirectories are built before the current
3961 directory.  However, it is possible to change this ordering.  You can
3962 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
3963 putting @samp{.} first will cause a prefix ordering of
3964 directories.
3966 Using
3968 @example
3969 SUBDIRS = lib src . test
3970 @end example
3972 @noindent
3973 will cause @file{lib/} to be built before @file{src/}, then the
3974 current directory will be built, finally the @file{test/} directory
3975 will be built.  It is customary to arrange test directories to be
3976 built after everything else since they are meant to test what has
3977 been constructed.
3979 All @code{clean} rules are run in reverse order of build rules.
3981 @node Conditional Subdirectories
3982 @section Conditional Subdirectories
3983 @cindex Subdirectories, building conditionally
3984 @cindex Conditional subdirectories
3985 @cindex @code{SUBDIRS}, conditional
3986 @cindex Conditional @code{SUBDIRS}
3988 It is possible to define the @code{SUBDIRS} variable conditionally if,
3989 like in the case of GNU Inetutils, you want to only build a subset of
3990 the entire package.
3992 To illustrate how this works, let's assume we have two directories
3993 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
3994 want to decide in @command{configure} whether @file{opt/} will be built
3995 or not.  (For this example we will assume that @file{opt/} should be
3996 built when the variable @samp{$want_opt} was set to @samp{yes}.)
3998 Running @command{make} should thus recurse into @file{src/} always, and
3999 then maybe in @file{opt/}.
4001 However @samp{make dist} should always recurse into both @file{src/}
4002 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4003 is not needed in the current configuration.  This means
4004 @file{opt/Makefile} should be created @emph{unconditionally}.
4006 There are two ways to setup a project like this.  You can use Automake
4007 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4008 variables (@pxref{Setting Output Variables, , Setting Output
4009 Variables, autoconf, The Autoconf Manual}).  Using Automake
4010 conditionals is the preferred solution.  Before we illustrate these
4011 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4013 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4014 @cindex @code{DIST_SUBDIRS}, explained
4016 Automake considers two sets of directories, defined by the variables
4017 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4019 @code{SUBDIRS} contains the subdirectories of the current directory
4020 that must be built (@pxref{Subdirectories}).  It must be defined
4021 manually; Automake will never guess a directory is to be built.  As we
4022 will see in the next two sections, it is possible to define it
4023 conditionally so that some directory will be omitted from the build.
4025 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4026 directories, even those that have been conditionally left out of the
4027 build.  Recall our example where we may not want to build subdirectory
4028 @file{opt/}, but yet we want to distribute it?  This is where
4029 @code{DIST_SUBDIRS} come into play: @samp{opt} may not appear in
4030 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4032 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4033 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4034 other recursive rules use @code{SUBDIRS}.
4036 If @code{SUBDIRS} is defined conditionally using Automake
4037 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4038 from the possibles values of @code{SUBDIRS} in all conditions.
4040 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4041 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4042 does not know the possible values of these variables.  In this case
4043 @code{DIST_SUBDIRS} needs to be defined manually.
4045 @subsection Conditional subdirectories with @code{AM_CONDITIONAL}
4046 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4047 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4049 @c The test case for the setup described here is
4050 @c     test/subdircond2.test
4051 @c Try to keep it in sync.
4053 @file{configure} should output the @file{Makefile} for each directory
4054 and define a condition into which @file{opt/} should be built.
4056 @example
4057 @dots{}
4058 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4059 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4060 @dots{}
4061 @end example
4063 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4064 as follows.
4066 @example
4067 if COND_OPT
4068   MAYBE_OPT = opt
4069 endif
4070 SUBDIRS = src $(MAYBE_OPT)
4071 @end example
4073 As you can see, running @command{make} will rightly recurse into
4074 @file{src/} and maybe @file{opt/}.
4076 @vindex DIST_SUBDIRS
4077 As you can't see, running @samp{make dist} will recurse into both
4078 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4079 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4080 @code{DIST_SUBDIRS} variable.
4082 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4083 automatically because it knows that @code{MAYBE_OPT} can contain
4084 @samp{opt} in some condition.
4086 @subsection Conditional Subdirectories with @code{AC_SUBST}
4087 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4088 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4090 @c The test case for the setup described here is
4091 @c     test/subdircond3.test
4092 @c Try to keep it in sync.
4094 Another possibility is to define @code{MAYBE_OPT} from
4095 @file{./configure} using @code{AC_SUBST}:
4097 @example
4098 @dots{}
4099 if test "$want_opt" = yes; then
4100   MAYBE_OPT=opt
4101 else
4102   MAYBE_OPT=
4104 AC_SUBST([MAYBE_OPT])
4105 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4106 @dots{}
4107 @end example
4109 In this case the top-level @file{Makefile.am} should look as follows.
4111 @example
4112 SUBDIRS = src $(MAYBE_OPT)
4113 DIST_SUBDIRS = src opt
4114 @end example
4116 The drawback is that since Automake cannot guess what the possible
4117 values of @code{MAYBE_OPT} are, it is necessary to define
4118 @code{DIST_SUBDIRS}.
4120 @subsection Non-configured Subdirectories
4121 @cindex Subdirectories, configured conditionally
4123 The semantic of @code{DIST_SUBDIRS} is often misunderstood by some
4124 users that try to @emph{configure and build} subdirectories
4125 conditionally.  Here by configuring we mean creating the
4126 @file{Makefile} (it might also involve running a nested
4127 @command{configure} script: this is a costly operation that explains
4128 why people want to do it conditionally, but only the @file{Makefile}
4129 is relevant to the discussion).
4131 The above examples all assume that every @file{Makefile} is created,
4132 even in directories that are not going to be built.  The simple reason
4133 is that we want @samp{make dist} to distribute even the directories
4134 that are not being built (e.g., platform-dependent code), hence
4135 @file{make dist} must recurse into the subdirectory, hence this
4136 directory must be configured and appear in @code{DIST_SUBDIRS}.
4138 Building packages that do not configure every subdirectory is a tricky
4139 business, and we do not recommend it to the novice as it is easy to
4140 produce an incomplete tarball by mistake.  We will not discuss this
4141 topic in depth here, yet for the adventurous here are a few rules to
4142 remember.
4144 @cartouche
4145 @itemize
4146 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4148 It makes little sense to have a directory in @code{SUBDIRS} that
4149 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4150 which directories listed in the latter should be built.
4151 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4152 must be configured.
4154 I.e., the @file{Makefile} must exists or the recursive @command{make}
4155 rules will not be able to process the directory.
4156 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4158 So that the cleaning rule remove the generated @file{Makefile}s.
4159 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4160 lists all the directories that have been configured.
4161 @end itemize
4162 @end cartouche
4164 In order to prevent recursion in some non-configured directory you
4165 must therefore ensure that this directory does not appear in
4166 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4167 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4168 @code{DIST_SUBDIRS} explicitly, it will be default to
4169 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4170 = $(SUBDIRS)}.
4172 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4173 not be distributed unless you make other arrangements for this to
4174 happen (for instance, always running @samp{make dist} in a
4175 configuration where all directories are known to appear in
4176 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4177 distribute these directories).
4179 @cindex Subdirectories, not distributed
4180 In few packages, non-configured directories are not even expected to
4181 be distributed.  Although these packages do not require the
4182 aforementioned extra arrangements, there is another pitfall.  If the
4183 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4184 @command{automake} will make sure the directory exists.  Consequently
4185 @command{automake} cannot be run on such a distribution when one
4186 directory has been omitted.  One way to avoid this check is to use the
4187 @code{AC_SUBST} method to declare conditional directories; since
4188 @command{automake} does not know the values of @code{AC_SUBST}
4189 variables it cannot ensure the corresponding directory exist.
4191 @node Alternative
4192 @section An Alternative Approach to Subdirectories
4194 If you've ever read Peter Miller's excellent paper,
4195 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
4196 Recursive Make Considered Harmful}, the preceding sections on the use of
4197 subdirectories will probably come as unwelcome advice.  For those who
4198 haven't read the paper, Miller's main thesis is that recursive
4199 @command{make} invocations are both slow and error-prone.
4201 Automake provides sufficient cross-directory support @footnote{We
4202 believe.  This work is new and there are probably warts.
4203 @xref{Introduction}, for information on reporting bugs.} to enable you
4204 to write a single @file{Makefile.am} for a complex multi-directory
4205 package.
4208 By default an installable file specified in a subdirectory will have its
4209 directory name stripped before installation.  For instance, in this
4210 example, the header file will be installed as
4211 @file{$(includedir)/stdio.h}:
4213 @example
4214 include_HEADERS = inc/stdio.h
4215 @end example
4217 @vindex nobase_
4218 @cindex @code{nobase_} prefix
4219 @cindex Path stripping, avoiding
4220 @cindex Avoiding path stripping
4222 However, the @samp{nobase_} prefix can be used to circumvent this path
4223 stripping.  In this example, the header file will be installed as
4224 @file{$(includedir)/sys/types.h}:
4226 @example
4227 nobase_include_HEADERS = sys/types.h
4228 @end example
4230 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4231 @cindex @code{dist_} and @code{nobase_}
4232 @cindex @code{nodist_} and @code{nobase_}
4233 @vindex dist_
4234 @vindex nodist_
4236 @samp{nobase_} should be specified first when used in conjunction with
4237 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
4239 @example
4240 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4241 @end example
4243 Finally, note that a variable using the @samp{nobase_} prefix can
4244 always be replaced by several variables, one for each destination
4245 directory (@pxref{Uniform}).  For instance, the last example could be
4246 rewritten as follows:
4248 @example
4249 imagesdir = $(pkgdatadir)/images
4250 soundsdir = $(pkgdatadir)/sounds
4251 dist_images_DATA = images/vortex.pgm
4252 dist_sounds_DATA = sounds/whirl.ogg
4253 @end example
4255 @noindent
4256 This latter syntax makes it possible to change one destination
4257 directory without changing the layout of the source tree.
4259 @node Subpackages
4260 @section Nesting Packages
4261 @cindex Nesting packages
4262 @cindex Subpackages
4263 @acindex AC_CONFIG_SUBDIRS
4264 @acindex AC_CONFIG_AUX_DIR
4267 In the GNU Build System, packages can be nested to arbitrary depth.
4268 This means that a package can embedded other packages with their own
4269 @file{configure}, @file{Makefile}s, etc.
4271 These other packages should just appear as subdirectories of their
4272 parent package.  They must be listed in @code{SUBDIRS} like other
4273 ordinary directories.  However the subpackage's @file{Makefile}s
4274 should be output by its own @file{configure} script, not by the
4275 parent's @file{configure}.  This is achieved using the
4276 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4277 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4278 autoconf, The Autoconf Manual}).
4280 Here is an example package for an @code{arm} program that links with
4281 an @code{hand} library that is a nested package in subdirectory
4282 @file{hand/}.
4284 @code{arm}'s @file{configure.ac}:
4286 @example
4287 AC_INIT([arm], [1.0])
4288 AC_CONFIG_AUX_DIR([.])
4289 AM_INIT_AUTOMAKE
4290 AC_PROG_CC
4291 AC_CONFIG_FILES([Makefile])
4292 # Call hand's ./configure script recursively.
4293 AC_CONFIG_SUBDIRS([hand])
4294 AC_OUTPUT
4295 @end example
4297 @code{arm}'s @file{Makefile.am}:
4299 @example
4300 # Build the library in the hand subdirectory first.
4301 SUBDIRS = hand
4303 # Include hand's header when compiling this directory.
4304 AM_CPPFLAGS = -I$(srcdir)/hand
4306 bin_PROGRAMS = arm
4307 arm_SOURCES = arm.c
4308 # link with the hand library.
4309 arm_LDADD = hand/libhand.a
4310 @end example
4312 Now here is @code{hand}'s @file{hand/configure.ac}:
4314 @example
4315 AC_INIT([hand], [1.2])
4316 AC_CONFIG_AUX_DIR([.])
4317 AM_INIT_AUTOMAKE
4318 AC_PROG_CC
4319 AC_PROG_RANLIB
4320 AC_CONFIG_FILES([Makefile])
4321 AC_OUTPUT
4322 @end example
4324 @noindent
4325 and its @file{hand/Makefile.am}:
4327 @example
4328 lib_LIBRARIES = libhand.a
4329 libhand_a_SOURCES = hand.c
4330 @end example
4332 When @samp{make dist} is run from the top-level directory it will
4333 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4334 code as well as the @file{hand} subdirectory.  This package can be
4335 built and installed like any ordinary package, with the usual
4336 @samp{./configure && make && make install} sequence (the @code{hand}
4337 subpackage will be built and installed by the process).
4339 When @samp{make dist} is run from the hand directory, it will create a
4340 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4341 to be embedded in another package, it can still be used separately.
4343 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4344 force Automake and Autoconf to search for auxiliary scripts in the
4345 current directory.  For instance, this means that there will be two
4346 copies of @file{install-sh}: one in the top-level of the @code{arm}
4347 package, and another one in the @file{hand/} subdirectory for the
4348 @code{hand} package.
4350 The historical default is to search for these auxiliary scripts in
4351 the parent directory and the grandparent directory.  So if the
4352 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4353 @file{hand/configure.ac}, that subpackage would share the auxiliary
4354 script of the @code{arm} package.  This may looks like a gain in size
4355 (a few kilobytes), but it is actually a loss of modularity as the
4356 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4357 in the subdirectory will not work anymore).
4359 Packages that do not use Automake need more work to be integrated this
4360 way.  @xref{Third-Party Makefiles}.
4362 @node Programs
4363 @chapter Building Programs and Libraries
4365 A large part of Automake's functionality is dedicated to making it easy
4366 to build programs and libraries.
4368 @menu
4369 * A Program::                   Building a program
4370 * A Library::                   Building a library
4371 * A Shared Library::            Building a Libtool library
4372 * Program and Library Variables::  Variables controlling program and
4373                                 library builds
4374 * Default _SOURCES::            Default source files
4375 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4376 * Program variables::           Variables used when building a program
4377 * Yacc and Lex::                Yacc and Lex support
4378 * C++ Support::                 Compiling C++ sources
4379 * Objective C Support::         Compiling Objective C sources
4380 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4381 * Assembly Support::            Compiling assembly sources
4382 * Fortran 77 Support::          Compiling Fortran 77 sources
4383 * Fortran 9x Support::          Compiling Fortran 9x sources
4384 * Java Support::                Compiling Java sources
4385 * Support for Other Languages::  Compiling other languages
4386 * ANSI::                        Automatic de-ANSI-fication (obsolete)
4387 * Dependencies::                Automatic dependency tracking
4388 * EXEEXT::                      Support for executable extensions
4389 @end menu
4392 @node A Program
4393 @section Building a program
4395 In order to build a program, you need to tell Automake which sources
4396 are part of it, and which libraries it should be linked with.
4398 This section also covers conditional compilation of sources or
4399 programs.  Most of the comments about these also apply to libraries
4400 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4402 @menu
4403 * Program Sources::             Defining program sources
4404 * Linking::                     Linking with libraries or extra objects
4405 * Conditional Sources::         Handling conditional sources
4406 * Conditional Programs::        Building program conditionally
4407 @end menu
4409 @node Program Sources
4410 @subsection Defining program sources
4412 @cindex @code{PROGRAMS}, @code{bindir}
4413 @vindex _PROGRAMS
4414 @vindex bin_PROGRAMS
4415 @vindex sbin_PROGRAMS
4416 @vindex libexec_PROGRAMS
4417 @vindex pkglib_PROGRAMS
4418 @vindex noinst_PROGRAMS
4419 @vindex check_PROGRAMS
4421 In a directory containing source that gets built into a program (as
4422 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4423 Programs can be installed in @code{bindir}, @code{sbindir},
4424 @code{libexecdir}, @code{pkglibdir}, @code{pkglibexecdir}, or not at all
4425 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4426 which case the prefix is @samp{check_}.
4428 For instance:
4430 @example
4431 bin_PROGRAMS = hello
4432 @end example
4434 In this simple case, the resulting @file{Makefile.in} will contain code
4435 to generate a program named @code{hello}.
4437 Associated with each program are several assisting variables that are
4438 named after the program.  These variables are all optional, and have
4439 reasonable defaults.  Each variable, its use, and default is spelled out
4440 below; we use the ``hello'' example throughout.
4442 The variable @code{hello_SOURCES} is used to specify which source files
4443 get built into an executable:
4445 @example
4446 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4447 @end example
4449 This causes each mentioned @file{.c} file to be compiled into the
4450 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4452 @cindex @code{_SOURCES} primary, defined
4453 @cindex @code{SOURCES} primary, defined
4454 @cindex Primary variable, @code{SOURCES}
4455 @vindex _SOURCES
4457 If @code{hello_SOURCES} is not specified, then it defaults to the single
4458 file @file{hello.c} (@pxref{Default _SOURCES}).
4459 @vindex _SOURCES
4460 @vindex SOURCES
4462 Multiple programs can be built in a single directory.  Multiple programs
4463 can share a single source file, which must be listed in each
4464 @code{_SOURCES} definition.
4466 @cindex Header files in @code{_SOURCES}
4467 @cindex @code{_SOURCES} and header files
4469 Header files listed in a @code{_SOURCES} definition will be included in
4470 the distribution but otherwise ignored.  In case it isn't obvious, you
4471 should not include the header file generated by @file{configure} in a
4472 @code{_SOURCES} variable; this file should not be distributed.  Lex
4473 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4474 and Lex}.
4477 @node Linking
4478 @subsection Linking the program
4480 If you need to link against libraries that are not found by
4481 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4482 used to specify additional objects or libraries to link with; it is
4483 inappropriate for specifying specific linker flags, you should use
4484 @code{AM_LDFLAGS} for this purpose.
4485 @vindex LDADD
4486 @vindex AM_LDFLAGS
4488 @cindex @code{prog_LDADD}, defined
4490 Sometimes, multiple programs are built in one directory but do not share
4491 the same link-time requirements.  In this case, you can use the
4492 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4493 program as it appears in some @code{_PROGRAMS} variable, and usually
4494 written in lowercase) to override the global @code{LDADD}.  If this
4495 variable exists for a given program, then that program is not linked
4496 using @code{LDADD}.
4497 @vindex maude_LDADD
4499 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4500 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4501 built in the same directory, and has no such link requirement.  Also,
4502 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4503 is what cpio's @file{src/Makefile.am} looks like (abridged):
4505 @example
4506 bin_PROGRAMS = cpio pax $(MT)
4507 libexec_PROGRAMS = $(RMT)
4508 EXTRA_PROGRAMS = mt rmt
4510 LDADD = ../lib/libcpio.a $(INTLLIBS)
4511 rmt_LDADD =
4513 cpio_SOURCES = @dots{}
4514 pax_SOURCES = @dots{}
4515 mt_SOURCES = @dots{}
4516 rmt_SOURCES = @dots{}
4517 @end example
4519 @cindex @code{_LDFLAGS}, defined
4520 @vindex maude_LDFLAGS
4521 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4522 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4523 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4524 this purpose.
4526 @cindex @code{_DEPENDENCIES}, defined
4527 @vindex maude_DEPENDENCIES
4528 It is also occasionally useful to have a program depend on some other
4529 target that is not actually part of that program.  This can be done
4530 using the @code{@var{prog}_DEPENDENCIES} variable.  Each program
4531 depends on the contents of such a variable, but no further
4532 interpretation is done.
4534 Since these dependencies are associated to the link rule used to
4535 create the programs they should normally list files used by the link
4536 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4537 files.  In rare cases you may need to add other kinds of files such as
4538 linker scripts, but @emph{listing a source file in
4539 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4540 before all the components of a program are built, consider using the
4541 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4543 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4544 Automake.  The automatically-assigned value is the contents of
4545 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4546 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4547 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4548 @samp{$(ALLOCA)}; these are left because it is known that they will not
4549 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4550 generated.
4552 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4553 may be used.
4555 @cindex @code{LDADD} and @option{-l}
4556 @cindex @option{-l} and @code{LDADD}
4557 We recommend that you avoid using @option{-l} options in @code{LDADD}
4558 or @code{@var{prog}_LDADD} when referring to libraries built by your
4559 package.  Instead, write the file name of the library explicitly as in
4560 the above @code{cpio} example.  Use @option{-l} only to list
4561 third-party libraries.  If you follow this rule, the default value of
4562 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4563 omit the other ones.
4566 @node Conditional Sources
4567 @subsection Conditional compilation of sources
4569 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4570 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4571 @code{_SOURCES} variable.  The reason for this is a bit hard to
4572 explain, but suffice to say that it simply won't work.  Automake will
4573 give an error if you try to do this.
4575 Fortunately there are two other ways to achieve the same result.  One is
4576 to use configure substitutions in @code{_LDADD} variables, the other is
4577 to use an Automake conditional.
4579 @subsubsection Conditional compilation using @code{_LDADD} substitutions
4581 @cindex @code{EXTRA_prog_SOURCES}, defined
4583 Automake must know all the source files that could possibly go into a
4584 program, even if not all the files are built in every circumstance.  Any
4585 files that are only conditionally built should be listed in the
4586 appropriate @code{EXTRA_} variable.  For instance, if
4587 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4588 in @code{hello}, the @file{Makefile.am} would contain:
4590 @example
4591 bin_PROGRAMS = hello
4592 hello_SOURCES = hello-common.c
4593 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4594 hello_LDADD = $(HELLO_SYSTEM)
4595 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4596 @end example
4598 @noindent
4599 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4600 @file{configure.ac}:
4602 @example
4603 @dots{}
4604 case $host in
4605   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4606   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4607 esac
4608 AC_SUBST([HELLO_SYSTEM])
4609 @dots{}
4610 @end example
4612 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4613 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4614 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4615 built and linked in.
4617 @subsubsection Conditional compilation using Automake conditionals
4619 An often simpler way to compile source files conditionally is to use
4620 Automake conditionals.  For instance, you could use this
4621 @file{Makefile.am} construct to build the same @file{hello} example:
4623 @example
4624 bin_PROGRAMS = hello
4625 if LINUX
4626 hello_SOURCES = hello-linux.c hello-common.c
4627 else
4628 hello_SOURCES = hello-generic.c hello-common.c
4629 endif
4630 @end example
4632 In this case, @file{configure.ac} should setup the @code{LINUX}
4633 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4635 When using conditionals like this you don't need to use the
4636 @code{EXTRA_} variable, because Automake will examine the contents of
4637 each variable to construct the complete list of source files.
4639 If your program uses a lot of files, you will probably prefer a
4640 conditional @samp{+=}.
4642 @example
4643 bin_PROGRAMS = hello
4644 hello_SOURCES = hello-common.c
4645 if LINUX
4646 hello_SOURCES += hello-linux.c
4647 else
4648 hello_SOURCES += hello-generic.c
4649 endif
4650 @end example
4652 @node Conditional Programs
4653 @subsection Conditional compilation of programs
4654 @cindex Conditional programs
4655 @cindex Programs, conditional
4657 Sometimes it is useful to determine the programs that are to be built
4658 at configure time.  For instance, GNU @code{cpio} only builds
4659 @code{mt} and @code{rmt} under special circumstances.  The means to
4660 achieve conditional compilation of programs are the same you can use
4661 to compile source files conditionally: substitutions or conditionals.
4663 @subsubsection Conditional programs using @command{configure} substitutions
4665 @vindex EXTRA_PROGRAMS
4666 @cindex @code{EXTRA_PROGRAMS}, defined
4667 In this case, you must notify Automake of all the programs that can
4668 possibly be built, but at the same time cause the generated
4669 @file{Makefile.in} to use the programs specified by @command{configure}.
4670 This is done by having @command{configure} substitute values into each
4671 @code{_PROGRAMS} definition, while listing all optionally built programs
4672 in @code{EXTRA_PROGRAMS}.
4674 @example
4675 bin_PROGRAMS = cpio pax $(MT)
4676 libexec_PROGRAMS = $(RMT)
4677 EXTRA_PROGRAMS = mt rmt
4678 @end example
4680 As explained in @ref{EXEEXT}, Automake will rewrite
4681 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4682 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4683 Obviously it cannot rewrite values obtained at run-time through
4684 @command{configure} substitutions, therefore you should take care of
4685 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4686 ['mt$@{EXEEXT@}'])}.
4688 @subsubsection Conditional programs using Automake conditionals
4690 You can also use Automake conditionals (@pxref{Conditionals}) to
4691 select programs to be built.  In this case you don't have to worry
4692 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4694 @example
4695 bin_PROGRAMS = cpio pax
4696 if WANT_MT
4697   bin_PROGRAMS += mt
4698 endif
4699 if WANT_RMT
4700   libexec_PROGRAMS = rmt
4701 endif
4702 @end example
4705 @node A Library
4706 @section Building a library
4708 @cindex @code{_LIBRARIES} primary, defined
4709 @cindex @code{LIBRARIES} primary, defined
4710 @cindex Primary variable, @code{LIBRARIES}
4711 @vindex _LIBRARIES
4713 @vindex lib_LIBRARIES
4714 @vindex pkglib_LIBRARIES
4715 @vindex noinst_LIBRARIES
4717 Building a library is much like building a program.  In this case, the
4718 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
4719 @code{libdir} or @code{pkglibdir}.
4721 @xref{A Shared Library}, for information on how to build shared
4722 libraries using libtool and the @code{LTLIBRARIES} primary.
4724 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
4725 For instance, to create a library named @file{libcpio.a}, but not install
4726 it, you would write:
4728 @example
4729 noinst_LIBRARIES = libcpio.a
4730 libcpio_a_SOURCES = @dots{}
4731 @end example
4733 The sources that go into a library are determined exactly as they are
4734 for programs, via the @code{_SOURCES} variables.  Note that the library
4735 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
4736 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
4737 not @samp{libcpio.a_SOURCES}.
4739 @vindex maude_LIBADD
4740 Extra objects can be added to a library using the
4741 @code{@var{library}_LIBADD} variable.  This should be used for objects
4742 determined by @command{configure}.  Again from @code{cpio}:
4744 @example
4745 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4746 @end example
4748 In addition, sources for extra objects that will not exist until
4749 configure-time must be added to the @code{BUILT_SOURCES} variable
4750 (@pxref{Sources}).
4752 Building a static library is done by compiling all object files, then
4753 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
4754 library and the list of objects, and finally by calling
4755 @samp{$(RANLIB)} on that library.  You should call
4756 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
4757 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
4758 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
4759 can override these two variables my setting them in your
4760 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
4761 @file{configure.ac}, or by defining a per-library @code{maude_AR}
4762 variable (@pxref{Program and Library Variables}).
4764 @cindex Empty libraries
4765 Be careful when selecting library components conditionally.  Because
4766 building an empty library is not portable, you should ensure that any
4767 library contains always at least one object.
4769 To use a static library when building a program, add it to
4770 @code{LDADD} for this program.  In the following example, the program
4771 @file{cpio} is statically linked with the library @file{libcpio.a}.
4773 @example
4774 noinst_LIBRARIES = libcpio.a
4775 libcpio_a_SOURCES = @dots{}
4777 bin_PROGRAMS = cpio
4778 cpio_SOURCES = cpio.c @dots{}
4779 cpio_LDADD = libcpio.a
4780 @end example
4783 @node A Shared Library
4784 @section Building a Shared Library
4786 @cindex Shared libraries, support for
4788 Building shared libraries portably is a relatively complex matter.
4789 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
4790 Libtool Manual}) was created to help build shared libraries in a
4791 platform-independent way.
4793 @menu
4794 * Libtool Concept::             Introducing Libtool
4795 * Libtool Libraries::           Declaring Libtool Libraries
4796 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
4797 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
4798 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
4799 * Libtool Modules::             Building Libtool Modules
4800 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
4801 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
4802 * Libtool Issues::              Common Issues Related to Libtool's Use
4803 @end menu
4805 @node Libtool Concept
4806 @subsection The Libtool Concept
4808 @cindex @command{libtool}, introduction
4809 @cindex libtool library, definition
4810 @cindex suffix @file{.la}, defined
4811 @cindex @file{.la} suffix, defined
4813 Libtool abstracts shared and static libraries into a unified concept
4814 henceforth called @dfn{libtool libraries}.  Libtool libraries are
4815 files using the @file{.la} suffix, and can designate a static library,
4816 a shared library, or maybe both.  Their exact nature cannot be
4817 determined until @file{./configure} is run: not all platforms support
4818 all kinds of libraries, and users can explicitly select which
4819 libraries should be built.  (However the package's maintainers can
4820 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
4821 macro, libtool, The Libtool Manual}.)
4823 @cindex suffix @file{.lo}, defined
4824 Because object files for shared and static libraries must be compiled
4825 differently, libtool is also used during compilation.  Object files
4826 built by libtool are called @dfn{libtool objects}: these are files
4827 using the @file{.lo} suffix.  Libtool libraries are built from these
4828 libtool objects.
4830 You should not assume anything about the structure of @file{.la} or
4831 @file{.lo} files and how libtool constructs them: this is libtool's
4832 concern, and the last thing one wants is to learn about libtool's
4833 guts.  However the existence of these files matters, because they are
4834 used as targets and dependencies in @file{Makefile}s rules when
4835 building libtool libraries.  There are situations where you may have
4836 to refer to these, for instance when expressing dependencies for
4837 building source files conditionally (@pxref{Conditional Libtool
4838 Sources}).
4840 @cindex @file{libltdl}, introduction
4842 People considering writing a plug-in system, with dynamically loaded
4843 modules, should look into @file{libltdl}: libtool's dlopening library
4844 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
4845 This offers a portable dlopening facility to load libtool libraries
4846 dynamically, and can also achieve static linking where unavoidable.
4848 Before we discuss how to use libtool with Automake in details, it
4849 should be noted that the libtool manual also has a section about how
4850 to use Automake with libtool (@pxref{Using Automake, , Using Automake
4851 with Libtool, libtool, The Libtool Manual}).
4853 @node Libtool Libraries
4854 @subsection Building Libtool Libraries
4856 @cindex @code{_LTLIBRARIES} primary, defined
4857 @cindex @code{LTLIBRARIES} primary, defined
4858 @cindex Primary variable, @code{LTLIBRARIES}
4859 @cindex Example of shared libraries
4860 @vindex lib_LTLIBRARIES
4861 @vindex pkglib_LTLIBRARIES
4862 @vindex _LTLIBRARIES
4864 Automake uses libtool to build libraries declared with the
4865 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
4866 list of libtool libraries to build.  For instance, to create a libtool
4867 library named @file{libgettext.la}, and install it in @code{libdir},
4868 write:
4870 @example
4871 lib_LTLIBRARIES = libgettext.la
4872 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
4873 @end example
4875 Automake predefines the variable @code{pkglibdir}, so you can use
4876 @code{pkglib_LTLIBRARIES} to install libraries in
4877 @samp{$(libdir)/@@PACKAGE@@/}.
4879 If @file{gettext.h} is a public header file that needs to be installed
4880 in order for people to use the library, it should be declared using a
4881 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
4882 Headers listed in the latter should be internal headers that are not
4883 part of the public interface.
4885 @example
4886 lib_LTLIBRARIES = libgettext.la
4887 libgettext_la_SOURCES = gettext.c @dots{}
4888 include_HEADERS = gettext.h @dots{}
4889 @end example
4891 A package can build and install such a library along with other
4892 programs that use it.  This dependency should be specified using
4893 @code{LDADD}.  The following example builds a program named
4894 @file{hello} that is linked with @file{libgettext.la}.
4896 @example
4897 lib_LTLIBRARIES = libgettext.la
4898 libgettext_la_SOURCES = gettext.c @dots{}
4900 bin_PROGRAMS = hello
4901 hello_SOURCES = hello.c @dots{}
4902 hello_LDADD = libgettext.la
4903 @end example
4905 @noindent
4906 Whether @file{hello} is statically or dynamically linked with
4907 @file{libgettext.la} is not yet known: this will depend on the
4908 configuration of libtool and the capabilities of the host.
4911 @node Conditional Libtool Libraries
4912 @subsection Building Libtool Libraries Conditionally
4913 @cindex libtool libraries, conditional
4914 @cindex conditional libtool libraries
4916 Like conditional programs (@pxref{Conditional Programs}), there are
4917 two main ways to build conditional libraries: using Automake
4918 conditionals or using Autoconf @code{AC_SUBST}itutions.
4920 The important implementation detail you have to be aware of is that
4921 the place where a library will be installed matters to libtool: it
4922 needs to be indicated @emph{at link-time} using the @option{-rpath}
4923 option.
4925 For libraries whose destination directory is known when Automake runs,
4926 Automake will automatically supply the appropriate @option{-rpath}
4927 option to libtool.  This is the case for libraries listed explicitly in
4928 some installable @code{_LTLIBRARIES} variables such as
4929 @code{lib_LTLIBRARIES}.
4931 However, for libraries determined at configure time (and thus
4932 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
4933 final installation directory.  For such libraries you must add the
4934 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
4935 hand.
4937 The examples below illustrate the differences between these two methods.
4939 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
4940 variable set at @file{./configure}-time to either @file{libfoo.la},
4941 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
4942 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
4943 relates to @file{libfoo.la} or @file{libbar.la} by the time it creates
4944 the link rule for these two libraries.  Therefore the @option{-rpath}
4945 argument must be explicitly supplied.
4947 @example
4948 EXTRA_LTLIBRARIES = libfoo.la libbar.la
4949 lib_LTLIBRARIES = $(WANTEDLIBS)
4950 libfoo_la_SOURCES = foo.c @dots{}
4951 libfoo_la_LDFLAGS = -rpath '$(libdir)'
4952 libbar_la_SOURCES = bar.c @dots{}
4953 libbar_la_LDFLAGS = -rpath '$(libdir)'
4954 @end example
4956 Here is how the same @file{Makefile.am} would look using Automake
4957 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
4958 Automake is able to compute the @option{-rpath} setting itself, because
4959 it's clear that both libraries will end up in @samp{$(libdir)} if they
4960 are installed.
4962 @example
4963 lib_LTLIBRARIES =
4964 if WANT_LIBFOO
4965 lib_LTLIBRARIES += libfoo.la
4966 endif
4967 if WANT_LIBBAR
4968 lib_LTLIBRARIES += libbar.la
4969 endif
4970 libfoo_la_SOURCES = foo.c @dots{}
4971 libbar_la_SOURCES = bar.c @dots{}
4972 @end example
4974 @node Conditional Libtool Sources
4975 @subsection Libtool Libraries with Conditional Sources
4977 Conditional compilation of sources in a library can be achieved in the
4978 same way as conditional compilation of sources in a program
4979 (@pxref{Conditional Sources}).  The only difference is that
4980 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
4981 should mention libtool objects (@file{.lo} files).
4983 So, to mimic the @file{hello} example from @ref{Conditional Sources},
4984 we could build a @file{libhello.la} library using either
4985 @file{hello-linux.c} or @file{hello-generic.c} with the following
4986 @file{Makefile.am}.
4988 @example
4989 lib_LTLIBRARIES = libhello.la
4990 libhello_la_SOURCES = hello-common.c
4991 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
4992 libhello_la_LIBADD = $(HELLO_SYSTEM)
4993 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
4994 @end example
4996 @noindent
4997 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
4998 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5000 Or we could simply use an Automake conditional as follows.
5002 @example
5003 lib_LTLIBRARIES = libhello.la
5004 libhello_la_SOURCES = hello-common.c
5005 if LINUX
5006 libhello_la_SOURCES += hello-linux.c
5007 else
5008 libhello_la_SOURCES += hello-generic.c
5009 endif
5010 @end example
5012 @node Libtool Convenience Libraries
5013 @subsection Libtool Convenience Libraries
5014 @cindex convenience libraries, libtool
5015 @cindex libtool convenience libraries
5016 @vindex noinst_LTLIBRARIES
5017 @vindex check_LTLIBRARIES
5019 Sometimes you want to build libtool libraries that should not be
5020 installed.  These are called @dfn{libtool convenience libraries} and
5021 are typically used to encapsulate many sublibraries, later gathered
5022 into one big installed library.
5024 Libtool convenience libraries are declared by directory-less variables
5025 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5026 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5027 not need an @option{-rpath} flag at link time (actually this is the only
5028 difference).
5030 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5031 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5032 @samp{make check}.  Finally, libraries listed in
5033 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5034 rules to build them, but if the library does not appear as a Makefile
5035 dependency anywhere it won't be built (this is why
5036 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5038 Here is a sample setup merging libtool convenience libraries from
5039 subdirectories into one main @file{libtop.la} library.
5041 @example
5042 # -- Top-level Makefile.am --
5043 SUBDIRS = sub1 sub2 @dots{}
5044 lib_LTLIBRARIES = libtop.la
5045 libtop_la_SOURCES =
5046 libtop_la_LIBADD = \
5047   sub1/libsub1.la \
5048   sub2/libsub2.la \
5049   @dots{}
5051 # -- sub1/Makefile.am --
5052 noinst_LTLIBRARIES = libsub1.la
5053 libsub1_la_SOURCES = @dots{}
5055 # -- sub2/Makefile.am --
5056 # showing nested convenience libraries
5057 SUBDIRS = sub2.1 sub2.2 @dots{}
5058 noinst_LTLIBRARIES = libsub2.la
5059 libsub2_la_SOURCES =
5060 libsub2_la_LIBADD = \
5061   sub21/libsub21.la \
5062   sub22/libsub22.la \
5063   @dots{}
5064 @end example
5066 When using such setup, beware that @command{automake} will assume
5067 @file{libtop.la} is to be linked with the C linker.  This is because
5068 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5069 default language.  If @code{libtop_la_SOURCES} was not empty,
5070 @command{automake} would select the linker as explained in @ref{How
5071 the Linker is Chosen}.
5073 If one of the sublibraries contains non-C source, it is important that
5074 the appropriate linker be chosen.  One way to achieve this is to
5075 pretend that there is such a non-C file among the sources of the
5076 library, thus forcing @command{automake} to select the appropriate
5077 linker.  Here is the top-level @file{Makefile} of our example updated
5078 to force C++ linking.
5080 @example
5081 SUBDIRS = sub1 sub2 @dots{}
5082 lib_LTLIBRARIES = libtop.la
5083 libtop_la_SOURCES =
5084 # Dummy C++ source to cause C++ linking.
5085 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5086 libtop_la_LIBADD = \
5087   sub1/libsub1.la \
5088   sub2/libsub2.la \
5089   @dots{}
5090 @end example
5092 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5093 files that might be compiled (this is mostly useful when doing
5094 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5095 Libtool Sources}), and the @code{nodist_} prefix means the listed
5096 sources are not to be distributed (@pxref{Program and Library
5097 Variables}).  In effect the file @file{dummy.cxx} does not need to
5098 exist in the source tree.  Of course if you have some real source file
5099 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5100 @code{nodist_EXTRA_libtop_la_SOURCES}.
5103 @node Libtool Modules
5104 @subsection Libtool Modules
5105 @cindex modules, libtool
5106 @cindex libtool modules
5107 @cindex @option{-module}, libtool
5109 These are libtool libraries meant to be dlopened.  They are
5110 indicated to libtool by passing @option{-module} at link-time.
5112 @example
5113 pkglib_LTLIBRARIES = mymodule.la
5114 mymodule_la_SOURCES = doit.c
5115 mymodule_la_LDFLAGS = -module
5116 @end example
5118 Ordinarily, Automake requires that a library's name starts with
5119 @code{lib}.  However, when building a dynamically loadable module you
5120 might wish to use a "nonstandard" name.  Automake will not complain
5121 about such nonstandard name if it knows the library being built is a
5122 libtool module, i.e., if @option{-module} explicitly appears in the
5123 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5124 variable when no per-library @code{_LDFLAGS} variable is defined).
5126 As always, @code{AC_SUBST} variables are black boxes to Automake since
5127 their values are not yet known when @command{automake} is run.
5128 Therefore if @option{-module} is set via such a variable, Automake
5129 cannot notice it and will proceed as if the library was an ordinary
5130 libtool library, with strict naming.
5132 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5133 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5135 @node Libtool Flags
5136 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5137 @cindex @code{_LIBADD}, libtool
5138 @cindex @code{_LDFLAGS}, libtool
5139 @cindex @code{_LIBTOOLFLAGS}, libtool
5140 @vindex AM_LIBTOOLFLAGS
5141 @vindex LIBTOOLFLAGS
5142 @vindex maude_LIBTOOLFLAGS
5144 As shown in previous sections, the @samp{@var{library}_LIBADD}
5145 variable should be used to list extra libtool objects (@file{.lo}
5146 files) or libtool libraries (@file{.la}) to add to @var{library}.
5148 The @samp{@var{library}_LDFLAGS} variable is the place to list
5149 additional libtool linking flags, such as @option{-version-info},
5150 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5151 libtool, The Libtool Manual}.
5153 The @command{libtool} command has two kinds of options: mode-specific
5154 options and generic options.  Mode-specific options such as the
5155 aforementioned linking flags should be lumped with the other flags
5156 passed to the tool invoked by @command{libtool} (hence the use of
5157 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5158 options include @option{--tag=@var{TAG}} and @option{--silent}
5159 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5160 Libtool Manual} for more options) should appear before the mode
5161 selection on the command line; in @file{Makefile.am}s they should
5162 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5164 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, the global
5165 @code{AM_LIBTOOLFLAGS} variable is used instead.
5167 These flags are passed to libtool after the @option{--tag=@var{TAG}}
5168 option computed by Automake (if any), so
5169 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is the
5170 good place to override or supplement the @option{--tag=@var{TAG}}
5171 setting.
5173 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5174 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5175 Variables Ordering}.  It allows users to run @samp{make
5176 LIBTOOLFLAGS=--silent}, for instance.
5179 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5180 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5181 @cindex @code{LTLIBOBJS}, special handling
5182 @cindex @code{LIBOBJS}, and Libtool
5183 @cindex @code{LTALLOCA}, special handling
5184 @cindex @code{ALLOCA}, and Libtool
5185 @vindex LTLIBOBJS
5186 @vindex LIBOBJS
5187 @vindex LTALLOCA
5188 @vindex ALLOCA
5189 @acindex AC_LIBOBJ
5191 Where an ordinary library might include @samp{$(LIBOBJS)} or
5192 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5193 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5194 the object files that libtool operates on do not necessarily end in
5195 @file{.o}.
5197 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5198 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5199 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5201 @node Libtool Issues
5202 @subsection Common Issues Related to Libtool's Use
5204 @subsubsection @samp{required file `./ltmain.sh' not found}
5205 @cindex @file{ltmain.sh} not found
5206 @cindex @command{libtoolize}, no longer run by @command{automake}
5207 @cindex @command{libtoolize} and @command{autoreconf}
5208 @cindex @command{autoreconf} and @command{libtoolize}
5209 @cindex @file{bootstrap.sh} and @command{autoreconf}
5210 @cindex @file{autogen.sh} and @command{autoreconf}
5212 Libtool comes with a tool called @command{libtoolize} that will
5213 install libtool's supporting files into a package.  Running this
5214 command will install @file{ltmain.sh}.  You should execute it before
5215 @command{aclocal} and @command{automake}.
5217 People upgrading old packages to newer autotools are likely to face
5218 this issue because older Automake versions used to call
5219 @command{libtoolize}.  Therefore old build scripts do not call
5220 @command{libtoolize}.
5222 Since Automake 1.6, it has been decided that running
5223 @command{libtoolize} was none of Automake's business.  Instead, that
5224 functionality has been moved into the @command{autoreconf} command
5225 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5226 The Autoconf Manual}).  If you do not want to remember what to run and
5227 when, just learn the @command{autoreconf} command.  Hopefully,
5228 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5229 a call to @command{autoreconf} should also free you from any similar
5230 incompatible change in the future.
5232 @subsubsection Objects @samp{created with both libtool and without}
5234 Sometimes, the same source file is used both to build a libtool
5235 library and to build another non-libtool target (be it a program or
5236 another library).
5238 Let's consider the following @file{Makefile.am}.
5240 @example
5241 bin_PROGRAMS = prog
5242 prog_SOURCES = prog.c foo.c @dots{}
5244 lib_LTLIBRARIES = libfoo.la
5245 libfoo_la_SOURCES = foo.c @dots{}
5246 @end example
5248 @noindent
5249 (In this trivial case the issue could be avoided by linking
5250 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5251 @code{prog_SOURCES}.  But let's assume we really want to keep
5252 @file{prog} and @file{libfoo.la} separate.)
5254 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5255 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5256 that in the course of creating @file{foo.lo}, libtool may erase (or
5257 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5259 Therefore, when Automake detects this situation it will complain
5260 with a message such as
5261 @example
5262 object `foo.$(OBJEXT)' created both with libtool and without
5263 @end example
5265 A workaround for this issue is to ensure that these two objects get
5266 different basenames.  As explained in @ref{renamed objects}, this
5267 happens automatically when per-targets flags are used.
5269 @example
5270 bin_PROGRAMS = prog
5271 prog_SOURCES = prog.c foo.c @dots{}
5272 prog_CFLAGS = $(AM_CFLAGS)
5274 lib_LTLIBRARIES = libfoo.la
5275 libfoo_la_SOURCES = foo.c @dots{}
5276 @end example
5278 @noindent
5279 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5280 when the @code{prog_CFLAGS} is defined, it is used instead of
5281 @code{AM_CFLAGS}.  However as a side effect it will cause
5282 @file{prog.c} and @file{foo.c} to be compiled as
5283 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5284 the issue.
5286 @node Program and Library Variables
5287 @section Program and Library Variables
5289 Associated with each program are a collection of variables that can be
5290 used to modify how that program is built.  There is a similar list of
5291 such variables for each library.  The canonical name of the program (or
5292 library) is used as a base for naming these variables.
5294 In the list below, we use the name ``maude'' to refer to the program or
5295 library.  In your @file{Makefile.am} you would replace this with the
5296 canonical name of your program.  This list also refers to ``maude'' as a
5297 program, but in general the same rules apply for both static and dynamic
5298 libraries; the documentation below notes situations where programs and
5299 libraries differ.
5301 @vtable @code
5302 @item maude_SOURCES
5303 This variable, if it exists, lists all the source files that are
5304 compiled to build the program.  These files are added to the
5305 distribution by default.  When building the program, Automake will cause
5306 each source file to be compiled to a single @file{.o} file (or
5307 @file{.lo} when using libtool).  Normally these object files are named
5308 after the source file, but other factors can change this.  If a file in
5309 the @code{_SOURCES} variable has an unrecognized extension, Automake
5310 will do one of two things with it.  If a suffix rule exists for turning
5311 files with the unrecognized extension into @file{.o} files, then
5312 automake will treat this file as it will any other source file
5313 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5314 ignored as though it were a header file.
5316 The prefixes @code{dist_} and @code{nodist_} can be used to control
5317 whether files listed in a @code{_SOURCES} variable are distributed.
5318 @code{dist_} is redundant, as sources are distributed by default, but it
5319 can be specified for clarity if desired.
5321 It is possible to have both @code{dist_} and @code{nodist_} variants of
5322 a given @code{_SOURCES} variable at once; this lets you easily
5323 distribute some files and not others, for instance:
5325 @example
5326 nodist_maude_SOURCES = nodist.c
5327 dist_maude_SOURCES = dist-me.c
5328 @end example
5330 By default the output file (on Unix systems, the @file{.o} file) will
5331 be put into the current build directory.  However, if the option
5332 @option{subdir-objects} is in effect in the current directory then the
5333 @file{.o} file will be put into the subdirectory named after the
5334 source file.  For instance, with @option{subdir-objects} enabled,
5335 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5336 people prefer this mode of operation.  You can specify
5337 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5338 @cindex Subdirectory, objects in
5339 @cindex Objects in subdirectory
5342 @item EXTRA_maude_SOURCES
5343 Automake needs to know the list of files you intend to compile
5344 @emph{statically}.  For one thing, this is the only way Automake has of
5345 knowing what sort of language support a given @file{Makefile.in}
5346 requires.  @footnote{There are other, more obscure reasons for
5347 this limitation as well.}  This means that, for example, you can't put a
5348 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5349 variable.  If you intend to conditionally compile source files and use
5350 @file{configure} to substitute the appropriate object names into, e.g.,
5351 @code{_LDADD} (see below), then you should list the corresponding source
5352 files in the @code{EXTRA_} variable.
5354 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5355 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5356 sources that may need to be built, but should not be distributed.
5358 @item maude_AR
5359 A static library is created by default by invoking @samp{$(AR)
5360 $(ARFLAGS)} followed by the name of the library and then the objects
5361 being put into the library.  You can override this by setting the
5362 @code{_AR} variable.  This is usually used with C++; some C++
5363 compilers require a special invocation in order to instantiate all the
5364 templates that should go into a library.  For instance, the SGI C++
5365 compiler likes this variable set like so:
5366 @example
5367 libmaude_a_AR = $(CXX) -ar -o
5368 @end example
5370 @item maude_LIBADD
5371 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5372 variable.  For instance, this should be used for objects determined by
5373 @command{configure} (@pxref{A Library}).
5375 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5376 to other libtool libraries.
5378 @item maude_LDADD
5379 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5380 @file{*.la}) can be added to a @emph{program} by listing them in the
5381 @code{_LDADD} variable.  For instance, this should be used for objects
5382 determined by @command{configure} (@pxref{Linking}).
5384 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5385 program-specific linker flags (except for @option{-l}, @option{-L},
5386 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5387 for this purpose.
5389 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5390 could link your program against the X libraries like so:
5392 @example
5393 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5394 @end example
5396 We recommend that you use @option{-l} and @option{-L} only when
5397 referring to third-party libraries, and give the explicit file names
5398 of any library built by your package.  Doing so will ensure that
5399 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5401 @item maude_LDFLAGS
5402 This variable is used to pass extra flags to the link step of a program
5403 or a shared library.  It overrides the global @code{AM_LDFLAGS} variable.
5405 @item maude_LIBTOOLFLAGS
5406 This variable is used to pass extra options to @command{libtool}.
5407 It overrides the global @code{AM_LIBTOOLFLAGS} variable.
5408 These options are output before @command{libtool}'s @option{--mode=@var{MODE}}
5409 option, so they should not be mode-specific options (those belong to
5410 the compiler or linker flags).  @xref{Libtool Flags}.
5412 @item maude_DEPENDENCIES
5413 It is also occasionally useful to have a target (program or library)
5414 depend on some other file that is not actually part of that target.
5415 This can be done using the @code{_DEPENDENCIES} variable.  Each
5416 targets depends on the contents of such a variable, but no further
5417 interpretation is done.
5419 Since these dependencies are associated to the link rule used to
5420 create the programs they should normally list files used by the link
5421 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5422 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5423 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5424 may need to add other kinds of files such as linker scripts, but
5425 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5426 some source file needs to be built before all the components of a
5427 program are built, consider using the @code{BUILT_SOURCES} variable
5428 (@pxref{Sources}).
5430 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5431 The automatically-assigned value is the contents of @code{_LDADD} or
5432 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5433 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5434 substitutions that are left in are only @samp{$(LIBOBJS)} and
5435 @samp{$(ALLOCA)}; these are left because it is known that they will not
5436 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5438 @code{_DEPENDENCIES} is more likely used to perform conditional
5439 compilation using an @code{AC_SUBST} variable that contains a list of
5440 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5441 Sources}.
5443 @item maude_LINK
5444 You can override the linker on a per-program basis.  By default the
5445 linker is chosen according to the languages used by the program.  For
5446 instance, a program that includes C++ source code would use the C++
5447 compiler to link.  The @code{_LINK} variable must hold the name of a
5448 command that can be passed all the @file{.o} file names as arguments.
5449 Note that the name of the underlying program is @emph{not} passed to
5450 @code{_LINK}; typically one uses @samp{$@@}:
5452 @example
5453 maude_LINK = $(CCLD) -magic -o $@@
5454 @end example
5456 @item maude_CCASFLAGS
5457 @itemx maude_CFLAGS
5458 @itemx maude_CPPFLAGS
5459 @itemx maude_CXXFLAGS
5460 @itemx maude_FFLAGS
5461 @itemx maude_GCJFLAGS
5462 @itemx maude_LFLAGS
5463 @itemx maude_OBJCFLAGS
5464 @itemx maude_RFLAGS
5465 @itemx maude_UPCFLAGS
5466 @itemx maude_YFLAGS
5467 @cindex per-target compilation flags, defined
5468 Automake allows you to set compilation flags on a per-program (or
5469 per-library) basis.  A single source file can be included in several
5470 programs, and it will potentially be compiled with different flags for
5471 each program.  This works for any language directly supported by
5472 Automake.  These @dfn{per-target compilation flags} are
5473 @samp{_CCASFLAGS},
5474 @samp{_CFLAGS},
5475 @samp{_CPPFLAGS},
5476 @samp{_CXXFLAGS},
5477 @samp{_FFLAGS},
5478 @samp{_GCJFLAGS},
5479 @samp{_LFLAGS},
5480 @samp{_OBJCFLAGS},
5481 @samp{_RFLAGS},
5482 @samp{_UPCFLAGS}, and
5483 @samp{_YFLAGS}.
5485 When using a per-target compilation flag, Automake will choose a
5486 different name for the intermediate object files.  Ordinarily a file
5487 like @file{sample.c} will be compiled to produce @file{sample.o}.
5488 However, if the program's @code{_CFLAGS} variable is set, then the
5489 object file will be named, for instance, @file{maude-sample.o}.  (See
5490 also @ref{renamed objects}.)  The use of per-target compilation flags
5491 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5492 from @file{configure.ac}.
5494 In compilations with per-target flags, the ordinary @samp{AM_} form of
5495 the flags variable is @emph{not} automatically included in the
5496 compilation (however, the user form of the variable @emph{is} included).
5497 So for instance, if you want the hypothetical @file{maude} compilations
5498 to also use the value of @code{AM_CFLAGS}, you would need to write:
5500 @example
5501 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5502 @end example
5504 @xref{Flag Variables Ordering}, for more discussion about the
5505 interaction between user variables, @samp{AM_} shadow variables, and
5506 per-target variables.
5508 @item maude_SHORTNAME
5509 On some platforms the allowable file names are very short.  In order to
5510 support these systems and per-target compilation flags at the same
5511 time, Automake allows you to set a ``short name'' that will influence
5512 how intermediate object files are named.  For instance, in the following
5513 example,
5515 @example
5516 bin_PROGRAMS = maude
5517 maude_CPPFLAGS = -DSOMEFLAG
5518 maude_SHORTNAME = m
5519 maude_SOURCES = sample.c @dots{}
5520 @end example
5522 @noindent
5523 the object file would be named @file{m-sample.o} rather than
5524 @file{maude-sample.o}.
5526 This facility is rarely needed in practice,
5527 and we recommend avoiding it until you find it is required.
5528 @end vtable
5530 @node Default _SOURCES
5531 @section Default @code{_SOURCES}
5533 @vindex _SOURCES
5534 @vindex SOURCES
5535 @cindex @code{_SOURCES}, default
5536 @cindex default @code{_SOURCES}
5538 @code{_SOURCES} variables are used to specify source files of programs
5539 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5540 libraries (@pxref{A Shared Library}).
5542 When no such variable is specified for a target, Automake will define
5543 one itself.  The default is to compile a single C file whose base name
5544 is the name of the target itself, with any extension replaced by
5545 @file{.c}.  (Defaulting to C is terrible but we are stuck with it for
5546 historical reasons.)
5548 For example if you have the following somewhere in your
5549 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5551 @example
5552 lib_LIBRARIES = libfoo.a sub/libc++.a
5553 @end example
5555 @noindent
5556 @file{libfoo.a} will be built using a default source file named
5557 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5558 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5559 would be built from @file{sub_libc___a.c}, i.e., the default source
5560 was the canonized name of the target, with @file{.c} appended.
5561 We believe the new behavior is more sensible, but for backward
5562 compatibility automake will use the old name if a file or a rule
5563 with that name exist.)
5565 @cindex @code{check_PROGRAMS} example
5566 @vindex check_PROGRAMS
5567 Default sources are mainly useful in test suites, when building many
5568 tests programs each from a single source.  For instance, in
5570 @example
5571 check_PROGRAMS = test1 test2 test3
5572 @end example
5574 @noindent
5575 @file{test1}, @file{test2}, and @file{test3} will be built
5576 from @file{test1.c}, @file{test2.c}, and @file{test3.c}.
5578 @cindex Libtool modules, default source example
5579 @cindex default source, Libtool modules example
5580 Another case where is this convenient is building many Libtool modules
5581 (@file{moduleN.la}), each defined in its own file (@file{moduleN.c}).
5583 @example
5584 AM_LDFLAGS = -module
5585 lib_LTLIBRARIES = module1.la module2.la module3.la
5586 @end example
5588 @cindex empty @code{_SOURCES}
5589 @cindex @code{_SOURCES}, empty
5590 Finally, there is one situation where this default source computation
5591 needs to be avoided: when a target should not be built from sources.
5592 We already saw such an example in @ref{true}; this happens when all
5593 the constituents of a target have already been compiled and need just
5594 to be combined using a @code{_LDADD} variable.  Then it is necessary
5595 to define an empty @code{_SOURCES} variable, so that automake does not
5596 compute a default.
5598 @example
5599 bin_PROGRAMS = target
5600 target_SOURCES =
5601 target_LDADD = libmain.a libmisc.a
5602 @end example
5604 @node LIBOBJS
5605 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5607 @cindex @code{LIBOBJS}, example
5608 @cindex @code{ALLOCA}, example
5609 @cindex @code{LIBOBJS}, special handling
5610 @cindex @code{ALLOCA}, special handling
5611 @vindex LTLIBOBJS
5612 @vindex LIBOBJS
5613 @vindex LTALLOCA
5614 @vindex ALLOCA
5616 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5617 files that should be compiled into the project to provide an
5618 implementation for functions that are missing or broken on the host
5619 system.  They are substituted by @file{configure}.
5621 @acindex AC_LIBOBJ
5623 These variables are defined by Autoconf macros such as
5624 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5625 Generic Function Checks, autoconf, The Autoconf Manual}), or
5626 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5627 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5628 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5629 populate @samp{$(LIBOBJS)}.
5631 @acindex AC_LIBSOURCE
5633 Using these variables is very similar to doing conditional compilation
5634 using @code{AC_SUBST} variables, as described in @ref{Conditional
5635 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5636 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5637 variable, or to the @samp{*_LIBADD} variable when building a library.
5638 However there is no need to list the corresponding sources in
5639 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5640 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5641 dependencies, and it will discover the list of corresponding source
5642 files automatically (by tracing the invocations of the
5643 @code{AC_LIBSOURCE} Autoconf macros).
5645 These variables are usually used to build a portability library that
5646 is linked with all the programs of the project.  We now review a
5647 sample setup.  First, @file{configure.ac} contains some checks that
5648 affect either @code{LIBOBJS} or @code{ALLOCA}.
5650 @example
5651 # configure.ac
5652 @dots{}
5653 AC_CONFIG_LIBOBJ_DIR([lib])
5654 @dots{}
5655 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5656 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5657 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5658 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5659 @dots{}
5660 AC_CONFIG_FILES([
5661   lib/Makefile
5662   src/Makefile
5664 AC_OUTPUT
5665 @end example
5667 @acindex AC_CONFIG_LIBOBJ_DIR
5669 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
5670 of these object files are to be found in the @file{lib/} directory.
5671 Automake can also use this information, otherwise it expects the
5672 source files are to be in the directory where the @samp{$(LIBOBJS)}
5673 and @samp{$(ALLOCA)} variables are used.
5675 The @file{lib/} directory should therefore contain @file{malloc.c},
5676 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
5677 @file{Makefile.am}:
5679 @example
5680 # lib/Makefile.am
5682 noinst_LIBRARIES = libcompat.a
5683 libcompat_a_SOURCES =
5684 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5685 @end example
5687 The library can have any name, of course, and anyway it is not going
5688 to be installed: it just holds the replacement versions of the missing
5689 or broken functions so we can later link them in.  In many projects
5690 also include extra functions, specific to the project, in that
5691 library: they are simply added on the @code{_SOURCES} line.
5693 @cindex Empty libraries and @samp{$(LIBOBJS)}
5694 @cindex @samp{$(LIBOBJS)} and empty libraries
5695 There is a small trap here, though: @samp{$(LIBOBJS)} and
5696 @samp{$(ALLOCA)} might be empty, and building an empty library is not
5697 portable.  You should ensure that there is always something to put in
5698 @file{libcompat.a}.  Most projects will also add some utility
5699 functions in that directory, and list them in
5700 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
5701 be empty.
5703 Finally here is how this library could be used from the @file{src/}
5704 directory.
5706 @example
5707 # src/Makefile.am
5709 # Link all programs in this directory with libcompat.a
5710 LDADD = ../lib/libcompat.a
5712 bin_PROGRAMS = tool1 tool2 @dots{}
5713 tool1_SOURCES = @dots{}
5714 tool2_SOURCES = @dots{}
5715 @end example
5717 When option @option{subdir-objects} is not used, as in the above
5718 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
5719 be used in the directory where their sources lie.  E.g., here it would
5720 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
5721 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
5722 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
5723 in other directories.  For instance @file{src/Makefile.am} could be
5724 changed as follows.
5726 @example
5727 # src/Makefile.am
5729 AUTOMAKE_OPTIONS = subdir-objects
5730 LDADD = $(LIBOBJS) $(ALLOCA)
5732 bin_PROGRAMS = tool1 tool2 @dots{}
5733 tool1_SOURCES = @dots{}
5734 tool2_SOURCES = @dots{}
5735 @end example
5737 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
5738 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
5739 Libtool libraries (where the expected object extension is @file{.lo}):
5740 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
5742 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
5743 be defined by hand (as in the past), however at the time of writing
5744 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
5745 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
5746 autoconf, The Autoconf Manual}.
5749 @node Program variables
5750 @section Variables used when building a program
5752 Occasionally it is useful to know which @file{Makefile} variables
5753 Automake uses for compilations; for instance, you might need to do your
5754 own compilation in some special cases.
5756 Some variables are inherited from Autoconf; these are @code{CC},
5757 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
5758 @code{LIBS}.
5759 @vindex CC
5760 @vindex CFLAGS
5761 @vindex CPPFLAGS
5762 @vindex DEFS
5763 @vindex LDFLAGS
5764 @vindex LIBS
5766 There are some additional variables that Automake defines on its own:
5768 @vtable @code
5769 @item AM_CPPFLAGS
5770 The contents of this variable are passed to every compilation that invokes
5771 the C preprocessor; it is a list of arguments to the preprocessor.  For
5772 instance, @option{-I} and @option{-D} options should be listed here.
5774 Automake already provides some @option{-I} options automatically, in a
5775 separate variable that is also passed to every compilation that invokes
5776 the C preprocessor.  In particular it generates @samp{-I.},
5777 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
5778 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS} or
5779 @code{AM_CONFIG_HEADER}).  You can disable the default @option{-I}
5780 options using the @option{nostdinc} option.
5782 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
5783 per-library) @code{_CPPFLAGS} variable if it is defined.
5785 @item INCLUDES
5786 This does the same job as @code{AM_CPPFLAGS} (or any per-target
5787 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
5788 same functionality.  This variable is deprecated; we suggest using
5789 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
5791 @item AM_CFLAGS
5792 This is the variable the @file{Makefile.am} author can use to pass
5793 in additional C compiler flags.  It is more fully documented elsewhere.
5794 In some situations, this is not used, in preference to the
5795 per-executable (or per-library) @code{_CFLAGS}.
5797 @item COMPILE
5798 This is the command used to actually compile a C source file.  The
5799 file name is appended to form the complete command line.
5801 @item AM_LDFLAGS
5802 This is the variable the @file{Makefile.am} author can use to pass
5803 in additional linker flags.  In some situations, this is not used, in
5804 preference to the per-executable (or per-library) @code{_LDFLAGS}.
5806 @item LINK
5807 This is the command used to actually link a C program.  It already
5808 includes @samp{-o $@@} and the usual variable references (for instance,
5809 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
5810 and libraries to link in.
5811 @end vtable
5814 @node Yacc and Lex
5815 @section Yacc and Lex support
5817 Automake has somewhat idiosyncratic support for Yacc and Lex.
5819 Automake assumes that the @file{.c} file generated by @command{yacc}
5820 (or @command{lex}) should be named using the basename of the input
5821 file.  That is, for a yacc source file @file{foo.y}, Automake will
5822 cause the intermediate file to be named @file{foo.c} (as opposed to
5823 @file{y.tab.c}, which is more traditional).
5825 The extension of a yacc source file is used to determine the extension
5826 of the resulting C or C++ file.  Files with the extension @file{.y}
5827 will be turned into @file{.c} files; likewise, @file{.yy} will become
5828 @file{.cc}; @file{.y++}, @file{c++}; @file{.yxx}, @file{.cxx}; and
5829 @file{.ypp}, @file{.cpp}.
5831 Likewise, lex source files can be used to generate C or C++; the
5832 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
5833 @file{.lpp} are recognized.
5835 You should never explicitly mention the intermediate (C or C++) file
5836 in any @code{SOURCES} variable; only list the source file.
5838 The intermediate files generated by @command{yacc} (or @command{lex})
5839 will be included in any distribution that is made.  That way the user
5840 doesn't need to have @command{yacc} or @command{lex}.
5842 If a @command{yacc} source file is seen, then your @file{configure.ac} must
5843 define the variable @code{YACC}.  This is most easily done by invoking
5844 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
5845 Program Checks, autoconf, The Autoconf Manual}).
5847 @vindex YFLAGS
5848 @vindex AM_YFLAGS
5849 When @code{yacc} is invoked, it is passed @code{YFLAGS} and
5850 @code{AM_YFLAGS}.  The former is a user variable and the latter is
5851 intended for the @file{Makefile.am} author.
5853 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
5854 @command{yacc}.  Automake knows what this means and will automatically
5855 adjust its rules to update and distribute the header file built by
5856 @samp{yacc -d}.  What Automake cannot guess, though, is where this
5857 header will be used: it is up to you to ensure the header gets built
5858 before it is first used.  Typically this is necessary in order for
5859 dependency tracking to work when the header is included by another
5860 file.  The common solution is listing the header file in
5861 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
5863 @example
5864 BUILT_SOURCES = parser.h
5865 AM_YFLAGS = -d
5866 bin_PROGRAMS = foo
5867 foo_SOURCES = @dots{} parser.y @dots{}
5868 @end example
5870 If a @command{lex} source file is seen, then your @file{configure.ac}
5871 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
5872 to do this (@pxref{Particular Programs, , Particular Program Checks,
5873 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
5874 (@pxref{Macros}) is recommended.
5876 @vindex LFLAGS
5877 @vindex AM_LFLAGS
5878 When @command{lex} is invoked, it is passed @code{LFLAGS} and
5879 @code{AM_LFLAGS}.  The former is a user variable and the latter is
5880 intended for the @file{Makefile.am} author.
5882 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
5883 rebuild rule for distributed Yacc and Lex sources are only used when
5884 @code{maintainer-mode} is enabled, or when the files have been erased.
5886 @cindex @command{ylwrap}
5887 @cindex @command{yacc}, multiple parsers
5888 @cindex Multiple @command{yacc} parsers
5889 @cindex Multiple @command{lex} lexers
5890 @cindex @command{lex}, multiple lexers
5892 When @command{lex} or @command{yacc} sources are used, @code{automake
5893 -i} automatically installs an auxiliary program called
5894 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
5895 program is used by the build rules to rename the output of these
5896 tools, and makes it possible to include multiple @command{yacc} (or
5897 @command{lex}) source files in a single directory.  (This is necessary
5898 because yacc's output file name is fixed, and a parallel make could
5899 conceivably invoke more than one instance of @command{yacc}
5900 simultaneously.)
5902 For @command{yacc}, simply managing locking is insufficient.  The output of
5903 @command{yacc} always uses the same symbol names internally, so it isn't
5904 possible to link two @command{yacc} parsers into the same executable.
5906 We recommend using the following renaming hack used in @command{gdb}:
5907 @example
5908 #define yymaxdepth c_maxdepth
5909 #define yyparse c_parse
5910 #define yylex   c_lex
5911 #define yyerror c_error
5912 #define yylval  c_lval
5913 #define yychar  c_char
5914 #define yydebug c_debug
5915 #define yypact  c_pact
5916 #define yyr1    c_r1
5917 #define yyr2    c_r2
5918 #define yydef   c_def
5919 #define yychk   c_chk
5920 #define yypgo   c_pgo
5921 #define yyact   c_act
5922 #define yyexca  c_exca
5923 #define yyerrflag c_errflag
5924 #define yynerrs c_nerrs
5925 #define yyps    c_ps
5926 #define yypv    c_pv
5927 #define yys     c_s
5928 #define yy_yys  c_yys
5929 #define yystate c_state
5930 #define yytmp   c_tmp
5931 #define yyv     c_v
5932 #define yy_yyv  c_yyv
5933 #define yyval   c_val
5934 #define yylloc  c_lloc
5935 #define yyreds  c_reds
5936 #define yytoks  c_toks
5937 #define yylhs   c_yylhs
5938 #define yylen   c_yylen
5939 #define yydefred c_yydefred
5940 #define yydgoto c_yydgoto
5941 #define yysindex c_yysindex
5942 #define yyrindex c_yyrindex
5943 #define yygindex c_yygindex
5944 #define yytable  c_yytable
5945 #define yycheck  c_yycheck
5946 #define yyname   c_yyname
5947 #define yyrule   c_yyrule
5948 @end example
5950 For each define, replace the @samp{c_} prefix with whatever you like.
5951 These defines work for @command{bison}, @command{byacc}, and
5952 traditional @code{yacc}s.  If you find a parser generator that uses a
5953 symbol not covered here, please report the new name so it can be added
5954 to the list.
5957 @node C++ Support
5958 @section C++ Support
5960 @cindex C++ support
5961 @cindex Support for C++
5963 Automake includes full support for C++.
5965 Any package including C++ code must define the output variable
5966 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
5967 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
5968 Program Checks, autoconf, The Autoconf Manual}).
5970 A few additional variables are defined when a C++ source file is seen:
5972 @vtable @code
5973 @item CXX
5974 The name of the C++ compiler.
5976 @item CXXFLAGS
5977 Any flags to pass to the C++ compiler.
5979 @item AM_CXXFLAGS
5980 The maintainer's variant of @code{CXXFLAGS}.
5982 @item CXXCOMPILE
5983 The command used to actually compile a C++ source file.  The file name
5984 is appended to form the complete command line.
5986 @item CXXLINK
5987 The command used to actually link a C++ program.
5988 @end vtable
5991 @node Objective C Support
5992 @section Objective C Support
5994 @cindex Objective C support
5995 @cindex Support for Objective C
5997 Automake includes some support for Objective C.
5999 Any package including Objective C code must define the output variable
6000 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6001 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6002 Program Checks, autoconf, The Autoconf Manual}).
6004 A few additional variables are defined when an Objective C source file
6005 is seen:
6007 @vtable @code
6008 @item OBJC
6009 The name of the Objective C compiler.
6011 @item OBJCFLAGS
6012 Any flags to pass to the Objective C compiler.
6014 @item AM_OBJCFLAGS
6015 The maintainer's variant of @code{OBJCFLAGS}.
6017 @item OBJCCOMPILE
6018 The command used to actually compile a Objective C source file.  The
6019 file name is appended to form the complete command line.
6021 @item OBJCLINK
6022 The command used to actually link a Objective C program.
6023 @end vtable
6026 @node Unified Parallel C Support
6027 @section Unified Parallel C Support
6029 @cindex Unified Parallel C support
6030 @cindex Support for Unified Parallel C
6032 Automake includes some support for Unified Parallel C.
6034 Any package including Unified Parallel C code must define the output
6035 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6036 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public macros}).
6038 A few additional variables are defined when an Unified Parallel C
6039 source file is seen:
6041 @vtable @code
6042 @item UPC
6043 The name of the Unified Parallel C compiler.
6045 @item UPCFLAGS
6046 Any flags to pass to the Unified Parallel C compiler.
6048 @item AM_UPCFLAGS
6049 The maintainer's variant of @code{UPCFLAGS}.
6051 @item UPCCOMPILE
6052 The command used to actually compile a Unified Parallel C source file.
6053 The file name is appended to form the complete command line.
6055 @item UPCLINK
6056 The command used to actually link a Unified Parallel C program.
6057 @end vtable
6060 @node Assembly Support
6061 @section Assembly Support
6063 Automake includes some support for assembly code.  There are two forms
6064 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6065 (@file{*.S} or @file{*.sx}).
6067 @vindex CCAS
6068 @vindex CCASFLAGS
6069 @vindex CPPFLAGS
6070 @vindex AM_CCASFLAGS
6071 @vindex AM_CPPFLAGS
6072 The variable @code{CCAS} holds the name of the compiler used to build
6073 assembly code.  This compiler must work a bit like a C compiler; in
6074 particular it must accept @option{-c} and @option{-o}.  The values of
6075 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6076 definition) is passed to the compilation.  For preprocessed files,
6077 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6078 and @code{AM_CPPFLAGS} are also used.
6080 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6081 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6082 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6083 flags), but you are free to define these variables by other means.
6085 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6086 @command{automake} as being files containing assembly code.
6089 @node Fortran 77 Support
6090 @comment  node-name,  next,  previous,  up
6091 @section Fortran 77 Support
6093 @cindex Fortran 77 support
6094 @cindex Support for Fortran 77
6096 Automake includes full support for Fortran 77.
6098 Any package including Fortran 77 code must define the output variable
6099 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6100 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6101 Program Checks, autoconf, The Autoconf Manual}).
6103 A few additional variables are defined when a Fortran 77 source file is
6104 seen:
6106 @vtable @code
6108 @item F77
6109 The name of the Fortran 77 compiler.
6111 @item FFLAGS
6112 Any flags to pass to the Fortran 77 compiler.
6114 @item AM_FFLAGS
6115 The maintainer's variant of @code{FFLAGS}.
6117 @item RFLAGS
6118 Any flags to pass to the Ratfor compiler.
6120 @item AM_RFLAGS
6121 The maintainer's variant of @code{RFLAGS}.
6123 @item F77COMPILE
6124 The command used to actually compile a Fortran 77 source file.  The file
6125 name is appended to form the complete command line.
6127 @item FLINK
6128 The command used to actually link a pure Fortran 77 program or shared
6129 library.
6131 @end vtable
6133 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6134 addition to compiling them@footnote{Much, if not most, of the
6135 information in the following sections pertaining to preprocessing
6136 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6137 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6138 also contains some support for creating programs and shared libraries
6139 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6140 Fortran 77 With C and C++}).
6142 These issues are covered in the following sections.
6144 @menu
6145 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6146 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6147 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6148 @end menu
6151 @node Preprocessing Fortran 77
6152 @comment  node-name,  next,  previous,  up
6153 @subsection Preprocessing Fortran 77
6155 @cindex Preprocessing Fortran 77
6156 @cindex Fortran 77, Preprocessing
6157 @cindex Ratfor programs
6159 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6160 rule runs just the preprocessor to convert a preprocessable Fortran 77
6161 or Ratfor source file into a strict Fortran 77 source file.  The precise
6162 command used is as follows:
6164 @table @file
6166 @item .F
6167 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6168 $(AM_FFLAGS) $(FFLAGS)}
6170 @item .r
6171 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6173 @end table
6176 @node Compiling Fortran 77 Files
6177 @comment  node-name,  next,  previous,  up
6178 @subsection Compiling Fortran 77 Files
6180 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6181 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6182 is as follows:
6184 @table @file
6186 @item .f
6187 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6189 @item .F
6190 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6191 $(AM_FFLAGS) $(FFLAGS)}
6193 @item .r
6194 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6196 @end table
6199 @node Mixing Fortran 77 With C and C++
6200 @comment  node-name,  next,  previous,  up
6201 @subsection Mixing Fortran 77 With C and C++
6203 @cindex Fortran 77, mixing with C and C++
6204 @cindex Mixing Fortran 77 with C and C++
6205 @cindex Linking Fortran 77 with C and C++
6206 @cindex cfortran
6207 @cindex Mixing Fortran 77 with C and/or C++
6209 Automake currently provides @emph{limited} support for creating programs
6210 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6211 However, there are many other issues related to mixing Fortran 77 with
6212 other languages that are @emph{not} (currently) handled by Automake, but
6213 that are handled by other packages@footnote{For example,
6214 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6215 addresses all of these inter-language issues, and runs under nearly all
6216 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6217 @command{cfortran} is not yet Free Software, but it will be in the next
6218 major release.}.
6220 @page
6221 Automake can help in two ways:
6223 @enumerate
6224 @item
6225 Automatic selection of the linker depending on which combinations of
6226 source code.
6228 @item
6229 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6230 @option{-l}) to pass to the automatically selected linker in order to link
6231 in the appropriate Fortran 77 intrinsic and run-time libraries.
6233 @cindex @code{FLIBS}, defined
6234 @vindex FLIBS
6235 These extra Fortran 77 linker flags are supplied in the output variable
6236 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
6237 supplied with newer versions of Autoconf (Autoconf version 2.13 and
6238 later).  @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
6239 Autoconf}.
6240 @end enumerate
6242 If Automake detects that a program or shared library (as mentioned in
6243 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6244 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6245 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6246 @file{configure.ac}, and that either @code{$(FLIBS)}
6247 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6248 (for shared libraries) variables.  It is the responsibility of the
6249 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6250 appears in the appropriate @code{_LDADD} or
6251 @code{_LIBADD} variable.
6253 @cindex Mixed language example
6254 @cindex Example, mixed language
6256 For example, consider the following @file{Makefile.am}:
6258 @example
6259 bin_PROGRAMS = foo
6260 foo_SOURCES  = main.cc foo.f
6261 foo_LDADD    = libfoo.la $(FLIBS)
6263 pkglib_LTLIBRARIES = libfoo.la
6264 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6265 libfoo_la_LIBADD   = $(FLIBS)
6266 @end example
6268 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6269 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6270 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6271 Automake would have issued a warning.
6274 @page
6275 @menu
6276 * How the Linker is Chosen::    Automatic linker selection
6277 @end menu
6279 @node How the Linker is Chosen
6280 @comment  node-name,  next,  previous,  up
6281 @subsubsection How the Linker is Chosen
6283 @cindex Automatic linker selection
6284 @cindex Selecting the linker automatically
6286 When a program or library mixes several languages, Automake choose the
6287 linker according to the following priorities.  (The names in
6288 parentheses are the variables containing the link command.)
6290 @enumerate
6291 @item
6292 @vindex GCJLINK
6293 Native Java (@code{GCJLINK})
6294 @item
6295 @vindex CXXLINK
6296 C++ (@code{CXXLINK})
6297 @item
6298 @vindex F77LINK
6299 Fortran 77 (@code{F77LINK})
6300 @item
6301 @vindex FCLINK
6302 Fortran (@code{FCLINK})
6303 @item
6304 @vindex OBJCLINK
6305 Objective C (@code{OBJCLINK})
6306 @item
6307 @vindex UPCLINK
6308 Unified Parallel C (@code{UPCLINK})
6309 @item
6310 @vindex LINK
6311 C (@code{LINK})
6312 @end enumerate
6314 For example, if Fortran 77, C and C++ source code is compiled
6315 into a program, then the C++ linker will be used.  In this case, if the
6316 C or Fortran 77 linkers required any special libraries that weren't
6317 included by the C++ linker, then they must be manually added to an
6318 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6319 @file{Makefile.am}.
6321 Automake only looks at the file names listed in @file{_SOURCES}
6322 variables to choose the linker, and defaults to the C linker.
6323 Sometimes this is inconvenient because you are linking against a
6324 library written in another language and would like to set the linker
6325 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6326 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6329 @node Fortran 9x Support
6330 @comment  node-name,  next,  previous,  up
6331 @section Fortran 9x Support
6333 @cindex Fortran 9x support
6334 @cindex Support for Fortran 9x
6336 Automake includes support for Fortran 9x.
6338 Any package including Fortran 9x code must define the output variable
6339 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6340 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6341 Program Checks, autoconf, The Autoconf Manual}).
6343 A few additional variables are defined when a Fortran 9x source file is
6344 seen:
6346 @vtable @code
6348 @item FC
6349 The name of the Fortran 9x compiler.
6351 @item FCFLAGS
6352 Any flags to pass to the Fortran 9x compiler.
6354 @item AM_FCFLAGS
6355 The maintainer's variant of @code{FCFLAGS}.
6357 @item FCCOMPILE
6358 The command used to actually compile a Fortran 9x source file.  The file
6359 name is appended to form the complete command line.
6361 @item FCLINK
6362 The command used to actually link a pure Fortran 9x program or shared
6363 library.
6365 @end vtable
6367 @menu
6368 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6369 @end menu
6371 @node Compiling Fortran 9x Files
6372 @comment  node-name,  next,  previous,  up
6373 @subsection Compiling Fortran 9x Files
6375 @file{@var{N}.o} is made automatically from @file{@var{N}.f90},
6376 @file{@var{N}.f95}, @file{@var{N}.f03}, or @file{@var{N}.f08}
6377 by running the Fortran 9x compiler.  The precise command used
6378 is as follows:
6380 @table @file
6382 @item .f90
6383 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6385 @item .f95
6386 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6388 @item .f03
6389 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6391 @item .f08
6392 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6394 @end table
6396 @node Java Support
6397 @comment  node-name,  next,  previous,  up
6398 @section Java Support
6400 @cindex Java support
6401 @cindex Support for Java
6403 Automake includes support for compiled Java, using @command{gcj}, the Java
6404 front end to the GNU Compiler Collection.
6406 Any package including Java code to be compiled must define the output
6407 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6408 must also be defined somehow (either in @file{configure.ac} or
6409 @file{Makefile.am}).  The simplest way to do this is to use the
6410 @code{AM_PROG_GCJ} macro.
6412 @vindex GCJFLAGS
6414 By default, programs including Java source files are linked with
6415 @command{gcj}.
6417 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6418 compilation invoking @command{gcj} (in its role as an ahead-of-time
6419 compiler, when invoking it to create @file{.class} files,
6420 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6421 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6422 the user variable @code{GCJFLAGS}, should be used.
6424 @vindex AM_GCJFLAGS
6426 @command{gcj} can be used to compile @file{.java}, @file{.class},
6427 @file{.zip}, or @file{.jar} files.
6429 When linking, @command{gcj} requires that the main class be specified
6430 using the @option{--main=} option.  The easiest way to do this is to use
6431 the @code{_LDFLAGS} variable for the program.
6434 @node Support for Other Languages
6435 @comment  node-name,  next,  previous,  up
6436 @section Support for Other Languages
6438 Automake currently only includes full support for C, C++ (@pxref{C++
6439 Support}), Objective C (@pxref{Objective C Support}), Fortran 77
6440 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6441 and Java (@pxref{Java Support}).  There is only rudimentary support for other
6442 languages, support for which will be improved based on user demand.
6444 Some limited support for adding your own languages is available via the
6445 suffix rule handling (@pxref{Suffixes}).
6448 @node ANSI
6449 @section Automatic de-ANSI-fication
6451 @cindex de-ANSI-fication, defined
6453 The features described in this section are obsolete; you should not
6454 used any of them in new code, and they may be withdrawn in future
6455 Automake releases.
6457 When the C language was standardized in 1989, there was a long
6458 transition period where package developers needed to worry about
6459 porting to older systems that did not support ANSI C by default.
6460 These older systems are no longer in practical use and are no longer
6461 supported by their original suppliers, so developers need not worry
6462 about this problem any more.
6464 Automake allows you to write packages that are portable to K&R C by
6465 @dfn{de-ANSI-fying} each source file before the actual compilation takes
6466 place.
6468 @vindex AUTOMAKE_OPTIONS
6469 @opindex ansi2knr
6471 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
6472 (@pxref{Options}) contains the option @option{ansi2knr} then code to
6473 handle de-ANSI-fication is inserted into the generated
6474 @file{Makefile.in}.
6476 This causes each C source file in the directory to be treated as ANSI C@.
6477 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
6478 is available, the @command{ansi2knr} program is used to convert the source
6479 files into K&R C, which is then compiled.
6481 The @command{ansi2knr} program is simple-minded.  It assumes the source
6482 code will be formatted in a particular way; see the @command{ansi2knr} man
6483 page for details.
6485 @acindex AM_C_PROTOTYPES
6486 Support for the obsolete de-ANSI-fication feature
6487 requires the source files @file{ansi2knr.c}
6488 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
6489 these files are distributed with Automake.  Also, the package
6490 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
6491 (@pxref{Macros}).
6493 Automake also handles finding the @command{ansi2knr} support files in some
6494 other directory in the current package.  This is done by prepending the
6495 relative path to the appropriate directory to the @command{ansi2knr}
6496 option.  For instance, suppose the package has ANSI C code in the
6497 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
6498 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
6499 @file{src/Makefile.am}:
6501 @example
6502 AUTOMAKE_OPTIONS = ../lib/ansi2knr
6503 @end example
6505 If no directory prefix is given, the files are assumed to be in the
6506 current directory.
6508 Note that automatic de-ANSI-fication will not work when the package is
6509 being built for a different host architecture.  That is because automake
6510 currently has no way to build @command{ansi2knr} for the build machine.
6512 @c FIXME: this paragraph might be better moved to an `upgrading' section.
6513 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
6514 @cindex @code{LIBOBJS} and @code{ansi2knr}
6515 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
6516 @cindex @code{ansi2knr} and @code{LIBOBJS}
6517 Using @code{LIBOBJS} with source de-ANSI-fication used to require
6518 hand-crafted code in @file{configure} to append @samp{$U} to basenames
6519 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
6520 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
6521 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
6522 vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual})
6524 @node Dependencies
6525 @section Automatic dependency tracking
6527 As a developer it is often painful to continually update the
6528 @file{Makefile.in} whenever the include-file dependencies change in a
6529 project.  Automake supplies a way to automatically track dependency
6530 changes (@pxref{Dependency Tracking}).
6532 @cindex Dependency tracking
6533 @cindex Automatic dependency tracking
6535 Automake always uses complete dependencies for a compilation,
6536 including system headers.  Automake's model is that dependency
6537 computation should be a side effect of the build.  To this end,
6538 dependencies are computed by running all compilations through a
6539 special wrapper program called @command{depcomp}.  @command{depcomp}
6540 understands how to coax many different C and C++ compilers into
6541 generating dependency information in the format it requires.
6542 @samp{automake -a} will install @command{depcomp} into your source
6543 tree for you.  If @command{depcomp} can't figure out how to properly
6544 invoke your compiler, dependency tracking will simply be disabled for
6545 your build.
6547 @cindex @command{depcomp}
6549 Experience with earlier versions of Automake (@pxref{Dependency
6550 Tracking Evolution}) taught us that it is not reliable to generate
6551 dependencies only on the maintainer's system, as configurations vary
6552 too much.  So instead Automake implements dependency tracking at build
6553 time.
6555 Automatic dependency tracking can be suppressed by putting
6556 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6557 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6558 (this should be the preferred way).  Or, you can invoke @command{automake}
6559 with the @option{-i} option.  Dependency tracking is enabled by default.
6561 @vindex AUTOMAKE_OPTIONS
6562 @opindex no-dependencies
6564 The person building your package also can choose to disable dependency
6565 tracking by configuring with @option{--disable-dependency-tracking}.
6567 @cindex Disabling dependency tracking
6568 @cindex Dependency tracking, disabling
6571 @node EXEEXT
6572 @section Support for executable extensions
6574 @cindex Executable extension
6575 @cindex Extension, executable
6576 @cindex Windows
6578 On some platforms, such as Windows, executables are expected to have an
6579 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6580 among them) will automatically generate @file{foo.exe} when asked to
6581 generate @file{foo}.
6583 Automake provides mostly-transparent support for this.  Unfortunately
6584 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6585 dictionary is revised, you will have to assist Automake if your package
6586 must support those platforms.
6588 One thing you must be aware of is that, internally, Automake rewrites
6589 something like this:
6591 @example
6592 bin_PROGRAMS = liver
6593 @end example
6595 to this:
6597 @example
6598 bin_PROGRAMS = liver$(EXEEXT)
6599 @end example
6601 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6602 extension.
6604 The variables @code{TESTS}, @code{XFAIL_TESTS} (@pxref{Tests}) are also
6605 rewritten if it contains filenames that have been declared as programs
6606 in the same @file{Makefile}.  (This is mostly useful when some programs
6607 from @code{check_PROGRAMS} are listed in @code{TESTS}.)
6609 However, Automake cannot apply this rewriting to @command{configure}
6610 substitutions.  This means that if you are conditionally building a
6611 program using such a substitution, then your @file{configure.ac} must
6612 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6614 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
6615 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
6616 automatically if you configure a compiler (say, through
6617 @code{AC_PROG_CC}).
6619 Sometimes maintainers like to write an explicit link rule for their
6620 program.  Without executable extension support, this is easy---you
6621 simply write a rule whose target is the name of the program.  However,
6622 when executable extension support is enabled, you must instead add the
6623 @samp{$(EXEEXT)} suffix.
6625 Unfortunately, due to the change in Autoconf 2.50, this means you must
6626 always add this extension.  However, this is a problem for maintainers
6627 who know their package will never run on a platform that has
6628 executable extensions.  For those maintainers, the @option{no-exeext}
6629 option (@pxref{Options}) will disable this feature.  This works in a
6630 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6631 rule for a target named @code{foo} in @file{Makefile.am} will override
6632 an automake-generated rule for @samp{foo$(EXEEXT)}.  Without
6633 the @option{no-exeext} option, this use will give a diagnostic.
6636 @node Other objects
6637 @chapter Other Derived Objects
6639 Automake can handle derived objects that are not C programs.  Sometimes
6640 the support for actually building such objects must be explicitly
6641 supplied, but Automake will still automatically handle installation and
6642 distribution.
6644 @menu
6645 * Scripts::                     Executable scripts
6646 * Headers::                     Header files
6647 * Data::                        Architecture-independent data files
6648 * Sources::                     Derived sources
6649 @end menu
6652 @node Scripts
6653 @section Executable Scripts
6655 @cindex @code{_SCRIPTS} primary, defined
6656 @cindex @code{SCRIPTS} primary, defined
6657 @cindex Primary variable, @code{SCRIPTS}
6658 @vindex _SCRIPTS
6659 @cindex Installing scripts
6661 It is possible to define and install programs that are scripts.  Such
6662 programs are listed using the @code{SCRIPTS} primary name.  When the
6663 script is distributed in its final, installable form, the
6664 @file{Makefile} usually looks as follows:
6665 @vindex SCRIPTS
6667 @example
6668 # Install my_script in $(bindir) and distribute it.
6669 dist_bin_SCRIPTS = my_script
6670 @end example
6672 Script are not distributed by default; as we have just seen, those
6673 that should be distributed can be specified using a @code{dist_}
6674 prefix as with other primaries.
6676 @cindex @code{SCRIPTS}, installation directories
6677 @vindex bin_SCRIPTS
6678 @vindex sbin_SCRIPTS
6679 @vindex libexec_SCRIPTS
6680 @vindex pkgdata_SCRIPTS
6681 @vindex noinst_SCRIPTS
6682 @vindex check_SCRIPTS
6684 Scripts can be installed in @code{bindir}, @code{sbindir},
6685 @code{libexecdir}, or @code{pkgdatadir}.
6687 Scripts that need not being installed can be listed in
6688 @code{noinst_SCRIPTS}, and among them, those which are needed only by
6689 @samp{make check} should go in @code{check_SCRIPTS}.
6691 When a script needs to be built, the @file{Makefile.am} should include
6692 the appropriate rules.  For instance the @command{automake} program
6693 itself is a Perl script that is generated from @file{automake.in}.
6694 Here is how this is handled:
6696 @example
6697 bin_SCRIPTS = automake
6698 CLEANFILES = $(bin_SCRIPTS)
6699 EXTRA_DIST = automake.in
6701 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
6702             -e 's,[@@]PERL[@@],$(PERL),g' \
6703             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
6704             -e 's,[@@]VERSION[@@],$(VERSION),g' \
6705             @dots{}
6707 automake: automake.in Makefile
6708         $(do_subst) < $(srcdir)/automake.in > automake
6709         chmod +x automake
6710 @end example
6712 Such scripts for which a build rule has been supplied need to be
6713 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
6714 sources have to be distributed, usually with @code{EXTRA_DIST}
6715 (@pxref{Dist}).
6717 Another common way to build scripts is to process them from
6718 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
6719 Automake knows which files should be cleaned and distributed, and what
6720 the rebuild rules should look like.
6722 For instance if @file{configure.ac} contains
6724 @example
6725 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
6726 @end example
6728 @noindent
6729 to build @file{src/my_script} from @file{src/my_script.in}, then an
6730 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
6731 be as simple as
6733 @example
6734 bin_SCRIPTS = my_script
6735 CLEANFILES = $(bin_SCRIPTS)
6736 @end example
6738 @noindent
6739 There is no need for @code{EXTRA_DIST} or any build rule: Automake
6740 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
6741 @code{CLEANFILES} is still useful, because by default Automake will
6742 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
6743 @code{clean}.
6745 Although this looks simpler, building scripts this way has one
6746 drawback: directory variables such as @code{$(datadir)} are not fully
6747 expanded and may refer to other directory variables.
6749 @node Headers
6750 @section Header files
6752 @cindex @code{_HEADERS} primary, defined
6753 @cindex @code{HEADERS} primary, defined
6754 @cindex Primary variable, @code{HEADERS}
6755 @vindex _HEADERS
6756 @vindex noinst_HEADERS
6757 @cindex @code{HEADERS}, installation directories
6758 @cindex Installing headers
6759 @vindex include_HEADERS
6760 @vindex oldinclude_HEADERS
6761 @vindex pkginclude_HEADERS
6764 Header files that must be installed are specified by the
6765 @code{HEADERS} family of variables.  Headers can be installed in
6766 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
6767 other directory you may have defined (@pxref{Uniform}).  For instance,
6769 @example
6770 include_HEADERS = foo.h bar/bar.h
6771 @end example
6773 @noindent
6774 will install the two files as @file{$(includedir)/foo.h} and
6775 @file{$(includedir)/bar.h}.
6777 The @code{nobase_} prefix is also supported,
6779 @example
6780 nobase_include_HEADERS = foo.h bar/bar.h
6781 @end example
6783 @noindent
6784 will install the two files as @file{$(includedir)/foo.h} and
6785 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
6787 @vindex noinst_HEADERS
6788 Usually, only header files that accompany installed libraries need to
6789 be installed.  Headers used by programs or convenience libraries are
6790 not installed.  The @code{noinst_HEADERS} variable can be used for
6791 such headers.  However when the header actually belongs to one
6792 convenient library or program, we recommend listing it in the
6793 program's or library's @code{_SOURCES} variable (@pxref{Program
6794 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
6795 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
6796 right variable to use in a directory containing only headers and no
6797 associated library or program.
6799 All header files must be listed somewhere; in a @code{_SOURCES}
6800 variable or in a @code{_HEADERS} variable.  Missing ones will not
6801 appear in the distribution.
6803 For header files that are built and must not be distributed, use the
6804 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
6805 @code{nodist_prog_SOURCES}.  If these generated headers are needed
6806 during the build, you must also ensure they exist before they are
6807 used (@pxref{Sources}).
6810 @node Data
6811 @section Architecture-independent data files
6813 @cindex @code{_DATA} primary, defined
6814 @cindex @code{DATA} primary, defined
6815 @cindex Primary variable, @code{DATA}
6816 @vindex _DATA
6818 Automake supports the installation of miscellaneous data files using the
6819 @code{DATA} family of variables.
6820 @vindex DATA
6822 @vindex data_DATA
6823 @vindex sysconf_DATA
6824 @vindex sharedstate_DATA
6825 @vindex localstate_DATA
6826 @vindex pkgdata_DATA
6828 Such data can be installed in the directories @code{datadir},
6829 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
6830 @code{pkgdatadir}.
6832 By default, data files are @emph{not} included in a distribution.  Of
6833 course, you can use the @code{dist_} prefix to change this on a
6834 per-variable basis.
6836 Here is how Automake declares its auxiliary data files:
6838 @example
6839 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
6840 @end example
6843 @node Sources
6844 @section Built sources
6846 Because Automake's automatic dependency tracking works as a side-effect
6847 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
6848 target should not be compiled before its dependencies are made, but
6849 these dependencies are unknown until the target is first compiled.
6851 Ordinarily this is not a problem, because dependencies are distributed
6852 sources: they preexist and do not need to be built.  Suppose that
6853 @file{foo.c} includes @file{foo.h}.  When it first compiles
6854 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
6855 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
6856 records the @file{foo.h} dependency so that following invocations of
6857 @command{make} will honor it.  In these conditions, it's clear there is
6858 no problem: either @file{foo.o} doesn't exist and has to be built
6859 (regardless of the dependencies), or accurate dependencies exist and
6860 they can be used to decide whether @file{foo.o} should be rebuilt.
6862 It's a different story if @file{foo.h} doesn't exist by the first
6863 @command{make} run.  For instance, there might be a rule to build
6864 @file{foo.h}.  This time @file{file.o}'s build will fail because the
6865 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
6866 rule to build @file{foo.h} first by lack of dependency information.
6868 @vindex BUILT_SOURCES
6869 @cindex @code{BUILT_SOURCES}, defined
6871 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
6872 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
6873 or @samp{make check} (or even @samp{make install}) before other
6874 targets are processed.  However, such a source file is not
6875 @emph{compiled} unless explicitly requested by mentioning it in some
6876 other @code{_SOURCES} variable.
6878 So, to conclude our introductory example, we could use
6879 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
6880 any other target (including @file{foo.o}) during @samp{make all} or
6881 @samp{make check}.
6883 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
6884 must be created early in the build process can be listed in this
6885 variable.  Moreover, all built sources do not necessarily have to be
6886 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
6887 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
6888 another source), because it's a known dependency of the associated
6889 object.
6891 It might be important to emphasize that @code{BUILT_SOURCES} is
6892 honored only by @samp{make all}, @samp{make check} and @samp{make
6893 install}.  This means you cannot build a specific target (e.g.,
6894 @samp{make foo}) in a clean tree if it depends on a built source.
6895 However it will succeed if you have run @samp{make all} earlier,
6896 because accurate dependencies are already available.
6898 The next section illustrates and discusses the handling of built sources
6899 on a toy example.
6901 @menu
6902 * Built sources example::       Several ways to handle built sources.
6903 @end menu
6905 @node Built sources example
6906 @subsection Built sources example
6908 Suppose that @file{foo.c} includes @file{bindir.h}, which is
6909 installation-dependent and not distributed: it needs to be built.  Here
6910 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
6911 value of the @command{make} variable @code{bindir} (inherited from
6912 @file{configure}).
6914 We suggest several implementations below.  It's not meant to be an
6915 exhaustive listing of all ways to handle built sources, but it will give
6916 you a few ideas if you encounter this issue.
6918 @unnumberedsubsec First try
6920 This first implementation will illustrate the bootstrap issue mentioned
6921 in the previous section (@pxref{Sources}).
6923 Here is a tentative @file{Makefile.am}.
6925 @example
6926 # This won't work.
6927 bin_PROGRAMS = foo
6928 foo_SOURCES = foo.c
6929 nodist_foo_SOURCES = bindir.h
6930 CLEANFILES = bindir.h
6931 bindir.h: Makefile
6932         echo '#define bindir "$(bindir)"' >$@@
6933 @end example
6935 This setup doesn't work, because Automake doesn't know that @file{foo.c}
6936 includes @file{bindir.h}.  Remember, automatic dependency tracking works
6937 as a side-effect of compilation, so the dependencies of @file{foo.o} will
6938 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
6939 The symptom is as follows.
6941 @example
6942 % make
6943 source='foo.c' object='foo.o' libtool=no \
6944 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
6945 depmode=gcc /bin/sh ./depcomp \
6946 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
6947 foo.c:2: bindir.h: No such file or directory
6948 make: *** [foo.o] Error 1
6949 @end example
6951 In this example @file{bindir.h} is not distributed nor installed, and
6952 it is not even being built on-time.  One may wonder if the
6953 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
6954 line simply states that @file{bindir.h} is a source of @code{foo}, so
6955 for instance, it should be inspected while generating tags
6956 (@pxref{Tags}).  In other words, it does not help our present problem,
6957 and the build would fail identically without it.
6959 @unnumberedsubsec Using @code{BUILT_SOURCES}
6961 A solution is to require @file{bindir.h} to be built before anything
6962 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
6964 @example
6965 bin_PROGRAMS = foo
6966 foo_SOURCES = foo.c
6967 nodist_foo_SOURCES = bindir.h
6968 BUILT_SOURCES = bindir.h
6969 CLEANFILES = bindir.h
6970 bindir.h: Makefile
6971         echo '#define bindir "$(bindir)"' >$@@
6972 @end example
6974 See how @file{bindir.h} get built first:
6976 @example
6977 % make
6978 echo '#define bindir "/usr/local/bin"' >bindir.h
6979 make  all-am
6980 make[1]: Entering directory `/home/adl/tmp'
6981 source='foo.c' object='foo.o' libtool=no \
6982 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
6983 depmode=gcc /bin/sh ./depcomp \
6984 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
6985 gcc  -g -O2   -o foo  foo.o
6986 make[1]: Leaving directory `/home/adl/tmp'
6987 @end example
6989 However, as said earlier, @code{BUILT_SOURCES} applies only to the
6990 @code{all}, @code{check}, and @code{install} targets.  It still fails
6991 if you try to run @samp{make foo} explicitly:
6993 @example
6994 % make clean
6995 test -z "bindir.h" || rm -f bindir.h
6996 test -z "foo" || rm -f foo
6997 rm -f *.o
6998 % : > .deps/foo.Po # Suppress previously recorded dependencies
6999 % make foo
7000 source='foo.c' object='foo.o' libtool=no \
7001 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7002 depmode=gcc /bin/sh ./depcomp \
7003 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7004 foo.c:2: bindir.h: No such file or directory
7005 make: *** [foo.o] Error 1
7006 @end example
7008 @unnumberedsubsec Recording dependencies manually
7010 Usually people are happy enough with @code{BUILT_SOURCES} because they
7011 never build targets such as @samp{make foo} before @samp{make all}, as
7012 in the previous example.  However if this matters to you, you can
7013 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7014 the @file{Makefile.am}.
7016 @example
7017 bin_PROGRAMS = foo
7018 foo_SOURCES = foo.c
7019 nodist_foo_SOURCES = bindir.h
7020 foo.$(OBJEXT): bindir.h
7021 CLEANFILES = bindir.h
7022 bindir.h: Makefile
7023         echo '#define bindir "$(bindir)"' >$@@
7024 @end example
7026 You don't have to list @emph{all} the dependencies of @file{foo.o}
7027 explicitly, only those that might need to be built.  If a dependency
7028 already exists, it will not hinder the first compilation and will be
7029 recorded by the normal dependency tracking code.  (Note that after
7030 this first compilation the dependency tracking code will also have
7031 recorded the dependency between @file{foo.o} and
7032 @file{bindir.h}; so our explicit dependency is really useful to
7033 the first build only.)
7035 Adding explicit dependencies like this can be a bit dangerous if you are
7036 not careful enough.  This is due to the way Automake tries not to
7037 overwrite your rules (it assumes you know better than it).
7038 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7039 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7040 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7041 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7042 Always check the generated @file{Makefile.in} if you do this.
7044 @unnumberedsubsec Build @file{bindir.h} from @file{configure}
7046 It's possible to define this preprocessor macro from @file{configure},
7047 either in @file{config.h} (@pxref{Defining Directories, , Defining
7048 Directories, autoconf, The Autoconf Manual}), or by processing a
7049 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7050 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7051 Autoconf Manual}).
7053 At this point it should be clear that building @file{bindir.h} from
7054 @file{configure} work well for this example.  @file{bindir.h} will exist
7055 before you build any target, hence will not cause any dependency issue.
7057 The Makefile can be shrunk as follows.  We do not even have to mention
7058 @file{bindir.h}.
7060 @example
7061 bin_PROGRAMS = foo
7062 foo_SOURCES = foo.c
7063 @end example
7065 However, it's not always possible to build sources from
7066 @file{configure}, especially when these sources are generated by a tool
7067 that needs to be built first...
7069 @unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
7071 Another attractive idea is to define @code{bindir} as a variable or
7072 function exported from @file{bindir.o}, and build @file{bindir.c}
7073 instead of @file{bindir.h}.
7075 @example
7076 noinst_PROGRAMS = foo
7077 foo_SOURCES = foo.c bindir.h
7078 nodist_foo_SOURCES = bindir.c
7079 CLEANFILES = bindir.c
7080 bindir.c: Makefile
7081         echo 'const char bindir[] = "$(bindir)";' >$@@
7082 @end example
7084 @file{bindir.h} contains just the variable's declaration and doesn't
7085 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7086 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7087 first.
7089 @unnumberedsubsec Which is best?
7091 There is no panacea, of course.  Each solution has its merits and
7092 drawbacks.
7094 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7095 foo} on a clean tree is important to you.
7097 You won't add explicit dependencies if you are leery of overriding
7098 an Automake rule by mistake.
7100 Building files from @file{./configure} is not always possible, neither
7101 is converting @file{.h} files into @file{.c} files.
7104 @node Other GNU Tools
7105 @chapter Other GNU Tools
7107 Since Automake is primarily intended to generate @file{Makefile.in}s for
7108 use in GNU programs, it tries hard to interoperate with other GNU tools.
7110 @menu
7111 * Emacs Lisp::                  Emacs Lisp
7112 * gettext::                     Gettext
7113 * Libtool::                     Libtool
7114 * Java::                        Java
7115 * Python::                      Python
7116 @end menu
7119 @node Emacs Lisp
7120 @section Emacs Lisp
7122 @cindex @code{_LISP} primary, defined
7123 @cindex @code{LISP} primary, defined
7124 @cindex Primary variable, @code{LISP}
7126 @vindex _LISP
7127 @vindex lisp_LISP
7128 @vindex noinst_LISP
7130 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7131 is used to hold a list of @file{.el} files.  Possible prefixes for this
7132 primary are @code{lisp_} and @code{noinst_}.  Note that if
7133 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7134 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7136 @vindex dist_lisp_LISP
7137 @vindex dist_noinst_LISP
7138 Lisp sources are not distributed by default.  You can prefix the
7139 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7140 @code{dist_noinst_LISP}, to indicate that these files should be
7141 distributed.
7143 Automake will byte-compile all Emacs Lisp source files using the Emacs
7144 found by @code{AM_PATH_LISPDIR}, if any was found.
7146 Byte-compiled Emacs Lisp files are not portable among all versions of
7147 Emacs, so it makes sense to turn this off if you expect sites to have
7148 more than one version of Emacs installed.  Furthermore, many packages
7149 don't actually benefit from byte-compilation.  Still, we recommend
7150 that you byte-compile your Emacs Lisp sources.  It is probably better
7151 for sites with strange setups to cope for themselves than to make the
7152 installation less nice for everybody else.
7154 There are two ways to avoid byte-compiling.  Historically, we have
7155 recommended the following construct.
7156 @example
7157 lisp_LISP = file1.el file2.el
7158 ELCFILES =
7159 @end example
7160 @noindent
7161 @code{ELCFILES} is an internal Automake variable that normally lists
7162 all @file{.elc} files that must be byte-compiled.  Automake defines
7163 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7164 variable explicitly prevents byte-compilation to occur.
7166 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead.  As
7168 @example
7169 lisp_DATA = file1.el file2.el
7170 @end example
7172 Note that these two constructs are not equivalent.  @code{_LISP} will
7173 not install a file if Emacs is not installed, while @code{_DATA} will
7174 always install its files.
7176 @node gettext
7177 @section Gettext
7179 @cindex GNU Gettext support
7180 @cindex Gettext support
7181 @cindex Support for GNU Gettext
7183 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7184 turns on support for GNU gettext, a message catalog system for
7185 internationalization
7186 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7188 The @code{gettext} support in Automake requires the addition of one or
7189 two subdirectories to the package, @file{po} and possibly also @file{intl}.
7190 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7191 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7192 Automake ensures that these directories exist and are mentioned in
7193 @code{SUBDIRS}.
7195 @node Libtool
7196 @section Libtool
7198 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7199 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7200 @xref{A Shared Library}.
7203 @node Java
7204 @section Java
7206 @cindex @code{_JAVA} primary, defined
7207 @cindex @code{JAVA} primary, defined
7208 @cindex Primary variable, @code{JAVA}
7210 Automake provides some minimal support for Java compilation with the
7211 @code{JAVA} primary.
7213 Any @file{.java} files listed in a @code{_JAVA} variable will be
7214 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7215 files are not included in the distribution, you should use the
7216 @code{dist_} prefix to distribute them.
7218 Here is a typical setup for distributing @file{.java} files and
7219 installing the @file{.class} files resulting from their compilation.
7221 @example
7222 javadir = $(datadir)/java
7223 dist_java_JAVA = a.java b.java @dots{}
7224 @end example
7226 @cindex @code{JAVA} restrictions
7227 @cindex Restrictions for @code{JAVA}
7229 Currently Automake enforces the restriction that only one @code{_JAVA}
7230 primary can be used in a given @file{Makefile.am}.  The reason for this
7231 restriction is that, in general, it isn't possible to know which
7232 @file{.class} files were generated from which @file{.java} files, so
7233 it would be impossible to know which files to install where.  For
7234 instance, a @file{.java} file can define multiple classes; the resulting
7235 @file{.class} file names cannot be predicted without parsing the
7236 @file{.java} file.
7238 There are a few variables that are used when compiling Java sources:
7240 @vtable @code
7241 @item JAVAC
7242 The name of the Java compiler.  This defaults to @samp{javac}.
7244 @item JAVACFLAGS
7245 The flags to pass to the compiler.  This is considered to be a user
7246 variable (@pxref{User Variables}).
7248 @item AM_JAVACFLAGS
7249 More flags to pass to the Java compiler.  This, and not
7250 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7251 compiler flags into @file{Makefile.am}.
7253 @item JAVAROOT
7254 The value of this variable is passed to the @option{-d} option to
7255 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7257 @item CLASSPATH_ENV
7258 This variable is an @code{sh} expression that is used to set the
7259 @env{CLASSPATH} environment variable on the @code{javac} command line.
7260 (In the future we will probably handle class path setting differently.)
7261 @end vtable
7264 @node Python
7265 @section Python
7267 @cindex @code{_PYTHON} primary, defined
7268 @cindex @code{PYTHON} primary, defined
7269 @cindex Primary variable, @code{PYTHON}
7270 @vindex _PYTHON
7272 Automake provides support for Python compilation with the
7273 @code{PYTHON} primary.  A typical setup is to call
7274 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7275 following in @file{Makefile.am}:
7277 @example
7278 python_PYTHON = tree.py leave.py
7279 @end example
7281 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7282 with @command{py-compile} at install time.  @command{py-compile}
7283 actually creates both standard (@file{.pyc}) and optimized
7284 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7285 because byte-compilation occurs at install time, any files listed in
7286 @code{noinst_PYTHON} will not be compiled.  Python source files are
7287 included in the distribution by default, prepend @code{nodist_} (as in
7288 @code{nodist_python_PYTHON}) to omit them.
7290 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7291 that will determine some Python-related directory variables (see
7292 below).  If you have called @code{AM_PATH_PYTHON} from
7293 @file{configure.ac}, then you may use the variables
7294 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7295 files in your @file{Makefile.am}, depending where you want your files
7296 installed (see the definitions of @code{pythondir} and
7297 @code{pkgpythondir} below).
7299 @defmac AM_PATH_PYTHON (@ovar{VERSION}, @ovar{ACTION-IF-FOUND}, @ovar{ACTION-IF-NOT-FOUND})
7301 Search for a Python interpreter on the system.  This macro takes three
7302 optional arguments.  The first argument, if present, is the minimum
7303 version of Python required for this package: @code{AM_PATH_PYTHON}
7304 will skip any Python interpreter that is older than @var{VERSION}.
7305 If an interpreter is found and satisfies @var{VERSION}, then
7306 @var{ACTION-IF-FOUND} is run.  Otherwise, @var{ACTION-IF-NOT-FOUND} is
7307 run.
7309 If @var{ACTION-IF-NOT-FOUND} is not specified, as in the following
7310 example, the default is to abort @command{configure}.
7312 @example
7313 AM_PATH_PYTHON([2.2])
7314 @end example
7316 @noindent
7317 This is fine when Python is an absolute requirement for the package.
7318 If Python >= 2.2 was only @emph{optional} to the package,
7319 @code{AM_PATH_PYTHON} could be called as follows.
7321 @example
7322 AM_PATH_PYTHON([2.2],, [:])
7323 @end example
7325 @code{AM_PATH_PYTHON} creates the following output variables based on
7326 the Python installation found during configuration.
7327 @end defmac
7329 @vtable @code
7330 @item PYTHON
7331 The name of the Python executable, or @samp{:} if no suitable
7332 interpreter could be found.
7334 Assuming @var{ACTION-IF-NOT-FOUND} is used (otherwise @file{./configure}
7335 will abort if Python is absent), the value of @code{PYTHON} can be used
7336 to setup a conditional in order to disable the relevant part of a build
7337 as follows.
7339 @example
7340   AM_PATH_PYTHON(,, [:])
7341   AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7342 @end example
7344 @item PYTHON_VERSION
7345 The Python version number, in the form @var{major}.@var{minor}
7346 (e.g., @samp{1.5}).  This is currently the value of
7347 @samp{sys.version[:3]}.
7349 @item PYTHON_PREFIX
7350 The string @samp{$@{prefix@}}.  This term may be used in future work
7351 that needs the contents of Python's @samp{sys.prefix}, but general
7352 consensus is to always use the value from configure.
7354 @item PYTHON_EXEC_PREFIX
7355 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7356 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7357 consensus is to always use the value from configure.
7359 @item PYTHON_PLATFORM
7360 The canonical name used by Python to describe the operating system, as
7361 given by @samp{sys.platform}.  This value is sometimes needed when
7362 building Python extensions.
7364 @item pythondir
7365 The directory name for the @file{site-packages} subdirectory of the
7366 standard Python install tree.
7368 @item pkgpythondir
7369 This is the directory under @code{pythondir} that is named after the
7370 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7371 as a convenience.
7373 @item pyexecdir
7374 This is the directory where Python extension modules (shared libraries)
7375 should be installed.  An extension module written in C could be declared
7376 as follows to Automake:
7378 @example
7379 pyexec_LTLIBRARIES = quaternion.la
7380 quaternion_SOURCES = quaternion.c support.c support.h
7381 quaternion_la_LDFLAGS = -avoid-version -module
7382 @end example
7384 @item pkgpyexecdir
7385 This is a convenience variable that is defined as
7386 @samp{$(pyexecdir)/$(PACKAGE)}.
7387 @end vtable
7389 All these directory variables have values that start with either
7390 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7391 fine in @file{Makefiles}, but it makes these variables hard to use in
7392 @file{configure}.  This is mandated by the GNU coding standards, so
7393 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7394 manual has a section with more details on this topic
7395 (@pxref{Installation Directory Variables, , Installation Directory
7396 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7397 Install Paths}.
7400 @node Documentation
7401 @chapter Building documentation
7403 Currently Automake provides support for Texinfo and man pages.
7405 @menu
7406 * Texinfo::                     Texinfo
7407 * Man pages::                   Man pages
7408 @end menu
7411 @node Texinfo
7412 @section Texinfo
7414 @cindex @code{_TEXINFOS} primary, defined
7415 @cindex @code{TEXINFOS} primary, defined
7416 @cindex Primary variable, @code{TEXINFOS}
7417 @cindex HTML output using Texinfo
7418 @cindex PDF output using Texinfo
7419 @cindex PS output using Texinfo
7420 @cindex DVI output using Texinfo
7421 @vindex _TEXINFOS
7422 @vindex info_TEXINFOS
7424 If the current directory contains Texinfo source, you must declare it
7425 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7426 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7427 here.  Any Texinfo source file must end in the @file{.texi},
7428 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7429 for new manuals.
7431 Automake generates rules to build @file{.info}, @file{.dvi},
7432 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7433 sources.  Following the GNU Coding Standards, only the @file{.info}
7434 files are built by @samp{make all} and installed by @samp{make
7435 install} (unless you use @option{no-installinfo}, see below).
7436 Furthermore, @file{.info} files are automatically distributed so that
7437 Texinfo is not a prerequisite for installing your package.
7439 @trindex dvi
7440 @trindex html
7441 @trindex pdf
7442 @trindex ps
7443 @trindex install-dvi
7444 @trindex install-html
7445 @trindex install-pdf
7446 @trindex install-ps
7447 Other documentation formats can be built on request by @samp{make
7448 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7449 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7450 @samp{make install-pdf} and @samp{make install-html} explicitly.
7451 @samp{make uninstall} will remove everything: the Texinfo
7452 documentation installed by default as well as all the above optional
7453 formats.
7455 All these targets can be extended using @samp{-local} rules
7456 (@pxref{Extending}).
7458 @cindex Texinfo flag, @code{VERSION}
7459 @cindex Texinfo flag, @code{UPDATED}
7460 @cindex Texinfo flag, @code{EDITION}
7461 @cindex Texinfo flag, @code{UPDATED-MONTH}
7463 @cindex @code{VERSION} Texinfo flag
7464 @cindex @code{UPDATED} Texinfo flag
7465 @cindex @code{EDITION} Texinfo flag
7466 @cindex @code{UPDATED-MONTH} Texinfo flag
7468 @cindex @file{mdate-sh}
7470 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7471 that file will be automatically generated.  The file @file{version.texi}
7472 defines four Texinfo flag you can reference using
7473 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7474 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7476 @table @code
7477 @item EDITION
7478 @itemx VERSION
7479 Both of these flags hold the version number of your program.  They are
7480 kept separate for clarity.
7482 @item UPDATED
7483 This holds the date the primary @file{.texi} file was last modified.
7485 @item UPDATED-MONTH
7486 This holds the name of the month in which the primary @file{.texi} file
7487 was last modified.
7488 @end table
7490 The @file{version.texi} support requires the @command{mdate-sh}
7491 script; this script is supplied with Automake and automatically
7492 included when @command{automake} is invoked with the
7493 @option{--add-missing} option.
7495 If you have multiple Texinfo files, and you want to use the
7496 @file{version.texi} feature, then you have to have a separate version
7497 file for each Texinfo file.  Automake will treat any include in a
7498 Texinfo file that matches @file{vers*.texi} just as an automatically
7499 generated version file.
7501 Sometimes an info file actually depends on more than one @file{.texi}
7502 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7503 @file{gpl.texi}.  You can tell Automake about these dependencies using
7504 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7505 @vindex TEXINFOS
7506 @vindex _TEXINFOS
7508 @example
7509 info_TEXINFOS = hello.texi
7510 hello_TEXINFOS = gpl.texi
7511 @end example
7513 @cindex @file{texinfo.tex}
7515 By default, Automake requires the file @file{texinfo.tex} to appear in
7516 the same directory as the @file{Makefile.am} file that lists the
7517 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7518 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7519 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7520 there.  In both cases, automake then supplies @file{texinfo.tex} if
7521 @option{--add-missing} is given, and takes care of its distribution.
7522 However, if you set the @code{TEXINFO_TEX} variable (see below),
7523 it overrides the location of the file and turns off its installation
7524 into the source as well as its distribution.
7526 The option @option{no-texinfo.tex} can be used to eliminate the
7527 requirement for the file @file{texinfo.tex}.  Use of the variable
7528 @code{TEXINFO_TEX} is preferable, however, because that allows the
7529 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7531 @cindex Option, @code{no-installinfo}
7532 @cindex Target, @code{install-info}
7533 @cindex @code{install-info} target
7534 @cindex @code{no-installinfo} option
7536 @opindex no-installinfo
7537 @trindex install-info
7539 Automake generates an @code{install-info} rule; some people apparently
7540 use this.  By default, info pages are installed by @samp{make
7541 install}, so running @code{make install-info} is pointless.  This can
7542 be prevented via the @code{no-installinfo} option.  In this case,
7543 @file{.info} files are not installed by default, and user must
7544 request this explicitly using @samp{make install-info}
7546 The following variables are used by the Texinfo build rules.
7548 @vtable @code
7549 @item MAKEINFO
7550 The name of the program invoked to build @file{.info} files.  This
7551 variable is defined by Automake.  If the @command{makeinfo} program is
7552 found on the system then it will be used by default; otherwise
7553 @command{missing} will be used instead.
7555 @item MAKEINFOHTML
7556 The command invoked to build @file{.html} files.  Automake
7557 defines this to @samp{$(MAKEINFO) --html}.
7559 @item MAKEINFOFLAGS
7560 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7561 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7562 not expected to be defined in any @file{Makefile}; it can be used by
7563 users to pass extra flags to suit their needs.
7565 @item AM_MAKEINFOFLAGS
7566 @itemx AM_MAKEINFOHTMLFLAGS
7567 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7568 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7569 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7570 passed to @code{makeinfo} when building @file{.info} files; and
7571 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7572 files.
7574 For instance, the following setting can be used to obtain one single
7575 @file{.html} file per manual, without node separators.
7576 @example
7577 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7578 @end example
7580 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7581 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7582 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7583 and @file{.html} files.
7585 @item TEXI2DVI
7586 The name of the command that converts a @file{.texi} file into a
7587 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7588 with the Texinfo package.
7590 @item TEXI2PDF
7591 The name of the command that translates a @file{.texi} file into a
7592 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7594 @item DVIPS
7595 The name of the command that build a @file{.ps} file out of a
7596 @file{.dvi} file.  This defaults to @samp{dvips}.
7598 @item TEXINFO_TEX
7600 If your package has Texinfo files in many directories, you can use the
7601 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7602 @file{texinfo.tex} for your package.  The value of this variable should
7603 be the relative path from the current @file{Makefile.am} to
7604 @file{texinfo.tex}:
7606 @example
7607 TEXINFO_TEX = ../doc/texinfo.tex
7608 @end example
7609 @end vtable
7612 @node Man pages
7613 @section Man pages
7615 @cindex @code{_MANS} primary, defined
7616 @cindex @code{MANS} primary, defined
7617 @cindex Primary variable, @code{MANS}
7619 @vindex _MANS
7620 @vindex man_MANS
7621 A package can also include man pages (but see the GNU standards on this
7622 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7623 pages are declared using the @code{MANS} primary.  Generally the
7624 @code{man_MANS} variable is used.  Man pages are automatically installed in
7625 the correct subdirectory of @code{mandir}, based on the file extension.
7627 File extensions such as @file{.1c} are handled by looking for the valid
7628 part of the extension and using that to determine the correct
7629 subdirectory of @code{mandir}.  Valid section names are the digits
7630 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7632 Sometimes developers prefer to name a man page something like
7633 @file{foo.man} in the source, and then rename it to have the correct
7634 suffix, for example @file{foo.1}, when installing the file.  Automake
7635 also supports this mode.  For a valid section named @var{SECTION},
7636 there is a corresponding directory named @samp{man@var{SECTION}dir},
7637 and a corresponding @code{_MANS} variable.  Files listed in such a
7638 variable are installed in the indicated section.  If the file already
7639 has a valid suffix, then it is installed as-is; otherwise the file
7640 suffix is changed to match the section.
7642 For instance, consider this example:
7643 @example
7644 man1_MANS = rename.man thesame.1 alsothesame.1c
7645 @end example
7647 In this case, @file{rename.man} will be renamed to @file{rename.1} when
7648 installed, but the other files will keep their names.
7650 @cindex Target, @code{install-man}
7651 @cindex Option, @option{no-installman}
7652 @cindex @code{install-man} target
7653 @cindex @option{no-installman} option
7654 @opindex no-installman
7655 @trindex install-man
7657 By default, man pages are installed by @samp{make install}.  However,
7658 since the GNU project does not require man pages, many maintainers do
7659 not expend effort to keep the man pages up to date.  In these cases, the
7660 @option{no-installman} option will prevent the man pages from being
7661 installed by default.  The user can still explicitly install them via
7662 @samp{make install-man}.
7664 Man pages are not currently considered to be source, because it is not
7665 uncommon for man pages to be automatically generated.  Therefore they
7666 are not automatically included in the distribution.  However, this can
7667 be changed by use of the @code{dist_} prefix.  For instance here is
7668 how to distribute and install the two man pages of GNU @command{cpio}
7669 (which includes both Texinfo documentation and man pages):
7671 @example
7672 dist_man_MANS = cpio.1 mt.1
7673 @end example
7675 The @code{nobase_} prefix is meaningless for man pages and is
7676 disallowed.
7678 @vindex notrans_
7679 @cindex @code{notrans_} prefix
7680 @cindex Man page renaming, avoiding
7681 @cindex Avoiding man page renaming
7683 Executables and manpages may be renamed upon installation
7684 (@pxref{Renaming}).  For manpages this can be avoided by use of the
7685 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
7686 allowing to access a library function @samp{foo} from the command line.
7687 The way to avoid renaming of the @file{foo.3} manpage is:
7689 @example
7690 man_MANS = foo.1
7691 notrans_man_MANS = foo.3
7692 @end example
7694 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
7695 @cindex @code{dist_} and @code{notrans_}
7696 @cindex @code{nodist_} and @code{notrans_}
7698 @samp{notrans_} must be specified first when used in conjunction with
7699 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
7701 @example
7702 notrans_dist_man3_MANS = bar.3
7703 @end example
7705 @node Install
7706 @chapter What Gets Installed
7708 @cindex Installation support
7709 @cindex @samp{make install} support
7711 @section Basics of installation
7713 Naturally, Automake handles the details of actually installing your
7714 program once it has been built.  All files named by the various
7715 primaries are automatically installed in the appropriate places when the
7716 user runs @samp{make install}.
7718 A file named in a primary is installed by copying the built file into
7719 the appropriate directory.  The base name of the file is used when
7720 installing.
7722 @example
7723 bin_PROGRAMS = hello subdir/goodbye
7724 @end example
7726 In this example, both @samp{hello} and @samp{goodbye} will be installed
7727 in @samp{$(bindir)}.
7729 Sometimes it is useful to avoid the basename step at install time.  For
7730 instance, you might have a number of header files in subdirectories of
7731 the source tree that are laid out precisely how you want to install
7732 them.  In this situation you can use the @code{nobase_} prefix to
7733 suppress the base name step.  For example:
7735 @example
7736 nobase_include_HEADERS = stdio.h sys/types.h
7737 @end example
7739 Will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
7740 in @samp{$(includedir)/sys}.
7742 @section The two parts of install
7744 Automake generates separate @code{install-data} and @code{install-exec}
7745 rules, in case the installer is installing on multiple machines that
7746 share directory structure---these targets allow the machine-independent
7747 parts to be installed only once.  @code{install-exec} installs
7748 platform-dependent files, and @code{install-data} installs
7749 platform-independent files.  The @code{install} target depends on both
7750 of these targets.  While Automake tries to automatically segregate
7751 objects into the correct category, the @file{Makefile.am} author is, in
7752 the end, responsible for making sure this is done correctly.
7753 @trindex install-data
7754 @trindex install-exec
7755 @trindex install
7756 @cindex Install, two parts of
7758 Variables using the standard directory prefixes @samp{data},
7759 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
7760 @samp{pkgdata}, or @samp{pkginclude} are installed by
7761 @code{install-data}.
7763 Variables using the standard directory prefixes @samp{bin},
7764 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
7765 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
7767 For instance, @code{data_DATA} files are installed by @code{install-data},
7768 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
7770 Any variable using a user-defined directory prefix with @samp{exec} in
7771 the name (e.g., @code{myexecbin_PROGRAMS}) is installed by
7772 @code{install-exec}.  All other user-defined prefixes are installed by
7773 @code{install-data}.
7775 @section Extending installation
7777 It is possible to extend this mechanism by defining an
7778 @code{install-exec-local} or @code{install-data-local} rule.  If these
7779 rules exist, they will be run at @samp{make install} time.  These
7780 rules can do almost anything; care is required.
7781 @trindex install-exec-local
7782 @trindex install-data-local
7784 Automake also supports two install hooks, @code{install-exec-hook} and
7785 @code{install-data-hook}.  These hooks are run after all other install
7786 rules of the appropriate type, exec or data, have completed.  So, for
7787 instance, it is possible to perform post-installation modifications
7788 using an install hook.  @xref{Extending}, for some examples.
7789 @cindex Install hook
7791 @section Staged installs
7793 @vindex DESTDIR
7794 Automake generates support for the @code{DESTDIR} variable in all
7795 install rules.  @code{DESTDIR} is used during the @samp{make install}
7796 step to relocate install objects into a staging area.  Each object and
7797 path is prefixed with the value of @code{DESTDIR} before being copied
7798 into the install area.  Here is an example of typical DESTDIR usage:
7800 @example
7801 mkdir /tmp/staging &&
7802 make DESTDIR=/tmp/staging install
7803 @end example
7805 The @command{mkdir} command avoids a security problem if the attacker
7806 creates a symbolic link from @file{/tmp/staging} to a victim area;
7807 then @command{make} places install objects in a directory tree built under
7808 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
7809 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
7810 would install @file{/tmp/staging/gnu/bin/foo} and
7811 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
7813 This feature is commonly used to build install images and packages
7814 (@pxref{DESTDIR}).
7816 Support for @code{DESTDIR} is implemented by coding it directly into
7817 the install rules.  If your @file{Makefile.am} uses a local install
7818 rule (e.g., @code{install-exec-local}) or an install hook, then you
7819 must write that code to respect @code{DESTDIR}.
7821 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
7822 for another usage example.
7824 @section Rules for the user
7826 Automake also generates rules for targets @code{uninstall},
7827 @code{installdirs}, and @code{install-strip}.
7828 @trindex uninstall
7829 @trindex installdirs
7830 @trindex install-strip
7832 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
7833 There is no notion of separate uninstalls for ``exec'' and ``data'', as
7834 these features would not provide additional functionality.
7836 Note that @code{uninstall} is not meant as a replacement for a real
7837 packaging tool.
7840 @node Clean
7841 @chapter What Gets Cleaned
7843 @cindex @samp{make clean} support
7845 The GNU Makefile Standards specify a number of different clean rules.
7846 @xref{Standard Targets, , Standard Targets for Users, standards,
7847 The GNU Coding Standards}.
7849 Generally the files that can be cleaned are determined automatically by
7850 Automake.  Of course, Automake also recognizes some variables that can
7851 be defined to specify additional files to clean.  These variables are
7852 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
7853 @code{MAINTAINERCLEANFILES}.
7854 @vindex MOSTLYCLEANFILES
7855 @vindex CLEANFILES
7856 @vindex DISTCLEANFILES
7857 @vindex MAINTAINERCLEANFILES
7859 @trindex mostlyclean-local
7860 @trindex clean-local
7861 @trindex distclean-local
7862 @trindex maintainer-clean-local
7863 When cleaning involves more than deleting some hard-coded list of
7864 files, it is also possible to supplement the cleaning rules with your
7865 own commands.  Simply define a rule for any of the
7866 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
7867 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
7868 case is deleting a directory, for instance, a directory created by the
7869 test suite:
7871 @example
7872 clean-local:
7873         -rm -rf testSubDir
7874 @end example
7876 As the GNU Standards aren't always explicit as to which files should
7877 be removed by which rule, we've adopted a heuristic that we believe
7878 was first formulated by Fran@,{c}ois Pinard:
7880 @itemize @bullet
7881 @item
7882 If @command{make} built it, and it is commonly something that one would
7883 want to rebuild (for instance, a @file{.o} file), then
7884 @code{mostlyclean} should delete it.
7886 @item
7887 Otherwise, if @command{make} built it, then @code{clean} should delete it.
7889 @item
7890 If @command{configure} built it, then @code{distclean} should delete it.
7892 @item
7893 If the maintainer built it (for instance, a @file{.info} file), then
7894 @code{maintainer-clean} should delete it.  However
7895 @code{maintainer-clean} should not delete anything that needs to exist
7896 in order to run @samp{./configure && make}.
7897 @end itemize
7899 We recommend that you follow this same set of heuristics in your
7900 @file{Makefile.am}.
7903 @node Dist
7904 @chapter What Goes in a Distribution
7906 @section Basics of distribution
7908 @cindex @samp{make dist}
7910 @vindex PACKAGE
7911 @vindex VERSION
7912 @trindex dist
7913 The @code{dist} rule in the generated @file{Makefile.in} can be used
7914 to generate a gzipped @code{tar} file and other flavors of archive for
7915 distribution.  The files is named based on the @code{PACKAGE} and
7916 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
7917 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
7918 @samp{@var{package}-@var{version}.tar.gz}.
7919 @vindex GZIP_ENV
7920 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
7921 is run.  The default setting is @option{--best}.
7923 @cindex @code{m4_include}, distribution
7924 @cindex @code{include}, distribution
7925 @acindex m4_include
7926 @cmindex include
7927 For the most part, the files to distribute are automatically found by
7928 Automake: all source files are automatically included in a distribution,
7929 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
7930 has a built-in list of commonly used files that are automatically
7931 included if they are found in the current directory (either physically,
7932 or as the target of a @file{Makefile.am} rule).  This list is printed by
7933 @samp{automake --help}.  Also, files that are read by @command{configure}
7934 (i.e.@: the source files corresponding to the files specified in various
7935 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
7936 automatically distributed.  Files included in @file{Makefile.am}s (using
7937 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
7938 helper scripts installed with @samp{automake --add-missing} are also
7939 distributed.
7941 @vindex EXTRA_DIST
7942 Still, sometimes there are files that must be distributed, but which
7943 are not covered in the automatic rules.  These files should be listed in
7944 the @code{EXTRA_DIST} variable.  You can mention files from
7945 subdirectories in @code{EXTRA_DIST}.
7947 You can also mention a directory in @code{EXTRA_DIST}; in this case the
7948 entire directory will be recursively copied into the distribution.
7949 Please note that this will also copy @emph{everything} in the directory,
7950 including CVS/RCS version control files.  We recommend against using
7951 this feature.
7953 @vindex SUBDIRS
7954 @vindex DIST_SUBDIRS
7955 If you define @code{SUBDIRS}, Automake will recursively include the
7956 subdirectories in the distribution.  If @code{SUBDIRS} is defined
7957 conditionally (@pxref{Conditionals}), Automake will normally include
7958 all directories that could possibly appear in @code{SUBDIRS} in the
7959 distribution.  If you need to specify the set of directories
7960 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
7961 exact list of subdirectories to include in the distribution
7962 (@pxref{Conditional Subdirectories}).
7965 @section Fine-grained distribution control
7967 @vindex dist_
7968 @vindex nodist_
7969 Sometimes you need tighter control over what does @emph{not} go into the
7970 distribution; for instance, you might have source files that are
7971 generated and that you do not want to distribute.  In this case
7972 Automake gives fine-grained control using the @code{dist} and
7973 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
7974 prefixed with @code{dist_} to add the listed files to the distribution.
7975 Similarly, @code{nodist_} can be used to omit the files from the
7976 distribution.
7978 As an example, here is how you would cause some data to be distributed
7979 while leaving some source code out of the distribution:
7981 @example
7982 dist_data_DATA = distribute-this
7983 bin_PROGRAMS = foo
7984 nodist_foo_SOURCES = do-not-distribute.c
7985 @end example
7987 @section The dist hook
7989 @trindex dist-hook
7991 Occasionally it is useful to be able to change the distribution before
7992 it is packaged up.  If the @code{dist-hook} rule exists, it is run
7993 after the distribution directory is filled, but before the actual tar
7994 (or shar) file is created.  One way to use this is for distributing
7995 files in subdirectories for which a new @file{Makefile.am} is overkill:
7997 @example
7998 dist-hook:
7999         mkdir $(distdir)/random
8000         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
8001 @end example
8003 Another way to use this is for removing unnecessary files that get
8004 recursively included by specifying a directory in EXTRA_DIST:
8006 @example
8007 EXTRA_DIST = doc
8009 dist-hook:
8010         rm -rf `find $(distdir)/doc -name CVS`
8011 @end example
8013 @vindex distdir
8014 @vindex top_distdir
8015 Two variables that come handy when writing @code{dist-hook} rules are
8016 @samp{$(distdir)} and @samp{$(top_distdir)}.
8018 @samp{$(distdir)} points to the directory where the @code{dist} rule
8019 will copy files from the current directory before creating the
8020 tarball.  If you are at the top-level directory, then @samp{distdir =
8021 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8022 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8023 @samp{$(distdir)} can be a relative or absolute path, do not assume
8024 any form.
8026 @samp{$(top_distdir)} always points to the root directory of the
8027 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8028 In the @file{foo/} subdirectory
8029 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8030 @samp{$(top_distdir)} too can be a relative or absolute path.
8032 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8033 (@pxref{Subpackages}), then @samp{$(distdir)} and
8034 @samp{$(top_distdir)} are relative to the package where @samp{make
8035 dist} was run, not to any sub-packages involved.
8037 @section Checking the distribution
8039 @cindex @samp{make distcheck}
8040 @cindex @samp{make distcleancheck}
8041 @vindex distcleancheck_listfiles
8042 @cindex @samp{make distuninstallcheck}
8043 @vindex distuninstallcheck_listfiles
8045 @trindex distcheck
8046 Automake also generates a @code{distcheck} rule that can be of help to
8047 ensure that a given distribution will actually work.  @code{distcheck}
8048 makes a distribution, then tries to do a @code{VPATH} build
8049 (@pxref{VPATH Builds}), run the test suite, and finally make another
8050 tarball to ensure the distribution is self-contained.
8052 @vindex DISTCHECK_CONFIGURE_FLAGS
8053 Building the package involves running @samp{./configure}.  If you need
8054 to supply additional flags to @command{configure}, define them in the
8055 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
8056 @file{Makefile.am}, or on the command line when invoking @command{make}.
8058 @trindex distcheck-hook
8059 If the @code{distcheck-hook} rule is defined in your top-level
8060 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8061 the new distribution has been unpacked, but before the unpacked copy
8062 is configured and built.  Your @code{distcheck-hook} can do almost
8063 anything, though as always caution is advised.  Generally this hook is
8064 used to check for potential distribution errors not caught by the
8065 standard mechanism.  Note that @code{distcheck-hook} as well as
8066 @code{DISTCHECK_CONFIGURE_FLAGS} are not honored in a subpackage
8067 @file{Makefile.am}, but the @code{DISTCHECK_CONFIGURE_FLAGS} are
8068 passed down to the @command{configure} script of the subpackage.
8070 @trindex distcleancheck
8071 @vindex DISTCLEANFILES
8072 @vindex distcleancheck_listfiles
8073 Speaking of potential distribution errors, @code{distcheck} also
8074 ensures that the @code{distclean} rule actually removes all built
8075 files.  This is done by running @samp{make distcleancheck} at the end of
8076 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8077 @code{distclean} and then make sure the build tree has been emptied by
8078 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8079 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8080 variable (@pxref{Clean}).
8082 The @code{distcleancheck} behavior should be OK for most packages,
8083 otherwise you have the possibility to override the definition of
8084 either the @code{distcleancheck} rule, or the
8085 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8086 @code{distcleancheck} completely, add the following rule to your
8087 top-level @file{Makefile.am}:
8089 @example
8090 distcleancheck:
8091         @@:
8092 @end example
8094 If you want @code{distcleancheck} to ignore built files that have not
8095 been cleaned because they are also part of the distribution, add the
8096 following definition instead:
8098 @example
8099 distcleancheck_listfiles = \
8100   find -type f -exec sh -c 'test -f $(srcdir)/@{@} || echo @{@}' ';'
8101 @end example
8103 The above definition is not the default because it's usually an error if
8104 your Makefiles cause some distributed files to be rebuilt when the user
8105 build the package.  (Think about the user missing the tool required to
8106 build the file; or if the required tool is built by your package,
8107 consider the cross-compilation case where it can't be run.)  There is
8108 a FAQ entry about this (@pxref{distcleancheck}), make sure you read it
8109 before playing with @code{distcleancheck_listfiles}.
8111 @code{distcheck} also checks that the @code{uninstall} rule works
8112 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8113 by invoking @samp{make uninstall}, and then it checks the install tree
8114 to see if any files are left over.  This check will make sure that you
8115 correctly coded your @code{uninstall}-related rules.
8117 By default, the checking is done by the @code{distuninstallcheck} rule,
8118 and the list of files in the install tree is generated by
8119 @samp{$(distuninstallcheck_listfiles}) (this is a variable whose value is
8120 a shell command to run that prints the list of files to stdout).
8122 Either of these can be overridden to modify the behavior of
8123 @code{distcheck}.  For instance, to disable this check completely, you
8124 would write:
8126 @example
8127 distuninstallcheck:
8128         @@:
8129 @end example
8131 @section The types of distributions
8133 Automake generates rules to provide archives of the project for
8134 distributions in various formats.  Their targets are:
8136 @table @asis
8137 @item @code{dist-bzip2}
8138 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8139 frequently smaller than gzipped archives.
8140 @trindex dist-bzip2
8142 @item @code{dist-gzip}
8143 Generate a gzip tar archive of the distribution.
8144 @trindex dist-gzip
8146 @item @code{dist-lzma}
8147 Generate a lzma tar archive of the distribution.  lzma archives are
8148 frequently smaller than @command{bzip2}-compressed archives.
8149 @trindex dist-lzma
8151 @item @code{dist-shar}
8152 Generate a shar archive of the distribution.
8153 @trindex dist-shar
8155 @item @code{dist-zip}
8156 Generate a zip archive of the distribution.
8157 @trindex dist-zip
8159 @item @code{dist-tarZ}
8160 Generate a compressed tar archive of
8161 the distribution.
8162 @trindex dist-tarZ
8163 @end table
8165 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8166 create archives in all the enabled formats, @ref{Options}.  By
8167 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8170 @node Tests
8171 @chapter Support for test suites
8173 @cindex Test suites
8174 @cindex @code{make check}
8175 @trindex check
8177 Automake supports two forms of test suites.
8179 @section Simple Tests
8181 If the variable @code{TESTS} is defined, its value is taken to be a
8182 list of programs or scripts to run in order to do the testing.
8183 Programs needing data files should look for them in @code{srcdir}
8184 (which is both an environment variable and a make variable) so they
8185 work when building in a separate directory (@pxref{Build Directories,
8186 , Build Directories , autoconf, The Autoconf Manual}), and in
8187 particular for the @code{distcheck} rule (@pxref{Dist}).
8189 For each of the @code{TESTS}, the result of execution is printed along
8190 with the test name, where @code{PASS} denotes a successful test,
8191 @code{FAIL} denotes a failed test, @code{XFAIL} an expected failure,
8192 @code{XPASS} an unexpected pass for a test that is supposed to fail,
8193 and @code{SKIP} denotes a skipped test.
8195 @cindex Exit status 77, special interpretation
8197 The number of failures will be printed at the end of the run.  If a
8198 given test program exits with a status of 77, then its result is ignored
8199 in the final count.  This feature allows non-portable tests to be
8200 ignored in environments where they don't make sense.
8202 @vindex AM_COLOR_TESTS
8203 If the Automake option @code{color-tests} is used (@pxref{Options})
8204 and standard output is connected to a capable terminal, then the test
8205 results and the summary are colored appropriately.  The user can disable
8206 colored output by setting the @command{make} variable
8207 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8208 terminal with @samp{AM_COLOR_TESTS=always}.
8210 @vindex TESTS
8211 @vindex TESTS_ENVIRONMENT
8212 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
8213 variables for the test run; the environment variable @code{srcdir} is
8214 set in the rule.  If all your test programs are scripts, you can also
8215 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
8216 @samp{$(SHELL) -x} can be useful for debugging the tests), or any other
8217 interpreter.  For instance the following setup is used by the Automake
8218 package to run four tests in Perl.
8219 @example
8220 TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
8221 TESTS = Condition.pl DisjConditions.pl Version.pl Wrap.pl
8222 @end example
8225 @cindex Tests, expected failure
8226 @cindex Expected test failure
8228 You may define the variable @code{XFAIL_TESTS} to a list of tests
8229 (usually a subset of @code{TESTS}) that are expected to fail.  This will
8230 reverse the result of those tests.
8231 @vindex XFAIL_TESTS
8233 Automake ensures that each file listed in @code{TESTS} is built before
8234 any tests are run; you can list both source and derived programs (or
8235 scripts) in @code{TESTS}; the generated rule will look both in
8236 @code{srcdir} and @file{.}.  For instance, you might want to run a C
8237 program as a test.  To do this you would list its name in @code{TESTS}
8238 and also in @code{check_PROGRAMS}, and then specify it as you would
8239 any other program.
8241 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8242 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8243 not during @code{make all}.  You should list there any program needed
8244 by your tests that does not need to be built by @code{make all}.  Note
8245 that @code{check_PROGRAMS} are @emph{not} automatically added to
8246 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8247 by the tests, not the tests themselves.  Of course you can set
8248 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8250 @section DejaGnu Tests
8252 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
8253 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
8254 assumed.  The variable @code{DEJATOOL} is a list of names that are
8255 passed, one at a time, as the @option{--tool} argument to
8256 @command{runtest} invocations; it defaults to the name of the package.
8258 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
8259 @option{--srcdir} flags that are passed to dejagnu by default; this can be
8260 overridden if necessary.
8261 @vindex RUNTESTDEFAULTFLAGS
8263 The variables @code{EXPECT} and @code{RUNTEST} can
8264 also be overridden to provide project-specific values.  For instance,
8265 you will need to do this if you are testing a compiler toolchain,
8266 because the default values do not take into account host and target
8267 names.
8268 @opindex dejagnu
8269 @vindex DEJATOOL
8270 @vindex EXPECT
8271 @vindex RUNTEST
8273 The contents of the variable @code{RUNTESTFLAGS} are passed to the
8274 @code{runtest} invocation.  This is considered a ``user variable''
8275 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
8276 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
8277 @vindex RUNTESTFLAGS
8278 @vindex AM_RUNTESTFLAGS
8280 @cindex @file{site.exp}
8281 Automake will generate rules to create a local @file{site.exp} file,
8282 defining various variables detected by @command{configure}.  This file
8283 is automatically read by DejaGnu.  It is OK for the user of a package
8284 to edit this file in order to tune the test suite.  However this is
8285 not the place where the test suite author should define new variables:
8286 this should be done elsewhere in the real test suite code.
8287 Especially, @file{site.exp} should not be distributed.
8289 For more information regarding DejaGnu test suites, see @ref{Top, , ,
8290 dejagnu, The DejaGnu Manual}.
8292 In either case, the testing is done via @samp{make check}.
8294 @section Install Tests
8296 The @code{installcheck} target is available to the user as a way to
8297 run any tests after the package has been installed.  You can add tests
8298 to this by writing an @code{installcheck-local} rule.
8301 @node Rebuilding
8302 @chapter Rebuilding Makefiles
8303 @cindex rebuild rules
8305 Automake generates rules to automatically rebuild @file{Makefile}s,
8306 @file{configure}, and other derived files like @file{Makefile.in}.
8308 @acindex AM_MAINTAINER_MODE
8309 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
8310 these automatic rebuilding rules are only enabled in maintainer mode.
8312 @vindex ACLOCAL_AMFLAGS
8313 Sometimes you need to run @command{aclocal} with an argument like
8314 @option{-I} to tell it where to find @file{.m4} files.  Since
8315 sometimes @command{make} will automatically run @command{aclocal}, you
8316 need a way to specify these arguments.  You can do this by defining
8317 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
8318 to @command{aclocal}.  This variable is only useful in the top-level
8319 @file{Makefile.am}.
8321 @vindex CONFIG_STATUS_DEPENDENCIES
8322 @vindex CONFIGURE_DEPENDENCIES
8323 @cindex @file{version.sh}, example
8324 @cindex @file{version.m4}, example
8326 Sometimes it is convenient to supplement the rebuild rules for
8327 @file{configure} or @file{config.status} with additional dependencies.
8328 The variables @code{CONFIGURE_DEPENDENCIES} and
8329 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
8330 dependencies.  These variable should be defined in all
8331 @file{Makefile}s of the tree (because these two rebuild rules are
8332 output in all them), so it is safer and easier to @code{AC_SUBST} them
8333 from @file{configure.ac}.  For instance, the following statement will
8334 cause @file{configure} to be rerun each time @file{version.sh} is
8335 changed.
8336 @example
8337 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
8338 @end example
8339 @noindent
8340 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
8341 is to be used in all @file{Makefile}s, its value must be sensible at
8342 any level in the build hierarchy.
8344 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
8345 @code{CONFIG_STATUS_DEPENDENCIES}.
8347 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
8348 @file{configure} rule, whose effect is to run @command{autoconf}.  This
8349 variable should be seldom used, because @command{automake} already tracks
8350 @code{m4_include}d files.  However it can be useful when playing
8351 tricky games with @code{m4_esyscmd} or similar non-recommendable
8352 macros with side effects.
8354 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
8355 @file{config.status} rule, whose effect is to run @file{configure}.
8356 This variable should therefore carry any non-standard source that may
8357 be read as a side effect of running configure, like @file{version.sh}
8358 in the example above.
8360 Speaking of @file{version.sh} scripts, we recommend against them
8361 today.  They are mainly used when the version of a package is updated
8362 automatically by a script (e.g., in daily builds).  Here is what some
8363 old-style @file{configure.ac}s may look like:
8364 @example
8365 AC_INIT
8366 . $srcdir/version.sh
8367 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
8368 @dots{}
8369 @end example
8370 @noindent
8371 Here, @file{version.sh} is a shell fragment that sets
8372 @code{VERSION_NUMBER}.  The problem with this example is that
8373 @command{automake} cannot track dependencies (listing @file{version.sh}
8374 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
8375 to the user), and that it uses the obsolete form of @code{AC_INIT} and
8376 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
8377 straightforward, because shell variables are not allowed in
8378 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
8379 replaced by an M4 file that is included by @file{configure.ac}:
8380 @example
8381 m4_include([version.m4])
8382 AC_INIT([name], VERSION_NUMBER)
8383 AM_INIT_AUTOMAKE
8384 @dots{}
8385 @end example
8386 @noindent
8387 Here @file{version.m4} could contain something like
8388 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
8389 second form is that @command{automake} will take care of the
8390 dependencies when defining the rebuild rule, and will also distribute
8391 the file automatically.  An inconvenience is that @command{autoconf}
8392 will now be rerun each time the version number is bumped, when only
8393 @file{configure} had to be rerun in the previous setup.
8396 @node Options
8397 @chapter Changing Automake's Behavior
8399 Various features of Automake can be controlled by options in the
8400 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
8401 basis when listed in a special @file{Makefile} variable named
8402 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
8403 @file{Makefiles} when listed in the first argument of
8404 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}.  Currently understood
8405 options are:
8406 @vindex AUTOMAKE_OPTIONS
8408 @table @asis
8409 @item @option{gnits}
8410 @itemx @option{gnu}
8411 @itemx @option{foreign}
8412 @itemx @option{cygnus}
8413 @cindex Option, @option{gnits}
8414 @cindex Option, @option{gnu}
8415 @cindex Option, @option{foreign}
8416 @cindex Option, @option{cygnus}
8417 @opindex gnits
8418 @opindex gnu
8419 @opindex foreign
8420 @opindex cygnus
8422 Set the strictness as appropriate.  The @option{gnits} option also
8423 implies options @option{readme-alpha} and @option{check-news}.
8425 @item @option{ansi2knr}
8426 @itemx @option{@var{path}/ansi2knr}
8427 @cindex Option, @option{ansi2knr}
8428 @opindex ansi2knr
8429 Turn on the obsolete de-ANSI-fication feature.  @xref{ANSI}.  If preceded by a
8430 path, the generated @file{Makefile.in} will look in the specified
8431 directory to find the @file{ansi2knr} program.  The path should be a
8432 relative path to another directory in the same distribution (Automake
8433 currently does not check this).
8435 @item @option{check-news}
8436 @cindex Option, @option{check-news}
8437 @opindex check-news
8438 Cause @samp{make dist} to fail unless the current version number appears
8439 in the first few lines of the @file{NEWS} file.
8441 @item @option{color-tests}
8442 @cindex Option, @option{color-tests}
8443 @opindex color-tests
8444 Cause output of the simple test suite (@pxref{Tests}) to be
8445 colorized on capable terminals.
8447 @item @option{dejagnu}
8448 @cindex Option, @option{dejagnu}
8449 @opindex dejagnu
8450 Cause @command{dejagnu}-specific rules to be generated.  @xref{Tests}.
8452 @item @option{dist-bzip2}
8453 @cindex Option, @option{dist-bzip2}
8454 @opindex dist-bzip2
8455 Hook @code{dist-bzip2} to @code{dist}.
8456 @trindex dist-bzip2
8458 @item @option{dist-lzma}
8459 @cindex Option, @option{dist-lzma}
8460 @opindex dist-lzma
8461 Hook @code{dist-lzma} to @code{dist}.
8462 @trindex dist-lzma
8464 @item @option{dist-shar}
8465 @cindex Option, @option{dist-shar}
8466 @opindex dist-shar
8467 Hook @code{dist-shar} to @code{dist}.
8468 @trindex dist-shar
8470 @item @option{dist-zip}
8471 @cindex Option, @option{dist-zip}
8472 @opindex dist-zip
8473 Hook @code{dist-zip} to @code{dist}.
8474 @trindex dist-zip
8476 @item @option{dist-tarZ}
8477 @cindex Option, @option{dist-tarZ}
8478 @opindex dist-tarZ
8479 Hook @code{dist-tarZ} to @code{dist}.
8480 @trindex dist-tarZ
8482 @item @option{filename-length-max=99}
8483 @cindex Option, @option{filename-length-max=99}
8484 @opindex filename-length-max=99
8485 Abort if file names longer than 99 characters are found during
8486 @samp{make dist}.  Such long file names are generally considered not to
8487 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
8488 options below.  This option should be used in the top-level
8489 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
8490 @file{configure.ac}, it will be ignored otherwise.  It will also be
8491 ignored in sub-packages of nested packages (@pxref{Subpackages}).
8493 @item @option{no-define}
8494 @cindex Option, @option{no-define}
8495 @opindex no-define
8496 This options is meaningful only when passed as an argument to
8497 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
8498 @code{VERSION} variables to be @code{AC_DEFINE}d.
8500 @item @option{no-dependencies}
8501 @cindex Option, @option{no-dependencies}
8502 @opindex no-dependencies
8503 This is similar to using @option{--ignore-deps} on the command line,
8504 but is useful for those situations where you don't have the necessary
8505 bits to make automatic dependency tracking work
8506 (@pxref{Dependencies}).  In this case the effect is to effectively
8507 disable automatic dependency tracking.
8509 @item @option{no-dist}
8510 @cindex Option, @option{no-dist}
8511 @opindex no-dist
8512 Don't emit any code related to @code{dist} target.  This is useful
8513 when a package has its own method for making distributions.
8515 @item @option{no-dist-gzip}
8516 @cindex Option, @option{no-dist-gzip}
8517 @opindex no-dist-gzip
8518 Do not hook @code{dist-gzip} to @code{dist}.
8519 @trindex no-dist-gzip
8521 @item @option{no-exeext}
8522 @cindex Option, @option{no-exeext}
8523 @opindex no-exeext
8524 If your @file{Makefile.am} defines a rule for target @code{foo}, it
8525 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
8526 necessary when @code{EXEEXT} is found to be empty.  However, by
8527 default automake will generate an error for this use.  The
8528 @option{no-exeext} option will disable this error.  This is intended for
8529 use only where it is known in advance that the package will not be
8530 ported to Windows, or any other operating system using extensions on
8531 executables.
8533 @item @option{no-installinfo}
8534 @cindex Option, @option{no-installinfo}
8535 @opindex no-installinfo
8536 The generated @file{Makefile.in} will not cause info pages to be built
8537 or installed by default.  However, @code{info} and @code{install-info}
8538 targets will still be available.  This option is disallowed at
8539 @option{gnu} strictness and above.
8540 @trindex info
8541 @trindex install-info
8543 @item @option{no-installman}
8544 @cindex Option, @option{no-installman}
8545 @opindex no-installman
8546 The generated @file{Makefile.in} will not cause man pages to be
8547 installed by default.  However, an @code{install-man} target will still
8548 be available for optional installation.  This option is disallowed at
8549 @option{gnu} strictness and above.
8550 @trindex install-man
8552 @item @option{nostdinc}
8553 @cindex Option, @option{nostdinc}
8554 @opindex nostdinc
8555 This option can be used to disable the standard @option{-I} options that
8556 are ordinarily automatically provided by Automake.
8558 @item @option{no-texinfo.tex}
8559 @cindex Option, @option{no-texinfo.tex}
8560 @opindex no-texinfo.tex
8561 Don't require @file{texinfo.tex}, even if there are texinfo files in
8562 this directory.
8564 @item @option{readme-alpha}
8565 @cindex Option, @option{readme-alpha}
8566 @opindex readme-alpha
8567 If this release is an alpha release, and the file @file{README-alpha}
8568 exists, then it will be added to the distribution.  If this option is
8569 given, version numbers are expected to follow one of two forms.  The
8570 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
8571 element is a number; the final period and number should be left off for
8572 non-alpha releases.  The second form is
8573 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
8574 letter; it should be omitted for non-alpha releases.
8576 @item @option{std-options}
8577 @cindex Options, @option{std-options}
8578 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
8579 @cindex @option{--help} check
8580 @cindex @option{--version} check
8581 @opindex std-options
8583 Make the @code{installcheck} rule check that installed scripts and
8584 programs support the @option{--help} and @option{--version} options.
8585 This also provides a basic check that the program's
8586 run-time dependencies are satisfied after installation.
8588 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
8589 In a few situations, programs (or scripts) have to be exempted from this
8590 test.  For instance, @command{false} (from GNU sh-utils) is never
8591 successful, even for @option{--help} or @option{--version}.  You can list
8592 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
8593 Programs (not scripts) listed in this variable should be suffixed by
8594 @samp{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance, suppose we
8595 build @file{false} as a program but @file{true.sh} as a script, and that
8596 neither of them support @option{--help} or @option{--version}:
8598 @example
8599 AUTOMAKE_OPTIONS = std-options
8600 bin_PROGRAMS = false ...
8601 bin_SCRIPTS = true.sh ...
8602 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
8603 @end example
8605 @item @option{subdir-objects}
8606 @cindex Options, @option{subdir-objects}
8607 @opindex subdir-objects
8608 If this option is specified, then objects are placed into the
8609 subdirectory of the build directory corresponding to the subdirectory of
8610 the source file.  For instance, if the source file is
8611 @file{subdir/file.cxx}, then the output file would be
8612 @file{subdir/file.o}.
8614 In order to use this option with C sources, you should add
8615 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
8617 @anchor{tar-formats}
8618 @item @option{tar-v7}
8619 @itemx @option{tar-ustar}
8620 @itemx @option{tar-pax}
8621 @cindex Option, @option{tar-v7}
8622 @cindex Option, @option{tar-ustar}
8623 @cindex Option, @option{tar-pax}
8624 @cindex @command{tar} formats
8625 @cindex v7 @command{tar} format
8626 @cindex ustar format
8627 @cindex pax format
8628 @opindex tar-v7
8629 @opindex tar-ustar
8630 @opindex tar-pax
8632 These three mutually exclusive options select the tar format to use
8633 when generating tarballs with @samp{make dist}.  (The tar file created
8634 is then compressed according to the set of @option{no-dist-gzip},
8635 @option{dist-bzip2}, @option{dist-lzma} and @option{dist-tarZ} options in use.)
8637 These options must be passed as argument to @code{AM_INIT_AUTOMAKE}
8638 (@pxref{Macros}) because they can require additional configure checks.
8639 Automake will complain if it sees such options in an
8640 @code{AUTOMAKE_OPTIONS} variable.
8642 @option{tar-v7} selects the old V7 tar format.  This is the historical
8643 default.  This antiquated format is understood by all tar
8644 implementations and supports file names with up to 99 characters.  When
8645 given longer file names some tar implementations will diagnose the
8646 problem while other will generate broken tarballs or use non-portable
8647 extensions.  Furthermore, the V7 format cannot store empty
8648 directories.  When using this format, consider using the
8649 @option{filename-length-max=99} option to catch file names too long.
8651 @option{tar-ustar} selects the ustar format defined by POSIX
8652 1003.1-1988.  This format is believed to be old enough to be portable.
8653 It fully supports empty directories.  It can store file names with up
8654 to 256 characters, provided that the file name can be split at
8655 directory separator in two parts, first of them being at most 155
8656 bytes long.  So, in most cases the maximum file name length will be
8657 shorter than 256 characters.  However you may run against broken tar
8658 implementations that incorrectly handle file names longer than 99
8659 characters (please report them to @email{bug-automake@@gnu.org} so we
8660 can document this accurately).
8662 @option{tar-pax} selects the new pax interchange format defined by POSIX
8663 1003.1-2001.  It does not limit the length of file names.  However,
8664 this format is very young and should probably be restricted to
8665 packages that target only very modern platforms.  There are moves to
8666 change the pax format in an upward-compatible way, so this option may
8667 refer to a more recent version in the future.
8669 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
8670 further discussion about tar formats.
8672 @command{configure} knows several ways to construct these formats.  It
8673 will not abort if it cannot find a tool up to the task (so that the
8674 package can still be built), but @samp{make dist} will fail.
8676 @item @var{version}
8677 @cindex Option, @var{version}
8678 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
8679 newer than the version specified, creation of the @file{Makefile.in}
8680 will be suppressed.
8682 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
8683 @cindex Option, warnings
8684 @cindex Option, @option{-W@var{category}}
8685 @cindex Option, @option{--warnings=@var{category}}
8686 These options behave exactly like their command-line counterpart
8687 (@pxref{Invoking Automake}).  This allows you to enable or disable some
8688 warning categories on a per-file basis.  You can also setup some warnings
8689 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
8690 in your @file{configure.ac}.
8692 @end table
8694 Unrecognized options are diagnosed by @command{automake}.
8696 If you want an option to apply to all the files in the tree, you can use
8697 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
8698 @xref{Macros}.
8701 @node Miscellaneous
8702 @chapter Miscellaneous Rules
8704 There are a few rules and variables that didn't fit anywhere else.
8706 @menu
8707 * Tags::                        Interfacing to etags and mkid
8708 * Suffixes::                    Handling new file extensions
8709 * Multilibs::                   Support for multilibs.
8710 @end menu
8713 @node Tags
8714 @section Interfacing to @command{etags}
8716 @cindex @file{TAGS} support
8718 Automake will generate rules to generate @file{TAGS} files for use with
8719 GNU Emacs under some circumstances.
8721 @trindex tags
8722 If any C, C++ or Fortran 77 source code or headers are present, then
8723 @code{tags} and @code{TAGS} rules will be generated for the directory.
8724 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
8725 @code{_LISP} primaries will be used to generate tags.  Note that
8726 generated source files that are not distributed must be declared in
8727 variables like @code{nodist_noinst_HEADERS} or
8728 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
8730 A @code{tags} rule will be output at the topmost directory of a
8731 multi-directory package.  When run from this topmost directory,
8732 @samp{make tags} will generate a @file{TAGS} file that includes by
8733 reference all @file{TAGS} files from subdirectories.
8735 The @code{tags} rule will also be generated if the variable
8736 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
8737 directories that contain taggable source that @command{etags} does
8738 not understand.  The user can use the @code{ETAGSFLAGS} to pass
8739 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
8740 available for use in @file{Makefile.am}.
8741 @vindex ETAGS_ARGS
8742 @vindex ETAGSFLAGS
8743 @vindex AM_ETAGSFLAGS
8745 Here is how Automake generates tags for its source, and for nodes in its
8746 Texinfo file:
8748 @example
8749 ETAGS_ARGS = automake.in --lang=none \
8750  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
8751 @end example
8753 If you add file names to @code{ETAGS_ARGS}, you will probably also
8754 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
8755 are added directly to the dependencies for the @code{tags} rule.
8756 @vindex TAGS_DEPENDENCIES
8758 Automake also generates a @code{ctags} rule that can be used to
8759 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
8760 is the name of the program to invoke (by default @command{ctags});
8761 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
8762 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
8764 Automake will also generate an @code{ID} rule that will run
8765 @command{mkid} on the source.  This is only supported on a
8766 directory-by-directory basis.
8767 @trindex id
8769 Finally, Automake also emit rules to support the
8770 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
8771 The @code{GTAGS} rule runs Global Tags and puts the
8772 result in the top build directory.  The variable @code{GTAGS_ARGS}
8773 holds arguments that are passed to @command{gtags}.
8774 @vindex GTAGS_ARGS
8777 @node Suffixes
8778 @section Handling new file extensions
8780 @cindex Adding new @code{SUFFIXES}
8781 @cindex @code{SUFFIXES}, adding
8782 @vindex SUFFIXES
8784 It is sometimes useful to introduce a new implicit rule to handle a file
8785 type that Automake does not know about.
8787 For instance, suppose you had a compiler that could compile @file{.foo}
8788 files to @file{.o} files.  You would simply define an suffix rule for
8789 your language:
8791 @example
8792 .foo.o:
8793         foocc -c -o $@@ $<
8794 @end example
8796 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
8797 variable and expect the correct results:
8799 @example
8800 bin_PROGRAMS = doit
8801 doit_SOURCES = doit.foo
8802 @end example
8804 This was the simpler and more common case.  In other cases, you will
8805 have to help Automake to figure which extensions you are defining your
8806 suffix rule for.  This usually happens when your extensions does not
8807 start with a dot.  Then, all you have to do is to put a list of new
8808 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
8809 implicit rule.
8811 For instance, the following definition prevents Automake to misinterpret
8812 @samp{.idlC.cpp:} as an attempt to transform @file{.idlC} files into
8813 @file{.cpp} files.
8815 @example
8816 SUFFIXES = .idl C.cpp
8817 .idlC.cpp:
8818         # whatever
8819 @end example
8821 As you may have noted, the @code{SUFFIXES} variable behaves like the
8822 @code{.SUFFIXES} special target of @command{make}.  You should not touch
8823 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
8824 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
8825 @code{SUFFIXES} go at the start of the generated suffixes list, followed
8826 by Automake generated suffixes not already in the list.
8828 @node Multilibs
8829 @section Support for Multilibs
8831 Automake has support for an obscure feature called multilibs.  A
8832 @dfn{multilib} is a library that is built for multiple different ABIs
8833 at a single time; each time the library is built with a different target
8834 flag combination.  This is only useful when the library is intended to
8835 be cross-compiled, and it is almost exclusively used for compiler
8836 support libraries.
8838 The multilib support is still experimental.  Only use it if you are
8839 familiar with multilibs and can debug problems you might encounter.
8842 @node Include
8843 @chapter Include
8845 @cmindex include
8846 @cindex Including @file{Makefile} fragment
8847 @cindex @file{Makefile} fragment, including
8849 Automake supports an @code{include} directive that  can be used to
8850 include other @file{Makefile} fragments when @command{automake} is run.
8851 Note that these fragments are read and interpreted by @command{automake},
8852 not by @command{make}.  As with conditionals, @command{make} has no idea that
8853 @code{include} is in use.
8855 There are two forms of @code{include}:
8857 @table @code
8858 @item include $(srcdir)/file
8859 Include a fragment that is found relative to the current source
8860 directory.
8862 @item include $(top_srcdir)/file
8863 Include a fragment that is found relative to the top source directory.
8864 @end table
8866 Note that if a fragment is included inside a conditional, then the
8867 condition applies to the entire contents of that fragment.
8869 Makefile fragments included this way are always distributed because
8870 they are needed to rebuild @file{Makefile.in}.
8872 @node Conditionals
8873 @chapter Conditionals
8875 @cindex Conditionals
8877 Automake supports a simple type of conditionals.
8879 @unnumberedsec Usage
8881 @acindex AM_CONDITIONAL
8882 Before using a conditional, you must define it by using
8883 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
8885 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
8886 The conditional name, @var{conditional}, should be a simple string
8887 starting with a letter and containing only letters, digits, and
8888 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
8889 that are reserved by Automake.
8891 The shell @var{condition} (suitable for use in a shell @code{if}
8892 statement) is evaluated when @command{configure} is run.  Note that you
8893 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
8894 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
8895 conditionally (e.g., in a shell @code{if} statement), then the result
8896 will confuse automake.
8897 @end defmac
8899 @cindex @option{--enable-debug}, example
8900 @cindex Example conditional @option{--enable-debug}
8901 @cindex Conditional example, @option{--enable-debug}
8903 Conditionals typically depend upon options that the user provides to
8904 the @command{configure} script.  Here is an example of how to write a
8905 conditional that is true if the user uses the @option{--enable-debug}
8906 option.
8908 @example
8909 AC_ARG_ENABLE([debug],
8910 [  --enable-debug    Turn on debugging],
8911 [case "$@{enableval@}" in
8912   yes) debug=true ;;
8913   no)  debug=false ;;
8914   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
8915 esac],[debug=false])
8916 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
8917 @end example
8919 Here is an example of how to use that conditional in @file{Makefile.am}:
8921 @cmindex if
8922 @cmindex endif
8923 @cmindex else
8925 @example
8926 if DEBUG
8927 DBG = debug
8928 else
8929 DBG =
8930 endif
8931 noinst_PROGRAMS = $(DBG)
8932 @end example
8934 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
8935 (@pxref{Conditional Programs}).
8937 You may only test a single variable in an @code{if} statement, possibly
8938 negated using @samp{!}.  The @code{else} statement may be omitted.
8939 Conditionals may be nested to any depth.  You may specify an argument to
8940 @code{else} in which case it must be the negation of the condition used
8941 for the current @code{if}.  Similarly you may specify the condition
8942 that is closed by an @code{end}:
8944 @example
8945 if DEBUG
8946 DBG = debug
8947 else !DEBUG
8948 DBG =
8949 endif !DEBUG
8950 @end example
8952 @noindent
8953 Unbalanced conditions are errors.
8955 The @code{else} branch of the above two examples could be omitted,
8956 since assigning the empty string to an otherwise undefined variable
8957 makes no difference.
8959 @acindex AM_COND_IF
8960 In order to allow access to the condition registered by
8961 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
8962 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
8964 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
8965 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
8966 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
8967 it will cause @command{automake} to output the rules for the respective
8968 files only for the given condition.
8969 @end defmac
8971 @code{AM_COND_IF} macros may be nested when m4 quotation is used
8972 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
8974 @cindex Example conditional @code{AC_CONFIG_FILES}
8975 @cindex @code{AC_CONFIG_FILES}, conditional
8977 Here is an example of how to define a conditional config file:
8979 @example
8980 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
8981 AM_COND_IF([SHELL_WRAPPER],
8982            [AC_CONFIG_FILES([wrapper:wrapper.in])])
8983 @end example
8985 @unnumberedsec Portability
8987 Note that conditionals in Automake are not the same as conditionals in
8988 GNU Make.  Automake conditionals are checked at configure time by the
8989 @file{configure} script, and affect the translation from
8990 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
8991 to @file{configure} and on results that @file{configure} has discovered
8992 about the host system.  GNU Make conditionals are checked at @command{make}
8993 time, and are based on variables passed to the make program or defined
8994 in the @file{Makefile}.
8996 Automake conditionals will work with any make program.
8998 @unnumberedsec Limits
9000 Conditionals should enclose complete statements like variables or
9001 rules definitions.  Automake cannot deal with conditionals used inside
9002 a variable definition, for instance, and is not even able to diagnose
9003 this situation.  The following example would not work:
9005 @example
9006 # This syntax is not understood by Automake
9007 AM_CPPFLAGS = \
9008   -DFEATURE_A \
9009 if WANT_DEBUG
9010   -DDEBUG \
9011 endif
9012   -DFEATURE_B
9013 @end example
9015 However the intended definition of @code{AM_CPPFLAGS} can be achieved
9016 with
9018 @example
9019 if WANT_DEBUG
9020   DEBUGFLAGS = -DDEBUG
9021 endif
9022 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
9023 @end example
9025 @noindent or
9027 @example
9028 AM_CPPFLAGS = -DFEATURE_A
9029 if WANT_DEBUG
9030 AM_CPPFLAGS += -DDEBUG
9031 endif
9032 AM_CPPFLAGS += -DFEATURE_B
9033 @end example
9035 @node Gnits
9036 @chapter The effect of @option{--gnu} and @option{--gnits}
9038 @cindex @option{--gnu}, required files
9039 @cindex @option{--gnu}, complete description
9041 The @option{--gnu} option (or @option{gnu} in the
9042 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
9043 the following:
9045 @itemize @bullet
9046 @item
9047 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
9048 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
9049 or @file{COPYING}, are required at the topmost directory of the package.
9051 @item
9052 The options @option{no-installman} and @option{no-installinfo} are
9053 prohibited.
9054 @end itemize
9056 Note that this option will be extended in the future to do even more
9057 checking; it is advisable to be familiar with the precise requirements
9058 of the GNU standards.  Also, @option{--gnu} can require certain
9059 non-standard GNU programs to exist for use by various maintainer-only
9060 rules; for instance, in the future @command{pathchk} might be required for
9061 @samp{make dist}.
9063 @cindex @option{--gnits}, complete description
9065 The @option{--gnits} option does everything that @option{--gnu} does, and
9066 checks the following as well:
9068 @itemize @bullet
9069 @item
9070 @samp{make installcheck} will check to make sure that the @option{--help}
9071 and @option{--version} really print a usage message and a version string,
9072 respectively.  This is the @option{std-options} option (@pxref{Options}).
9074 @item
9075 @samp{make dist} will check to make sure the @file{NEWS} file has been
9076 updated to the current version.
9078 @item
9079 @code{VERSION} is checked to make sure its format complies with Gnits
9080 standards.
9081 @c FIXME xref when standards are finished
9083 @item
9084 @cindex @file{README-alpha}
9085 If @code{VERSION} indicates that this is an alpha release, and the file
9086 @file{README-alpha} appears in the topmost directory of a package, then
9087 it is included in the distribution.  This is done in @option{--gnits}
9088 mode, and no other, because this mode is the only one where version
9089 number formats are constrained, and hence the only mode where Automake
9090 can automatically determine whether @file{README-alpha} should be
9091 included.
9093 @item
9094 The file @file{THANKS} is required.
9095 @end itemize
9098 @node Cygnus
9099 @chapter The effect of @option{--cygnus}
9101 @cindex @option{cygnus} strictness
9103 Some packages, notably GNU GCC and GNU gdb, have a build environment
9104 originally written at Cygnus Support (subsequently renamed Cygnus
9105 Solutions, and then later purchased by Red Hat).  Packages with this
9106 ancestry are sometimes referred to as ``Cygnus'' trees.
9108 A Cygnus tree has slightly different rules for how a
9109 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
9110 @command{automake} will cause any generated @file{Makefile.in} to
9111 comply with Cygnus rules.
9113 Here are the precise effects of @option{--cygnus}:
9115 @itemize @bullet
9116 @item
9117 Info files are always created in the build directory, and not in the
9118 source directory.
9120 @item
9121 @file{texinfo.tex} is not required if a Texinfo source file is
9122 specified.  The assumption is that the file will be supplied, but in a
9123 place that Automake cannot find.  This assumption is an artifact of how
9124 Cygnus packages are typically bundled.
9126 @item
9127 @samp{make dist} is not supported, and the rules for it are not
9128 generated.  Cygnus-style trees use their own distribution mechanism.
9130 @item
9131 Certain tools will be searched for in the build tree as well as in the
9132 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
9133 @command{makeinfo} and @command{texi2dvi}.
9135 @item
9136 @option{--foreign} is implied.
9138 @item
9139 The options @option{no-installinfo} and @option{no-dependencies} are
9140 implied.
9142 @item
9143 The macros @code{AM_MAINTAINER_MODE} and @code{AM_CYGWIN32} are
9144 required.
9146 @item
9147 The @code{check} target doesn't depend on @code{all}.
9148 @end itemize
9150 GNU maintainers are advised to use @option{gnu} strictness in preference
9151 to the special Cygnus mode.  Some day, perhaps, the differences between
9152 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
9153 more standards compliant).  At that time the special Cygnus mode will be
9154 removed.
9157 @node Not Enough
9158 @chapter When Automake Isn't Enough
9160 In some situations, where Automake is not up to one task, one has to
9161 resort to handwritten rules or even handwritten @file{Makefile}s.
9163 @menu
9164 * Extending::                   Adding new rules or overriding existing ones.
9165 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
9166 @end menu
9168 @node Extending
9169 @section Extending Automake Rules
9171 With some minor exceptions (for example @code{_PROGRAMS} variables,
9172 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
9173 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
9174 @file{Makefile.in} verbatim.
9176 @cindex copying semantics
9178 These copying semantics means that many problems can be worked around
9179 by simply adding some @command{make} variables and rules to
9180 @file{Makefile.am}.  Automake will ignore these additions.
9182 @cindex conflicting definitions
9183 @cindex rules, conflicting
9184 @cindex variables, conflicting
9185 @cindex definitions, conflicts
9187 Since a @file{Makefile.in} is built from data gathered from three
9188 different places (@file{Makefile.am}, @file{configure.ac}, and
9189 @command{automake} itself), it is possible to have conflicting
9190 definitions of rules or variables.  When building @file{Makefile.in}
9191 the following priorities are respected by @command{automake} to ensure
9192 the user always have the last word.  User defined variables in
9193 @file{Makefile.am} have priority over variables @code{AC_SUBST}ed from
9194 @file{configure.ac}, and @code{AC_SUBST}ed variables have priority
9195 over @command{automake}-defined variables.  As far rules are
9196 concerned, a user-defined rule overrides any
9197 @command{automake}-defined rule for the same target.
9199 @cindex overriding rules
9200 @cindex overriding semantics
9201 @cindex rules, overriding
9203 These overriding semantics make it possible to fine tune some default
9204 settings of Automake, or replace some of its rules.  Overriding
9205 Automake rules is often inadvisable, particularly in the topmost
9206 directory of a package with subdirectories.  The @option{-Woverride}
9207 option (@pxref{Invoking Automake}) comes handy to catch overridden
9208 definitions.
9210 Note that Automake does not make any difference between rules with
9211 commands and rules that only specify dependencies.  So it is not
9212 possible to append new dependencies to an @command{automake}-defined
9213 target without redefining the entire rule.
9215 @cindex @option{-local} targets
9216 @cindex local targets
9218 However, various useful targets have a @samp{-local} version you can
9219 specify in your @file{Makefile.am}.  Automake will supplement the
9220 standard target with these user-supplied targets.
9222 @trindex  all
9223 @trindex  all-local
9224 @trindex  info
9225 @trindex  info-local
9226 @trindex  dvi
9227 @trindex  dvi-local
9228 @trindex  ps
9229 @trindex  ps-local
9230 @trindex  pdf
9231 @trindex  pdf-local
9232 @trindex  html
9233 @trindex  html-local
9234 @trindex  check
9235 @trindex  check-local
9236 @trindex  install
9237 @trindex  install-data
9238 @trindex  install-data-local
9239 @trindex  install-dvi
9240 @trindex  install-dvi-local
9241 @trindex  install-exec
9242 @trindex  install-exec-local
9243 @trindex  install-html
9244 @trindex  install-html-local
9245 @trindex  install-info
9246 @trindex  install-info-local
9247 @trindex  install-pdf
9248 @trindex  install-pdf-local
9249 @trindex  install-ps
9250 @trindex  install-ps-local
9251 @trindex  uninstall
9252 @trindex  uninstall-local
9253 @trindex  mostlyclean
9254 @trindex  mostlyclean-local
9255 @trindex  clean
9256 @trindex  clean-local
9257 @trindex  distclean
9258 @trindex  distclean-local
9259 @trindex  installdirs
9260 @trindex  installdirs-local
9261 @trindex  installcheck
9262 @trindex  installcheck-local
9264 The targets that support a local version are @code{all}, @code{info},
9265 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
9266 @code{install-data}, @code{install-dvi}, @code{install-exec},
9267 @code{install-html}, @code{install-info}, @code{install-pdf},
9268 @code{install-ps}, @code{uninstall}, @code{installdirs},
9269 @code{installcheck} and the various @code{clean} targets
9270 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
9271 @code{maintainer-clean}).
9273 Note that there are no @code{uninstall-exec-local} or
9274 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
9275 It doesn't make sense to uninstall just data or just executables.
9277 For instance, here is one way to erase a subdirectory during
9278 @samp{make clean} (@pxref{Clean}).
9280 @example
9281 clean-local:
9282         -rm -rf testSubDir
9283 @end example
9285 You may be tempted to use @code{install-data-local} to install a file
9286 to some hard-coded location, but you should avoid this
9287 (@pxref{Hard-Coded Install Paths}).
9289 With the @code{-local} targets, there is no particular guarantee of
9290 execution order; typically, they are run early, but with parallel
9291 make, there is no way to be sure of that.
9293 @cindex @option{-hook} targets
9294 @cindex hook targets
9295 @trindex install-data-hook
9296 @trindex install-exec-hook
9297 @trindex uninstall-hook
9298 @trindex dist-hook
9300 In contrast, some rules also have a way to run another rule, called a
9301 @dfn{hook}; hooks are always executed after the main rule's work is done.
9302 The hook is named after the principal target, with @samp{-hook} appended.
9303 The targets allowing hooks are @code{install-data},
9304 @code{install-exec}, @code{uninstall}, @code{dist}, and
9305 @code{distcheck}.
9307 For instance, here is how to create a hard link to an installed program:
9309 @example
9310 install-exec-hook:
9311         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
9312            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
9313 @end example
9315 Although cheaper and more portable than symbolic links, hard links
9316 will not work everywhere (for instance, OS/2 does not have
9317 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
9318 @command{ln} does not work.  An easy way, if symbolic links are
9319 acceptable to you, is to add @code{AC_PROG_LN_S} to
9320 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
9321 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
9322 @file{Makefile.am}.
9324 @cindex versioned binaries, installing
9325 @cindex installing versioned binaries
9326 @cindex @code{LN_S} example
9327 For instance, here is how you could install a versioned copy of a
9328 program using @samp{$(LN_S)}:
9330 @example
9331 install-exec-hook:
9332         cd $(DESTDIR)$(bindir) && \
9333           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
9334           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
9335 @end example
9337 Note that we rename the program so that a new version will erase the
9338 symbolic link, not the real binary.  Also we @command{cd} into the
9339 destination directory in order to create relative links.
9341 When writing @code{install-exec-hook} or @code{install-data-hook},
9342 please bear in mind that the exec/data distinction is based on the
9343 installation directory, not on the primary used (@pxref{Install}).  So
9344 a @code{foo_SCRIPTS} will be installed by @code{install-data}, and a
9345 @code{barexec_SCRIPTS} will be installed by @code{install-exec}.  You
9346 should define your hooks consequently.
9348 @c FIXME should include discussion of variables you can use in these
9349 @c rules
9351 @node Third-Party Makefiles
9352 @section Third-Party @file{Makefile}s
9354 @cindex Third-party packages, interfacing with
9355 @cindex Interfacing with third-party packages
9357 In most projects all @file{Makefile}s are generated by Automake.  In
9358 some cases, however, projects need to embed subdirectories with
9359 handwritten @file{Makefile}s.  For instance, one subdirectory could be
9360 a third-party project with its own build system, not using Automake.
9362 It is possible to list arbitrary directories in @code{SUBDIRS} or
9363 @code{DIST_SUBDIRS} provided each of these directories has a
9364 @file{Makefile} that recognizes all the following recursive targets.
9366 @cindex recursive targets and third-party @file{Makefile}s
9367 When a user runs one of these targets, that target is run recursively
9368 in all subdirectories.  This is why it is important that even
9369 third-party @file{Makefile}s support them.
9371 @table @code
9372 @item all
9373 Compile the entire package.  This is the default target in
9374 Automake-generated @file{Makefile}s, but it does not need to be the
9375 default in third-party @file{Makefile}s.
9377 @item distdir
9378 @trindex distdir
9379 @vindex distdir
9380 @vindex top_distdir
9381 Copy files to distribute into @samp{$(distdir)}, before a tarball is
9382 constructed.  Of course this target is not required if the
9383 @option{no-dist} option (@pxref{Options}) is used.
9385 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
9386 (@pxref{Dist}) will be passed from the outer package to the subpackage
9387 when the @code{distdir} target is invoked.  These two variables have
9388 been adjusted for the directory that is being recursed into, so they
9389 are ready to use.
9391 @item install
9392 @itemx install-data
9393 @itemx install-exec
9394 @itemx uninstall
9395 Install or uninstall files (@pxref{Install}).
9397 @item install-dvi
9398 @itemx install-html
9399 @itemx install-info
9400 @itemx install-ps
9401 @itemx install-pdf
9402 Install only some specific documentation format (@pxref{Texinfo}).
9404 @item installdirs
9405 Create install directories, but do not install any files.
9407 @item check
9408 @itemx installcheck
9409 Check the package (@pxref{Tests}).
9411 @item mostlyclean
9412 @itemx clean
9413 @itemx distclean
9414 @itemx maintainer-clean
9415 Cleaning rules (@pxref{Clean}).
9417 @item dvi
9418 @itemx pdf
9419 @itemx ps
9420 @itemx info
9421 @itemx html
9422 Build the documentation in various formats (@pxref{Texinfo}).
9424 @item tags
9425 @itemx ctags
9426 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
9427 @end table
9429 If you have ever used Gettext in a project, this is a good example of
9430 how third-party @file{Makefile}s can be used with Automake.  The
9431 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
9432 @file{intl/} directories are handwritten @file{Makefile}s that
9433 implement all these targets.  That way they can be added to
9434 @code{SUBDIRS} in Automake packages.
9436 Directories that are only listed in @code{DIST_SUBDIRS} but not in
9437 @code{SUBDIRS} need only the @code{distclean},
9438 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
9439 Subdirectories}).
9441 Usually, many of these rules are irrelevant to the third-party
9442 subproject, but they are required for the whole package to work.  It's
9443 OK to have a rule that does nothing, so if you are integrating a
9444 third-party project with no documentation or tag support, you could
9445 simply augment its @file{Makefile} as follows:
9447 @example
9448 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
9449 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
9450 $(EMPTY_AUTOMAKE_TARGETS):
9451 @end example
9453 Another aspect of integrating third-party build systems is whether
9454 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
9455 subpackage does not support VPATH builds the whole package will not
9456 support VPATH builds.  This in turns means that @samp{make distcheck}
9457 will not work, because it relies on VPATH builds.  Some people can
9458 live without this (actually, many Automake users have never heard of
9459 @samp{make distcheck}).  Other people may prefer to revamp the
9460 existing @file{Makefile}s to support VPATH@.  Doing so does not
9461 necessarily require Automake, only Autoconf is needed (@pxref{Build
9462 Directories, , Build Directories, autoconf, The Autoconf Manual}).
9463 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
9464 and @samp{@@top_builddir@@} are defined by @file{configure} when it
9465 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
9466 Output Variables, autoconf, The Autoconf Manual}), they are not
9467 computed by the Makefile like the aforementioned @samp{$(distdir)} and
9468 @samp{$(top_distdir)} variables..
9470 It is sometimes inconvenient to modify a third-party @file{Makefile}
9471 to introduce the above required targets.  For instance, one may want to
9472 keep the third-party sources untouched to ease upgrades to new
9473 versions.
9475 @cindex @file{GNUmakefile} including @file{Makefile}
9476 Here are two other ideas.  If GNU make is assumed, one possibility is
9477 to add to that subdirectory a @file{GNUmakefile} that defines the
9478 required targets and include the third-party @file{Makefile}.  For
9479 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
9480 directory; the easiest way to do this is to write a
9481 @file{GNUmakefile.in} instead, and have it processed with
9482 @code{AC_CONFIG_FILES} from the outer package.  For example if we
9483 assume @file{Makefile} defines all targets except the documentation
9484 targets, and that the @code{check} target is actually called
9485 @code{test}, we could write @file{GNUmakefile} (or
9486 @file{GNUmakefile.in}) like this:
9488 @example
9489 # First, include the real Makefile
9490 include Makefile
9491 # Then, define the other targets needed by Automake Makefiles.
9492 .PHONY: dvi pdf ps info html check
9493 dvi pdf ps info html:
9494 check: test
9495 @end example
9497 @cindex Proxy @file{Makefile} for third-party packages
9498 A similar idea that does not use @code{include} is to write a proxy
9499 @file{Makefile} that dispatches rules to the real @file{Makefile},
9500 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
9501 it's OK to rename the original @file{Makefile}) or with @samp{cd
9502 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
9503 subdirectory project one directory deeper).  The good news is that
9504 this proxy @file{Makefile} can be generated with Automake.  All we
9505 need are @option{-local} targets (@pxref{Extending}) that perform the
9506 dispatch.  Of course the other Automake features are available, so you
9507 could decide to let Automake perform distribution or installation.
9508 Here is a possible @file{Makefile.am}:
9510 @example
9511 all-local:
9512         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
9513 check-local:
9514         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
9515 clean-local:
9516         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
9518 # Assuming the package knows how to install itself
9519 install-data-local:
9520         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
9521 install-exec-local:
9522         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
9523 uninstall-local:
9524         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
9526 # Distribute files from here.
9527 EXTRA_DIST = subdir/Makefile subdir/program.c ...
9528 @end example
9530 Pushing this idea to the extreme, it is also possible to ignore the
9531 subproject build system and build everything from this proxy
9532 @file{Makefile.am}.  This might sounds very sensible if you need VPATH
9533 builds but the subproject does not support them.
9535 @node Distributing
9536 @chapter Distributing @file{Makefile.in}s
9538 Automake places no restrictions on the distribution of the resulting
9539 @file{Makefile.in}s.  We still encourage software authors to
9540 distribute their work under terms like those of the GPL, but doing so
9541 is not required to use Automake.
9543 Some of the files that can be automatically installed via the
9544 @option{--add-missing} switch do fall under the GPL@.  However, these also
9545 have a special exception allowing you to distribute them with your
9546 package, regardless of the licensing you choose.
9549 @node API versioning
9550 @chapter Automake API versioning
9552 New Automake releases usually include bug fixes and new features.
9553 Unfortunately they may also introduce new bugs and incompatibilities.
9554 This makes four reasons why a package may require a particular Automake
9555 version.
9557 Things get worse when maintaining a large tree of packages, each one
9558 requiring a different version of Automake.  In the past, this meant that
9559 any developer (and sometime users) had to install several versions of
9560 Automake in different places, and switch @samp{$PATH} appropriately for
9561 each package.
9563 Starting with version 1.6, Automake installs versioned binaries.  This
9564 means you can install several versions of Automake in the same
9565 @samp{$prefix}, and can select an arbitrary Automake version by running
9566 @command{automake-1.6} or @command{automake-1.7} without juggling with
9567 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
9568 will use @command{automake-1.6} explicitly in their rebuild rules.
9570 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
9571 not Automake's version.  If a bug fix release is made, for instance
9572 Automake 1.6.1, the API version will remain 1.6.  This means that a
9573 package that works with Automake 1.6 should also work with 1.6.1; after
9574 all, this is what people expect from bug fix releases.
9576 If your package relies on a feature or a bug fix introduced in
9577 a release, you can pass this version as an option to Automake to ensure
9578 older releases will not be used.  For instance, use this in your
9579 @file{configure.ac}:
9581 @example
9582   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
9583 @end example
9584 @noindent
9585 or, in a particular @file{Makefile.am}:
9587 @example
9588   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
9589 @end example
9590 @noindent
9591 Automake will print an error message if its version is
9592 older than the requested version.
9595 @heading What is in the API
9597 Automake's programming interface is not easy to define.  Basically it
9598 should include at least all @strong{documented} variables and targets
9599 that a @file{Makefile.am} author can use, any behavior associated with
9600 them (e.g., the places where @samp{-hook}'s are run), the command line
9601 interface of @command{automake} and @command{aclocal}, @dots{}
9603 @heading What is not in the API
9605 Every undocumented variable, target, or command line option, is not part
9606 of the API@.  You should avoid using them, as they could change from one
9607 version to the other (even in bug fix releases, if this helps to fix a
9608 bug).
9610 If it turns out you need to use such a undocumented feature, contact
9611 @email{automake@@gnu.org} and try to get it documented and exercised by
9612 the test-suite.
9614 @node Upgrading
9615 @chapter Upgrading a Package to a Newer Automake Version
9617 Automake maintains three kind of files in a package.
9619 @itemize
9620 @item @file{aclocal.m4}
9621 @item @file{Makefile.in}s
9622 @item auxiliary tools like @file{install-sh} or @file{py-compile}
9623 @end itemize
9625 @file{aclocal.m4} is generated by @command{aclocal} and contains some
9626 Automake-supplied M4 macros.  Auxiliary tools are installed by
9627 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
9628 built from @file{Makefile.am} by @command{automake}, and rely on the
9629 definitions of the M4 macros put in @file{aclocal.m4} as well as the
9630 behavior of the auxiliary tools installed.
9632 Because all these files are closely related, it is important to
9633 regenerate all of them when upgrading to a newer Automake release.
9634 The usual way to do that is
9636 @example
9637 aclocal # with any option needed (such a -I m4)
9638 autoconf
9639 automake --add-missing --force-missing
9640 @end example
9642 @noindent
9643 or more conveniently:
9645 @example
9646 autoreconf -vfi
9647 @end example
9649 The use of @option{--force-missing} ensures that auxiliary tools will be
9650 overridden by new versions (@pxref{Invoking Automake}).
9652 It is important to regenerate all these files each time Automake is
9653 upgraded, even between bug fixes releases.  For instance, it is not
9654 unusual for a bug fix to involve changes to both the rules generated
9655 in @file{Makefile.in} and the supporting M4 macros copied to
9656 @file{aclocal.m4}.
9658 Presently @command{automake} is able to diagnose situations where
9659 @file{aclocal.m4} has been generated with another version of
9660 @command{aclocal}.  However it never checks whether auxiliary scripts
9661 are up-to-date.  In other words, @command{automake} will tell you when
9662 @command{aclocal} needs to be rerun, but it will never diagnose a
9663 missing @option{--force-missing}.
9665 Before upgrading to a new major release, it is a good idea to read the
9666 file @file{NEWS}.  This file lists all changes between releases: new
9667 features, obsolete constructs, known incompatibilities, and
9668 workarounds.
9670 @node FAQ
9671 @chapter Frequently Asked Questions about Automake
9673 This chapter covers some questions that often come up on the mailing
9674 lists.
9676 @menu
9677 * CVS::                         CVS and generated files
9678 * maintainer-mode::             missing and AM_MAINTAINER_MODE
9679 * wildcards::                   Why doesn't Automake support wildcards?
9680 * limitations on file names::   Limitations on source and installed file names
9681 * distcleancheck::              Files left in build directory after distclean
9682 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
9683 * renamed objects::             Why are object files sometimes renamed?
9684 * Per-Object Flags::            How to simulate per-object flags?
9685 * Multiple Outputs::            Writing rules for tools with many output files
9686 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
9687 @end menu
9689 @node CVS
9690 @section CVS and generated files
9692 @subsection Background: distributed generated files
9693 @cindex generated files, distributed
9694 @cindex rebuild rules
9696 Packages made with Autoconf and Automake ship with some generated
9697 files like @file{configure} or @file{Makefile.in}.  These files were
9698 generated on the developer's host and are distributed so that
9699 end-users do not have to install the maintainer tools required to
9700 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
9701 or Info documentation, are usually distributed on similar grounds.
9703 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
9704 instance, @command{make} will run @command{autoconf} to rebuild
9705 @file{configure} whenever @file{configure.ac} is changed.  This makes
9706 development safer by ensuring a @file{configure} is never out-of-date
9707 with respect to @file{configure.ac}.
9709 As generated files shipped in packages are up-to-date, and because
9710 @command{tar} preserves times-tamps, these rebuild rules are not
9711 triggered when a user unpacks and builds a package.
9713 @subsection Background: CVS and timestamps
9714 @cindex timestamps and CVS
9715 @cindex CVS and timestamps
9717 Unless you use CVS keywords (in which case files must be updated at
9718 commit time), CVS preserves timestamp during @samp{cvs commit} and
9719 @samp{cvs import -d} operations.
9721 When you check out a file using @samp{cvs checkout} its timestamp is
9722 set to that of the revision that is being checked out.
9724 However, during @command{cvs update}, files will have the date of the
9725 update, not the original timestamp of this revision.  This is meant to
9726 make sure that @command{make} notices sources files have been updated.
9728 This timestamp shift is troublesome when both sources and generated
9729 files are kept under CVS@.  Because CVS processes files in lexical
9730 order, @file{configure.ac} will appear newer than @file{configure}
9731 after a @command{cvs update} that updates both files, even if
9732 @file{configure} was newer than @file{configure.ac} when it was
9733 checked in.  Calling @command{make} will then trigger a spurious rebuild
9734 of @file{configure}.
9736 @subsection Living with CVS in Autoconfiscated projects
9737 @cindex CVS and generated files
9738 @cindex generated files and CVS
9740 There are basically two clans amongst maintainers: those who keep all
9741 distributed files under CVS, including generated files, and those who
9742 keep generated files @emph{out} of CVS.
9744 @subsubheading All files in CVS
9746 @itemize @bullet
9747 @item
9748 The CVS repository contains all distributed files so you know exactly
9749 what is distributed, and you can checkout any prior version entirely.
9751 @item
9752 Maintainers can see how generated files evolve (for instance, you can
9753 see what happens to your @file{Makefile.in}s when you upgrade Automake
9754 and make sure they look OK).
9756 @item
9757 Users do not need the autotools to build a checkout of the project, it
9758 works just like a released tarball.
9760 @item
9761 If users use @command{cvs update} to update their copy, instead of
9762 @command{cvs checkout} to fetch a fresh one, timestamps will be
9763 inaccurate.  Some rebuild rules will be triggered and attempt to
9764 run developer tools such as @command{autoconf} or @command{automake}.
9766 Actually, calls to such tools are all wrapped into a call to the
9767 @command{missing} script discussed later (@pxref{maintainer-mode}).
9768 @command{missing} will take care of fixing the timestamps when these
9769 tools are not installed, so that the build can continue.
9771 @item
9772 In distributed development, developers are likely to have different
9773 version of the maintainer tools installed.  In this case rebuilds
9774 triggered by timestamp lossage will lead to spurious changes
9775 to generated files.  There are several solutions to this:
9777 @itemize
9778 @item
9779 All developers should use the same versions, so that the rebuilt files
9780 are identical to files in CVS@.  (This starts to be difficult when each
9781 project you work on uses different versions.)
9782 @item
9783 Or people use a script to fix the timestamp after a checkout (the GCC
9784 folks have such a script).
9785 @item
9786 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
9787 disable all these rebuild rules by default.  This is further discussed
9788 in @ref{maintainer-mode}.
9789 @end itemize
9791 @item
9792 Although we focused on spurious rebuilds, the converse can also
9793 happen.  CVS's timestamp handling can also let you think an
9794 out-of-date file is up-to-date.
9796 For instance, suppose a developer has modified @file{Makefile.am} and
9797 has rebuilt @file{Makefile.in}.  He then decide to do a last-minute
9798 change to @file{Makefile.am} right before checking in both files
9799 (without rebuilding @file{Makefile.in} to account for the change).
9801 This last change to @file{Makefile.am} make the copy of
9802 @file{Makefile.in} out-of-date.  Since CVS processes files
9803 alphabetically, when another developer @samp{cvs update} his or her
9804 tree, @file{Makefile.in} will happen to be newer than
9805 @file{Makefile.am}.  This other developer will not see
9806 @file{Makefile.in} is out-of-date.
9808 @end itemize
9810 @subsubheading Generated files out of CVS
9812 One way to get CVS and @command{make} working peacefully is to never
9813 store generated files in CVS, i.e., do not CVS-control files that
9814 are @file{Makefile} targets (also called @emph{derived} files).
9816 This way developers are not annoyed by changes to generated files.  It
9817 does not matter if they all have different versions (assuming they are
9818 compatible, of course).  And finally, timestamps are not lost, changes
9819 to sources files can't be missed as in the
9820 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
9822 The drawback is that the CVS repository is not an exact copy of what
9823 is distributed and that users now need to install various development
9824 tools (maybe even specific versions) before they can build a checkout.
9825 But, after all, CVS's job is versioning, not distribution.
9827 Allowing developers to use different versions of their tools can also
9828 hide bugs during distributed development.  Indeed, developers will be
9829 using (hence testing) their own generated files, instead of the
9830 generated files that will be released actually.  The developer who
9831 prepares the tarball might be using a version of the tool that
9832 produces bogus output (for instance a non-portable C file), something
9833 other developers could have noticed if they weren't using their own
9834 versions of this tool.
9836 @subsection Third-party files
9837 @cindex CVS and third-party files
9838 @cindex third-party files and CVS
9840 Another class of files not discussed here (because they do not cause
9841 timestamp issues) are files that are shipped with a package, but
9842 maintained elsewhere.  For instance, tools like @command{gettextize}
9843 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
9844 Libtool), will install or update files in your package.
9846 These files, whether they are kept under CVS or not, raise similar
9847 concerns about version mismatch between developers' tools.  The
9848 Gettext manual has a section about this, see @ref{CVS Issues, CVS
9849 Issues, Integrating with CVS, gettext, GNU gettext tools}.
9851 @node maintainer-mode
9852 @section @command{missing} and @code{AM_MAINTAINER_MODE}
9854 @subsection @command{missing}
9855 @cindex @command{missing}, purpose
9857 The @command{missing} script is a wrapper around several maintainer
9858 tools, designed to warn users if a maintainer tool is required but
9859 missing.  Typical maintainer tools are @command{autoconf},
9860 @command{automake}, @command{bison}, etc.  Because file generated by
9861 these tools are shipped with the other sources of a package, these
9862 tools shouldn't be required during a user build and they are not
9863 checked for in @file{configure}.
9865 However, if for some reason a rebuild rule is triggered and involves a
9866 missing tool, @command{missing} will notice it and warn the user.
9867 Besides the warning, when a tool is missing, @command{missing} will
9868 attempt to fix timestamps in a way that allows the build to continue.
9869 For instance, @command{missing} will touch @file{configure} if
9870 @command{autoconf} is not installed.  When all distributed files are
9871 kept under CVS, this feature of @command{missing} allows user
9872 @emph{with no maintainer tools} to build a package off CVS, bypassing
9873 any timestamp inconsistency implied by @samp{cvs update}.
9875 If the required tool is installed, @command{missing} will run it and
9876 won't attempt to continue after failures.  This is correct during
9877 development: developers love fixing failures.  However, users with
9878 wrong versions of maintainer tools may get an error when the rebuild
9879 rule is spuriously triggered, halting the build.  This failure to let
9880 the build continue is one of the arguments of the
9881 @code{AM_MAINTAINER_MODE} advocates.
9883 @subsection @code{AM_MAINTAINER_MODE}
9884 @cindex @code{AM_MAINTAINER_MODE}, purpose
9885 @acindex AM_MAINTAINER_MODE
9887 @code{AM_MAINTAINER_MODE} allows to choose whether the so called
9888 "rebuild rules" should be enabled or disabled.  With
9889 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
9890 otherwise they are disabled by default.  In the latter case, if
9891 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
9892 @samp{./configure && make}, then @command{make} will *never* attempt to
9893 rebuilt @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
9894 I.e., this disables build rules for files that are usually distributed
9895 and that users should normally not have to update.
9897 The user can override the default setting by passing either
9898 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
9899 to @command{configure}.
9901 People use @code{AM_MAINTAINER_MODE} either because they do want their
9902 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
9903 because they simply can't stand the rebuild rules and prefer running
9904 maintainer tools explicitly.
9906 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
9907 rules conditionally.  Some developers use this feature to disable
9908 rules that need exotic tools that users may not have available.
9910 Several years ago Fran@,{c}ois Pinard pointed out several arguments
9911 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
9912 insecurity.  By removing dependencies you get non-dependable builds:
9913 change to sources files can have no effect on generated files and this
9914 can be very confusing when unnoticed.  He adds that security shouldn't
9915 be reserved to maintainers (what @option{--enable-maintainer-mode}
9916 suggests), on the contrary.  If one user has to modify a
9917 @file{Makefile.am}, then either @file{Makefile.in} should be updated
9918 or a warning should be output (this is what Automake uses
9919 @command{missing} for) but the last thing you want is that nothing
9920 happens and the user doesn't notice it (this is what happens when
9921 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
9923 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
9924 swayed by Fran@,{c}ois's arguments, and got rid of
9925 @code{AM_MAINTAINER_MODE} in all of his packages.
9927 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
9928 it helps them working on projects where all files are kept under CVS,
9929 and because @command{missing} isn't enough if you have the wrong
9930 version of the tools.
9933 @node wildcards
9934 @section Why doesn't Automake support wildcards?
9935 @cindex wildcards
9937 Developers are lazy.  They would often like to use wildcards in
9938 @file{Makefile.am}s, so that they would not need to remember to
9939 update @file{Makefile.am}s every time they add, delete, or rename
9940 a file.
9942 There are several objections to this:
9943 @itemize
9944 @item
9945 When using CVS (or similar) developers need to remember they have to
9946 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
9947 @file{Makefile.am} accordingly quickly becomes a reflex.
9949 Conversely, if your application doesn't compile
9950 because you forgot to add a file in @file{Makefile.am}, it will help
9951 you remember to @samp{cvs add} it.
9953 @item
9954 Using wildcards makes it easy to distribute files by mistake.  For
9955 instance, some code a developer is experimenting with (a test case,
9956 say) that should not be part of the distribution.
9958 @item
9959 Using wildcards it's easy to omit some files by mistake.  For
9960 instance, one developer creates a new file, uses it in many places,
9961 but forgets to commit it.  Another developer then checks out the
9962 incomplete project and is able to run @samp{make dist} successfully,
9963 even though a file is missing. By listing files, @samp{make dist}
9964 @emph{will} complain.
9966 @item
9967 Finally, it's really hard to @emph{forget} to add a file to
9968 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
9969 not compiled or installed, so you can't even test them.
9970 @end itemize
9972 Still, these are philosophical objections, and as such you may disagree,
9973 or find enough value in wildcards to dismiss all of them.  Before you
9974 start writing a patch against Automake to teach it about wildcards,
9975 let's see the main technical issue: portability.
9977 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
9978 not portable to other @command{make} implementations.
9980 The only way Automake could support @command{$(wildcard ...)} is by
9981 expending @command{$(wildcard ...)} when @command{automake} is run.
9982 The resulting @file{Makefile.in}s would be portable since they would
9983 list all files and not use @samp{$(wildcard ...)}.  However that
9984 means developers would need to remember to run @command{automake} each
9985 time they add, delete, or rename files.
9987 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
9988 it's easier and faster to type @samp{automake; make} than to type
9989 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
9990 patch to add support for this syntax.  Some people use scripts to
9991 generate file lists in @file{Makefile.am} or in separate
9992 @file{Makefile} fragments.
9994 Even if you don't care about portability, and are tempted to use
9995 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
9996 should know there are many places where Automake need to know exactly
9997 which files should be processed.  As Automake doesn't know how to
9998 expand @samp{$(wildcard ...)}, you cannot use it in these places.
9999 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
10000 variables as far Automake is concerned.
10002 You can get warnings about @samp{$(wildcard ...}) constructs using the
10003 @option{-Wportability} flag.
10005 @node limitations on file names
10006 @section Limitations on file names
10007 @cindex file names, limitations on
10009 Automake attempts to support all kinds of file names, even those that
10010 contain unusual characters or are unusually long.  However, some
10011 limitations are imposed by the underlying operating system and tools.
10013 Most operating systems prohibit the use of the null byte in file
10014 names, and reserve @samp{/} as a directory separator.  Also, they
10015 require that file names are properly encoded for the user's locale.
10016 Automake is subject to these limits.
10018 Portable packages should limit themselves to @acronym{POSIX} file
10019 names.  These can contain @acronym{ASCII} letters and digits,
10020 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
10021 separated by @samp{/}.  File name components cannot begin with
10022 @samp{-}.
10024 Portable POSIX file names cannot contain components that exceed a
10025 14-byte limit, but nowadays it's normally safe to assume the
10026 more-generous @acronym{XOPEN} limit of 255 bytes.  @acronym{POSIX}
10027 limits file names to 255 bytes (@acronym{XOPEN} allows 1023 bytes),
10028 but you may want to limit a source tarball to file names to 99 bytes
10029 to avoid interoperability problems with old versions of @command{tar}.
10031 If you depart from these rules (e.g., by using non-@acronym{ASCII}
10032 characters in file names, or by using lengthy file names), your
10033 installers may have problems for reasons unrelated to Automake.
10034 However, if this does not concern you, you should know about the
10035 limitations imposed by Automake itself.  These limitations are
10036 undesirable, but some of them seem to be inherent to underlying tools
10037 like Autoconf, Make, M4, and the shell.  They fall into three
10038 categories: install directories, build directories, and file names.
10040 The following characters:
10042 @example
10043 @r{newline} " # $ ' `
10044 @end example
10046 should not appear in the names of install directories.  For example,
10047 the operand of @command{configure}'s @option{--prefix} option should
10048 not contain these characters.
10050 Build directories suffer the same limitations as install directories,
10051 and in addition should not contain the following characters:
10053 @example
10054 & @@ \
10055 @end example
10057 For example, the full name of the directory containing the source
10058 files should not contain these characters.
10060 Source and installation file names like @file{main.c} are limited even
10061 further: they should conform to the @acronym{POSIX}/@acronym{XOPEN}
10062 rules described above.  In addition, if you plan to port to
10063 non-@acronym{POSIX} environments, you should avoid file names that
10064 differ only in case (e.g., @file{makefile} and @file{Makefile}).
10065 Nowadays it is no longer worth worrying about the 8.3 limits of
10066 @acronym{DOS} file systems.
10068 @node distcleancheck
10069 @section Files left in build directory after distclean
10070 @cindex @code{distclean}, diagnostic
10071 @cindex @samp{make distclean}, diagnostic
10072 @cindex dependencies and distributed files
10073 @trindex distclean
10074 @trindex distcleancheck
10076 This is a diagnostic you might encounter while running @samp{make
10077 distcheck}.
10079 As explained in @ref{Dist}, @samp{make distcheck} attempts to build
10080 and check your package for errors like this one.
10082 @samp{make distcheck} will perform a @code{VPATH} build of your
10083 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
10084 Files left in the build directory after @samp{make distclean} has run
10085 are listed after this error.
10087 This diagnostic really covers two kinds of errors:
10089 @itemize @bullet
10090 @item
10091 files that are forgotten by distclean;
10092 @item
10093 distributed files that are erroneously rebuilt.
10094 @end itemize
10096 The former left-over files are not distributed, so the fix is to mark
10097 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
10098 more explanations.
10100 The latter bug is not always easy to understand and fix, so let's
10101 proceed with an example.  Suppose our package contains a program for
10102 which we want to build a man page using @command{help2man}.  GNU
10103 @command{help2man} produces simple manual pages from the @option{--help}
10104 and @option{--version} output of other commands (@pxref{Top, , Overview,
10105 help2man, The Help2man Manual}).  Because we don't to force want our
10106 users to install @command{help2man}, we decide to distribute the
10107 generated man page using the following setup.
10109 @example
10110 # This Makefile.am is bogus.
10111 bin_PROGRAMS = foo
10112 foo_SOURCES = foo.c
10113 dist_man_MANS = foo.1
10115 foo.1: foo$(EXEEXT)
10116         help2man --output=foo.1 ./foo$(EXEEXT)
10117 @end example
10119 This will effectively distribute the man page.  However,
10120 @samp{make distcheck} will fail with:
10122 @example
10123 ERROR: files left in build directory after distclean:
10124 ./foo.1
10125 @end example
10127 Why was @file{foo.1} rebuilt?  Because although distributed,
10128 @file{foo.1} depends on a non-distributed built file:
10129 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
10130 will always appear to be newer than the distributed @file{foo.1}.
10132 @samp{make distcheck} caught an inconsistency in our package.  Our
10133 intent was to distribute @file{foo.1} so users do not need installing
10134 @command{help2man}, however since this our rule causes this file to be
10135 always rebuilt, users @emph{do} need @command{help2man}.  Either we
10136 should ensure that @file{foo.1} is not rebuilt by users, or there is
10137 no point in distributing @file{foo.1}.
10139 More generally, the rule is that distributed files should never depend
10140 on non-distributed built files.  If you distribute something
10141 generated, distribute its sources.
10143 One way to fix the above example, while still distributing
10144 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
10145 assuming @command{foo --version} and @command{foo --help} do not
10146 change unless @file{foo.c} or @file{configure.ac} change, we could
10147 write the following @file{Makefile.am}:
10149 @example
10150 bin_PROGRAMS = foo
10151 foo_SOURCES = foo.c
10152 dist_man_MANS = foo.1
10154 foo.1: foo.c $(top_srcdir)/configure.ac
10155         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
10156         help2man --output=foo.1 ./foo$(EXEEXT)
10157 @end example
10159 This way, @file{foo.1} will not get rebuilt every time
10160 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
10161 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
10162 way to ensure this would be to use separate directories for binaries
10163 and man pages, and set @code{SUBDIRS} so that binaries are built
10164 before man pages.
10166 We could also decide not to distribute @file{foo.1}.  In
10167 this case it's fine to have @file{foo.1} dependent upon
10168 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
10169 However it would be impossible to build the package in a
10170 cross-compilation, because building @file{foo.1} involves
10171 an @emph{execution} of @file{foo$(EXEEXT)}.
10173 Another context where such errors are common is when distributed files
10174 are built by tools that are built by the package.  The pattern is
10175 similar:
10177 @example
10178 distributed-file: built-tools distributed-sources
10179         build-command
10180 @end example
10182 @noindent
10183 should be changed to
10185 @example
10186 distributed-file: distributed-sources
10187         $(MAKE) $(AM_MAKEFLAGS) built-tools
10188         build-command
10189 @end example
10191 @noindent
10192 or you could choose not to distribute @file{distributed-file}, if
10193 cross-compilation does not matter.
10195 The points made through these examples are worth a summary:
10197 @cartouche
10198 @itemize
10199 @item
10200 Distributed files should never depend upon non-distributed built
10201 files.
10202 @item
10203 Distributed files should be distributed with all their dependencies.
10204 @item
10205 If a file is @emph{intended} to be rebuilt by users, then there is no point
10206 in distributing it.
10207 @end itemize
10208 @end cartouche
10210 @vrindex distcleancheck_listfiles
10211 For desperate cases, it's always possible to disable this check by
10212 setting @code{distcleancheck_listfiles} as documented in @ref{Dist}.
10213 Make sure you do understand the reason why @samp{make distcheck}
10214 complains before you do this.  @code{distcleancheck_listfiles} is a
10215 way to @emph{hide} errors, not to fix them.  You can always do better.
10217 @node Flag Variables Ordering
10218 @section Flag Variables Ordering
10219 @cindex Ordering flag variables
10220 @cindex Flag variables, ordering
10222 @display
10223 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
10224 @code{mumble_CFLAGS}?
10225 @end display
10227 @display
10228 Why does @command{automake} output @code{CPPFLAGS} after
10229 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
10230 @end display
10232 @display
10233 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
10234 one @file{Makefile.am} I would like to append a new flag, however if I
10235 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
10236 flags, not appended.
10237 @end display
10239 @subsection Compile Flag Variables
10240 @cindex Flag Variables, Ordering
10241 @cindex Compile Flag Variables
10242 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
10243 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
10244 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
10245 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
10246 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
10247 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
10248 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
10249 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
10250 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
10251 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
10252 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
10253 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
10254 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
10255 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
10256 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
10257 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
10258 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
10259 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
10260 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
10261 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
10262 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
10263 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
10264 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
10265 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
10266 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
10267 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
10268 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
10269 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
10271 This section attempts to answer all the above questions.  We will
10272 mostly discuss @code{CPPFLAGS} in our examples, but actually the
10273 answer holds for all the compile flags used in Automake:
10274 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
10275 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
10276 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
10277 @code{UPCFLAGS}, and @code{YFLAGS}.
10279 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
10280 three variables that can be used to pass flags to the C preprocessor
10281 (actually these variables are also used for other languages like C++
10282 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
10283 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
10284 and @code{mumble_CPPFLAGS} is the variable specific to the
10285 @code{mumble} target (we call this a per-target variable,
10286 @pxref{Program and Library Variables}).
10288 Automake always uses two of these variables when compiling C sources
10289 files.  When compiling an object file for the @code{mumble} target,
10290 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
10291 @code{AM_CPPFLAGS} otherwise.  The second variable is always
10292 @code{CPPFLAGS}.
10294 In the following example,
10296 @example
10297 bin_PROGRAMS = foo bar
10298 foo_SOURCES = xyz.c
10299 bar_SOURCES = main.c
10300 foo_CPPFLAGS = -DFOO
10301 AM_CPPFLAGS = -DBAZ
10302 @end example
10304 @noindent
10305 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
10306 (because @file{xyz.o} is part of the @code{foo} target), while
10307 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
10308 (because there is no per-target variable for target @code{bar}).
10310 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
10311 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
10312 is a user variable, i.e., a variable that users are entitled to modify
10313 in order to compile the package.  This variable, like many others,
10314 is documented at the end of the output of @samp{configure --help}.
10316 For instance, someone who needs to add @file{/home/my/usr/include} to
10317 the C compiler's search path would configure a package with
10319 @example
10320 ./configure CPPFLAGS='-I /home/my/usr/include'
10321 @end example
10323 @noindent
10324 and this flag would be propagated to the compile rules of all
10325 @file{Makefile}s.
10327 It is also not uncommon to override a user variable at
10328 @command{make}-time.  Many installers do this with @code{prefix}, but
10329 this can be useful with compiler flags too.  For instance, if, while
10330 debugging a C++ project, you need to disable optimization in one
10331 specific object file, you can run something like
10333 @example
10334 rm file.o
10335 make CXXFLAGS=-O0 file.o
10336 make
10337 @end example
10339 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
10340 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
10341 should always have the last say.  It probably makes more sense if you
10342 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
10343 should supersede any other switch from @code{AM_CXXFLAGS} or
10344 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
10345 of @code{CXXFLAGS}).
10347 You should never redefine a user variable such as @code{CPPFLAGS} in
10348 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
10349 mistakes.  Even something like
10351 @example
10352 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
10353 @end example
10355 @noindent
10356 is erroneous.  Although this preserves @file{configure}'s value of
10357 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
10358 user attempts to override @code{CPPFLAGS} from the @command{make}
10359 command line.
10361 @example
10362 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
10363 @end example
10365 @noindent
10366 is all what is needed here if no per-target flags are used.
10368 You should not add options to these user variables within
10369 @file{configure} either, for the same reason.  Occasionally you need
10370 to modify these variables to perform a test, but you should reset
10371 their values afterwards.  In contrast, it is OK to modify the
10372 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
10373 them, but it is rather rare that you need to do this, unless you
10374 really want to change the default definitions of the @samp{AM_}
10375 variables in all @file{Makefile}s.
10377 What we recommend is that you define extra flags in separate
10378 variables.  For instance, you may write an Autoconf macro that computes
10379 a set of warning options for the C compiler, and @code{AC_SUBST} them
10380 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
10381 determines which compiler and which linker flags should be used to
10382 link with library @file{libfoo}, and @code{AC_SUBST} these in
10383 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
10384 @file{Makefile.am} could use these variables as follows:
10386 @example
10387 AM_CFLAGS = $(WARNINGCFLAGS)
10388 bin_PROGRAMS = prog1 prog2
10389 prog1_SOURCES = @dots{}
10390 prog2_SOURCES = @dots{}
10391 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
10392 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
10393 @end example
10395 In this example both programs will be compiled with the flags
10396 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
10397 additionally be compiled with the flags required to link with
10398 @file{libfoo}.
10400 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
10401 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
10402 every target in a @file{Makefile.in}.
10404 Using variables like this gives you full control over the ordering of
10405 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
10406 you want to negate for a particular target, you can use something like
10407 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
10408 been forcefully appended to @code{CFLAGS}, there would be no way to
10409 disable one flag.  Yet another reason to leave user variables to
10410 users.
10412 Finally, we have avoided naming the variable of the example
10413 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
10414 Automake to think that this is actually a per-target variable (like
10415 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
10417 @subsection Other Variables
10419 There are other variables in Automake that follow similar principles
10420 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
10421 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
10422 DejaGnu tests (@pxref{Tests}) use @code{RUNTESTDEFAULTFLAGS} and
10423 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
10424 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
10425 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
10426 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
10427 of these rules supports per-target flags (yet).
10429 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
10430 obeys this naming scheme.  The slight difference is that
10431 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
10432 @command{make} itself.
10434 However you should not think that all variables ending with
10435 @code{FLAGS} follow this convention.  For instance,
10436 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Dist}),
10437 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
10438 are two variables that are only useful to the maintainer and have no
10439 user counterpart.
10441 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
10442 has neither @code{AM_} nor per-target cousin.
10444 Finally you should not think either that the existence of a per-target
10445 variable implies that of an @code{AM_} variable or that of a user
10446 variable.  For instance, the @code{mumble_LDADD} per-target variable
10447 overrides the global @code{LDADD} variable (which is not a user
10448 variable), and @code{mumble_LIBADD} exists only as a per-target
10449 variable.  @xref{Program and Library Variables}.
10452 @node renamed objects
10453 @section Why are object files sometimes renamed?
10455 This happens when per-target compilation flags are used.  Object
10456 files need to be renamed just in case they would clash with object
10457 files compiled from the same sources, but with different flags.
10458 Consider the following example.
10460 @example
10461 bin_PROGRAMS = true false
10462 true_SOURCES = generic.c
10463 true_CPPFLAGS = -DEXIT_CODE=0
10464 false_SOURCES = generic.c
10465 false_CPPFLAGS = -DEXIT_CODE=1
10466 @end example
10467 @noindent
10468 Obviously the two programs are built from the same source, but it
10469 would be bad if they shared the same object, because @file{generic.o}
10470 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
10471 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
10472 build two different objects: @file{true-generic.o} and
10473 @file{false-generic.o}.
10475 @command{automake} doesn't actually look whether source files are
10476 shared to decide if it must rename objects.  It will just rename all
10477 objects of a target as soon as it sees per-target compilation flags
10478 are used.
10480 It's OK to share object files when per-target compilation flags are not
10481 used.  For instance, @file{true} and @file{false} will both use
10482 @file{version.o} in the following example.
10484 @example
10485 AM_CPPFLAGS = -DVERSION=1.0
10486 bin_PROGRAMS = true false
10487 true_SOURCES = true.c version.c
10488 false_SOURCES = false.c version.c
10489 @end example
10491 Note that the renaming of objects is also affected by the
10492 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
10495 @node Per-Object Flags
10496 @section Per-Object Flags Emulation
10497 @cindex Per-object flags, emulated
10499 @display
10500 One of my source files needs to be compiled with different flags.  How
10501 do I do?
10502 @end display
10504 Automake supports per-program and per-library compilation flags (see
10505 @ref{Program and Library Variables} and @ref{Flag Variables
10506 Ordering}).  With this you can define compilation flags that apply to
10507 all files compiled for a target.  For instance, in
10509 @example
10510 bin_PROGRAMS = foo
10511 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
10512 foo_CFLAGS = -some -flags
10513 @end example
10515 @noindent
10516 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
10517 compiled with @samp{-some -flags}.  (If you wonder about the names of
10518 these object files, see @ref{renamed objects}.)  Note that
10519 @code{foo_CFLAGS} gives the flags to use when compiling all the C
10520 sources of the @emph{program} @code{foo}, it has nothing to do with
10521 @file{foo.c} or @file{foo-foo.o} specifically.
10523 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
10524 specific flags, that none of the other files requires?  Obviously
10525 per-program flags are not directly applicable here.  Something like
10526 per-object flags are expected, i.e., flags that would be used only
10527 when creating @file{foo-foo.o}.  Automake does not support that,
10528 however this is easy to simulate using a library that contains only
10529 that object, and compiling this library with per-library flags.
10531 @example
10532 bin_PROGRAMS = foo
10533 foo_SOURCES = bar.c bar.h main.c
10534 foo_CFLAGS = -some -flags
10535 foo_LDADD = libfoo.a
10536 noinst_LIBRARIES = libfoo.a
10537 libfoo_a_SOURCES = foo.c foo.h
10538 libfoo_a_CFLAGS = -some -other -flags
10539 @end example
10541 Here @file{foo-bar.o} and @file{foo-main.o} will all be
10542 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
10543 be compiled using @samp{-some -other -flags}.  Eventually, all
10544 three objects will be linked to form @file{foo}.
10546 This trick can also be achieved using Libtool convenience libraries,
10547 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
10548 Convenience Libraries}).
10550 Another tempting idea to implement per-object flags is to override the
10551 compile rules @command{automake} would output for these files.
10552 Automake will not define a rule for a target you have defined, so you
10553 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
10554 We recommend against this, because this is error prone.  For instance,
10555 if you add such a rule to the first example, it will break the day you
10556 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
10557 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{renamed
10558 objects}).  Also in order to support dependency tracking, the two
10559 @file{.o}/@file{.obj} extensions, and all the other flags variables
10560 involved in a compilation, you will end up modifying a copy of the
10561 rule previously output by @command{automake} for this file.  If a new
10562 release of Automake generates a different rule, your copy will need to
10563 be updated by hand.
10565 @node Multiple Outputs
10566 @section Handling Tools that Produce Many Outputs
10567 @cindex multiple outputs, rules with
10568 @cindex many outputs, rules with
10569 @cindex rules with multiple outputs
10571 This section describes a @command{make} idiom that can be used when a
10572 tool produces multiple output files.  It is not specific to Automake
10573 and can be used in ordinary @file{Makefile}s.
10575 Suppose we have a program called @command{foo} that will read one file
10576 called @file{data.foo} and produce two files named @file{data.c} and
10577 @file{data.h}.  We want to write a @file{Makefile} rule that captures
10578 this one-to-two dependency.
10580 The naive rule is incorrect:
10582 @example
10583 # This is incorrect.
10584 data.c data.h: data.foo
10585         foo data.foo
10586 @end example
10588 @noindent
10589 What the above rule really says is that @file{data.c} and
10590 @file{data.h} each depend on @file{data.foo}, and can each be built by
10591 running @samp{foo data.foo}.  In other words it is equivalent to:
10593 @example
10594 # We do not want this.
10595 data.c: data.foo
10596         foo data.foo
10597 data.h: data.foo
10598         foo data.foo
10599 @end example
10601 @noindent
10602 which means that @command{foo} can be run twice.  Usually it will not
10603 be run twice, because @command{make} implementations are smart enough
10604 to check for the existence of the second file after the first one has
10605 been built; they will therefore detect that it already exists.
10606 However there are a few situations where it can run twice anyway:
10608 @itemize
10609 @item
10610 The most worrying case is when running a parallel @command{make}.  If
10611 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
10612 data.foo} commands will run concurrently.  This is harmful.
10613 @item
10614 Another case is when the dependency (here @file{data.foo}) is
10615 (or depends upon) a phony target.
10616 @end itemize
10618 A solution that works with parallel @command{make} but not with
10619 phony dependencies is the following:
10621 @example
10622 data.c data.h: data.foo
10623         foo data.foo
10624 data.h: data.c
10625 @end example
10627 @noindent
10628 The above rules are equivalent to
10630 @example
10631 data.c: data.foo
10632         foo data.foo
10633 data.h: data.foo data.c
10634         foo data.foo
10635 @end example
10636 @noindent
10637 therefore a parallel @command{make} will have to serialize the builds
10638 of @file{data.c} and @file{data.h}, and will detect that the second is
10639 no longer needed once the first is over.
10641 Using this pattern is probably enough for most cases.  However it does
10642 not scale easily to more output files (in this scheme all output files
10643 must be totally ordered by the dependency relation), so we will
10644 explore a more complicated solution.
10646 Another idea is to write the following:
10648 @example
10649 # There is still a problem with this one.
10650 data.c: data.foo
10651         foo data.foo
10652 data.h: data.c
10653 @end example
10655 @noindent
10656 The idea is that @samp{foo data.foo} is run only when @file{data.c}
10657 needs to be updated, but we further state that @file{data.h} depends
10658 upon @file{data.c}.  That way, if @file{data.h} is required and
10659 @file{data.foo} is out of date, the dependency on @file{data.c} will
10660 trigger the build.
10662 This is almost perfect, but suppose we have built @file{data.h} and
10663 @file{data.c}, and then we erase @file{data.h}.  Then, running
10664 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
10665 just state that @file{data.c} must be up-to-date with respect to
10666 @file{data.foo}, and this is already the case.
10668 What we need is a rule that forces a rebuild when @file{data.h} is
10669 missing.  Here it is:
10671 @example
10672 data.c: data.foo
10673         foo data.foo
10674 data.h: data.c
10675 ## Recover from the removal of $@@
10676         @@if test -f $@@; then :; else \
10677           rm -f data.c; \
10678           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10679         fi
10680 @end example
10682 The above scheme can be extended to handle more outputs and more
10683 inputs.  One of the outputs is selected to serve as a witness to the
10684 successful completion of the command, it depends upon all inputs, and
10685 all other outputs depend upon it.  For instance, if @command{foo}
10686 should additionally read @file{data.bar} and also produce
10687 @file{data.w} and @file{data.x}, we would write:
10689 @example
10690 data.c: data.foo data.bar
10691         foo data.foo data.bar
10692 data.h data.w data.x: data.c
10693 ## Recover from the removal of $@@
10694         @@if test -f $@@; then :; else \
10695           rm -f data.c; \
10696           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10697         fi
10698 @end example
10700 However there are now two minor problems in this setup.  One is related
10701 to the timestamp ordering of @file{data.h}, @file{data.w},
10702 @file{data.x}, and @file{data.c}.  The other one is a race condition
10703 if a parallel @command{make} attempts to run multiple instances of the
10704 recover block at once.
10706 Let us deal with the first problem.  @command{foo} outputs four files,
10707 but we do not know in which order these files are created.  Suppose
10708 that @file{data.h} is created before @file{data.c}.  Then we have a
10709 weird situation.  The next time @command{make} is run, @file{data.h}
10710 will appear older than @file{data.c}, the second rule will be
10711 triggered, a shell will be started to execute the @samp{if@dots{}fi}
10712 command, but actually it will just execute the @code{then} branch,
10713 that is: nothing.  In other words, because the witness we selected is
10714 not the first file created by @command{foo}, @command{make} will start
10715 a shell to do nothing each time it is run.
10717 A simple riposte is to fix the timestamps when this happens.
10719 @example
10720 data.c: data.foo data.bar
10721         foo data.foo data.bar
10722 data.h data.w data.x: data.c
10723         @@if test -f $@@; then \
10724           touch $@@; \
10725         else \
10726 ## Recover from the removal of $@@
10727           rm -f data.c; \
10728           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10729         fi
10730 @end example
10732 Another solution is to use a different and dedicated file as witness,
10733 rather than using any of @command{foo}'s outputs.
10735 @example
10736 data.stamp: data.foo data.bar
10737         @@rm -f data.tmp
10738         @@touch data.tmp
10739         foo data.foo data.bar
10740         @@mv -f data.tmp $@@
10741 data.c data.h data.w data.x: data.stamp
10742 ## Recover from the removal of $@@
10743         @@if test -f $@@; then :; else \
10744           rm -f data.stamp; \
10745           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10746         fi
10747 @end example
10749 @file{data.tmp} is created before @command{foo} is run, so it has a
10750 timestamp older than output files output by @command{foo}.  It is then
10751 renamed to @file{data.stamp} after @command{foo} has run, because we
10752 do not want to update @file{data.stamp} if @command{foo} fails.
10754 This solution still suffers from the second problem: the race
10755 condition in the recover rule.  If, after a successful build, a user
10756 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
10757 @command{make} may start both recover rules in parallel.  If the two
10758 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
10759 data.stamp} concurrently the build is likely to fail (for instance, the
10760 two rules will create @file{data.tmp}, but only one can rename it).
10762 Admittedly, such a weird situation does not arise during ordinary
10763 builds.  It occurs only when the build tree is mutilated.  Here
10764 @file{data.c} and @file{data.h} have been explicitly removed without
10765 also removing @file{data.stamp} and the other output files.
10766 @code{make clean; make} will always recover from these situations even
10767 with parallel makes, so you may decide that the recover rule is solely
10768 to help non-parallel make users and leave things as-is.  Fixing this
10769 requires some locking mechanism to ensure only one instance of the
10770 recover rule rebuilds @file{data.stamp}.  One could imagine something
10771 along the following lines.
10773 @example
10774 data.c data.h data.w data.x: data.stamp
10775 ## Recover from the removal of $@@
10776         @@if test -f $@@; then :; else \
10777           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
10778 ## mkdir is a portable test-and-set
10779           if mkdir data.lock 2>/dev/null; then \
10780 ## This code is being executed by the first process.
10781             rm -f data.stamp; \
10782             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10783             result=$$?; rm -rf data.lock; exit $$result; \
10784           else \
10785 ## This code is being executed by the follower processes.
10786 ## Wait until the first process is done.
10787             while test -d data.lock; do sleep 1; done; \
10788 ## Succeed if and only if the first process succeeded.
10789             test -f data.stamp; \
10790           fi; \
10791         fi
10792 @end example
10794 Using a dedicated witness, like @file{data.stamp}, is very handy when
10795 the list of output files is not known beforehand.  As an illustration,
10796 consider the following rules to compile many @file{*.el} files into
10797 @file{*.elc} files in a single command.  It does not matter how
10798 @code{ELFILES} is defined (as long as it is not empty: empty targets
10799 are not accepted by POSIX).
10801 @example
10802 ELFILES = one.el two.el three.el @dots{}
10803 ELCFILES = $(ELFILES:=c)
10805 elc-stamp: $(ELFILES)
10806         @@rm -f elc-temp
10807         @@touch elc-temp
10808         $(elisp_comp) $(ELFILES)
10809         @@mv -f elc-temp $@@
10811 $(ELCFILES): elc-stamp
10812 ## Recover from the removal of $@@
10813         @@if test -f $@@; then :; else \
10814           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
10815           if mkdir elc-lock 2>/dev/null; then \
10816 ## This code is being executed by the first process.
10817             rm -f elc-stamp; \
10818             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
10819             rmdir elc-lock; \
10820           else \
10821 ## This code is being executed by the follower processes.
10822 ## Wait until the first process is done.
10823             while test -d elc-lock; do sleep 1; done; \
10824 ## Succeed if and only if the first process succeeded.
10825             test -f elc-stamp; exit $$?; \
10826           fi; \
10827         fi
10828 @end example
10830 For completeness it should be noted that GNU @command{make} is able to
10831 express rules with multiple output files using pattern rules
10832 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
10833 Manual}).  We do not discuss pattern rules here because they are not
10834 portable, but they can be convenient in packages that assume GNU
10835 @command{make}.
10838 @node Hard-Coded Install Paths
10839 @section Installing to Hard-Coded Locations
10841 @display
10842 My package needs to install some configuration file.  I tried to use
10843 the following rule, but @samp{make distcheck} fails.  Why?
10845 @example
10846 # Do not do this.
10847 install-data-local:
10848         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
10849 @end example
10850 @end display
10852 @display
10853 My package needs to populate the installation directory of another
10854 package at install-time.  I can easily compute that installation
10855 directory in @file{configure}, but if I install files therein,
10856 @samp{make distcheck} fails.  How else should I do?
10857 @end display
10859 These two setups share their symptoms: @samp{make distcheck} fails
10860 because they are installing files to hard-coded paths.  In the later
10861 case the path is not really hard-coded in the package, but we can
10862 consider it to be hard-coded in the system (or in whichever tool that
10863 supplies the path).  As long as the path does not use any of the
10864 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
10865 @samp{$(datadir)}, etc.), the effect will be the same:
10866 user-installations are impossible.
10868 When a (non-root) user wants to install a package, he usually has no
10869 right to install anything in @file{/usr} or @file{/usr/local}.  So he
10870 does something like @samp{./configure --prefix ~/usr} to install
10871 package in his own @file{~/usr} tree.
10873 If a package attempts to install something to some hard-coded path
10874 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
10875 then the installation will fail.  @samp{make distcheck} performs such
10876 a @option{--prefix} installation, hence it will fail too.
10878 Now, there are some easy solutions.
10880 The above @code{install-data-local} example for installing
10881 @file{/etc/afile} would be better replaced by
10883 @example
10884 sysconf_DATA = afile
10885 @end example
10887 @noindent
10888 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
10889 this is what the GNU Standards require.  When such a package is
10890 installed on a FHS compliant system, the installer will have to set
10891 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
10892 should not be concerned by such site policies: use the appropriate
10893 standard directory variable to install your files so that installer
10894 can easily redefine these variables to match their site conventions.
10896 Installing files that should be used by another package is slightly
10897 more involved.  Let's take an example and assume you want to install
10898 shared library that is a Python extension module.  If you ask Python
10899 where to install the library, it will answer something like this:
10901 @example
10902 % @kbd{python -c 'from distutils import sysconfig;
10903              print sysconfig.get_python_lib(1,0)'}
10904 /usr/lib/python2.3/site-packages
10905 @end example
10907 If you indeed use this absolute path to install your shared library,
10908 non-root users will not be able to install the package, hence
10909 distcheck fails.
10911 Let's do better.  The @samp{sysconfig.get_python_lib()} function
10912 actually accepts a third argument that will replace Python's
10913 installation prefix.
10915 @example
10916 % @kbd{python -c 'from distutils import sysconfig;
10917              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
10918 $@{exec_prefix@}/lib/python2.3/site-packages
10919 @end example
10921 You can also use this new path.  If you do
10922 @itemize @bullet
10923 @item
10924 root users can install your package with the same @option{--prefix}
10925 as Python (you get the behavior of the previous attempt)
10927 @item
10928 non-root users can install your package too, they will have the
10929 extension module in a place that is not searched by Python but they
10930 can work around this using environment variables (and if you installed
10931 scripts that use this shared library, it's easy to tell Python were to
10932 look in the beginning of your script, so the script works in both
10933 cases).
10934 @end itemize
10936 The @code{AM_PATH_PYTHON} macro uses similar commands to define
10937 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
10939 Of course not all tools are as advanced as Python regarding that
10940 substitution of @var{prefix}.  So another strategy is to figure the
10941 part of the of the installation directory that must be preserved.  For
10942 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
10943 computes @samp{$(lispdir)}:
10945 @example
10946 $EMACS -batch -q -eval '(while load-path
10947   (princ (concat (car load-path) "\n"))
10948   (setq load-path (cdr load-path)))' >conftest.out
10949 lispdir=`sed -n
10950   -e 's,/$,,'
10951   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
10952         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
10953       @}'
10954   -e '/.*\/share\/x*emacs\/site-lisp$/@{
10955         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
10956       @}'
10957   conftest.out`
10958 @end example
10960 I.e., it just picks the first directory that looks like
10961 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
10962 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
10963 @samp{$@{datadir@}} appropriately.
10965 The emacs case looks complicated because it processes a list and
10966 expect two possible layouts, otherwise it's easy, and the benefit for
10967 non-root users are really worth the extra @command{sed} invocation.
10970 @node History
10971 @chapter History of Automake
10973 This chapter presents various aspects of the history of Automake.  The
10974 exhausted reader can safely skip it; this will be more of interest to
10975 nostalgic people, or to those curious to learn about the evolution of
10976 Automake.
10978 @menu
10979 * Timeline::                    The Automake story.
10980 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
10981 * Releases::                    Statistics about Automake Releases
10982 @end menu
10984 @node Timeline
10985 @section Timeline
10987 @table @asis
10988 @item 1994-09-19 First CVS commit.
10990 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
10991 working on Automake (or AutoMake, as it was spelt then) this Monday.
10993 The first version of the @command{automake} script looks as follows.
10995 @example
10996 #!/bin/sh
10998 status=0
11000 for makefile
11002   if test ! -f $@{makefile@}.am; then
11003     echo "automake: $@{makefile@}.am: No such honkin' file"
11004     status=1
11005     continue
11006   fi
11008   exec 4> $@{makefile@}.in
11010 done
11011 @end example
11013 From this you can already see that Automake will be about reading
11014 @file{*.am} file and producing @file{*.in} files.  You cannot see
11015 anything else, but if you also know that David is the one who created
11016 Autoconf two years before you can guess the rest.
11018 Several commits follow, and by the end of the day Automake is
11019 reported to work for GNU fileutils and GNU m4.
11021 The modus operandi is the one that is still used today: variables
11022 assignments in @file{Makefile.am} files trigger injections of
11023 precanned @file{Makefile} fragments into the generated
11024 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
11025 by the 4.4BSD @command{make} and include files, however Automake aims
11026 to be portable and to conform to the GNU standards for @file{Makefile}
11027 variables and targets.
11029 At this point, the most recent release of Autoconf is version 1.11,
11030 and David is preparing to release Autoconf 2.0 in late October.  As a
11031 matter of fact, he will barely touch Automake after September.
11033 @item 1994-11-05 David MacKenzie's last commit.
11035 At this point Automake is a 200 line portable shell script, plus 332
11036 lines of @file{Makefile} fragments.  In the @file{README}, David
11037 states his ambivalence between ``portable shell'' and ``more
11038 appropriate language'':
11040 @quotation
11041 I wrote it keeping in mind the possibility of it becoming an Autoconf
11042 macro, so it would run at configure-time.  That would slow
11043 configuration down a bit, but allow users to modify the Makefile.am
11044 without needing to fetch the AutoMake package.  And, the Makefile.in
11045 files wouldn't need to be distributed.  But all of AutoMake would.  So
11046 I might reimplement AutoMake in Perl, m4, or some other more
11047 appropriate language.
11048 @end quotation
11050 Automake is described as ``an experimental Makefile generator''.
11051 There is no documentation.  Adventurous users are referred to the
11052 examples and patches needed to use Automake with GNU m4 1.3, fileutils
11053 3.9, time 1.6, and development versions of find and indent.
11055 These examples seem to have been lost.  However at the time of writing
11056 (10 years later in September, 2004) the FSF still distributes a
11057 package that uses this version of Automake: check out GNU termutils
11058 2.0.
11060 @item 1995-11-12 Tom Tromey's first commit.
11062 After one year of inactivity, Tom Tromey takes over the package.
11063 Tom was working on GNU cpio back then, and doing this just for fun,
11064 having trouble finding a project to contribute to.  So while hacking
11065 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
11066 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
11067 grabbed it and tried it out.
11069 Tom didn't talk to djm about it until later, just to make sure he
11070 didn't mind if he made a release.  He did a bunch of early releases to
11071 the Gnits folks.
11073 Gnits was (and still is) totally informal, just a few GNU friends who
11074 Fran@,cois Pinard knew, who were all interested in making a common
11075 infrastructure for GNU projects, and shared a similar outlook on how
11076 to do it.  So they were able to make some progress.  It came along
11077 with Autoconf and extensions thereof, and then Automake from David and
11078 Tom (who were both gnitsians).  One of their ideas was to write a
11079 document paralleling the GNU standards, that was more strict in some
11080 ways and more detailed.  They never finished the GNITS standards, but
11081 the ideas mostly made their way into Automake.
11083 @item 1995-11-23 Automake 0.20
11085 Besides introducing automatic dependency tracking (@pxref{Dependency
11086 Tracking Evolution}), this version also supplies a 9-page manual.
11088 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
11089 exist, so many things had to be done by hand.  For instance, here is
11090 what a configure.in (this is the former name of the
11091 @file{configure.ac} we use today) must contain in order to use
11092 Automake 0.20:
11094 @example
11095 PACKAGE=cpio
11096 VERSION=2.3.911
11097 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
11098 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
11099 AC_SUBST(PACKAGE)
11100 AC_SUBST(VERSION)
11101 AC_ARG_PROGRAM
11102 AC_PROG_INSTALL
11103 @end example
11105 (Today all of the above is achieved by @code{AC_INIT} and
11106 @code{AM_INIT_AUTOMAKE}.)
11108 Here is how programs are specified in @file{Makefile.am}:
11110 @example
11111 PROGRAMS = hello
11112 hello_SOURCES = hello.c
11113 @end example
11115 This looks pretty much like what we do today, except the
11116 @code{PROGRAMS} variable has no directory prefix specifying where
11117 @file{hello} should be installed: all programs are installed in
11118 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
11119 that must be built but not installed (it is called
11120 @code{noinst_PROGRAMS} nowadays).
11122 Programs can be built conditionally using @code{AC_SUBST}itutions:
11124 @example
11125 PROGRAMS = @@progs@@
11126 AM_PROGRAMS = foo bar baz
11127 @end example
11129 (@code{AM_PROGRAMS} has since then been renamed to
11130 @code{EXTRA_PROGRAMS}.)
11132 Similarly scripts, static libraries, and data can built and installed
11133 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
11134 However @code{LIBRARIES} were treated a bit specially in that Automake
11135 did automatically supply the @file{lib} and @file{.a} prefixes.
11136 Therefore to build @file{libcpio.a}, one had to write
11138 @example
11139 LIBRARIES = cpio
11140 cpio_SOURCES = ...
11141 @end example
11143 Extra files to distribute must be listed in @code{DIST_OTHER} (the
11144 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
11145 distributed should appear in @code{DIST_SUBDIRS}, but the manual
11146 describes this as a temporary ugly hack (today extra directories should
11147 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
11148 for another purpose, @pxref{Conditional Subdirectories}).
11150 @item 1995-11-26 Automake 0.21
11152 In less time that it takes to cook a frozen pizza, Tom rewrites
11153 Automake using Perl.  At this time Perl 5 is only one year old, and
11154 Perl 4.036 is in use at many sites.  Supporting several Perl versions
11155 has been a source of problems through the whole history of Automake.
11157 If you never used Perl 4, imagine Perl 5 without objects, without
11158 @samp{my} variables (only dynamically scoped @samp{local} variables),
11159 without function prototypes, with function calls that needs to be
11160 prefixed with @samp{&}, etc.  Traces of this old style can still be
11161 found in today's @command{automake}.
11163 @item 1995-11-28 Automake 0.22
11164 @itemx 1995-11-29 Automake 0.23
11166 Bug fixes.
11168 @item 1995-12-08 Automake 0.24
11169 @itemx 1995-12-10 Automake 0.25
11171 Releases are raining.  0.24 introduces the uniform naming scheme we
11172 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
11173 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
11174 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
11175 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
11176 prefixes.)  Adding support for prefixes like that was one of the major
11177 ideas in automake; it has lasted pretty well.
11179 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
11180 Pinard's doing).
11182 0.25 fixes a Perl 4 portability bug.
11184 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
11185 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
11187 @item 1996-01-03 Automake 0.26
11188 @itemx 1996-01-03 Automake 0.27
11190 Of the many change and suggestions sent by Fran@,cois Pinard and
11191 included in 0.26, the most important is perhaps the advise that to
11192 ease customization a user rule or variable definition should always
11193 override an Automake rule or definition.
11195 Gordon Matzigkeit and Jim Meyering are two other early contributors
11196 that have been sending fixes.
11198 0.27 fixes yet another Perl 4 portability bug.
11200 @item 1996-01-13 Automake 0.28
11202 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
11203 support.  This is an important step because until this version
11204 Automake did only know about the @file{Makefile.am}s it processed.
11205 @file{configure.in} was Autoconf's world and the link between Autoconf
11206 and Automake had to be done by the @file{Makefile.am} author.  For
11207 instance, if @file{config.h} was generated by @file{configure}, it was the
11208 package maintainer's responsibility to define the @code{CONFIG_HEADER}
11209 variable in each @file{Makefile.am}.
11211 Succeeding releases will rely more and more on scanning
11212 @file{configure.in} to better automate the Autoconf integration.
11214 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
11215 @option{--gnu} and @option{--gnits} options, the latter being stricter.
11217 @item 1996-02-07 Automake 0.29
11219 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
11220 and rebuild rules for @file{configure}-generated file are
11221 automatically output.
11223 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
11224 scheme.
11226 @item 1996-02-24 Automake 0.30
11228 The test suite is born.  It contains 9 tests.  From now on test cases
11229 will be added pretty regularly (@pxref{Releases}), and this proved to
11230 be really helpful later on.
11232 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
11234 All the third-party Autoconf macros, written mostly by Fran@,cois
11235 Pinard (and later Jim Meyering), are distributed in Automake's
11236 hand-written @file{aclocal.m4} file.  Package maintainers are expected
11237 to extract the necessary macros from this file.  (In previous version
11238 you had to copy and paste them from the manual...)
11240 @item 1996-03-11 Automake 0.31
11242 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
11243 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
11244 whenever the @code{TESTS} variable is defined.
11246 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
11247 prefix is introduced.  The syntax is now the same as today.
11249 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
11251 @item 1996-04-27 Automake 0.32
11253 @code{-hook} targets are introduced; an idea from Dieter Baron.
11255 @file{*.info} files, which were output in the build directory are
11256 now built in the source directory, because they are distributed.  It
11257 seems these files like to move back and forth as that will happen
11258 again in future versions.
11260 @item 1996-05-18 Automake 0.33
11262 Gord Matzigkeit's main two contributions:
11264 @itemize
11265 @item very preliminary libtool support
11266 @item the distcheck rule
11267 @end itemize
11269 Although they were very basic at this point, these are probably
11270 among the top features for Automake today.
11272 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
11273 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
11274 author (@pxref{maintainer-mode}).
11276 @item 1996-05-28 Automake 1.0
11278 After only six months of heavy development, the automake script is
11279 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
11280 package has 30 pages of documentation, and 38 test cases.
11281 @file{aclocal.m4} contains 4 macros.
11283 From now on and until version 1.4, new releases will occur at a rate
11284 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
11285 been the name of beta releases for 1.2.  This is the first time
11286 Automake uses suffix letters to designate beta releases, an habit that
11287 lasts.
11289 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
11291 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
11293 Between June and October, the Autoconf development is almost stalled.
11294 Roland McGrath has been working at the beginning of the year.  David
11295 comes back in November to release 2.12, but he won't touch Autoconf
11296 anymore after this year, and Autoconf then really stagnates.  The
11297 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
11299 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
11301 The mailing list is announced as follows:
11302 @smallexample
11303 I've created the "automake" mailing list.  It is
11304 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
11305 automake-request@@gnu.ai.mit.edu.
11307 The charter of this list is discussion of automake, autoconf, and
11308 other configuration/portability tools (e.g., libtool).  It is expected
11309 that discussion will range from pleas for help all the way up to
11310 patches.
11312 This list is archived on the FSF machines.  Offhand I don't know if
11313 you can get the archive without an account there.
11315 This list is open to anybody who wants to join.  Tell all your
11316 friends!
11317 -- Tom Tromey
11318 @end smallexample
11320 Before that people were discussing Automake privately, on the Gnits
11321 mailing list (which is not public either), and less frequently on
11322 @code{gnu.misc.discuss}.
11324 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
11325 noticed.  The archives of the early years of the
11326 @code{automake@@gnu.org} list have been lost, so today it is almost
11327 impossible to find traces of discussions that occurred before 1999.
11328 This has been annoying more than once, as such discussions can be
11329 useful to understand the rationale behind a piece of uncommented code
11330 that was introduced back then.
11332 @item 1997-06-22 Automake 1.2
11334 Automake developments continues, and more and more new Autoconf macros
11335 are required.  Distributing them in @file{aclocal.m4} and requiring
11336 people to browse this file to extract the relevant macros becomes
11337 uncomfortable.  Ideally, some of them should be contributed to
11338 Autoconf so that they can be used directly, however Autoconf is
11339 currently inactive.  Automake 1.2 consequently introduces
11340 @command{aclocal} (@command{aclocal} was actually started on
11341 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
11342 file from a repository of third-party macros.  Because Autoconf has
11343 stalled, Automake also becomes a kind of repository for such
11344 third-party macros, even macros completely unrelated to Automake (for
11345 instance macros that fix broken Autoconf macros).
11347 The 1.2 release contains 20 macros, among which the
11348 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
11349 @file{configure.in}.
11351 Libtool is fully supported using @code{*_LTLIBRARIES}.
11353 The missing script is introduced by Fran@,cois Pinard; it is meant to be
11354 a better solution than @code{AM_MAINTAINER_MODE}
11355 (@pxref{maintainer-mode}).
11357 Conditionals support was implemented by Ian Lance Taylor.  At the
11358 time, Tom and Ian were working on an internal project at Cygnus.  They
11359 were using ILU, which is pretty similar to CORBA@.  They wanted to
11360 integrate ILU into their build, which was all @file{configure}-based,
11361 and Ian thought that adding conditionals to @command{automake} was
11362 simpler than doing all the work in @file{configure} (which was the
11363 standard at the time).  So this was actually funded by Cygnus.
11365 This very useful but tricky feature will take a lot of time to
11366 stabilize.  (At the time this text is written, there are still
11367 primaries that have not been updated to support conditional
11368 definitions in Automake 1.9.)
11370 The @command{automake} script has almost doubled: 6089 lines of Perl,
11371 plus 1294 lines of @file{Makefile} fragments.
11373 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
11375 @item 1998-04-05 Automake 1.3
11377 This is a small advance compared to 1.2.
11378 It add support for assembly, and preliminary support for Java.
11380 Perl 5.004_04 is out, but fixes to support Perl 4 are still
11381 regularly submitted whenever Automake breaks it.
11383 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
11385 Sourceware was setup by Jason Molenda to host open source projects.
11387 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
11388 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake
11389 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
11390 publicly accessible CVS repository.  This CVS repository is a copy of
11391 the one Tom was using on his machine, which in turn is based on
11392 a copy of the CVS repository of David MacKenzie.  This is why we still
11393 have to full source history.  (Automake was on Sourceware until 2007-10-29,
11394 when it moved to a git repository on @code{savannah.gnu.org},
11395 but the Sourceware host had been renamed to @code{sources.redhat.com}.)
11397 The oldest file in the administrative directory of the CVS repository
11398 that was created on Sourceware is dated 1998-09-19, while the
11399 announcement that @command{automake} and @command{autoconf} had joined
11400 @command{sourceware} was made on 1998-10-26.  They were among the
11401 first projects to be hosted there.
11403 The heedful reader will have noticed Automake was exactly 4-year-old
11404 on 1998-09-19.
11406 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
11408 @item 1999-01-14 Automake 1.4
11410 This release adds support for Fortran 77 and for the @code{include}
11411 statement.  Also, @samp{+=} assignments are introduced, but it is
11412 still quite easy to fool Automake when mixing this with conditionals.
11414 These two releases, Automake 1.4 and Autoconf 2.13 makes a duo that
11415 will be used together for years.
11417 @command{automake} is 7228 lines, plus 1591 lines of Makefile
11418 fragment, 20 macros (some 1.3 macros were finally contributed back to
11419 Autoconf), 197 test cases, and 51 pages of documentation.
11421 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
11423 This implements a new dependency tracking schemed that should be
11424 able to handle automatic dependency tracking using any compiler (not
11425 just gcc) and any make (not just GNU @command{make}).  In addition,
11426 the new scheme should be more reliable than the old one, as
11427 dependencies are generated on the end user's machine.  Alexandre Oliva
11428 creates depcomp for this purpose.
11430 @xref{Dependency Tracking Evolution}, for more details about the
11431 evolution of automatic dependency tracking in Automake.
11433 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
11435 This was a huge problem since we also had patches going in on the
11436 trunk.  The merge took a long time and was very painful.
11438 @item 2000-05-10
11440 Since September 1999 and until 2003, Akim Demaille will be zealously
11441 revamping Autoconf.
11443 @quotation
11444 I think the next release should be called "3.0".@*
11445 Let's face it: you've basically rewritten autoconf.@*
11446 Every weekend there are 30 new patches.@*
11447 I don't see how we could call this "2.15" with a straight face.@*
11448 -- Tom Tromey on @email{autoconf@@gnu.org}
11449 @end quotation
11451 Actually Akim works like a submarine: he will pile up patches while he
11452 works off-line during the weekend, and flush them in batch when he
11453 resurfaces on Monday.
11455 @item 2001-01-24
11457 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
11458 is out, and Akim has to find something to do during his week-end :)
11460 @item 2001-01-28
11462 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
11464 @quotation
11465 Aiieeee!  I was dreading the day that the Demaillator turned his
11466 sights on automake@dots{} and now it has arrived! -- Tom Tromey
11467 @end quotation
11469 It's only the beginning: in two months he will send 192 patches.  Then
11470 he would slow down so Tom can catch up and review all this.  Initially
11471 Tom actually read all these patches, then he probably trustingly
11472 answered OK to most of them, and finally gave up and let Akim apply
11473 whatever he wanted.  There was no way to keep up with that patch rate.
11475 @quotation
11476 Anyway the patch below won't apply since it predates Akim's
11477 sourcequake; I have yet to figure where the relevant passage has
11478 been moved :) -- Alexandre Duret-Lutz
11479 @end quotation
11481 All these patches were sent to and discussed on
11482 @email{automake@@gnu.org}, so subscribed users were literally drown in
11483 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
11484 mailing list was created in May.
11486 Year after year, Automake had drifted away from its initial design:
11487 construct @file{Makefile.in} by assembling various @file{Makefile}
11488 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
11489 various places in the @command{automake} script itself; this does not
11490 help ensuring a consistent treatment of these rules (for instance
11491 making sure that user-defined rules override Automake's own rules).
11492 One of Akim's goal was moving all these hard-coded rules to separate
11493 @file{Makefile} fragments, so the logic could be centralized in a
11494 @file{Makefile} fragment processor.
11496 Another significant contribution of Akim is the interface with the
11497 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
11498 this time was to read the file and grep the various macro of interest
11499 to Automake.  Doing so could break in many unexpected ways; automake
11500 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
11501 where the arguments are known only when M4 is run), or conversely it
11502 could detect some macro that was not expanded (because it is called
11503 conditionally).  In the CVS version of Autoconf, Akim had implemented
11504 the @option{--trace} option, which provides accurate information about
11505 where macros are actually called and with what arguments.  Akim will
11506 equip Automake with a second @file{configure.in} scanner that uses
11507 this @option{--trace} interface.  Since it was not sensible to drop the
11508 Autoconf 2.13 compatibility yet, this experimental scanner was only
11509 used when an environment variable was set, the traditional
11510 grep-scanner being still the default.
11512 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
11514 It has been more than two years since Automake 1.4, CVS Automake has
11515 suffered lot's of heavy changes and still is not ready for release.
11516 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
11518 @item 2001-05-08 Automake 1.4-p1
11519 @itemx 2001-05-24 Automake 1.4-p2
11521 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
11522 release'' of Automake:
11524 @quotation
11525 The main purpose of this release is to have a stable automake
11526 which is compatible with the latest stable libtool.
11527 @end quotation
11529 The release also contains obvious fixes for bugs in Automake 1.4,
11530 some of which were reported almost monthly.
11532 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
11534 @item 2001-06-07 Automake 1.4-p3
11535 @itemx 2001-06-10 Automake 1.4-p4
11536 @itemx 2001-07-15 Automake 1.4-p5
11538 Gary continues his patch-release series.  These also add support for
11539 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
11540 @file{configure.ac} over @file{configure.in}, and it introduces a new
11541 syntax for @code{AC_OUTPUT}ing files.
11543 @item 2001-08-23 Automake 1.5
11545 A major and long-awaited release, that comes more than two years after
11546 1.4.  It brings many changes, among which:
11547 @itemize
11548 @item The new dependency tracking scheme that uses @command{depcomp}.
11549 Aside from the improvement on the dependency tracking itself
11550 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
11551 of automake generated @file{Makefile.in}s as the @file{Makefile.in}s
11552 used during development are now the same as those used in
11553 distributions.  Before that the @file{Makefile.in}s generated for
11554 maintainers required GNU @command{make} and GCC, they were different
11555 from the portable @file{Makefile} generated for distribution; this was
11556 causing some confusion.
11558 @item Support for per-target compilation flags.
11560 @item Support for reference to files in subdirectories in most
11561 @file{Makefile.am} variables.
11563 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
11564 prefixes.
11565 @item Perl 4 support is finally dropped.
11566 @end itemize
11568 1.5 did broke several packages that worked with 1.4.  Enough so that
11569 Linux distributions could not easily install the new Automake version
11570 without breaking many of the packages for which they had to run
11571 @command{automake}.
11573 Some of these breakages were effectively bugs that would eventually be
11574 fixed in the next release.  However, a lot of damage was caused by
11575 some changes made deliberately to render Automake stricter on some
11576 setup we did consider bogus.  For instance, @samp{make distcheck} was
11577 improved to check that @samp{make uninstall} did remove all the files
11578 @samp{make install} installed, that @samp{make distclean} did not omit
11579 some file, and that a VPATH build would work even if the source
11580 directory was read-only.  Similarly, Automake now rejects multiple
11581 definitions of the same variable (because that would mix very badly
11582 with conditionals), and @samp{+=} assignments with no previous
11583 definition.  Because these changes all occurred suddenly after 1.4 had
11584 been established for more than two years, it hurt users.
11586 To make matter worse, meanwhile Autoconf (now at version 2.52) was
11587 facing similar troubles, for similar reasons.
11589 @item 2002-03-05 Automake 1.6
11591 This release introduced versioned installation (@pxref{API
11592 versioning}).  This was mainly pushed by Havoc Pennington, taking the
11593 GNOME source tree as motive: due to incompatibilities between the
11594 autotools it's impossible for the GNOME packages to switch to Autoconf
11595 2.53 and Automake 1.5 all at once, so they are currently stuck with
11596 Autoconf 2.13 and Automake 1.4.
11598 The idea was to call this version @file{automake-1.6}, call all its
11599 bug-fix versions identically, and switch to @file{automake-1.7} for
11600 the next release that adds new features or changes some rules.  This
11601 scheme implies maintaining a bug-fix branch in addition to the
11602 development trunk, which means more work from the maintainer, but
11603 providing regular bug-fix releases proved to be really worthwhile.
11605 Like 1.5, 1.6 also introduced a bunch of incompatibilities, meant or
11606 not.  Perhaps the more annoying was the dependence on the newly
11607 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
11608 since its explosive 2.50 release, and included changes required to fix
11609 some bugs in Automake.  In order to upgrade to Automake 1.6, people
11610 now had to upgrade Autoconf too; for some packages it was no picnic.
11612 While versioned installation helped people to upgrade, it also
11613 unfortunately allowed people not to upgrade.  At the time of writing,
11614 some Linux distributions are shipping packages for Automake 1.4, 1.5,
11615 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
11616 Some distribution also call 1.4 the ``stable'' version, and present
11617 ``1.9'' as the development version; this does not really makes sense
11618 since 1.9 is way more solid than 1.4.  All this does not help the
11619 newcomer.
11621 @item 2002-04-11 Automake 1.6.1
11623 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
11624 This one and those following will be handled by Alexandre
11625 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
11626 but his interest into Automake is drifting away towards projects like
11627 @command{gcj}.
11629 Alexandre has been using Automake since 2000, and started to
11630 contribute mostly on Akim's incitement (Akim and Alexandre have been
11631 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
11632 a lot of free time to enjoy hacking Automake.
11634 @item 2002-06-14 Automake 1.6.2
11636 @item 2002-07-28 Automake 1.6.3
11637 @itemx 2002-07-28 Automake 1.4-p6
11639 Two releases on the same day.  1.6.3 is a bug-fix release.
11641 Tom Tromey backported the versioned installation mechanism on the 1.4
11642 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
11643 side by side.  Another request from the GNOME folks.
11645 @item 2002-09-25 Automake 1.7
11647 This release switches to the new @file{configure.ac} scanner Akim
11648 was experimenting in 1.5.
11650 @item 2002-10-16 Automake 1.7.1
11651 @itemx 2002-12-06 Automake 1.7.2
11652 @itemx 2003-02-20 Automake 1.7.3
11653 @itemx 2003-04-23 Automake 1.7.4
11654 @itemx 2003-05-18 Automake 1.7.5
11655 @itemx 2003-07-10 Automake 1.7.6
11656 @itemx 2003-09-07 Automake 1.7.7
11657 @itemx 2003-10-07 Automake 1.7.8
11659 Many bug-fix releases.  1.7 lasted because the development version
11660 (upcoming 1.8) was suffering some major internal revamping.
11662 @item 2003-10-26 Automake on screen
11664 Episode 49, `Repercussions', in the third season of the `Alias' TV
11665 show is first aired.
11667 Marshall, one of the character, is working on a computer virus that he
11668 has to modify before it gets into the wrong hands or something like
11669 that.  The screenshots you see do not show any program code, they show
11670 a @file{Makefile.in} @code{generated by automake}...
11672 @item 2003-11-09 Automake 1.7.9
11674 @item 2003-12-10 Automake 1.8
11676 The most striking update is probably that of @command{aclocal}.
11678 @command{aclocal} now uses @code{m4_include} in the produced
11679 @file{aclocal.m4} when the included macros are already distributed
11680 with the package (an idiom used in many packages), which reduces code
11681 duplication.  Many people liked that, but in fact this change was
11682 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
11683 must be rebuilt whenever a dependency of @file{configure} changes, but
11684 all the @file{m4} files included in @file{aclocal.m4} where unknown
11685 from @command{automake}.  Now @command{automake} can just trace the
11686 @code{m4_include}s to discover the dependencies.
11688 @command{aclocal} also starts using the @option{--trace} Autoconf option
11689 in order to discover used macros more accurately.  This will turn out
11690 to be very tricky (later releases will improve this) as people had
11691 devised many ways to cope with the limitation of previous
11692 @command{aclocal} versions, notably using handwritten
11693 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
11694 rule that is already included by such statement.
11696 Automake also has seen its guts rewritten.  Although this rewriting
11697 took a lot of efforts, it is only apparent to the users in that some
11698 constructions previously disallowed by the implementation now work
11699 nicely.  Conditionals, Locations, Variable and Rule definitions,
11700 Options: these items on which Automake works have been rewritten as
11701 separate Perl modules, and documented.
11703 @itemx 2004-01-11 Automake 1.8.1
11704 @itemx 2004-01-12 Automake 1.8.2
11705 @itemx 2004-03-07 Automake 1.8.3
11706 @itemx 2004-04-25 Automake 1.8.4
11707 @itemx 2004-05-16 Automake 1.8.5
11709 @item 2004-07-28 Automake 1.9
11711 This release tries to simplify the compilation rules it outputs to
11712 reduce the size of the Makefile.  The complaint initially come from
11713 the libgcj developers.  Their @file{Makefile.in} generated with
11714 Automake 1.4 and custom build rules (1.4 did not support compiled
11715 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
11716 down to 1.2MB@.
11718 Aside from this it contains mainly minor changes and bug-fixes.
11720 @itemx 2004-08-11 Automake 1.9.1
11721 @itemx 2004-09-19 Automake 1.9.2
11723 Automake has ten years.  This chapter of the manual was initially
11724 written for this occasion.
11726 @itemx 2007-10-29 Automake repository moves to @code{savannah.gnu.org} and uses
11727 git as primary repository.
11729 @end table
11731 @node Dependency Tracking Evolution
11732 @section Dependency Tracking in Automake
11734 Over the years Automake has deployed three different dependency
11735 tracking methods.  Each method, including the current one, has had
11736 flaws of various sorts.  Here we lay out the different dependency
11737 tracking methods, their flaws, and their fixes.  We conclude with
11738 recommendations for tool writers, and by indicating future directions
11739 for dependency tracking work in Automake.
11741 @subsection First Take
11742 @unnumberedsubsubsec Description
11744 Our first attempt at automatic dependency tracking was based on the
11745 method recommended by GNU @command{make}.  (@pxref{Automatic
11746 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
11747 make Manual})
11749 This version worked by precomputing dependencies ahead of time.  For
11750 each source file, it had a special @file{.P} file that held the
11751 dependencies.  There was a rule to generate a @file{.P} file by
11752 invoking the compiler appropriately.  All such @file{.P} files were
11753 included by the @file{Makefile}, thus implicitly becoming dependencies
11754 of @file{Makefile}.
11756 @unnumberedsubsubsec Bugs
11758 This approach had several critical bugs.
11760 @itemize
11761 @item
11762 The code to generate the @file{.P} file relied on @command{gcc}.
11763 (A limitation, not technically a bug.)
11764 @item
11765 The dependency tracking mechanism itself relied on GNU @command{make}.
11766 (A limitation, not technically a bug.)
11767 @item
11768 Because each @file{.P} file was a dependency of @file{Makefile}, this
11769 meant that dependency tracking was done eagerly by @command{make}.
11770 For instance, @samp{make clean} would cause all the dependency files
11771 to be updated, and then immediately removed.  This eagerness also
11772 caused problems with some configurations; if a certain source file
11773 could not be compiled on a given architecture for some reason,
11774 dependency tracking would fail, aborting the entire build.
11775 @item
11776 As dependency tracking was done as a pre-pass, compile times were
11777 doubled--the compiler had to be run twice per source file.
11778 @item
11779 @samp{make dist} re-ran @command{automake} to generate a
11780 @file{Makefile} that did not have automatic dependency tracking (and
11781 that was thus portable to any version of @command{make}).  In order to
11782 do this portably, Automake had to scan the dependency files and remove
11783 any reference that was to a source file not in the distribution.
11784 This process was error-prone.  Also, if @samp{make dist} was run in an
11785 environment where some object file had a dependency on a source file
11786 that was only conditionally created, Automake would generate a
11787 @file{Makefile} that referred to a file that might not appear in the
11788 end user's build.  A special, hacky mechanism was required to work
11789 around this.
11790 @end itemize
11792 @unnumberedsubsubsec Historical Note
11794 The code generated by Automake is often inspired by the
11795 @file{Makefile} style of a particular author.  In the case of the first
11796 implementation of dependency tracking, I believe the impetus and
11797 inspiration was Jim Meyering.  (I could be mistaken.  If you know
11798 otherwise feel free to correct me.)
11800 @subsection Dependencies As Side Effects
11801 @unnumberedsubsubsec Description
11803 The next refinement of Automake's automatic dependency tracking scheme
11804 was to implement dependencies as side effects of the compilation.
11805 This was aimed at solving the most commonly reported problems with the
11806 first approach.  In particular we were most concerned with eliminating
11807 the weird rebuilding effect associated with make clean.
11809 In this approach, the @file{.P} files were included using the
11810 @code{-include} command, which let us create these files lazily.  This
11811 avoided the @samp{make clean} problem.
11813 We only computed dependencies when a file was actually compiled.  This
11814 avoided the performance penalty associated with scanning each file
11815 twice.  It also let us avoid the other problems associated with the
11816 first, eager, implementation.  For instance, dependencies would never
11817 be generated for a source file that was not compilable on a given
11818 architecture (because it in fact would never be compiled).
11820 @unnumberedsubsubsec Bugs
11822 @itemize
11823 @item
11824 This approach also relied on the existence of @command{gcc} and GNU
11825 @command{make}.  (A limitation, not technically a bug.)
11826 @item
11827 Dependency tracking was still done by the developer, so the problems
11828 from the first implementation relating to massaging of dependencies by
11829 @samp{make dist} were still in effect.
11830 @item
11831 This implementation suffered from the ``deleted header file'' problem.
11832 Suppose a lazily-created @file{.P} file includes a dependency on a
11833 given header file, like this:
11835 @example
11836 maude.o: maude.c something.h
11837 @end example
11839 Now suppose that the developer removes @file{something.h} and updates
11840 @file{maude.c} so that this include is no longer needed.  If he runs
11841 @command{make}, he will get an error because there is no way to create
11842 @file{something.h}.
11844 We fixed this problem in a later release by further massaging the
11845 output of @command{gcc} to include a dummy dependency for each header
11846 file.
11847 @end itemize
11849 @subsection Dependencies for the User
11850 @unnumberedsubsubsec Description
11852 The bugs associated with @samp{make dist}, over time, became a real
11853 problem.  Packages using Automake were being built on a large number
11854 of platforms, and were becoming increasingly complex.  Broken
11855 dependencies were distributed in ``portable'' @file{Makefile.in}s,
11856 leading to user complaints.  Also, the requirement for @command{gcc}
11857 and GNU @command{make} was a constant source of bug reports.  The next
11858 implementation of dependency tracking aimed to remove these problems.
11860 We realized that the only truly reliable way to automatically track
11861 dependencies was to do it when the package itself was built.  This
11862 meant discovering a method portable to any version of make and any
11863 compiler.  Also, we wanted to preserve what we saw as the best point
11864 of the second implementation: dependency computation as a side effect
11865 of compilation.
11867 In the end we found that most modern make implementations support some
11868 form of include directive.  Also, we wrote a wrapper script that let
11869 us abstract away differences between dependency tracking methods for
11870 compilers.  For instance, some compilers cannot generate dependencies
11871 as a side effect of compilation.  In this case we simply have the
11872 script run the compiler twice.  Currently our wrapper script
11873 (@command{depcomp}) knows about twelve different compilers (including
11874 a "compiler" that simply invokes @command{makedepend} and then the
11875 real compiler, which is assumed to be a standard Unix-like C compiler
11876 with no way to do dependency tracking).
11878 @unnumberedsubsubsec Bugs
11880 @itemize
11881 @item
11882 Running a wrapper script for each compilation slows down the build.
11883 @item
11884 Many users don't really care about precise dependencies.
11885 @item
11886 This implementation, like every other automatic dependency tracking
11887 scheme in common use today (indeed, every one we've ever heard of),
11888 suffers from the ``duplicated new header'' bug.
11890 This bug occurs because dependency tracking tools, such as the
11891 compiler, only generate dependencies on the successful opening of a
11892 file, and not on every probe.
11894 Suppose for instance that the compiler searches three directories for
11895 a given header, and that the header is found in the third directory.
11896 If the programmer erroneously adds a header file with the same name to
11897 the first directory, then a clean rebuild from scratch could fail
11898 (suppose the new header file is buggy), whereas an incremental rebuild
11899 will succeed.
11901 What has happened here is that people have a misunderstanding of what
11902 a dependency is.  Tool writers think a dependency encodes information
11903 about which files were read by the compiler.  However, a dependency
11904 must actually encode information about what the compiler tried to do.
11906 This problem is not serious in practice.  Programmers typically do not
11907 use the same name for a header file twice in a given project.  (At
11908 least, not in C or C++.  This problem may be more troublesome in
11909 Java.)  This problem is easy to fix, by modifying dependency
11910 generators to record every probe, instead of every successful open.
11912 @item
11913 Since automake generates dependencies as a side effect of compilation,
11914 there is a bootstrapping problem when header files are generated by
11915 running a program.  The problem is that, the first time the build is
11916 done, there is no way by default to know that the headers are
11917 required, so make might try to run a compilation for which the headers
11918 have not yet been built.
11920 This was also a problem in the previous dependency tracking implementation.
11922 The current fix is to use @code{BUILT_SOURCES} to list built headers
11923 (@pxref{Sources}).  This causes them to be built before any other
11924 build rules are run.  This is unsatisfactory as a general solution,
11925 however in practice it seems sufficient for most actual programs.
11926 @end itemize
11928 This code is used since Automake 1.5.
11930 In GCC 3.0, we managed to convince the maintainers to add special
11931 command-line options to help Automake more efficiently do its job.  We
11932 hoped this would let us avoid the use of a wrapper script when
11933 Automake's automatic dependency tracking was used with @command{gcc}.
11935 Unfortunately, this code doesn't quite do what we want.  In
11936 particular, it removes the dependency file if the compilation fails;
11937 we'd prefer that it instead only touch the file in any way if the
11938 compilation succeeds.
11940 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
11941 detected at @command{configure} time, we inline the
11942 dependency-generation code and do not use the @command{depcomp}
11943 wrapper script.  This makes compilations faster for those using this
11944 compiler (probably our primary user base).  The counterpart is that
11945 because we have to encode two compilation rules in @file{Makefile}
11946 (with or without @command{depcomp}), the produced @file{Makefile}s are
11947 larger.
11949 @subsection Techniques for Computing Dependencies
11951 There are actually several ways for a build tool like Automake to
11952 cause tools to generate dependencies.
11954 @table @asis
11955 @item @command{makedepend}
11956 This was a commonly-used method in the past.  The idea is to run a
11957 special program over the source and have it generate dependency
11958 information.  Traditional implementations of @command{makedepend} are
11959 not completely precise; ordinarily they were conservative and
11960 discovered too many dependencies.
11961 @item The tool
11962 An obvious way to generate dependencies is to simply write the tool so
11963 that it can generate the information needed by the build tool.  This is
11964 also the most portable method.  Many compilers have an option to
11965 generate dependencies.  Unfortunately, not all tools provide such an
11966 option.
11967 @item The file system
11968 It is possible to write a special file system that tracks opens,
11969 reads, writes, etc, and then feed this information back to the build
11970 tool.  @command{clearmake} does this.  This is a very powerful
11971 technique, as it doesn't require cooperation from the
11972 tool.  Unfortunately it is also very difficult to implement and also
11973 not practical in the general case.
11974 @item @code{LD_PRELOAD}
11975 Rather than use the file system, one could write a special library to
11976 intercept @code{open} and other syscalls.  This technique is also quite
11977 powerful, but unfortunately it is not portable enough for use in
11978 @command{automake}.
11979 @end table
11981 @subsection Recommendations for Tool Writers
11983 We think that every compilation tool ought to be able to generate
11984 dependencies as a side effect of compilation.  Furthermore, at least
11985 while @command{make}-based tools are nearly universally in use (at
11986 least in the free software community), the tool itself should generate
11987 dummy dependencies for header files, to avoid the deleted header file
11988 bug.  Finally, the tool should generate a dependency for each probe,
11989 instead of each successful file open, in order to avoid the duplicated
11990 new header bug.
11992 @subsection Future Directions for Automake's Dependency Tracking
11994 Currently, only languages and compilers understood by Automake can
11995 have dependency tracking enabled.  We would like to see if it is
11996 practical (and worthwhile) to let this support be extended by the user
11997 to languages unknown to Automake.
11999 @node Releases
12000 @section Release Statistics
12002 The following table (inspired by @samp{perlhist(1)}) quantifies the
12003 evolution of Automake using these metrics:
12005 @table @asis
12006 @item Date, Rel
12007 The date and version of the release.
12008 @item am
12009 The number of lines of the @command{automake} script.
12010 @item acl
12011 The number of lines of the @command{aclocal} script.
12012 @item pm
12013 The number of lines of the @command{Perl} supporting modules.
12014 @item @file{*.am}
12015 The number of lines of the @file{Makefile} fragments.  The number in parenthesis
12016 is the number of files.
12017 @item m4
12018 The number of lines (and files) of Autoconf macros.
12019 @item doc
12020 The number of pages of the documentation (the Postscript version).
12021 @item t
12022 The number of test cases in the test suite.
12023 @end table
12025 @multitable {8888-88-88} {8.8-p8} {8888} {8888} {8888} {8888 (88)} {8888 (88)} {888} {888}
12026 @headitem Date   @tab Rel @tab am @tab acl @tab pm @tab @file{*.am} @tab m4 @tab doc @tab t
12027 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
12028 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
12029 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
12030 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
12031 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
12032 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
12033 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
12034 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
12035 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
12036 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
12037 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
12038 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
12039 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
12040 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
12041 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
12042 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
12043 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
12044 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (20) @tab  37 @tab 126
12045 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (23) @tab  39 @tab 156
12046 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
12047 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
12048 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
12049 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
12050 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 198
12051 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (20) @tab  51 @tab 198
12052 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (29) @tab  63 @tab 327
12053 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (27) @tab  66 @tab 365
12054 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (27) @tab  66 @tab 372
12055 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (27) @tab  67 @tab 386
12056 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (27) @tab  67 @tab 391
12057 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (20) @tab  49 @tab 197
12058 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (28) @tab  73 @tab 430
12059 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (28) @tab  73 @tab 437
12060 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (28) @tab  77 @tab 445
12061 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (29) @tab  84 @tab 448
12062 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (29) @tab  85 @tab 458
12063 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (29) @tab  85 @tab 459
12064 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (29) @tab  85 @tab 461
12065 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 467
12066 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 468
12067 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (29) @tab  90 @tab 468
12068 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (31) @tab 104 @tab 521
12069 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (31) @tab 104 @tab 525
12070 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (31) @tab 104 @tab 526
12071 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (31) @tab 111 @tab 530
12072 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (31) @tab 112 @tab 531
12073 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (31) @tab 112 @tab 533
12074 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (32) @tab 115 @tab 551
12075 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 115 @tab 552
12076 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 132 @tab 554
12077 @item 2004-11-01 @tab 1.9.3  @tab 7507 @tab 718 @tab 7804 @tab 3354 (40) @tab 1812 (32) @tab 134 @tab 556
12078 @item 2004-12-18 @tab 1.9.4  @tab 7508 @tab 718 @tab 7856 @tab 3361 (40) @tab 1811 (32) @tab 140 @tab 560
12079 @item 2005-02-13 @tab 1.9.5  @tab 7523 @tab 719 @tab 7859 @tab 3373 (40) @tab 1453 (32) @tab 142 @tab 562
12080 @item 2005-07-10 @tab 1.9.6  @tab 7539 @tab 699 @tab 7867 @tab 3400 (40) @tab 1453 (32) @tab 144 @tab 570
12081 @item 2006-10-15 @tab 1.10   @tab 7859 @tab 1072 @tab 8024 @tab 3512 (40) @tab 1496 (34) @tab 172 @tab 604
12082 @end multitable
12085 @c ========================================================== Appendices
12087 @page
12088 @node Copying This Manual
12089 @appendix Copying This Manual
12091 @menu
12092 * GNU Free Documentation License::  License for copying this manual
12093 @end menu
12095 @include fdl.texi
12097 @page
12098 @node Indices
12099 @appendix Indices
12101 @menu
12102 * Macro Index::                 Index of Autoconf macros
12103 * Variable Index::              Index of Makefile variables
12104 * General Index::               General index
12105 @end menu
12107 @node Macro Index
12108 @appendixsec Macro Index
12110 @printindex fn
12112 @node Variable Index
12113 @appendixsec Variable Index
12115 @printindex vr
12117 @node General Index
12118 @appendixsec General Index
12120 @printindex cp
12123 @page
12124 @contents
12125 @bye
12127 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
12128 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
12129 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
12130 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
12131 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
12132 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
12133 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
12134 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
12135 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
12136 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
12137 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
12138 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
12139 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
12140 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
12141 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
12142 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
12143 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
12144 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
12145 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
12146 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
12147 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
12148 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
12149 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
12150 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
12151 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
12152 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
12153 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
12154 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
12155 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
12156 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
12157 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
12158 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
12159 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
12160 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
12161 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
12162 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
12163 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
12164 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
12165 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
12166 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
12167 @c  LocalWords:  unnumberedsubsec depfile tmpdepfile depmode const interoperate
12168 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
12169 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
12170 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
12171 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
12172 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
12173 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
12174 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
12175 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
12176 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
12177 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
12178 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
12179 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
12180 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
12181 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
12182 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
12183 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
12184 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
12185 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
12186 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
12187 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
12188 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
12189 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
12190 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
12191 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
12192 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
12193 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
12194 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
12195 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
12196 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
12197 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
12198 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
12199 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
12200 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
12201 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
12202 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
12203 @c  LocalWords:  barexec Pinard's automatize initialize lzma