Implement the `notrans_' prefix for untransformed manpages.
[automake/plouj.git] / doc / automake.texi
bloba56eca455146257f789724338b2b0fb78ebf243f
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @setchapternewpage off
6 @c %**end of header
8 @include version.texi
10 @copying
12 This manual is for @acronym{GNU} Automake (version @value{VERSION},
13 @value{UPDATED}), a program that creates GNU standards-compliant
14 Makefiles from template files.
16 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
17 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
19 @quotation
20 Permission is granted to copy, distribute and/or modify this document
21 under the terms of the @acronym{GNU} Free Documentation License,
22 Version 1.2 or any later version published by the Free Software
23 Foundation; with no Invariant Sections, with no Front-Cover texts,
24 and with no Back-Cover Texts.  A copy of the license is included in the
25 section entitled ``@acronym{GNU} Free Documentation License.''
27 @end quotation
28 @end copying
30 @c info Automake  points to the Automake package's documentation
31 @c info automake  points to the automake script's documentation
32 @c (Autoconf has a similar setup.)
33 @dircategory Software development
34 @direntry
35 * Automake: (automake).         Making GNU standards-compliant Makefiles.
36 @end direntry
38 @dircategory Individual utilities
39 @direntry
40 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4.
41 * automake: (automake)Invoking Automake.        Generating Makefile.in.
42 @end direntry
44 @titlepage
45 @title GNU Automake
46 @subtitle For version @value{VERSION}, @value{UPDATED}
47 @author David MacKenzie
48 @author Tom Tromey
49 @author Alexandre Duret-Lutz
50 @page
51 @vskip 0pt plus 1filll
52 @insertcopying
53 @end titlepage
56 @c We use the following macros to define indices:
57 @c   @cindex   concepts, and anything that does not fit elsewhere
58 @c   @vindex   Makefile variables
59 @c   @trindex  targets
60 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
61 @c   @opindex  tool options
63 @c Define an index of configure macros.
64 @defcodeindex ac
65 @c Define an index of options.
66 @defcodeindex op
67 @c Define an index of targets.
68 @defcodeindex tr
69 @c Define an index of commands.
70 @defcodeindex cm
72 @c Put the macros in the function index.
73 @syncodeindex ac fn
75 @c Put everything else into one index (arbitrarily chosen to be the concept index).
76 @syncodeindex op cp
77 @syncodeindex tr cp
78 @syncodeindex cm cp
80 @ifnottex
81 @node Top
82 @comment  node-name,  next,  previous,  up
83 @top GNU Automake
85 @insertcopying
87 @menu
88 * Introduction::                Automake's purpose
89 * Autotools Introduction::      An Introduction to the Autotools
90 * Generalities::                General ideas
91 * Examples::                    Some example packages
92 * Invoking Automake::           Creating a Makefile.in
93 * configure::                   Scanning configure.ac or configure.in
94 * Directories::                 Declaring subdirectories
95 * Programs::                    Building programs and libraries
96 * Other objects::               Other derived objects
97 * Other GNU Tools::             Other GNU Tools
98 * Documentation::               Building documentation
99 * Install::                     What gets installed
100 * Clean::                       What gets cleaned
101 * Dist::                        What goes in a distribution
102 * Tests::                       Support for test suites
103 * Rebuilding::                  Automatic rebuilding of Makefile
104 * Options::                     Changing Automake's behavior
105 * Miscellaneous::               Miscellaneous rules
106 * Include::                     Including extra files in an Automake template.
107 * Conditionals::                Conditionals
108 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
109 * Cygnus::                      The effect of @option{--cygnus}
110 * Not Enough::                  When Automake is not Enough
111 * Distributing::                Distributing the Makefile.in
112 * API versioning::              About compatibility between Automake versions
113 * Upgrading::                   Upgrading to a Newer Automake Version
114 * FAQ::                         Frequently Asked Questions
115 * History::                     Notes about the history of Automake
116 * Copying This Manual::         How to make copies of this manual
117 * Indices::                     Indices of variables, macros, and concepts
119 @detailmenu
120  --- The Detailed Node Listing ---
122 An Introduction to the Autotools
124 * GNU Build System::            Introducing the GNU Build System
125 * Use Cases::                   Use Cases for the GNU Build System
126 * Why Autotools::               How Autotools Help
127 * Hello World::                 A Small Hello World Package
129 Use Cases for the GNU Build System
131 * Basic Installation::          Common installation procedure
132 * Standard Targets::            A list of standard Makefile targets
133 * Standard Directory Variables::  A list of standard directory variables
134 * Standard Configuration Variables::  Using configuration variables
135 * config.site::                 Using a config.site file
136 * VPATH Builds::                Parallel build trees
137 * Two-Part Install::            Installing data and programs separately
138 * Cross-Compilation::           Building for other architectures
139 * Renaming::                    Renaming programs at install time
140 * DESTDIR::                     Building binary packages with DESTDIR
141 * Preparing Distributions::     Rolling out tarballs
142 * Dependency Tracking::         Automatic dependency tracking
143 * Nested Packages::             The GNU Build Systems can be nested
145 A Small Hello World
147 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
148 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
150 General ideas
152 * General Operation::           General operation of Automake
153 * Strictness::                  Standards conformance checking
154 * Uniform::                     The Uniform Naming Scheme
155 * Canonicalization::            How derived variables are named
156 * User Variables::              Variables reserved for the user
157 * Auxiliary Programs::          Programs automake might require
159 Some example packages
161 * Complete::                    A simple example, start to finish
162 * true::                        Building true and false
164 Scanning @file{configure.ac}
166 * Requirements::                Configuration requirements
167 * Optional::                    Other things Automake recognizes
168 * Invoking aclocal::            Auto-generating aclocal.m4
169 * Macros::                      Autoconf macros supplied with Automake
171 Auto-generating aclocal.m4
173 * aclocal options::             Options supported by aclocal
174 * Macro search path::           How aclocal finds .m4 files
175 * Extending aclocal::           Writing your own aclocal macros
176 * Local Macros::                Organizing local macros
177 * Serials::                     Serial lines in Autoconf macros
178 * Future of aclocal::           aclocal's scheduled death
180 Autoconf macros supplied with Automake
182 * Public macros::               Macros that you can use.
183 * Obsolete macros::             Macros that you should stop using.
184 * Private macros::              Macros that you should not use.
186 Directories
188 * Subdirectories::              Building subdirectories recursively
189 * Conditional Subdirectories::  Conditionally not building directories
190 * Alternative::                 Subdirectories without recursion
191 * Subpackages::                 Nesting packages
193 Building Programs and Libraries
195 * A Program::                   Building a program
196 * A Library::                   Building a library
197 * A Shared Library::            Building a Libtool library
198 * Program and Library Variables::  Variables controlling program and
199                                 library builds
200 * Default _SOURCES::            Default source files
201 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
202 * Program variables::           Variables used when building a program
203 * Yacc and Lex::                Yacc and Lex support
204 * C++ Support::                 Compiling C++ sources
205 * Objective C Support::         Compiling Objective C sources
206 * Unified Parallel C Support::  Compiling Unified Parallel C sources
207 * Assembly Support::            Compiling assembly sources
208 * Fortran 77 Support::          Compiling Fortran 77 sources
209 * Fortran 9x Support::          Compiling Fortran 9x sources
210 * Java Support::                Compiling Java sources
211 * Support for Other Languages::  Compiling other languages
212 * ANSI::                        Automatic de-ANSI-fication (obsolete)
213 * Dependencies::                Automatic dependency tracking
214 * EXEEXT::                      Support for executable extensions
216 Building a program
218 * Program Sources::             Defining program sources
219 * Linking::                     Linking with libraries or extra objects
220 * Conditional Sources::         Handling conditional sources
221 * Conditional Programs::        Building program conditionally
223 Building a Shared Library
225 * Libtool Concept::             Introducing Libtool
226 * Libtool Libraries::           Declaring Libtool Libraries
227 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
228 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
229 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
230 * Libtool Modules::             Building Libtool Modules
231 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
232 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
233 * Libtool Issues::              Common Issues Related to Libtool's Use
235 Fortran 77 Support
237 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
238 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
239 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
241 Mixing Fortran 77 With C and C++
243 * How the Linker is Chosen::    Automatic linker selection
245 Fortran 9x Support
247 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
249 Other Derived Objects
251 * Scripts::                     Executable scripts
252 * Headers::                     Header files
253 * Data::                        Architecture-independent data files
254 * Sources::                     Derived sources
256 Built sources
258 * Built sources example::       Several ways to handle built sources.
260 Other GNU Tools
262 * Emacs Lisp::                  Emacs Lisp
263 * gettext::                     Gettext
264 * Libtool::                     Libtool
265 * Java::                        Java
266 * Python::                      Python
268 Building documentation
270 * Texinfo::                     Texinfo
271 * Man pages::                   Man pages
273 Miscellaneous Rules
275 * Tags::                        Interfacing to etags and mkid
276 * Suffixes::                    Handling new file extensions
277 * Multilibs::                   Support for multilibs.
279 When Automake Isn't Enough
281 * Extending::                   Adding new rules or overriding existing ones.
282 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
284 Frequently Asked Questions about Automake
286 * CVS::                         CVS and generated files
287 * maintainer-mode::             missing and AM_MAINTAINER_MODE
288 * wildcards::                   Why doesn't Automake support wildcards?
289 * limitations on file names::   Limitations on source and installed file names
290 * distcleancheck::              Files left in build directory after distclean
291 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
292 * renamed objects::             Why are object files sometimes renamed?
293 * Per-Object Flags::            How to simulate per-object flags?
294 * Multiple Outputs::            Writing rules for tools with many output files
295 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
297 History of Automake
299 * Timeline::                    The Automake story.
300 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
301 * Releases::                    Statistics about Automake Releases
303 Copying This Manual
305 * GNU Free Documentation License::  License for copying this manual
307 Indices
309 * Macro Index::                 Index of Autoconf macros
310 * Variable Index::              Index of Makefile variables
311 * General Index::               General index
313 @end detailmenu
314 @end menu
316 @end ifnottex
319 @node Introduction
320 @chapter Introduction
322 Automake is a tool for automatically generating @file{Makefile.in}s
323 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
324 basically a series of @command{make} variable
325 definitions@footnote{These variables are also called @dfn{make macros}
326 in Make terminology, however in this manual we reserve the term
327 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
328 occasionally.  The generated @file{Makefile.in}s are compliant with
329 the GNU Makefile standards.
331 @cindex GNU Makefile standards
333 The GNU Makefile Standards Document
334 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
335 is long, complicated, and subject to change.  The goal of Automake is to
336 remove the burden of Makefile maintenance from the back of the
337 individual GNU maintainer (and put it on the back of the Automake
338 maintainers).
340 The typical Automake input file is simply a series of variable definitions.
341 Each such file is processed to create a @file{Makefile.in}.  There
342 should generally be one @file{Makefile.am} per directory of a project.
344 @cindex Constraints of Automake
345 @cindex Automake constraints
347 Automake does constrain a project in certain ways; for instance, it
348 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
349 autoconf, The Autoconf Manual}), and enforces certain restrictions on
350 the @file{configure.ac} contents@footnote{Older Autoconf versions used
351 @file{configure.in}.  Autoconf 2.50 and greater promotes
352 @file{configure.ac} over @file{configure.in}.  The rest of this
353 documentation will refer to @file{configure.ac}, but Automake also
354 supports @file{configure.in} for backward compatibility.}.
356 @cindex Automake requirements
357 @cindex Requirements, Automake
359 Automake requires @command{perl} in order to generate the
360 @file{Makefile.in}s.  However, the distributions created by Automake are
361 fully GNU standards-compliant, and do not require @command{perl} in order
362 to be built.
364 @cindex Bugs, reporting
365 @cindex Reporting bugs
366 @cindex E-mail, bug reports
368 Mail suggestions and bug reports for Automake to
369 @email{bug-automake@@gnu.org}.
371 @node Autotools Introduction
372 @chapter An Introduction to the Autotools
374 If you are new to Automake, maybe you know that it is part of a set of
375 tools called @emph{The Autotools}.  Maybe you've already delved into a
376 package full of files named @file{configure}, @file{configure.ac},
377 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
378 some of them claiming to be @emph{generated by} Autoconf or Automake.
379 But the exact purpose of these files and their relations is probably
380 fuzzy.  The goal of this chapter is to introduce you to this machinery,
381 to show you how it works and how powerful it is.  If you've never
382 installed or seen such a package, do not worry: this chapter will walk
383 you through it.
385 If you need some teaching material, more illustrations, or a less
386 @command{automake}-centered continuation, some slides for this
387 introduction are available in Alexandre Duret-Lutz's
388 @uref{http://www-src.lip6.fr/@/~Alexandre.Duret-Lutz/@/autotools.html,
389 Autotools Tutorial}.
390 This chapter is the written version of the first part of his tutorial.
392 @menu
393 * GNU Build System::            Introducing the GNU Build System
394 * Use Cases::                   Use Cases for the GNU Build System
395 * Why Autotools::               How Autotools Help
396 * Hello World::                 A Small Hello World Package
397 @end menu
399 @node GNU Build System
400 @section Introducing the GNU Build System
401 @cindex GNU Build System, introduction
403 It is a truth universally acknowledged, that a developer in
404 possession of a new package, must be in want of a build system.
406 In the Unix world, such a build system is traditionally achieved using
407 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
408 Manual}).  The developer expresses the recipe to build his package in
409 a @file{Makefile}.  This file is a set of rules to build the files in
410 the package.  For instance the program @file{prog} may be built by
411 running the linker on the files @file{main.o}, @file{foo.o}, and
412 @file{bar.o}; the file @file{main.o} may be built by running the
413 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
414 reads @file{Makefile}, checks the existence and modification time of
415 the files mentioned, decides what files need to be built (or rebuilt),
416 and runs the associated commands.
418 When a package needs to be built on a different platform than the one
419 it was developed on, its @file{Makefile} usually needs to be adjusted.
420 For instance the compiler may have another name or require more
421 options.  In 1991, David J. MacKenzie got tired of customizing
422 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
423 handcrafted a little shell script called @file{configure} to
424 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
425 autoconf, The Autoconf Manual}).  Compiling his package was now
426 as simple as running @code{./configure && make}.
428 @cindex GNU Coding Standards
430 Today this process has been standardized in the GNU project.  The GNU
431 Coding Standards (@pxref{Managing Releases, The Release Process, ,
432 standards, The GNU Coding Standards}) explains how each package of the
433 GNU project should have a @file{configure} script, and the minimal
434 interface it should have.  The @file{Makefile} too should follow some
435 established conventions.  The result?  A unified build system that
436 makes all packages almost indistinguishable by the installer.  In its
437 simplest scenario, all the installer has to do is to unpack the
438 package, run @code{./configure && make && make install}, and repeat
439 with the next package to install.
441 We call this build system the @dfn{GNU Build System}, since it was
442 grown out of the GNU project.  However it is used by a vast number of
443 other packages: following any existing convention has its advantages.
445 @cindex Autotools, introduction
447 The Autotools are tools that will create a GNU Build System for your
448 package.  Autoconf mostly focuses on @file{configure} and Automake on
449 @file{Makefile}s.  It is entirely possible to create a GNU Build
450 System without the help of these tools.  However it is rather
451 burdensome and error-prone.  We will discuss this again after some
452 illustration of the GNU Build System in action.
454 @node Use Cases
455 @section Use Cases for the GNU Build System
456 @cindex GNU Build System, use cases
457 @cindex GNU Build System, features
458 @cindex Features of the GNU Build System
459 @cindex Use Cases for the GNU Build System
460 @cindex @file{amhello-1.0.tar.gz}, location
461 @cindex @file{amhello-1.0.tar.gz}, use cases
463 In this section we explore several use cases for the GNU Build System.
464 You can replay all these examples on the @file{amhello-1.0.tar.gz}
465 package distributed with Automake.  If Automake is installed on your
466 system, you should find a copy of this file in
467 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
468 @var{prefix} is the installation prefix specified during configuration
469 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
470 installed by some GNU/Linux distribution it most likely has been set
471 to @file{/usr}).  If you do not have a copy of Automake installed,
472 you can find a copy of this file inside the @file{doc/} directory of
473 the Automake package.
475 Some of the following use cases present features that are in fact
476 extensions to the GNU Build System.  Read: they are not specified by
477 the GNU Coding Standards, but they are nonetheless part of the build
478 system created by the Autotools.  To keep things simple, we do not
479 point out the difference.  Our objective is to show you many of the
480 features that the build system created by the Autotools will offer to
481 you.
483 @menu
484 * Basic Installation::          Common installation procedure
485 * Standard Targets::            A list of standard Makefile targets
486 * Standard Directory Variables::  A list of standard directory variables
487 * Standard Configuration Variables::  Using configuration variables
488 * config.site::                 Using a config.site file
489 * VPATH Builds::                Parallel build trees
490 * Two-Part Install::            Installing data and programs separately
491 * Cross-Compilation::           Building for other architectures
492 * Renaming::                    Renaming programs at install time
493 * DESTDIR::                     Building binary packages with DESTDIR
494 * Preparing Distributions::     Rolling out tarballs
495 * Dependency Tracking::         Automatic dependency tracking
496 * Nested Packages::             The GNU Build Systems can be nested
497 @end menu
499 @node Basic Installation
500 @subsection Basic Installation
501 @cindex Configuration, basics
502 @cindex Installation, basics
503 @cindex GNU Build System, basics
505 The most common installation procedure looks as follows.
507 @example
508 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
509 ~ % @kbd{cd amhello-1.0}
510 ~/amhello-1.0 % @kbd{./configure}
511 @dots{}
512 config.status: creating Makefile
513 config.status: creating src/Makefile
514 @dots{}
515 ~/amhello-1.0 % @kbd{make}
516 @dots{}
517 ~/amhello-1.0 % @kbd{make check}
518 @dots{}
519 ~/amhello-1.0 % @kbd{su}
520 Password:
521 /home/adl/amhello-1.0 # @kbd{make install}
522 @dots{}
523 /home/adl/amhello-1.0 # @kbd{exit}
524 ~/amhello-1.0 % @kbd{make installcheck}
525 @dots{}
526 @end example
528 @cindex Unpacking
530 The user first unpacks the package.  Here, and in the following
531 examples, we will use the non-portable @code{tar zxf} command for
532 simplicity.  On a system without GNU @command{tar} installed, this
533 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
535 The user then enters the newly created directory to run the
536 @file{configure} script.  This script probes the system for various
537 features, and finally creates the @file{Makefile}s.  In this toy
538 example there are only two @file{Makefile}s, but in real-world projects,
539 there may be many more, usually one @file{Makefile} per directory.
541 It is now possible to run @code{make}.  This will construct all the
542 programs, libraries, and scripts that need to be constructed for the
543 package.  In our example, this compiles the @file{hello} program.
544 All files are constructed in place, in the source tree; we will see
545 later how this can be changed.
547 @code{make check} causes the package's tests to be run.  This step is
548 not mandatory, but it is often good to make sure the programs that
549 have been built behave as they should, before you decide to install
550 them.  Our example does not contain any tests, so running @code{make
551 check} is a no-op.
553 @cindex su, before @code{make install}
554 After everything has been built, and maybe tested, it is time to
555 install it on the system.  That means copying the programs,
556 libraries, header files, scripts, and other data files from the
557 source directory to their final destination on the system.  The
558 command @code{make install} will do that.  However, by default
559 everything will be installed in subdirectories of @file{/usr/local}:
560 binaries will go into @file{/usr/local/bin}, libraries will end up in
561 @file{/usr/local/lib}, etc.  This destination is usually not writable
562 by any user, so we assume that we have to become root before we can
563 run @code{make install}.  In our example, running @code{make install}
564 will copy the program @file{hello} into @file{/usr/local/bin}
565 and @file{README} into @file{/usr/local/share/doc/amhello}.
567 A last and optional step is to run @code{make installcheck}.  This
568 command may run tests on the installed files.  @code{make check} tests
569 the files in the source tree, while @code{make installcheck} tests
570 their installed copies.  The tests run by the latter can be different
571 from those run by the former.  For instance, there are tests that
572 cannot be run in the source tree.  Conversely, some packages are set
573 up so that @code{make installcheck} will run the very same tests as
574 @code{make check}, only on different files (non-installed
575 vs.@: installed).  It can make a difference, for instance when the
576 source tree's layout is different from that of the installation.
577 Furthermore it may help to diagnose an incomplete installation.
579 Presently most packages do not have any @code{installcheck} tests
580 because the existence of @code{installcheck} is little known, and its
581 usefulness is neglected.  Our little toy package is no better: @code{make
582 installcheck} does nothing.
584 @node Standard Targets
585 @subsection Standard @file{Makefile} Targets
587 So far we have come across four ways to run @command{make} in the GNU
588 Build System: @code{make}, @code{make check}, @code{make install}, and
589 @code{make installcheck}.  The words @code{check}, @code{install}, and
590 @code{installcheck}, passed as arguments to @command{make}, are called
591 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
592 @code{all} being the default target in the GNU Build System.
594 Here is a list of the most useful targets that the GNU Coding Standards
595 specify.
597 @table @code
598 @item make all
599 @trindex all
600 Build programs, libraries, documentation, etc.@: (same as @code{make}).
601 @item make install
602 @trindex install
603 Install what needs to be installed, copying the files from the
604 package's tree to system-wide directories.
605 @item make install-strip
606 @trindex install-strip
607 Same as @code{make install}, then strip debugging symbols.  Some
608 users like to trade space for useful bug reports@enddots{}
609 @item make uninstall
610 @trindex uninstall
611 The opposite of @code{make install}: erase the installed files.
612 (This needs to be run from the same build tree that was installed.)
613 @item make clean
614 @trindex clean
615 Erase from the build tree the files built by @code{make all}.
616 @item make distclean
617 @trindex distclean
618 Additionally erase anything @code{./configure} created.
619 @item make check
620 @trindex check
621 Run the test suite, if any.
622 @item make installcheck
623 @trindex installcheck
624 Check the installed programs or libraries, if supported.
625 @item make dist
626 @trindex dist
627 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
628 files.
629 @end table
631 @node Standard Directory Variables
632 @subsection Standard Directory Variables
633 @cindex directory variables
635 The GNU Coding Standards also specify a hierarchy of variables to
636 denote installation directories.  Some of these are:
638 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
639 @headitem Directory variable    @tab Default value
640 @item @code{prefix}              @tab @code{/usr/local}
641 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
642 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
643 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
644 @item @w{@ @ @ @ @dots{}}
645 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
646 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
647 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
648 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
649 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
650 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
651 @item @w{@ @ @dots{}}
652 @end multitable
654 @c We should provide a complete table somewhere, but not here.  The
655 @c complete list of directory variables it too confusing as-is.  It
656 @c requires some explanations that are too complicated for this
657 @c introduction.  Besides listing directories like localstatedir
658 @c would make the explanations in ``Two-Part Install'' harder.
660 Each of these directories has a role which is often obvious from its
661 name.  In a package, any installable file will be installed in one of
662 these directories.  For instance in @code{amhello-1.0}, the program
663 @file{hello} is to be installed in @var{bindir}, the directory for
664 binaries.  The default value for this directory is
665 @file{/usr/local/bin}, but the user can supply a different value when
666 calling @command{configure}.  Also the file @file{README} will be
667 installed into @var{docdir}, which defaults to
668 @file{/usr/local/share/doc/amhello}.
670 @opindex --prefix
672 A user who wishes to install a package on his own account could proceed
673 as follows:
675 @example
676 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
677 @dots{}
678 ~/amhello-1.0 % @kbd{make}
679 @dots{}
680 ~/amhello-1.0 % @kbd{make install}
681 @dots{}
682 @end example
684 This would install @file{~/usr/bin/hello} and
685 @file{~/usr/share/doc/amhello/README}.
687 The list of all such directory options is shown by
688 @code{./configure --help}.
690 @node Standard Configuration Variables
691 @subsection Standard Configuration Variables
692 @cindex configuration variables, overriding
694 The GNU Coding Standards also define a set of standard configuration
695 variables used during the build.  Here are some:
697 @table @asis
698 @item @code{CC}
699 C compiler command
700 @item @code{CFLAGS}
701 C compiler flags
702 @item @code{CXX}
703 C++ compiler command
704 @item @code{CXXFLAGS}
705 C++ compiler flags
706 @item @code{LDFLAGS}
707 linker flags
708 @item @code{CPPFLAGS}
709 C/C++ preprocessor flags
710 @item @dots{}
711 @end table
713 @command{configure} usually does a good job at setting appropriate
714 values for these variables, but there are cases where you may want to
715 override them.  For instance you may have several versions of a
716 compiler installed and would like to use another one, you may have
717 header files installed outside the default search path of the
718 compiler, or even libraries out of the way of the linker.
720 Here is how one would call @command{configure} to force it to use
721 @command{gcc-3} as C compiler, use header files from
722 @file{~/usr/include} when compiling, and libraries from
723 @file{~/usr/lib} when linking.
725 @example
726 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
727 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
728 @end example
730 Again, a full list of these variables appears in the output of
731 @code{./configure --help}.
733 @node config.site
734 @subsection Overriding Default Configuration Setting with @file{config.site}
735 @cindex @file{config.site} example
737 When installing several packages using the same setup, it can be
738 convenient to create a file to capture common settings.
739 If a file named @file{@var{prefix}/share/config.site} exists,
740 @command{configure} will source it at the beginning of its execution.
742 Recall the command from the previous section:
744 @example
745 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
746 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
747 @end example
749 Assuming we are installing many package in @file{~/usr}, and will
750 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
751 @code{LDFLAGS}, we can automate this by creating the following
752 @file{~/usr/share/config.site} file:
754 @example
755 test -z "$CC" && CC=gcc-3
756 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
757 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
758 @end example
760 Now, any time a @file{configure} script is using the @file{~/usr}
761 prefix, it will execute the above @file{config.site} and define
762 these three variables.
764 @example
765 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
766 configure: loading site script /home/adl/usr/share/config.site
767 @dots{}
768 @end example
770 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
771 Manual}, for more information about this feature.
774 @node VPATH Builds
775 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
776 @cindex Parallel build trees
777 @cindex VPATH builds
778 @cindex source tree and build tree
779 @cindex build tree and source tree
780 @cindex trees, source vs.@: build
782 The GNU Build System distinguishes two trees: the source tree, and
783 the build tree.
785 The source tree is rooted in the directory containing
786 @file{configure}.  It contains all the sources files (those that are
787 distributed), and may be arranged using several subdirectories.
789 The build tree is rooted in the directory in which @file{configure}
790 was run, and is populated with all object files, programs, libraries,
791 and other derived files built from the sources (and hence not
792 distributed).  The build tree usually has the same subdirectory layout
793 as the source tree; its subdirectories are created automatically by
794 the build system.
796 If @file{configure} is executed in its own directory, the source and
797 build trees are combined: derived files are constructed in the same
798 directories as their sources.  This was the case in our first
799 installation example (@pxref{Basic Installation}).
801 A common request from users is that they want to confine all derived
802 files to a single directory, to keep their source directories
803 uncluttered.  Here is how we could run @file{configure} to build
804 everything in a subdirectory called @file{build/}.
806 @example
807 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
808 ~ % @kbd{cd amhello-1.0}
809 ~/amhello-1.0 % @kbd{mkdir build && cd build}
810 ~/amhello-1.0/build % @kbd{../configure}
811 @dots{}
812 ~/amhello-1.0/build % @kbd{make}
813 @dots{}
814 @end example
816 These setups, where source and build trees are different, are often
817 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
818 @emph{parallel build} is misleading: the word @emph{parallel} is a
819 reference to the way the build tree shadows the source tree, it is not
820 about some concurrency in the way build commands are run.  For this
821 reason we refer to such setups using the name @emph{VPATH builds} in
822 the following.  @emph{VPATH} is the name of the @command{make} feature
823 used by the @file{Makefile}s to allow these builds (@pxref{General
824 Search, , @code{VPATH}: Search Path for All Prerequisites, make, The
825 GNU Make Manual}).
827 @cindex multiple configurations, example
828 @cindex debug build, example
829 @cindex optimized build, example
831 VPATH builds have other interesting uses.  One is to build the same
832 sources with multiple configurations.  For instance:
834 @example
835 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
836 ~ % @kbd{cd amhello-1.0}
837 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
838 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
839 @dots{}
840 ~/amhello-1.0/debug % @kbd{make}
841 @dots{}
842 ~/amhello-1.0/debug % cd ../optim
843 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
844 @dots{}
845 ~/amhello-1.0/optim % @kbd{make}
846 @dots{}
847 @end example
849 With network file systems, a similar approach can be used to build the
850 same sources on different machines.  For instance, suppose that the
851 sources are installed on a directory shared by two hosts: @code{HOST1}
852 and @code{HOST2}, which may be different platforms.
854 @example
855 ~ % @kbd{cd /nfs/src}
856 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
857 @end example
859 On the first host, you could create a local build directory:
860 @example
861 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
862 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
864 [HOST1] /tmp/amh % @kbd{make && sudo make install}
866 @end example
868 @noindent
869 (Here we assume the that installer has configured @command{sudo} so it
870 can execute @code{make install} with root privileges; it is more convenient
871 than using @command{su} like in @ref{Basic Installation}).
873 On the second host, you would do exactly the same, possibly at
874 the same time:
875 @example
876 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
877 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
879 [HOST2] /tmp/amh % @kbd{make && sudo make install}
881 @end example
883 @cindex read-only source tree
884 @cindex source tree, read-only
886 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
887 directory from being read-only.  In fact VPATH builds are also a means
888 of building packages from a read-only medium such as a CD-ROM.  (The
889 FSF used to sell CD-ROM with unpacked source code, before the GNU
890 project grew so big.)
892 @node Two-Part Install
893 @subsection Two-Part Installation
895 In our last example (@pxref{VPATH Builds}), a source tree was shared
896 by two hosts, but compilation and installation were done separately on
897 each host.
899 The GNU Build System also supports networked setups where part of the
900 installed files should be shared amongst multiple hosts.  It does so
901 by distinguishing architecture-dependent files from
902 architecture-independent files, and providing two @file{Makefile}
903 targets to install each of these classes of files.
905 @trindex install-exec
906 @trindex install-data
908 These targets are @code{install-exec} for architecture-dependent files
909 and @code{install-data} for architecture-independent files.
910 The command we used up to now, @code{make install}, can be thought of
911 as a shorthand for @code{make install-exec install-data}.
913 From the GNU Build System point of view, the distinction between
914 architecture-dependent files and architecture-independent files is
915 based exclusively on the directory variable used to specify their
916 installation destination.  In the list of directory variables we
917 provided earlier (@pxref{Standard Directory Variables}), all the
918 variables based on @var{exec-prefix} designate architecture-dependent
919 directories whose files will be installed by @code{make install-exec}.
920 The others designate architecture-independent directories and will
921 serve files installed by @code{make install-data}.  @xref{Install},
922 for more details.
924 Here is how we could revisit our two-host installation example,
925 assuming that (1) we want to install the package directly in
926 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
927 two hosts.
929 On the first host we would run
930 @example
931 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
932 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
934 [HOST1] /tmp/amh % @kbd{make && sudo make install}
936 @end example
938 On the second host, however, we need only install the
939 architecture-specific files.
940 @example
941 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
942 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
944 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
946 @end example
948 In packages that have installation checks, it would make sense to run
949 @code{make installcheck} (@pxref{Basic Installation}) to verify that
950 the package works correctly despite the apparent partial installation.
952 @node Cross-Compilation
953 @subsection Cross-Compilation
954 @cindex cross-compilation
956 To @dfn{cross-compile} is to build on one platform a binary that will
957 run on another platform.  When speaking of cross-compilation, it is
958 important to distinguish between the @dfn{build platform} on which
959 the compilation is performed, and the @dfn{host platform} on which the
960 resulting executable is expected to run.  The following
961 @command{configure} options are used to specify each of them:
963 @table @option
964 @item --build=@var{BUILD}
965 @opindex --build=@var{BUILD}
966 The system on which the package is built.
967 @item --host=@var{HOST}
968 @opindex --host=@var{HOST}
969 The system where built programs and libraries will run.
970 @end table
972 When the @option{--host} is used, @command{configure} will search for
973 the cross-compiling suite for this platform.  Cross-compilation tools
974 commonly have their target architecture as prefix of their name.  For
975 instance my cross-compiler for MinGW32 has its binaries called
976 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
977 @code{i586-mingw32msvc-as}, etc.
979 @cindex MinGW cross-compilation example
980 @cindex cross-compilation example
982 Here is how we could build @code{amhello-1.0} for
983 @code{i586-mingw32msvc} on a GNU/Linux PC.
985 @smallexample
986 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
987 checking for a BSD-compatible install... /usr/bin/install -c
988 checking whether build environment is sane... yes
989 checking for gawk... gawk
990 checking whether make sets $(MAKE)... yes
991 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
992 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
993 checking for C compiler default output file name... a.exe
994 checking whether the C compiler works... yes
995 checking whether we are cross compiling... yes
996 checking for suffix of executables... .exe
997 checking for suffix of object files... o
998 checking whether we are using the GNU C compiler... yes
999 checking whether i586-mingw32msvc-gcc accepts -g... yes
1000 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1001 @dots{}
1002 ~/amhello-1.0 % @kbd{make}
1003 @dots{}
1004 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1005 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1006 @end smallexample
1008 The @option{--host} and @option{--build} options are usually all we
1009 need for cross-compiling.  The only exception is if the package being
1010 built is itself a cross-compiler: we need a third option to specify
1011 its target architecture.
1013 @table @option
1014 @item --target=@var{TARGET}
1015 @opindex --target=@var{TARGET}
1016 When building compiler tools: the system for which the tools will
1017 create output.
1018 @end table
1020 For instance when installing GCC, the GNU Compiler Collection, we can
1021 use @option{--target=@var{TARGET}} to specify that we want to build
1022 GCC as a cross-compiler for @var{TARGET}.  Mixing @option{--build} and
1023 @option{--target}, we can actually cross-compile a cross-compiler;
1024 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1026 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1027 Autoconf Manual}, for more information about these @command{configure}
1028 options.
1030 @node Renaming
1031 @subsection Renaming Programs at Install Time
1032 @cindex Renaming programs
1033 @cindex Transforming program names
1034 @cindex Programs, renaming during installation
1036 The GNU Build System provides means to automatically rename
1037 executables and manpages before they are installed (@pxref{Man pages}).
1038 This is especially convenient
1039 when installing a GNU package on a system that already has a
1040 proprietary implementation you do not want to overwrite.  For instance,
1041 you may want to install GNU @command{tar} as @command{gtar} so you can
1042 distinguish it from your vendor's @command{tar}.
1044 This can be done using one of these three @command{configure} options.
1046 @table @option
1047 @item --program-prefix=@var{PREFIX}
1048 @opindex --program-prefix=@var{PREFIX}
1049 Prepend @var{PREFIX} to installed program names.
1050 @item --program-suffix=@var{SUFFIX}
1051 @opindex --program-suffix=@var{SUFFIX}
1052 Append @var{SUFFIX} to installed program names.
1053 @item --program-transform-name=@var{PROGRAM}
1054 @opindex --program-transform-name=@var{PROGRAM}
1055 Run @code{sed @var{PROGRAM}} on installed program names.
1056 @end table
1058 The following commands would install @file{hello}
1059 as @file{/usr/local/bin/test-hello}, for instance.
1061 @example
1062 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1063 @dots{}
1064 ~/amhello-1.0 % @kbd{make}
1065 @dots{}
1066 ~/amhello-1.0 % @kbd{sudo make install}
1067 @dots{}
1068 @end example
1070 @node DESTDIR
1071 @subsection Building Binary Packages Using DESTDIR
1072 @vindex DESTDIR
1074 The GNU Build System's @code{make install} and @code{make uninstall}
1075 interface does not exactly fit the needs of a system administrator
1076 who has to deploy and upgrade packages on lots of hosts.  In other
1077 words, the GNU Build System does not replace a package manager.
1079 Such package managers usually need to know which files have been
1080 installed by a package, so a mere @code{make install} is
1081 inappropriate.
1083 @cindex Staged installation
1085 The @code{DESTDIR} variable can be used to perform a staged
1086 installation.  The package should be configured as if it was going to
1087 be installed in its final location (e.g., @code{--prefix /usr}), but
1088 when running @code{make install}, the @code{DESTDIR} should be set to
1089 the absolute name of a directory into which the installation will be
1090 diverted.  From this directory it is easy to review which files are
1091 being installed where, and finally copy them to their final location
1092 by some means.
1094 @cindex Binary package
1096 For instance here is how we could create a binary package containing a
1097 snapshot of all the files to be installed.
1099 @example
1100 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1101 @dots{}
1102 ~/amhello-1.0 % @kbd{make}
1103 @dots{}
1104 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1105 @dots{}
1106 ~/amhello-1.0 % @kbd{cd ~/inst}
1107 ~/inst % @kbd{find . -type f -print > ../files.lst}
1108 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../file.lst`}
1109 ./usr/bin/hello
1110 ./usr/share/doc/amhello/README
1111 @end example
1113 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1114 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../file.lst`}
1115 instead of @samp{.} as argument for @command{tar} avoids entries for
1116 each subdirectory in the archive: we would not like @command{tar} to
1117 restore the modification time of @file{/}, @file{/usr/}, etc.)
1119 Note that when building packages for several architectures, it might
1120 be convenient to use @code{make install-data} and @code{make
1121 install-exec} (@pxref{Two-Part Install}) to gather
1122 architecture-independent files in a single package.
1124 @xref{Install}, for more information.
1126 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1127 @c UNINSTALL counterparts.
1129 @node Preparing Distributions
1130 @subsection Preparing Distributions
1131 @cindex Preparing distributions
1132 @cindex Packages, preparation
1133 @cindex Distributions, preparation
1135 We have already mentioned @code{make dist}.  This target collects all
1136 your source files and the necessary parts of the build system to
1137 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1139 @cindex @code{distcheck} better than @code{dist}
1141 Another, more useful command is @code{make distcheck}.  The
1142 @code{distcheck} target constructs
1143 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1144 but it additionally ensures most of the use cases presented so far
1145 work:
1147 @itemize @bullet
1148 @item
1149 It attempts a full compilation of the package (@pxref{Basic
1150 Installation}), unpacking the newly constructed tarball, running
1151 @code{make}, @code{make check}, @code{make install}, as well as
1152 @code{make installcheck}, and even @code{make dist},
1153 @item
1154 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1155 @item
1156 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1157 uninstall} do not omit any file (@pxref{Standard Targets}),
1158 @item
1159 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1160 @end itemize
1162 All of these actions are performed in a temporary subdirectory, so
1163 that no root privileges are required.
1165 Releasing a package that fails @code{make distcheck} means that one of
1166 the scenarios we presented will not work and some users will be
1167 disappointed.  Therefore it is a good practice to release a package
1168 only after a successful @code{make distcheck}.  This of course does
1169 not imply that the package will be flawless, but at least it will
1170 prevent some of the embarrassing errors you may find in packages
1171 released by people who have never heard about @code{distcheck} (like
1172 @code{DESTDIR} not working because of a typo, or a distributed file
1173 being erased by @code{make clean}, or even @code{VPATH} builds not
1174 working).
1176 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1177 @code{make distcheck}.  @xref{Dist}, for more information about
1178 @code{distcheck}.
1180 @node Dependency Tracking
1181 @subsection Automatic Dependency Tracking
1182 @cindex Dependency tracking
1184 Dependency tracking is performed as a side-effect of compilation.
1185 Each time the build system compiles a source file, it computes its
1186 list of dependencies (in C these are the header files included by the
1187 source being compiled).  Later, any time @command{make} is run and a
1188 dependency appears to have changed, the dependent files will be
1189 rebuilt.
1191 When @command{configure} is executed, you can see it probing each
1192 compiler for the dependency mechanism it supports (several mechanisms
1193 can be used):
1195 @example
1196 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1197 @dots{}
1198 checking dependency style of gcc... gcc3
1199 @dots{}
1200 @end example
1202 Because dependencies are only computed as a side-effect of the
1203 compilation, no dependency information exists the first time a package
1204 is built.  This is OK because all the files need to be built anyway:
1205 @code{make} does not have to decide which files need to be rebuilt.
1206 In fact, dependency tracking is completely useless for one-time builds
1207 and there is a @command{configure} option to disable this:
1209 @table @option
1210 @item --disable-dependency-tracking
1211 @opindex --disable-dependency-tracking
1212 Speed up one-time builds.
1213 @end table
1215 Some compilers do not offer any practical way to derive the list of
1216 dependencies as a side-effect of the compilation, requiring a separate
1217 run (maybe of another tool) to compute these dependencies.  The
1218 performance penalty implied by these methods is important enough to
1219 disable them by default.  The option @option{--enable-dependency-tracking}
1220 must be passed to @command{configure} to activate them.
1222 @table @option
1223 @item --enable-dependency-tracking
1224 @opindex --enable-dependency-tracking
1225 Do not reject slow dependency extractors.
1226 @end table
1228 @xref{Dependency Tracking Evolution}, for some discussion about the
1229 different dependency tracking schemes used by Automake over the years.
1231 @node Nested Packages
1232 @subsection Nested Packages
1233 @cindex Nested packages
1234 @cindex Packages, nested
1235 @cindex Subpackages
1237 Although nesting packages isn't something we would recommend to
1238 someone who is discovering the Autotools, it is a nice feature worthy
1239 of mention in this small advertising tour.
1241 Autoconfiscated packages (that means packages whose build system have
1242 been created by Autoconf and friends) can be nested to arbitrary
1243 depth.
1245 A typical setup is that a package A will distribute one of the libraries
1246 it needs in a subdirectory.  This library B is a complete package with
1247 its own GNU Build System.  The @command{configure} script of A will
1248 run the @command{configure} script of B as part of its execution,
1249 building and installing A will also build and install B.  Generating a
1250 distribution for A will also include B.
1252 It is possible to gather several package like this.  GCC is a heavy
1253 user of this feature.  This gives installers a single package to
1254 configure, build and install, while it allows developers to work on
1255 subpackages independently.
1257 When configuring nested packages, the @command{configure} options
1258 given to the top-level @command{configure} are passed recursively to
1259 nested @command{configure}s.  A package that does not understand an
1260 option will ignore it, assuming it is meaningful to some other
1261 package.
1263 @opindex --help=recursive
1265 The command @code{configure --help=recursive} can be used to display
1266 the options supported by all the included packages.
1268 @xref{Subpackages}, for an example setup.
1270 @node Why Autotools
1271 @section How Autotools Help
1272 @cindex Autotools, purpose
1274 There are several reasons why you may not want to implement the GNU
1275 Build System yourself (read: write a @file{configure} script and
1276 @file{Makefile}s yourself).
1278 @itemize @bullet
1279 @item
1280 As we have seen, the GNU Build System has a lot of
1281 features (@pxref{Use Cases}).
1282 Some users may expect features you have not implemented because
1283 you did not need them.
1284 @item
1285 Implementing these features portably is difficult and exhausting.
1286 Think of writing portable shell scripts, and portable
1287 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1288 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1289 convince yourself.
1290 @item
1291 You will have to upgrade your setup to follow changes to the GNU
1292 Coding Standards.
1293 @end itemize
1295 The GNU Autotools take all this burden off your back and provide:
1297 @itemize @bullet
1298 @item
1299 Tools to create a portable, complete, and self-contained GNU Build
1300 System, from simple instructions.
1301 @emph{Self-contained} meaning the resulting build system does not
1302 require the GNU Autotools.
1303 @item
1304 A central place where fixes and improvements are made:
1305 a bug-fix for a portability issue will benefit every package.
1306 @end itemize
1308 Yet there also exist reasons why you may want NOT to use the
1309 Autotools@enddots{} For instance you may be already using (or used to)
1310 another incompatible build system.  Autotools will only be useful if
1311 you do accept the concepts of the GNU Build System.  People who have their
1312 own idea of how a build system should work will feel frustrated by the
1313 Autotools.
1315 @node Hello World
1316 @section A Small Hello World
1317 @cindex Example Hello World
1318 @cindex Hello World example
1319 @cindex @file{amhello-1.0.tar.gz}, creation
1321 In this section we recreate the @file{amhello-1.0} package from
1322 scratch.  The first subsection shows how to call the Autotools to
1323 instantiate the GNU Build System, while the second explains the
1324 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1325 by the Autotools.
1327 @menu
1328 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1329 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
1330 @end menu
1332 @node Creating amhello
1333 @subsection Creating @file{amhello-1.0.tar.gz}
1335 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1336 The package is simple enough so that we will only need to write 5
1337 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1338 that is distributed with Automake if you do not want to write them.)
1340 Create the following files in an empty directory.
1342 @itemize @bullet
1344 @item
1345 @file{src/main.c} is the source file for the @file{hello} program.  We
1346 store it in the @file{src/} subdirectory, because later, when the package
1347 evolves, it will ease the addition of a @file{man/} directory for man
1348 pages, a @file{data/} directory for data files, etc.
1349 @example
1350 ~/amhello % @kbd{cat src/main.c}
1351 #include <config.h>
1352 #include <stdio.h>
1355 main (void)
1357   puts ("Hello World!");
1358   puts ("This is " PACKAGE_STRING ".");
1359   return 0;
1361 @end example
1363 @item
1364 @file{README} contains some very limited documentation for our little
1365 package.
1366 @example
1367 ~/amhello % @kbd{cat README}
1368 This is a demonstration package for GNU Automake.
1369 Type `info Automake' to read the Automake manual.
1370 @end example
1372 @item
1373 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1374 instructions for these two directories.
1376 @example
1377 ~/amhello % @kbd{cat src/Makefile.am}
1378 bin_PROGRAMS = hello
1379 hello_SOURCES = main.c
1380 ~/amhello % @kbd{cat Makefile.am}
1381 SUBDIRS = src
1382 dist_doc_DATA = README
1383 @end example
1385 @item
1386 Finally, @file{configure.ac} contains Autoconf instructions to
1387 create the @command{configure} script.
1389 @example
1390 ~/amhello % @kbd{cat configure.ac}
1391 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1392 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1393 AC_PROG_CC
1394 AC_CONFIG_HEADERS([config.h])
1395 AC_CONFIG_FILES([
1396  Makefile
1397  src/Makefile
1399 AC_OUTPUT
1400 @end example
1401 @end itemize
1403 @cindex @command{autoreconf}, example
1405 Once you have these five files, it is time to run the Autotools to
1406 instantiate the build system.  Do this using the @command{autoreconf}
1407 command as follows:
1409 @example
1410 ~/amhello % @kbd{autoreconf --install}
1411 configure.ac: installing `./install-sh'
1412 configure.ac: installing `./missing'
1413 src/Makefile.am: installing `./depcomp'
1414 @end example
1416 At this point the build system is complete.
1418 In addition to the three scripts mentioned in its output, you can see
1419 that @command{autoreconf} created four other files: @file{configure},
1420 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1421 The latter three files are templates that will be adapted to the
1422 system by @command{configure} under the names @file{config.h},
1423 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1425 @example
1426 ~/amhello % @kbd{./configure}
1427 checking for a BSD-compatible install... /usr/bin/install -c
1428 checking whether build environment is sane... yes
1429 checking for gawk... no
1430 checking for mawk... mawk
1431 checking whether make sets $(MAKE)... yes
1432 checking for gcc... gcc
1433 checking for C compiler default output file name... a.out
1434 checking whether the C compiler works... yes
1435 checking whether we are cross compiling... no
1436 checking for suffix of executables...
1437 checking for suffix of object files... o
1438 checking whether we are using the GNU C compiler... yes
1439 checking whether gcc accepts -g... yes
1440 checking for gcc option to accept ISO C89... none needed
1441 checking for style of include used by make... GNU
1442 checking dependency style of gcc... gcc3
1443 configure: creating ./config.status
1444 config.status: creating Makefile
1445 config.status: creating src/Makefile
1446 config.status: creating config.h
1447 config.status: executing depfiles commands
1448 @end example
1450 @trindex distcheck
1451 @cindex @code{distcheck} example
1453 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1454 being created at the end after @command{configure} has probed the
1455 system.  It is now possible to run all the targets we wish
1456 (@pxref{Standard Targets}).  For instance:
1458 @example
1459 ~/amhello % @kbd{make}
1460 @dots{}
1461 ~/amhello % @kbd{src/hello}
1462 Hello World!
1463 This is amhello 1.0.
1464 ~/amhello % @kbd{make distcheck}
1465 @dots{}
1466 =============================================
1467 amhello-1.0 archives ready for distribution:
1468 amhello-1.0.tar.gz
1469 =============================================
1470 @end example
1472 Note that running @command{autoreconf} is only needed initially when
1473 the GNU Build System does not exist.  When you later change some
1474 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1475 relevant part of the build system will be regenerated automatically
1476 when you execute @command{make}.
1478 @command{autoreconf} is a script that calls @command{autoconf},
1479 @command{automake}, and a bunch of other commands in the right order.
1480 If you are beginning with these tools, it is not important to figure
1481 out in which order all these tools should be invoked and why.  However,
1482 because Autoconf and Automake have separate manuals, the important
1483 point to understand is that @command{autoconf} is in charge of
1484 creating @file{configure} from @file{configure.ac}, while
1485 @command{automake} is in charge of creating @file{Makefile.in}s from
1486 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1487 direct you to the right manual when seeking answers.
1490 @node amhello Explained
1491 @subsection @file{amhello-1.0} Explained
1493 Let us begin with the contents of @file{configure.ac}.
1495 @example
1496 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1497 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1498 AC_PROG_CC
1499 AC_CONFIG_HEADERS([config.h])
1500 AC_CONFIG_FILES([
1501  Makefile
1502  src/Makefile
1504 AC_OUTPUT
1505 @end example
1507 This file is read by both @command{autoconf} (to create
1508 @file{configure}) and @command{automake} (to create the various
1509 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1510 expanded as shell code to finally form the @file{configure} script.
1511 We will not elaborate on the syntax of this file, because the Autoconf
1512 manual has a whole section about it (@pxref{Writing configure.ac, ,
1513 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1515 The macros prefixed with @code{AC_} are Autoconf macros, documented
1516 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1517 Index, autoconf, The Autoconf Manual}).  The macros that start with
1518 @code{AM_} are Automake macros, documented later in this manual
1519 (@pxref{Macro Index}).
1521 The first two lines of @file{configure.ac} initialize Autoconf and
1522 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1523 its version number, and a contact address for bug-reports about the
1524 package (this address is output at the end of @code{./configure
1525 --help}, for instance).  When adapting this setup to your own package,
1526 by all means please do not blindly copy Automake's address: use the
1527 mailing list of your package, or your own mail address.
1529 @opindex -Wall
1530 @opindex -Werror
1531 @opindex foreign
1533 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1534 @command{automake} (@pxref{Options}).  @option{-Wall} and
1535 @option{-Werror} ask @command{automake} to turn on all warnings and
1536 report them as errors.  We are speaking of @strong{Automake} warnings
1537 here, such as dubious instructions in @file{Makefile.am}.  This has
1538 absolutely nothing to do with how the compiler will be called, even
1539 though it may support options with similar names.  Using @option{-Wall
1540 -Werror} is a safe setting when starting to work on a package: you do
1541 not want to miss any issues.  Later you may decide to relax things a
1542 bit.  The @option{foreign} option tells Automake that this package
1543 will not follow the GNU Standards.  GNU packages should always
1544 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1545 etc.  We do not want @command{automake} to complain about these
1546 missing files in our small example.
1548 The @code{AC_PROG_CC} line causes the @command{configure} script to
1549 search for a C compiler and define the variable @code{CC} with its
1550 name.  The @file{src/Makefile.in} file generated by Automake uses the
1551 variable @code{CC} to build @file{hello}, so when @command{configure}
1552 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1553 @code{CC} with the value it has found.  If Automake is asked to create
1554 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1555 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1557 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1558 @command{configure} script to create a @file{config.h} file gathering
1559 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1560 case, the @code{AC_INIT} macro already defined a few of them.  Here
1561 is an excerpt of @file{config.h} after @command{configure} has run:
1563 @smallexample
1564 @dots{}
1565 /* Define to the address where bug reports for this package should be sent. */
1566 #define PACKAGE_BUGREPORT "bug-automake@@gnu.org"
1568 /* Define to the full name and version of this package. */
1569 #define PACKAGE_STRING "amhello 1.0"
1570 @dots{}
1571 @end smallexample
1573 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1574 it can use @code{PACKAGE_STRING}.  In a real-world project,
1575 @file{config.h} can grow really big, with one @samp{#define} per
1576 feature probed on the system.
1578 The @code{AC_CONFIG_FILES} macro declares the list of files that
1579 @command{configure} should create from their @file{*.in} templates.
1580 Automake also scans this list to find the @file{Makefile.am} files it must
1581 process.  (This is important to remember: when adding a new directory
1582 to your project, you should add its @file{Makefile} to this list,
1583 otherwise Automake will never process the new @file{Makefile.am} you
1584 wrote in that directory.)
1586 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1587 produces the part of the script in charge of creating the files
1588 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1590 @cindex @command{autoscan}
1592 When starting a new project, we suggest you start with such a simple
1593 @file{configure.ac}, and gradually add the other tests it requires.
1594 The command @command{autoscan} can also suggest a few of the tests
1595 your package may need (@pxref{autoscan Invocation, , Using
1596 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1597 Autoconf Manual}).
1599 @cindex @file{Makefile.am}, Hello World
1601 We now turn to @file{src/Makefile.am}.  This file contains
1602 Automake instructions to build and install @file{hello}.
1604 @example
1605 bin_PROGRAMS = hello
1606 hello_SOURCES = main.c
1607 @end example
1609 A @file{Makefile.am} has the same syntax as an ordinary
1610 @file{Makefile}.  When @command{automake} processes a
1611 @file{Makefile.am} it copies the entire file into the output
1612 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1613 @command{configure}) but will react to certain variable definitions
1614 by generating some build rules and other variables.
1615 Often @file{Makefile.am}s contain only a list of variable definitions as
1616 above, but they can also contain other variable and rule definitions that
1617 @command{automake} will pass along without interpretation.
1619 Variables that end with @code{_PROGRAMS} are special variables
1620 that list programs that the resulting @file{Makefile} should build.
1621 In Automake speak, this @code{_PROGRAMS} suffix is called a
1622 @dfn{primary}; Automake recognizes other primaries such as
1623 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1624 to different types of files.
1626 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1627 @command{automake} that the resulting programs should be installed in
1628 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1629 to denote destination directories and allow users to customize these
1630 locations (@pxref{Standard Directory Variables}).  Any such directory
1631 variable can be put in front of a primary (omitting the @code{dir}
1632 suffix) to tell @command{automake} where to install the listed files.
1634 Programs need to be built from source files, so for each program
1635 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1636 @command{automake} will look for another variable named
1637 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1638 than one source file: they will all be compiled and linked together.
1640 Automake also knows that source files need to be distributed when
1641 creating a tarball (unlike built programs).  So a side-effect of this
1642 @code{hello_SOURCES} declaration is that @file{main.c} will be
1643 part of the tarball created by @code{make dist}.
1645 Finally here are some explanations regarding the top-level
1646 @file{Makefile.am}.
1648 @example
1649 SUBDIRS = src
1650 dist_doc_DATA = README
1651 @end example
1653 @code{SUBDIRS} is a special variable listing all directories that
1654 @command{make} should recurse into before processing the current
1655 directory.  So this line is responsible for @command{make} building
1656 @file{src/hello} even though we run it from the top-level.  This line
1657 also causes @code{make install} to install @file{src/hello} before
1658 installing @file{README} (not that this order matters).
1660 The line @code{dist_doc_DATA = README} causes @file{README} to be
1661 distributed and installed in @var{docdir}.  Files listed with the
1662 @code{_DATA} primary are not automatically part of the tarball built
1663 with @code{make dist}, so we add the @code{dist_} prefix so they get
1664 distributed.  However, for @file{README} it would not have been
1665 necessary: @command{automake} automatically distributes any
1666 @file{README} file it encounters (the list of other files
1667 automatically distributed is presented by @code{automake --help}).
1668 The only important effect of this second line is therefore to install
1669 @file{README} during @code{make install}.
1672 @node Generalities
1673 @chapter General ideas
1675 The following sections cover a few basic ideas that will help you
1676 understand how Automake works.
1678 @menu
1679 * General Operation::           General operation of Automake
1680 * Strictness::                  Standards conformance checking
1681 * Uniform::                     The Uniform Naming Scheme
1682 * Canonicalization::            How derived variables are named
1683 * User Variables::              Variables reserved for the user
1684 * Auxiliary Programs::          Programs automake might require
1685 @end menu
1688 @node General Operation
1689 @section General Operation
1691 Automake works by reading a @file{Makefile.am} and generating a
1692 @file{Makefile.in}.  Certain variables and rules defined in the
1693 @file{Makefile.am} instruct Automake to generate more specialized code;
1694 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1695 for compiling and linking programs to be generated.
1697 @cindex Non-standard targets
1698 @cindex @code{cvs-dist}, non-standard example
1699 @trindex cvs-dist
1700 @trindex git-dist
1702 The variable definitions and rules in the @file{Makefile.am} are
1703 copied verbatim into the generated file.  This allows you to add
1704 arbitrary code into the generated @file{Makefile.in}.  For instance,
1705 the Automake distribution includes a non-standard rule for the
1706 @code{git-dist} target, which the Automake maintainer uses to make
1707 distributions from his source control system.
1709 @cindex GNU make extensions
1711 Note that most GNU make extensions are not recognized by Automake.  Using
1712 such extensions in a @file{Makefile.am} will lead to errors or confusing
1713 behavior.
1715 @cindex Append operator
1716 @cmindex +=
1717 A special exception is that the GNU make append operator, @samp{+=}, is
1718 supported.  This operator appends its right hand argument to the variable
1719 specified on the left.  Automake will translate the operator into
1720 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1722 Automake tries to keep comments grouped with any adjoining rules or
1723 variable definitions.
1725 @cindex Make targets, overriding
1726 @cindex Make rules, overriding
1727 @cindex Overriding make rules
1728 @cindex Overriding make targets
1730 A rule defined in @file{Makefile.am} generally overrides any such
1731 rule of a similar name that would be automatically generated by
1732 @command{automake}.  Although this is a supported feature, it is generally
1733 best to avoid making use of it, as sometimes the generated rules are
1734 very particular.
1736 @cindex Variables, overriding
1737 @cindex Overriding make variables
1739 Similarly, a variable defined in @file{Makefile.am} or
1740 @code{AC_SUBST}ed from @file{configure.ac} will override any
1741 definition of the variable that @command{automake} would ordinarily
1742 create.  This feature is more often useful than the ability to
1743 override a rule.  Be warned that many of the variables generated by
1744 @command{automake} are considered to be for internal use only, and their
1745 names might change in future releases.
1747 @cindex Recursive operation of Automake
1748 @cindex Automake, recursive operation
1749 @cindex Example of recursive operation
1751 When examining a variable definition, Automake will recursively examine
1752 variables referenced in the definition.  For example, if Automake is
1753 looking at the content of @code{foo_SOURCES} in this snippet
1755 @example
1756 xs = a.c b.c
1757 foo_SOURCES = c.c $(xs)
1758 @end example
1760 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1761 contents of @code{foo_SOURCES}.
1763 @cindex @code{##} (special Automake comment)
1764 @cindex Special Automake comment
1765 @cindex Comment, special to Automake
1767 Automake also allows a form of comment that is @emph{not} copied into
1768 the output; all lines beginning with @samp{##} (leading spaces allowed)
1769 are completely ignored by Automake.
1771 It is customary to make the first line of @file{Makefile.am} read:
1773 @cindex Makefile.am, first line
1774 @cindex First line of Makefile.am
1776 @example
1777 ## Process this file with automake to produce Makefile.in
1778 @end example
1780 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1781 @c I don't know quite what to say.
1783 @c FIXME document customary ordering of Makefile.am here!
1786 @node Strictness
1787 @section Strictness
1789 @cindex Non-GNU packages
1791 While Automake is intended to be used by maintainers of GNU packages, it
1792 does make some effort to accommodate those who wish to use it, but do
1793 not want to use all the GNU conventions.
1795 @cindex Strictness, defined
1796 @cindex Strictness, @option{foreign}
1797 @cindex @option{foreign} strictness
1798 @cindex Strictness, @option{gnu}
1799 @cindex @option{gnu} strictness
1800 @cindex Strictness, @option{gnits}
1801 @cindex @option{gnits} strictness
1803 To this end, Automake supports three levels of @dfn{strictness}---the
1804 strictness indicating how stringently Automake should check standards
1805 conformance.
1807 The valid strictness levels are:
1809 @table @option
1810 @item foreign
1811 Automake will check for only those things that are absolutely
1812 required for proper operations.  For instance, whereas GNU standards
1813 dictate the existence of a @file{NEWS} file, it will not be required in
1814 this mode.  The name comes from the fact that Automake is intended to be
1815 used for GNU programs; these relaxed rules are not the standard mode of
1816 operation.
1818 @item gnu
1819 Automake will check---as much as possible---for compliance to the GNU
1820 standards for packages.  This is the default.
1822 @item gnits
1823 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1824 standards}.  These are based on the GNU standards, but are even more
1825 detailed.  Unless you are a Gnits standards contributor, it is
1826 recommended that you avoid this option until such time as the Gnits
1827 standard is actually published (which may never happen).
1828 @end table
1830 @xref{Gnits}, for more information on the precise implications of the
1831 strictness level.
1833 Automake also has a special ``cygnus'' mode that is similar to
1834 strictness but handled differently.  This mode is useful for packages
1835 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
1836 @xref{Cygnus}, for more information on this mode.
1839 @node Uniform
1840 @section The Uniform Naming Scheme
1842 @cindex Uniform naming scheme
1844 Automake variables generally follow a @dfn{uniform naming scheme} that
1845 makes it easy to decide how programs (and other derived objects) are
1846 built, and how they are installed.  This scheme also supports
1847 @command{configure} time determination of what should be built.
1849 @cindex @code{_PROGRAMS} primary variable
1850 @cindex @code{PROGRAMS} primary variable
1851 @cindex Primary variable, @code{PROGRAMS}
1852 @cindex Primary variable, defined
1853 @vindex _PROGRAMS
1855 At @command{make} time, certain variables are used to determine which
1856 objects are to be built.  The variable names are made of several pieces
1857 that are concatenated together.
1859 The piece that tells automake what is being built is commonly called
1860 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1861 list of programs that are to be compiled and linked.
1862 @vindex PROGRAMS
1864 @cindex @code{pkgdatadir}, defined
1865 @cindex @code{pkgincludedir}, defined
1866 @cindex @code{pkglibdir}, defined
1867 @cindex @code{pkglibexecdir}, defined
1869 @vindex pkgdatadir
1870 @vindex pkgincludedir
1871 @vindex pkglibdir
1872 @vindex pkglibexecdir
1874 @cindex @code{PACKAGE}, directory
1875 A different set of names is used to decide where the built objects
1876 should be installed.  These names are prefixes to the primary, and they
1877 indicate which standard directory should be used as the installation
1878 directory.  The standard directory names are given in the GNU standards
1879 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1880 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
1881 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
1882 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
1883 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
1885 @cindex @code{EXTRA_}, prepending
1886 For each primary, there is one additional variable named by prepending
1887 @samp{EXTRA_} to the primary name.  This variable is used to list
1888 objects that may or may not be built, depending on what
1889 @command{configure} decides.  This variable is required because Automake
1890 must statically know the entire list of objects that may be built in
1891 order to generate a @file{Makefile.in} that will work in all cases.
1893 @cindex @code{EXTRA_PROGRAMS}, defined
1894 @cindex Example, @code{EXTRA_PROGRAMS}
1895 @cindex @command{cpio} example
1897 For instance, @command{cpio} decides at configure time which programs
1898 should be built.  Some of the programs are installed in @code{bindir},
1899 and some are installed in @code{sbindir}:
1901 @example
1902 EXTRA_PROGRAMS = mt rmt
1903 bin_PROGRAMS = cpio pax
1904 sbin_PROGRAMS = $(MORE_PROGRAMS)
1905 @end example
1907 Defining a primary without a prefix as a variable, e.g.,
1908 @samp{PROGRAMS}, is an error.
1910 Note that the common @samp{dir} suffix is left off when constructing the
1911 variable names; thus one writes @samp{bin_PROGRAMS} and not
1912 @samp{bindir_PROGRAMS}.
1914 Not every sort of object can be installed in every directory.  Automake
1915 will flag those attempts it finds in error.
1916 Automake will also diagnose obvious misspellings in directory names.
1918 @cindex Extending list of installation directories
1919 @cindex Installation directories, extending list
1921 Sometimes the standard directories---even as augmented by
1922 Automake---are not enough.  In particular it is sometimes useful, for
1923 clarity, to install objects in a subdirectory of some predefined
1924 directory.  To this end, Automake allows you to extend the list of
1925 possible installation directories.  A given prefix (e.g., @samp{zar})
1926 is valid if a variable of the same name with @samp{dir} appended is
1927 defined (e.g., @samp{zardir}).
1929 For instance, the following snippet will install @file{file.xml} into
1930 @samp{$(datadir)/xml}.
1932 @example
1933 xmldir = $(datadir)/xml
1934 xml_DATA = file.xml
1935 @end example
1937 @cindex @samp{noinst_} primary prefix, definition
1938 @vindex noinst_
1940 The special prefix @samp{noinst_} indicates that the objects in question
1941 should be built but not installed at all.  This is usually used for
1942 objects required to build the rest of your package, for instance static
1943 libraries (@pxref{A Library}), or helper scripts.
1945 @cindex @samp{check_} primary prefix, definition
1946 @vindex check_
1948 The special prefix @samp{check_} indicates that the objects in question
1949 should not be built until the @samp{make check} command is run.  Those
1950 objects are not installed either.
1952 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
1953 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
1954 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
1955 @vindex PROGRAMS
1956 @vindex LIBRARIES
1957 @vindex LISP
1958 @vindex PYTHON
1959 @vindex JAVA
1960 @vindex SCRIPTS
1961 @vindex DATA
1962 @vindex HEADERS
1963 @vindex MANS
1964 @vindex TEXINFOS
1966 Some primaries also allow additional prefixes that control other
1967 aspects of @command{automake}'s behavior.  The currently defined prefixes
1968 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
1969 These prefixes are explained later (@pxref{Program and Library Variables})
1970 (@pxref{Man pages}).
1973 @node Canonicalization
1974 @section How derived variables are named
1976 @cindex canonicalizing Automake variables
1978 Sometimes a Makefile variable name is derived from some text the
1979 maintainer supplies.  For instance, a program name listed in
1980 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
1981 variable.  In cases like this, Automake canonicalizes the text, so that
1982 program names and the like do not have to follow Makefile variable naming
1983 rules.  All characters in the name except for letters, numbers, the
1984 strudel (@@), and the underscore are turned into underscores when making
1985 variable references.
1987 For example, if your program is named @file{sniff-glue}, the derived
1988 variable name would be @samp{sniff_glue_SOURCES}, not
1989 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
1990 @file{libmumble++.a} should be listed in the
1991 @samp{libmumble___a_SOURCES} variable.
1993 The strudel is an addition, to make the use of Autoconf substitutions in
1994 variable names less obfuscating.
1997 @node User Variables
1998 @section Variables reserved for the user
2000 @cindex variables, reserved for the user
2001 @cindex user variables
2003 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2004 for the use of the ``user''---the person building the package.  For
2005 instance, @code{CFLAGS} is one such variable.
2007 Sometimes package developers are tempted to set user variables such as
2008 @code{CFLAGS} because it appears to make their job easier.  However,
2009 the package itself should never set a user variable, particularly not
2010 to include switches that are required for proper compilation of the
2011 package.  Since these variables are documented as being for the
2012 package builder, that person rightfully expects to be able to override
2013 any of these variables at build time.
2015 To get around this problem, Automake introduces an automake-specific
2016 shadow variable for each user flag variable.  (Shadow variables are
2017 not introduced for variables like @code{CC}, where they would make no
2018 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2019 user variable's name.  For instance, the shadow variable for
2020 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2021 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2022 files---may adjust these shadow variables however necessary.
2024 @xref{Flag Variables Ordering}, for more discussion about these
2025 variables and how they interact with per-target variables.
2027 @node Auxiliary Programs
2028 @section Programs automake might require
2030 @cindex Programs, auxiliary
2031 @cindex Auxiliary programs
2033 Automake sometimes requires helper programs so that the generated
2034 @file{Makefile} can do its work properly.  There are a fairly large
2035 number of them, and we list them here.
2037 Although all of these files are distributed and installed with
2038 Automake, a couple of them are maintained separately.  The Automake
2039 copies are updated before each release, but we mention the original
2040 source in case you need more recent versions.
2042 @table @code
2043 @item ansi2knr.c
2044 @itemx ansi2knr.1
2045 These two files are used by the obsolete de-ANSI-fication support
2046 (@pxref{ANSI}).
2048 @item compile
2049 This is a wrapper for compilers that do not accept options @option{-c}
2050 and @option{-o} at the same time.  It is only used when absolutely
2051 required.  Such compilers are rare.
2053 @item config.guess
2054 @itemx config.sub
2055 These two programs compute the canonical triplets for the given build,
2056 host, or target architecture.  These programs are updated regularly to
2057 support new architectures and fix probes broken by changes in new
2058 kernel versions.  Each new release of Automake comes with up-to-date
2059 copies of these programs.  If your copy of Automake is getting old,
2060 you are encouraged to fetch the latest versions of these files from
2061 @url{http://savannah.gnu.org/cvs/?group=config} before making a
2062 release.
2064 @item config-ml.in
2065 This file is not a program, it is a @file{configure} fragment used for
2066 multilib support (@pxref{Multilibs}).  This file is maintained in the
2067 GCC tree at @url{http://gcc.gnu.org/svn.html}.
2069 @item depcomp
2070 This program understands how to run a compiler so that it will
2071 generate not only the desired output but also dependency information
2072 that is then used by the automatic dependency tracking feature
2073 (@pxref{Dependencies}).
2075 @item elisp-comp
2076 This program is used to byte-compile Emacs Lisp code.
2078 @item install-sh
2079 This is a replacement for the @command{install} program that works on
2080 platforms where @command{install} is unavailable or unusable.
2082 @item mdate-sh
2083 This script is used to generate a @file{version.texi} file.  It examines
2084 a file and prints some date information about it.
2086 @item missing
2087 This wraps a number of programs that are typically only required by
2088 maintainers.  If the program in question doesn't exist,
2089 @command{missing} prints an informative warning and attempts to fix
2090 things so that the build can continue.
2092 @item mkinstalldirs
2093 This script used to be a wrapper around @samp{mkdir -p}, which is not
2094 portable.  Now we prefer to use @samp{install-sh -d} when configure
2095 finds that @samp{mkdir -p} does not work, this makes one less script to
2096 distribute.
2098 For backward compatibility @file{mkinstalldirs} is still used and
2099 distributed when @command{automake} finds it in a package.  But it is no
2100 longer installed automatically, and it should be safe to remove it.
2102 @item py-compile
2103 This is used to byte-compile Python scripts.
2105 @item symlink-tree
2106 This program duplicates a tree of directories, using symbolic links
2107 instead of copying files.  Such operation is performed when building
2108 multilibs (@pxref{Multilibs}).  This file is maintained in the GCC
2109 tree at @url{http://gcc.gnu.org/svn.html}.
2111 @item texinfo.tex
2112 Not a program, this file is required for @samp{make dvi}, @samp{make
2113 ps} and @samp{make pdf} to work when Texinfo sources are in the
2114 package.  The latest version can be downloaded from
2115 @url{http://www.gnu.org/software/texinfo/}.
2117 @item ylwrap
2118 This program wraps @command{lex} and @command{yacc} to rename their
2119 output files.  It also ensures that, for instance, multiple
2120 @command{yacc} instances can be invoked in a single directory in
2121 parallel.
2123 @end table
2126 @node Examples
2127 @chapter Some example packages
2129 This section contains two small examples.
2131 The first example (@pxref{Complete}) assumes you have an existing
2132 project already using Autoconf, with handcrafted @file{Makefile}s, and
2133 that you want to convert it to using Automake.  If you are discovering
2134 both tools, it is probably better that you look at the Hello World
2135 example presented earlier (@pxref{Hello World}).
2137 The second example (@pxref{true}) shows how two programs can be built
2138 from the same file, using different compilation parameters.  It
2139 contains some technical digressions that are probably best skipped on
2140 first read.
2142 @menu
2143 * Complete::                    A simple example, start to finish
2144 * true::                        Building true and false
2145 @end menu
2148 @node Complete
2149 @section A simple example, start to finish
2151 @cindex Complete example
2153 Let's suppose you just finished writing @code{zardoz}, a program to make
2154 your head float from vortex to vortex.  You've been using Autoconf to
2155 provide a portability framework, but your @file{Makefile.in}s have been
2156 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2158 @cindex @code{AM_INIT_AUTOMAKE}, example use
2160 The first step is to update your @file{configure.ac} to include the
2161 commands that @command{automake} needs.  The way to do this is to add an
2162 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2164 @example
2165 AC_INIT([zardoz], [1.0])
2166 AM_INIT_AUTOMAKE
2167 @dots{}
2168 @end example
2170 Since your program doesn't have any complicating factors (e.g., it
2171 doesn't use @code{gettext}, it doesn't want to build a shared library),
2172 you're done with this part.  That was easy!
2174 @cindex @command{aclocal} program, introduction
2175 @cindex @file{aclocal.m4}, preexisting
2176 @cindex @file{acinclude.m4}, defined
2178 Now you must regenerate @file{configure}.  But to do that, you'll need
2179 to tell @command{autoconf} how to find the new macro you've used.  The
2180 easiest way to do this is to use the @command{aclocal} program to
2181 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2182 already have an @file{aclocal.m4}, because you had to write some hairy
2183 macros for your program.  The @command{aclocal} program lets you put
2184 your own macros into @file{acinclude.m4}, so simply rename and then
2185 run:
2187 @example
2188 mv aclocal.m4 acinclude.m4
2189 aclocal
2190 autoconf
2191 @end example
2193 @cindex @command{zardoz} example
2195 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2196 Since @code{zardoz} is a user program, you want to install it where the
2197 rest of the user programs go: @code{bindir}.  Additionally,
2198 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2199 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2200 @samp{$(LIBOBJS)}.  So here's what you'd write:
2202 @example
2203 bin_PROGRAMS = zardoz
2204 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2205 zardoz_LDADD = $(LIBOBJS)
2207 info_TEXINFOS = zardoz.texi
2208 @end example
2210 Now you can run @samp{automake --add-missing} to generate your
2211 @file{Makefile.in} and grab any auxiliary files you might need, and
2212 you're done!
2215 @node true
2216 @section Building true and false
2218 @cindex Example, @command{false} and @command{true}
2219 @cindex @command{false} Example
2220 @cindex @command{true} Example
2222 Here is another, trickier example.  It shows how to generate two
2223 programs (@code{true} and @code{false}) from the same source file
2224 (@file{true.c}).  The difficult part is that each compilation of
2225 @file{true.c} requires different @code{cpp} flags.
2227 @example
2228 bin_PROGRAMS = true false
2229 false_SOURCES =
2230 false_LDADD = false.o
2232 true.o: true.c
2233         $(COMPILE) -DEXIT_CODE=0 -c true.c
2235 false.o: true.c
2236         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2237 @end example
2239 Note that there is no @code{true_SOURCES} definition.  Automake will
2240 implicitly assume that there is a source file named @file{true.c}, and
2241 define rules to compile @file{true.o} and link @file{true}.  The
2242 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2243 will override the Automake generated rule to build @file{true.o}.
2245 @code{false_SOURCES} is defined to be empty---that way no implicit value
2246 is substituted.  Because we have not listed the source of
2247 @file{false}, we have to tell Automake how to link the program.  This is
2248 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2249 variable, holding the dependencies of the @file{false} target will be
2250 automatically generated by Automake from the content of
2251 @code{false_LDADD}.
2253 The above rules won't work if your compiler doesn't accept both
2254 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2255 bogus dependency (to avoid problems with a parallel @command{make}):
2257 @example
2258 true.o: true.c false.o
2259         $(COMPILE) -DEXIT_CODE=0 -c true.c
2261 false.o: true.c
2262         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2263 @end example
2265 Also, these explicit rules do not work if the obsolete de-ANSI-fication feature
2266 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
2267 more work:
2269 @example
2270 true_.o: true_.c false_.o
2271         $(COMPILE) -DEXIT_CODE=0 -c true_.c
2273 false_.o: true_.c
2274         $(COMPILE) -DEXIT_CODE=1 -c true_.c && mv true_.o false_.o
2275 @end example
2277 As it turns out, there is also a much easier way to do this same task.
2278 Some of the above techniques are useful enough that we've kept the
2279 example in the manual.  However if you were to build @code{true} and
2280 @code{false} in real life, you would probably use per-program
2281 compilation flags, like so:
2283 @example
2284 bin_PROGRAMS = false true
2286 false_SOURCES = true.c
2287 false_CPPFLAGS = -DEXIT_CODE=1
2289 true_SOURCES = true.c
2290 true_CPPFLAGS = -DEXIT_CODE=0
2291 @end example
2293 In this case Automake will cause @file{true.c} to be compiled twice,
2294 with different flags.  De-ANSI-fication will work automatically.  In
2295 this instance, the names of the object files would be chosen by
2296 automake; they would be @file{false-true.o} and @file{true-true.o}.
2297 (The name of the object files rarely matters.)
2300 @node Invoking Automake
2301 @chapter Creating a @file{Makefile.in}
2303 @cindex Multiple @file{configure.ac} files
2304 @cindex Invoking @command{automake}
2305 @cindex @command{automake}, invoking
2307 To create all the @file{Makefile.in}s for a package, run the
2308 @command{automake} program in the top level directory, with no
2309 arguments.  @command{automake} will automatically find each
2310 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2311 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2312 Note that @command{automake} has a rather simplistic view of what
2313 constitutes a package; it assumes that a package has only one
2314 @file{configure.ac}, at the top.  If your package has multiple
2315 @file{configure.ac}s, then you must run @command{automake} in each
2316 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2317 on Autoconf's @command{autoreconf}, which is able to recurse your
2318 package tree and run @command{automake} where appropriate.)
2320 You can optionally give @command{automake} an argument; @file{.am} is
2321 appended to the argument and the result is used as the name of the
2322 input file.  This feature is generally only used to automatically
2323 rebuild an out-of-date @file{Makefile.in}.  Note that
2324 @command{automake} must always be run from the topmost directory of a
2325 project, even if being used to regenerate the @file{Makefile.in} in
2326 some subdirectory.  This is necessary because @command{automake} must
2327 scan @file{configure.ac}, and because @command{automake} uses the
2328 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2329 behavior in some cases.
2331 @vindex AUTOCONF
2332 Automake will run @command{autoconf} to scan @file{configure.ac} and
2333 its dependencies (i.e., @file{aclocal.m4} and any included file),
2334 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2335 an @env{AUTOCONF} variable in your environment it will be used
2336 instead of @command{autoconf}, this allows you to select a particular
2337 version of Autoconf.  By the way, don't misunderstand this paragraph:
2338 @command{automake} runs @command{autoconf} to @strong{scan} your
2339 @file{configure.ac}, this won't build @file{configure} and you still
2340 have to run @command{autoconf} yourself for this purpose.
2342 @cindex @command{automake} options
2343 @cindex Options, @command{automake}
2344 @cindex Strictness, command line
2346 @command{automake} accepts the following options:
2348 @cindex Extra files distributed with Automake
2349 @cindex Files distributed with Automake
2350 @cindex @file{config.guess}
2352 @table @code
2353 @item -a
2354 @itemx --add-missing
2355 @opindex -a
2356 @opindex --add-missing
2357 Automake requires certain common files to exist in certain situations;
2358 for instance, @file{config.guess} is required if @file{configure.ac} runs
2359 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2360 files (@pxref{Auxiliary Programs}); this option will cause the missing
2361 ones to be automatically added to the package, whenever possible.  In
2362 general if Automake tells you a file is missing, try using this option.
2363 By default Automake tries to make a symbolic link pointing to its own
2364 copy of the missing file; this can be changed with @option{--copy}.
2366 Many of the potentially-missing files are common scripts whose
2367 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2368 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2369 file is considered missing, and where the missing file is added
2370 (@pxref{Optional}).
2372 @item --libdir=@var{dir}
2373 @opindex --libdir
2374 Look for Automake data files in directory @var{dir} instead of in the
2375 installation directory.  This is typically used for debugging.
2377 @item -c
2378 @opindex -c
2379 @itemx --copy
2380 @opindex --copy
2381 When used with @option{--add-missing}, causes installed files to be
2382 copied.  The default is to make a symbolic link.
2384 @item --cygnus
2385 @opindex --cygnus
2386 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2387 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2389 @item -f
2390 @opindex -f
2391 @itemx --force-missing
2392 @opindex --force-missing
2393 When used with @option{--add-missing}, causes standard files to be reinstalled
2394 even if they already exist in the source tree.  This involves removing
2395 the file from the source tree before creating the new symlink (or, with
2396 @option{--copy}, copying the new file).
2398 @item --foreign
2399 @opindex --foreign
2400 Set the global strictness to @option{foreign}.  For more information, see
2401 @ref{Strictness}.
2403 @item --gnits
2404 @opindex --gnits
2405 Set the global strictness to @option{gnits}.  For more information, see
2406 @ref{Gnits}.
2408 @item --gnu
2409 @opindex --gnu
2410 Set the global strictness to @option{gnu}.  For more information, see
2411 @ref{Gnits}.  This is the default strictness.
2413 @item --help
2414 @opindex --help
2415 Print a summary of the command line options and exit.
2417 @item -i
2418 @itemx --ignore-deps
2419 @opindex -i
2420 This disables the dependency tracking feature in generated
2421 @file{Makefile}s; see @ref{Dependencies}.
2423 @item --include-deps
2424 @opindex --include-deps
2425 This enables the dependency tracking feature.  This feature is enabled
2426 by default.  This option is provided for historical reasons only and
2427 probably should not be used.
2429 @item --no-force
2430 @opindex --no-force
2431 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2432 @file{configure.ac}.  This option causes it to only update those
2433 @file{Makefile.in}s that are out of date with respect to one of their
2434 dependents.
2436 @item -o @var{dir}
2437 @itemx --output-dir=@var{dir}
2438 @opindex -o
2439 @opindex --output-dir
2440 Put the generated @file{Makefile.in} in the directory @var{dir}.
2441 Ordinarily each @file{Makefile.in} is created in the directory of the
2442 corresponding @file{Makefile.am}.  This option is deprecated and will be
2443 removed in a future release.
2445 @item -v
2446 @itemx --verbose
2447 @opindex -v
2448 @opindex --verbose
2449 Cause Automake to print information about which files are being read or
2450 created.
2452 @item --version
2453 @opindex --version
2454 Print the version number of Automake and exit.
2456 @item -W CATEGORY
2457 @item --warnings=@var{category}
2458 @opindex -W
2459 @opindex --warnings
2460 Output warnings falling in @var{category}.  @var{category} can be
2461 one of:
2462 @table @code
2463 @item gnu
2464 warnings related to the GNU Coding Standards
2465 (@pxref{Top, , , standards, The GNU Coding Standards}).
2466 @item obsolete
2467 obsolete features or constructions
2468 @item override
2469 user redefinitions of Automake rules or variables
2470 @item portability
2471 portability issues (e.g., use of @command{make} features that are
2472 known to be not portable)
2473 @item syntax
2474 weird syntax, unused variables, typos
2475 @item unsupported
2476 unsupported or incomplete features
2477 @item all
2478 all the warnings
2479 @item none
2480 turn off all the warnings
2481 @item error
2482 treat warnings as errors
2483 @end table
2485 A category can be turned off by prefixing its name with @samp{no-}.  For
2486 instance, @option{-Wno-syntax} will hide the warnings about unused
2487 variables.
2489 The categories output by default are @samp{syntax} and
2490 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2491 are enabled in @option{--gnu} and @option{--gnits} strictness.
2493 @vindex WARNINGS
2494 The environment variable @env{WARNINGS} can contain a comma separated
2495 list of categories to enable.  It will be taken into account before the
2496 command-line switches, this way @option{-Wnone} will also ignore any
2497 warning category enabled by @env{WARNINGS}.  This variable is also used
2498 by other tools like @command{autoconf}; unknown categories are ignored
2499 for this reason.
2501 @end table
2504 @node configure
2505 @chapter Scanning @file{configure.ac}
2507 @cindex @file{configure.ac}, scanning
2508 @cindex Scanning @file{configure.ac}
2510 Automake scans the package's @file{configure.ac} to determine certain
2511 information about the package.  Some @command{autoconf} macros are required
2512 and some variables must be defined in @file{configure.ac}.  Automake
2513 will also use information from @file{configure.ac} to further tailor its
2514 output.
2516 Automake also supplies some Autoconf macros to make the maintenance
2517 easier.  These macros can automatically be put into your
2518 @file{aclocal.m4} using the @command{aclocal} program.
2520 @menu
2521 * Requirements::                Configuration requirements
2522 * Optional::                    Other things Automake recognizes
2523 * Invoking aclocal::            Auto-generating aclocal.m4
2524 * Macros::                      Autoconf macros supplied with Automake
2525 @end menu
2528 @node Requirements
2529 @section Configuration requirements
2531 @cindex Automake requirements
2532 @cindex Requirements of Automake
2534 @acindex AM_INIT_AUTOMAKE
2535 The one real requirement of Automake is that your @file{configure.ac}
2536 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2537 required for proper Automake operation (@pxref{Macros}).
2539 Here are the other macros that Automake requires but which are not run
2540 by @code{AM_INIT_AUTOMAKE}:
2542 @table @code
2543 @item AC_CONFIG_FILES
2544 @itemx AC_OUTPUT
2545 @acindex AC_CONFIG_FILES
2546 @acindex AC_OUTPUT
2547 These two macros are usually invoked as follows near the end of
2548 @file{configure.ac}.
2550 @example
2551 @dots{}
2552 AC_CONFIG_FILES([
2553   Makefile
2554   doc/Makefile
2555   src/Makefile
2556   src/lib/Makefile
2557   @dots{}
2559 AC_OUTPUT
2560 @end example
2562 Automake uses these to determine which files to create (@pxref{Output, ,
2563 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2564 is considered to be an Automake generated @file{Makefile} if there
2565 exists a file with the same name and the @file{.am} extension appended.
2566 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2567 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2569 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2571 @example
2572 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2573 @end example
2575 @noindent
2576 @command{automake} will generate the first @file{.in} input file for
2577 which a @file{.am} file exists.  If no such file exists the output
2578 file is not considered to be Automake generated.
2580 Files created by @code{AC_CONFIG_FILES}, be they Automake
2581 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2582 Their inputs are automatically distributed, except for inputs that
2583 turn out the be outputs of prior @code{AC_CONFIG_FILES} commands.
2584 Finally, rebuild rules are generated in the Automake @file{Makefile}
2585 existing in the subdirectory of the output file, if there is one, or
2586 in the top-level @file{Makefile} otherwise.
2588 The above machinery (cleaning, distributing, and rebuilding) works
2589 fine if the @code{AC_CONFIG_FILES} specifications contain only
2590 literals.  If part of the specification uses shell variables,
2591 @command{automake} will not be able to fulfill this setup, and you will
2592 have to complete the missing bits by hand.  For instance, on
2594 @example
2595 file=input
2596 @dots{}
2597 AC_CONFIG_FILES([output:$file],, [file=$file])
2598 @end example
2600 @noindent
2601 @command{automake} will output rules to clean @file{output}, and
2602 rebuild it.  However the rebuild rule will not depend on @file{input},
2603 and this file will not be distributed either.  (You must add
2604 @samp{EXTRA_DIST = input} to your @file{Makefile} if @file{input} is a
2605 source file.)
2607 Similarly
2609 @example
2610 file=output
2611 file2=out:in
2612 @dots{}
2613 AC_CONFIG_FILES([$file:input],, [file=$file])
2614 AC_CONFIG_FILES([$file2],, [file2=$file2])
2615 @end example
2617 @noindent
2618 will only cause @file{input} to be distributed.  No file will be
2619 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2620 yourself), and no rebuild rule will be output.
2622 Obviously @command{automake} cannot guess what value @samp{$file} is
2623 going to hold later when @file{configure} is run, and it cannot use
2624 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2625 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2626 that is compatible with @command{make}'s syntax) and furthermore use
2627 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2628 @file{Makefile}, then @command{automake} will be able to use
2629 @samp{$@{file@}} to generate all these rules.  For instance, here is
2630 how the Automake package itself generates versioned scripts for its
2631 test suite:
2633 @example
2634 AC_SUBST([APIVERSION], @dots{})
2635 @dots{}
2636 AC_CONFIG_FILES(
2637   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2638   [chmod +x tests/aclocal-$@{APIVERSION@}],
2639   [APIVERSION=$APIVERSION])
2640 AC_CONFIG_FILES(
2641   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2642   [chmod +x tests/automake-$@{APIVERSION@}])
2643 @end example
2645 @noindent
2646 Here cleaning, distributing, and rebuilding are done automatically,
2647 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2649 Note that you should not use shell variables to declare
2650 @file{Makefile} files for which @command{automake} must create
2651 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2652 @command{automake} needs to know the file name when it runs in order
2653 to check whether @file{Makefile.am} exists.  (In the very hairy case
2654 that your setup requires such use of variables, you will have to tell
2655 Automake which @file{Makefile.in}s to generate on the command-line.)
2657 To summarize:
2658 @itemize @bullet
2659 @item
2660 Use literals for @file{Makefile}s, and for other files whenever possible.
2661 @item
2662 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2663 for files that @command{automake} should ignore.
2664 @item
2665 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2666 that @command{automake} should not ignore.
2667 @end itemize
2669 @end table
2672 @node Optional
2673 @section Other things Automake recognizes
2675 @cindex Macros Automake recognizes
2676 @cindex Recognized macros by Automake
2678 Every time Automake is run it calls Autoconf to trace
2679 @file{configure.ac}.  This way it can recognize the use of certain
2680 macros and tailor the generated @file{Makefile.in} appropriately.
2681 Currently recognized macros and their effects are:
2683 @ftable @code
2684 @item AC_CANONICAL_BUILD
2685 @itemx AC_CANONICAL_HOST
2686 @itemx AC_CANONICAL_TARGET
2687 @vindex build_triplet
2688 @vindex host_triplet
2689 @vindex target_triplet
2690 Automake will ensure that @file{config.guess} and @file{config.sub}
2691 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2692 @code{host_triplet} and @code{target_triplet} are introduced.  See
2693 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2694 The Autoconf Manual}.
2696 @item AC_CONFIG_AUX_DIR
2697 Automake will look for various helper scripts, such as
2698 @file{install-sh}, in the directory named in this macro invocation.
2699 @c This list is accurate relative to version 1.8
2700 (The full list of scripts is: @file{config.guess}, @file{config.sub},
2701 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
2702 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
2703 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
2704 scripts are always searched for; some scripts will only be sought if the
2705 generated @file{Makefile.in} requires them.
2707 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2708 their standard locations.  For @file{mdate-sh},
2709 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2710 source directory corresponding to the current @file{Makefile.am}.  For
2711 the rest, the standard location is the first one of @file{.}, @file{..},
2712 or @file{../..} (relative to the top source directory) that provides any
2713 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2714 autoconf, The Autoconf Manual}.
2716 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2717 distributed, even if there is no @file{Makefile.am} in this directory.
2719 @item AC_CONFIG_LIBOBJ_DIR
2720 Automake will require the sources file declared with
2721 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2722 macro.
2724 @item AC_CONFIG_HEADERS
2725 Automake will generate rules to rebuild these headers.  Older versions
2726 of Automake required the use of @code{AM_CONFIG_HEADER}
2727 (@pxref{Macros}); this is no longer the case today.
2729 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2730 specification using shell variables will be ignored as far as
2731 cleaning, distributing, and rebuilding is concerned.
2733 @item AC_CONFIG_LINKS
2734 Automake will generate rules to remove @file{configure} generated
2735 links on @samp{make distclean} and to distribute named source files as
2736 part of @samp{make dist}.
2738 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2739 specification using shell variables will be ignored as far as cleaning
2740 and distributing is concerned.  (There is no rebuild rules for links.)
2742 @item AC_LIBOBJ
2743 @itemx AC_LIBSOURCE
2744 @itemx AC_LIBSOURCES
2745 @vindex LIBOBJS
2746 Automake will automatically distribute any file listed in
2747 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2749 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2750 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2751 @file{file.c} will be distributed automatically by Automake.  This
2752 encompasses many macros like @code{AC_FUNC_ALLOCA},
2753 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2755 By the way, direct assignments to @code{LIBOBJS} are no longer
2756 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2757 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2758 autoconf, The Autoconf Manual}.
2760 @item AC_PROG_RANLIB
2761 This is required if any libraries are built in the package.
2762 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2763 Autoconf Manual}.
2765 @item AC_PROG_CXX
2766 This is required if any C++ source is included.  @xref{Particular
2767 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2769 @item AC_PROG_OBJC
2770 This is required if any Objective C source is included.  @xref{Particular
2771 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2773 @item AC_PROG_F77
2774 This is required if any Fortran 77 source is included.  This macro is
2775 distributed with Autoconf version 2.13 and later.  @xref{Particular
2776 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2778 @item AC_F77_LIBRARY_LDFLAGS
2779 This is required for programs and shared libraries that are a mixture of
2780 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
2781 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
2783 @item AC_FC_SRCEXT
2784 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
2785 of files with the respective source extension (@pxref{Fortran Compiler, ,
2786 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
2788 @item AC_PROG_FC
2789 This is required if any Fortran 90/95 source is included.  This macro is
2790 distributed with Autoconf version 2.58 and later.  @xref{Particular
2791 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2793 @item AC_PROG_LIBTOOL
2794 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
2795 Introduction, libtool, The Libtool Manual}).
2797 @item AC_PROG_YACC
2798 @vindex YACC
2799 If a Yacc source file is seen, then you must either use this macro or
2800 define the variable @code{YACC} in @file{configure.ac}.  The former is
2801 preferred (@pxref{Particular Programs, , Particular Program Checks,
2802 autoconf, The Autoconf Manual}).
2804 @item AC_PROG_LEX
2805 If a Lex source file is seen, then this macro must be used.
2806 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2807 Autoconf Manual}.
2809 @item AC_REQUIRE_AUX_FILE
2810 @command{automake} will ensure each file for which this macro is
2811 called exists in the aux directory, and will complain otherwise.  It
2812 will also automatically distribute the file.  This macro should be
2813 used by third-party Autoconf macros that requires some supporting
2814 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
2815 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
2816 The Autoconf Manual}.
2818 @item AC_SUBST
2819 The first argument is automatically defined as a variable in each
2820 generated @file{Makefile.in}.  @xref{Setting Output Variables, , Setting
2821 Output Variables, autoconf, The Autoconf Manual}.
2823 If the Autoconf manual says that a macro calls @code{AC_SUBST} for
2824 @var{var}, or defines the output variable @var{var} then @var{var} will
2825 be defined in each @file{Makefile.in} generated by Automake.
2826 E.g.@: @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and @code{X_LIBS}, so
2827 you can use these variables in any @file{Makefile.am} if
2828 @code{AC_PATH_XTRA} is called.
2830 @item AM_C_PROTOTYPES
2831 This is required when using the obsolete de-ANSI-fication feature; see
2832 @ref{ANSI}.
2834 @item AM_GNU_GETTEXT
2835 This macro is required for packages that use GNU gettext
2836 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
2837 this macro it ensures that the package meets some of gettext's
2838 requirements.
2840 @item AM_GNU_GETTEXT_INTL_SUBDIR
2841 This macro specifies that the @file{intl/} subdirectory is to be built,
2842 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
2843 of @samp{external}.
2845 @item AM_MAINTAINER_MODE
2846 @opindex --enable-maintainer-mode
2847 This macro adds a @option{--enable-maintainer-mode} option to
2848 @command{configure}.  If this is used, @command{automake} will cause
2849 ``maintainer-only'' rules to be turned off by default in the
2850 generated @file{Makefile.in}s.  This macro defines the
2851 @code{MAINTAINER_MODE} conditional, which you can use in your own
2852 @file{Makefile.am}.  @xref{maintainer-mode}.
2854 @item m4_include
2855 Files included by @file{configure.ac} using this macro will be
2856 detected by Automake and automatically distributed.  They will also
2857 appear as dependencies in @file{Makefile} rules.
2859 @code{m4_include} is seldom used by @file{configure.ac} authors, but
2860 can appear in @file{aclocal.m4} when @command{aclocal} detects that
2861 some required macros come from files local to your package (as opposed
2862 to macros installed in a system-wide directory, @pxref{Invoking
2863 aclocal}).
2865 @end ftable
2868 @node Invoking aclocal
2869 @section Auto-generating aclocal.m4
2871 @cindex Invoking @command{aclocal}
2872 @cindex @command{aclocal}, Invoking
2874 Automake includes a number of Autoconf macros that can be used in
2875 your package (@pxref{Macros}); some of them are actually required by
2876 Automake in certain situations.  These macros must be defined in your
2877 @file{aclocal.m4}; otherwise they will not be seen by
2878 @command{autoconf}.
2880 The @command{aclocal} program will automatically generate
2881 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
2882 This provides a convenient way to get Automake-provided macros,
2883 without having to search around.  The @command{aclocal} mechanism
2884 allows other packages to supply their own macros (@pxref{Extending
2885 aclocal}).  You can also use it to maintain your own set of custom
2886 macros (@pxref{Local Macros}).
2888 At startup, @command{aclocal} scans all the @file{.m4} files it can
2889 find, looking for macro definitions (@pxref{Macro search path}).  Then
2890 it scans @file{configure.ac}.  Any mention of one of the macros found
2891 in the first step causes that macro, and any macros it in turn
2892 requires, to be put into @file{aclocal.m4}.
2894 @emph{Putting} the file that contains the macro definition into
2895 @file{aclocal.m4} is usually done by copying the entire text of this
2896 file, including unused macro definitions as well as both @samp{#} and
2897 @samp{dnl} comments.  If you want to make a comment that will be
2898 completely ignored by @command{aclocal}, use @samp{##} as the comment
2899 leader.
2901 When a file selected by @command{aclocal} is located in a subdirectory
2902 specified as a relative search path with @command{aclocal}'s @option{-I}
2903 argument, @command{aclocal} assumes the file belongs to the package
2904 and uses @code{m4_include} instead of copying it into
2905 @file{aclocal.m4}.  This makes the package smaller, eases dependency
2906 tracking, and cause the file to be distributed automatically.
2907 (@xref{Local Macros}, for an example.)  Any macro that is found in a
2908 system-wide directory, or via an absolute search path will be copied.
2909 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
2910 some relative directory need to be considered outside the package.
2912 The contents of @file{acinclude.m4}, if this file exists, are also
2913 automatically included in @file{aclocal.m4}.  We recommend against
2914 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
2916 @vindex AUTOM4TE
2917 @cindex autom4te
2918 While computing @file{aclocal.m4}, @command{aclocal} runs
2919 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
2920 autoconf, The Autoconf Manual}) in order to trace the macros that are
2921 really used, and omit from @file{aclocal.m4} all macros that are
2922 mentioned but otherwise unexpanded (this can happen when a macro is
2923 called conditionally).  @command{autom4te} is expected to be in the
2924 @env{PATH}, just as @command{autoconf}.  Its location can be
2925 overridden using the @env{AUTOM4TE} environment variable.
2927 @menu
2928 * aclocal options::             Options supported by aclocal
2929 * Macro search path::           How aclocal finds .m4 files
2930 * Extending aclocal::           Writing your own aclocal macros
2931 * Local Macros::                Organizing local macros
2932 * Serials::                     Serial lines in Autoconf macros
2933 * Future of aclocal::           aclocal's scheduled death
2934 @end menu
2936 @node aclocal options
2937 @subsection aclocal options
2939 @cindex @command{aclocal}, Options
2940 @cindex Options, @command{aclocal}
2942 @command{aclocal} accepts the following options:
2944 @table @code
2945 @item --acdir=@var{dir}
2946 @opindex --acdir
2947 Look for the macro files in @var{dir} instead of the installation
2948 directory.  This is typically used for debugging.
2950 @item --diff[=@var{command}]
2951 @opindex --diff
2952 Run @var{command} on M4 file that would be installed or overwritten
2953 by @option{--install}.  The default @var{command} is @samp{diff -u}.
2954 This option implies @option{--install} and @option{--dry-run}.
2956 @item --dry-run
2957 @opindex --dry-run
2958 Do not actually overwrite (or create) @file{aclocal.m4} and M4
2959 files installed by @option{--install}.
2961 @item --help
2962 @opindex --help
2963 Print a summary of the command line options and exit.
2965 @item -I @var{dir}
2966 @opindex -I
2967 Add the directory @var{dir} to the list of directories searched for
2968 @file{.m4} files.
2970 @item --install
2971 @opindex --install
2972 Install system-wide third-party macros into the first directory
2973 specified with @samp{-I @var{dir}} instead of copying them in the
2974 output file.
2976 @cindex serial number and @option{--install}
2977 When this option is used, and only when this option is used,
2978 @command{aclocal} will also honor @samp{#serial @var{NUMBER}} lines
2979 that appear in macros: an M4 file is ignored if there exists another
2980 M4 file with the same basename and a greater serial number in the
2981 search path (@pxref{Serials}).
2983 @item --force
2984 @opindex --force
2985 Always overwrite the output file.  The default is to overwrite the output
2986 file only when really needed, i.e., when its contents changes or if one
2987 of its dependencies is younger.
2989 This option forces the update of @file{aclocal.m4} (or the file
2990 specified with @file{--output} below) and only this file, it has
2991 absolutely no influence on files that may need to be installed by
2992 @option{--install}.
2994 @item --output=@var{file}
2995 @opindex --output
2996 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
2998 @item --print-ac-dir
2999 @opindex --print-ac-dir
3000 Prints the name of the directory that @command{aclocal} will search to
3001 find third-party @file{.m4} files.  When this option is given, normal
3002 processing is suppressed.  This option can be used by a package to
3003 determine where to install a macro file.
3005 @item --verbose
3006 @opindex --verbose
3007 Print the names of the files it examines.
3009 @item --version
3010 @opindex --version
3011 Print the version number of Automake and exit.
3013 @item -W CATEGORY
3014 @item --warnings=@var{category}
3015 @opindex -W
3016 @opindex --warnings
3017 Output warnings falling in @var{category}.  @var{category} can be
3018 one of:
3019 @table @code
3020 @item syntax
3021 dubious syntactic constructs, underquoted macros, unused macros, etc.
3022 @item unsupported
3023 unknown macros
3024 @item all
3025 all the warnings, this is the default
3026 @item none
3027 turn off all the warnings
3028 @item error
3029 treat warnings as errors
3030 @end table
3032 All warnings are output by default.
3034 @vindex WARNINGS
3035 The environment variable @env{WARNINGS} is honored in the same
3036 way as it is for @command{automake} (@pxref{Invoking Automake}).
3038 @end table
3040 @node Macro search path
3041 @subsection Macro search path
3043 @cindex Macro search path
3044 @cindex @command{aclocal} search path
3046 By default, @command{aclocal} searches for @file{.m4} files in the following
3047 directories, in this order:
3049 @table @code
3050 @item @var{acdir-APIVERSION}
3051 This is where the @file{.m4} macros distributed with automake itself
3052 are stored.  @var{APIVERSION} depends on the automake release used;
3053 for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
3055 @item @var{acdir}
3056 This directory is intended for third party @file{.m4} files, and is
3057 configured when @command{automake} itself is built.  This is
3058 @file{@@datadir@@/aclocal/}, which typically
3059 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3060 value of @var{acdir}, use the @option{--print-ac-dir} option
3061 (@pxref{aclocal options}).
3062 @end table
3064 As an example, suppose that @command{automake-1.6.2} was configured with
3065 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3067 @enumerate
3068 @item @file{/usr/local/share/aclocal-1.6/}
3069 @item @file{/usr/local/share/aclocal/}
3070 @end enumerate
3072 As explained in (@pxref{aclocal options}), there are several options that
3073 can be used to change or extend this search path.
3075 @subsubsection Modifying the macro search path: @option{--acdir}
3077 The most erroneous option to modify the search path is
3078 @option{--acdir=@var{dir}}, which changes default directory and
3079 drops the @var{APIVERSION} directory.  For example, if one specifies
3080 @samp{--acdir=/opt/private/}, then the search path becomes:
3082 @enumerate
3083 @item @file{/opt/private/}
3084 @end enumerate
3086 This option, @option{--acdir}, is intended for use by the internal
3087 automake test suite only; it is not ordinarily needed by end-users.
3089 @subsubsection Modifying the macro search path: @samp{-I @var{dir}}
3091 Any extra directories specified using @option{-I} options
3092 (@pxref{aclocal options}) are @emph{prepended} to this search list.  Thus,
3093 @samp{aclocal -I /foo -I /bar} results in the following search path:
3095 @enumerate
3096 @item @file{/foo}
3097 @item @file{/bar}
3098 @item @var{acdir}-@var{APIVERSION}
3099 @item @var{acdir}
3100 @end enumerate
3102 @subsubsection Modifying the macro search path: @file{dirlist}
3103 @cindex @file{dirlist}
3105 There is a third mechanism for customizing the search path.  If a
3106 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3107 contain a list of directory patterns, one per line.  @command{aclocal}
3108 expands these patterns to directory names, and adds them to the search
3109 list @emph{after} all other directories.  @file{dirlist} entries may
3110 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3112 For example, suppose
3113 @file{@var{acdir}/dirlist} contains the following:
3115 @example
3116 /test1
3117 /test2
3118 /test3*
3119 @end example
3121 @noindent
3122 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3123 Then, the search path would be
3125 @c @code looks better than @file here
3126 @enumerate
3127 @item @code{/foo}
3128 @item @code{/bar}
3129 @item @var{acdir}-@var{APIVERSION}
3130 @item @var{acdir}
3131 @item @code{/test1}
3132 @item @code{/test2}
3133 @end enumerate
3135 @noindent
3136 and all directories with path names starting with @code{/test3}.
3138 If the @option{--acdir=@var{dir}} option is used, then @command{aclocal}
3139 will search for the @file{dirlist} file in @var{dir}.  In the
3140 @samp{--acdir=/opt/private/} example above, @command{aclocal} would look
3141 for @file{/opt/private/dirlist}.  Again, however, the @option{--acdir}
3142 option is intended for use by the internal automake test suite only;
3143 @option{--acdir} is not ordinarily needed by end-users.
3145 @file{dirlist} is useful in the following situation: suppose that
3146 @command{automake} version @code{1.6.2} is installed with
3147 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3148 directories are
3150 @c @code looks better than @file here
3151 @enumerate
3152 @item @code{/usr/share/aclocal-1.6/}
3153 @item @code{/usr/share/aclocal/}
3154 @end enumerate
3156 However, suppose further that many packages have been manually
3157 installed on the system, with $prefix=/usr/local, as is typical.  In
3158 that case, many of these ``extra'' @file{.m4} files are in
3159 @file{/usr/local/share/aclocal}.  The only way to force
3160 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3161 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3162 inconvenient.  With @file{dirlist}, one may create a file
3163 @file{/usr/share/aclocal/dirlist} containing only the single line
3165 @example
3166 /usr/local/share/aclocal
3167 @end example
3169 Now, the ``default'' search path on the affected system is
3171 @c @code looks better than @file here
3172 @enumerate
3173 @item @code{/usr/share/aclocal-1.6/}
3174 @item @code{/usr/share/aclocal/}
3175 @item @code{/usr/local/share/aclocal/}
3176 @end enumerate
3178 without the need for @option{-I} options; @option{-I} options can be reserved
3179 for project-specific needs (@file{my-source-dir/m4/}), rather than
3180 using it to work around local system-dependent tool installation
3181 directories.
3183 Similarly, @file{dirlist} can be handy if you have installed a local
3184 copy Automake on your account and want @command{aclocal} to look for
3185 macros installed at other places on the system.
3188 @node Extending aclocal
3189 @subsection Writing your own aclocal macros
3191 @cindex @command{aclocal}, extending
3192 @cindex Extending @command{aclocal}
3194 The @command{aclocal} program doesn't have any built-in knowledge of any
3195 macros, so it is easy to extend it with your own macros.
3197 This can be used by libraries that want to supply their own Autoconf
3198 macros for use by other programs.  For instance, the @command{gettext}
3199 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3200 any package using @command{gettext}.  When the library is installed, it
3201 installs this macro so that @command{aclocal} will find it.
3203 A macro file's name should end in @file{.m4}.  Such files should be
3204 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3206 @example
3207 aclocaldir = $(datadir)/aclocal
3208 aclocal_DATA = mymacro.m4 myothermacro.m4
3209 @end example
3211 @noindent
3212 Please do use @file{$(datadir)/aclocal}, and not something based on
3213 the result of @samp{aclocal --print-ac-dir}.  @xref{Hard-Coded Install
3214 Paths}, for arguments.
3216 A file of macros should be a series of properly quoted
3217 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3218 Autoconf Manual}).  The @command{aclocal} programs also understands
3219 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3220 Autoconf Manual}), so it is safe to put each macro in a separate file.
3221 Each file should have no side effects but macro definitions.
3222 Especially, any call to @code{AC_PREREQ} should be done inside the
3223 defined macro, not at the beginning of the file.
3225 @cindex underquoted @code{AC_DEFUN}
3226 @acindex AC_DEFUN
3227 @acindex AC_PREREQ
3229 Starting with Automake 1.8, @command{aclocal} will warn about all
3230 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3231 lot of people, because @command{aclocal} was not so strict in the past
3232 and many third party macros are underquoted; and we have to apologize
3233 for this temporary inconvenience.  The reason we have to be stricter
3234 is that a future implementation of @command{aclocal} (@pxref{Future of
3235 aclocal}) will have to temporarily include all these third party
3236 @file{.m4} files, maybe several times, including even files that are
3237 not actually needed.  Doing so should alleviate many problems of the
3238 current implementation, however it requires a stricter style from the
3239 macro authors.  Hopefully it is easy to revise the existing macros.
3240 For instance,
3241 @example
3242 # bad style
3243 AC_PREREQ(2.57)
3244 AC_DEFUN(AX_FOOBAR,
3245 [AC_REQUIRE([AX_SOMETHING])dnl
3246 AX_FOO
3247 AX_BAR
3249 @end example
3250 @noindent
3251 should be rewritten as
3252 @example
3253 AC_DEFUN([AX_FOOBAR],
3254 [AC_PREREQ([2.57])dnl
3255 AC_REQUIRE([AX_SOMETHING])dnl
3256 AX_FOO
3257 AX_BAR
3259 @end example
3261 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3262 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
3263 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3264 allows the macro to be redefined or included twice (otherwise this
3265 first argument would be expanded during the second definition).  For
3266 consistency we like to quote even arguments such as @code{2.57} that
3267 do not require it.
3269 If you have been directed here by the @command{aclocal} diagnostic but
3270 are not the maintainer of the implicated macro, you will want to
3271 contact the maintainer of that macro.  Please make sure you have the
3272 last version of the macro and that the problem already hasn't been
3273 reported before doing so: people tend to work faster when they aren't
3274 flooded by mails.
3276 Another situation where @command{aclocal} is commonly used is to
3277 manage macros that are used locally by the package, @ref{Local
3278 Macros}.
3280 @node Local Macros
3281 @subsection Handling Local Macros
3283 Feature tests offered by Autoconf do not cover all needs.  People
3284 often have to supplement existing tests with their own macros, or
3285 with third-party macros.
3287 There are two ways to organize custom macros in a package.
3289 The first possibility (the historical practice) is to list all your
3290 macros in @file{acinclude.m4}.  This file will be included in
3291 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3292 henceforth be visible to @command{autoconf}.  However if it contains
3293 numerous macros, it will rapidly become difficult to maintain, and it
3294 will be almost impossible to share macros between packages.
3296 @vindex ACLOCAL_AMFLAGS
3297 The second possibility, which we do recommend, is to write each macro
3298 in its own file and gather all these files in a directory.  This
3299 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3300 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3301 From the command line, this is done with @samp{aclocal -I m4}.  The
3302 top-level @file{Makefile.am} should also be updated to define
3304 @example
3305 ACLOCAL_AMFLAGS = -I m4
3306 @end example
3308 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3309 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3310 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3311 Using @command{autoreconf} to Update @file{configure} Scripts,
3312 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3313 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3314 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3315 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3316 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3317 the place where Gettext's macros should be installed.  So even if you
3318 do not really care about the rebuild rules, you should define
3319 @code{ACLOCAL_AMFLAGS}.
3321 When @samp{aclocal -I m4} is run, it will build a @file{aclocal.m4}
3322 that @code{m4_include}s any file from @file{m4/} that defines a
3323 required macro.  Macros not found locally will still be searched in
3324 system-wide directories, as explained in @ref{Macro search path}.
3326 Custom macros should be distributed for the same reason that
3327 @file{configure.ac} is: so that other people have all the sources of
3328 your package if they want to work on it.  Actually, this distribution
3329 happens automatically because all @code{m4_include}d files are
3330 distributed.
3332 However there is no consensus on the distribution of third-party
3333 macros that your package may use.  Many libraries install their own
3334 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3335 aclocal}).  For instance, Guile ships with a file called
3336 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3337 be used to define setup compiler and linker flags appropriate for
3338 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3339 cause @command{aclocal} to copy @file{guile.m4} into
3340 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3341 it will not be distributed.  Technically, that means a user who
3342 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3343 This is probably OK, if Guile already is a requirement to build the
3344 package.  However, if Guile is only an optional feature, or if your
3345 package might run on architectures where Guile cannot be installed,
3346 this requirement will hinder development.  An easy solution is to copy
3347 such third-party macros in your local @file{m4/} directory so they get
3348 distributed.
3350 Since Automake 1.10, @command{aclocal} offers an option to copy these
3351 system-wide third-party macros in your local macro directory, solving
3352 the above problem.  Simply use:
3354 @example
3355 ACLOCAL_AMFLAGS = -I m4 --install
3356 @end example
3358 @noindent
3359 With this setup, system-wide macros will be copied to @file{m4/}
3360 the first time you run @command{autoreconf}.  Then the locally
3361 installed macros will have precedence over the system-wide installed
3362 macros each time @command{aclocal} is run again.
3364 One reason why you should keep @option{--install} in the flags even
3365 after the first run is that when you later edit @file{configure.ac}
3366 and depend on a new macro, this macro will be installed in your
3367 @file{m4/} automatically.  Another one is that serial numbers
3368 (@pxref{Serials}) can be used to update the macros in your source tree
3369 automatically when new system-wide versions are installed.  A serial
3370 number should be a single line of the form
3372 @example
3373 #serial @var{NNN}
3374 @end example
3376 @noindent
3377 where @var{NNN} contains only digits and dots.  It should appear in
3378 the M4 file before any macro definition.  It is a good practice to
3379 maintain a serial number for each macro you distribute, even if you do
3380 not use the @option{--install} option of @command{aclocal}: this allows
3381 other people to use it.
3384 @node Serials
3385 @subsection Serial Numbers
3386 @cindex serial numbers in macros
3387 @cindex macro serial numbers
3388 @cindex @code{#serial} syntax
3389 @cindex @command{aclocal} and serial numbers
3391 Because third-party macros defined in @file{*.m4} files are naturally
3392 shared between multiple projects, some people like to version them.
3393 This makes it easier to tell which of two M4 files is newer.  Since at
3394 least 1996, the tradition is to use a @samp{#serial} line for this.
3396 A serial number should be a single line of the form
3398 @example
3399 # serial @var{version}
3400 @end example
3402 @noindent
3403 where @var{version} is a version number containing only digits and
3404 dots.  Usually people use a single integer, and they increment it each
3405 time they change the macro (hence the name of ``serial'').  Such a
3406 line should appear in the M4 file before any macro definition.
3408 The @samp{#} must be the first character on the line,
3409 and it is OK to have extra words after the version, as in
3411 @example
3412 #serial @var{version} @var{garbage}
3413 @end example
3415 Normally these serial numbers are completely ignored by
3416 @command{aclocal} and @command{autoconf}, like any genuine comment.
3417 However when using @command{aclocal}'s @option{--install} feature, these
3418 serial numbers will modify the way @command{aclocal} selects the
3419 macros to install in the package: if two files with the same basename
3420 exists in your search path, and if at least one of them use a
3421 @samp{#serial} line, @command{aclocal} will ignore the file that has
3422 the older @samp{#serial} line (or the file that has none).
3424 Note that a serial number applies to a whole M4 file, not to any macro
3425 it contains.  A file can contains multiple macros, but only one
3426 serial.
3428 Here is a use case that illustrate the use of @option{--install} and
3429 its interaction with serial numbers.  Let's assume we maintain a
3430 package called MyPackage, the @file{configure.ac} of which requires a
3431 third-party macro @code{AX_THIRD_PARTY} defined in
3432 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3434 @example
3435 # serial 1
3436 AC_DEFUN([AX_THIRD_PARTY], [...])
3437 @end example
3439 MyPackage uses an @file{m4/} directory to store local macros as
3440 explained in @ref{Local Macros}, and has
3442 @example
3443 ACLOCAL_AMFLAGS = -I m4 --install
3444 @end example
3446 @noindent
3447 in its top-level @file{Makefile.am}.
3449 Initially the @file{m4/} directory is empty.  The first time we run
3450 @command{autoreconf}, it will fetch the options to pass to
3451 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3452 --install}.  @command{aclocal} will notice that
3454 @itemize @bullet
3455 @item
3456 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3457 @item
3458 No local macros define @code{AX_THIRD_PARTY}
3459 @item
3460 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3461 with serial 1.
3462 @end itemize
3464 @noindent
3465 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3466 and @command{aclocal} was given the @option{--install} option, it will
3467 copy this file in @file{m4/thirdparty.m4}, and output an
3468 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3470 The next time @samp{aclocal -I m4 --install} is run (either via
3471 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3472 rules) something different happens.  @command{aclocal} notices that
3474 @itemize @bullet
3475 @item
3476 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3477 @item
3478 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3479 with serial 1.
3480 @item
3481 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3482 with serial 1.
3483 @end itemize
3485 @noindent
3486 Because both files have the same serial number, @command{aclocal} uses
3487 the first it found in its search path order (@pxref{Macro search
3488 path}).  @command{aclocal} therefore ignores
3489 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3490 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3492 Local directories specified with @option{-I} are always searched before
3493 system-wide directories, so a local file will always be preferred to
3494 the system-wide file in case of equal serial numbers.
3496 Now suppose the system-wide third-party macro is changed.  This can
3497 happen if the package installing this macro is updated.  Let's suppose
3498 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3499 --install} is run the situation is the following:
3501 @itemize @bullet
3502 @item
3503 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3504 @item
3505 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3506 with serial 1.
3507 @item
3508 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3509 with serial 2.
3510 @end itemize
3512 @noindent
3513 When @command{aclocal} sees a greater serial number, it immediately
3514 forgets anything it knows from files that have the same basename and a
3515 smaller serial number.  So after it has found
3516 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3517 @command{aclocal} will proceed as if it had never seen
3518 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3519 to that at the beginning of our example, where no local file defined
3520 the macro.  @command{aclocal} will install the new version of the
3521 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3522 version.  MyPackage just had its macro updated as a side effect of
3523 running @command{aclocal}.
3525 If you are leery of letting @command{aclocal} update your local macro,
3526 you can run @samp{aclocal -I m4 --diff} to review the changes
3527 @samp{aclocal -I m4 --install} would perform on these macros.
3529 Finally, note that the @option{--force} option of @command{aclocal} has
3530 absolutely no effect on the files installed by @option{--install}.  For
3531 instance, if you have modified your local macros, do not expect
3532 @option{--install --force} to replace the local macros by their
3533 system-wide versions.  If you want to do so, simply erase the local
3534 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3537 @node Future of aclocal
3538 @subsection The Future of @command{aclocal}
3539 @cindex @command{aclocal}'s scheduled death
3541 @command{aclocal} is expected to disappear.  This feature really
3542 should not be offered by Automake.  Automake should focus on
3543 generating @file{Makefile}s; dealing with M4 macros really is
3544 Autoconf's job.  That some people install Automake just to use
3545 @command{aclocal}, but do not use @command{automake} otherwise is an
3546 indication of how that feature is misplaced.
3548 The new implementation will probably be done slightly differently.
3549 For instance, it could enforce the @file{m4/}-style layout discussed in
3550 @ref{Local Macros}.
3552 We have no idea when and how this will happen.  This has been
3553 discussed several times in the past, but someone still has to commit
3554 itself to that non-trivial task.
3556 From the user point of view, @command{aclocal}'s removal might turn
3557 out to be painful.  There is a simple precaution that you may take to
3558 make that switch more seamless: never call @command{aclocal} yourself.
3559 Keep this guy under the exclusive control of @command{autoreconf} and
3560 Automake's rebuild rules.  Hopefully you won't need to worry about
3561 things breaking, when @command{aclocal} disappears, because everything
3562 will have been taken care of.  If otherwise you used to call
3563 @command{aclocal} directly yourself or from some script, you will
3564 quickly notice the change.
3566 Many packages come with a script called @file{bootstrap.sh} or
3567 @file{autogen.sh}, that will just call @command{aclocal},
3568 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3569 @command{autoconf}, @command{autoheader}, and @command{automake} in
3570 the right order.  Actually this is precisely what @command{autoreconf}
3571 can do for you.  If your package has such a @file{bootstrap.sh} or
3572 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3573 should simplify its logic a lot (less things to maintain, yum!), it's
3574 even likely you will not need the script anymore, and more to the point
3575 you will not call @command{aclocal} directly anymore.
3577 For the time being, third-party packages should continue to install
3578 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3579 is replaced by another tool it might make sense to rename the
3580 directory, but supporting @file{/usr/share/aclocal/} for backward
3581 compatibility should be really easy provided all macros are properly
3582 written (@pxref{Extending aclocal}).
3586 @node Macros
3587 @section Autoconf macros supplied with Automake
3589 Automake ships with several Autoconf macros that you can use from your
3590 @file{configure.ac}.  When you use one of them it will be included by
3591 @command{aclocal} in @file{aclocal.m4}.
3593 @menu
3594 * Public macros::               Macros that you can use.
3595 * Obsolete macros::             Macros that you should stop using.
3596 * Private macros::              Macros that you should not use.
3597 @end menu
3599 @c consider generating the following subsections automatically from m4 files.
3601 @node Public macros
3602 @subsection Public macros
3604 @table @code
3606 @item AM_ENABLE_MULTILIB
3607 @acindex AM_ENABLE_MULTILIB
3608 This is used when a ``multilib'' library is being built.  The first
3609 optional argument is the name of the @file{Makefile} being generated; it
3610 defaults to @samp{Makefile}.  The second option argument is used to find
3611 the top source directory; it defaults to the empty string (generally
3612 this should not be used unless you are familiar with the internals).
3613 @xref{Multilibs}.
3615 @item AM_INIT_AUTOMAKE([OPTIONS])
3616 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
3617 @acindex AM_INIT_AUTOMAKE
3618 Runs many macros required for proper operation of the generated Makefiles.
3620 @vindex AUTOMAKE_OPTIONS
3621 This macro has two forms, the first of which is preferred.
3622 In this form, @code{AM_INIT_AUTOMAKE} is called with a
3623 single argument: a space-separated list of Automake options that should
3624 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3625 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3627 @acindex AC_INIT
3628 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
3629 arguments: the package and the version number.  This form is
3630 obsolete because the @var{package} and @var{version} can be obtained
3631 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
3632 form).
3634 If your @file{configure.ac} has:
3636 @example
3637 AC_INIT([src/foo.c])
3638 AM_INIT_AUTOMAKE([mumble], [1.5])
3639 @end example
3641 @noindent
3642 you can modernize it as follows:
3644 @example
3645 AC_INIT([mumble], [1.5])
3646 AC_CONFIG_SRCDIR([src/foo.c])
3647 AM_INIT_AUTOMAKE
3648 @end example
3650 Note that if you're upgrading your @file{configure.ac} from an earlier
3651 version of Automake, it is not always correct to simply move the
3652 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3653 @code{AC_INIT}, as in the example above.  The first argument to
3654 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3655 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3656 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3657 tarball name from the package name, which should work for most but not
3658 all package names.  (If it doesn't work for yours, you can use the
3659 four-argument form of @code{AC_INIT} to provide the tarball name
3660 explicitly).
3662 @cindex @code{PACKAGE}, prevent definition
3663 @cindex @code{VERSION}, prevent definition
3664 @opindex no-define
3665 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3666 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3667 option, as in:
3668 @example
3669 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3670 @end example
3671 or by passing a third non-empty argument to the obsolete form.
3673 @item AM_PATH_LISPDIR
3674 @acindex AM_PATH_LISPDIR
3675 @vindex EMACS
3676 @vindex lispdir
3677 Searches for the program @command{emacs}, and, if found, sets the
3678 output variable @code{lispdir} to the full path to Emacs' site-lisp
3679 directory.
3681 Note that this test assumes the @command{emacs} found to be a version
3682 that supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other
3683 emacsen can cause this test to hang (some, like old versions of
3684 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3685 exit, which is hardly obvious for a non-emacs user).  In most cases,
3686 however, you should be able to use @kbd{C-c} to kill the test.  In
3687 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3688 environment, or use the @option{--with-lispdir} option to
3689 @command{configure} to explicitly set the correct path (if you're sure
3690 you have an @command{emacs} that supports Emacs Lisp.
3692 @item AM_PROG_AS
3693 @acindex AM_PROG_AS
3694 @vindex CCAS
3695 @vindex CCASFLAGS
3696 Use this macro when you have assembly code in your project.  This will
3697 choose the assembler for you (by default the C compiler) and set
3698 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
3700 @item AM_PROG_CC_C_O
3701 @acindex AM_PROG_CC_C_O
3702 @acindex AC_PROG_CC_C_O
3703 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
3704 the manner required by automake.  You must use this instead of
3705 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
3706 using per-target flags or subdir-objects with C sources.
3708 @item AM_PROG_LEX
3709 @acindex AM_PROG_LEX
3710 @acindex AC_PROG_LEX
3711 @cindex HP-UX 10, @command{lex} problems
3712 @cindex @command{lex} problems with HP-UX 10
3713 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
3714 Program Checks, autoconf, The Autoconf Manual}), but uses the
3715 @command{missing} script on systems that do not have @command{lex}.
3716 HP-UX 10 is one such system.
3718 @item AM_PROG_GCJ
3719 @acindex AM_PROG_GCJ
3720 @vindex GCJ
3721 @vindex GCJFLAGS
3722 This macro finds the @command{gcj} program or causes an error.  It sets
3723 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
3724 GNU Compiler Collection.
3726 @item AM_PROG_UPC([@var{compiler-search-list}])
3727 @acindex AM_PROG_UPC
3728 @vindex UPC
3729 Find a compiler for Unified Parallel C and define the @code{UPC}
3730 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
3731 This macro will abort @command{configure} if no Unified Parallel C
3732 compiler is found.
3734 @item AM_WITH_DMALLOC
3735 @acindex AM_WITH_DMALLOC
3736 @cindex @command{dmalloc}, support for
3737 @vindex WITH_DMALLOC
3738 @opindex --with-dmalloc
3739 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
3740 the user runs @command{configure} with @option{--with-dmalloc}, then
3741 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
3743 @item AM_WITH_REGEX
3744 @acindex AM_WITH_REGEX
3745 @vindex WITH_REGEX
3746 @opindex --with-regex
3747 @cindex regex package
3748 @cindex rx package
3749 Adds @option{--with-regex} to the @command{configure} command line.  If
3750 specified (the default), then the @samp{regex} regular expression
3751 library is used, @file{regex.o} is put into @code{LIBOBJS}, and
3752 @code{WITH_REGEX} is defined.  If @option{--without-regex} is given, then
3753 the @code{rx} regular expression library is used, and @file{rx.o} is put
3754 into @code{LIBOBJS}.
3756 @end table
3759 @node Obsolete macros
3760 @subsection Obsolete macros
3761 @cindex obsolete macros
3762 @cindex autoupdate
3764 Although using some of the following macros was required in past
3765 releases, you should not use any of them in new code.  Running
3766 @command{autoupdate} should adjust your @file{configure.ac}
3767 automatically (@pxref{autoupdate Invocation, , Using
3768 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
3769 Autoconf Manual}).
3771 @table @code
3772 @item AM_C_PROTOTYPES
3773 @acindex AM_C_PROTOTYPES
3774 @vindex ANSI2KNR
3775 @vindex U
3776 Check to see if function prototypes are understood by the compiler.  If
3777 so, define @samp{PROTOTYPES} and set the output variables @code{U} and
3778 @code{ANSI2KNR} to the empty string.  Otherwise, set @code{U} to
3779 @samp{_} and @code{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
3780 values to implement the obsolete de-ANSI-fication feature.
3782 @item AM_CONFIG_HEADER
3783 @acindex AM_CONFIG_HEADER
3784 Automake will generate rules to automatically regenerate the config
3785 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
3786 today (@pxref{Optional}).
3788 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3789 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3790 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
3791 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
3792 found in @file{<termios.h>}.  This macro is obsolete, you should
3793 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
3795 @item AM_PROG_MKDIR_P
3796 @acindex AM_PROG_MKDIR_P
3797 @cindex @code{mkdir -p}, macro check
3798 @vindex MKDIR_P
3799 @vindex mkdir_p
3801 From Automake 1.8 to 1.9.6 this macro used to define the output
3802 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
3803 -d}, or @code{mkinstalldirs}.
3805 Nowadays Autoconf provides a similar functionality with
3806 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
3807 Program Checks, autoconf, The Autoconf Manual}), however this defines
3808 the output variable @code{MKDIR_P} instead.  Therefore
3809 @code{AM_PROG_MKDIR_P} has been rewritten as a thin wrapper around
3810 @code{AC_PROG_MKDIR_P} to define @code{mkdir_p} to the same value as
3811 @code{MKDIR_P} for backward compatibility.
3813 If you are using Automake, there is normally no reason to call this
3814 macro, because @code{AM_INIT_AUTOMAKE} already does so.  However, make
3815 sure that the custom rules in your @file{Makefile}s use
3816 @code{$(MKDIR_P)} and not @code{$(mkdir_p)}.  Even if both variables
3817 still work, the latter should be considered obsolete.
3819 If you are not using Automake, please call @code{AC_PROG_MKDIR_P}
3820 instead of @code{AM_PROG_MKDIR_P}.
3822 @item AM_SYS_POSIX_TERMIOS
3823 @acindex AM_SYS_POSIX_TERMIOS
3824 @cindex POSIX termios headers
3825 @cindex termios POSIX headers
3826 Check to see if POSIX termios headers and functions are available on the
3827 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
3828 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
3829 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
3831 @end table
3834 @node Private macros
3835 @subsection Private macros
3837 The following macros are private macros you should not call directly.
3838 They are called by the other public macros when appropriate.  Do not
3839 rely on them, as they might be changed in a future version.  Consider
3840 them as implementation details; or better, do not consider them at all:
3841 skip this section!
3843 @ftable @code
3844 @item _AM_DEPENDENCIES
3845 @itemx AM_SET_DEPDIR
3846 @itemx AM_DEP_TRACK
3847 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
3848 These macros are used to implement Automake's automatic dependency
3849 tracking scheme.  They are called automatically by automake when
3850 required, and there should be no need to invoke them manually.
3852 @item AM_MAKE_INCLUDE
3853 This macro is used to discover how the user's @command{make} handles
3854 @code{include} statements.  This macro is automatically invoked when
3855 needed; there should be no need to invoke it manually.
3857 @item AM_PROG_INSTALL_STRIP
3858 This is used to find a version of @code{install} that can be used to
3859 strip a program at installation time.  This macro is automatically
3860 included when required.
3862 @item AM_SANITY_CHECK
3863 This checks to make sure that a file created in the build directory is
3864 newer than a file in the source directory.  This can fail on systems
3865 where the clock is set incorrectly.  This macro is automatically run
3866 from @code{AM_INIT_AUTOMAKE}.
3868 @end ftable
3871 @node Directories
3872 @chapter Directories
3874 For simple projects that distributes all files in the same directory
3875 it is enough to have a single @file{Makefile.am} that builds
3876 everything in place.
3878 In larger projects it is common to organize files in different
3879 directories, in a tree.  For instance one directory per program, per
3880 library or per module.  The traditional approach is to build these
3881 subdirectory recursively: each directory contains its @file{Makefile}
3882 (generated from @file{Makefile.am}), and when @command{make} is run
3883 from the top level directory it enters each subdirectory in turn to
3884 build its contents.
3886 @menu
3887 * Subdirectories::              Building subdirectories recursively
3888 * Conditional Subdirectories::  Conditionally not building directories
3889 * Alternative::                 Subdirectories without recursion
3890 * Subpackages::                 Nesting packages
3891 @end menu
3893 @node Subdirectories
3894 @section Recursing subdirectories
3896 @cindex @code{SUBDIRS}, explained
3898 In packages with subdirectories, the top level @file{Makefile.am} must
3899 tell Automake which subdirectories are to be built.  This is done via
3900 the @code{SUBDIRS} variable.
3901 @vindex SUBDIRS
3903 The @code{SUBDIRS} variable holds a list of subdirectories in which
3904 building of various sorts can occur.  The rules for many targets
3905 (e.g., @code{all}) in the generated @file{Makefile} will run commands
3906 both locally and in all specified subdirectories.  Note that the
3907 directories listed in @code{SUBDIRS} are not required to contain
3908 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
3909 This allows inclusion of libraries from packages that do not use
3910 Automake (such as @code{gettext}; see also @ref{Third-Party
3911 Makefiles}).
3913 In packages that use subdirectories, the top-level @file{Makefile.am} is
3914 often very short.  For instance, here is the @file{Makefile.am} from the
3915 GNU Hello distribution:
3917 @example
3918 EXTRA_DIST = BUGS ChangeLog.O README-alpha
3919 SUBDIRS = doc intl po src tests
3920 @end example
3922 When Automake invokes @command{make} in a subdirectory, it uses the value
3923 of the @code{MAKE} variable.  It passes the value of the variable
3924 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
3925 @file{Makefile.am} if there are flags you must always pass to
3926 @command{make}.
3927 @vindex MAKE
3928 @vindex AM_MAKEFLAGS
3930 The directories mentioned in @code{SUBDIRS} are usually direct
3931 children of the current directory, each subdirectory containing its
3932 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
3933 subdirectories.  Automake can be used to construct packages of
3934 arbitrary depth this way.
3936 By default, Automake generates @file{Makefiles} that work depth-first
3937 in postfix order: the subdirectories are built before the current
3938 directory.  However, it is possible to change this ordering.  You can
3939 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
3940 putting @samp{.} first will cause a prefix ordering of
3941 directories.
3943 Using
3945 @example
3946 SUBDIRS = lib src . test
3947 @end example
3949 @noindent
3950 will cause @file{lib/} to be built before @file{src/}, then the
3951 current directory will be built, finally the @file{test/} directory
3952 will be built.  It is customary to arrange test directories to be
3953 built after everything else since they are meant to test what has
3954 been constructed.
3956 All @code{clean} rules are run in reverse order of build rules.
3958 @node Conditional Subdirectories
3959 @section Conditional Subdirectories
3960 @cindex Subdirectories, building conditionally
3961 @cindex Conditional subdirectories
3962 @cindex @code{SUBDIRS}, conditional
3963 @cindex Conditional @code{SUBDIRS}
3965 It is possible to define the @code{SUBDIRS} variable conditionally if,
3966 like in the case of GNU Inetutils, you want to only build a subset of
3967 the entire package.
3969 To illustrate how this works, let's assume we have two directories
3970 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
3971 want to decide in @command{configure} whether @file{opt/} will be built
3972 or not.  (For this example we will assume that @file{opt/} should be
3973 built when the variable @samp{$want_opt} was set to @samp{yes}.)
3975 Running @command{make} should thus recurse into @file{src/} always, and
3976 then maybe in @file{opt/}.
3978 However @samp{make dist} should always recurse into both @file{src/}
3979 and @file{opt/}.  Because @file{opt/} should be distributed even if it
3980 is not needed in the current configuration.  This means
3981 @file{opt/Makefile} should be created @emph{unconditionally}.
3983 There are two ways to setup a project like this.  You can use Automake
3984 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
3985 variables (@pxref{Setting Output Variables, , Setting Output
3986 Variables, autoconf, The Autoconf Manual}).  Using Automake
3987 conditionals is the preferred solution.  Before we illustrate these
3988 two possibilities, let's introduce @code{DIST_SUBDIRS}.
3990 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
3991 @cindex @code{DIST_SUBDIRS}, explained
3993 Automake considers two sets of directories, defined by the variables
3994 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
3996 @code{SUBDIRS} contains the subdirectories of the current directory
3997 that must be built (@pxref{Subdirectories}).  It must be defined
3998 manually; Automake will never guess a directory is to be built.  As we
3999 will see in the next two sections, it is possible to define it
4000 conditionally so that some directory will be omitted from the build.
4002 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4003 directories, even those that have been conditionally left out of the
4004 build.  Recall our example where we may not want to build subdirectory
4005 @file{opt/}, but yet we want to distribute it?  This is where
4006 @code{DIST_SUBDIRS} come into play: @samp{opt} may not appear in
4007 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4009 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4010 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4011 other recursive rules use @code{SUBDIRS}.
4013 If @code{SUBDIRS} is defined conditionally using Automake
4014 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4015 from the possibles values of @code{SUBDIRS} in all conditions.
4017 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4018 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4019 does not know the possible values of these variables.  In this case
4020 @code{DIST_SUBDIRS} needs to be defined manually.
4022 @subsection Conditional subdirectories with @code{AM_CONDITIONAL}
4023 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4024 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4026 @c The test case for the setup described here is
4027 @c     test/subdircond2.test
4028 @c Try to keep it in sync.
4030 @file{configure} should output the @file{Makefile} for each directory
4031 and define a condition into which @file{opt/} should be built.
4033 @example
4034 @dots{}
4035 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4036 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4037 @dots{}
4038 @end example
4040 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4041 as follows.
4043 @example
4044 if COND_OPT
4045   MAYBE_OPT = opt
4046 endif
4047 SUBDIRS = src $(MAYBE_OPT)
4048 @end example
4050 As you can see, running @command{make} will rightly recurse into
4051 @file{src/} and maybe @file{opt/}.
4053 @vindex DIST_SUBDIRS
4054 As you can't see, running @samp{make dist} will recurse into both
4055 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4056 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4057 @code{DIST_SUBDIRS} variable.
4059 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4060 automatically because it knows that @code{MAYBE_OPT} can contain
4061 @samp{opt} in some condition.
4063 @subsection Conditional Subdirectories with @code{AC_SUBST}
4064 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4065 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4067 @c The test case for the setup described here is
4068 @c     test/subdircond3.test
4069 @c Try to keep it in sync.
4071 Another possibility is to define @code{MAYBE_OPT} from
4072 @file{./configure} using @code{AC_SUBST}:
4074 @example
4075 @dots{}
4076 if test "$want_opt" = yes; then
4077   MAYBE_OPT=opt
4078 else
4079   MAYBE_OPT=
4081 AC_SUBST([MAYBE_OPT])
4082 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4083 @dots{}
4084 @end example
4086 In this case the top-level @file{Makefile.am} should look as follows.
4088 @example
4089 SUBDIRS = src $(MAYBE_OPT)
4090 DIST_SUBDIRS = src opt
4091 @end example
4093 The drawback is that since Automake cannot guess what the possible
4094 values of @code{MAYBE_OPT} are, it is necessary to define
4095 @code{DIST_SUBDIRS}.
4097 @subsection Non-configured Subdirectories
4098 @cindex Subdirectories, configured conditionally
4100 The semantic of @code{DIST_SUBDIRS} is often misunderstood by some
4101 users that try to @emph{configure and build} subdirectories
4102 conditionally.  Here by configuring we mean creating the
4103 @file{Makefile} (it might also involve running a nested
4104 @command{configure} script: this is a costly operation that explains
4105 why people want to do it conditionally, but only the @file{Makefile}
4106 is relevant to the discussion).
4108 The above examples all assume that every @file{Makefile} is created,
4109 even in directories that are not going to be built.  The simple reason
4110 is that we want @samp{make dist} to distribute even the directories
4111 that are not being built (e.g., platform-dependent code), hence
4112 @file{make dist} must recurse into the subdirectory, hence this
4113 directory must be configured and appear in @code{DIST_SUBDIRS}.
4115 Building packages that do not configure every subdirectory is a tricky
4116 business, and we do not recommend it to the novice as it is easy to
4117 produce an incomplete tarball by mistake.  We will not discuss this
4118 topic in depth here, yet for the adventurous here are a few rules to
4119 remember.
4121 @cartouche
4122 @itemize
4123 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4125 It makes little sense to have a directory in @code{SUBDIRS} that
4126 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4127 which directories listed in the latter should be built.
4128 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4129 must be configured.
4131 I.e., the @file{Makefile} must exists or the recursive @command{make}
4132 rules will not be able to process the directory.
4133 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4135 So that the cleaning rule remove the generated @file{Makefile}s.
4136 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4137 lists all the directories that have been configured.
4138 @end itemize
4139 @end cartouche
4141 In order to prevent recursion in some non-configured directory you
4142 must therefore ensure that this directory does not appear in
4143 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4144 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4145 @code{DIST_SUBDIRS} explicitly, it will be default to
4146 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4147 = $(SUBDIRS)}.
4149 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4150 not be distributed unless you make other arrangements for this to
4151 happen (for instance, always running @samp{make dist} in a
4152 configuration where all directories are known to appear in
4153 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4154 distribute these directories).
4156 @cindex Subdirectories, not distributed
4157 In few packages, non-configured directories are not even expected to
4158 be distributed.  Although these packages do not require the
4159 aforementioned extra arrangements, there is another pitfall.  If the
4160 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4161 @command{automake} will make sure the directory exists.  Consequently
4162 @command{automake} cannot be run on such a distribution when one
4163 directory has been omitted.  One way to avoid this check is to use the
4164 @code{AC_SUBST} method to declare conditional directories; since
4165 @command{automake} does not know the values of @code{AC_SUBST}
4166 variables it cannot ensure the corresponding directory exist.
4168 @node Alternative
4169 @section An Alternative Approach to Subdirectories
4171 If you've ever read Peter Miller's excellent paper,
4172 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
4173 Recursive Make Considered Harmful}, the preceding sections on the use of
4174 subdirectories will probably come as unwelcome advice.  For those who
4175 haven't read the paper, Miller's main thesis is that recursive
4176 @command{make} invocations are both slow and error-prone.
4178 Automake provides sufficient cross-directory support @footnote{We
4179 believe.  This work is new and there are probably warts.
4180 @xref{Introduction}, for information on reporting bugs.} to enable you
4181 to write a single @file{Makefile.am} for a complex multi-directory
4182 package.
4185 By default an installable file specified in a subdirectory will have its
4186 directory name stripped before installation.  For instance, in this
4187 example, the header file will be installed as
4188 @file{$(includedir)/stdio.h}:
4190 @example
4191 include_HEADERS = inc/stdio.h
4192 @end example
4194 @vindex nobase_
4195 @cindex @code{nobase_} prefix
4196 @cindex Path stripping, avoiding
4197 @cindex Avoiding path stripping
4199 However, the @samp{nobase_} prefix can be used to circumvent this path
4200 stripping.  In this example, the header file will be installed as
4201 @file{$(includedir)/sys/types.h}:
4203 @example
4204 nobase_include_HEADERS = sys/types.h
4205 @end example
4207 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4208 @cindex @code{dist_} and @code{nobase_}
4209 @cindex @code{nodist_} and @code{nobase_}
4210 @vindex dist_
4211 @vindex nodist_
4213 @samp{nobase_} should be specified first when used in conjunction with
4214 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
4216 @example
4217 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4218 @end example
4220 Finally, note that a variable using the @samp{nobase_} prefix can
4221 always be replaced by several variables, one for each destination
4222 directory (@pxref{Uniform}).  For instance, the last example could be
4223 rewritten as follows:
4225 @example
4226 imagesdir = $(pkgdatadir)/images
4227 soundsdir = $(pkgdatadir)/sounds
4228 dist_images_DATA = images/vortex.pgm
4229 dist_sounds_DATA = sounds/whirl.ogg
4230 @end example
4232 @noindent
4233 This latter syntax makes it possible to change one destination
4234 directory without changing the layout of the source tree.
4236 @node Subpackages
4237 @section Nesting Packages
4238 @cindex Nesting packages
4239 @cindex Subpackages
4240 @acindex AC_CONFIG_SUBDIRS
4241 @acindex AC_CONFIG_AUX_DIR
4244 In the GNU Build System, packages can be nested to arbitrary depth.
4245 This means that a package can embedded other packages with their own
4246 @file{configure}, @file{Makefile}s, etc.
4248 These other packages should just appear as subdirectories of their
4249 parent package.  They must be listed in @code{SUBDIRS} like other
4250 ordinary directories.  However the subpackage's @file{Makefile}s
4251 should be output by its own @file{configure} script, not by the
4252 parent's @file{configure}.  This is achieved using the
4253 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4254 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4255 autoconf, The Autoconf Manual}).
4257 Here is an example package for an @code{arm} program that links with
4258 an @code{hand} library that is a nested package in subdirectory
4259 @file{hand/}.
4261 @code{arm}'s @file{configure.ac}:
4263 @example
4264 AC_INIT([arm], [1.0])
4265 AC_CONFIG_AUX_DIR([.])
4266 AM_INIT_AUTOMAKE
4267 AC_PROG_CC
4268 AC_CONFIG_FILES([Makefile])
4269 # Call hand's ./configure script recursively.
4270 AC_CONFIG_SUBDIRS([hand])
4271 AC_OUTPUT
4272 @end example
4274 @code{arm}'s @file{Makefile.am}:
4276 @example
4277 # Build the library in the hand subdirectory first.
4278 SUBDIRS = hand
4280 # Include hand's header when compiling this directory.
4281 AM_CPPFLAGS = -I$(srcdir)/hand
4283 bin_PROGRAMS = arm
4284 arm_SOURCES = arm.c
4285 # link with the hand library.
4286 arm_LDADD = hand/libhand.a
4287 @end example
4289 Now here is @code{hand}'s @file{hand/configure.ac}:
4291 @example
4292 AC_INIT([hand], [1.2])
4293 AC_CONFIG_AUX_DIR([.])
4294 AM_INIT_AUTOMAKE
4295 AC_PROG_CC
4296 AC_PROG_RANLIB
4297 AC_CONFIG_FILES([Makefile])
4298 AC_OUTPUT
4299 @end example
4301 @noindent
4302 and its @file{hand/Makefile.am}:
4304 @example
4305 lib_LIBRARIES = libhand.a
4306 libhand_a_SOURCES = hand.c
4307 @end example
4309 When @samp{make dist} is run from the top-level directory it will
4310 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4311 code as well as the @file{hand} subdirectory.  This package can be
4312 built and installed like any ordinary package, with the usual
4313 @samp{./configure && make && make install} sequence (the @code{hand}
4314 subpackage will be built and installed by the process).
4316 When @samp{make dist} is run from the hand directory, it will create a
4317 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4318 to be embedded in another package, it can still be used separately.
4320 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4321 force Automake and Autoconf to search for auxiliary scripts in the
4322 current directory.  For instance, this means that there will be two
4323 copies of @file{install-sh}: one in the top-level of the @code{arm}
4324 package, and another one in the @file{hand/} subdirectory for the
4325 @code{hand} package.
4327 The historical default is to search for these auxiliary scripts in
4328 the parent directory and the grandparent directory.  So if the
4329 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4330 @file{hand/configure.ac}, that subpackage would share the auxiliary
4331 script of the @code{arm} package.  This may looks like a gain in size
4332 (a few kilobytes), but it is actually a loss of modularity as the
4333 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4334 in the subdirectory will not work anymore).
4336 Packages that do not use Automake need more work to be integrated this
4337 way.  @xref{Third-Party Makefiles}.
4339 @node Programs
4340 @chapter Building Programs and Libraries
4342 A large part of Automake's functionality is dedicated to making it easy
4343 to build programs and libraries.
4345 @menu
4346 * A Program::                   Building a program
4347 * A Library::                   Building a library
4348 * A Shared Library::            Building a Libtool library
4349 * Program and Library Variables::  Variables controlling program and
4350                                 library builds
4351 * Default _SOURCES::            Default source files
4352 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4353 * Program variables::           Variables used when building a program
4354 * Yacc and Lex::                Yacc and Lex support
4355 * C++ Support::                 Compiling C++ sources
4356 * Objective C Support::         Compiling Objective C sources
4357 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4358 * Assembly Support::            Compiling assembly sources
4359 * Fortran 77 Support::          Compiling Fortran 77 sources
4360 * Fortran 9x Support::          Compiling Fortran 9x sources
4361 * Java Support::                Compiling Java sources
4362 * Support for Other Languages::  Compiling other languages
4363 * ANSI::                        Automatic de-ANSI-fication (obsolete)
4364 * Dependencies::                Automatic dependency tracking
4365 * EXEEXT::                      Support for executable extensions
4366 @end menu
4369 @node A Program
4370 @section Building a program
4372 In order to build a program, you need to tell Automake which sources
4373 are part of it, and which libraries it should be linked with.
4375 This section also covers conditional compilation of sources or
4376 programs.  Most of the comments about these also apply to libraries
4377 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4379 @menu
4380 * Program Sources::             Defining program sources
4381 * Linking::                     Linking with libraries or extra objects
4382 * Conditional Sources::         Handling conditional sources
4383 * Conditional Programs::        Building program conditionally
4384 @end menu
4386 @node Program Sources
4387 @subsection Defining program sources
4389 @cindex @code{PROGRAMS}, @code{bindir}
4390 @vindex _PROGRAMS
4391 @vindex bin_PROGRAMS
4392 @vindex sbin_PROGRAMS
4393 @vindex libexec_PROGRAMS
4394 @vindex pkglib_PROGRAMS
4395 @vindex noinst_PROGRAMS
4396 @vindex check_PROGRAMS
4398 In a directory containing source that gets built into a program (as
4399 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4400 Programs can be installed in @code{bindir}, @code{sbindir},
4401 @code{libexecdir}, @code{pkglibdir}, @code{pkglibexecdir}, or not at all
4402 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4403 which case the prefix is @samp{check_}.
4405 For instance:
4407 @example
4408 bin_PROGRAMS = hello
4409 @end example
4411 In this simple case, the resulting @file{Makefile.in} will contain code
4412 to generate a program named @code{hello}.
4414 Associated with each program are several assisting variables that are
4415 named after the program.  These variables are all optional, and have
4416 reasonable defaults.  Each variable, its use, and default is spelled out
4417 below; we use the ``hello'' example throughout.
4419 The variable @code{hello_SOURCES} is used to specify which source files
4420 get built into an executable:
4422 @example
4423 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4424 @end example
4426 This causes each mentioned @file{.c} file to be compiled into the
4427 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4429 @cindex @code{_SOURCES} primary, defined
4430 @cindex @code{SOURCES} primary, defined
4431 @cindex Primary variable, @code{SOURCES}
4432 @vindex _SOURCES
4434 If @code{hello_SOURCES} is not specified, then it defaults to the single
4435 file @file{hello.c} (@pxref{Default _SOURCES}).
4436 @vindex _SOURCES
4437 @vindex SOURCES
4439 Multiple programs can be built in a single directory.  Multiple programs
4440 can share a single source file, which must be listed in each
4441 @code{_SOURCES} definition.
4443 @cindex Header files in @code{_SOURCES}
4444 @cindex @code{_SOURCES} and header files
4446 Header files listed in a @code{_SOURCES} definition will be included in
4447 the distribution but otherwise ignored.  In case it isn't obvious, you
4448 should not include the header file generated by @file{configure} in a
4449 @code{_SOURCES} variable; this file should not be distributed.  Lex
4450 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4451 and Lex}.
4454 @node Linking
4455 @subsection Linking the program
4457 If you need to link against libraries that are not found by
4458 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4459 used to specify additional objects or libraries to link with; it is
4460 inappropriate for specifying specific linker flags, you should use
4461 @code{AM_LDFLAGS} for this purpose.
4462 @vindex LDADD
4463 @vindex AM_LDFLAGS
4465 @cindex @code{prog_LDADD}, defined
4467 Sometimes, multiple programs are built in one directory but do not share
4468 the same link-time requirements.  In this case, you can use the
4469 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4470 program as it appears in some @code{_PROGRAMS} variable, and usually
4471 written in lowercase) to override the global @code{LDADD}.  If this
4472 variable exists for a given program, then that program is not linked
4473 using @code{LDADD}.
4474 @vindex maude_LDADD
4476 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4477 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4478 built in the same directory, and has no such link requirement.  Also,
4479 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4480 is what cpio's @file{src/Makefile.am} looks like (abridged):
4482 @example
4483 bin_PROGRAMS = cpio pax $(MT)
4484 libexec_PROGRAMS = $(RMT)
4485 EXTRA_PROGRAMS = mt rmt
4487 LDADD = ../lib/libcpio.a $(INTLLIBS)
4488 rmt_LDADD =
4490 cpio_SOURCES = @dots{}
4491 pax_SOURCES = @dots{}
4492 mt_SOURCES = @dots{}
4493 rmt_SOURCES = @dots{}
4494 @end example
4496 @cindex @code{_LDFLAGS}, defined
4497 @vindex maude_LDFLAGS
4498 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4499 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4500 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4501 this purpose.
4503 @cindex @code{_DEPENDENCIES}, defined
4504 @vindex maude_DEPENDENCIES
4505 It is also occasionally useful to have a program depend on some other
4506 target that is not actually part of that program.  This can be done
4507 using the @code{@var{prog}_DEPENDENCIES} variable.  Each program
4508 depends on the contents of such a variable, but no further
4509 interpretation is done.
4511 Since these dependencies are associated to the link rule used to
4512 create the programs they should normally list files used by the link
4513 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4514 files.  In rare cases you may need to add other kinds of files such as
4515 linker scripts, but @emph{listing a source file in
4516 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4517 before all the components of a program are built, consider using the
4518 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4520 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4521 Automake.  The automatically-assigned value is the contents of
4522 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4523 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4524 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4525 @samp{$(ALLOCA)}; these are left because it is known that they will not
4526 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4527 generated.
4529 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4530 is useful.
4532 @cindex @code{LDADD} and @option{-l}
4533 @cindex @option{-l} and @code{LDADD}
4534 We recommend that you avoid using @option{-l} options in @code{LDADD}
4535 or @code{@var{prog}_LDADD} when referring to libraries built by your
4536 package.  Instead, write the file name of the library explicitly as in
4537 the above @code{cpio} example.  Use @option{-l} only to list
4538 third-party libraries.  If you follow this rule, the default value of
4539 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4540 omit the other ones.
4543 @node Conditional Sources
4544 @subsection Conditional compilation of sources
4546 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4547 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4548 @code{_SOURCES} variable.  The reason for this is a bit hard to
4549 explain, but suffice to say that it simply won't work.  Automake will
4550 give an error if you try to do this.
4552 Fortunately there are two other ways to achieve the same result.  One is
4553 to use configure substitutions in @code{_LDADD} variables, the other is
4554 to use an Automake conditional.
4556 @subsubsection Conditional compilation using @code{_LDADD} substitutions
4558 @cindex @code{EXTRA_prog_SOURCES}, defined
4560 Automake must know all the source files that could possibly go into a
4561 program, even if not all the files are built in every circumstance.  Any
4562 files that are only conditionally built should be listed in the
4563 appropriate @code{EXTRA_} variable.  For instance, if
4564 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4565 in @code{hello}, the @file{Makefile.am} would contain:
4567 @example
4568 bin_PROGRAMS = hello
4569 hello_SOURCES = hello-common.c
4570 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4571 hello_LDADD = $(HELLO_SYSTEM)
4572 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4573 @end example
4575 @noindent
4576 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4577 @file{configure.ac}:
4579 @example
4580 @dots{}
4581 case $host in
4582   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4583   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4584 esac
4585 AC_SUBST([HELLO_SYSTEM])
4586 @dots{}
4587 @end example
4589 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4590 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4591 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4592 built and linked in.
4594 @subsubsection Conditional compilation using Automake conditionals
4596 An often simpler way to compile source files conditionally is to use
4597 Automake conditionals.  For instance, you could use this
4598 @file{Makefile.am} construct to build the same @file{hello} example:
4600 @example
4601 bin_PROGRAMS = hello
4602 if LINUX
4603 hello_SOURCES = hello-linux.c hello-common.c
4604 else
4605 hello_SOURCES = hello-generic.c hello-common.c
4606 endif
4607 @end example
4609 In this case, @file{configure.ac} should setup the @code{LINUX}
4610 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4612 When using conditionals like this you don't need to use the
4613 @code{EXTRA_} variable, because Automake will examine the contents of
4614 each variable to construct the complete list of source files.
4616 If your program uses a lot of files, you will probably prefer a
4617 conditional @samp{+=}.
4619 @example
4620 bin_PROGRAMS = hello
4621 hello_SOURCES = hello-common.c
4622 if LINUX
4623 hello_SOURCES += hello-linux.c
4624 else
4625 hello_SOURCES += hello-generic.c
4626 endif
4627 @end example
4629 @node Conditional Programs
4630 @subsection Conditional compilation of programs
4631 @cindex Conditional programs
4632 @cindex Programs, conditional
4634 Sometimes it is useful to determine the programs that are to be built
4635 at configure time.  For instance, GNU @code{cpio} only builds
4636 @code{mt} and @code{rmt} under special circumstances.  The means to
4637 achieve conditional compilation of programs are the same you can use
4638 to compile source files conditionally: substitutions or conditionals.
4640 @subsubsection Conditional programs using @command{configure} substitutions
4642 @vindex EXTRA_PROGRAMS
4643 @cindex @code{EXTRA_PROGRAMS}, defined
4644 In this case, you must notify Automake of all the programs that can
4645 possibly be built, but at the same time cause the generated
4646 @file{Makefile.in} to use the programs specified by @command{configure}.
4647 This is done by having @command{configure} substitute values into each
4648 @code{_PROGRAMS} definition, while listing all optionally built programs
4649 in @code{EXTRA_PROGRAMS}.
4651 @example
4652 bin_PROGRAMS = cpio pax $(MT)
4653 libexec_PROGRAMS = $(RMT)
4654 EXTRA_PROGRAMS = mt rmt
4655 @end example
4657 As explained in @ref{EXEEXT}, Automake will rewrite
4658 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4659 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4660 Obviously it cannot rewrite values obtained at run-time through
4661 @command{configure} substitutions, therefore you should take care of
4662 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4663 ['mt$@{EXEEXT@}'])}.
4665 @subsubsection Conditional programs using Automake conditionals
4667 You can also use Automake conditionals (@pxref{Conditionals}) to
4668 select programs to be built.  In this case you don't have to worry
4669 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4671 @example
4672 bin_PROGRAMS = cpio pax
4673 if WANT_MT
4674   bin_PROGRAMS += mt
4675 endif
4676 if WANT_RMT
4677   libexec_PROGRAMS = rmt
4678 endif
4679 @end example
4682 @node A Library
4683 @section Building a library
4685 @cindex @code{_LIBRARIES} primary, defined
4686 @cindex @code{LIBRARIES} primary, defined
4687 @cindex Primary variable, @code{LIBRARIES}
4688 @vindex _LIBRARIES
4690 @vindex lib_LIBRARIES
4691 @vindex pkglib_LIBRARIES
4692 @vindex noinst_LIBRARIES
4694 Building a library is much like building a program.  In this case, the
4695 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
4696 @code{libdir} or @code{pkglibdir}.
4698 @xref{A Shared Library}, for information on how to build shared
4699 libraries using libtool and the @code{LTLIBRARIES} primary.
4701 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
4702 For instance, to create a library named @file{libcpio.a}, but not install
4703 it, you would write:
4705 @example
4706 noinst_LIBRARIES = libcpio.a
4707 libcpio_a_SOURCES = @dots{}
4708 @end example
4710 The sources that go into a library are determined exactly as they are
4711 for programs, via the @code{_SOURCES} variables.  Note that the library
4712 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
4713 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
4714 not @samp{libcpio.a_SOURCES}.
4716 @vindex maude_LIBADD
4717 Extra objects can be added to a library using the
4718 @code{@var{library}_LIBADD} variable.  This should be used for objects
4719 determined by @command{configure}.  Again from @code{cpio}:
4721 @example
4722 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4723 @end example
4725 In addition, sources for extra objects that will not exist until
4726 configure-time must be added to the @code{BUILT_SOURCES} variable
4727 (@pxref{Sources}).
4729 Building a static library is done by compiling all object files, then
4730 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
4731 library and the list of objects, and finally by calling
4732 @samp{$(RANLIB)} on that library.  You should call
4733 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
4734 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
4735 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
4736 can override these two variables my setting them in your
4737 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
4738 @file{configure.ac}, or by defining a per-library @code{maude_AR}
4739 variable (@pxref{Program and Library Variables}).
4741 @cindex Empty libraries
4742 Be careful when selecting library components conditionally.  Because
4743 building an empty library is not portable, you should ensure that any
4744 library contains always at least one object.
4746 To use a static library when building a program, add it to
4747 @code{LDADD} for this program.  In the following example, the program
4748 @file{cpio} is statically linked with the library @file{libcpio.a}.
4750 @example
4751 noinst_LIBRARIES = libcpio.a
4752 libcpio_a_SOURCES = @dots{}
4754 bin_PROGRAMS = cpio
4755 cpio_SOURCES = cpio.c @dots{}
4756 cpio_LDADD = libcpio.a
4757 @end example
4760 @node A Shared Library
4761 @section Building a Shared Library
4763 @cindex Shared libraries, support for
4765 Building shared libraries portably is a relatively complex matter.
4766 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
4767 Libtool Manual}) was created to help build shared libraries in a
4768 platform-independent way.
4770 @menu
4771 * Libtool Concept::             Introducing Libtool
4772 * Libtool Libraries::           Declaring Libtool Libraries
4773 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
4774 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
4775 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
4776 * Libtool Modules::             Building Libtool Modules
4777 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
4778 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
4779 * Libtool Issues::              Common Issues Related to Libtool's Use
4780 @end menu
4782 @node Libtool Concept
4783 @subsection The Libtool Concept
4785 @cindex @command{libtool}, introduction
4786 @cindex libtool library, definition
4787 @cindex suffix @file{.la}, defined
4788 @cindex @file{.la} suffix, defined
4790 Libtool abstracts shared and static libraries into a unified concept
4791 henceforth called @dfn{libtool libraries}.  Libtool libraries are
4792 files using the @file{.la} suffix, and can designate a static library,
4793 a shared library, or maybe both.  Their exact nature cannot be
4794 determined until @file{./configure} is run: not all platforms support
4795 all kinds of libraries, and users can explicitly select which
4796 libraries should be built.  (However the package's maintainers can
4797 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
4798 macro, libtool, The Libtool Manual}.)
4800 @cindex suffix @file{.lo}, defined
4801 Because object files for shared and static libraries must be compiled
4802 differently, libtool is also used during compilation.  Object files
4803 built by libtool are called @dfn{libtool objects}: these are files
4804 using the @file{.lo} suffix.  Libtool libraries are built from these
4805 libtool objects.
4807 You should not assume anything about the structure of @file{.la} or
4808 @file{.lo} files and how libtool constructs them: this is libtool's
4809 concern, and the last thing one wants is to learn about libtool's
4810 guts.  However the existence of these files matters, because they are
4811 used as targets and dependencies in @file{Makefile}s rules when
4812 building libtool libraries.  There are situations where you may have
4813 to refer to these, for instance when expressing dependencies for
4814 building source files conditionally (@pxref{Conditional Libtool
4815 Sources}).
4817 @cindex @file{libltdl}, introduction
4819 People considering writing a plug-in system, with dynamically loaded
4820 modules, should look into @file{libltdl}: libtool's dlopening library
4821 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
4822 This offers a portable dlopening facility to load libtool libraries
4823 dynamically, and can also achieve static linking where unavoidable.
4825 Before we discuss how to use libtool with Automake in details, it
4826 should be noted that the libtool manual also has a section about how
4827 to use Automake with libtool (@pxref{Using Automake, , Using Automake
4828 with Libtool, libtool, The Libtool Manual}).
4830 @node Libtool Libraries
4831 @subsection Building Libtool Libraries
4833 @cindex @code{_LTLIBRARIES} primary, defined
4834 @cindex @code{LTLIBRARIES} primary, defined
4835 @cindex Primary variable, @code{LTLIBRARIES}
4836 @cindex Example of shared libraries
4837 @vindex lib_LTLIBRARIES
4838 @vindex pkglib_LTLIBRARIES
4839 @vindex _LTLIBRARIES
4841 Automake uses libtool to build libraries declared with the
4842 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
4843 list of libtool libraries to build.  For instance, to create a libtool
4844 library named @file{libgettext.la}, and install it in @code{libdir},
4845 write:
4847 @example
4848 lib_LTLIBRARIES = libgettext.la
4849 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
4850 @end example
4852 Automake predefines the variable @code{pkglibdir}, so you can use
4853 @code{pkglib_LTLIBRARIES} to install libraries in
4854 @samp{$(libdir)/@@PACKAGE@@/}.
4856 If @file{gettext.h} is a public header file that needs to be installed
4857 in order for people to use the library, it should be declared using a
4858 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
4859 Headers listed in the latter should be internal headers that are not
4860 part of the public interface.
4862 @example
4863 lib_LTLIBRARIES = libgettext.la
4864 libgettext_la_SOURCES = gettext.c @dots{}
4865 include_HEADERS = gettext.h @dots{}
4866 @end example
4868 A package can build and install such a library along with other
4869 programs that use it.  This dependency should be specified using
4870 @code{LDADD}.  The following example builds a program named
4871 @file{hello} that is linked with @file{libgettext.la}.
4873 @example
4874 lib_LTLIBRARIES = libgettext.la
4875 libgettext_la_SOURCES = gettext.c @dots{}
4877 bin_PROGRAMS = hello
4878 hello_SOURCES = hello.c @dots{}
4879 hello_LDADD = libgettext.la
4880 @end example
4882 @noindent
4883 Whether @file{hello} is statically or dynamically linked with
4884 @file{libgettext.la} is not yet known: this will depend on the
4885 configuration of libtool and the capabilities of the host.
4888 @node Conditional Libtool Libraries
4889 @subsection Building Libtool Libraries Conditionally
4890 @cindex libtool libraries, conditional
4891 @cindex conditional libtool libraries
4893 Like conditional programs (@pxref{Conditional Programs}), there are
4894 two main ways to build conditional libraries: using Automake
4895 conditionals or using Autoconf @code{AC_SUBST}itutions.
4897 The important implementation detail you have to be aware of is that
4898 the place where a library will be installed matters to libtool: it
4899 needs to be indicated @emph{at link-time} using the @option{-rpath}
4900 option.
4902 For libraries whose destination directory is known when Automake runs,
4903 Automake will automatically supply the appropriate @option{-rpath}
4904 option to libtool.  This is the case for libraries listed explicitly in
4905 some installable @code{_LTLIBRARIES} variables such as
4906 @code{lib_LTLIBRARIES}.
4908 However, for libraries determined at configure time (and thus
4909 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
4910 final installation directory.  For such libraries you must add the
4911 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
4912 hand.
4914 The examples below illustrate the differences between these two methods.
4916 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
4917 variable set at @file{./configure}-time to either @file{libfoo.la},
4918 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
4919 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
4920 relates to @file{libfoo.la} or @file{libbar.la} by the time it creates
4921 the link rule for these two libraries.  Therefore the @option{-rpath}
4922 argument must be explicitly supplied.
4924 @example
4925 EXTRA_LTLIBRARIES = libfoo.la libbar.la
4926 lib_LTLIBRARIES = $(WANTEDLIBS)
4927 libfoo_la_SOURCES = foo.c @dots{}
4928 libfoo_la_LDFLAGS = -rpath '$(libdir)'
4929 libbar_la_SOURCES = bar.c @dots{}
4930 libbar_la_LDFLAGS = -rpath '$(libdir)'
4931 @end example
4933 Here is how the same @file{Makefile.am} would look using Automake
4934 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
4935 Automake is able to compute the @option{-rpath} setting itself, because
4936 it's clear that both libraries will end up in @samp{$(libdir)} if they
4937 are installed.
4939 @example
4940 lib_LTLIBRARIES =
4941 if WANT_LIBFOO
4942 lib_LTLIBRARIES += libfoo.la
4943 endif
4944 if WANT_LIBBAR
4945 lib_LTLIBRARIES += libbar.la
4946 endif
4947 libfoo_la_SOURCES = foo.c @dots{}
4948 libbar_la_SOURCES = bar.c @dots{}
4949 @end example
4951 @node Conditional Libtool Sources
4952 @subsection Libtool Libraries with Conditional Sources
4954 Conditional compilation of sources in a library can be achieved in the
4955 same way as conditional compilation of sources in a program
4956 (@pxref{Conditional Sources}).  The only difference is that
4957 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
4958 should mention libtool objects (@file{.lo} files).
4960 So, to mimic the @file{hello} example from @ref{Conditional Sources},
4961 we could build a @file{libhello.la} library using either
4962 @file{hello-linux.c} or @file{hello-generic.c} with the following
4963 @file{Makefile.am}.
4965 @example
4966 lib_LTLIBRARIES = libhello.la
4967 libhello_la_SOURCES = hello-common.c
4968 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
4969 libhello_la_LIBADD = $(HELLO_SYSTEM)
4970 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
4971 @end example
4973 @noindent
4974 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
4975 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
4977 Or we could simply use an Automake conditional as follows.
4979 @example
4980 lib_LTLIBRARIES = libhello.la
4981 libhello_la_SOURCES = hello-common.c
4982 if LINUX
4983 libhello_la_SOURCES += hello-linux.c
4984 else
4985 libhello_la_SOURCES += hello-generic.c
4986 endif
4987 @end example
4989 @node Libtool Convenience Libraries
4990 @subsection Libtool Convenience Libraries
4991 @cindex convenience libraries, libtool
4992 @cindex libtool convenience libraries
4993 @vindex noinst_LTLIBRARIES
4994 @vindex check_LTLIBRARIES
4996 Sometimes you want to build libtool libraries that should not be
4997 installed.  These are called @dfn{libtool convenience libraries} and
4998 are typically used to encapsulate many sublibraries, later gathered
4999 into one big installed library.
5001 Libtool convenience libraries are declared by directory-less variables
5002 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5003 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5004 not need an @option{-rpath} flag at link time (actually this is the only
5005 difference).
5007 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5008 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5009 @samp{make check}.  Finally, libraries listed in
5010 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5011 rules to build them, but if the library does not appear as a Makefile
5012 dependency anywhere it won't be built (this is why
5013 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5015 Here is a sample setup merging libtool convenience libraries from
5016 subdirectories into one main @file{libtop.la} library.
5018 @example
5019 # -- Top-level Makefile.am --
5020 SUBDIRS = sub1 sub2 @dots{}
5021 lib_LTLIBRARIES = libtop.la
5022 libtop_la_SOURCES =
5023 libtop_la_LIBADD = \
5024   sub1/libsub1.la \
5025   sub2/libsub2.la \
5026   @dots{}
5028 # -- sub1/Makefile.am --
5029 noinst_LTLIBRARIES = libsub1.la
5030 libsub1_la_SOURCES = @dots{}
5032 # -- sub2/Makefile.am --
5033 # showing nested convenience libraries
5034 SUBDIRS = sub2.1 sub2.2 @dots{}
5035 noinst_LTLIBRARIES = libsub2.la
5036 libsub2_la_SOURCES =
5037 libsub2_la_LIBADD = \
5038   sub21/libsub21.la \
5039   sub22/libsub22.la \
5040   @dots{}
5041 @end example
5043 When using such setup, beware that @command{automake} will assume
5044 @file{libtop.la} is to be linked with the C linker.  This is because
5045 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5046 default language.  If @code{libtop_la_SOURCES} was not empty,
5047 @command{automake} would select the linker as explained in @ref{How
5048 the Linker is Chosen}.
5050 If one of the sublibraries contains non-C source, it is important that
5051 the appropriate linker be chosen.  One way to achieve this is to
5052 pretend that there is such a non-C file among the sources of the
5053 library, thus forcing @command{automake} to select the appropriate
5054 linker.  Here is the top-level @file{Makefile} of our example updated
5055 to force C++ linking.
5057 @example
5058 SUBDIRS = sub1 sub2 @dots{}
5059 lib_LTLIBRARIES = libtop.la
5060 libtop_la_SOURCES =
5061 # Dummy C++ source to cause C++ linking.
5062 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5063 libtop_la_LIBADD = \
5064   sub1/libsub1.la \
5065   sub2/libsub2.la \
5066   @dots{}
5067 @end example
5069 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5070 files that might be compiled (this is mostly useful when doing
5071 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5072 Libtool Sources}), and the @code{nodist_} prefix means the listed
5073 sources are not to be distributed (@pxref{Program and Library
5074 Variables}).  In effect the file @file{dummy.cxx} does not need to
5075 exist in the source tree.  Of course if you have some real source file
5076 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5077 @code{nodist_EXTRA_libtop_la_SOURCES}.
5080 @node Libtool Modules
5081 @subsection Libtool Modules
5082 @cindex modules, libtool
5083 @cindex libtool modules
5084 @cindex @option{-module}, libtool
5086 These are libtool libraries meant to be dlopened.  They are
5087 indicated to libtool by passing @option{-module} at link-time.
5089 @example
5090 pkglib_LTLIBRARIES = mymodule.la
5091 mymodule_la_SOURCES = doit.c
5092 mymodule_la_LDFLAGS = -module
5093 @end example
5095 Ordinarily, Automake requires that a library's name starts with
5096 @code{lib}.  However, when building a dynamically loadable module you
5097 might wish to use a "nonstandard" name.  Automake will not complain
5098 about such nonstandard name if it knows the library being built is a
5099 libtool module, i.e., if @option{-module} explicitly appears in the
5100 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5101 variable when no per-library @code{_LDFLAGS} variable is defined).
5103 As always, @code{AC_SUBST} variables are black boxes to Automake since
5104 their values are not yet known when @command{automake} is run.
5105 Therefore if @option{-module} is set via such a variable, Automake
5106 cannot notice it and will proceed as if the library was an ordinary
5107 libtool library, with strict naming.
5109 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5110 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5112 @node Libtool Flags
5113 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5114 @cindex @code{_LIBADD}, libtool
5115 @cindex @code{_LDFLAGS}, libtool
5116 @cindex @code{_LIBTOOLFLAGS}, libtool
5117 @vindex AM_LIBTOOLFLAGS
5118 @vindex LIBTOOLFLAGS
5119 @vindex maude_LIBTOOLFLAGS
5121 As shown in previous sections, the @samp{@var{library}_LIBADD}
5122 variable should be used to list extra libtool objects (@file{.lo}
5123 files) or libtool libraries (@file{.la}) to add to @var{library}.
5125 The @samp{@var{library}_LDFLAGS} variable is the place to list
5126 additional libtool linking flags, such as @option{-version-info},
5127 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5128 libtool, The Libtool Manual}.
5130 The @command{libtool} command has two kinds of options: mode-specific
5131 options and generic options.  Mode-specific options such as the
5132 aforementioned linking flags should be lumped with the other flags
5133 passed to the tool invoked by @command{libtool} (hence the use of
5134 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5135 options include @option{--tag=@var{TAG}} and @option{--silent}
5136 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5137 Libtool Manual} for more options) should appear before the mode
5138 selection on the command line; in @file{Makefile.am}s they should
5139 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5141 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, the global
5142 @code{AM_LIBTOOLFLAGS} variable is used instead.
5144 These flags are passed to libtool after the @option{--tag=@var{TAG}}
5145 option computed by Automake (if any), so
5146 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is the
5147 good place to override or supplement the @option{--tag=@var{TAG}}
5148 setting.
5150 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5151 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5152 Variables Ordering}.  It allows users to run @samp{make
5153 LIBTOOLFLAGS=--silent}, for instance.
5156 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5157 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5158 @cindex @code{LTLIBOBJS}, special handling
5159 @cindex @code{LIBOBJS}, and Libtool
5160 @cindex @code{LTALLOCA}, special handling
5161 @cindex @code{ALLOCA}, and Libtool
5162 @vindex LTLIBOBJS
5163 @vindex LIBOBJS
5164 @vindex LTALLOCA
5165 @vindex ALLOCA
5166 @acindex AC_LIBOBJ
5168 Where an ordinary library might include @samp{$(LIBOBJS)} or
5169 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5170 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5171 the object files that libtool operates on do not necessarily end in
5172 @file{.o}.
5174 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5175 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5176 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5178 @node Libtool Issues
5179 @subsection Common Issues Related to Libtool's Use
5181 @subsubsection @samp{required file `./ltmain.sh' not found}
5182 @cindex @file{ltmain.sh} not found
5183 @cindex @command{libtoolize}, no longer run by @command{automake}
5184 @cindex @command{libtoolize} and @command{autoreconf}
5185 @cindex @command{autoreconf} and @command{libtoolize}
5186 @cindex @file{bootstrap.sh} and @command{autoreconf}
5187 @cindex @file{autogen.sh} and @command{autoreconf}
5189 Libtool comes with a tool called @command{libtoolize} that will
5190 install libtool's supporting files into a package.  Running this
5191 command will install @file{ltmain.sh}.  You should execute it before
5192 @command{aclocal} and @command{automake}.
5194 People upgrading old packages to newer autotools are likely to face
5195 this issue because older Automake versions used to call
5196 @command{libtoolize}.  Therefore old build scripts do not call
5197 @command{libtoolize}.
5199 Since Automake 1.6, it has been decided that running
5200 @command{libtoolize} was none of Automake's business.  Instead, that
5201 functionality has been moved into the @command{autoreconf} command
5202 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5203 The Autoconf Manual}).  If you do not want to remember what to run and
5204 when, just learn the @command{autoreconf} command.  Hopefully,
5205 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5206 a call to @command{autoreconf} should also free you from any similar
5207 incompatible change in the future.
5209 @subsubsection Objects @samp{created with both libtool and without}
5211 Sometimes, the same source file is used both to build a libtool
5212 library and to build another non-libtool target (be it a program or
5213 another library).
5215 Let's consider the following @file{Makefile.am}.
5217 @example
5218 bin_PROGRAMS = prog
5219 prog_SOURCES = prog.c foo.c @dots{}
5221 lib_LTLIBRARIES = libfoo.la
5222 libfoo_la_SOURCES = foo.c @dots{}
5223 @end example
5225 @noindent
5226 (In this trivial case the issue could be avoided by linking
5227 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5228 @code{prog_SOURCES}.  But let's assume we really want to keep
5229 @file{prog} and @file{libfoo.la} separate.)
5231 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5232 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5233 that in the course of creating @file{foo.lo}, libtool may erase (or
5234 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5236 Therefore, when Automake detects this situation it will complain
5237 with a message such as
5238 @example
5239 object `foo.$(OBJEXT)' created both with libtool and without
5240 @end example
5242 A workaround for this issue is to ensure that these two objects get
5243 different basenames.  As explained in @ref{renamed objects}, this
5244 happens automatically when per-targets flags are used.
5246 @example
5247 bin_PROGRAMS = prog
5248 prog_SOURCES = prog.c foo.c @dots{}
5249 prog_CFLAGS = $(AM_CFLAGS)
5251 lib_LTLIBRARIES = libfoo.la
5252 libfoo_la_SOURCES = foo.c @dots{}
5253 @end example
5255 @noindent
5256 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5257 when the @code{prog_CFLAGS} is defined, it is used instead of
5258 @code{AM_CFLAGS}.  However as a side effect it will cause
5259 @file{prog.c} and @file{foo.c} to be compiled as
5260 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5261 the issue.
5263 @node Program and Library Variables
5264 @section Program and Library Variables
5266 Associated with each program are a collection of variables that can be
5267 used to modify how that program is built.  There is a similar list of
5268 such variables for each library.  The canonical name of the program (or
5269 library) is used as a base for naming these variables.
5271 In the list below, we use the name ``maude'' to refer to the program or
5272 library.  In your @file{Makefile.am} you would replace this with the
5273 canonical name of your program.  This list also refers to ``maude'' as a
5274 program, but in general the same rules apply for both static and dynamic
5275 libraries; the documentation below notes situations where programs and
5276 libraries differ.
5278 @vtable @code
5279 @item maude_SOURCES
5280 This variable, if it exists, lists all the source files that are
5281 compiled to build the program.  These files are added to the
5282 distribution by default.  When building the program, Automake will cause
5283 each source file to be compiled to a single @file{.o} file (or
5284 @file{.lo} when using libtool).  Normally these object files are named
5285 after the source file, but other factors can change this.  If a file in
5286 the @code{_SOURCES} variable has an unrecognized extension, Automake
5287 will do one of two things with it.  If a suffix rule exists for turning
5288 files with the unrecognized extension into @file{.o} files, then
5289 automake will treat this file as it will any other source file
5290 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5291 ignored as though it were a header file.
5293 The prefixes @code{dist_} and @code{nodist_} can be used to control
5294 whether files listed in a @code{_SOURCES} variable are distributed.
5295 @code{dist_} is redundant, as sources are distributed by default, but it
5296 can be specified for clarity if desired.
5298 It is possible to have both @code{dist_} and @code{nodist_} variants of
5299 a given @code{_SOURCES} variable at once; this lets you easily
5300 distribute some files and not others, for instance:
5302 @example
5303 nodist_maude_SOURCES = nodist.c
5304 dist_maude_SOURCES = dist-me.c
5305 @end example
5307 By default the output file (on Unix systems, the @file{.o} file) will
5308 be put into the current build directory.  However, if the option
5309 @option{subdir-objects} is in effect in the current directory then the
5310 @file{.o} file will be put into the subdirectory named after the
5311 source file.  For instance, with @option{subdir-objects} enabled,
5312 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5313 people prefer this mode of operation.  You can specify
5314 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5315 @cindex Subdirectory, objects in
5316 @cindex Objects in subdirectory
5319 @item EXTRA_maude_SOURCES
5320 Automake needs to know the list of files you intend to compile
5321 @emph{statically}.  For one thing, this is the only way Automake has of
5322 knowing what sort of language support a given @file{Makefile.in}
5323 requires.  @footnote{There are other, more obscure reasons for
5324 this limitation as well.}  This means that, for example, you can't put a
5325 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5326 variable.  If you intend to conditionally compile source files and use
5327 @file{configure} to substitute the appropriate object names into, e.g.,
5328 @code{_LDADD} (see below), then you should list the corresponding source
5329 files in the @code{EXTRA_} variable.
5331 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5332 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5333 sources that may need to be built, but should not be distributed.
5335 @item maude_AR
5336 A static library is created by default by invoking @samp{$(AR)
5337 $(ARFLAGS)} followed by the name of the library and then the objects
5338 being put into the library.  You can override this by setting the
5339 @code{_AR} variable.  This is usually used with C++; some C++
5340 compilers require a special invocation in order to instantiate all the
5341 templates that should go into a library.  For instance, the SGI C++
5342 compiler likes this variable set like so:
5343 @example
5344 libmaude_a_AR = $(CXX) -ar -o
5345 @end example
5347 @item maude_LIBADD
5348 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5349 variable.  For instance, this should be used for objects determined by
5350 @command{configure} (@pxref{A Library}).
5352 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5353 to other libtool libraries.
5355 @item maude_LDADD
5356 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5357 @file{*.la}) can be added to a @emph{program} by listing them in the
5358 @code{_LDADD} variable.  For instance, this should be used for objects
5359 determined by @command{configure} (@pxref{Linking}).
5361 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5362 program-specific linker flags (except for @option{-l}, @option{-L},
5363 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5364 for this purpose.
5366 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5367 could link your program against the X libraries like so:
5369 @example
5370 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5371 @end example
5373 We recommend that you use @option{-l} and @option{-L} only when
5374 referring to third-party libraries, and give the explicit file names
5375 of any library built by your package.  Doing so will ensure that
5376 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5378 @item maude_LDFLAGS
5379 This variable is used to pass extra flags to the link step of a program
5380 or a shared library.  It overrides the global @code{AM_LDFLAGS} variable.
5382 @item maude_LIBTOOLFLAGS
5383 This variable is used to pass extra options to @command{libtool}.
5384 It overrides the global @code{AM_LIBTOOLFLAGS} variable.
5385 These options are output before @command{libtool}'s @option{--mode=@var{MODE}}
5386 option, so they should not be mode-specific options (those belong to
5387 the compiler or linker flags).  @xref{Libtool Flags}.
5389 @item maude_DEPENDENCIES
5390 It is also occasionally useful to have a target (program or library)
5391 depend on some other file that is not actually part of that target.
5392 This can be done using the @code{_DEPENDENCIES} variable.  Each
5393 targets depends on the contents of such a variable, but no further
5394 interpretation is done.
5396 Since these dependencies are associated to the link rule used to
5397 create the programs they should normally list files used by the link
5398 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5399 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5400 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5401 may need to add other kinds of files such as linker scripts, but
5402 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5403 some source file needs to be built before all the components of a
5404 program are built, consider using the @code{BUILT_SOURCES} variable
5405 (@pxref{Sources}).
5407 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5408 The automatically-assigned value is the contents of @code{_LDADD} or
5409 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5410 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5411 substitutions that are left in are only @samp{$(LIBOBJS)} and
5412 @samp{$(ALLOCA)}; these are left because it is known that they will not
5413 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5415 @code{_DEPENDENCIES} is more likely used to perform conditional
5416 compilation using an @code{AC_SUBST} variable that contains a list of
5417 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5418 Sources}.
5420 @item maude_LINK
5421 You can override the linker on a per-program basis.  By default the
5422 linker is chosen according to the languages used by the program.  For
5423 instance, a program that includes C++ source code would use the C++
5424 compiler to link.  The @code{_LINK} variable must hold the name of a
5425 command that can be passed all the @file{.o} file names as arguments.
5426 Note that the name of the underlying program is @emph{not} passed to
5427 @code{_LINK}; typically one uses @samp{$@@}:
5429 @example
5430 maude_LINK = $(CCLD) -magic -o $@@
5431 @end example
5433 @item maude_CCASFLAGS
5434 @itemx maude_CFLAGS
5435 @itemx maude_CPPFLAGS
5436 @itemx maude_CXXFLAGS
5437 @itemx maude_FFLAGS
5438 @itemx maude_GCJFLAGS
5439 @itemx maude_LFLAGS
5440 @itemx maude_OBJCFLAGS
5441 @itemx maude_RFLAGS
5442 @itemx maude_UPCFLAGS
5443 @itemx maude_YFLAGS
5444 @cindex per-target compilation flags, defined
5445 Automake allows you to set compilation flags on a per-program (or
5446 per-library) basis.  A single source file can be included in several
5447 programs, and it will potentially be compiled with different flags for
5448 each program.  This works for any language directly supported by
5449 Automake.  These @dfn{per-target compilation flags} are
5450 @samp{_CCASFLAGS},
5451 @samp{_CFLAGS},
5452 @samp{_CPPFLAGS},
5453 @samp{_CXXFLAGS},
5454 @samp{_FFLAGS},
5455 @samp{_GCJFLAGS},
5456 @samp{_LFLAGS},
5457 @samp{_OBJCFLAGS},
5458 @samp{_RFLAGS},
5459 @samp{_UPCFLAGS}, and
5460 @samp{_YFLAGS}.
5462 When using a per-target compilation flag, Automake will choose a
5463 different name for the intermediate object files.  Ordinarily a file
5464 like @file{sample.c} will be compiled to produce @file{sample.o}.
5465 However, if the program's @code{_CFLAGS} variable is set, then the
5466 object file will be named, for instance, @file{maude-sample.o}.  (See
5467 also @ref{renamed objects}.)  The use of per-target compilation flags
5468 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5469 from @file{configure.ac}.
5471 In compilations with per-target flags, the ordinary @samp{AM_} form of
5472 the flags variable is @emph{not} automatically included in the
5473 compilation (however, the user form of the variable @emph{is} included).
5474 So for instance, if you want the hypothetical @file{maude} compilations
5475 to also use the value of @code{AM_CFLAGS}, you would need to write:
5477 @example
5478 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5479 @end example
5481 @xref{Flag Variables Ordering}, for more discussion about the
5482 interaction between user variables, @samp{AM_} shadow variables, and
5483 per-target variables.
5485 @item maude_SHORTNAME
5486 On some platforms the allowable file names are very short.  In order to
5487 support these systems and per-target compilation flags at the same
5488 time, Automake allows you to set a ``short name'' that will influence
5489 how intermediate object files are named.  For instance, in the following
5490 example,
5492 @example
5493 bin_PROGRAMS = maude
5494 maude_CPPFLAGS = -DSOMEFLAG
5495 maude_SHORTNAME = m
5496 maude_SOURCES = sample.c @dots{}
5497 @end example
5499 @noindent
5500 the object file would be named @file{m-sample.o} rather than
5501 @file{maude-sample.o}.
5503 This facility is rarely needed in practice,
5504 and we recommend avoiding it until you find it is required.
5505 @end vtable
5507 @node Default _SOURCES
5508 @section Default @code{_SOURCES}
5510 @vindex _SOURCES
5511 @vindex SOURCES
5512 @cindex @code{_SOURCES}, default
5513 @cindex default @code{_SOURCES}
5515 @code{_SOURCES} variables are used to specify source files of programs
5516 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5517 libraries (@pxref{A Shared Library}).
5519 When no such variable is specified for a target, Automake will define
5520 one itself.  The default is to compile a single C file whose base name
5521 is the name of the target itself, with any extension replaced by
5522 @file{.c}.  (Defaulting to C is terrible but we are stuck with it for
5523 historical reasons.)
5525 For example if you have the following somewhere in your
5526 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5528 @example
5529 lib_LIBRARIES = libfoo.a sub/libc++.a
5530 @end example
5532 @noindent
5533 @file{libfoo.a} will be built using a default source file named
5534 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5535 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5536 would be built from @file{sub_libc___a.c}, i.e., the default source
5537 was the canonized name of the target, with @file{.c} appended.
5538 We believe the new behavior is more sensible, but for backward
5539 compatibility automake will use the old name if a file or a rule
5540 with that name exist.)
5542 @cindex @code{check_PROGRAMS} example
5543 @vindex check_PROGRAMS
5544 Default sources are mainly useful in test suites, when building many
5545 tests programs each from a single source.  For instance, in
5547 @example
5548 check_PROGRAMS = test1 test2 test3
5549 @end example
5551 @noindent
5552 @file{test1}, @file{test2}, and @file{test3} will be built
5553 from @file{test1.c}, @file{test2.c}, and @file{test3.c}.
5555 @cindex Libtool modules, default source example
5556 @cindex default source, Libtool modules example
5557 Another case where is this convenient is building many Libtool modules
5558 (@file{moduleN.la}), each defined in its own file (@file{moduleN.c}).
5560 @example
5561 AM_LDFLAGS = -module
5562 lib_LTLIBRARIES = module1.la module2.la module3.la
5563 @end example
5565 @cindex empty @code{_SOURCES}
5566 @cindex @code{_SOURCES}, empty
5567 Finally, there is one situation where this default source computation
5568 needs to be avoided: when a target should not be built from sources.
5569 We already saw such an example in @ref{true}; this happens when all
5570 the constituents of a target have already been compiled and need just
5571 to be combined using a @code{_LDADD} variable.  Then it is necessary
5572 to define an empty @code{_SOURCES} variable, so that automake does not
5573 compute a default.
5575 @example
5576 bin_PROGRAMS = target
5577 target_SOURCES =
5578 target_LDADD = libmain.a libmisc.a
5579 @end example
5581 @node LIBOBJS
5582 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5584 @cindex @code{LIBOBJS}, example
5585 @cindex @code{ALLOCA}, example
5586 @cindex @code{LIBOBJS}, special handling
5587 @cindex @code{ALLOCA}, special handling
5588 @vindex LTLIBOBJS
5589 @vindex LIBOBJS
5590 @vindex LTALLOCA
5591 @vindex ALLOCA
5593 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5594 files that should be compiled into the project to provide an
5595 implementation for functions that are missing or broken on the host
5596 system.  They are substituted by @file{configure}.
5598 @acindex AC_LIBOBJ
5600 These variables are defined by Autoconf macros such as
5601 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5602 Generic Function Checks, autoconf, The Autoconf Manual}), or
5603 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5604 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5605 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5606 populate @samp{$(LIBOBJS)}.
5608 @acindex AC_LIBSOURCE
5610 Using these variables is very similar to doing conditional compilation
5611 using @code{AC_SUBST} variables, as described in @ref{Conditional
5612 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5613 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5614 variable, or to the @samp{*_LIBADD} variable when building a library.
5615 However there is no need to list the corresponding sources in
5616 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5617 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5618 dependencies, and it will discover the list of corresponding source
5619 files automatically (by tracing the invocations of the
5620 @code{AC_LIBSOURCE} Autoconf macros).
5622 These variables are usually used to build a portability library that
5623 is linked with all the programs of the project.  We now review a
5624 sample setup.  First, @file{configure.ac} contains some checks that
5625 affect either @code{LIBOBJS} or @code{ALLOCA}.
5627 @example
5628 # configure.ac
5629 @dots{}
5630 AC_CONFIG_LIBOBJ_DIR([lib])
5631 @dots{}
5632 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5633 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5634 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5635 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5636 @dots{}
5637 AC_CONFIG_FILES([
5638   lib/Makefile
5639   src/Makefile
5641 AC_OUTPUT
5642 @end example
5644 @acindex AC_CONFIG_LIBOBJ_DIR
5646 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
5647 of these object files are to be found in the @file{lib/} directory.
5648 Automake can also use this information, otherwise it expects the
5649 source files are to be in the directory where the @samp{$(LIBOBJS)}
5650 and @samp{$(ALLOCA)} variables are used.
5652 The @file{lib/} directory should therefore contain @file{malloc.c},
5653 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
5654 @file{Makefile.am}:
5656 @example
5657 # lib/Makefile.am
5659 noinst_LIBRARIES = libcompat.a
5660 libcompat_a_SOURCES =
5661 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5662 @end example
5664 The library can have any name, of course, and anyway it is not going
5665 to be installed: it just holds the replacement versions of the missing
5666 or broken functions so we can later link them in.  In many projects
5667 also include extra functions, specific to the project, in that
5668 library: they are simply added on the @code{_SOURCES} line.
5670 @cindex Empty libraries and @samp{$(LIBOBJS)}
5671 @cindex @samp{$(LIBOBJS)} and empty libraries
5672 There is a small trap here, though: @samp{$(LIBOBJS)} and
5673 @samp{$(ALLOCA)} might be empty, and building an empty library is not
5674 portable.  You should ensure that there is always something to put in
5675 @file{libcompat.a}.  Most projects will also add some utility
5676 functions in that directory, and list them in
5677 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
5678 be empty.
5680 Finally here is how this library could be used from the @file{src/}
5681 directory.
5683 @example
5684 # src/Makefile.am
5686 # Link all programs in this directory with libcompat.a
5687 LDADD = ../lib/libcompat.a
5689 bin_PROGRAMS = tool1 tool2 @dots{}
5690 tool1_SOURCES = @dots{}
5691 tool2_SOURCES = @dots{}
5692 @end example
5694 When option @option{subdir-objects} is not used, as in the above
5695 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
5696 be used in the directory where their sources lie.  E.g., here it would
5697 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
5698 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
5699 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
5700 in other directories.  For instance @file{src/Makefile.am} could be
5701 changed as follows.
5703 @example
5704 # src/Makefile.am
5706 AUTOMAKE_OPTIONS = subdir-objects
5707 LDADD = $(LIBOBJS) $(ALLOCA)
5709 bin_PROGRAMS = tool1 tool2 @dots{}
5710 tool1_SOURCES = @dots{}
5711 tool2_SOURCES = @dots{}
5712 @end example
5714 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
5715 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
5716 Libtool libraries (where the expected object extension is @file{.lo}):
5717 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
5719 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
5720 be defined by hand (as in the past), however at the time of writing
5721 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
5722 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
5723 autoconf, The Autoconf Manual}.
5726 @node Program variables
5727 @section Variables used when building a program
5729 Occasionally it is useful to know which @file{Makefile} variables
5730 Automake uses for compilations; for instance, you might need to do your
5731 own compilation in some special cases.
5733 Some variables are inherited from Autoconf; these are @code{CC},
5734 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
5735 @code{LIBS}.
5736 @vindex CC
5737 @vindex CFLAGS
5738 @vindex CPPFLAGS
5739 @vindex DEFS
5740 @vindex LDFLAGS
5741 @vindex LIBS
5743 There are some additional variables that Automake defines on its own:
5745 @vtable @code
5746 @item AM_CPPFLAGS
5747 The contents of this variable are passed to every compilation that invokes
5748 the C preprocessor; it is a list of arguments to the preprocessor.  For
5749 instance, @option{-I} and @option{-D} options should be listed here.
5751 Automake already provides some @option{-I} options automatically, in a
5752 separate variable that is also passed to every compilation that invokes
5753 the C preprocessor.  In particular it generates @samp{-I.},
5754 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
5755 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS} or
5756 @code{AM_CONFIG_HEADER}).  You can disable the default @option{-I}
5757 options using the @option{nostdinc} option.
5759 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
5760 per-library) @code{_CPPFLAGS} variable if it is defined.
5762 @item INCLUDES
5763 This does the same job as @code{AM_CPPFLAGS} (or any per-target
5764 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
5765 same functionality.  This variable is deprecated; we suggest using
5766 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
5768 @item AM_CFLAGS
5769 This is the variable the @file{Makefile.am} author can use to pass
5770 in additional C compiler flags.  It is more fully documented elsewhere.
5771 In some situations, this is not used, in preference to the
5772 per-executable (or per-library) @code{_CFLAGS}.
5774 @item COMPILE
5775 This is the command used to actually compile a C source file.  The
5776 file name is appended to form the complete command line.
5778 @item AM_LDFLAGS
5779 This is the variable the @file{Makefile.am} author can use to pass
5780 in additional linker flags.  In some situations, this is not used, in
5781 preference to the per-executable (or per-library) @code{_LDFLAGS}.
5783 @item LINK
5784 This is the command used to actually link a C program.  It already
5785 includes @samp{-o $@@} and the usual variable references (for instance,
5786 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
5787 and libraries to link in.
5788 @end vtable
5791 @node Yacc and Lex
5792 @section Yacc and Lex support
5794 Automake has somewhat idiosyncratic support for Yacc and Lex.
5796 Automake assumes that the @file{.c} file generated by @command{yacc}
5797 (or @command{lex}) should be named using the basename of the input
5798 file.  That is, for a yacc source file @file{foo.y}, Automake will
5799 cause the intermediate file to be named @file{foo.c} (as opposed to
5800 @file{y.tab.c}, which is more traditional).
5802 The extension of a yacc source file is used to determine the extension
5803 of the resulting C or C++ file.  Files with the extension @file{.y}
5804 will be turned into @file{.c} files; likewise, @file{.yy} will become
5805 @file{.cc}; @file{.y++}, @file{c++}; @file{.yxx}, @file{.cxx}; and
5806 @file{.ypp}, @file{.cpp}.
5808 Likewise, lex source files can be used to generate C or C++; the
5809 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
5810 @file{.lpp} are recognized.
5812 You should never explicitly mention the intermediate (C or C++) file
5813 in any @code{SOURCES} variable; only list the source file.
5815 The intermediate files generated by @command{yacc} (or @command{lex})
5816 will be included in any distribution that is made.  That way the user
5817 doesn't need to have @command{yacc} or @command{lex}.
5819 If a @command{yacc} source file is seen, then your @file{configure.ac} must
5820 define the variable @code{YACC}.  This is most easily done by invoking
5821 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
5822 Program Checks, autoconf, The Autoconf Manual}).
5824 @vindex YFLAGS
5825 @vindex AM_YFLAGS
5826 When @code{yacc} is invoked, it is passed @code{YFLAGS} and
5827 @code{AM_YFLAGS}.  The former is a user variable and the latter is
5828 intended for the @file{Makefile.am} author.
5830 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
5831 @command{yacc}.  Automake knows what this means and will automatically
5832 adjust its rules to update and distribute the header file built by
5833 @samp{yacc -d}.  What Automake cannot guess, though, is where this
5834 header will be used: it is up to you to ensure the header gets built
5835 before it is first used.  Typically this is necessary in order for
5836 dependency tracking to work when the header is included by another
5837 file.  The common solution is listing the header file in
5838 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
5840 @example
5841 BUILT_SOURCES = parser.h
5842 AM_YFLAGS = -d
5843 bin_PROGRAMS = foo
5844 foo_SOURCES = @dots{} parser.y @dots{}
5845 @end example
5847 If a @command{lex} source file is seen, then your @file{configure.ac}
5848 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
5849 to do this (@pxref{Particular Programs, , Particular Program Checks,
5850 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
5851 (@pxref{Macros}) is recommended.
5853 @vindex LFLAGS
5854 @vindex AM_LFLAGS
5855 When @command{lex} is invoked, it is passed @code{LFLAGS} and
5856 @code{AM_LFLAGS}.  The former is a user variable and the latter is
5857 intended for the @file{Makefile.am} author.
5859 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
5860 rebuild rule for distributed Yacc and Lex sources are only used when
5861 @code{maintainer-mode} is enabled, or when the files have been erased.
5863 @cindex @command{ylwrap}
5864 @cindex @command{yacc}, multiple parsers
5865 @cindex Multiple @command{yacc} parsers
5866 @cindex Multiple @command{lex} lexers
5867 @cindex @command{lex}, multiple lexers
5869 When @command{lex} or @command{yacc} sources are used, @code{automake
5870 -i} automatically installs an auxiliary program called
5871 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
5872 program is used by the build rules to rename the output of these
5873 tools, and makes it possible to include multiple @command{yacc} (or
5874 @command{lex}) source files in a single directory.  (This is necessary
5875 because yacc's output file name is fixed, and a parallel make could
5876 conceivably invoke more than one instance of @command{yacc}
5877 simultaneously.)
5879 For @command{yacc}, simply managing locking is insufficient.  The output of
5880 @command{yacc} always uses the same symbol names internally, so it isn't
5881 possible to link two @command{yacc} parsers into the same executable.
5883 We recommend using the following renaming hack used in @command{gdb}:
5884 @example
5885 #define yymaxdepth c_maxdepth
5886 #define yyparse c_parse
5887 #define yylex   c_lex
5888 #define yyerror c_error
5889 #define yylval  c_lval
5890 #define yychar  c_char
5891 #define yydebug c_debug
5892 #define yypact  c_pact
5893 #define yyr1    c_r1
5894 #define yyr2    c_r2
5895 #define yydef   c_def
5896 #define yychk   c_chk
5897 #define yypgo   c_pgo
5898 #define yyact   c_act
5899 #define yyexca  c_exca
5900 #define yyerrflag c_errflag
5901 #define yynerrs c_nerrs
5902 #define yyps    c_ps
5903 #define yypv    c_pv
5904 #define yys     c_s
5905 #define yy_yys  c_yys
5906 #define yystate c_state
5907 #define yytmp   c_tmp
5908 #define yyv     c_v
5909 #define yy_yyv  c_yyv
5910 #define yyval   c_val
5911 #define yylloc  c_lloc
5912 #define yyreds  c_reds
5913 #define yytoks  c_toks
5914 #define yylhs   c_yylhs
5915 #define yylen   c_yylen
5916 #define yydefred c_yydefred
5917 #define yydgoto c_yydgoto
5918 #define yysindex c_yysindex
5919 #define yyrindex c_yyrindex
5920 #define yygindex c_yygindex
5921 #define yytable  c_yytable
5922 #define yycheck  c_yycheck
5923 #define yyname   c_yyname
5924 #define yyrule   c_yyrule
5925 @end example
5927 For each define, replace the @samp{c_} prefix with whatever you like.
5928 These defines work for @command{bison}, @command{byacc}, and
5929 traditional @code{yacc}s.  If you find a parser generator that uses a
5930 symbol not covered here, please report the new name so it can be added
5931 to the list.
5934 @node C++ Support
5935 @section C++ Support
5937 @cindex C++ support
5938 @cindex Support for C++
5940 Automake includes full support for C++.
5942 Any package including C++ code must define the output variable
5943 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
5944 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
5945 Program Checks, autoconf, The Autoconf Manual}).
5947 A few additional variables are defined when a C++ source file is seen:
5949 @vtable @code
5950 @item CXX
5951 The name of the C++ compiler.
5953 @item CXXFLAGS
5954 Any flags to pass to the C++ compiler.
5956 @item AM_CXXFLAGS
5957 The maintainer's variant of @code{CXXFLAGS}.
5959 @item CXXCOMPILE
5960 The command used to actually compile a C++ source file.  The file name
5961 is appended to form the complete command line.
5963 @item CXXLINK
5964 The command used to actually link a C++ program.
5965 @end vtable
5968 @node Objective C Support
5969 @section Objective C Support
5971 @cindex Objective C support
5972 @cindex Support for Objective C
5974 Automake includes some support for Objective C.
5976 Any package including Objective C code must define the output variable
5977 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
5978 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
5979 Program Checks, autoconf, The Autoconf Manual}).
5981 A few additional variables are defined when an Objective C source file
5982 is seen:
5984 @vtable @code
5985 @item OBJC
5986 The name of the Objective C compiler.
5988 @item OBJCFLAGS
5989 Any flags to pass to the Objective C compiler.
5991 @item AM_OBJCFLAGS
5992 The maintainer's variant of @code{OBJCFLAGS}.
5994 @item OBJCCOMPILE
5995 The command used to actually compile a Objective C source file.  The
5996 file name is appended to form the complete command line.
5998 @item OBJCLINK
5999 The command used to actually link a Objective C program.
6000 @end vtable
6003 @node Unified Parallel C Support
6004 @section Unified Parallel C Support
6006 @cindex Unified Parallel C support
6007 @cindex Support for Unified Parallel C
6009 Automake includes some support for Unified Parallel C.
6011 Any package including Unified Parallel C code must define the output
6012 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6013 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public macros}).
6015 A few additional variables are defined when an Unified Parallel C
6016 source file is seen:
6018 @vtable @code
6019 @item UPC
6020 The name of the Unified Parallel C compiler.
6022 @item UPCFLAGS
6023 Any flags to pass to the Unified Parallel C compiler.
6025 @item AM_UPCFLAGS
6026 The maintainer's variant of @code{UPCFLAGS}.
6028 @item UPCCOMPILE
6029 The command used to actually compile a Unified Parallel C source file.
6030 The file name is appended to form the complete command line.
6032 @item UPCLINK
6033 The command used to actually link a Unified Parallel C program.
6034 @end vtable
6037 @node Assembly Support
6038 @section Assembly Support
6040 Automake includes some support for assembly code.  There are two forms
6041 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6042 (@file{*.S} or @file{*.sx}).
6044 @vindex CCAS
6045 @vindex CCASFLAGS
6046 @vindex CPPFLAGS
6047 @vindex AM_CCASFLAGS
6048 @vindex AM_CPPFLAGS
6049 The variable @code{CCAS} holds the name of the compiler used to build
6050 assembly code.  This compiler must work a bit like a C compiler; in
6051 particular it must accept @option{-c} and @option{-o}.  The values of
6052 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6053 definition) is passed to the compilation.  For preprocessed files,
6054 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6055 and @code{AM_CPPFLAGS} are also used.
6057 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6058 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6059 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6060 flags), but you are free to define these variables by other means.
6062 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6063 @command{automake} as being files containing assembly code.
6066 @node Fortran 77 Support
6067 @comment  node-name,  next,  previous,  up
6068 @section Fortran 77 Support
6070 @cindex Fortran 77 support
6071 @cindex Support for Fortran 77
6073 Automake includes full support for Fortran 77.
6075 Any package including Fortran 77 code must define the output variable
6076 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6077 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6078 Program Checks, autoconf, The Autoconf Manual}).
6080 A few additional variables are defined when a Fortran 77 source file is
6081 seen:
6083 @vtable @code
6085 @item F77
6086 The name of the Fortran 77 compiler.
6088 @item FFLAGS
6089 Any flags to pass to the Fortran 77 compiler.
6091 @item AM_FFLAGS
6092 The maintainer's variant of @code{FFLAGS}.
6094 @item RFLAGS
6095 Any flags to pass to the Ratfor compiler.
6097 @item AM_RFLAGS
6098 The maintainer's variant of @code{RFLAGS}.
6100 @item F77COMPILE
6101 The command used to actually compile a Fortran 77 source file.  The file
6102 name is appended to form the complete command line.
6104 @item FLINK
6105 The command used to actually link a pure Fortran 77 program or shared
6106 library.
6108 @end vtable
6110 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6111 addition to compiling them@footnote{Much, if not most, of the
6112 information in the following sections pertaining to preprocessing
6113 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6114 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6115 also contains some support for creating programs and shared libraries
6116 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6117 Fortran 77 With C and C++}).
6119 These issues are covered in the following sections.
6121 @menu
6122 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6123 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6124 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6125 @end menu
6128 @node Preprocessing Fortran 77
6129 @comment  node-name,  next,  previous,  up
6130 @subsection Preprocessing Fortran 77
6132 @cindex Preprocessing Fortran 77
6133 @cindex Fortran 77, Preprocessing
6134 @cindex Ratfor programs
6136 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6137 rule runs just the preprocessor to convert a preprocessable Fortran 77
6138 or Ratfor source file into a strict Fortran 77 source file.  The precise
6139 command used is as follows:
6141 @table @file
6143 @item .F
6144 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6145 $(AM_FFLAGS) $(FFLAGS)}
6147 @item .r
6148 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6150 @end table
6153 @node Compiling Fortran 77 Files
6154 @comment  node-name,  next,  previous,  up
6155 @subsection Compiling Fortran 77 Files
6157 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6158 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6159 is as follows:
6161 @table @file
6163 @item .f
6164 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6166 @item .F
6167 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6168 $(AM_FFLAGS) $(FFLAGS)}
6170 @item .r
6171 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6173 @end table
6176 @node Mixing Fortran 77 With C and C++
6177 @comment  node-name,  next,  previous,  up
6178 @subsection Mixing Fortran 77 With C and C++
6180 @cindex Fortran 77, mixing with C and C++
6181 @cindex Mixing Fortran 77 with C and C++
6182 @cindex Linking Fortran 77 with C and C++
6183 @cindex cfortran
6184 @cindex Mixing Fortran 77 with C and/or C++
6186 Automake currently provides @emph{limited} support for creating programs
6187 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6188 However, there are many other issues related to mixing Fortran 77 with
6189 other languages that are @emph{not} (currently) handled by Automake, but
6190 that are handled by other packages@footnote{For example,
6191 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6192 addresses all of these inter-language issues, and runs under nearly all
6193 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6194 @command{cfortran} is not yet Free Software, but it will be in the next
6195 major release.}.
6197 @page
6198 Automake can help in two ways:
6200 @enumerate
6201 @item
6202 Automatic selection of the linker depending on which combinations of
6203 source code.
6205 @item
6206 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6207 @option{-l}) to pass to the automatically selected linker in order to link
6208 in the appropriate Fortran 77 intrinsic and run-time libraries.
6210 @cindex @code{FLIBS}, defined
6211 @vindex FLIBS
6212 These extra Fortran 77 linker flags are supplied in the output variable
6213 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
6214 supplied with newer versions of Autoconf (Autoconf version 2.13 and
6215 later).  @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
6216 Autoconf}.
6217 @end enumerate
6219 If Automake detects that a program or shared library (as mentioned in
6220 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6221 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6222 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6223 @file{configure.ac}, and that either @code{$(FLIBS)}
6224 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6225 (for shared libraries) variables.  It is the responsibility of the
6226 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6227 appears in the appropriate @code{_LDADD} or
6228 @code{_LIBADD} variable.
6230 @cindex Mixed language example
6231 @cindex Example, mixed language
6233 For example, consider the following @file{Makefile.am}:
6235 @example
6236 bin_PROGRAMS = foo
6237 foo_SOURCES  = main.cc foo.f
6238 foo_LDADD    = libfoo.la $(FLIBS)
6240 pkglib_LTLIBRARIES = libfoo.la
6241 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6242 libfoo_la_LIBADD   = $(FLIBS)
6243 @end example
6245 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6246 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6247 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6248 Automake would have issued a warning.
6251 @page
6252 @menu
6253 * How the Linker is Chosen::    Automatic linker selection
6254 @end menu
6256 @node How the Linker is Chosen
6257 @comment  node-name,  next,  previous,  up
6258 @subsubsection How the Linker is Chosen
6260 @cindex Automatic linker selection
6261 @cindex Selecting the linker automatically
6263 When a program or library mixes several languages, Automake choose the
6264 linker according to the following priorities.  (The names in
6265 parentheses are the variables containing the link command.)
6267 @enumerate
6268 @item
6269 @vindex GCJLINK
6270 Native Java (@code{GCJLINK})
6271 @item
6272 @vindex CXXLINK
6273 C++ (@code{CXXLINK})
6274 @item
6275 @vindex F77LINK
6276 Fortran 77 (@code{F77LINK})
6277 @item
6278 @vindex FCLINK
6279 Fortran (@code{FCLINK})
6280 @item
6281 @vindex OBJCLINK
6282 Objective C (@code{OBJCLINK})
6283 @item
6284 @vindex UPCLINK
6285 Unified Parallel C (@code{UPCLINK})
6286 @item
6287 @vindex LINK
6288 C (@code{LINK})
6289 @end enumerate
6291 For example, if Fortran 77, C and C++ source code is compiled
6292 into a program, then the C++ linker will be used.  In this case, if the
6293 C or Fortran 77 linkers required any special libraries that weren't
6294 included by the C++ linker, then they must be manually added to an
6295 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6296 @file{Makefile.am}.
6298 Automake only looks at the file names listed in @file{_SOURCES}
6299 variables to choose the linker, and defaults to the C linker.
6300 Sometimes this is inconvenient because you are linking against a
6301 library written in another language and would like to set the linker
6302 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6303 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6306 @node Fortran 9x Support
6307 @comment  node-name,  next,  previous,  up
6308 @section Fortran 9x Support
6310 @cindex Fortran 9x support
6311 @cindex Support for Fortran 9x
6313 Automake includes support for Fortran 9x.
6315 Any package including Fortran 9x code must define the output variable
6316 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6317 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6318 Program Checks, autoconf, The Autoconf Manual}).
6320 A few additional variables are defined when a Fortran 9x source file is
6321 seen:
6323 @vtable @code
6325 @item FC
6326 The name of the Fortran 9x compiler.
6328 @item FCFLAGS
6329 Any flags to pass to the Fortran 9x compiler.
6331 @item AM_FCFLAGS
6332 The maintainer's variant of @code{FCFLAGS}.
6334 @item FCCOMPILE
6335 The command used to actually compile a Fortran 9x source file.  The file
6336 name is appended to form the complete command line.
6338 @item FCLINK
6339 The command used to actually link a pure Fortran 9x program or shared
6340 library.
6342 @end vtable
6344 @menu
6345 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6346 @end menu
6348 @node Compiling Fortran 9x Files
6349 @comment  node-name,  next,  previous,  up
6350 @subsection Compiling Fortran 9x Files
6352 @file{@var{N}.o} is made automatically from @file{@var{N}.f90},
6353 @file{@var{N}.f95}, @file{@var{N}.f03}, or @file{@var{N}.f08}
6354 by running the Fortran 9x compiler.  The precise command used
6355 is as follows:
6357 @table @file
6359 @item .f90
6360 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6362 @item .f95
6363 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6365 @item .f03
6366 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6368 @item .f08
6369 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6371 @end table
6373 @node Java Support
6374 @comment  node-name,  next,  previous,  up
6375 @section Java Support
6377 @cindex Java support
6378 @cindex Support for Java
6380 Automake includes support for compiled Java, using @command{gcj}, the Java
6381 front end to the GNU Compiler Collection.
6383 Any package including Java code to be compiled must define the output
6384 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6385 must also be defined somehow (either in @file{configure.ac} or
6386 @file{Makefile.am}).  The simplest way to do this is to use the
6387 @code{AM_PROG_GCJ} macro.
6389 @vindex GCJFLAGS
6391 By default, programs including Java source files are linked with
6392 @command{gcj}.
6394 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6395 compilation invoking @command{gcj} (in its role as an ahead-of-time
6396 compiler, when invoking it to create @file{.class} files,
6397 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6398 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6399 the user variable @code{GCJFLAGS}, should be used.
6401 @vindex AM_GCJFLAGS
6403 @command{gcj} can be used to compile @file{.java}, @file{.class},
6404 @file{.zip}, or @file{.jar} files.
6406 When linking, @command{gcj} requires that the main class be specified
6407 using the @option{--main=} option.  The easiest way to do this is to use
6408 the @code{_LDFLAGS} variable for the program.
6411 @node Support for Other Languages
6412 @comment  node-name,  next,  previous,  up
6413 @section Support for Other Languages
6415 Automake currently only includes full support for C, C++ (@pxref{C++
6416 Support}), Objective C (@pxref{Objective C Support}), Fortran 77
6417 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6418 and Java (@pxref{Java Support}).  There is only rudimentary support for other
6419 languages, support for which will be improved based on user demand.
6421 Some limited support for adding your own languages is available via the
6422 suffix rule handling (@pxref{Suffixes}).
6425 @node ANSI
6426 @section Automatic de-ANSI-fication
6428 @cindex de-ANSI-fication, defined
6430 The features described in this section are obsolete; you should not
6431 used any of them in new code, and they may be withdrawn in future
6432 Automake releases.
6434 When the C language was standardized in 1989, there was a long
6435 transition period where package developers needed to worry about
6436 porting to older systems that did not support ANSI C by default.
6437 These older systems are no longer in practical use and are no longer
6438 supported by their original suppliers, so developers need not worry
6439 about this problem any more.
6441 Automake allows you to write packages that are portable to K&R C by
6442 @dfn{de-ANSI-fying} each source file before the actual compilation takes
6443 place.
6445 @vindex AUTOMAKE_OPTIONS
6446 @opindex ansi2knr
6448 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
6449 (@pxref{Options}) contains the option @option{ansi2knr} then code to
6450 handle de-ANSI-fication is inserted into the generated
6451 @file{Makefile.in}.
6453 This causes each C source file in the directory to be treated as ANSI C@.
6454 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
6455 is available, the @command{ansi2knr} program is used to convert the source
6456 files into K&R C, which is then compiled.
6458 The @command{ansi2knr} program is simple-minded.  It assumes the source
6459 code will be formatted in a particular way; see the @command{ansi2knr} man
6460 page for details.
6462 @acindex AM_C_PROTOTYPES
6463 Support for the obsolete de-ANSI-fication feature
6464 requires the source files @file{ansi2knr.c}
6465 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
6466 these files are distributed with Automake.  Also, the package
6467 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
6468 (@pxref{Macros}).
6470 Automake also handles finding the @command{ansi2knr} support files in some
6471 other directory in the current package.  This is done by prepending the
6472 relative path to the appropriate directory to the @command{ansi2knr}
6473 option.  For instance, suppose the package has ANSI C code in the
6474 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
6475 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
6476 @file{src/Makefile.am}:
6478 @example
6479 AUTOMAKE_OPTIONS = ../lib/ansi2knr
6480 @end example
6482 If no directory prefix is given, the files are assumed to be in the
6483 current directory.
6485 Note that automatic de-ANSI-fication will not work when the package is
6486 being built for a different host architecture.  That is because automake
6487 currently has no way to build @command{ansi2knr} for the build machine.
6489 @c FIXME: this paragraph might be better moved to an `upgrading' section.
6490 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
6491 @cindex @code{LIBOBJS} and @code{ansi2knr}
6492 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
6493 @cindex @code{ansi2knr} and @code{LIBOBJS}
6494 Using @code{LIBOBJS} with source de-ANSI-fication used to require
6495 hand-crafted code in @file{configure} to append @samp{$U} to basenames
6496 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
6497 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
6498 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
6499 vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual})
6501 @node Dependencies
6502 @section Automatic dependency tracking
6504 As a developer it is often painful to continually update the
6505 @file{Makefile.in} whenever the include-file dependencies change in a
6506 project.  Automake supplies a way to automatically track dependency
6507 changes (@pxref{Dependency Tracking}).
6509 @cindex Dependency tracking
6510 @cindex Automatic dependency tracking
6512 Automake always uses complete dependencies for a compilation,
6513 including system headers.  Automake's model is that dependency
6514 computation should be a side effect of the build.  To this end,
6515 dependencies are computed by running all compilations through a
6516 special wrapper program called @command{depcomp}.  @command{depcomp}
6517 understands how to coax many different C and C++ compilers into
6518 generating dependency information in the format it requires.
6519 @samp{automake -a} will install @command{depcomp} into your source
6520 tree for you.  If @command{depcomp} can't figure out how to properly
6521 invoke your compiler, dependency tracking will simply be disabled for
6522 your build.
6524 @cindex @command{depcomp}
6526 Experience with earlier versions of Automake (@pxref{Dependency
6527 Tracking Evolution}) taught us that it is not reliable to generate
6528 dependencies only on the maintainer's system, as configurations vary
6529 too much.  So instead Automake implements dependency tracking at build
6530 time.
6532 Automatic dependency tracking can be suppressed by putting
6533 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6534 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6535 (this should be the preferred way).  Or, you can invoke @command{automake}
6536 with the @option{-i} option.  Dependency tracking is enabled by default.
6538 @vindex AUTOMAKE_OPTIONS
6539 @opindex no-dependencies
6541 The person building your package also can choose to disable dependency
6542 tracking by configuring with @option{--disable-dependency-tracking}.
6544 @cindex Disabling dependency tracking
6545 @cindex Dependency tracking, disabling
6548 @node EXEEXT
6549 @section Support for executable extensions
6551 @cindex Executable extension
6552 @cindex Extension, executable
6553 @cindex Windows
6555 On some platforms, such as Windows, executables are expected to have an
6556 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6557 among them) will automatically generate @file{foo.exe} when asked to
6558 generate @file{foo}.
6560 Automake provides mostly-transparent support for this.  Unfortunately
6561 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6562 dictionary is revised, you will have to assist Automake if your package
6563 must support those platforms.
6565 One thing you must be aware of is that, internally, Automake rewrites
6566 something like this:
6568 @example
6569 bin_PROGRAMS = liver
6570 @end example
6572 to this:
6574 @example
6575 bin_PROGRAMS = liver$(EXEEXT)
6576 @end example
6578 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6579 extension.
6581 The variables @code{TESTS}, @code{XFAIL_TESTS} (@pxref{Tests}) are also
6582 rewritten if it contains filenames that have been declared as programs
6583 in the same @file{Makefile}.  (This is mostly useful when some programs
6584 from @code{check_PROGRAMS} are listed in @code{TESTS}.)
6586 However, Automake cannot apply this rewriting to @command{configure}
6587 substitutions.  This means that if you are conditionally building a
6588 program using such a substitution, then your @file{configure.ac} must
6589 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6591 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
6592 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
6593 automatically if you configure a compiler (say, through
6594 @code{AC_PROG_CC}).
6596 Sometimes maintainers like to write an explicit link rule for their
6597 program.  Without executable extension support, this is easy---you
6598 simply write a rule whose target is the name of the program.  However,
6599 when executable extension support is enabled, you must instead add the
6600 @samp{$(EXEEXT)} suffix.
6602 Unfortunately, due to the change in Autoconf 2.50, this means you must
6603 always add this extension.  However, this is a problem for maintainers
6604 who know their package will never run on a platform that has
6605 executable extensions.  For those maintainers, the @option{no-exeext}
6606 option (@pxref{Options}) will disable this feature.  This works in a
6607 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6608 rule for a target named @code{foo} in @file{Makefile.am} will override
6609 an automake-generated rule for @samp{foo$(EXEEXT)}.  Without
6610 the @option{no-exeext} option, this use will give a diagnostic.
6613 @node Other objects
6614 @chapter Other Derived Objects
6616 Automake can handle derived objects that are not C programs.  Sometimes
6617 the support for actually building such objects must be explicitly
6618 supplied, but Automake will still automatically handle installation and
6619 distribution.
6621 @menu
6622 * Scripts::                     Executable scripts
6623 * Headers::                     Header files
6624 * Data::                        Architecture-independent data files
6625 * Sources::                     Derived sources
6626 @end menu
6629 @node Scripts
6630 @section Executable Scripts
6632 @cindex @code{_SCRIPTS} primary, defined
6633 @cindex @code{SCRIPTS} primary, defined
6634 @cindex Primary variable, @code{SCRIPTS}
6635 @vindex _SCRIPTS
6636 @cindex Installing scripts
6638 It is possible to define and install programs that are scripts.  Such
6639 programs are listed using the @code{SCRIPTS} primary name.  When the
6640 script is distributed in its final, installable form, the
6641 @file{Makefile} usually looks as follows:
6642 @vindex SCRIPTS
6644 @example
6645 # Install my_script in $(bindir) and distribute it.
6646 dist_bin_SCRIPTS = my_script
6647 @end example
6649 Script are not distributed by default; as we have just seen, those
6650 that should be distributed can be specified using a @code{dist_}
6651 prefix as with other primaries.
6653 @cindex @code{SCRIPTS}, installation directories
6654 @vindex bin_SCRIPTS
6655 @vindex sbin_SCRIPTS
6656 @vindex libexec_SCRIPTS
6657 @vindex pkgdata_SCRIPTS
6658 @vindex noinst_SCRIPTS
6659 @vindex check_SCRIPTS
6661 Scripts can be installed in @code{bindir}, @code{sbindir},
6662 @code{libexecdir}, or @code{pkgdatadir}.
6664 Scripts that need not being installed can be listed in
6665 @code{noinst_SCRIPTS}, and among them, those which are needed only by
6666 @samp{make check} should go in @code{check_SCRIPTS}.
6668 When a script needs to be built, the @file{Makefile.am} should include
6669 the appropriate rules.  For instance the @command{automake} program
6670 itself is a Perl script that is generated from @file{automake.in}.
6671 Here is how this is handled:
6673 @example
6674 bin_SCRIPTS = automake
6675 CLEANFILES = $(bin_SCRIPTS)
6676 EXTRA_DIST = automake.in
6678 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
6679             -e 's,[@@]PERL[@@],$(PERL),g' \
6680             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
6681             -e 's,[@@]VERSION[@@],$(VERSION),g' \
6682             @dots{}
6684 automake: automake.in Makefile
6685         $(do_subst) < $(srcdir)/automake.in > automake
6686         chmod +x automake
6687 @end example
6689 Such scripts for which a build rule has been supplied need to be
6690 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
6691 sources have to be distributed, usually with @code{EXTRA_DIST}
6692 (@pxref{Dist}).
6694 Another common way to build scripts is to process them from
6695 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
6696 Automake knows which files should be cleaned and distributed, and what
6697 the rebuild rules should look like.
6699 For instance if @file{configure.ac} contains
6701 @example
6702 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
6703 @end example
6705 @noindent
6706 to build @file{src/my_script} from @file{src/my_script.in}, then an
6707 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
6708 be as simple as
6710 @example
6711 bin_SCRIPTS = my_script
6712 CLEANFILES = $(bin_SCRIPTS)
6713 @end example
6715 @noindent
6716 There is no need for @code{EXTRA_DIST} or any build rule: Automake
6717 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
6718 @code{CLEANFILES} is still useful, because by default Automake will
6719 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
6720 @code{clean}.
6722 Although this looks simpler, building scripts this way has one
6723 drawback: directory variables such as @code{$(datadir)} are not fully
6724 expanded and may refer to other directory variables.
6726 @node Headers
6727 @section Header files
6729 @cindex @code{_HEADERS} primary, defined
6730 @cindex @code{HEADERS} primary, defined
6731 @cindex Primary variable, @code{HEADERS}
6732 @vindex _HEADERS
6733 @vindex noinst_HEADERS
6734 @cindex @code{HEADERS}, installation directories
6735 @cindex Installing headers
6736 @vindex include_HEADERS
6737 @vindex oldinclude_HEADERS
6738 @vindex pkginclude_HEADERS
6741 Header files that must be installed are specified by the
6742 @code{HEADERS} family of variables.  Headers can be installed in
6743 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
6744 other directory you may have defined (@pxref{Uniform}).  For instance,
6746 @example
6747 include_HEADERS = foo.h bar/bar.h
6748 @end example
6750 @noindent
6751 will install the two files as @file{$(includedir)/foo.h} and
6752 @file{$(includedir)/bar.h}.
6754 The @code{nobase_} prefix is also supported,
6756 @example
6757 nobase_include_HEADERS = foo.h bar/bar.h
6758 @end example
6760 @noindent
6761 will install the two files as @file{$(includedir)/foo.h} and
6762 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
6764 @vindex noinst_HEADERS
6765 Usually, only header files that accompany installed libraries need to
6766 be installed.  Headers used by programs or convenience libraries are
6767 not installed.  The @code{noinst_HEADERS} variable can be used for
6768 such headers.  However when the header actually belongs to one
6769 convenient library or program, we recommend listing it in the
6770 program's or library's @code{_SOURCES} variable (@pxref{Program
6771 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
6772 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
6773 right variable to use in a directory containing only headers and no
6774 associated library or program.
6776 All header files must be listed somewhere; in a @code{_SOURCES}
6777 variable or in a @code{_HEADERS} variable.  Missing ones will not
6778 appear in the distribution.
6780 For header files that are built and must not be distributed, use the
6781 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
6782 @code{nodist_prog_SOURCES}.  If these generated headers are needed
6783 during the build, you must also ensure they exist before they are
6784 used (@pxref{Sources}).
6787 @node Data
6788 @section Architecture-independent data files
6790 @cindex @code{_DATA} primary, defined
6791 @cindex @code{DATA} primary, defined
6792 @cindex Primary variable, @code{DATA}
6793 @vindex _DATA
6795 Automake supports the installation of miscellaneous data files using the
6796 @code{DATA} family of variables.
6797 @vindex DATA
6799 @vindex data_DATA
6800 @vindex sysconf_DATA
6801 @vindex sharedstate_DATA
6802 @vindex localstate_DATA
6803 @vindex pkgdata_DATA
6805 Such data can be installed in the directories @code{datadir},
6806 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
6807 @code{pkgdatadir}.
6809 By default, data files are @emph{not} included in a distribution.  Of
6810 course, you can use the @code{dist_} prefix to change this on a
6811 per-variable basis.
6813 Here is how Automake declares its auxiliary data files:
6815 @example
6816 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
6817 @end example
6820 @node Sources
6821 @section Built sources
6823 Because Automake's automatic dependency tracking works as a side-effect
6824 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
6825 target should not be compiled before its dependencies are made, but
6826 these dependencies are unknown until the target is first compiled.
6828 Ordinarily this is not a problem, because dependencies are distributed
6829 sources: they preexist and do not need to be built.  Suppose that
6830 @file{foo.c} includes @file{foo.h}.  When it first compiles
6831 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
6832 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
6833 records the @file{foo.h} dependency so that following invocations of
6834 @command{make} will honor it.  In these conditions, it's clear there is
6835 no problem: either @file{foo.o} doesn't exist and has to be built
6836 (regardless of the dependencies), or accurate dependencies exist and
6837 they can be used to decide whether @file{foo.o} should be rebuilt.
6839 It's a different story if @file{foo.h} doesn't exist by the first
6840 @command{make} run.  For instance, there might be a rule to build
6841 @file{foo.h}.  This time @file{file.o}'s build will fail because the
6842 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
6843 rule to build @file{foo.h} first by lack of dependency information.
6845 @vindex BUILT_SOURCES
6846 @cindex @code{BUILT_SOURCES}, defined
6848 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
6849 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
6850 or @samp{make check} (or even @samp{make install}) before other
6851 targets are processed.  However, such a source file is not
6852 @emph{compiled} unless explicitly requested by mentioning it in some
6853 other @code{_SOURCES} variable.
6855 So, to conclude our introductory example, we could use
6856 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
6857 any other target (including @file{foo.o}) during @samp{make all} or
6858 @samp{make check}.
6860 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
6861 must be created early in the build process can be listed in this
6862 variable.  Moreover, all built sources do not necessarily have to be
6863 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
6864 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
6865 another source), because it's a known dependency of the associated
6866 object.
6868 It might be important to emphasize that @code{BUILT_SOURCES} is
6869 honored only by @samp{make all}, @samp{make check} and @samp{make
6870 install}.  This means you cannot build a specific target (e.g.,
6871 @samp{make foo}) in a clean tree if it depends on a built source.
6872 However it will succeed if you have run @samp{make all} earlier,
6873 because accurate dependencies are already available.
6875 The next section illustrates and discusses the handling of built sources
6876 on a toy example.
6878 @menu
6879 * Built sources example::       Several ways to handle built sources.
6880 @end menu
6882 @node Built sources example
6883 @subsection Built sources example
6885 Suppose that @file{foo.c} includes @file{bindir.h}, which is
6886 installation-dependent and not distributed: it needs to be built.  Here
6887 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
6888 value of the @command{make} variable @code{bindir} (inherited from
6889 @file{configure}).
6891 We suggest several implementations below.  It's not meant to be an
6892 exhaustive listing of all ways to handle built sources, but it will give
6893 you a few ideas if you encounter this issue.
6895 @unnumberedsubsec First try
6897 This first implementation will illustrate the bootstrap issue mentioned
6898 in the previous section (@pxref{Sources}).
6900 Here is a tentative @file{Makefile.am}.
6902 @example
6903 # This won't work.
6904 bin_PROGRAMS = foo
6905 foo_SOURCES = foo.c
6906 nodist_foo_SOURCES = bindir.h
6907 CLEANFILES = bindir.h
6908 bindir.h: Makefile
6909         echo '#define bindir "$(bindir)"' >$@@
6910 @end example
6912 This setup doesn't work, because Automake doesn't know that @file{foo.c}
6913 includes @file{bindir.h}.  Remember, automatic dependency tracking works
6914 as a side-effect of compilation, so the dependencies of @file{foo.o} will
6915 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
6916 The symptom is as follows.
6918 @example
6919 % make
6920 source='foo.c' object='foo.o' libtool=no \
6921 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
6922 depmode=gcc /bin/sh ./depcomp \
6923 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
6924 foo.c:2: bindir.h: No such file or directory
6925 make: *** [foo.o] Error 1
6926 @end example
6928 In this example @file{bindir.h} is not distributed nor installed, and
6929 it is not even being built on-time.  One may wonder if the
6930 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
6931 line simply states that @file{bindir.h} is a source of @code{foo}, so
6932 for instance, it should be inspected while generating tags
6933 (@pxref{Tags}).  In other words, it does not help our present problem,
6934 and the build would fail identically without it.
6936 @unnumberedsubsec Using @code{BUILT_SOURCES}
6938 A solution is to require @file{bindir.h} to be built before anything
6939 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
6941 @example
6942 bin_PROGRAMS = foo
6943 foo_SOURCES = foo.c
6944 nodist_foo_SOURCES = bindir.h
6945 BUILT_SOURCES = bindir.h
6946 CLEANFILES = bindir.h
6947 bindir.h: Makefile
6948         echo '#define bindir "$(bindir)"' >$@@
6949 @end example
6951 See how @file{bindir.h} get built first:
6953 @example
6954 % make
6955 echo '#define bindir "/usr/local/bin"' >bindir.h
6956 make  all-am
6957 make[1]: Entering directory `/home/adl/tmp'
6958 source='foo.c' object='foo.o' libtool=no \
6959 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
6960 depmode=gcc /bin/sh ./depcomp \
6961 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
6962 gcc  -g -O2   -o foo  foo.o
6963 make[1]: Leaving directory `/home/adl/tmp'
6964 @end example
6966 However, as said earlier, @code{BUILT_SOURCES} applies only to the
6967 @code{all}, @code{check}, and @code{install} targets.  It still fails
6968 if you try to run @samp{make foo} explicitly:
6970 @example
6971 % make clean
6972 test -z "bindir.h" || rm -f bindir.h
6973 test -z "foo" || rm -f foo
6974 rm -f *.o
6975 % : > .deps/foo.Po # Suppress previously recorded dependencies
6976 % make foo
6977 source='foo.c' object='foo.o' libtool=no \
6978 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
6979 depmode=gcc /bin/sh ./depcomp \
6980 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
6981 foo.c:2: bindir.h: No such file or directory
6982 make: *** [foo.o] Error 1
6983 @end example
6985 @unnumberedsubsec Recording dependencies manually
6987 Usually people are happy enough with @code{BUILT_SOURCES} because they
6988 never build targets such as @samp{make foo} before @samp{make all}, as
6989 in the previous example.  However if this matters to you, you can
6990 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
6991 the @file{Makefile.am}.
6993 @example
6994 bin_PROGRAMS = foo
6995 foo_SOURCES = foo.c
6996 nodist_foo_SOURCES = bindir.h
6997 foo.$(OBJEXT): bindir.h
6998 CLEANFILES = bindir.h
6999 bindir.h: Makefile
7000         echo '#define bindir "$(bindir)"' >$@@
7001 @end example
7003 You don't have to list @emph{all} the dependencies of @file{foo.o}
7004 explicitly, only those that might need to be built.  If a dependency
7005 already exists, it will not hinder the first compilation and will be
7006 recorded by the normal dependency tracking code.  (Note that after
7007 this first compilation the dependency tracking code will also have
7008 recorded the dependency between @file{foo.o} and
7009 @file{bindir.h}; so our explicit dependency is really useful to
7010 the first build only.)
7012 Adding explicit dependencies like this can be a bit dangerous if you are
7013 not careful enough.  This is due to the way Automake tries not to
7014 overwrite your rules (it assumes you know better than it).
7015 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7016 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7017 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7018 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7019 Always check the generated @file{Makefile.in} if you do this.
7021 @unnumberedsubsec Build @file{bindir.h} from @file{configure}
7023 It's possible to define this preprocessor macro from @file{configure},
7024 either in @file{config.h} (@pxref{Defining Directories, , Defining
7025 Directories, autoconf, The Autoconf Manual}), or by processing a
7026 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7027 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7028 Autoconf Manual}).
7030 At this point it should be clear that building @file{bindir.h} from
7031 @file{configure} work well for this example.  @file{bindir.h} will exist
7032 before you build any target, hence will not cause any dependency issue.
7034 The Makefile can be shrunk as follows.  We do not even have to mention
7035 @file{bindir.h}.
7037 @example
7038 bin_PROGRAMS = foo
7039 foo_SOURCES = foo.c
7040 @end example
7042 However, it's not always possible to build sources from
7043 @file{configure}, especially when these sources are generated by a tool
7044 that needs to be built first...
7046 @unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
7048 Another attractive idea is to define @code{bindir} as a variable or
7049 function exported from @file{bindir.o}, and build @file{bindir.c}
7050 instead of @file{bindir.h}.
7052 @example
7053 noinst_PROGRAMS = foo
7054 foo_SOURCES = foo.c bindir.h
7055 nodist_foo_SOURCES = bindir.c
7056 CLEANFILES = bindir.c
7057 bindir.c: Makefile
7058         echo 'const char bindir[] = "$(bindir)";' >$@@
7059 @end example
7061 @file{bindir.h} contains just the variable's declaration and doesn't
7062 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7063 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7064 first.
7066 @unnumberedsubsec Which is best?
7068 There is no panacea, of course.  Each solution has its merits and
7069 drawbacks.
7071 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7072 foo} on a clean tree is important to you.
7074 You won't add explicit dependencies if you are leery of overriding
7075 an Automake rule by mistake.
7077 Building files from @file{./configure} is not always possible, neither
7078 is converting @file{.h} files into @file{.c} files.
7081 @node Other GNU Tools
7082 @chapter Other GNU Tools
7084 Since Automake is primarily intended to generate @file{Makefile.in}s for
7085 use in GNU programs, it tries hard to interoperate with other GNU tools.
7087 @menu
7088 * Emacs Lisp::                  Emacs Lisp
7089 * gettext::                     Gettext
7090 * Libtool::                     Libtool
7091 * Java::                        Java
7092 * Python::                      Python
7093 @end menu
7096 @node Emacs Lisp
7097 @section Emacs Lisp
7099 @cindex @code{_LISP} primary, defined
7100 @cindex @code{LISP} primary, defined
7101 @cindex Primary variable, @code{LISP}
7103 @vindex _LISP
7104 @vindex lisp_LISP
7105 @vindex noinst_LISP
7107 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7108 is used to hold a list of @file{.el} files.  Possible prefixes for this
7109 primary are @code{lisp_} and @code{noinst_}.  Note that if
7110 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7111 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7113 @vindex dist_lisp_LISP
7114 @vindex dist_noinst_LISP
7115 Lisp sources are not distributed by default.  You can prefix the
7116 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7117 @code{dist_noinst_LISP}, to indicate that these files should be
7118 distributed.
7120 Automake will byte-compile all Emacs Lisp source files using the Emacs
7121 found by @code{AM_PATH_LISPDIR}, if any was found.
7123 Byte-compiled Emacs Lisp files are not portable among all versions of
7124 Emacs, so it makes sense to turn this off if you expect sites to have
7125 more than one version of Emacs installed.  Furthermore, many packages
7126 don't actually benefit from byte-compilation.  Still, we recommend
7127 that you byte-compile your Emacs Lisp sources.  It is probably better
7128 for sites with strange setups to cope for themselves than to make the
7129 installation less nice for everybody else.
7131 There are two ways to avoid byte-compiling.  Historically, we have
7132 recommended the following construct.
7133 @example
7134 lisp_LISP = file1.el file2.el
7135 ELCFILES =
7136 @end example
7137 @noindent
7138 @code{ELCFILES} is an internal Automake variable that normally lists
7139 all @file{.elc} files that must be byte-compiled.  Automake defines
7140 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7141 variable explicitly prevents byte-compilation to occur.
7143 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead.  As
7145 @example
7146 lisp_DATA = file1.el file2.el
7147 @end example
7149 Note that these two constructs are not equivalent.  @code{_LISP} will
7150 not install a file if Emacs is not installed, while @code{_DATA} will
7151 always install its files.
7153 @node gettext
7154 @section Gettext
7156 @cindex GNU Gettext support
7157 @cindex Gettext support
7158 @cindex Support for GNU Gettext
7160 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7161 turns on support for GNU gettext, a message catalog system for
7162 internationalization
7163 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7165 The @code{gettext} support in Automake requires the addition of one or
7166 two subdirectories to the package, @file{po} and possibly also @file{intl}.
7167 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7168 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7169 Automake ensures that these directories exist and are mentioned in
7170 @code{SUBDIRS}.
7172 @node Libtool
7173 @section Libtool
7175 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7176 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7177 @xref{A Shared Library}.
7180 @node Java
7181 @section Java
7183 @cindex @code{_JAVA} primary, defined
7184 @cindex @code{JAVA} primary, defined
7185 @cindex Primary variable, @code{JAVA}
7187 Automake provides some minimal support for Java compilation with the
7188 @code{JAVA} primary.
7190 Any @file{.java} files listed in a @code{_JAVA} variable will be
7191 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7192 files are not included in the distribution, you should use the
7193 @code{dist_} prefix to distribute them.
7195 Here is a typical setup for distributing @file{.java} files and
7196 installing the @file{.class} files resulting from their compilation.
7198 @example
7199 javadir = $(datadir)/java
7200 dist_java_JAVA = a.java b.java @dots{}
7201 @end example
7203 @cindex @code{JAVA} restrictions
7204 @cindex Restrictions for @code{JAVA}
7206 Currently Automake enforces the restriction that only one @code{_JAVA}
7207 primary can be used in a given @file{Makefile.am}.  The reason for this
7208 restriction is that, in general, it isn't possible to know which
7209 @file{.class} files were generated from which @file{.java} files, so
7210 it would be impossible to know which files to install where.  For
7211 instance, a @file{.java} file can define multiple classes; the resulting
7212 @file{.class} file names cannot be predicted without parsing the
7213 @file{.java} file.
7215 There are a few variables that are used when compiling Java sources:
7217 @vtable @code
7218 @item JAVAC
7219 The name of the Java compiler.  This defaults to @samp{javac}.
7221 @item JAVACFLAGS
7222 The flags to pass to the compiler.  This is considered to be a user
7223 variable (@pxref{User Variables}).
7225 @item AM_JAVACFLAGS
7226 More flags to pass to the Java compiler.  This, and not
7227 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7228 compiler flags into @file{Makefile.am}.
7230 @item JAVAROOT
7231 The value of this variable is passed to the @option{-d} option to
7232 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7234 @item CLASSPATH_ENV
7235 This variable is an @code{sh} expression that is used to set the
7236 @env{CLASSPATH} environment variable on the @code{javac} command line.
7237 (In the future we will probably handle class path setting differently.)
7238 @end vtable
7241 @node Python
7242 @section Python
7244 @cindex @code{_PYTHON} primary, defined
7245 @cindex @code{PYTHON} primary, defined
7246 @cindex Primary variable, @code{PYTHON}
7247 @vindex _PYTHON
7249 Automake provides support for Python compilation with the
7250 @code{PYTHON} primary.  A typical setup is to call
7251 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7252 following in @file{Makefile.am}:
7254 @example
7255 python_PYTHON = tree.py leave.py
7256 @end example
7258 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7259 with @command{py-compile} at install time.  @command{py-compile}
7260 actually creates both standard (@file{.pyc}) and optimized
7261 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7262 because byte-compilation occurs at install time, any files listed in
7263 @code{noinst_PYTHON} will not be compiled.  Python source files are
7264 included in the distribution by default, prepend @code{nodist_} (as in
7265 @code{nodist_python_PYTHON}) to omit them.
7267 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7268 that will determine some Python-related directory variables (see
7269 below).  If you have called @code{AM_PATH_PYTHON} from
7270 @file{configure.ac}, then you may use the variables
7271 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7272 files in your @file{Makefile.am}, depending where you want your files
7273 installed (see the definitions of @code{pythondir} and
7274 @code{pkgpythondir} below).
7276 @defmac AM_PATH_PYTHON ([@var{VERSION}], [@var{ACTION-IF-FOUND}], [@var{ACTION-IF-NOT-FOUND}])
7278 Search for a Python interpreter on the system.  This macro takes three
7279 optional arguments.  The first argument, if present, is the minimum
7280 version of Python required for this package: @code{AM_PATH_PYTHON}
7281 will skip any Python interpreter that is older than @var{VERSION}.
7282 If an interpreter is found and satisfies @var{VERSION}, then
7283 @var{ACTION-IF-FOUND} is run.  Otherwise, @var{ACTION-IF-NOT-FOUND} is
7284 run.
7286 If @var{ACTION-IF-NOT-FOUND} is not specified, as in the following
7287 example, the default is to abort @command{configure}.
7289 @example
7290 AM_PATH_PYTHON([2.2])
7291 @end example
7293 @noindent
7294 This is fine when Python is an absolute requirement for the package.
7295 If Python >= 2.2 was only @emph{optional} to the package,
7296 @code{AM_PATH_PYTHON} could be called as follows.
7298 @example
7299 AM_PATH_PYTHON([2.2],, [:])
7300 @end example
7302 @code{AM_PATH_PYTHON} creates the following output variables based on
7303 the Python installation found during configuration.
7304 @end defmac
7306 @vtable @code
7307 @item PYTHON
7308 The name of the Python executable, or @samp{:} if no suitable
7309 interpreter could be found.
7311 Assuming @var{ACTION-IF-NOT-FOUND} is used (otherwise @file{./configure}
7312 will abort if Python is absent), the value of @code{PYTHON} can be used
7313 to setup a conditional in order to disable the relevant part of a build
7314 as follows.
7316 @example
7317   AM_PATH_PYTHON(,, [:])
7318   AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7319 @end example
7321 @item PYTHON_VERSION
7322 The Python version number, in the form @var{major}.@var{minor}
7323 (e.g., @samp{1.5}).  This is currently the value of
7324 @samp{sys.version[:3]}.
7326 @item PYTHON_PREFIX
7327 The string @samp{$@{prefix@}}.  This term may be used in future work
7328 that needs the contents of Python's @samp{sys.prefix}, but general
7329 consensus is to always use the value from configure.
7331 @item PYTHON_EXEC_PREFIX
7332 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7333 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7334 consensus is to always use the value from configure.
7336 @item PYTHON_PLATFORM
7337 The canonical name used by Python to describe the operating system, as
7338 given by @samp{sys.platform}.  This value is sometimes needed when
7339 building Python extensions.
7341 @item pythondir
7342 The directory name for the @file{site-packages} subdirectory of the
7343 standard Python install tree.
7345 @item pkgpythondir
7346 This is the directory under @code{pythondir} that is named after the
7347 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7348 as a convenience.
7350 @item pyexecdir
7351 This is the directory where Python extension modules (shared libraries)
7352 should be installed.  An extension module written in C could be declared
7353 as follows to Automake:
7355 @example
7356 pyexec_LTLIBRARIES = quaternion.la
7357 quaternion_SOURCES = quaternion.c support.c support.h
7358 quaternion_la_LDFLAGS = -avoid-version -module
7359 @end example
7361 @item pkgpyexecdir
7362 This is a convenience variable that is defined as
7363 @samp{$(pyexecdir)/$(PACKAGE)}.
7364 @end vtable
7366 All these directory variables have values that start with either
7367 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7368 fine in @file{Makefiles}, but it makes these variables hard to use in
7369 @file{configure}.  This is mandated by the GNU coding standards, so
7370 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7371 manual has a section with more details on this topic
7372 (@pxref{Installation Directory Variables, , Installation Directory
7373 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7374 Install Paths}.
7377 @node Documentation
7378 @chapter Building documentation
7380 Currently Automake provides support for Texinfo and man pages.
7382 @menu
7383 * Texinfo::                     Texinfo
7384 * Man pages::                   Man pages
7385 @end menu
7388 @node Texinfo
7389 @section Texinfo
7391 @cindex @code{_TEXINFOS} primary, defined
7392 @cindex @code{TEXINFOS} primary, defined
7393 @cindex Primary variable, @code{TEXINFOS}
7394 @cindex HTML output using Texinfo
7395 @cindex PDF output using Texinfo
7396 @cindex PS output using Texinfo
7397 @cindex DVI output using Texinfo
7398 @vindex _TEXINFOS
7399 @vindex info_TEXINFOS
7401 If the current directory contains Texinfo source, you must declare it
7402 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7403 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7404 here.  Any Texinfo source file must end in the @file{.texi},
7405 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7406 for new manuals.
7408 Automake generates rules to build @file{.info}, @file{.dvi},
7409 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7410 sources.  Following the GNU Coding Standards, only the @file{.info}
7411 files are built by @samp{make all} and installed by @samp{make
7412 install} (unless you use @option{no-installinfo}, see below).
7413 Furthermore, @file{.info} files are automatically distributed so that
7414 Texinfo is not a prerequisite for installing your package.
7416 @trindex dvi
7417 @trindex html
7418 @trindex pdf
7419 @trindex ps
7420 @trindex install-dvi
7421 @trindex install-html
7422 @trindex install-pdf
7423 @trindex install-ps
7424 Other documentation formats can be built on request by @samp{make
7425 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7426 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7427 @samp{make install-pdf} and @samp{make install-html} explicitly.
7428 @samp{make uninstall} will remove everything: the Texinfo
7429 documentation installed by default as well as all the above optional
7430 formats.
7432 All these targets can be extended using @samp{-local} rules
7433 (@pxref{Extending}).
7435 @cindex Texinfo flag, @code{VERSION}
7436 @cindex Texinfo flag, @code{UPDATED}
7437 @cindex Texinfo flag, @code{EDITION}
7438 @cindex Texinfo flag, @code{UPDATED-MONTH}
7440 @cindex @code{VERSION} Texinfo flag
7441 @cindex @code{UPDATED} Texinfo flag
7442 @cindex @code{EDITION} Texinfo flag
7443 @cindex @code{UPDATED-MONTH} Texinfo flag
7445 @cindex @file{mdate-sh}
7447 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7448 that file will be automatically generated.  The file @file{version.texi}
7449 defines four Texinfo flag you can reference using
7450 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7451 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7453 @table @code
7454 @item EDITION
7455 @itemx VERSION
7456 Both of these flags hold the version number of your program.  They are
7457 kept separate for clarity.
7459 @item UPDATED
7460 This holds the date the primary @file{.texi} file was last modified.
7462 @item UPDATED-MONTH
7463 This holds the name of the month in which the primary @file{.texi} file
7464 was last modified.
7465 @end table
7467 The @file{version.texi} support requires the @command{mdate-sh}
7468 script; this script is supplied with Automake and automatically
7469 included when @command{automake} is invoked with the
7470 @option{--add-missing} option.
7472 If you have multiple Texinfo files, and you want to use the
7473 @file{version.texi} feature, then you have to have a separate version
7474 file for each Texinfo file.  Automake will treat any include in a
7475 Texinfo file that matches @file{vers*.texi} just as an automatically
7476 generated version file.
7478 Sometimes an info file actually depends on more than one @file{.texi}
7479 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7480 @file{gpl.texi}.  You can tell Automake about these dependencies using
7481 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7482 @vindex TEXINFOS
7483 @vindex _TEXINFOS
7485 @example
7486 info_TEXINFOS = hello.texi
7487 hello_TEXINFOS = gpl.texi
7488 @end example
7490 @cindex @file{texinfo.tex}
7492 By default, Automake requires the file @file{texinfo.tex} to appear in
7493 the same directory as the @file{Makefile.am} file that lists the
7494 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7495 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7496 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7497 there.  In both cases, automake then supplies @file{texinfo.tex} if
7498 @option{--add-missing} is given, and takes care of its distribution.
7499 However, if you set the @code{TEXINFO_TEX} variable (see below),
7500 it overrides the location of the file and turns off its installation
7501 into the source as well as its distribution.
7503 The option @option{no-texinfo.tex} can be used to eliminate the
7504 requirement for the file @file{texinfo.tex}.  Use of the variable
7505 @code{TEXINFO_TEX} is preferable, however, because that allows the
7506 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7508 @cindex Option, @code{no-installinfo}
7509 @cindex Target, @code{install-info}
7510 @cindex @code{install-info} target
7511 @cindex @code{no-installinfo} option
7513 @opindex no-installinfo
7514 @trindex install-info
7516 Automake generates an @code{install-info} rule; some people apparently
7517 use this.  By default, info pages are installed by @samp{make
7518 install}, so running @code{make install-info} is pointless.  This can
7519 be prevented via the @code{no-installinfo} option.  In this case,
7520 @file{.info} files are not installed by default, and user must
7521 request this explicitly using @samp{make install-info}
7523 The following variables are used by the Texinfo build rules.
7525 @vtable @code
7526 @item MAKEINFO
7527 The name of the program invoked to build @file{.info} files.  This
7528 variable is defined by Automake.  If the @command{makeinfo} program is
7529 found on the system then it will be used by default; otherwise
7530 @command{missing} will be used instead.
7532 @item MAKEINFOHTML
7533 The command invoked to build @file{.html} files.  Automake
7534 defines this to @samp{$(MAKEINFO) --html}.
7536 @item MAKEINFOFLAGS
7537 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7538 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7539 not expected to be defined in any @file{Makefile}; it can be used by
7540 users to pass extra flags to suit their needs.
7542 @item AM_MAKEINFOFLAGS
7543 @itemx AM_MAKEINFOHTMLFLAGS
7544 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7545 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7546 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7547 passed to @code{makeinfo} when building @file{.info} files; and
7548 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7549 files.
7551 For instance, the following setting can be used to obtain one single
7552 @file{.html} file per manual, without node separators.
7553 @example
7554 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7555 @end example
7557 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7558 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7559 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7560 and @file{.html} files.
7562 @item TEXI2DVI
7563 The name of the command that converts a @file{.texi} file into a
7564 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7565 with the Texinfo package.
7567 @item TEXI2PDF
7568 The name of the command that translates a @file{.texi} file into a
7569 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7571 @item DVIPS
7572 The name of the command that build a @file{.ps} file out of a
7573 @file{.dvi} file.  This defaults to @samp{dvips}.
7575 @item TEXINFO_TEX
7577 If your package has Texinfo files in many directories, you can use the
7578 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7579 @file{texinfo.tex} for your package.  The value of this variable should
7580 be the relative path from the current @file{Makefile.am} to
7581 @file{texinfo.tex}:
7583 @example
7584 TEXINFO_TEX = ../doc/texinfo.tex
7585 @end example
7586 @end vtable
7589 @node Man pages
7590 @section Man pages
7592 @cindex @code{_MANS} primary, defined
7593 @cindex @code{MANS} primary, defined
7594 @cindex Primary variable, @code{MANS}
7596 @vindex _MANS
7597 @vindex man_MANS
7598 A package can also include man pages (but see the GNU standards on this
7599 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7600 pages are declared using the @code{MANS} primary.  Generally the
7601 @code{man_MANS} variable is used.  Man pages are automatically installed in
7602 the correct subdirectory of @code{mandir}, based on the file extension.
7604 File extensions such as @file{.1c} are handled by looking for the valid
7605 part of the extension and using that to determine the correct
7606 subdirectory of @code{mandir}.  Valid section names are the digits
7607 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7609 Sometimes developers prefer to name a man page something like
7610 @file{foo.man} in the source, and then rename it to have the correct
7611 suffix, for example @file{foo.1}, when installing the file.  Automake
7612 also supports this mode.  For a valid section named @var{SECTION},
7613 there is a corresponding directory named @samp{man@var{SECTION}dir},
7614 and a corresponding @code{_MANS} variable.  Files listed in such a
7615 variable are installed in the indicated section.  If the file already
7616 has a valid suffix, then it is installed as-is; otherwise the file
7617 suffix is changed to match the section.
7619 For instance, consider this example:
7620 @example
7621 man1_MANS = rename.man thesame.1 alsothesame.1c
7622 @end example
7624 In this case, @file{rename.man} will be renamed to @file{rename.1} when
7625 installed, but the other files will keep their names.
7627 @cindex Target, @code{install-man}
7628 @cindex Option, @option{no-installman}
7629 @cindex @code{install-man} target
7630 @cindex @option{no-installman} option
7631 @opindex no-installman
7632 @trindex install-man
7634 By default, man pages are installed by @samp{make install}.  However,
7635 since the GNU project does not require man pages, many maintainers do
7636 not expend effort to keep the man pages up to date.  In these cases, the
7637 @option{no-installman} option will prevent the man pages from being
7638 installed by default.  The user can still explicitly install them via
7639 @samp{make install-man}.
7641 Man pages are not currently considered to be source, because it is not
7642 uncommon for man pages to be automatically generated.  Therefore they
7643 are not automatically included in the distribution.  However, this can
7644 be changed by use of the @code{dist_} prefix.  For instance here is
7645 how to distribute and install the two man pages of GNU @command{cpio}
7646 (which includes both Texinfo documentation and man pages):
7648 @example
7649 dist_man_MANS = cpio.1 mt.1
7650 @end example
7652 The @code{nobase_} prefix is meaningless for man pages and is
7653 disallowed.
7655 @vindex notrans_
7656 @cindex @code{notrans_} prefix
7657 @cindex Man page renaming, avoiding
7658 @cindex Avoiding man page renaming
7660 Executables and manpages may be renamed upon installation
7661 (@pxref{Renaming}).  For manpages this can be avoided by use of the
7662 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
7663 allowing to access a library function @samp{foo} from the command line.
7664 The way to avoid renaming of the @file{foo.3} manpage is:
7666 @example
7667 man_MANS = foo.1
7668 notrans_man_MANS = foo.3
7669 @end example
7671 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
7672 @cindex @code{dist_} and @code{notrans_}
7673 @cindex @code{nodist_} and @code{notrans_}
7675 @samp{notrans_} must be specified first when used in conjunction with
7676 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
7678 @example
7679 notrans_dist_man3_MANS = bar.3
7680 @end example
7682 @node Install
7683 @chapter What Gets Installed
7685 @cindex Installation support
7686 @cindex @samp{make install} support
7688 @section Basics of installation
7690 Naturally, Automake handles the details of actually installing your
7691 program once it has been built.  All files named by the various
7692 primaries are automatically installed in the appropriate places when the
7693 user runs @samp{make install}.
7695 A file named in a primary is installed by copying the built file into
7696 the appropriate directory.  The base name of the file is used when
7697 installing.
7699 @example
7700 bin_PROGRAMS = hello subdir/goodbye
7701 @end example
7703 In this example, both @samp{hello} and @samp{goodbye} will be installed
7704 in @samp{$(bindir)}.
7706 Sometimes it is useful to avoid the basename step at install time.  For
7707 instance, you might have a number of header files in subdirectories of
7708 the source tree that are laid out precisely how you want to install
7709 them.  In this situation you can use the @code{nobase_} prefix to
7710 suppress the base name step.  For example:
7712 @example
7713 nobase_include_HEADERS = stdio.h sys/types.h
7714 @end example
7716 Will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
7717 in @samp{$(includedir)/sys}.
7719 @section The two parts of install
7721 Automake generates separate @code{install-data} and @code{install-exec}
7722 rules, in case the installer is installing on multiple machines that
7723 share directory structure---these targets allow the machine-independent
7724 parts to be installed only once.  @code{install-exec} installs
7725 platform-dependent files, and @code{install-data} installs
7726 platform-independent files.  The @code{install} target depends on both
7727 of these targets.  While Automake tries to automatically segregate
7728 objects into the correct category, the @file{Makefile.am} author is, in
7729 the end, responsible for making sure this is done correctly.
7730 @trindex install-data
7731 @trindex install-exec
7732 @trindex install
7733 @cindex Install, two parts of
7735 Variables using the standard directory prefixes @samp{data},
7736 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
7737 @samp{pkgdata}, or @samp{pkginclude} are installed by
7738 @code{install-data}.
7740 Variables using the standard directory prefixes @samp{bin},
7741 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
7742 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
7744 For instance, @code{data_DATA} files are installed by @code{install-data},
7745 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
7747 Any variable using a user-defined directory prefix with @samp{exec} in
7748 the name (e.g., @code{myexecbin_PROGRAMS}) is installed by
7749 @code{install-exec}.  All other user-defined prefixes are installed by
7750 @code{install-data}.
7752 @section Extending installation
7754 It is possible to extend this mechanism by defining an
7755 @code{install-exec-local} or @code{install-data-local} rule.  If these
7756 rules exist, they will be run at @samp{make install} time.  These
7757 rules can do almost anything; care is required.
7758 @trindex install-exec-local
7759 @trindex install-data-local
7761 Automake also supports two install hooks, @code{install-exec-hook} and
7762 @code{install-data-hook}.  These hooks are run after all other install
7763 rules of the appropriate type, exec or data, have completed.  So, for
7764 instance, it is possible to perform post-installation modifications
7765 using an install hook.  @ref{Extending} gives some examples.
7766 @cindex Install hook
7768 @section Staged installs
7770 @vindex DESTDIR
7771 Automake generates support for the @code{DESTDIR} variable in all
7772 install rules.  @code{DESTDIR} is used during the @samp{make install}
7773 step to relocate install objects into a staging area.  Each object and
7774 path is prefixed with the value of @code{DESTDIR} before being copied
7775 into the install area.  Here is an example of typical DESTDIR usage:
7777 @example
7778 mkdir /tmp/staging &&
7779 make DESTDIR=/tmp/staging install
7780 @end example
7782 The @command{mkdir} command avoids a security problem if the attacker
7783 creates a symbolic link from @file{/tmp/staging} to a victim area;
7784 then @command{make} places install objects in a directory tree built under
7785 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
7786 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
7787 would install @file{/tmp/staging/gnu/bin/foo} and
7788 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
7790 This feature is commonly used to build install images and packages
7791 (@pxref{DESTDIR}).
7793 Support for @code{DESTDIR} is implemented by coding it directly into
7794 the install rules.  If your @file{Makefile.am} uses a local install
7795 rule (e.g., @code{install-exec-local}) or an install hook, then you
7796 must write that code to respect @code{DESTDIR}.
7798 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
7799 for another usage example.
7801 @section Rules for the user
7803 Automake also generates rules for targets @code{uninstall},
7804 @code{installdirs}, and @code{install-strip}.
7805 @trindex uninstall
7806 @trindex installdirs
7807 @trindex install-strip
7809 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
7810 There is no notion of separate uninstalls for ``exec'' and ``data'', as
7811 these features would not provide additional functionality.
7813 Note that @code{uninstall} is not meant as a replacement for a real
7814 packaging tool.
7817 @node Clean
7818 @chapter What Gets Cleaned
7820 @cindex @samp{make clean} support
7822 The GNU Makefile Standards specify a number of different clean rules.
7823 @xref{Standard Targets, , Standard Targets for Users, standards,
7824 The GNU Coding Standards}.
7826 Generally the files that can be cleaned are determined automatically by
7827 Automake.  Of course, Automake also recognizes some variables that can
7828 be defined to specify additional files to clean.  These variables are
7829 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
7830 @code{MAINTAINERCLEANFILES}.
7831 @vindex MOSTLYCLEANFILES
7832 @vindex CLEANFILES
7833 @vindex DISTCLEANFILES
7834 @vindex MAINTAINERCLEANFILES
7836 @trindex mostlyclean-local
7837 @trindex clean-local
7838 @trindex distclean-local
7839 @trindex maintainer-clean-local
7840 When cleaning involves more than deleting some hard-coded list of
7841 files, it is also possible to supplement the cleaning rules with your
7842 own commands.  Simply define a rule for any of the
7843 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
7844 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
7845 case is deleting a directory, for instance, a directory created by the
7846 test suite:
7848 @example
7849 clean-local:
7850         -rm -rf testSubDir
7851 @end example
7853 As the GNU Standards aren't always explicit as to which files should
7854 be removed by which rule, we've adopted a heuristic that we believe
7855 was first formulated by Fran@,{c}ois Pinard:
7857 @itemize @bullet
7858 @item
7859 If @command{make} built it, and it is commonly something that one would
7860 want to rebuild (for instance, a @file{.o} file), then
7861 @code{mostlyclean} should delete it.
7863 @item
7864 Otherwise, if @command{make} built it, then @code{clean} should delete it.
7866 @item
7867 If @command{configure} built it, then @code{distclean} should delete it.
7869 @item
7870 If the maintainer built it (for instance, a @file{.info} file), then
7871 @code{maintainer-clean} should delete it.  However
7872 @code{maintainer-clean} should not delete anything that needs to exist
7873 in order to run @samp{./configure && make}.
7874 @end itemize
7876 We recommend that you follow this same set of heuristics in your
7877 @file{Makefile.am}.
7880 @node Dist
7881 @chapter What Goes in a Distribution
7883 @section Basics of distribution
7885 @cindex @samp{make dist}
7887 @vindex PACKAGE
7888 @vindex VERSION
7889 @trindex dist
7890 The @code{dist} rule in the generated @file{Makefile.in} can be used
7891 to generate a gzipped @code{tar} file and other flavors of archive for
7892 distribution.  The files is named based on the @code{PACKAGE} and
7893 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
7894 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
7895 @samp{@var{package}-@var{version}.tar.gz}.
7896 @vindex GZIP_ENV
7897 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
7898 is run.  The default setting is @option{--best}.
7900 @cindex @code{m4_include}, distribution
7901 @cindex @code{include}, distribution
7902 @acindex m4_include
7903 @cmindex include
7904 For the most part, the files to distribute are automatically found by
7905 Automake: all source files are automatically included in a distribution,
7906 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
7907 has a built-in list of commonly used files that are automatically
7908 included if they are found in the current directory (either physically,
7909 or as the target of a @file{Makefile.am} rule).  This list is printed by
7910 @samp{automake --help}.  Also, files that are read by @command{configure}
7911 (i.e.@: the source files corresponding to the files specified in various
7912 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
7913 automatically distributed.  Files included in @file{Makefile.am}s (using
7914 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
7915 helper scripts installed with @samp{automake --add-missing} are also
7916 distributed.
7918 @vindex EXTRA_DIST
7919 Still, sometimes there are files that must be distributed, but which
7920 are not covered in the automatic rules.  These files should be listed in
7921 the @code{EXTRA_DIST} variable.  You can mention files from
7922 subdirectories in @code{EXTRA_DIST}.
7924 You can also mention a directory in @code{EXTRA_DIST}; in this case the
7925 entire directory will be recursively copied into the distribution.
7926 Please note that this will also copy @emph{everything} in the directory,
7927 including CVS/RCS version control files.  We recommend against using
7928 this feature.
7930 @vindex SUBDIRS
7931 @vindex DIST_SUBDIRS
7932 If you define @code{SUBDIRS}, Automake will recursively include the
7933 subdirectories in the distribution.  If @code{SUBDIRS} is defined
7934 conditionally (@pxref{Conditionals}), Automake will normally include
7935 all directories that could possibly appear in @code{SUBDIRS} in the
7936 distribution.  If you need to specify the set of directories
7937 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
7938 exact list of subdirectories to include in the distribution
7939 (@pxref{Conditional Subdirectories}).
7942 @section Fine-grained distribution control
7944 @vindex dist_
7945 @vindex nodist_
7946 Sometimes you need tighter control over what does @emph{not} go into the
7947 distribution; for instance, you might have source files that are
7948 generated and that you do not want to distribute.  In this case
7949 Automake gives fine-grained control using the @code{dist} and
7950 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
7951 prefixed with @code{dist_} to add the listed files to the distribution.
7952 Similarly, @code{nodist_} can be used to omit the files from the
7953 distribution.
7955 As an example, here is how you would cause some data to be distributed
7956 while leaving some source code out of the distribution:
7958 @example
7959 dist_data_DATA = distribute-this
7960 bin_PROGRAMS = foo
7961 nodist_foo_SOURCES = do-not-distribute.c
7962 @end example
7964 @section The dist hook
7966 @trindex dist-hook
7968 Occasionally it is useful to be able to change the distribution before
7969 it is packaged up.  If the @code{dist-hook} rule exists, it is run
7970 after the distribution directory is filled, but before the actual tar
7971 (or shar) file is created.  One way to use this is for distributing
7972 files in subdirectories for which a new @file{Makefile.am} is overkill:
7974 @example
7975 dist-hook:
7976         mkdir $(distdir)/random
7977         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
7978 @end example
7980 Another way to use this is for removing unnecessary files that get
7981 recursively included by specifying a directory in EXTRA_DIST:
7983 @example
7984 EXTRA_DIST = doc
7986 dist-hook:
7987         rm -rf `find $(distdir)/doc -name CVS`
7988 @end example
7990 @vindex distdir
7991 @vindex top_distdir
7992 Two variables that come handy when writing @code{dist-hook} rules are
7993 @samp{$(distdir)} and @samp{$(top_distdir)}.
7995 @samp{$(distdir)} points to the directory where the @code{dist} rule
7996 will copy files from the current directory before creating the
7997 tarball.  If you are at the top-level directory, then @samp{distdir =
7998 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
7999 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8000 @samp{$(distdir)} can be a relative or absolute path, do not assume
8001 any form.
8003 @samp{$(top_distdir)} always points to the root directory of the
8004 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8005 In the @file{foo/} subdirectory
8006 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8007 @samp{$(top_distdir)} too can be a relative or absolute path.
8009 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8010 (@pxref{Subpackages}), then @samp{$(distdir)} and
8011 @samp{$(top_distdir)} are relative to the package where @samp{make
8012 dist} was run, not to any sub-packages involved.
8014 @section Checking the distribution
8016 @cindex @samp{make distcheck}
8017 @cindex @samp{make distcleancheck}
8018 @vindex distcleancheck_listfiles
8019 @cindex @samp{make distuninstallcheck}
8020 @vindex distuninstallcheck_listfiles
8022 @trindex distcheck
8023 Automake also generates a @code{distcheck} rule that can be of help to
8024 ensure that a given distribution will actually work.  @code{distcheck}
8025 makes a distribution, then tries to do a @code{VPATH} build
8026 (@pxref{VPATH Builds}), run the test suite, and finally make another
8027 tarball to ensure the distribution is self-contained.
8029 @vindex DISTCHECK_CONFIGURE_FLAGS
8030 Building the package involves running @samp{./configure}.  If you need
8031 to supply additional flags to @command{configure}, define them in the
8032 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
8033 @file{Makefile.am}, or on the command line when invoking @command{make}.
8035 @trindex distcheck-hook
8036 If the @code{distcheck-hook} rule is defined in your top-level
8037 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8038 the new distribution has been unpacked, but before the unpacked copy
8039 is configured and built.  Your @code{distcheck-hook} can do almost
8040 anything, though as always caution is advised.  Generally this hook is
8041 used to check for potential distribution errors not caught by the
8042 standard mechanism.  Note that @code{distcheck-hook} as well as
8043 @code{DISTCHECK_CONFIGURE_FLAGS} are not honored in a subpackage
8044 @file{Makefile.am}, but the @code{DISTCHECK_CONFIGURE_FLAGS} are
8045 passed down to the @command{configure} script of the subpackage.
8047 @trindex distcleancheck
8048 @vindex DISTCLEANFILES
8049 @vindex distcleancheck_listfiles
8050 Speaking of potential distribution errors, @code{distcheck} also
8051 ensures that the @code{distclean} rule actually removes all built
8052 files.  This is done by running @samp{make distcleancheck} at the end of
8053 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8054 @code{distclean} and then make sure the build tree has been emptied by
8055 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8056 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8057 variable (@pxref{Clean}).
8059 The @code{distcleancheck} behavior should be OK for most packages,
8060 otherwise you have the possibility to override the definition of
8061 either the @code{distcleancheck} rule, or the
8062 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8063 @code{distcleancheck} completely, add the following rule to your
8064 top-level @file{Makefile.am}:
8066 @example
8067 distcleancheck:
8068         @@:
8069 @end example
8071 If you want @code{distcleancheck} to ignore built files that have not
8072 been cleaned because they are also part of the distribution, add the
8073 following definition instead:
8075 @example
8076 distcleancheck_listfiles = \
8077   find -type f -exec sh -c 'test -f $(srcdir)/@{@} || echo @{@}' ';'
8078 @end example
8080 The above definition is not the default because it's usually an error if
8081 your Makefiles cause some distributed files to be rebuilt when the user
8082 build the package.  (Think about the user missing the tool required to
8083 build the file; or if the required tool is built by your package,
8084 consider the cross-compilation case where it can't be run.)  There is
8085 a FAQ entry about this (@pxref{distcleancheck}), make sure you read it
8086 before playing with @code{distcleancheck_listfiles}.
8088 @code{distcheck} also checks that the @code{uninstall} rule works
8089 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8090 by invoking @samp{make uninstall}, and then it checks the install tree
8091 to see if any files are left over.  This check will make sure that you
8092 correctly coded your @code{uninstall}-related rules.
8094 By default, the checking is done by the @code{distuninstallcheck} rule,
8095 and the list of files in the install tree is generated by
8096 @samp{$(distuninstallcheck_listfiles}) (this is a variable whose value is
8097 a shell command to run that prints the list of files to stdout).
8099 Either of these can be overridden to modify the behavior of
8100 @code{distcheck}.  For instance, to disable this check completely, you
8101 would write:
8103 @example
8104 distuninstallcheck:
8105         @@:
8106 @end example
8108 @section The types of distributions
8110 Automake generates rules to provide archives of the project for
8111 distributions in various formats.  Their targets are:
8113 @table @asis
8114 @item @code{dist-bzip2}
8115 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8116 frequently smaller than gzipped archives.
8117 @trindex dist-bzip2
8119 @item @code{dist-gzip}
8120 Generate a gzip tar archive of the distribution.
8121 @trindex dist-gzip
8123 @item @code{dist-lzma}
8124 Generate a lzma tar archive of the distribution.  lzma archives are
8125 frequently smaller than @command{bzip2}-compressed archives.
8126 @trindex dist-lzma
8128 @item @code{dist-shar}
8129 Generate a shar archive of the distribution.
8130 @trindex dist-shar
8132 @item @code{dist-zip}
8133 Generate a zip archive of the distribution.
8134 @trindex dist-zip
8136 @item @code{dist-tarZ}
8137 Generate a compressed tar archive of
8138 the distribution.
8139 @trindex dist-tarZ
8140 @end table
8142 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8143 create archives in all the enabled formats, @ref{Options}.  By
8144 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8147 @node Tests
8148 @chapter Support for test suites
8150 @cindex Test suites
8151 @cindex @code{make check}
8152 @trindex check
8154 Automake supports two forms of test suites.
8156 @section Simple Tests
8158 If the variable @code{TESTS} is defined, its value is taken to be a
8159 list of programs or scripts to run in order to do the testing.
8160 Programs needing data files should look for them in @code{srcdir}
8161 (which is both an environment variable and a make variable) so they
8162 work when building in a separate directory (@pxref{Build Directories,
8163 , Build Directories , autoconf, The Autoconf Manual}), and in
8164 particular for the @code{distcheck} rule (@pxref{Dist}).
8166 For each of the @code{TESTS}, the result of execution is printed along
8167 with the test name, where @code{PASS} denotes a successful test,
8168 @code{FAIL} denotes a failed test, @code{XFAIL} an expected failure,
8169 @code{XPASS} an unexpected pass for a test that is supposed to fail,
8170 and @code{SKIP} denotes a skipped test.
8172 @cindex Exit status 77, special interpretation
8174 The number of failures will be printed at the end of the run.  If a
8175 given test program exits with a status of 77, then its result is ignored
8176 in the final count.  This feature allows non-portable tests to be
8177 ignored in environments where they don't make sense.
8179 @vindex AM_COLOR_TESTS
8180 If the Automake option @code{color-tests} is used (@pxref{Options})
8181 and standard output is connected to a capable terminal, then the test
8182 results and the summary are colored appropriately.  The user can disable
8183 colored output by setting the @command{make} variable
8184 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8185 terminal with @samp{AM_COLOR_TESTS=always}.
8187 @vindex TESTS
8188 @vindex TESTS_ENVIRONMENT
8189 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
8190 variables for the test run; the environment variable @code{srcdir} is
8191 set in the rule.  If all your test programs are scripts, you can also
8192 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
8193 @samp{$(SHELL) -x} can be useful for debugging the tests), or any other
8194 interpreter.  For instance the following setup is used by the Automake
8195 package to run four tests in Perl.
8196 @example
8197 TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
8198 TESTS = Condition.pl DisjConditions.pl Version.pl Wrap.pl
8199 @end example
8202 @cindex Tests, expected failure
8203 @cindex Expected test failure
8205 You may define the variable @code{XFAIL_TESTS} to a list of tests
8206 (usually a subset of @code{TESTS}) that are expected to fail.  This will
8207 reverse the result of those tests.
8208 @vindex XFAIL_TESTS
8210 Automake ensures that each file listed in @code{TESTS} is built before
8211 any tests are run; you can list both source and derived programs (or
8212 scripts) in @code{TESTS}; the generated rule will look both in
8213 @code{srcdir} and @file{.}.  For instance, you might want to run a C
8214 program as a test.  To do this you would list its name in @code{TESTS}
8215 and also in @code{check_PROGRAMS}, and then specify it as you would
8216 any other program.
8218 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8219 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8220 not during @code{make all}.  You should list there any program needed
8221 by your tests that does not need to be built by @code{make all}.  Note
8222 that @code{check_PROGRAMS} are @emph{not} automatically added to
8223 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8224 by the tests, not the tests themselves.  Of course you can set
8225 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8227 @section DejaGnu Tests
8229 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
8230 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
8231 assumed.  The variable @code{DEJATOOL} is a list of names that are
8232 passed, one at a time, as the @option{--tool} argument to
8233 @command{runtest} invocations; it defaults to the name of the package.
8235 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
8236 @option{--srcdir} flags that are passed to dejagnu by default; this can be
8237 overridden if necessary.
8238 @vindex RUNTESTDEFAULTFLAGS
8240 The variables @code{EXPECT} and @code{RUNTEST} can
8241 also be overridden to provide project-specific values.  For instance,
8242 you will need to do this if you are testing a compiler toolchain,
8243 because the default values do not take into account host and target
8244 names.
8245 @opindex dejagnu
8246 @vindex DEJATOOL
8247 @vindex EXPECT
8248 @vindex RUNTEST
8250 The contents of the variable @code{RUNTESTFLAGS} are passed to the
8251 @code{runtest} invocation.  This is considered a ``user variable''
8252 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
8253 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
8254 @vindex RUNTESTFLAGS
8255 @vindex AM_RUNTESTFLAGS
8257 @cindex @file{site.exp}
8258 Automake will generate rules to create a local @file{site.exp} file,
8259 defining various variables detected by @command{configure}.  This file
8260 is automatically read by DejaGnu.  It is OK for the user of a package
8261 to edit this file in order to tune the test suite.  However this is
8262 not the place where the test suite author should define new variables:
8263 this should be done elsewhere in the real test suite code.
8264 Especially, @file{site.exp} should not be distributed.
8266 For more information regarding DejaGnu test suites, see @ref{Top, , ,
8267 dejagnu, The DejaGnu Manual}.
8269 In either case, the testing is done via @samp{make check}.
8271 @section Install Tests
8273 The @code{installcheck} target is available to the user as a way to
8274 run any tests after the package has been installed.  You can add tests
8275 to this by writing an @code{installcheck-local} rule.
8278 @node Rebuilding
8279 @chapter Rebuilding Makefiles
8280 @cindex rebuild rules
8282 Automake generates rules to automatically rebuild @file{Makefile}s,
8283 @file{configure}, and other derived files like @file{Makefile.in}.
8285 @acindex AM_MAINTAINER_MODE
8286 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
8287 these automatic rebuilding rules are only enabled in maintainer mode.
8289 @vindex ACLOCAL_AMFLAGS
8290 Sometimes you need to run @command{aclocal} with an argument like
8291 @option{-I} to tell it where to find @file{.m4} files.  Since
8292 sometimes @command{make} will automatically run @command{aclocal}, you
8293 need a way to specify these arguments.  You can do this by defining
8294 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
8295 to @command{aclocal}.  This variable is only useful in the top-level
8296 @file{Makefile.am}.
8298 @vindex CONFIG_STATUS_DEPENDENCIES
8299 @vindex CONFIGURE_DEPENDENCIES
8300 @cindex @file{version.sh}, example
8301 @cindex @file{version.m4}, example
8303 Sometimes it is convenient to supplement the rebuild rules for
8304 @file{configure} or @file{config.status} with additional dependencies.
8305 The variables @code{CONFIGURE_DEPENDENCIES} and
8306 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
8307 dependencies.  These variable should be defined in all
8308 @file{Makefile}s of the tree (because these two rebuild rules are
8309 output in all them), so it is safer and easier to @code{AC_SUBST} them
8310 from @file{configure.ac}.  For instance, the following statement will
8311 cause @file{configure} to be rerun each time @file{version.sh} is
8312 changed.
8313 @example
8314 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
8315 @end example
8316 @noindent
8317 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
8318 is to be used in all @file{Makefile}s, its value must be sensible at
8319 any level in the build hierarchy.
8321 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
8322 @code{CONFIG_STATUS_DEPENDENCIES}.
8324 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
8325 @file{configure} rule, whose effect is to run @command{autoconf}.  This
8326 variable should be seldom used, because @command{automake} already tracks
8327 @code{m4_include}d files.  However it can be useful when playing
8328 tricky games with @code{m4_esyscmd} or similar non-recommendable
8329 macros with side effects.
8331 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
8332 @file{config.status} rule, whose effect is to run @file{configure}.
8333 This variable should therefore carry any non-standard source that may
8334 be read as a side effect of running configure, like @file{version.sh}
8335 in the example above.
8337 Speaking of @file{version.sh} scripts, we recommend against them
8338 today.  They are mainly used when the version of a package is updated
8339 automatically by a script (e.g., in daily builds).  Here is what some
8340 old-style @file{configure.ac}s may look like:
8341 @example
8342 AC_INIT
8343 . $srcdir/version.sh
8344 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
8345 @dots{}
8346 @end example
8347 @noindent
8348 Here, @file{version.sh} is a shell fragment that sets
8349 @code{VERSION_NUMBER}.  The problem with this example is that
8350 @command{automake} cannot track dependencies (listing @file{version.sh}
8351 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
8352 to the user), and that it uses the obsolete form of @code{AC_INIT} and
8353 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
8354 straightforward, because shell variables are not allowed in
8355 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
8356 replaced by an M4 file that is included by @file{configure.ac}:
8357 @example
8358 m4_include([version.m4])
8359 AC_INIT([name], VERSION_NUMBER)
8360 AM_INIT_AUTOMAKE
8361 @dots{}
8362 @end example
8363 @noindent
8364 Here @file{version.m4} could contain something like
8365 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
8366 second form is that @command{automake} will take care of the
8367 dependencies when defining the rebuild rule, and will also distribute
8368 the file automatically.  An inconvenience is that @command{autoconf}
8369 will now be rerun each time the version number is bumped, when only
8370 @file{configure} had to be rerun in the previous setup.
8373 @node Options
8374 @chapter Changing Automake's Behavior
8376 Various features of Automake can be controlled by options in the
8377 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
8378 basis when listed in a special @file{Makefile} variable named
8379 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
8380 @file{Makefiles} when listed in the first argument of
8381 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}.  Currently understood
8382 options are:
8383 @vindex AUTOMAKE_OPTIONS
8385 @table @asis
8386 @item @option{gnits}
8387 @itemx @option{gnu}
8388 @itemx @option{foreign}
8389 @itemx @option{cygnus}
8390 @cindex Option, @option{gnits}
8391 @cindex Option, @option{gnu}
8392 @cindex Option, @option{foreign}
8393 @cindex Option, @option{cygnus}
8394 @opindex gnits
8395 @opindex gnu
8396 @opindex foreign
8397 @opindex cygnus
8399 Set the strictness as appropriate.  The @option{gnits} option also
8400 implies options @option{readme-alpha} and @option{check-news}.
8402 @item @option{ansi2knr}
8403 @itemx @option{@var{path}/ansi2knr}
8404 @cindex Option, @option{ansi2knr}
8405 @opindex ansi2knr
8406 Turn on the obsolete de-ANSI-fication feature.  @xref{ANSI}.  If preceded by a
8407 path, the generated @file{Makefile.in} will look in the specified
8408 directory to find the @file{ansi2knr} program.  The path should be a
8409 relative path to another directory in the same distribution (Automake
8410 currently does not check this).
8412 @item @option{check-news}
8413 @cindex Option, @option{check-news}
8414 @opindex check-news
8415 Cause @samp{make dist} to fail unless the current version number appears
8416 in the first few lines of the @file{NEWS} file.
8418 @item @option{color-tests}
8419 @cindex Option, @option{color-tests}
8420 @opindex color-tests
8421 Cause output of the simple test suite (@pxref{Tests}) to be
8422 colorized on capable terminals.
8424 @item @option{dejagnu}
8425 @cindex Option, @option{dejagnu}
8426 @opindex dejagnu
8427 Cause @command{dejagnu}-specific rules to be generated.  @xref{Tests}.
8429 @item @option{dist-bzip2}
8430 @cindex Option, @option{dist-bzip2}
8431 @opindex dist-bzip2
8432 Hook @code{dist-bzip2} to @code{dist}.
8433 @trindex dist-bzip2
8435 @item @option{dist-lzma}
8436 @cindex Option, @option{dist-lzma}
8437 @opindex dist-lzma
8438 Hook @code{dist-lzma} to @code{dist}.
8439 @trindex dist-lzma
8441 @item @option{dist-shar}
8442 @cindex Option, @option{dist-shar}
8443 @opindex dist-shar
8444 Hook @code{dist-shar} to @code{dist}.
8445 @trindex dist-shar
8447 @item @option{dist-zip}
8448 @cindex Option, @option{dist-zip}
8449 @opindex dist-zip
8450 Hook @code{dist-zip} to @code{dist}.
8451 @trindex dist-zip
8453 @item @option{dist-tarZ}
8454 @cindex Option, @option{dist-tarZ}
8455 @opindex dist-tarZ
8456 Hook @code{dist-tarZ} to @code{dist}.
8457 @trindex dist-tarZ
8459 @item @option{filename-length-max=99}
8460 @cindex Option, @option{filename-length-max=99}
8461 @opindex filename-length-max=99
8462 Abort if file names longer than 99 characters are found during
8463 @samp{make dist}.  Such long file names are generally considered not to
8464 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
8465 options below.  This option should be used in the top-level
8466 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
8467 @file{configure.ac}, it will be ignored otherwise.  It will also be
8468 ignored in sub-packages of nested packages (@pxref{Subpackages}).
8470 @item @option{no-define}
8471 @cindex Option, @option{no-define}
8472 @opindex no-define
8473 This options is meaningful only when passed as an argument to
8474 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
8475 @code{VERSION} variables to be @code{AC_DEFINE}d.
8477 @item @option{no-dependencies}
8478 @cindex Option, @option{no-dependencies}
8479 @opindex no-dependencies
8480 This is similar to using @option{--ignore-deps} on the command line,
8481 but is useful for those situations where you don't have the necessary
8482 bits to make automatic dependency tracking work
8483 (@pxref{Dependencies}).  In this case the effect is to effectively
8484 disable automatic dependency tracking.
8486 @item @option{no-dist}
8487 @cindex Option, @option{no-dist}
8488 @opindex no-dist
8489 Don't emit any code related to @code{dist} target.  This is useful
8490 when a package has its own method for making distributions.
8492 @item @option{no-dist-gzip}
8493 @cindex Option, @option{no-dist-gzip}
8494 @opindex no-dist-gzip
8495 Do not hook @code{dist-gzip} to @code{dist}.
8496 @trindex no-dist-gzip
8498 @item @option{no-exeext}
8499 @cindex Option, @option{no-exeext}
8500 @opindex no-exeext
8501 If your @file{Makefile.am} defines a rule for target @code{foo}, it
8502 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
8503 necessary when @code{EXEEXT} is found to be empty.  However, by
8504 default automake will generate an error for this use.  The
8505 @option{no-exeext} option will disable this error.  This is intended for
8506 use only where it is known in advance that the package will not be
8507 ported to Windows, or any other operating system using extensions on
8508 executables.
8510 @item @option{no-installinfo}
8511 @cindex Option, @option{no-installinfo}
8512 @opindex no-installinfo
8513 The generated @file{Makefile.in} will not cause info pages to be built
8514 or installed by default.  However, @code{info} and @code{install-info}
8515 targets will still be available.  This option is disallowed at
8516 @option{gnu} strictness and above.
8517 @trindex info
8518 @trindex install-info
8520 @item @option{no-installman}
8521 @cindex Option, @option{no-installman}
8522 @opindex no-installman
8523 The generated @file{Makefile.in} will not cause man pages to be
8524 installed by default.  However, an @code{install-man} target will still
8525 be available for optional installation.  This option is disallowed at
8526 @option{gnu} strictness and above.
8527 @trindex install-man
8529 @item @option{nostdinc}
8530 @cindex Option, @option{nostdinc}
8531 @opindex nostdinc
8532 This option can be used to disable the standard @option{-I} options that
8533 are ordinarily automatically provided by Automake.
8535 @item @option{no-texinfo.tex}
8536 @cindex Option, @option{no-texinfo.tex}
8537 @opindex no-texinfo.tex
8538 Don't require @file{texinfo.tex}, even if there are texinfo files in
8539 this directory.
8541 @item @option{readme-alpha}
8542 @cindex Option, @option{readme-alpha}
8543 @opindex readme-alpha
8544 If this release is an alpha release, and the file @file{README-alpha}
8545 exists, then it will be added to the distribution.  If this option is
8546 given, version numbers are expected to follow one of two forms.  The
8547 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
8548 element is a number; the final period and number should be left off for
8549 non-alpha releases.  The second form is
8550 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
8551 letter; it should be omitted for non-alpha releases.
8553 @item @option{std-options}
8554 @cindex Options, @option{std-options}
8555 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
8556 @cindex @option{--help} check
8557 @cindex @option{--version} check
8558 @opindex std-options
8560 Make the @code{installcheck} rule check that installed scripts and
8561 programs support the @option{--help} and @option{--version} options.
8562 This also provides a basic check that the program's
8563 run-time dependencies are satisfied after installation.
8565 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
8566 In a few situations, programs (or scripts) have to be exempted from this
8567 test.  For instance, @command{false} (from GNU sh-utils) is never
8568 successful, even for @option{--help} or @option{--version}.  You can list
8569 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
8570 Programs (not scripts) listed in this variable should be suffixed by
8571 @samp{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance, suppose we
8572 build @file{false} as a program but @file{true.sh} as a script, and that
8573 neither of them support @option{--help} or @option{--version}:
8575 @example
8576 AUTOMAKE_OPTIONS = std-options
8577 bin_PROGRAMS = false ...
8578 bin_SCRIPTS = true.sh ...
8579 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
8580 @end example
8582 @item @option{subdir-objects}
8583 @cindex Options, @option{subdir-objects}
8584 @opindex subdir-objects
8585 If this option is specified, then objects are placed into the
8586 subdirectory of the build directory corresponding to the subdirectory of
8587 the source file.  For instance, if the source file is
8588 @file{subdir/file.cxx}, then the output file would be
8589 @file{subdir/file.o}.
8591 In order to use this option with C sources, you should add
8592 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
8594 @anchor{tar-formats}
8595 @item @option{tar-v7}
8596 @itemx @option{tar-ustar}
8597 @itemx @option{tar-pax}
8598 @cindex Option, @option{tar-v7}
8599 @cindex Option, @option{tar-ustar}
8600 @cindex Option, @option{tar-pax}
8601 @cindex @command{tar} formats
8602 @cindex v7 @command{tar} format
8603 @cindex ustar format
8604 @cindex pax format
8605 @opindex tar-v7
8606 @opindex tar-ustar
8607 @opindex tar-pax
8609 These three mutually exclusive options select the tar format to use
8610 when generating tarballs with @samp{make dist}.  (The tar file created
8611 is then compressed according to the set of @option{no-dist-gzip},
8612 @option{dist-bzip2}, @option{dist-lzma} and @option{dist-tarZ} options in use.)
8614 These options must be passed as argument to @code{AM_INIT_AUTOMAKE}
8615 (@pxref{Macros}) because they can require additional configure checks.
8616 Automake will complain if it sees such options in an
8617 @code{AUTOMAKE_OPTIONS} variable.
8619 @option{tar-v7} selects the old V7 tar format.  This is the historical
8620 default.  This antiquated format is understood by all tar
8621 implementations and supports file names with up to 99 characters.  When
8622 given longer file names some tar implementations will diagnose the
8623 problem while other will generate broken tarballs or use non-portable
8624 extensions.  Furthermore, the V7 format cannot store empty
8625 directories.  When using this format, consider using the
8626 @option{filename-length-max=99} option to catch file names too long.
8628 @option{tar-ustar} selects the ustar format defined by POSIX
8629 1003.1-1988.  This format is believed to be old enough to be portable.
8630 It fully supports empty directories.  It can store file names with up
8631 to 256 characters, provided that the file name can be split at
8632 directory separator in two parts, first of them being at most 155
8633 bytes long.  So, in most cases the maximum file name length will be
8634 shorter than 256 characters.  However you may run against broken tar
8635 implementations that incorrectly handle file names longer than 99
8636 characters (please report them to @email{bug-automake@@gnu.org} so we
8637 can document this accurately).
8639 @option{tar-pax} selects the new pax interchange format defined by POSIX
8640 1003.1-2001.  It does not limit the length of file names.  However,
8641 this format is very young and should probably be restricted to
8642 packages that target only very modern platforms.  There are moves to
8643 change the pax format in an upward-compatible way, so this option may
8644 refer to a more recent version in the future.
8646 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
8647 further discussion about tar formats.
8649 @command{configure} knows several ways to construct these formats.  It
8650 will not abort if it cannot find a tool up to the task (so that the
8651 package can still be built), but @samp{make dist} will fail.
8653 @item @var{version}
8654 @cindex Option, @var{version}
8655 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
8656 newer than the version specified, creation of the @file{Makefile.in}
8657 will be suppressed.
8659 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
8660 @cindex Option, warnings
8661 @cindex Option, @option{-W@var{category}}
8662 @cindex Option, @option{--warnings=@var{category}}
8663 These options behave exactly like their command-line counterpart
8664 (@pxref{Invoking Automake}).  This allows you to enable or disable some
8665 warning categories on a per-file basis.  You can also setup some warnings
8666 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
8667 in your @file{configure.ac}.
8669 @end table
8671 Unrecognized options are diagnosed by @command{automake}.
8673 If you want an option to apply to all the files in the tree, you can use
8674 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
8675 @xref{Macros}.
8678 @node Miscellaneous
8679 @chapter Miscellaneous Rules
8681 There are a few rules and variables that didn't fit anywhere else.
8683 @menu
8684 * Tags::                        Interfacing to etags and mkid
8685 * Suffixes::                    Handling new file extensions
8686 * Multilibs::                   Support for multilibs.
8687 @end menu
8690 @node Tags
8691 @section Interfacing to @command{etags}
8693 @cindex @file{TAGS} support
8695 Automake will generate rules to generate @file{TAGS} files for use with
8696 GNU Emacs under some circumstances.
8698 @trindex tags
8699 If any C, C++ or Fortran 77 source code or headers are present, then
8700 @code{tags} and @code{TAGS} rules will be generated for the directory.
8701 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
8702 @code{_LISP} primaries will be used to generate tags.  Note that
8703 generated source files that are not distributed must be declared in
8704 variables like @code{nodist_noinst_HEADERS} or
8705 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
8707 A @code{tags} rule will be output at the topmost directory of a
8708 multi-directory package.  When run from this topmost directory,
8709 @samp{make tags} will generate a @file{TAGS} file that includes by
8710 reference all @file{TAGS} files from subdirectories.
8712 The @code{tags} rule will also be generated if the variable
8713 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
8714 directories that contain taggable source that @command{etags} does
8715 not understand.  The user can use the @code{ETAGSFLAGS} to pass
8716 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
8717 available for use in @file{Makefile.am}.
8718 @vindex ETAGS_ARGS
8719 @vindex ETAGSFLAGS
8720 @vindex AM_ETAGSFLAGS
8722 Here is how Automake generates tags for its source, and for nodes in its
8723 Texinfo file:
8725 @example
8726 ETAGS_ARGS = automake.in --lang=none \
8727  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
8728 @end example
8730 If you add file names to @code{ETAGS_ARGS}, you will probably also
8731 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
8732 are added directly to the dependencies for the @code{tags} rule.
8733 @vindex TAGS_DEPENDENCIES
8735 Automake also generates a @code{ctags} rule that can be used to
8736 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
8737 is the name of the program to invoke (by default @command{ctags});
8738 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
8739 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
8741 Automake will also generate an @code{ID} rule that will run
8742 @command{mkid} on the source.  This is only supported on a
8743 directory-by-directory basis.
8744 @trindex id
8746 Finally, Automake also emit rules to support the
8747 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
8748 The @code{GTAGS} rule runs Global Tags and puts the
8749 result in the top build directory.  The variable @code{GTAGS_ARGS}
8750 holds arguments that are passed to @command{gtags}.
8751 @vindex GTAGS_ARGS
8754 @node Suffixes
8755 @section Handling new file extensions
8757 @cindex Adding new @code{SUFFIXES}
8758 @cindex @code{SUFFIXES}, adding
8759 @vindex SUFFIXES
8761 It is sometimes useful to introduce a new implicit rule to handle a file
8762 type that Automake does not know about.
8764 For instance, suppose you had a compiler that could compile @file{.foo}
8765 files to @file{.o} files.  You would simply define an suffix rule for
8766 your language:
8768 @example
8769 .foo.o:
8770         foocc -c -o $@@ $<
8771 @end example
8773 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
8774 variable and expect the correct results:
8776 @example
8777 bin_PROGRAMS = doit
8778 doit_SOURCES = doit.foo
8779 @end example
8781 This was the simpler and more common case.  In other cases, you will
8782 have to help Automake to figure which extensions you are defining your
8783 suffix rule for.  This usually happens when your extensions does not
8784 start with a dot.  Then, all you have to do is to put a list of new
8785 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
8786 implicit rule.
8788 For instance, the following definition prevents Automake to misinterpret
8789 @samp{.idlC.cpp:} as an attempt to transform @file{.idlC} files into
8790 @file{.cpp} files.
8792 @example
8793 SUFFIXES = .idl C.cpp
8794 .idlC.cpp:
8795         # whatever
8796 @end example
8798 As you may have noted, the @code{SUFFIXES} variable behaves like the
8799 @code{.SUFFIXES} special target of @command{make}.  You should not touch
8800 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
8801 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
8802 @code{SUFFIXES} go at the start of the generated suffixes list, followed
8803 by Automake generated suffixes not already in the list.
8805 @node Multilibs
8806 @section Support for Multilibs
8808 Automake has support for an obscure feature called multilibs.  A
8809 @dfn{multilib} is a library that is built for multiple different ABIs
8810 at a single time; each time the library is built with a different target
8811 flag combination.  This is only useful when the library is intended to
8812 be cross-compiled, and it is almost exclusively used for compiler
8813 support libraries.
8815 The multilib support is still experimental.  Only use it if you are
8816 familiar with multilibs and can debug problems you might encounter.
8819 @node Include
8820 @chapter Include
8822 @cmindex include
8823 @cindex Including @file{Makefile} fragment
8824 @cindex @file{Makefile} fragment, including
8826 Automake supports an @code{include} directive that  can be used to
8827 include other @file{Makefile} fragments when @command{automake} is run.
8828 Note that these fragments are read and interpreted by @command{automake},
8829 not by @command{make}.  As with conditionals, @command{make} has no idea that
8830 @code{include} is in use.
8832 There are two forms of @code{include}:
8834 @table @code
8835 @item include $(srcdir)/file
8836 Include a fragment that is found relative to the current source
8837 directory.
8839 @item include $(top_srcdir)/file
8840 Include a fragment that is found relative to the top source directory.
8841 @end table
8843 Note that if a fragment is included inside a conditional, then the
8844 condition applies to the entire contents of that fragment.
8846 Makefile fragments included this way are always distributed because
8847 they are needed to rebuild @file{Makefile.in}.
8849 @node Conditionals
8850 @chapter Conditionals
8852 @cindex Conditionals
8854 Automake supports a simple type of conditionals.
8856 @unnumberedsec Usage
8858 @acindex AM_CONDITIONAL
8859 Before using a conditional, you must define it by using
8860 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
8862 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
8863 The conditional name, @var{conditional}, should be a simple string
8864 starting with a letter and containing only letters, digits, and
8865 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
8866 that are reserved by Automake.
8868 The shell @var{condition} (suitable for use in a shell @code{if}
8869 statement) is evaluated when @command{configure} is run.  Note that you
8870 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
8871 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
8872 conditionally (e.g., in a shell @code{if} statement), then the result
8873 will confuse automake.
8874 @end defmac
8876 @cindex @option{--enable-debug}, example
8877 @cindex Example conditional @option{--enable-debug}
8878 @cindex Conditional example, @option{--enable-debug}
8880 Conditionals typically depend upon options that the user provides to
8881 the @command{configure} script.  Here is an example of how to write a
8882 conditional that is true if the user uses the @option{--enable-debug}
8883 option.
8885 @example
8886 AC_ARG_ENABLE([debug],
8887 [  --enable-debug    Turn on debugging],
8888 [case "$@{enableval@}" in
8889   yes) debug=true ;;
8890   no)  debug=false ;;
8891   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
8892 esac],[debug=false])
8893 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
8894 @end example
8896 Here is an example of how to use that conditional in @file{Makefile.am}:
8898 @cmindex if
8899 @cmindex endif
8900 @cmindex else
8902 @example
8903 if DEBUG
8904 DBG = debug
8905 else
8906 DBG =
8907 endif
8908 noinst_PROGRAMS = $(DBG)
8909 @end example
8911 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
8912 (@pxref{Conditional Programs}).
8914 You may only test a single variable in an @code{if} statement, possibly
8915 negated using @samp{!}.  The @code{else} statement may be omitted.
8916 Conditionals may be nested to any depth.  You may specify an argument to
8917 @code{else} in which case it must be the negation of the condition used
8918 for the current @code{if}.  Similarly you may specify the condition
8919 that is closed by an @code{end}:
8921 @example
8922 if DEBUG
8923 DBG = debug
8924 else !DEBUG
8925 DBG =
8926 endif !DEBUG
8927 @end example
8929 @noindent
8930 Unbalanced conditions are errors.
8932 The @code{else} branch of the above two examples could be omitted,
8933 since assigning the empty string to an otherwise undefined variable
8934 makes no difference.
8936 @unnumberedsec Portability
8938 Note that conditionals in Automake are not the same as conditionals in
8939 GNU Make.  Automake conditionals are checked at configure time by the
8940 @file{configure} script, and affect the translation from
8941 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
8942 to @file{configure} and on results that @file{configure} has discovered
8943 about the host system.  GNU Make conditionals are checked at @command{make}
8944 time, and are based on variables passed to the make program or defined
8945 in the @file{Makefile}.
8947 Automake conditionals will work with any make program.
8949 @unnumberedsec Limits
8951 Conditionals should enclose complete statements like variables or
8952 rules definitions.  Automake cannot deal with conditionals used inside
8953 a variable definition, for instance, and is not even able to diagnose
8954 this situation.  The following example would not work:
8956 @example
8957 # This syntax is not understood by Automake
8958 AM_CPPFLAGS = \
8959   -DFEATURE_A \
8960 if WANT_DEBUG
8961   -DDEBUG \
8962 endif
8963   -DFEATURE_B
8964 @end example
8966 However the intended definition of @code{AM_CPPFLAGS} can be achieved
8967 with
8969 @example
8970 if WANT_DEBUG
8971   DEBUGFLAGS = -DDEBUG
8972 endif
8973 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
8974 @end example
8976 @noindent or
8978 @example
8979 AM_CPPFLAGS = -DFEATURE_A
8980 if WANT_DEBUG
8981 AM_CPPFLAGS += -DDEBUG
8982 endif
8983 AM_CPPFLAGS += -DFEATURE_B
8984 @end example
8986 @node Gnits
8987 @chapter The effect of @option{--gnu} and @option{--gnits}
8989 @cindex @option{--gnu}, required files
8990 @cindex @option{--gnu}, complete description
8992 The @option{--gnu} option (or @option{gnu} in the
8993 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
8994 the following:
8996 @itemize @bullet
8997 @item
8998 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
8999 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
9000 or @file{COPYING}, are required at the topmost directory of the package.
9002 @item
9003 The options @option{no-installman} and @option{no-installinfo} are
9004 prohibited.
9005 @end itemize
9007 Note that this option will be extended in the future to do even more
9008 checking; it is advisable to be familiar with the precise requirements
9009 of the GNU standards.  Also, @option{--gnu} can require certain
9010 non-standard GNU programs to exist for use by various maintainer-only
9011 rules; for instance, in the future @command{pathchk} might be required for
9012 @samp{make dist}.
9014 @cindex @option{--gnits}, complete description
9016 The @option{--gnits} option does everything that @option{--gnu} does, and
9017 checks the following as well:
9019 @itemize @bullet
9020 @item
9021 @samp{make installcheck} will check to make sure that the @option{--help}
9022 and @option{--version} really print a usage message and a version string,
9023 respectively.  This is the @option{std-options} option (@pxref{Options}).
9025 @item
9026 @samp{make dist} will check to make sure the @file{NEWS} file has been
9027 updated to the current version.
9029 @item
9030 @code{VERSION} is checked to make sure its format complies with Gnits
9031 standards.
9032 @c FIXME xref when standards are finished
9034 @item
9035 @cindex @file{README-alpha}
9036 If @code{VERSION} indicates that this is an alpha release, and the file
9037 @file{README-alpha} appears in the topmost directory of a package, then
9038 it is included in the distribution.  This is done in @option{--gnits}
9039 mode, and no other, because this mode is the only one where version
9040 number formats are constrained, and hence the only mode where Automake
9041 can automatically determine whether @file{README-alpha} should be
9042 included.
9044 @item
9045 The file @file{THANKS} is required.
9046 @end itemize
9049 @node Cygnus
9050 @chapter The effect of @option{--cygnus}
9052 @cindex @option{cygnus} strictness
9054 Some packages, notably GNU GCC and GNU gdb, have a build environment
9055 originally written at Cygnus Support (subsequently renamed Cygnus
9056 Solutions, and then later purchased by Red Hat).  Packages with this
9057 ancestry are sometimes referred to as ``Cygnus'' trees.
9059 A Cygnus tree has slightly different rules for how a
9060 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
9061 @command{automake} will cause any generated @file{Makefile.in} to
9062 comply with Cygnus rules.
9064 Here are the precise effects of @option{--cygnus}:
9066 @itemize @bullet
9067 @item
9068 Info files are always created in the build directory, and not in the
9069 source directory.
9071 @item
9072 @file{texinfo.tex} is not required if a Texinfo source file is
9073 specified.  The assumption is that the file will be supplied, but in a
9074 place that Automake cannot find.  This assumption is an artifact of how
9075 Cygnus packages are typically bundled.
9077 @item
9078 @samp{make dist} is not supported, and the rules for it are not
9079 generated.  Cygnus-style trees use their own distribution mechanism.
9081 @item
9082 Certain tools will be searched for in the build tree as well as in the
9083 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
9084 @command{makeinfo} and @command{texi2dvi}.
9086 @item
9087 @option{--foreign} is implied.
9089 @item
9090 The options @option{no-installinfo} and @option{no-dependencies} are
9091 implied.
9093 @item
9094 The macros @code{AM_MAINTAINER_MODE} and @code{AM_CYGWIN32} are
9095 required.
9097 @item
9098 The @code{check} target doesn't depend on @code{all}.
9099 @end itemize
9101 GNU maintainers are advised to use @option{gnu} strictness in preference
9102 to the special Cygnus mode.  Some day, perhaps, the differences between
9103 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
9104 more standards compliant).  At that time the special Cygnus mode will be
9105 removed.
9108 @node Not Enough
9109 @chapter When Automake Isn't Enough
9111 In some situations, where Automake is not up to one task, one has to
9112 resort to handwritten rules or even handwritten @file{Makefile}s.
9114 @menu
9115 * Extending::                   Adding new rules or overriding existing ones.
9116 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
9117 @end menu
9119 @node Extending
9120 @section Extending Automake Rules
9122 With some minor exceptions (like @code{_PROGRAMS} variables, @code{TESTS},
9123 or @code{XFAIL_TESTS}) being rewritten to append @samp{$(EXEEXT)}), the
9124 contents of a @file{Makefile.am} is copied to @file{Makefile.in} verbatim.
9126 @cindex copying semantics
9128 These copying semantics means that many problems can be worked around
9129 by simply adding some @command{make} variables and rules to
9130 @file{Makefile.am}.  Automake will ignore these additions.
9132 @cindex conflicting definitions
9133 @cindex rules, conflicting
9134 @cindex variables, conflicting
9135 @cindex definitions, conflicts
9137 Since a @file{Makefile.in} is built from data gathered from three
9138 different places (@file{Makefile.am}, @file{configure.ac}, and
9139 @command{automake} itself), it is possible to have conflicting
9140 definitions of rules or variables.  When building @file{Makefile.in}
9141 the following priorities are respected by @command{automake} to ensure
9142 the user always have the last word.  User defined variables in
9143 @file{Makefile.am} have priority over variables @code{AC_SUBST}ed from
9144 @file{configure.ac}, and @code{AC_SUBST}ed variables have priority
9145 over @command{automake}-defined variables.  As far rules are
9146 concerned, a user-defined rule overrides any
9147 @command{automake}-defined rule for the same target.
9149 @cindex overriding rules
9150 @cindex overriding semantics
9151 @cindex rules, overriding
9153 These overriding semantics make it possible to fine tune some default
9154 settings of Automake, or replace some of its rules.  Overriding
9155 Automake rules is often inadvisable, particularly in the topmost
9156 directory of a package with subdirectories.  The @option{-Woverride}
9157 option (@pxref{Invoking Automake}) comes handy to catch overridden
9158 definitions.
9160 Note that Automake does not make any difference between rules with
9161 commands and rules that only specify dependencies.  So it is not
9162 possible to append new dependencies to an @command{automake}-defined
9163 target without redefining the entire rule.
9165 @cindex @option{-local} targets
9166 @cindex local targets
9168 However, various useful targets have a @samp{-local} version you can
9169 specify in your @file{Makefile.am}.  Automake will supplement the
9170 standard target with these user-supplied targets.
9172 @trindex  all
9173 @trindex  all-local
9174 @trindex  info
9175 @trindex  info-local
9176 @trindex  dvi
9177 @trindex  dvi-local
9178 @trindex  ps
9179 @trindex  ps-local
9180 @trindex  pdf
9181 @trindex  pdf-local
9182 @trindex  html
9183 @trindex  html-local
9184 @trindex  check
9185 @trindex  check-local
9186 @trindex  install
9187 @trindex  install-data
9188 @trindex  install-data-local
9189 @trindex  install-dvi
9190 @trindex  install-dvi-local
9191 @trindex  install-exec
9192 @trindex  install-exec-local
9193 @trindex  install-html
9194 @trindex  install-html-local
9195 @trindex  install-info
9196 @trindex  install-info-local
9197 @trindex  install-pdf
9198 @trindex  install-pdf-local
9199 @trindex  install-ps
9200 @trindex  install-ps-local
9201 @trindex  uninstall
9202 @trindex  uninstall-local
9203 @trindex  mostlyclean
9204 @trindex  mostlyclean-local
9205 @trindex  clean
9206 @trindex  clean-local
9207 @trindex  distclean
9208 @trindex  distclean-local
9209 @trindex  installdirs
9210 @trindex  installdirs-local
9211 @trindex  installcheck
9212 @trindex  installcheck-local
9214 The targets that support a local version are @code{all}, @code{info},
9215 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
9216 @code{install-data}, @code{install-dvi}, @code{install-exec},
9217 @code{install-html}, @code{install-info}, @code{install-pdf},
9218 @code{install-ps}, @code{uninstall}, @code{installdirs},
9219 @code{installcheck} and the various @code{clean} targets
9220 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
9221 @code{maintainer-clean}).
9223 Note that there are no @code{uninstall-exec-local} or
9224 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
9225 It doesn't make sense to uninstall just data or just executables.
9227 For instance, here is one way to erase a subdirectory during
9228 @samp{make clean} (@pxref{Clean}).
9230 @example
9231 clean-local:
9232         -rm -rf testSubDir
9233 @end example
9235 Older version of this manual used to show how to use
9236 @code{install-data-local} to install a file to some hard-coded
9237 location, but you should avoid this.  (@pxref{Hard-Coded Install Paths})
9239 @cindex @option{-hook} targets
9240 @cindex hook targets
9242 Some rule also have a way to run another rule, called a @dfn{hook},
9243 after their work is done.  The hook is named after the principal target,
9244 with @samp{-hook} appended.  The targets allowing hooks are
9245 @code{install-data}, @code{install-exec}, @code{uninstall}, @code{dist},
9246 and @code{distcheck}.
9247 @trindex install-data-hook
9248 @trindex install-exec-hook
9249 @trindex uninstall-hook
9250 @trindex dist-hook
9252 For instance, here is how to create a hard link to an installed program:
9254 @example
9255 install-exec-hook:
9256         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
9257            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
9258 @end example
9260 Although cheaper and more portable than symbolic links, hard links
9261 will not work everywhere (for instance, OS/2 does not have
9262 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
9263 @command{ln} does not work.  An easy way, if symbolic links are
9264 acceptable to you, is to add @code{AC_PROG_LN_S} to
9265 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
9266 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
9267 @file{Makefile.am}.
9269 @cindex versioned binaries, installing
9270 @cindex installing versioned binaries
9271 @cindex @code{LN_S} example
9272 For instance, here is how you could install a versioned copy of a
9273 program using @samp{$(LN_S)}:
9275 @example
9276 install-exec-hook:
9277         cd $(DESTDIR)$(bindir) && \
9278           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
9279           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
9280 @end example
9282 Note that we rename the program so that a new version will erase the
9283 symbolic link, not the real binary.  Also we @command{cd} into the
9284 destination directory in order to create relative links.
9286 When writing @code{install-exec-hook} or @code{install-data-hook},
9287 please bear in mind that the exec/data distinction is based on the
9288 installation directory, not on the primary used (@pxref{Install}).  So
9289 a @code{foo_SCRIPTS} will be installed by @code{install-data}, and a
9290 @code{barexec_SCRIPTS} will be installed by @code{install-exec}.  You
9291 should define your hooks consequently.
9293 @c FIXME should include discussion of variables you can use in these
9294 @c rules
9296 @node Third-Party Makefiles
9297 @section Third-Party @file{Makefile}s
9299 @cindex Third-party packages, interfacing with
9300 @cindex Interfacing with third-party packages
9302 In most projects all @file{Makefile}s are generated by Automake.  In
9303 some cases, however, projects need to embed subdirectories with
9304 handwritten @file{Makefile}s.  For instance, one subdirectory could be
9305 a third-party project with its own build system, not using Automake.
9307 It is possible to list arbitrary directories in @code{SUBDIRS} or
9308 @code{DIST_SUBDIRS} provided each of these directories has a
9309 @file{Makefile} that recognizes all the following recursive targets.
9311 @cindex recursive targets and third-party @file{Makefile}s
9312 When a user runs one of these targets, that target is run recursively
9313 in all subdirectories.  This is why it is important that even
9314 third-party @file{Makefile}s support them.
9316 @table @code
9317 @item all
9318 Compile the entire package.  This is the default target in
9319 Automake-generated @file{Makefile}s, but it does not need to be the
9320 default in third-party @file{Makefile}s.
9322 @item distdir
9323 @trindex distdir
9324 @vindex distdir
9325 @vindex top_distdir
9326 Copy files to distribute into @samp{$(distdir)}, before a tarball is
9327 constructed.  Of course this target is not required if the
9328 @option{no-dist} option (@pxref{Options}) is used.
9330 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
9331 (@pxref{Dist}) will be passed from the outer package to the subpackage
9332 when the @code{distdir} target is invoked.  These two variables have
9333 been adjusted for the directory that is being recursed into, so they
9334 are ready to use.
9336 @item install
9337 @itemx install-data
9338 @itemx install-exec
9339 @itemx uninstall
9340 Install or uninstall files (@pxref{Install}).
9342 @item install-dvi
9343 @itemx install-html
9344 @itemx install-info
9345 @itemx install-ps
9346 @itemx install-pdf
9347 Install only some specific documentation format (@pxref{Texinfo}).
9349 @item installdirs
9350 Create install directories, but do not install any files.
9352 @item check
9353 @itemx installcheck
9354 Check the package (@pxref{Tests}).
9356 @item mostlyclean
9357 @itemx clean
9358 @itemx distclean
9359 @itemx maintainer-clean
9360 Cleaning rules (@pxref{Clean}).
9362 @item dvi
9363 @itemx pdf
9364 @itemx ps
9365 @itemx info
9366 @itemx html
9367 Build the documentation in various formats (@pxref{Texinfo}).
9369 @item tags
9370 @itemx ctags
9371 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
9372 @end table
9374 If you have ever used Gettext in a project, this is a good example of
9375 how third-party @file{Makefile}s can be used with Automake.  The
9376 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
9377 @file{intl/} directories are handwritten @file{Makefile}s that
9378 implement all these targets.  That way they can be added to
9379 @code{SUBDIRS} in Automake packages.
9381 Directories that are only listed in @code{DIST_SUBDIRS} but not in
9382 @code{SUBDIRS} need only the @code{distclean},
9383 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
9384 Subdirectories}).
9386 Usually, many of these rules are irrelevant to the third-party
9387 subproject, but they are required for the whole package to work.  It's
9388 OK to have a rule that does nothing, so if you are integrating a
9389 third-party project with no documentation or tag support, you could
9390 simply augment its @file{Makefile} as follows:
9392 @example
9393 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
9394 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
9395 $(EMPTY_AUTOMAKE_TARGETS):
9396 @end example
9398 Another aspect of integrating third-party build systems is whether
9399 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
9400 subpackage does not support VPATH builds the whole package will not
9401 support VPATH builds.  This in turns means that @samp{make distcheck}
9402 will not work, because it relies on VPATH builds.  Some people can
9403 live without this (actually, many Automake users have never heard of
9404 @samp{make distcheck}).  Other people may prefer to revamp the
9405 existing @file{Makefile}s to support VPATH@.  Doing so does not
9406 necessarily require Automake, only Autoconf is needed (@pxref{Build
9407 Directories, , Build Directories, autoconf, The Autoconf Manual}).
9408 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
9409 and @samp{@@top_builddir@@} are defined by @file{configure} when it
9410 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
9411 Output Variables, autoconf, The Autoconf Manual}), they are not
9412 computed by the Makefile like the aforementioned @samp{$(distdir)} and
9413 @samp{$(top_distdir)} variables..
9415 It is sometimes inconvenient to modify a third-party @file{Makefile}
9416 to introduce the above required targets.  For instance, one may want to
9417 keep the third-party sources untouched to ease upgrades to new
9418 versions.
9420 @cindex @file{GNUmakefile} including @file{Makefile}
9421 Here are two other ideas.  If GNU make is assumed, one possibility is
9422 to add to that subdirectory a @file{GNUmakefile} that defines the
9423 required targets and include the third-party @file{Makefile}.  For
9424 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
9425 directory; the easiest way to do this is to write a
9426 @file{GNUmakefile.in} instead, and have it processed with
9427 @code{AC_CONFIG_FILES} from the outer package.  For example if we
9428 assume @file{Makefile} defines all targets except the documentation
9429 targets, and that the @code{check} target is actually called
9430 @code{test}, we could write @file{GNUmakefile} (or
9431 @file{GNUmakefile.in}) like this:
9433 @example
9434 # First, include the real Makefile
9435 include Makefile
9436 # Then, define the other targets needed by Automake Makefiles.
9437 .PHONY: dvi pdf ps info html check
9438 dvi pdf ps info html:
9439 check: test
9440 @end example
9442 @cindex Proxy @file{Makefile} for third-party packages
9443 A similar idea that does not use @code{include} is to write a proxy
9444 @file{Makefile} that dispatches rules to the real @file{Makefile},
9445 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
9446 it's OK to rename the original @file{Makefile}) or with @samp{cd
9447 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
9448 subdirectory project one directory deeper).  The good news is that
9449 this proxy @file{Makefile} can be generated with Automake.  All we
9450 need are @option{-local} targets (@pxref{Extending}) that perform the
9451 dispatch.  Of course the other Automake features are available, so you
9452 could decide to let Automake perform distribution or installation.
9453 Here is a possible @file{Makefile.am}:
9455 @example
9456 all-local:
9457         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
9458 check-local:
9459         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
9460 clean-local:
9461         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
9463 # Assuming the package knows how to install itself
9464 install-data-local:
9465         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
9466 install-exec-local:
9467         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
9468 uninstall-local:
9469         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
9471 # Distribute files from here.
9472 EXTRA_DIST = subdir/Makefile subdir/program.c ...
9473 @end example
9475 Pushing this idea to the extreme, it is also possible to ignore the
9476 subproject build system and build everything from this proxy
9477 @file{Makefile.am}.  This might sounds very sensible if you need VPATH
9478 builds but the subproject does not support them.
9480 @node Distributing
9481 @chapter Distributing @file{Makefile.in}s
9483 Automake places no restrictions on the distribution of the resulting
9484 @file{Makefile.in}s.  We still encourage software authors to
9485 distribute their work under terms like those of the GPL, but doing so
9486 is not required to use Automake.
9488 Some of the files that can be automatically installed via the
9489 @option{--add-missing} switch do fall under the GPL@.  However, these also
9490 have a special exception allowing you to distribute them with your
9491 package, regardless of the licensing you choose.
9494 @node API versioning
9495 @chapter Automake API versioning
9497 New Automake releases usually include bug fixes and new features.
9498 Unfortunately they may also introduce new bugs and incompatibilities.
9499 This makes four reasons why a package may require a particular Automake
9500 version.
9502 Things get worse when maintaining a large tree of packages, each one
9503 requiring a different version of Automake.  In the past, this meant that
9504 any developer (and sometime users) had to install several versions of
9505 Automake in different places, and switch @samp{$PATH} appropriately for
9506 each package.
9508 Starting with version 1.6, Automake installs versioned binaries.  This
9509 means you can install several versions of Automake in the same
9510 @samp{$prefix}, and can select an arbitrary Automake version by running
9511 @command{automake-1.6} or @command{automake-1.7} without juggling with
9512 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
9513 will use @command{automake-1.6} explicitly in their rebuild rules.
9515 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
9516 not Automake's version.  If a bug fix release is made, for instance
9517 Automake 1.6.1, the API version will remain 1.6.  This means that a
9518 package that works with Automake 1.6 should also work with 1.6.1; after
9519 all, this is what people expect from bug fix releases.
9521 If your package relies on a feature or a bug fix introduced in
9522 a release, you can pass this version as an option to Automake to ensure
9523 older releases will not be used.  For instance, use this in your
9524 @file{configure.ac}:
9526 @example
9527   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
9528 @end example
9529 @noindent
9530 or, in a particular @file{Makefile.am}:
9532 @example
9533   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
9534 @end example
9535 @noindent
9536 Automake will print an error message if its version is
9537 older than the requested version.
9540 @heading What is in the API
9542 Automake's programming interface is not easy to define.  Basically it
9543 should include at least all @strong{documented} variables and targets
9544 that a @file{Makefile.am} author can use, any behavior associated with
9545 them (e.g., the places where @samp{-hook}'s are run), the command line
9546 interface of @command{automake} and @command{aclocal}, @dots{}
9548 @heading What is not in the API
9550 Every undocumented variable, target, or command line option, is not part
9551 of the API@.  You should avoid using them, as they could change from one
9552 version to the other (even in bug fix releases, if this helps to fix a
9553 bug).
9555 If it turns out you need to use such a undocumented feature, contact
9556 @email{automake@@gnu.org} and try to get it documented and exercised by
9557 the test-suite.
9559 @node Upgrading
9560 @chapter Upgrading a Package to a Newer Automake Version
9562 Automake maintains three kind of files in a package.
9564 @itemize
9565 @item @file{aclocal.m4}
9566 @item @file{Makefile.in}s
9567 @item auxiliary tools like @file{install-sh} or @file{py-compile}
9568 @end itemize
9570 @file{aclocal.m4} is generated by @command{aclocal} and contains some
9571 Automake-supplied M4 macros.  Auxiliary tools are installed by
9572 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
9573 built from @file{Makefile.am} by @command{automake}, and rely on the
9574 definitions of the M4 macros put in @file{aclocal.m4} as well as the
9575 behavior of the auxiliary tools installed.
9577 Because all these files are closely related, it is important to
9578 regenerate all of them when upgrading to a newer Automake release.
9579 The usual way to do that is
9581 @example
9582 aclocal # with any option needed (such a -I m4)
9583 autoconf
9584 automake --add-missing --force-missing
9585 @end example
9587 @noindent
9588 or more conveniently:
9590 @example
9591 autoreconf -vfi
9592 @end example
9594 The use of @option{--force-missing} ensures that auxiliary tools will be
9595 overridden by new versions (@pxref{Invoking Automake}).
9597 It is important to regenerate all these files each time Automake is
9598 upgraded, even between bug fixes releases.  For instance, it is not
9599 unusual for a bug fix to involve changes to both the rules generated
9600 in @file{Makefile.in} and the supporting M4 macros copied to
9601 @file{aclocal.m4}.
9603 Presently @command{automake} is able to diagnose situations where
9604 @file{aclocal.m4} has been generated with another version of
9605 @command{aclocal}.  However it never checks whether auxiliary scripts
9606 are up-to-date.  In other words, @command{automake} will tell you when
9607 @command{aclocal} needs to be rerun, but it will never diagnose a
9608 missing @option{--force-missing}.
9610 Before upgrading to a new major release, it is a good idea to read the
9611 file @file{NEWS}.  This file lists all changes between releases: new
9612 features, obsolete constructs, known incompatibilities, and
9613 workarounds.
9615 @node FAQ
9616 @chapter Frequently Asked Questions about Automake
9618 This chapter covers some questions that often come up on the mailing
9619 lists.
9621 @menu
9622 * CVS::                         CVS and generated files
9623 * maintainer-mode::             missing and AM_MAINTAINER_MODE
9624 * wildcards::                   Why doesn't Automake support wildcards?
9625 * limitations on file names::   Limitations on source and installed file names
9626 * distcleancheck::              Files left in build directory after distclean
9627 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
9628 * renamed objects::             Why are object files sometimes renamed?
9629 * Per-Object Flags::            How to simulate per-object flags?
9630 * Multiple Outputs::            Writing rules for tools with many output files
9631 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
9632 @end menu
9634 @node CVS
9635 @section CVS and generated files
9637 @subsection Background: distributed generated files
9638 @cindex generated files, distributed
9639 @cindex rebuild rules
9641 Packages made with Autoconf and Automake ship with some generated
9642 files like @file{configure} or @file{Makefile.in}.  These files were
9643 generated on the developer's host and are distributed so that
9644 end-users do not have to install the maintainer tools required to
9645 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
9646 or Info documentation, are usually distributed on similar grounds.
9648 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
9649 instance, @command{make} will run @command{autoconf} to rebuild
9650 @file{configure} whenever @file{configure.ac} is changed.  This makes
9651 development safer by ensuring a @file{configure} is never out-of-date
9652 with respect to @file{configure.ac}.
9654 As generated files shipped in packages are up-to-date, and because
9655 @command{tar} preserves times-tamps, these rebuild rules are not
9656 triggered when a user unpacks and builds a package.
9658 @subsection Background: CVS and timestamps
9659 @cindex timestamps and CVS
9660 @cindex CVS and timestamps
9662 Unless you use CVS keywords (in which case files must be updated at
9663 commit time), CVS preserves timestamp during @samp{cvs commit} and
9664 @samp{cvs import -d} operations.
9666 When you check out a file using @samp{cvs checkout} its timestamp is
9667 set to that of the revision that is being checked out.
9669 However, during @command{cvs update}, files will have the date of the
9670 update, not the original timestamp of this revision.  This is meant to
9671 make sure that @command{make} notices sources files have been updated.
9673 This timestamp shift is troublesome when both sources and generated
9674 files are kept under CVS@.  Because CVS processes files in lexical
9675 order, @file{configure.ac} will appear newer than @file{configure}
9676 after a @command{cvs update} that updates both files, even if
9677 @file{configure} was newer than @file{configure.ac} when it was
9678 checked in.  Calling @command{make} will then trigger a spurious rebuild
9679 of @file{configure}.
9681 @subsection Living with CVS in Autoconfiscated projects
9682 @cindex CVS and generated files
9683 @cindex generated files and CVS
9685 There are basically two clans amongst maintainers: those who keep all
9686 distributed files under CVS, including generated files, and those who
9687 keep generated files @emph{out} of CVS.
9689 @subsubheading All files in CVS
9691 @itemize @bullet
9692 @item
9693 The CVS repository contains all distributed files so you know exactly
9694 what is distributed, and you can checkout any prior version entirely.
9696 @item
9697 Maintainers can see how generated files evolve (for instance, you can
9698 see what happens to your @file{Makefile.in}s when you upgrade Automake
9699 and make sure they look OK).
9701 @item
9702 Users do not need the autotools to build a checkout of the project, it
9703 works just like a released tarball.
9705 @item
9706 If users use @command{cvs update} to update their copy, instead of
9707 @command{cvs checkout} to fetch a fresh one, timestamps will be
9708 inaccurate.  Some rebuild rules will be triggered and attempt to
9709 run developer tools such as @command{autoconf} or @command{automake}.
9711 Actually, calls to such tools are all wrapped into a call to the
9712 @command{missing} script discussed later (@pxref{maintainer-mode}).
9713 @command{missing} will take care of fixing the timestamps when these
9714 tools are not installed, so that the build can continue.
9716 @item
9717 In distributed development, developers are likely to have different
9718 version of the maintainer tools installed.  In this case rebuilds
9719 triggered by timestamp lossage will lead to spurious changes
9720 to generated files.  There are several solutions to this:
9722 @itemize
9723 @item
9724 All developers should use the same versions, so that the rebuilt files
9725 are identical to files in CVS@.  (This starts to be difficult when each
9726 project you work on uses different versions.)
9727 @item
9728 Or people use a script to fix the timestamp after a checkout (the GCC
9729 folks have such a script).
9730 @item
9731 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
9732 disable all these rebuild rules by default.  This is further discussed
9733 in @ref{maintainer-mode}.
9734 @end itemize
9736 @item
9737 Although we focused on spurious rebuilds, the converse can also
9738 happen.  CVS's timestamp handling can also let you think an
9739 out-of-date file is up-to-date.
9741 For instance, suppose a developer has modified @file{Makefile.am} and
9742 has rebuilt @file{Makefile.in}.  He then decide to do a last-minute
9743 change to @file{Makefile.am} right before checking in both files
9744 (without rebuilding @file{Makefile.in} to account for the change).
9746 This last change to @file{Makefile.am} make the copy of
9747 @file{Makefile.in} out-of-date.  Since CVS processes files
9748 alphabetically, when another developer @samp{cvs update} his or her
9749 tree, @file{Makefile.in} will happen to be newer than
9750 @file{Makefile.am}.  This other developer will not see
9751 @file{Makefile.in} is out-of-date.
9753 @end itemize
9755 @subsubheading Generated files out of CVS
9757 One way to get CVS and @command{make} working peacefully is to never
9758 store generated files in CVS, i.e., do not CVS-control files that
9759 are @file{Makefile} targets (also called @emph{derived} files).
9761 This way developers are not annoyed by changes to generated files.  It
9762 does not matter if they all have different versions (assuming they are
9763 compatible, of course).  And finally, timestamps are not lost, changes
9764 to sources files can't be missed as in the
9765 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
9767 The drawback is that the CVS repository is not an exact copy of what
9768 is distributed and that users now need to install various development
9769 tools (maybe even specific versions) before they can build a checkout.
9770 But, after all, CVS's job is versioning, not distribution.
9772 Allowing developers to use different versions of their tools can also
9773 hide bugs during distributed development.  Indeed, developers will be
9774 using (hence testing) their own generated files, instead of the
9775 generated files that will be released actually.  The developer who
9776 prepares the tarball might be using a version of the tool that
9777 produces bogus output (for instance a non-portable C file), something
9778 other developers could have noticed if they weren't using their own
9779 versions of this tool.
9781 @subsection Third-party files
9782 @cindex CVS and third-party files
9783 @cindex third-party files and CVS
9785 Another class of files not discussed here (because they do not cause
9786 timestamp issues) are files that are shipped with a package, but
9787 maintained elsewhere.  For instance, tools like @command{gettextize}
9788 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
9789 Libtool), will install or update files in your package.
9791 These files, whether they are kept under CVS or not, raise similar
9792 concerns about version mismatch between developers' tools.  The
9793 Gettext manual has a section about this, see @ref{CVS Issues, CVS
9794 Issues, Integrating with CVS, gettext, GNU gettext tools}.
9796 @node maintainer-mode
9797 @section @command{missing} and @code{AM_MAINTAINER_MODE}
9799 @subsection @command{missing}
9800 @cindex @command{missing}, purpose
9802 The @command{missing} script is a wrapper around several maintainer
9803 tools, designed to warn users if a maintainer tool is required but
9804 missing.  Typical maintainer tools are @command{autoconf},
9805 @command{automake}, @command{bison}, etc.  Because file generated by
9806 these tools are shipped with the other sources of a package, these
9807 tools shouldn't be required during a user build and they are not
9808 checked for in @file{configure}.
9810 However, if for some reason a rebuild rule is triggered and involves a
9811 missing tool, @command{missing} will notice it and warn the user.
9812 Besides the warning, when a tool is missing, @command{missing} will
9813 attempt to fix timestamps in a way that allows the build to continue.
9814 For instance, @command{missing} will touch @file{configure} if
9815 @command{autoconf} is not installed.  When all distributed files are
9816 kept under CVS, this feature of @command{missing} allows user
9817 @emph{with no maintainer tools} to build a package off CVS, bypassing
9818 any timestamp inconsistency implied by @samp{cvs update}.
9820 If the required tool is installed, @command{missing} will run it and
9821 won't attempt to continue after failures.  This is correct during
9822 development: developers love fixing failures.  However, users with
9823 wrong versions of maintainer tools may get an error when the rebuild
9824 rule is spuriously triggered, halting the build.  This failure to let
9825 the build continue is one of the arguments of the
9826 @code{AM_MAINTAINER_MODE} advocates.
9828 @subsection @code{AM_MAINTAINER_MODE}
9829 @cindex @code{AM_MAINTAINER_MODE}, purpose
9830 @acindex AM_MAINTAINER_MODE
9832 @code{AM_MAINTAINER_MODE} disables the so called "rebuild rules" by
9833 default.  If you have @code{AM_MAINTAINER_MODE} in
9834 @file{configure.ac}, and run @samp{./configure && make}, then
9835 @command{make} will *never* attempt to rebuilt @file{configure},
9836 @file{Makefile.in}s, Lex or Yacc outputs, etc.  I.e., this disables
9837 build rules for files that are usually distributed and that users
9838 should normally not have to update.
9840 If you run @samp{./configure --enable-maintainer-mode}, then these
9841 rebuild rules will be active.
9843 People use @code{AM_MAINTAINER_MODE} either because they do want their
9844 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
9845 because they simply can't stand the rebuild rules and prefer running
9846 maintainer tools explicitly.
9848 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
9849 rules conditionally.  Some developers use this feature to disable
9850 rules that need exotic tools that users may not have available.
9852 Several years ago Fran@,{c}ois Pinard pointed out several arguments
9853 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
9854 insecurity.  By removing dependencies you get non-dependable builds:
9855 change to sources files can have no effect on generated files and this
9856 can be very confusing when unnoticed.  He adds that security shouldn't
9857 be reserved to maintainers (what @option{--enable-maintainer-mode}
9858 suggests), on the contrary.  If one user has to modify a
9859 @file{Makefile.am}, then either @file{Makefile.in} should be updated
9860 or a warning should be output (this is what Automake uses
9861 @command{missing} for) but the last thing you want is that nothing
9862 happens and the user doesn't notice it (this is what happens when
9863 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
9865 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
9866 swayed by Fran@,{c}ois's arguments, and got rid of
9867 @code{AM_MAINTAINER_MODE} in all of his packages.
9869 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
9870 it helps them working on projects where all files are kept under CVS,
9871 and because @command{missing} isn't enough if you have the wrong
9872 version of the tools.
9875 @node wildcards
9876 @section Why doesn't Automake support wildcards?
9877 @cindex wildcards
9879 Developers are lazy.  They would often like to use wildcards in
9880 @file{Makefile.am}s, so that they would not need to remember to
9881 update @file{Makefile.am}s every time they add, delete, or rename
9882 a file.
9884 There are several objections to this:
9885 @itemize
9886 @item
9887 When using CVS (or similar) developers need to remember they have to
9888 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
9889 @file{Makefile.am} accordingly quickly becomes a reflex.
9891 Conversely, if your application doesn't compile
9892 because you forgot to add a file in @file{Makefile.am}, it will help
9893 you remember to @samp{cvs add} it.
9895 @item
9896 Using wildcards makes it easy to distribute files by mistake.  For
9897 instance, some code a developer is experimenting with (a test case,
9898 say) that should not be part of the distribution.
9900 @item
9901 Using wildcards it's easy to omit some files by mistake.  For
9902 instance, one developer creates a new file, uses it in many places,
9903 but forgets to commit it.  Another developer then checks out the
9904 incomplete project and is able to run @samp{make dist} successfully,
9905 even though a file is missing. By listing files, @samp{make dist}
9906 @emph{will} complain.
9908 @item
9909 Finally, it's really hard to @emph{forget} to add a file to
9910 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
9911 not compiled or installed, so you can't even test them.
9912 @end itemize
9914 Still, these are philosophical objections, and as such you may disagree,
9915 or find enough value in wildcards to dismiss all of them.  Before you
9916 start writing a patch against Automake to teach it about wildcards,
9917 let's see the main technical issue: portability.
9919 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
9920 not portable to other @command{make} implementations.
9922 The only way Automake could support @command{$(wildcard ...)} is by
9923 expending @command{$(wildcard ...)} when @command{automake} is run.
9924 The resulting @file{Makefile.in}s would be portable since they would
9925 list all files and not use @samp{$(wildcard ...)}.  However that
9926 means developers would need to remember to run @command{automake} each
9927 time they add, delete, or rename files.
9929 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
9930 it's easier and faster to type @samp{automake; make} than to type
9931 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
9932 patch to add support for this syntax.  Some people use scripts to
9933 generate file lists in @file{Makefile.am} or in separate
9934 @file{Makefile} fragments.
9936 Even if you don't care about portability, and are tempted to use
9937 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
9938 should know there are many places where Automake need to know exactly
9939 which files should be processed.  As Automake doesn't know how to
9940 expand @samp{$(wildcard ...)}, you cannot use it in these places.
9941 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
9942 variables as far Automake is concerned.
9944 You can get warnings about @samp{$(wildcard ...}) constructs using the
9945 @option{-Wportability} flag.
9947 @node limitations on file names
9948 @section Limitations on file names
9949 @cindex file names, limitations on
9951 Automake attempts to support all kinds of file names, even those that
9952 contain unusual characters or are unusually long.  However, some
9953 limitations are imposed by the underlying operating system and tools.
9955 Most operating systems prohibit the use of the null byte in file
9956 names, and reserve @samp{/} as a directory separator.  Also, they
9957 require that file names are properly encoded for the user's locale.
9958 Automake is subject to these limits.
9960 Portable packages should limit themselves to @acronym{POSIX} file
9961 names.  These can contain @acronym{ASCII} letters and digits,
9962 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
9963 separated by @samp{/}.  File name components cannot begin with
9964 @samp{-}.
9966 Portable POSIX file names cannot contain components that exceed a
9967 14-byte limit, but nowadays it's normally safe to assume the
9968 more-generous @acronym{XOPEN} limit of 255 bytes.  @acronym{POSIX}
9969 limits file names to 255 bytes (@acronym{XOPEN} allows 1023 bytes),
9970 but you may want to limit a source tarball to file names to 99 bytes
9971 to avoid interoperability problems with old versions of @command{tar}.
9973 If you depart from these rules (e.g., by using non-@acronym{ASCII}
9974 characters in file names, or by using lengthy file names), your
9975 installers may have problems for reasons unrelated to Automake.
9976 However, if this does not concern you, you should know about the
9977 limitations imposed by Automake itself.  These limitations are
9978 undesirable, but some of them seem to be inherent to underlying tools
9979 like Autoconf, Make, M4, and the shell.  They fall into three
9980 categories: install directories, build directories, and file names.
9982 The following characters:
9984 @example
9985 @r{newline} " # $ ' `
9986 @end example
9988 should not appear in the names of install directories.  For example,
9989 the operand of @command{configure}'s @option{--prefix} option should
9990 not contain these characters.
9992 Build directories suffer the same limitations as install directories,
9993 and in addition should not contain the following characters:
9995 @example
9996 & @@ \
9997 @end example
9999 For example, the full name of the directory containing the source
10000 files should not contain these characters.
10002 Source and installation file names like @file{main.c} are limited even
10003 further: they should conform to the @acronym{POSIX}/@acronym{XOPEN}
10004 rules described above.  In addition, if you plan to port to
10005 non-@acronym{POSIX} environments, you should avoid file names that
10006 differ only in case (e.g., @file{makefile} and @file{Makefile}).
10007 Nowadays it is no longer worth worrying about the 8.3 limits of
10008 @acronym{DOS} file systems.
10010 @node distcleancheck
10011 @section Files left in build directory after distclean
10012 @cindex @code{distclean}, diagnostic
10013 @cindex @samp{make distclean}, diagnostic
10014 @cindex dependencies and distributed files
10015 @trindex distclean
10016 @trindex distcleancheck
10018 This is a diagnostic you might encounter while running @samp{make
10019 distcheck}.
10021 As explained in @ref{Dist}, @samp{make distcheck} attempts to build
10022 and check your package for errors like this one.
10024 @samp{make distcheck} will perform a @code{VPATH} build of your
10025 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
10026 Files left in the build directory after @samp{make distclean} has run
10027 are listed after this error.
10029 This diagnostic really covers two kinds of errors:
10031 @itemize @bullet
10032 @item
10033 files that are forgotten by distclean;
10034 @item
10035 distributed files that are erroneously rebuilt.
10036 @end itemize
10038 The former left-over files are not distributed, so the fix is to mark
10039 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
10040 more explanations.
10042 The latter bug is not always easy to understand and fix, so let's
10043 proceed with an example.  Suppose our package contains a program for
10044 which we want to build a man page using @command{help2man}.  GNU
10045 @command{help2man} produces simple manual pages from the @option{--help}
10046 and @option{--version} output of other commands (@pxref{Top, , Overview,
10047 help2man, The Help2man Manual}).  Because we don't to force want our
10048 users to install @command{help2man}, we decide to distribute the
10049 generated man page using the following setup.
10051 @example
10052 # This Makefile.am is bogus.
10053 bin_PROGRAMS = foo
10054 foo_SOURCES = foo.c
10055 dist_man_MANS = foo.1
10057 foo.1: foo$(EXEEXT)
10058         help2man --output=foo.1 ./foo$(EXEEXT)
10059 @end example
10061 This will effectively distribute the man page.  However,
10062 @samp{make distcheck} will fail with:
10064 @example
10065 ERROR: files left in build directory after distclean:
10066 ./foo.1
10067 @end example
10069 Why was @file{foo.1} rebuilt?  Because although distributed,
10070 @file{foo.1} depends on a non-distributed built file:
10071 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
10072 will always appear to be newer than the distributed @file{foo.1}.
10074 @samp{make distcheck} caught an inconsistency in our package.  Our
10075 intent was to distribute @file{foo.1} so users do not need installing
10076 @command{help2man}, however since this our rule causes this file to be
10077 always rebuilt, users @emph{do} need @command{help2man}.  Either we
10078 should ensure that @file{foo.1} is not rebuilt by users, or there is
10079 no point in distributing @file{foo.1}.
10081 More generally, the rule is that distributed files should never depend
10082 on non-distributed built files.  If you distribute something
10083 generated, distribute its sources.
10085 One way to fix the above example, while still distributing
10086 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
10087 assuming @command{foo --version} and @command{foo --help} do not
10088 change unless @file{foo.c} or @file{configure.ac} change, we could
10089 write the following @file{Makefile.am}:
10091 @example
10092 bin_PROGRAMS = foo
10093 foo_SOURCES = foo.c
10094 dist_man_MANS = foo.1
10096 foo.1: foo.c $(top_srcdir)/configure.ac
10097         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
10098         help2man --output=foo.1 ./foo$(EXEEXT)
10099 @end example
10101 This way, @file{foo.1} will not get rebuilt every time
10102 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
10103 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
10104 way to ensure this would be to use separate directories for binaries
10105 and man pages, and set @code{SUBDIRS} so that binaries are built
10106 before man pages.
10108 We could also decide not to distribute @file{foo.1}.  In
10109 this case it's fine to have @file{foo.1} dependent upon
10110 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
10111 However it would be impossible to build the package in a
10112 cross-compilation, because building @file{foo.1} involves
10113 an @emph{execution} of @file{foo$(EXEEXT)}.
10115 Another context where such errors are common is when distributed files
10116 are built by tools that are built by the package.  The pattern is
10117 similar:
10119 @example
10120 distributed-file: built-tools distributed-sources
10121         build-command
10122 @end example
10124 @noindent
10125 should be changed to
10127 @example
10128 distributed-file: distributed-sources
10129         $(MAKE) $(AM_MAKEFLAGS) built-tools
10130         build-command
10131 @end example
10133 @noindent
10134 or you could choose not to distribute @file{distributed-file}, if
10135 cross-compilation does not matter.
10137 The points made through these examples are worth a summary:
10139 @cartouche
10140 @itemize
10141 @item
10142 Distributed files should never depend upon non-distributed built
10143 files.
10144 @item
10145 Distributed files should be distributed with all their dependencies.
10146 @item
10147 If a file is @emph{intended} to be rebuilt by users, then there is no point
10148 in distributing it.
10149 @end itemize
10150 @end cartouche
10152 @vrindex distcleancheck_listfiles
10153 For desperate cases, it's always possible to disable this check by
10154 setting @code{distcleancheck_listfiles} as documented in @ref{Dist}.
10155 Make sure you do understand the reason why @samp{make distcheck}
10156 complains before you do this.  @code{distcleancheck_listfiles} is a
10157 way to @emph{hide} errors, not to fix them.  You can always do better.
10159 @node Flag Variables Ordering
10160 @section Flag Variables Ordering
10161 @cindex Ordering flag variables
10162 @cindex Flag variables, ordering
10164 @display
10165 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
10166 @code{mumble_CFLAGS}?
10167 @end display
10169 @display
10170 Why does @command{automake} output @code{CPPFLAGS} after
10171 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
10172 @end display
10174 @display
10175 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
10176 one @file{Makefile.am} I would like to append a new flag, however if I
10177 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
10178 flags, not appended.
10179 @end display
10181 @subsection Compile Flag Variables
10182 @cindex Flag Variables, Ordering
10183 @cindex Compile Flag Variables
10184 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
10185 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
10186 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
10187 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
10188 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
10189 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
10190 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
10191 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
10192 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
10193 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
10194 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
10195 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
10196 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
10197 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
10198 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
10199 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
10200 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
10201 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
10202 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
10203 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
10204 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
10205 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
10206 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
10207 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
10208 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
10209 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
10210 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
10211 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
10213 This section attempts to answer all the above questions.  We will
10214 mostly discuss @code{CPPFLAGS} in our examples, but actually the
10215 answer holds for all the compile flags used in Automake:
10216 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
10217 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
10218 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
10219 @code{UPCFLAGS}, and @code{YFLAGS}.
10221 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
10222 three variables that can be used to pass flags to the C preprocessor
10223 (actually these variables are also used for other languages like C++
10224 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
10225 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
10226 and @code{mumble_CPPFLAGS} is the variable specific to the
10227 @code{mumble} target (we call this a per-target variable,
10228 @pxref{Program and Library Variables}).
10230 Automake always uses two of these variables when compiling C sources
10231 files.  When compiling an object file for the @code{mumble} target,
10232 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
10233 @code{AM_CPPFLAGS} otherwise.  The second variable is always
10234 @code{CPPFLAGS}.
10236 In the following example,
10238 @example
10239 bin_PROGRAMS = foo bar
10240 foo_SOURCES = xyz.c
10241 bar_SOURCES = main.c
10242 foo_CPPFLAGS = -DFOO
10243 AM_CPPFLAGS = -DBAZ
10244 @end example
10246 @noindent
10247 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
10248 (because @file{xyz.o} is part of the @code{foo} target), while
10249 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
10250 (because there is no per-target variable for target @code{bar}).
10252 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
10253 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
10254 is a user variable, i.e., a variable that users are entitled to modify
10255 in order to compile the package.  This variable, like many others,
10256 is documented at the end of the output of @samp{configure --help}.
10258 For instance, someone who needs to add @file{/home/my/usr/include} to
10259 the C compiler's search path would configure a package with
10261 @example
10262 ./configure CPPFLAGS='-I /home/my/usr/include'
10263 @end example
10265 @noindent
10266 and this flag would be propagated to the compile rules of all
10267 @file{Makefile}s.
10269 It is also not uncommon to override a user variable at
10270 @command{make}-time.  Many installers do this with @code{prefix}, but
10271 this can be useful with compiler flags too.  For instance, if, while
10272 debugging a C++ project, you need to disable optimization in one
10273 specific object file, you can run something like
10275 @example
10276 rm file.o
10277 make CXXFLAGS=-O0 file.o
10278 make
10279 @end example
10281 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
10282 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
10283 should always have the last say.  It probably makes more sense if you
10284 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
10285 should supersede any other switch from @code{AM_CXXFLAGS} or
10286 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
10287 of @code{CXXFLAGS}).
10289 You should never redefine a user variable such as @code{CPPFLAGS} in
10290 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
10291 mistakes.  Even something like
10293 @example
10294 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
10295 @end example
10297 @noindent
10298 is erroneous.  Although this preserves @file{configure}'s value of
10299 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
10300 user attempts to override @code{CPPFLAGS} from the @command{make}
10301 command line.
10303 @example
10304 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
10305 @end example
10307 @noindent
10308 is all what is needed here if no per-target flags are used.
10310 You should not add options to these user variables within
10311 @file{configure} either, for the same reason.  Occasionally you need
10312 to modify these variables to perform a test, but you should reset
10313 their values afterwards.  In contrast, it is OK to modify the
10314 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
10315 them, but it is rather rare that you need to do this, unless you
10316 really want to change the default definitions of the @samp{AM_}
10317 variables in all @file{Makefile}s.
10319 What we recommend is that you define extra flags in separate
10320 variables.  For instance, you may write an Autoconf macro that computes
10321 a set of warning options for the C compiler, and @code{AC_SUBST} them
10322 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
10323 determines which compiler and which linker flags should be used to
10324 link with library @file{libfoo}, and @code{AC_SUBST} these in
10325 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
10326 @file{Makefile.am} could use these variables as follows:
10328 @example
10329 AM_CFLAGS = $(WARNINGCFLAGS)
10330 bin_PROGRAMS = prog1 prog2
10331 prog1_SOURCES = @dots{}
10332 prog2_SOURCES = @dots{}
10333 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
10334 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
10335 @end example
10337 In this example both programs will be compiled with the flags
10338 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
10339 additionally be compiled with the flags required to link with
10340 @file{libfoo}.
10342 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
10343 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
10344 every target in a @file{Makefile.in}.
10346 Using variables like this gives you full control over the ordering of
10347 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
10348 you want to negate for a particular target, you can use something like
10349 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
10350 been forcefully appended to @code{CFLAGS}, there would be no way to
10351 disable one flag.  Yet another reason to leave user variables to
10352 users.
10354 Finally, we have avoided naming the variable of the example
10355 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
10356 Automake to think that this is actually a per-target variable (like
10357 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
10359 @subsection Other Variables
10361 There are other variables in Automake that follow similar principles
10362 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
10363 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
10364 DejaGnu tests (@pxref{Tests}) use @code{RUNTESTDEFAULTFLAGS} and
10365 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
10366 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
10367 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
10368 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
10369 of these rules do support per-target flags (yet).
10371 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
10372 obeys this naming scheme.  The slight difference is that
10373 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
10374 @command{make} itself.
10376 However you should not think that all variables ending with
10377 @code{FLAGS} follow this convention.  For instance,
10378 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Dist}),
10379 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
10380 are two variables that are only useful to the maintainer and have no
10381 user counterpart.
10383 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
10384 has neither @code{AM_} nor per-target cousin.
10386 Finally you should not think either that the existence of a per-target
10387 variable implies that of an @code{AM_} variable or that of a user
10388 variable.  For instance, the @code{mumble_LDADD} per-target variable
10389 overrides the global @code{LDADD} variable (which is not a user
10390 variable), and @code{mumble_LIBADD} exists only as a per-target
10391 variable.  @xref{Program and Library Variables}.
10394 @node renamed objects
10395 @section Why are object files sometimes renamed?
10397 This happens when per-target compilation flags are used.  Object
10398 files need to be renamed just in case they would clash with object
10399 files compiled from the same sources, but with different flags.
10400 Consider the following example.
10402 @example
10403 bin_PROGRAMS = true false
10404 true_SOURCES = generic.c
10405 true_CPPFLAGS = -DEXIT_CODE=0
10406 false_SOURCES = generic.c
10407 false_CPPFLAGS = -DEXIT_CODE=1
10408 @end example
10409 @noindent
10410 Obviously the two programs are built from the same source, but it
10411 would be bad if they shared the same object, because @file{generic.o}
10412 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
10413 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
10414 build two different objects: @file{true-generic.o} and
10415 @file{false-generic.o}.
10417 @command{automake} doesn't actually look whether source files are
10418 shared to decide if it must rename objects.  It will just rename all
10419 objects of a target as soon as it sees per-target compilation flags
10420 are used.
10422 It's OK to share object files when per-target compilation flags are not
10423 used.  For instance, @file{true} and @file{false} will both use
10424 @file{version.o} in the following example.
10426 @example
10427 AM_CPPFLAGS = -DVERSION=1.0
10428 bin_PROGRAMS = true false
10429 true_SOURCES = true.c version.c
10430 false_SOURCES = false.c version.c
10431 @end example
10433 Note that the renaming of objects is also affected by the
10434 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
10437 @node Per-Object Flags
10438 @section Per-Object Flags Emulation
10439 @cindex Per-object flags, emulated
10441 @display
10442 One of my source files needs to be compiled with different flags.  How
10443 do I do?
10444 @end display
10446 Automake supports per-program and per-library compilation flags (see
10447 @ref{Program and Library Variables} and @ref{Flag Variables
10448 Ordering}).  With this you can define compilation flags that apply to
10449 all files compiled for a target.  For instance, in
10451 @example
10452 bin_PROGRAMS = foo
10453 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
10454 foo_CFLAGS = -some -flags
10455 @end example
10457 @noindent
10458 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
10459 compiled with @samp{-some -flags}.  (If you wonder about the names of
10460 these object files, see @ref{renamed objects}.)  Note that
10461 @code{foo_CFLAGS} gives the flags to use when compiling all the C
10462 sources of the @emph{program} @code{foo}, it has nothing to do with
10463 @file{foo.c} or @file{foo-foo.o} specifically.
10465 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
10466 specific flags, that none of the other files require?  Obviously
10467 per-program flags are not directly applicable here.  Something like
10468 per-object flags are expected, i.e., flags that would be used only
10469 when creating @file{foo-foo.o}.  Automake does not support that,
10470 however this is easy to simulate using a library that contains only
10471 that object, and compiling this library with per-library flags.
10473 @example
10474 bin_PROGRAMS = foo
10475 foo_SOURCES = bar.c bar.h main.c
10476 foo_CFLAGS = -some -flags
10477 foo_LDADD = libfoo.a
10478 noinst_LIBRARIES = libfoo.a
10479 libfoo_a_SOURCES = foo.c foo.h
10480 libfoo_a_CFLAGS = -some -other -flags
10481 @end example
10483 Here @file{foo-bar.o} and @file{foo-main.o} will all be
10484 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
10485 be compiled using @samp{-some -other -flags}.  Eventually, all
10486 three objects will be linked to form @file{foo}.
10488 This trick can also be achieved using Libtool convenience libraries,
10489 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
10490 Convenience Libraries}).
10492 Another tempting idea to implement per-object flags is to override the
10493 compile rules @command{automake} would output for these files.
10494 Automake will not define a rule for a target you have defined, so you
10495 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
10496 We recommend against this, because this is error prone.  For instance,
10497 if you add such a rule to the first example, it will break the day you
10498 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
10499 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{renamed
10500 objects}).  Also in order to support dependency tracking, the two
10501 @file{.o}/@file{.obj} extensions, and all the other flags variables
10502 involved in a compilation, you will end up modifying a copy of the
10503 rule previously output by @command{automake} for this file.  If a new
10504 release of Automake generates a different rule, your copy will need to
10505 be updated by hand.
10507 @node Multiple Outputs
10508 @section Handling Tools that Produce Many Outputs
10509 @cindex multiple outputs, rules with
10510 @cindex many outputs, rules with
10511 @cindex rules with multiple outputs
10513 This section describes a @command{make} idiom that can be used when a
10514 tool produces multiple output files.  It is not specific to Automake
10515 and can be used in ordinary @file{Makefile}s.
10517 Suppose we have a program called @command{foo} that will read one file
10518 called @file{data.foo} and produce two files named @file{data.c} and
10519 @file{data.h}.  We want to write a @file{Makefile} rule that captures
10520 this one-to-two dependency.
10522 The naive rule is incorrect:
10524 @example
10525 # This is incorrect.
10526 data.c data.h: data.foo
10527         foo data.foo
10528 @end example
10530 @noindent
10531 What the above rule really says is that @file{data.c} and
10532 @file{data.h} each depend on @file{data.foo}, and can each be built by
10533 running @samp{foo data.foo}.  In other words it is equivalent to:
10535 @example
10536 # We do not want this.
10537 data.c: data.foo
10538         foo data.foo
10539 data.h: data.foo
10540         foo data.foo
10541 @end example
10543 @noindent
10544 which means that @command{foo} can be run twice.  Usually it will not
10545 be run twice, because @command{make} implementations are smart enough
10546 to check for the existence of the second file after the first one has
10547 been built; they will therefore detect that it already exists.
10548 However there are a few situations where it can run twice anyway:
10550 @itemize
10551 @item
10552 The most worrying case is when running a parallel @command{make}.  If
10553 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
10554 data.foo} commands will run concurrently.  This is harmful.
10555 @item
10556 Another case is when the dependency (here @file{data.foo}) is
10557 (or depends upon) a phony target.
10558 @end itemize
10560 A solution that works with parallel @command{make} but not with
10561 phony dependencies is the following:
10563 @example
10564 data.c data.h: data.foo
10565         foo data.foo
10566 data.h: data.c
10567 @end example
10569 @noindent
10570 The above rules are equivalent to
10572 @example
10573 data.c: data.foo
10574         foo data.foo
10575 data.h: data.foo data.c
10576         foo data.foo
10577 @end example
10578 @noindent
10579 therefore a parallel @command{make} will have to serialize the builds
10580 of @file{data.c} and @file{data.h}, and will detect that the second is
10581 no longer needed once the first is over.
10583 Using this pattern is probably enough for most cases.  However it does
10584 not scale easily to more output files (in this scheme all output files
10585 must be totally ordered by the dependency relation), so we will
10586 explore a more complicated solution.
10588 Another idea is to write the following:
10590 @example
10591 # There is still a problem with this one.
10592 data.c: data.foo
10593         foo data.foo
10594 data.h: data.c
10595 @end example
10597 @noindent
10598 The idea is that @samp{foo data.foo} is run only when @file{data.c}
10599 needs to be updated, but we further state that @file{data.h} depends
10600 upon @file{data.c}.  That way, if @file{data.h} is required and
10601 @file{data.foo} is out of date, the dependency on @file{data.c} will
10602 trigger the build.
10604 This is almost perfect, but suppose we have built @file{data.h} and
10605 @file{data.c}, and then we erase @file{data.h}.  Then, running
10606 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
10607 just state that @file{data.c} must be up-to-date with respect to
10608 @file{data.foo}, and this is already the case.
10610 What we need is a rule that forces a rebuild when @file{data.h} is
10611 missing.  Here it is:
10613 @example
10614 data.c: data.foo
10615         foo data.foo
10616 data.h: data.c
10617 ## Recover from the removal of $@@
10618         @@if test -f $@@; then :; else \
10619           rm -f data.c; \
10620           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10621         fi
10622 @end example
10624 The above scheme can be extended to handle more outputs and more
10625 inputs.  One of the outputs is selected to serve as a witness to the
10626 successful completion of the command, it depends upon all inputs, and
10627 all other outputs depend upon it.  For instance, if @command{foo}
10628 should additionally read @file{data.bar} and also produce
10629 @file{data.w} and @file{data.x}, we would write:
10631 @example
10632 data.c: data.foo data.bar
10633         foo data.foo data.bar
10634 data.h data.w data.x: data.c
10635 ## Recover from the removal of $@@
10636         @@if test -f $@@; then :; else \
10637           rm -f data.c; \
10638           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10639         fi
10640 @end example
10642 However there are now two minor problems in this setup.  One is related
10643 to the timestamp ordering of @file{data.h}, @file{data.w},
10644 @file{data.x}, and @file{data.c}.  The other one is a race condition
10645 if a parallel @command{make} attempts to run multiple instances of the
10646 recover block at once.
10648 Let us deal with the first problem.  @command{foo} outputs four files,
10649 but we do not know in which order these files are created.  Suppose
10650 that @file{data.h} is created before @file{data.c}.  Then we have a
10651 weird situation.  The next time @command{make} is run, @file{data.h}
10652 will appear older than @file{data.c}, the second rule will be
10653 triggered, a shell will be started to execute the @samp{if@dots{}fi}
10654 command, but actually it will just execute the @code{then} branch,
10655 that is: nothing.  In other words, because the witness we selected is
10656 not the first file created by @command{foo}, @command{make} will start
10657 a shell to do nothing each time it is run.
10659 A simple riposte is to fix the timestamps when this happens.
10661 @example
10662 data.c: data.foo data.bar
10663         foo data.foo data.bar
10664 data.h data.w data.x: data.c
10665         @@if test -f $@@; then \
10666           touch $@@; \
10667         else \
10668 ## Recover from the removal of $@@
10669           rm -f data.c; \
10670           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10671         fi
10672 @end example
10674 Another solution is to use a different and dedicated file as witness,
10675 rather than using any of @command{foo}'s outputs.
10677 @example
10678 data.stamp: data.foo data.bar
10679         @@rm -f data.tmp
10680         @@touch data.tmp
10681         foo data.foo data.bar
10682         @@mv -f data.tmp $@@
10683 data.c data.h data.w data.x: data.stamp
10684 ## Recover from the removal of $@@
10685         @@if test -f $@@; then :; else \
10686           rm -f data.stamp; \
10687           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10688         fi
10689 @end example
10691 @file{data.tmp} is created before @command{foo} is run, so it has a
10692 timestamp older than output files output by @command{foo}.  It is then
10693 renamed to @file{data.stamp} after @command{foo} has run, because we
10694 do not want to update @file{data.stamp} if @command{foo} fails.
10696 This solution still suffers from the second problem: the race
10697 condition in the recover rule.  If, after a successful build, a user
10698 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
10699 @command{make} may start both recover rules in parallel.  If the two
10700 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
10701 data.stamp} concurrently the build is likely to fail (for instance, the
10702 two rules will create @file{data.tmp}, but only one can rename it).
10704 Admittedly, such a weird situation does not arise during ordinary
10705 builds.  It occurs only when the build tree is mutilated.  Here
10706 @file{data.c} and @file{data.h} have been explicitly removed without
10707 also removing @file{data.stamp} and the other output files.
10708 @code{make clean; make} will always recover from these situations even
10709 with parallel makes, so you may decide that the recover rule is solely
10710 to help non-parallel make users and leave things as-is.  Fixing this
10711 requires some locking mechanism to ensure only one instance of the
10712 recover rule rebuilds @file{data.stamp}.  One could imagine something
10713 along the following lines.
10715 @example
10716 data.c data.h data.w data.x: data.stamp
10717 ## Recover from the removal of $@@
10718         @@if test -f $@@; then :; else \
10719           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
10720 ## mkdir is a portable test-and-set
10721           if mkdir data.lock 2>/dev/null; then \
10722 ## This code is being executed by the first process.
10723             rm -f data.stamp; \
10724             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10725             result=$$?; rm -rf data.lock; exit $$result; \
10726           else \
10727 ## This code is being executed by the follower processes.
10728 ## Wait until the first process is done.
10729             while test -d data.lock; do sleep 1; done; \
10730 ## Succeed if and only if the first process succeeded.
10731             test -f data.stamp; \
10732           fi; \
10733         fi
10734 @end example
10736 Using a dedicated witness, like @file{data.stamp}, is very handy when
10737 the list of output files is not known beforehand.  As an illustration,
10738 consider the following rules to compile many @file{*.el} files into
10739 @file{*.elc} files in a single command.  It does not matter how
10740 @code{ELFILES} is defined (as long as it is not empty: empty targets
10741 are not accepted by POSIX).
10743 @example
10744 ELFILES = one.el two.el three.el @dots{}
10745 ELCFILES = $(ELFILES:=c)
10747 elc-stamp: $(ELFILES)
10748         @@rm -f elc-temp
10749         @@touch elc-temp
10750         $(elisp_comp) $(ELFILES)
10751         @@mv -f elc-temp $@@
10753 $(ELCFILES): elc-stamp
10754 ## Recover from the removal of $@@
10755         @@if test -f $@@; then :; else \
10756           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
10757           if mkdir elc-lock 2>/dev/null; then \
10758 ## This code is being executed by the first process.
10759             rm -f elc-stamp; \
10760             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
10761             rmdir elc-lock; \
10762           else \
10763 ## This code is being executed by the follower processes.
10764 ## Wait until the first process is done.
10765             while test -d elc-lock; do sleep 1; done; \
10766 ## Succeed if and only if the first process succeeded.
10767             test -f elc-stamp; exit $$?; \
10768           fi; \
10769         fi
10770 @end example
10772 For completeness it should be noted that GNU @command{make} is able to
10773 express rules with multiple output files using pattern rules
10774 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
10775 Manual}).  We do not discuss pattern rules here because they are not
10776 portable, but they can be convenient in packages that assume GNU
10777 @command{make}.
10780 @node Hard-Coded Install Paths
10781 @section Installing to Hard-Coded Locations
10783 @display
10784 My package needs to install some configuration file.  I tried to use
10785 the following rule, but @samp{make distcheck} fails.  Why?
10787 @example
10788 # Do not do this.
10789 install-data-local:
10790         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
10791 @end example
10792 @end display
10794 @display
10795 My package needs to populate the installation directory of another
10796 package at install-time.  I can easily compute that installation
10797 directory in @file{configure}, but if I install files therein,
10798 @samp{make distcheck} fails.  How else should I do?
10799 @end display
10801 These two setups share their symptoms: @samp{make distcheck} fails
10802 because they are installing files to hard-coded paths.  In the later
10803 case the path is not really hard-coded in the package, but we can
10804 consider it to be hard-coded in the system (or in whichever tool that
10805 supplies the path).  As long as the path does not use any of the
10806 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
10807 @samp{$(datadir)}, etc.), the effect will be the same:
10808 user-installations are impossible.
10810 When a (non-root) user wants to install a package, he usually has no
10811 right to install anything in @file{/usr} or @file{/usr/local}.  So he
10812 does something like @samp{./configure --prefix ~/usr} to install
10813 package in his own @file{~/usr} tree.
10815 If a package attempts to install something to some hard-coded path
10816 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
10817 then the installation will fail.  @samp{make distcheck} performs such
10818 a @option{--prefix} installation, hence it will fail too.
10820 Now, there are some easy solutions.
10822 The above @code{install-data-local} example for installing
10823 @file{/etc/afile} would be better replaced by
10825 @example
10826 sysconf_DATA = afile
10827 @end example
10829 @noindent
10830 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
10831 this is what the GNU Standards require.  When such a package is
10832 installed on a FHS compliant system, the installer will have to set
10833 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
10834 should not be concerned by such site policies: use the appropriate
10835 standard directory variable to install your files so that installer
10836 can easily redefine these variables to match their site conventions.
10838 Installing files that should be used by another package, is slightly
10839 more involved.  Let's take an example and assume you want to install
10840 shared library that is a Python extension module.  If you ask Python
10841 where to install the library, it will answer something like this:
10843 @example
10844 % @kbd{python -c 'from distutils import sysconfig;
10845              print sysconfig.get_python_lib(1,0)'}
10846 /usr/lib/python2.3/site-packages
10847 @end example
10849 If you indeed use this absolute path to install your shared library,
10850 non-root users will not be able to install the package, hence
10851 distcheck fails.
10853 Let's do better.  The @samp{sysconfig.get_python_lib()} function
10854 actually accepts a third argument that will replace Python's
10855 installation prefix.
10857 @example
10858 % @kbd{python -c 'from distutils import sysconfig;
10859              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
10860 $@{exec_prefix@}/lib/python2.3/site-packages
10861 @end example
10863 You can also use this new path.  If you do
10864 @itemize @bullet
10865 @item
10866 root users can install your package with the same @option{--prefix}
10867 as Python (you get the behavior of the previous attempt)
10869 @item
10870 non-root users can install your package too, they will have the
10871 extension module in a place that is not searched by Python but they
10872 can work around this using environment variables (and if you installed
10873 scripts that use this shared library, it's easy to tell Python were to
10874 look in the beginning of your script, so the script works in both
10875 cases).
10876 @end itemize
10878 The @code{AM_PATH_PYTHON} macro uses similar commands to define
10879 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
10881 Of course not all tools are as advanced as Python regarding that
10882 substitution of @var{prefix}.  So another strategy is to figure the
10883 part of the of the installation directory that must be preserved.  For
10884 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
10885 computes @samp{$(lispdir)}:
10887 @example
10888 $EMACS -batch -q -eval '(while load-path
10889   (princ (concat (car load-path) "\n"))
10890   (setq load-path (cdr load-path)))' >conftest.out
10891 lispdir=`sed -n
10892   -e 's,/$,,'
10893   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
10894         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
10895       @}'
10896   -e '/.*\/share\/x*emacs\/site-lisp$/@{
10897         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
10898       @}'
10899   conftest.out`
10900 @end example
10902 I.e., it just picks the first directory that looks like
10903 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
10904 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
10905 @samp{$@{datadir@}} appropriately.
10907 The emacs case looks complicated because it processes a list and
10908 expect two possible layouts, otherwise it's easy, and the benefit for
10909 non-root users are really worth the extra @command{sed} invocation.
10912 @node History
10913 @chapter History of Automake
10915 This chapter presents various aspects of the history of Automake.  The
10916 exhausted reader can safely skip it; this will be more of interest to
10917 nostalgic people, or to those curious to learn about the evolution of
10918 Automake.
10920 @menu
10921 * Timeline::                    The Automake story.
10922 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
10923 * Releases::                    Statistics about Automake Releases
10924 @end menu
10926 @node Timeline
10927 @section Timeline
10929 @table @asis
10930 @item 1994-09-19 First CVS commit.
10932 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
10933 working on Automake (or AutoMake, as it was spelt then) this Monday.
10935 The first version of the @command{automake} script looks as follows.
10937 @example
10938 #!/bin/sh
10940 status=0
10942 for makefile
10944   if test ! -f $@{makefile@}.am; then
10945     echo "automake: $@{makefile@}.am: No such honkin' file"
10946     status=1
10947     continue
10948   fi
10950   exec 4> $@{makefile@}.in
10952 done
10953 @end example
10955 From this you can already see that Automake will be about reading
10956 @file{*.am} file and producing @file{*.in} files.  You cannot see
10957 anything else, but if you also know that David is the one who created
10958 Autoconf two years before you can guess the rest.
10960 Several commits follow, and by the end of the day Automake is
10961 reported to work for GNU fileutils and GNU m4.
10963 The modus operandi is the one that is still used today: variables
10964 assignments in @file{Makefile.am} files trigger injections of
10965 precanned @file{Makefile} fragments into the generated
10966 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
10967 by the 4.4BSD @command{make} and include files, however Automake aims
10968 to be portable and to conform to the GNU standards for @file{Makefile}
10969 variables and targets.
10971 At this point, the most recent release of Autoconf is version 1.11,
10972 and David is preparing to release Autoconf 2.0 in late October.  As a
10973 matter of fact, he will barely touch Automake after September.
10975 @item 1994-11-05 David MacKenzie's last commit.
10977 At this point Automake is a 200 line portable shell script, plus 332
10978 lines of @file{Makefile} fragments.  In the @file{README}, David
10979 states his ambivalence between ``portable shell'' and ``more
10980 appropriate language'':
10982 @quotation
10983 I wrote it keeping in mind the possibility of it becoming an Autoconf
10984 macro, so it would run at configure-time.  That would slow
10985 configuration down a bit, but allow users to modify the Makefile.am
10986 without needing to fetch the AutoMake package.  And, the Makefile.in
10987 files wouldn't need to be distributed.  But all of AutoMake would.  So
10988 I might reimplement AutoMake in Perl, m4, or some other more
10989 appropriate language.
10990 @end quotation
10992 Automake is described as ``an experimental Makefile generator''.
10993 There is no documentation.  Adventurous users are referred to the
10994 examples and patches needed to use Automake with GNU m4 1.3, fileutils
10995 3.9, time 1.6, and development versions of find and indent.
10997 These examples seem to have been lost.  However at the time of writing
10998 (10 years later in September, 2004) the FSF still distributes a
10999 package that uses this version of Automake: check out GNU termutils
11000 2.0.
11002 @item 1995-11-12 Tom Tromey's first commit.
11004 After one year of inactivity, Tom Tromey takes over the package.
11005 Tom was working on GNU cpio back then, and doing this just for fun,
11006 having trouble finding a project to contribute to.  So while hacking
11007 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
11008 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
11009 grabbed it and tried it out.
11011 Tom didn't talk to djm about it until later, just to make sure he
11012 didn't mind if he made a release.  He did a bunch of early releases to
11013 the Gnits folks.
11015 Gnits was (and still is) totally informal, just a few GNU friends who
11016 Fran@,cois Pinard knew, who were all interested in making a common
11017 infrastructure for GNU projects, and shared a similar outlook on how
11018 to do it.  So they were able to make some progress.  It came along
11019 with Autoconf and extensions thereof, and then Automake from David and
11020 Tom (who were both gnitsians).  One of their ideas was to write a
11021 document paralleling the GNU standards, that was more strict in some
11022 ways and more detailed.  They never finished the GNITS standards, but
11023 the ideas mostly made their way into Automake.
11025 @item 1995-11-23 Automake 0.20
11027 Besides introducing automatic dependency tracking (@pxref{Dependency
11028 Tracking Evolution}), this version also supplies a 9-page manual.
11030 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
11031 exist, so many things had to be done by hand.  For instance, here is
11032 what a configure.in (this is the former name of the
11033 @file{configure.ac} we use today) must contain in order to use
11034 Automake 0.20:
11036 @example
11037 PACKAGE=cpio
11038 VERSION=2.3.911
11039 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
11040 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
11041 AC_SUBST(PACKAGE)
11042 AC_SUBST(VERSION)
11043 AC_ARG_PROGRAM
11044 AC_PROG_INSTALL
11045 @end example
11047 (Today all of the above is achieved by @code{AC_INIT} and
11048 @code{AM_INIT_AUTOMAKE}.)
11050 Here is how programs are specified in @file{Makefile.am}:
11052 @example
11053 PROGRAMS = hello
11054 hello_SOURCES = hello.c
11055 @end example
11057 This looks pretty much like what we do today, except the
11058 @code{PROGRAMS} variable has no directory prefix specifying where
11059 @file{hello} should be installed: all programs are installed in
11060 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
11061 that must be built but not installed (it is called
11062 @code{noinst_PROGRAMS} nowadays).
11064 Programs can be built conditionally using @code{AC_SUBST}itutions:
11066 @example
11067 PROGRAMS = @@progs@@
11068 AM_PROGRAMS = foo bar baz
11069 @end example
11071 (@code{AM_PROGRAMS} has since then been renamed to
11072 @code{EXTRA_PROGRAMS}.)
11074 Similarly scripts, static libraries, and data can built and installed
11075 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
11076 However @code{LIBRARIES} were treated a bit specially in that Automake
11077 did automatically supply the @file{lib} and @file{.a} prefixes.
11078 Therefore to build @file{libcpio.a}, one had to write
11080 @example
11081 LIBRARIES = cpio
11082 cpio_SOURCES = ...
11083 @end example
11085 Extra files to distribute must be listed in @code{DIST_OTHER} (the
11086 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
11087 distributed should appear in @code{DIST_SUBDIRS}, but the manual
11088 describes this as a temporary ugly hack (today extra directories should
11089 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
11090 for another purpose, @pxref{Conditional Subdirectories}).
11092 @item 1995-11-26 Automake 0.21
11094 In less time that it takes to cook a frozen pizza, Tom rewrites
11095 Automake using Perl.  At this time Perl 5 is only one year old, and
11096 Perl 4.036 is in use at many sites.  Supporting several Perl versions
11097 has been a source of problems through the whole history of Automake.
11099 If you never used Perl 4, imagine Perl 5 without objects, without
11100 @samp{my} variables (only dynamically scoped @samp{local} variables),
11101 without function prototypes, with function calls that needs to be
11102 prefixed with @samp{&}, etc.  Traces of this old style can still be
11103 found in today's @command{automake}.
11105 @item 1995-11-28 Automake 0.22
11106 @itemx 1995-11-29 Automake 0.23
11108 Bug fixes.
11110 @item 1995-12-08 Automake 0.24
11111 @itemx 1995-12-10 Automake 0.25
11113 Releases are raining.  0.24 introduces the uniform naming scheme we
11114 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
11115 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
11116 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
11117 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
11118 prefixes.)  Adding support for prefixes like that was one of the major
11119 ideas in automake; it has lasted pretty well.
11121 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
11122 Pinard's doing).
11124 0.25 fixes a Perl 4 portability bug.
11126 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
11127 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
11129 @item 1996-01-03 Automake 0.26
11130 @itemx 1996-01-03 Automake 0.27
11132 Of the many change and suggestions sent by Fran@,cois Pinard and
11133 included in 0.26, the most important is perhaps the advise that to
11134 ease customization a user rule or variable definition should always
11135 override an Automake rule or definition.
11137 Gordon Matzigkeit and Jim Meyering are two other early contributors
11138 that have been sending fixes.
11140 0.27 fixes yet another Perl 4 portability bug.
11142 @item 1996-01-13 Automake 0.28
11144 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
11145 support.  This is an important step because until this version
11146 Automake did only know about the @file{Makefile.am}s it processed.
11147 @file{configure.in} was Autoconf's world and the link between Autoconf
11148 and Automake had to be done by the @file{Makefile.am} author.  For
11149 instance, if @file{config.h} was generated by @file{configure}, it was the
11150 package maintainer's responsibility to define the @code{CONFIG_HEADER}
11151 variable in each @file{Makefile.am}.
11153 Succeeding releases will rely more and more on scanning
11154 @file{configure.in} to better automate the Autoconf integration.
11156 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
11157 @option{--gnu} and @option{--gnits} options, the latter being stricter.
11159 @item 1996-02-07 Automake 0.29
11161 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
11162 and rebuild rules for @file{configure}-generated file are
11163 automatically output.
11165 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
11166 scheme.
11168 @item 1996-02-24 Automake 0.30
11170 The test suite is born.  It contains 9 tests.  From now on test cases
11171 will be added pretty regularly (@pxref{Releases}), and this proved to
11172 be really helpful later on.
11174 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
11176 All the third-party Autoconf macros, written mostly by Fran@,cois
11177 Pinard (and later Jim Meyering), are distributed in Automake's
11178 hand-written @file{aclocal.m4} file.  Package maintainers are expected
11179 to extract the necessary macros from this file.  (In previous version
11180 you had to copy and paste them from the manual...)
11182 @item 1996-03-11 Automake 0.31
11184 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
11185 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
11186 whenever the @code{TESTS} variable is defined.
11188 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
11189 prefix is introduced.  The syntax is now the same as today.
11191 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
11193 @item 1996-04-27 Automake 0.32
11195 @code{-hook} targets are introduced; an idea from Dieter Baron.
11197 @file{*.info} files, which were output in the build directory are
11198 now built in the source directory, because they are distributed.  It
11199 seems these files like to move back and forth as that will happen
11200 again in future versions.
11202 @item 1996-05-18 Automake 0.33
11204 Gord Matzigkeit's main two contributions:
11206 @itemize
11207 @item very preliminary libtool support
11208 @item the distcheck rule
11209 @end itemize
11211 Although they were very basic at this point, these are probably
11212 among the top features for Automake today.
11214 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
11215 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
11216 author (@pxref{maintainer-mode}).
11218 @item 1996-05-28 Automake 1.0
11220 After only six months of heavy development, the automake script is
11221 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
11222 package has 30 pages of documentation, and 38 test cases.
11223 @file{aclocal.m4} contains 4 macros.
11225 From now on and until version 1.4, new releases will occur at a rate
11226 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
11227 been the name of beta releases for 1.2.  This is the first time
11228 Automake uses suffix letters to designate beta releases, an habit that
11229 lasts.
11231 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
11233 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
11235 Between June and October, the Autoconf development is almost staled.
11236 Roland McGrath has been working at the beginning of the year.  David
11237 comes back in November to release 2.12, but he won't touch Autoconf
11238 anymore after this year, and Autoconf then really stagnates.  The
11239 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
11241 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
11243 The mailing list is announced as follows:
11244 @smallexample
11245 I've created the "automake" mailing list.  It is
11246 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
11247 automake-request@@gnu.ai.mit.edu.
11249 The charter of this list is discussion of automake, autoconf, and
11250 other configuration/portability tools (e.g., libtool).  It is expected
11251 that discussion will range from pleas for help all the way up to
11252 patches.
11254 This list is archived on the FSF machines.  Offhand I don't know if
11255 you can get the archive without an account there.
11257 This list is open to anybody who wants to join.  Tell all your
11258 friends!
11259 -- Tom Tromey
11260 @end smallexample
11262 Before that people were discussing Automake privately, on the Gnits
11263 mailing list (which is not public either), and less frequently on
11264 @code{gnu.misc.discuss}.
11266 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
11267 noticed.  The archives of the early years of the
11268 @code{automake@@gnu.org} list have been lost, so today it is almost
11269 impossible to find traces of discussions that occurred before 1999.
11270 This has been annoying more than once, as such discussions can be
11271 useful to understand the rationale behind a piece of uncommented code
11272 that was introduced back then.
11274 @item 1997-06-22 Automake 1.2
11276 Automake developments continues, and more and more new Autoconf macros
11277 are required.  Distributing them in @file{aclocal.m4} and requiring
11278 people to browse this file to extract the relevant macros becomes
11279 uncomfortable.  Ideally, some of them should be contributed to
11280 Autoconf so that they can be used directly, however Autoconf is
11281 currently inactive.  Automake 1.2 consequently introduces
11282 @command{aclocal} (@command{aclocal} was actually started on
11283 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
11284 file from a repository of third-party macros.  Because Autoconf has
11285 stalled, Automake also becomes a kind of repository for such
11286 third-party macros, even macros completely unrelated to Automake (for
11287 instance macros that fix broken Autoconf macros).
11289 The 1.2 release contains 20 macros, among which the
11290 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
11291 @file{configure.in}.
11293 Libtool is fully supported using @code{*_LTLIBRARIES}.
11295 The missing script is introduced by Fran@,cois Pinard; it is meant to be
11296 a better solution than @code{AM_MAINTAINER_MODE}
11297 (@pxref{maintainer-mode}).
11299 Conditionals support was implemented by Ian Lance Taylor.  At the
11300 time, Tom and Ian were working on an internal project at Cygnus.  They
11301 were using ILU, which is pretty similar to CORBA@.  They wanted to
11302 integrate ILU into their build, which was all @file{configure}-based,
11303 and Ian thought that adding conditionals to @command{automake} was
11304 simpler than doing all the work in @file{configure} (which was the
11305 standard at the time).  So this was actually funded by Cygnus.
11307 This very useful but tricky feature will take a lot of time to
11308 stabilize.  (At the time this text is written, there are still
11309 primaries that have not been updated to support conditional
11310 definitions in Automake 1.9.)
11312 The @command{automake} script has almost doubled: 6089 lines of Perl,
11313 plus 1294 lines of @file{Makefile} fragments.
11315 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
11317 @item 1998-04-05 Automake 1.3
11319 This is a small advance compared to 1.2.
11320 It add support for assembly, and preliminary support for Java.
11322 Perl 5.004_04 is out, but fixes to support Perl 4 are still
11323 regularly submitted whenever Automake breaks it.
11325 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
11327 Sourceware was setup by Jason Molenda to host open source projects.
11329 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
11330 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake
11331 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
11332 publicly accessible CVS repository.  This CVS repository is a copy of
11333 the one Tom was using on his machine, which in turn is based on
11334 a copy of the CVS repository of David MacKenzie.  This is why we still
11335 have to full source history.  (Automake was on Sourceware until 2007-10-29,
11336 when it moved to a git repository on @code{savannah.gnu.org},
11337 but the Sourceware host had been renamed to @code{sources.redhat.com}.)
11339 The oldest file in the administrative directory of the CVS repository
11340 that was created on Sourceware is dated 1998-09-19, while the
11341 announcement that @command{automake} and @command{autoconf} had joined
11342 @command{sourceware} was made on 1998-10-26.  They were among the
11343 first projects to be hosted there.
11345 The heedful reader will have noticed Automake was exactly 4-year-old
11346 on 1998-09-19.
11348 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
11350 @item 1999-01-14 Automake 1.4
11352 This release adds support for Fortran 77 and for the @code{include}
11353 statement.  Also, @samp{+=} assignments are introduced, but it is
11354 still quite easy to fool Automake when mixing this with conditionals.
11356 These two releases, Automake 1.4 and Autoconf 2.13 makes a duo that
11357 will be used together for years.
11359 @command{automake} is 7228 lines, plus 1591 lines of Makefile
11360 fragment, 20 macros (some 1.3 macros were finally contributed back to
11361 Autoconf), 197 test cases, and 51 pages of documentation.
11363 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
11365 This implements a new dependency tracking schemed that should be
11366 able to handle automatic dependency tracking using any compiler (not
11367 just gcc) and any make (not just GNU @command{make}).  In addition,
11368 the new scheme should be more reliable than the old one, as
11369 dependencies are generated on the end user's machine.  Alexandre Oliva
11370 creates depcomp for this purpose.
11372 @xref{Dependency Tracking Evolution}, for more details about the
11373 evolution of automatic dependency tracking in Automake.
11375 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
11377 This was a huge problem since we also had patches going in on the
11378 trunk.  The merge took a long time and was very painful.
11380 @item 2000-05-10
11382 Since September 1999 and until 2003, Akim Demaille will be zealously
11383 revamping Autoconf.
11385 @quotation
11386 I think the next release should be called "3.0".@*
11387 Let's face it: you've basically rewritten autoconf.@*
11388 Every weekend there are 30 new patches.@*
11389 I don't see how we could call this "2.15" with a straight face.@*
11390 -- Tom Tromey on @email{autoconf@@gnu.org}
11391 @end quotation
11393 Actually Akim works like a submarine: he will pile up patches while he
11394 works off-line during the weekend, and flush them in batch when he
11395 resurfaces on Monday.
11397 @item 2001-01-24
11399 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
11400 is out, and Akim has to find something to do during his week-end :)
11402 @item 2001-01-28
11404 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
11406 @quotation
11407 Aiieeee!  I was dreading the day that the Demaillator turned his
11408 sights on automake@dots{} and now it has arrived! -- Tom Tromey
11409 @end quotation
11411 It's only the beginning: in two months he will send 192 patches.  Then
11412 he would slow down so Tom can catch up and review all this.  Initially
11413 Tom actually read all these patches, then he probably trustingly
11414 answered OK to most of them, and finally gave up and let Akim apply
11415 whatever he wanted.  There was no way to keep up with that patch rate.
11417 @quotation
11418 Anyway the patch below won't apply since it predates Akim's
11419 sourcequake; I have yet to figure where the relevant passage has
11420 been moved :) -- Alexandre Duret-Lutz
11421 @end quotation
11423 All these patches were sent to and discussed on
11424 @email{automake@@gnu.org}, so subscribed users were literally drown in
11425 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
11426 mailing list was created in May.
11428 Year after year, Automake had drifted away from its initial design:
11429 construct @file{Makefile.in} by assembling various @file{Makefile}
11430 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
11431 various places in the @command{automake} script itself; this does not
11432 help ensuring a consistent treatment of these rules (for instance
11433 making sure that user-defined rules override Automake's own rules).
11434 One of Akim's goal was moving all these hard-coded rules to separate
11435 @file{Makefile} fragments, so the logic could be centralized in a
11436 @file{Makefile} fragment processor.
11438 Another significant contribution of Akim is the interface with the
11439 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
11440 this time was to read the file and grep the various macro of interest
11441 to Automake.  Doing so could break in many unexpected ways; automake
11442 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
11443 where the arguments are known only when M4 is run), or conversely it
11444 could detect some macro that was not expanded (because it is called
11445 conditionally).  In the CVS version of Autoconf, Akim had implemented
11446 the @option{--trace} option, which provides accurate information about
11447 where macros are actually called and with what arguments.  Akim will
11448 equip Automake with a second @file{configure.in} scanner that uses
11449 this @option{--trace} interface.  Since it was not sensible to drop the
11450 Autoconf 2.13 compatibility yet, this experimental scanner was only
11451 used when an environment variable was set, the traditional
11452 grep-scanner being still the default.
11454 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
11456 It has been more than two years since Automake 1.4, CVS Automake has
11457 suffered lot's of heavy changes and still is not ready for release.
11458 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
11460 @item 2001-05-08 Automake 1.4-p1
11461 @itemx 2001-05-24 Automake 1.4-p2
11463 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
11464 release'' of Automake:
11466 @quotation
11467 The main purpose of this release is to have a stable automake
11468 which is compatible with the latest stable libtool.
11469 @end quotation
11471 The release also contains obvious fixes for bugs in Automake 1.4,
11472 some of which were reported almost monthly.
11474 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
11476 @item 2001-06-07 Automake 1.4-p3
11477 @itemx 2001-06-10 Automake 1.4-p4
11478 @itemx 2001-07-15 Automake 1.4-p5
11480 Gary continues his patch-release series.  These also add support for
11481 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
11482 @file{configure.ac} over @file{configure.in}, and it introduces a new
11483 syntax for @code{AC_OUTPUT}ing files.
11485 @item 2001-08-23 Automake 1.5
11487 A major and long-awaited release, that comes more than two years after
11488 1.4.  It brings many changes, among which:
11489 @itemize
11490 @item The new dependency tracking scheme that uses @command{depcomp}.
11491 Aside from the improvement on the dependency tracking itself
11492 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
11493 of automake generated @file{Makefile.in}s as the @file{Makefile.in}s
11494 used during development are now the same as those used in
11495 distributions.  Before that the @file{Makefile.in}s generated for
11496 maintainers required GNU @command{make} and GCC, they were different
11497 from the portable @file{Makefile} generated for distribution; this was
11498 causing some confusion.
11500 @item Support for per-target compilation flags.
11502 @item Support for reference to files in subdirectories in most
11503 @file{Makefile.am} variables.
11505 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
11506 prefixes.
11507 @item Perl 4 support is finally dropped.
11508 @end itemize
11510 1.5 did broke several packages that worked with 1.4.  Enough so that
11511 Linux distributions could not easily install the new Automake version
11512 without breaking many of the packages for which they had to run
11513 @command{automake}.
11515 Some of these breakages were effectively bugs that would eventually be
11516 fixed in the next release.  However, a lot of damage was caused by
11517 some changes made deliberately to render Automake stricter on some
11518 setup we did consider bogus.  For instance, @samp{make distcheck} was
11519 improved to check that @samp{make uninstall} did remove all the files
11520 @samp{make install} installed, that @samp{make distclean} did not omit
11521 some file, and that a VPATH build would work even if the source
11522 directory was read-only.  Similarly, Automake now rejects multiple
11523 definitions of the same variable (because that would mix very badly
11524 with conditionals), and @samp{+=} assignments with no previous
11525 definition.  Because these changes all occurred suddenly after 1.4 had
11526 been established for more than two years, it hurt users.
11528 To make matter worse, meanwhile Autoconf (now at version 2.52) was
11529 facing similar troubles, for similar reasons.
11531 @item 2002-03-05 Automake 1.6
11533 This release introduced versioned installation (@pxref{API
11534 versioning}).  This was mainly pushed by Havoc Pennington, taking the
11535 GNOME source tree as motive: due to incompatibilities between the
11536 autotools it's impossible for the GNOME packages to switch to Autoconf
11537 2.53 and Automake 1.5 all at once, so they are currently stuck with
11538 Autoconf 2.13 and Automake 1.4.
11540 The idea was to call this version @file{automake-1.6}, call all its
11541 bug-fix versions identically, and switch to @file{automake-1.7} for
11542 the next release that adds new features or changes some rules.  This
11543 scheme implies maintaining a bug-fix branch in addition to the
11544 development trunk, which means more work from the maintainer, but
11545 providing regular bug-fix releases proved to be really worthwhile.
11547 Like 1.5, 1.6 also introduced a bunch of incompatibilities, meant or
11548 not.  Perhaps the more annoying was the dependence on the newly
11549 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
11550 since its explosive 2.50 release, and included changes required to fix
11551 some bugs in Automake.  In order to upgrade to Automake 1.6, people
11552 now had to upgrade Autoconf too; for some packages it was no picnic.
11554 While versioned installation helped people to upgrade, it also
11555 unfortunately allowed people not to upgrade.  At the time of writing,
11556 some Linux distributions are shipping packages for Automake 1.4, 1.5,
11557 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
11558 Some distribution also call 1.4 the ``stable'' version, and present
11559 ``1.9'' as the development version; this does not really makes sense
11560 since 1.9 is way more solid than 1.4.  All this does not help the
11561 newcomer.
11563 @item 2002-04-11 Automake 1.6.1
11565 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
11566 This one and those following will be handled by Alexandre
11567 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
11568 but his interest into Automake is drifting away towards projects like
11569 @command{gcj}.
11571 Alexandre has been using Automake since 2000, and started to
11572 contribute mostly on Akim's incitement (Akim and Alexandre have been
11573 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
11574 a lot of free time to enjoy hacking Automake.
11576 @item 2002-06-14 Automake 1.6.2
11578 @item 2002-07-28 Automake 1.6.3
11579 @itemx 2002-07-28 Automake 1.4-p6
11581 Two releases on the same day.  1.6.3 is a bug-fix release.
11583 Tom Tromey backported the versioned installation mechanism on the 1.4
11584 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
11585 side by side.  Another request from the GNOME folks.
11587 @item 2002-09-25 Automake 1.7
11589 This release switches to the new @file{configure.ac} scanner Akim
11590 was experimenting in 1.5.
11592 @item 2002-10-16 Automake 1.7.1
11593 @itemx 2002-12-06 Automake 1.7.2
11594 @itemx 2003-02-20 Automake 1.7.3
11595 @itemx 2003-04-23 Automake 1.7.4
11596 @itemx 2003-05-18 Automake 1.7.5
11597 @itemx 2003-07-10 Automake 1.7.6
11598 @itemx 2003-09-07 Automake 1.7.7
11599 @itemx 2003-10-07 Automake 1.7.8
11601 Many bug-fix releases.  1.7 lasted because the development version
11602 (upcoming 1.8) was suffering some major internal revamping.
11604 @item 2003-10-26 Automake on screen
11606 Episode 49, `Repercussions', in the third season of the `Alias' TV
11607 show is first aired.
11609 Marshall, one of the character, is working on a computer virus that he
11610 has to modify before it gets into the wrong hands or something like
11611 that.  The screenshots you see do not show any program code, they show
11612 a @file{Makefile.in} @code{generated by automake}...
11614 @item 2003-11-09 Automake 1.7.9
11616 @item 2003-12-10 Automake 1.8
11618 The most striking update is probably that of @command{aclocal}.
11620 @command{aclocal} now uses @code{m4_include} in the produced
11621 @file{aclocal.m4} when the included macros are already distributed
11622 with the package (an idiom used in many packages), which reduces code
11623 duplication.  Many people liked that, but in fact this change was
11624 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
11625 must be rebuilt whenever a dependency of @file{configure} changes, but
11626 all the @file{m4} files included in @file{aclocal.m4} where unknown
11627 from @command{automake}.  Now @command{automake} can just trace the
11628 @code{m4_include}s to discover the dependencies.
11630 @command{aclocal} also starts using the @option{--trace} Autoconf option
11631 in order to discover used macros more accurately.  This will turn out
11632 to be very tricky (later releases will improve this) as people had
11633 devised many ways to cope with the limitation of previous
11634 @command{aclocal} versions, notably using handwritten
11635 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
11636 rule that is already included by such statement.
11638 Automake also has seen its guts rewritten.  Although this rewriting
11639 took a lot of efforts, it is only apparent to the users in that some
11640 constructions previously disallowed by the implementation now work
11641 nicely.  Conditionals, Locations, Variable and Rule definitions,
11642 Options: these items on which Automake works have been rewritten as
11643 separate Perl modules, and documented.
11645 @itemx 2004-01-11 Automake 1.8.1
11646 @itemx 2004-01-12 Automake 1.8.2
11647 @itemx 2004-03-07 Automake 1.8.3
11648 @itemx 2004-04-25 Automake 1.8.4
11649 @itemx 2004-05-16 Automake 1.8.5
11651 @item 2004-07-28 Automake 1.9
11653 This release tries to simplify the compilation rules it outputs to
11654 reduce the size of the Makefile.  The complaint initially come from
11655 the libgcj developers.  Their @file{Makefile.in} generated with
11656 Automake 1.4 and custom build rules (1.4 did not support compiled
11657 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
11658 down to 1.2MB@.
11660 Aside from this it contains mainly minor changes and bug-fixes.
11662 @itemx 2004-08-11 Automake 1.9.1
11663 @itemx 2004-09-19 Automake 1.9.2
11665 Automake has ten years.  This chapter of the manual was initially
11666 written for this occasion.
11668 @itemx 2007-10-29 Automake repository moves to @code{savannah.gnu.org} and uses
11669 git as primary repository.
11671 @end table
11673 @node Dependency Tracking Evolution
11674 @section Dependency Tracking in Automake
11676 Over the years Automake has deployed three different dependency
11677 tracking methods.  Each method, including the current one, has had
11678 flaws of various sorts.  Here we lay out the different dependency
11679 tracking methods, their flaws, and their fixes.  We conclude with
11680 recommendations for tool writers, and by indicating future directions
11681 for dependency tracking work in Automake.
11683 @subsection First Take
11684 @unnumberedsubsubsec Description
11686 Our first attempt at automatic dependency tracking was based on the
11687 method recommended by GNU @command{make}.  (@pxref{Automatic
11688 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
11689 make Manual})
11691 This version worked by precomputing dependencies ahead of time.  For
11692 each source file, it had a special @file{.P} file that held the
11693 dependencies.  There was a rule to generate a @file{.P} file by
11694 invoking the compiler appropriately.  All such @file{.P} files were
11695 included by the @file{Makefile}, thus implicitly becoming dependencies
11696 of @file{Makefile}.
11698 @unnumberedsubsubsec Bugs
11700 This approach had several critical bugs.
11702 @itemize
11703 @item
11704 The code to generate the @file{.P} file relied on @command{gcc}.
11705 (A limitation, not technically a bug.)
11706 @item
11707 The dependency tracking mechanism itself relied on GNU @command{make}.
11708 (A limitation, not technically a bug.)
11709 @item
11710 Because each @file{.P} file was a dependency of @file{Makefile}, this
11711 meant that dependency tracking was done eagerly by @command{make}.
11712 For instance, @samp{make clean} would cause all the dependency files
11713 to be updated, and then immediately removed.  This eagerness also
11714 caused problems with some configurations; if a certain source file
11715 could not be compiled on a given architecture for some reason,
11716 dependency tracking would fail, aborting the entire build.
11717 @item
11718 As dependency tracking was done as a pre-pass, compile times were
11719 doubled--the compiler had to be run twice per source file.
11720 @item
11721 @samp{make dist} re-ran @command{automake} to generate a
11722 @file{Makefile} that did not have automatic dependency tracking (and
11723 that was thus portable to any version of @command{make}).  In order to
11724 do this portably, Automake had to scan the dependency files and remove
11725 any reference that was to a source file not in the distribution.
11726 This process was error-prone.  Also, if @samp{make dist} was run in an
11727 environment where some object file had a dependency on a source file
11728 that was only conditionally created, Automake would generate a
11729 @file{Makefile} that referred to a file that might not appear in the
11730 end user's build.  A special, hacky mechanism was required to work
11731 around this.
11732 @end itemize
11734 @unnumberedsubsubsec Historical Note
11736 The code generated by Automake is often inspired by the
11737 @file{Makefile} style of a particular author.  In the case of the first
11738 implementation of dependency tracking, I believe the impetus and
11739 inspiration was Jim Meyering.  (I could be mistaken.  If you know
11740 otherwise feel free to correct me.)
11742 @subsection Dependencies As Side Effects
11743 @unnumberedsubsubsec Description
11745 The next refinement of Automake's automatic dependency tracking scheme
11746 was to implement dependencies as side effects of the compilation.
11747 This was aimed at solving the most commonly reported problems with the
11748 first approach.  In particular we were most concerned with eliminating
11749 the weird rebuilding effect associated with make clean.
11751 In this approach, the @file{.P} files were included using the
11752 @code{-include} command, which let us create these files lazily.  This
11753 avoided the @samp{make clean} problem.
11755 We only computed dependencies when a file was actually compiled.  This
11756 avoided the performance penalty associated with scanning each file
11757 twice.  It also let us avoid the other problems associated with the
11758 first, eager, implementation.  For instance, dependencies would never
11759 be generated for a source file that was not compilable on a given
11760 architecture (because it in fact would never be compiled).
11762 @unnumberedsubsubsec Bugs
11764 @itemize
11765 @item
11766 This approach also relied on the existence of @command{gcc} and GNU
11767 @command{make}.  (A limitation, not technically a bug.)
11768 @item
11769 Dependency tracking was still done by the developer, so the problems
11770 from the first implementation relating to massaging of dependencies by
11771 @samp{make dist} were still in effect.
11772 @item
11773 This implementation suffered from the ``deleted header file'' problem.
11774 Suppose a lazily-created @file{.P} file includes a dependency on a
11775 given header file, like this:
11777 @example
11778 maude.o: maude.c something.h
11779 @end example
11781 Now suppose that the developer removes @file{something.h} and updates
11782 @file{maude.c} so that this include is no longer needed.  If he runs
11783 @command{make}, he will get an error because there is no way to create
11784 @file{something.h}.
11786 We fixed this problem in a later release by further massaging the
11787 output of @command{gcc} to include a dummy dependency for each header
11788 file.
11789 @end itemize
11791 @subsection Dependencies for the User
11792 @unnumberedsubsubsec Description
11794 The bugs associated with @samp{make dist}, over time, became a real
11795 problem.  Packages using Automake were being built on a large number
11796 of platforms, and were becoming increasingly complex.  Broken
11797 dependencies were distributed in ``portable'' @file{Makefile.in}s,
11798 leading to user complaints.  Also, the requirement for @command{gcc}
11799 and GNU @command{make} was a constant source of bug reports.  The next
11800 implementation of dependency tracking aimed to remove these problems.
11802 We realized that the only truly reliable way to automatically track
11803 dependencies was to do it when the package itself was built.  This
11804 meant discovering a method portable to any version of make and any
11805 compiler.  Also, we wanted to preserve what we saw as the best point
11806 of the second implementation: dependency computation as a side effect
11807 of compilation.
11809 In the end we found that most modern make implementations support some
11810 form of include directive.  Also, we wrote a wrapper script that let
11811 us abstract away differences between dependency tracking methods for
11812 compilers.  For instance, some compilers cannot generate dependencies
11813 as a side effect of compilation.  In this case we simply have the
11814 script run the compiler twice.  Currently our wrapper script
11815 (@command{depcomp}) knows about twelve different compilers (including
11816 a "compiler" that simply invokes @command{makedepend} and then the
11817 real compiler, which is assumed to be a standard Unix-like C compiler
11818 with no way to do dependency tracking).
11820 @unnumberedsubsubsec Bugs
11822 @itemize
11823 @item
11824 Running a wrapper script for each compilation slows down the build.
11825 @item
11826 Many users don't really care about precise dependencies.
11827 @item
11828 This implementation, like every other automatic dependency tracking
11829 scheme in common use today (indeed, every one we've ever heard of),
11830 suffers from the ``duplicated new header'' bug.
11832 This bug occurs because dependency tracking tools, such as the
11833 compiler, only generate dependencies on the successful opening of a
11834 file, and not on every probe.
11836 Suppose for instance that the compiler searches three directories for
11837 a given header, and that the header is found in the third directory.
11838 If the programmer erroneously adds a header file with the same name to
11839 the first directory, then a clean rebuild from scratch could fail
11840 (suppose the new header file is buggy), whereas an incremental rebuild
11841 will succeed.
11843 What has happened here is that people have a misunderstanding of what
11844 a dependency is.  Tool writers think a dependency encodes information
11845 about which files were read by the compiler.  However, a dependency
11846 must actually encode information about what the compiler tried to do.
11848 This problem is not serious in practice.  Programmers typically do not
11849 use the same name for a header file twice in a given project.  (At
11850 least, not in C or C++.  This problem may be more troublesome in
11851 Java.)  This problem is easy to fix, by modifying dependency
11852 generators to record every probe, instead of every successful open.
11854 @item
11855 Since automake generates dependencies as a side effect of compilation,
11856 there is a bootstrapping problem when header files are generated by
11857 running a program.  The problem is that, the first time the build is
11858 done, there is no way by default to know that the headers are
11859 required, so make might try to run a compilation for which the headers
11860 have not yet been built.
11862 This was also a problem in the previous dependency tracking implementation.
11864 The current fix is to use @code{BUILT_SOURCES} to list built headers
11865 (@pxref{Sources}).  This causes them to be built before any other
11866 build rules are run.  This is unsatisfactory as a general solution,
11867 however in practice it seems sufficient for most actual programs.
11868 @end itemize
11870 This code is used since Automake 1.5.
11872 In GCC 3.0, we managed to convince the maintainers to add special
11873 command-line options to help Automake more efficiently do its job.  We
11874 hoped this would let us avoid the use of a wrapper script when
11875 Automake's automatic dependency tracking was used with @command{gcc}.
11877 Unfortunately, this code doesn't quite do what we want.  In
11878 particular, it removes the dependency file if the compilation fails;
11879 we'd prefer that it instead only touch the file in any way if the
11880 compilation succeeds.
11882 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
11883 detected at @command{configure} time, we inline the
11884 dependency-generation code and do not use the @command{depcomp}
11885 wrapper script.  This makes compilations faster for those using this
11886 compiler (probably our primary user base).  The counterpart is that
11887 because we have to encode two compilation rules in @file{Makefile}
11888 (with or without @command{depcomp}), the produced @file{Makefile}s are
11889 larger.
11891 @subsection Techniques for Computing Dependencies
11893 There are actually several ways for a build tool like Automake to
11894 cause tools to generate dependencies.
11896 @table @asis
11897 @item @command{makedepend}
11898 This was a commonly-used method in the past.  The idea is to run a
11899 special program over the source and have it generate dependency
11900 information.  Traditional implementations of @command{makedepend} are
11901 not completely precise; ordinarily they were conservative and
11902 discovered too many dependencies.
11903 @item The tool
11904 An obvious way to generate dependencies is to simply write the tool so
11905 that it can generate the information needed by the build tool.  This is
11906 also the most portable method.  Many compilers have an option to
11907 generate dependencies.  Unfortunately, not all tools provide such an
11908 option.
11909 @item The file system
11910 It is possible to write a special file system that tracks opens,
11911 reads, writes, etc, and then feed this information back to the build
11912 tool.  @command{clearmake} does this.  This is a very powerful
11913 technique, as it doesn't require cooperation from the
11914 tool.  Unfortunately it is also very difficult to implement and also
11915 not practical in the general case.
11916 @item @code{LD_PRELOAD}
11917 Rather than use the file system, one could write a special library to
11918 intercept @code{open} and other syscalls.  This technique is also quite
11919 powerful, but unfortunately it is not portable enough for use in
11920 @command{automake}.
11921 @end table
11923 @subsection Recommendations for Tool Writers
11925 We think that every compilation tool ought to be able to generate
11926 dependencies as a side effect of compilation.  Furthermore, at least
11927 while @command{make}-based tools are nearly universally in use (at
11928 least in the free software community), the tool itself should generate
11929 dummy dependencies for header files, to avoid the deleted header file
11930 bug.  Finally, the tool should generate a dependency for each probe,
11931 instead of each successful file open, in order to avoid the duplicated
11932 new header bug.
11934 @subsection Future Directions for Automake's Dependency Tracking
11936 Currently, only languages and compilers understood by Automake can
11937 have dependency tracking enabled.  We would like to see if it is
11938 practical (and worthwhile) to let this support be extended by the user
11939 to languages unknown to Automake.
11941 @node Releases
11942 @section Release Statistics
11944 The following table (inspired by @samp{perlhist(1)}) quantifies the
11945 evolution of Automake using these metrics:
11947 @table @asis
11948 @item Date, Rel
11949 The date and version of the release.
11950 @item am
11951 The number of lines of the @command{automake} script.
11952 @item acl
11953 The number of lines of the @command{aclocal} script.
11954 @item pm
11955 The number of lines of the @command{Perl} supporting modules.
11956 @item @file{*.am}
11957 The number of lines of the @file{Makefile} fragments.  The number in parenthesis
11958 is the number of files.
11959 @item m4
11960 The number of lines (and files) of Autoconf macros.
11961 @item doc
11962 The number of pages of the documentation (the Postscript version).
11963 @item t
11964 The number of test cases in the test suite.
11965 @end table
11967 @multitable {8888-88-88} {8.8-p8} {8888} {8888} {8888} {8888 (88)} {8888 (88)} {888} {888}
11968 @headitem Date   @tab Rel @tab am @tab acl @tab pm @tab @file{*.am} @tab m4 @tab doc @tab t
11969 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
11970 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
11971 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
11972 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
11973 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
11974 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
11975 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
11976 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
11977 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
11978 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
11979 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
11980 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
11981 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
11982 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
11983 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
11984 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
11985 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
11986 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (20) @tab  37 @tab 126
11987 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (23) @tab  39 @tab 156
11988 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
11989 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
11990 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
11991 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
11992 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 198
11993 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (20) @tab  51 @tab 198
11994 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (29) @tab  63 @tab 327
11995 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (27) @tab  66 @tab 365
11996 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (27) @tab  66 @tab 372
11997 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (27) @tab  67 @tab 386
11998 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (27) @tab  67 @tab 391
11999 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (20) @tab  49 @tab 197
12000 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (28) @tab  73 @tab 430
12001 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (28) @tab  73 @tab 437
12002 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (28) @tab  77 @tab 445
12003 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (29) @tab  84 @tab 448
12004 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (29) @tab  85 @tab 458
12005 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (29) @tab  85 @tab 459
12006 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (29) @tab  85 @tab 461
12007 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 467
12008 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 468
12009 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (29) @tab  90 @tab 468
12010 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (31) @tab 104 @tab 521
12011 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (31) @tab 104 @tab 525
12012 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (31) @tab 104 @tab 526
12013 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (31) @tab 111 @tab 530
12014 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (31) @tab 112 @tab 531
12015 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (31) @tab 112 @tab 533
12016 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (32) @tab 115 @tab 551
12017 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 115 @tab 552
12018 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 132 @tab 554
12019 @item 2004-11-01 @tab 1.9.3  @tab 7507 @tab 718 @tab 7804 @tab 3354 (40) @tab 1812 (32) @tab 134 @tab 556
12020 @item 2004-12-18 @tab 1.9.4  @tab 7508 @tab 718 @tab 7856 @tab 3361 (40) @tab 1811 (32) @tab 140 @tab 560
12021 @item 2005-02-13 @tab 1.9.5  @tab 7523 @tab 719 @tab 7859 @tab 3373 (40) @tab 1453 (32) @tab 142 @tab 562
12022 @item 2005-07-10 @tab 1.9.6  @tab 7539 @tab 699 @tab 7867 @tab 3400 (40) @tab 1453 (32) @tab 144 @tab 570
12023 @item 2006-10-15 @tab 1.10   @tab 7859 @tab 1072 @tab 8024 @tab 3512 (40) @tab 1496 (34) @tab 172 @tab 604
12024 @end multitable
12027 @c ========================================================== Appendices
12029 @page
12030 @node Copying This Manual
12031 @appendix Copying This Manual
12033 @menu
12034 * GNU Free Documentation License::  License for copying this manual
12035 @end menu
12037 @include fdl.texi
12039 @page
12040 @node Indices
12041 @appendix Indices
12043 @menu
12044 * Macro Index::                 Index of Autoconf macros
12045 * Variable Index::              Index of Makefile variables
12046 * General Index::               General index
12047 @end menu
12049 @node Macro Index
12050 @appendixsec Macro Index
12052 @printindex fn
12054 @node Variable Index
12055 @appendixsec Variable Index
12057 @printindex vr
12059 @node General Index
12060 @appendixsec General Index
12062 @printindex cp
12065 @page
12066 @contents
12067 @bye
12069 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
12070 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
12071 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
12072 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
12073 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
12074 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
12075 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
12076 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
12077 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
12078 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
12079 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
12080 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
12081 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
12082 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
12083 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
12084 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
12085 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
12086 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
12087 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
12088 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
12089 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
12090 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
12091 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
12092 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
12093 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
12094 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
12095 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
12096 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
12097 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
12098 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
12099 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
12100 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
12101 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
12102 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
12103 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
12104 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
12105 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
12106 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
12107 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
12108 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
12109 @c  LocalWords:  unnumberedsubsec depfile tmpdepfile depmode const interoperate
12110 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
12111 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
12112 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
12113 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
12114 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
12115 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
12116 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
12117 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
12118 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
12119 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
12120 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
12121 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
12122 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
12123 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
12124 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
12125 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
12126 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
12127 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
12128 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
12129 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
12130 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
12131 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
12132 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
12133 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
12134 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
12135 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
12136 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
12137 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
12138 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
12139 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
12140 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
12141 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
12142 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
12143 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
12144 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
12145 @c  LocalWords:  barexec Pinard's automatize initialize lzma