tests/README: warn about zsh incompatibilities.
[automake.git] / doc / automake.texi
blobb3f4a7602e5ebe5f006810cc7a2c6192c4140b4f
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @setchapternewpage off
6 @c %**end of header
8 @include version.texi
10 @c @ovar(ARG, DEFAULT)
11 @c -------------------
12 @c The ARG is an optional argument.  To be used for macro arguments in
13 @c their documentation (@defmac).
14 @macro ovar{varname}
15 @r{[}@var{\varname\}@r{]}
16 @end macro
18 @copying
20 This manual is for @acronym{GNU} Automake (version @value{VERSION},
21 @value{UPDATED}), a program that creates GNU standards-compliant
22 Makefiles from template files.
24 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
25 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
27 @quotation
28 Permission is granted to copy, distribute and/or modify this document
29 under the terms of the @acronym{GNU} Free Documentation License,
30 Version 1.3 or any later version published by the Free Software
31 Foundation; with no Invariant Sections, with no Front-Cover texts,
32 and with no Back-Cover Texts.  A copy of the license is included in the
33 section entitled ``@acronym{GNU} Free Documentation License.''
35 @end quotation
36 @end copying
38 @c info Automake  points to the Automake package's documentation
39 @c info automake  points to the automake script's documentation
40 @c (Autoconf has a similar setup.)
41 @dircategory Software development
42 @direntry
43 * Automake: (automake).         Making GNU standards-compliant Makefiles.
44 @end direntry
46 @dircategory Individual utilities
47 @direntry
48 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4.
49 * automake: (automake)Invoking Automake.        Generating Makefile.in.
50 @end direntry
52 @titlepage
53 @title GNU Automake
54 @subtitle For version @value{VERSION}, @value{UPDATED}
55 @author David MacKenzie
56 @author Tom Tromey
57 @author Alexandre Duret-Lutz
58 @page
59 @vskip 0pt plus 1filll
60 @insertcopying
61 @end titlepage
64 @c We use the following macros to define indices:
65 @c   @cindex   concepts, and anything that does not fit elsewhere
66 @c   @vindex   Makefile variables
67 @c   @trindex  targets
68 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
69 @c   @opindex  tool options
71 @c Define an index of configure macros.
72 @defcodeindex ac
73 @c Define an index of options.
74 @defcodeindex op
75 @c Define an index of targets.
76 @defcodeindex tr
77 @c Define an index of commands.
78 @defcodeindex cm
80 @c Put the macros in the function index.
81 @syncodeindex ac fn
83 @c Put everything else into one index (arbitrarily chosen to be the concept index).
84 @syncodeindex op cp
85 @syncodeindex tr cp
86 @syncodeindex cm cp
88 @ifnottex
89 @node Top
90 @comment  node-name,  next,  previous,  up
91 @top GNU Automake
93 @insertcopying
95 @menu
96 * Introduction::                Automake's purpose
97 * Autotools Introduction::      An Introduction to the Autotools
98 * Generalities::                General ideas
99 * Examples::                    Some example packages
100 * Invoking Automake::           Creating a Makefile.in
101 * configure::                   Scanning configure.ac or configure.in
102 * Directories::                 Declaring subdirectories
103 * Programs::                    Building programs and libraries
104 * Other Objects::               Other derived objects
105 * Other GNU Tools::             Other GNU Tools
106 * Documentation::               Building documentation
107 * Install::                     What gets installed
108 * Clean::                       What gets cleaned
109 * Dist::                        What goes in a distribution
110 * Tests::                       Support for test suites
111 * Rebuilding::                  Automatic rebuilding of Makefile
112 * Options::                     Changing Automake's behavior
113 * Miscellaneous::               Miscellaneous rules
114 * Include::                     Including extra files in an Automake template
115 * Conditionals::                Conditionals
116 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
117 * Cygnus::                      The effect of @option{--cygnus}
118 * Not Enough::                  When Automake is not Enough
119 * Distributing::                Distributing the Makefile.in
120 * API Versioning::              About compatibility between Automake versions
121 * Upgrading::                   Upgrading to a Newer Automake Version
122 * FAQ::                         Frequently Asked Questions
123 * History::                     Notes about the history of Automake
124 * Copying This Manual::         How to make copies of this manual
125 * Indices::                     Indices of variables, macros, and concepts
127 @detailmenu
128  --- The Detailed Node Listing ---
130 An Introduction to the Autotools
132 * GNU Build System::            Introducing the GNU Build System
133 * Use Cases::                   Use Cases for the GNU Build System
134 * Why Autotools::               How Autotools Help
135 * Hello World::                 A Small Hello World Package
137 Use Cases for the GNU Build System
139 * Basic Installation::          Common installation procedure
140 * Standard Targets::            A list of standard Makefile targets
141 * Standard Directory Variables::  A list of standard directory variables
142 * Standard Configuration Variables::  Using configuration variables
143 * config.site::                 Using a config.site file
144 * VPATH Builds::                Parallel build trees
145 * Two-Part Install::            Installing data and programs separately
146 * Cross-Compilation::           Building for other architectures
147 * Renaming::                    Renaming programs at install time
148 * DESTDIR::                     Building binary packages with DESTDIR
149 * Preparing Distributions::     Rolling out tarballs
150 * Dependency Tracking::         Automatic dependency tracking
151 * Nested Packages::             The GNU Build Systems can be nested
153 A Small Hello World
155 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
156 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
158 General ideas
160 * General Operation::           General operation of Automake
161 * Strictness::                  Standards conformance checking
162 * Uniform::                     The Uniform Naming Scheme
163 * Canonicalization::            How derived variables are named
164 * Length Limitations::          Staying below the command line length limit
165 * User Variables::              Variables reserved for the user
166 * Auxiliary Programs::          Programs automake might require
168 Some example packages
170 * Complete::                    A simple example, start to finish
171 * true::                        Building true and false
173 Scanning @file{configure.ac}
175 * Requirements::                Configuration requirements
176 * Optional::                    Other things Automake recognizes
177 * Invoking aclocal::            Auto-generating aclocal.m4
178 * Macros::                      Autoconf macros supplied with Automake
180 Auto-generating aclocal.m4
182 * aclocal Options::             Options supported by aclocal
183 * Macro Search Path::           How aclocal finds .m4 files
184 * Extending aclocal::           Writing your own aclocal macros
185 * Local Macros::                Organizing local macros
186 * Serials::                     Serial lines in Autoconf macros
187 * Future of aclocal::           aclocal's scheduled death
189 Autoconf macros supplied with Automake
191 * Public Macros::               Macros that you can use.
192 * Obsolete Macros::             Macros that you should stop using.
193 * Private Macros::              Macros that you should not use.
195 Directories
197 * Subdirectories::              Building subdirectories recursively
198 * Conditional Subdirectories::  Conditionally not building directories
199 * Alternative::                 Subdirectories without recursion
200 * Subpackages::                 Nesting packages
202 Conditional Subdirectories
204 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
205 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
206 * Subdirectories with AC_SUBST::  Another way for conditional recursion
207 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
209 Building Programs and Libraries
211 * A Program::                   Building a program
212 * A Library::                   Building a library
213 * A Shared Library::            Building a Libtool library
214 * Program and Library Variables::  Variables controlling program and
215                                 library builds
216 * Default _SOURCES::            Default source files
217 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
218 * Program Variables::           Variables used when building a program
219 * Yacc and Lex::                Yacc and Lex support
220 * C++ Support::                 Compiling C++ sources
221 * Objective C Support::         Compiling Objective C sources
222 * Unified Parallel C Support::  Compiling Unified Parallel C sources
223 * Assembly Support::            Compiling assembly sources
224 * Fortran 77 Support::          Compiling Fortran 77 sources
225 * Fortran 9x Support::          Compiling Fortran 9x sources
226 * Java Support::                Compiling Java sources
227 * Vala Support::                Compiling Vala sources
228 * Support for Other Languages::  Compiling other languages
229 * ANSI::                        Automatic de-ANSI-fication (obsolete)
230 * Dependencies::                Automatic dependency tracking
231 * EXEEXT::                      Support for executable extensions
233 Building a program
235 * Program Sources::             Defining program sources
236 * Linking::                     Linking with libraries or extra objects
237 * Conditional Sources::         Handling conditional sources
238 * Conditional Programs::        Building program conditionally
240 Building a Shared Library
242 * Libtool Concept::             Introducing Libtool
243 * Libtool Libraries::           Declaring Libtool Libraries
244 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
245 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
246 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
247 * Libtool Modules::             Building Libtool Modules
248 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
249 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
250 * Libtool Issues::              Common Issues Related to Libtool's Use
252 Fortran 77 Support
254 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
255 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
256 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
258 Mixing Fortran 77 With C and C++
260 * How the Linker is Chosen::    Automatic linker selection
262 Fortran 9x Support
264 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
266 Other Derived Objects
268 * Scripts::                     Executable scripts
269 * Headers::                     Header files
270 * Data::                        Architecture-independent data files
271 * Sources::                     Derived sources
273 Built Sources
275 * Built Sources Example::       Several ways to handle built sources.
277 Other GNU Tools
279 * Emacs Lisp::                  Emacs Lisp
280 * gettext::                     Gettext
281 * Libtool::                     Libtool
282 * Java::                        Java
283 * Python::                      Python
285 Building documentation
287 * Texinfo::                     Texinfo
288 * Man Pages::                   Man pages
290 Installation
292 * Basics of Installation::      What gets installed where
293 * The Two Parts of Install::    Installing data and programs separately
294 * Extending Installation::      Adding your own rules for installation
295 * Staged Installs::             Installation in a temporary location
296 * Install Rules for the User::  Useful additional rules
298 Distribution
300 * Basics of Distribution::      Files distributed by default
301 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
302 * The dist Hook::               A target for last-minute distribution changes
303 * Checking the Distribution::   @samp{make distcheck} explained
304 * The Types of Distributions::  A variety of formats and compression methods
306 Support for Test Suites
308 * Simple Tests::                Listing programs and scripts in @code{TESTS}
309 * Simple Tests using parallel-tests::  More powerful test driver
310 * DejaGnu Tests::               Interfacing with the external testing framework
311 * Install Tests::               Running tests on installed packages
313 Miscellaneous Rules
315 * Tags::                        Interfacing to etags and mkid
316 * Suffixes::                    Handling new file extensions
317 * Multilibs::                   Support for multilibs.
319 Conditionals
321 * Usage of Conditionals::       Declaring conditional content
322 * Limits of Conditionals::      Enclosing complete statements
324 When Automake Isn't Enough
326 * Extending::                   Adding new rules or overriding existing ones.
327 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
329 Frequently Asked Questions about Automake
331 * CVS::                         CVS and generated files
332 * maintainer-mode::             missing and AM_MAINTAINER_MODE
333 * Wildcards::                   Why doesn't Automake support wildcards?
334 * Limitations on File Names::   Limitations on source and installed file names
335 * distcleancheck::              Files left in build directory after distclean
336 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
337 * Renamed Objects::             Why are object files sometimes renamed?
338 * Per-Object Flags::            How to simulate per-object flags?
339 * Multiple Outputs::            Writing rules for tools with many output files
340 * Hard-Coded Install Paths::    Installing to hard-coded locations
341 * Debugging Make Rules::        Strategies when things don't work as expected
343 History of Automake
345 * Timeline::                    The Automake story.
346 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
347 * Releases::                    Statistics about Automake Releases
349 Dependency Tracking Evolution
351 * First Take on Dependencies::  Precomputed dependency tracking
352 * Dependencies As Side Effects::  Update at developer compile time
353 * Dependencies for the User::   Update at user compile time
354 * Techniques for Dependencies:: Alternative approaches
355 * Recommendations for Tool Writers::  What tool writers can do to help
356 * Future Directions for Dependencies::  Languages Automake does not know
358 Copying This Manual
360 * GNU Free Documentation License::  License for copying this manual
362 Indices
364 * Macro Index::                 Index of Autoconf macros
365 * Variable Index::              Index of Makefile variables
366 * General Index::               General index
368 @end detailmenu
369 @end menu
371 @end ifnottex
374 @node Introduction
375 @chapter Introduction
377 Automake is a tool for automatically generating @file{Makefile.in}s
378 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
379 basically a series of @command{make} variable
380 definitions@footnote{These variables are also called @dfn{make macros}
381 in Make terminology, however in this manual we reserve the term
382 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
383 occasionally.  The generated @file{Makefile.in}s are compliant with
384 the GNU Makefile standards.
386 @cindex GNU Makefile standards
388 The GNU Makefile Standards Document
389 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
390 is long, complicated, and subject to change.  The goal of Automake is to
391 remove the burden of Makefile maintenance from the back of the
392 individual GNU maintainer (and put it on the back of the Automake
393 maintainers).
395 The typical Automake input file is simply a series of variable definitions.
396 Each such file is processed to create a @file{Makefile.in}.  There
397 should generally be one @file{Makefile.am} per directory of a project.
399 @cindex Constraints of Automake
400 @cindex Automake constraints
402 Automake does constrain a project in certain ways; for instance, it
403 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
404 autoconf, The Autoconf Manual}), and enforces certain restrictions on
405 the @file{configure.ac} contents@footnote{Older Autoconf versions used
406 @file{configure.in}.  Autoconf 2.50 and greater promotes
407 @file{configure.ac} over @file{configure.in}.  The rest of this
408 documentation will refer to @file{configure.ac}, but Automake also
409 supports @file{configure.in} for backward compatibility.}.
411 @cindex Automake requirements
412 @cindex Requirements, Automake
414 Automake requires @command{perl} in order to generate the
415 @file{Makefile.in}s.  However, the distributions created by Automake are
416 fully GNU standards-compliant, and do not require @command{perl} in order
417 to be built.
419 @cindex Bugs, reporting
420 @cindex Reporting bugs
421 @cindex E-mail, bug reports
423 Mail suggestions and bug reports for Automake to
424 @email{bug-automake@@gnu.org}.
426 @node Autotools Introduction
427 @chapter An Introduction to the Autotools
429 If you are new to Automake, maybe you know that it is part of a set of
430 tools called @emph{The Autotools}.  Maybe you've already delved into a
431 package full of files named @file{configure}, @file{configure.ac},
432 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
433 some of them claiming to be @emph{generated by} Autoconf or Automake.
434 But the exact purpose of these files and their relations is probably
435 fuzzy.  The goal of this chapter is to introduce you to this machinery,
436 to show you how it works and how powerful it is.  If you've never
437 installed or seen such a package, do not worry: this chapter will walk
438 you through it.
440 If you need some teaching material, more illustrations, or a less
441 @command{automake}-centered continuation, some slides for this
442 introduction are available in Alexandre Duret-Lutz's
443 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
444 Autotools Tutorial}.
445 This chapter is the written version of the first part of his tutorial.
447 @menu
448 * GNU Build System::            Introducing the GNU Build System
449 * Use Cases::                   Use Cases for the GNU Build System
450 * Why Autotools::               How Autotools Help
451 * Hello World::                 A Small Hello World Package
452 @end menu
454 @node GNU Build System
455 @section Introducing the GNU Build System
456 @cindex GNU Build System, introduction
458 It is a truth universally acknowledged, that a developer in
459 possession of a new package, must be in want of a build system.
461 In the Unix world, such a build system is traditionally achieved using
462 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
463 Manual}).  The developer expresses the recipe to build his package in
464 a @file{Makefile}.  This file is a set of rules to build the files in
465 the package.  For instance the program @file{prog} may be built by
466 running the linker on the files @file{main.o}, @file{foo.o}, and
467 @file{bar.o}; the file @file{main.o} may be built by running the
468 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
469 reads @file{Makefile}, checks the existence and modification time of
470 the files mentioned, decides what files need to be built (or rebuilt),
471 and runs the associated commands.
473 When a package needs to be built on a different platform than the one
474 it was developed on, its @file{Makefile} usually needs to be adjusted.
475 For instance the compiler may have another name or require more
476 options.  In 1991, David J. MacKenzie got tired of customizing
477 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
478 handcrafted a little shell script called @file{configure} to
479 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
480 autoconf, The Autoconf Manual}).  Compiling his package was now
481 as simple as running @code{./configure && make}.
483 @cindex GNU Coding Standards
485 Today this process has been standardized in the GNU project.  The GNU
486 Coding Standards (@pxref{Managing Releases, The Release Process, ,
487 standards, The GNU Coding Standards}) explains how each package of the
488 GNU project should have a @file{configure} script, and the minimal
489 interface it should have.  The @file{Makefile} too should follow some
490 established conventions.  The result?  A unified build system that
491 makes all packages almost indistinguishable by the installer.  In its
492 simplest scenario, all the installer has to do is to unpack the
493 package, run @code{./configure && make && make install}, and repeat
494 with the next package to install.
496 We call this build system the @dfn{GNU Build System}, since it was
497 grown out of the GNU project.  However it is used by a vast number of
498 other packages: following any existing convention has its advantages.
500 @cindex Autotools, introduction
502 The Autotools are tools that will create a GNU Build System for your
503 package.  Autoconf mostly focuses on @file{configure} and Automake on
504 @file{Makefile}s.  It is entirely possible to create a GNU Build
505 System without the help of these tools.  However it is rather
506 burdensome and error-prone.  We will discuss this again after some
507 illustration of the GNU Build System in action.
509 @node Use Cases
510 @section Use Cases for the GNU Build System
511 @cindex GNU Build System, use cases
512 @cindex GNU Build System, features
513 @cindex Features of the GNU Build System
514 @cindex Use Cases for the GNU Build System
515 @cindex @file{amhello-1.0.tar.gz}, location
516 @cindex @file{amhello-1.0.tar.gz}, use cases
518 In this section we explore several use cases for the GNU Build System.
519 You can replay all these examples on the @file{amhello-1.0.tar.gz}
520 package distributed with Automake.  If Automake is installed on your
521 system, you should find a copy of this file in
522 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
523 @var{prefix} is the installation prefix specified during configuration
524 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
525 installed by some GNU/Linux distribution it most likely has been set
526 to @file{/usr}).  If you do not have a copy of Automake installed,
527 you can find a copy of this file inside the @file{doc/} directory of
528 the Automake package.
530 Some of the following use cases present features that are in fact
531 extensions to the GNU Build System.  Read: they are not specified by
532 the GNU Coding Standards, but they are nonetheless part of the build
533 system created by the Autotools.  To keep things simple, we do not
534 point out the difference.  Our objective is to show you many of the
535 features that the build system created by the Autotools will offer to
536 you.
538 @menu
539 * Basic Installation::          Common installation procedure
540 * Standard Targets::            A list of standard Makefile targets
541 * Standard Directory Variables::  A list of standard directory variables
542 * Standard Configuration Variables::  Using configuration variables
543 * config.site::                 Using a config.site file
544 * VPATH Builds::                Parallel build trees
545 * Two-Part Install::            Installing data and programs separately
546 * Cross-Compilation::           Building for other architectures
547 * Renaming::                    Renaming programs at install time
548 * DESTDIR::                     Building binary packages with DESTDIR
549 * Preparing Distributions::     Rolling out tarballs
550 * Dependency Tracking::         Automatic dependency tracking
551 * Nested Packages::             The GNU Build Systems can be nested
552 @end menu
554 @node Basic Installation
555 @subsection Basic Installation
556 @cindex Configuration, basics
557 @cindex Installation, basics
558 @cindex GNU Build System, basics
560 The most common installation procedure looks as follows.
562 @example
563 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
564 ~ % @kbd{cd amhello-1.0}
565 ~/amhello-1.0 % @kbd{./configure}
566 @dots{}
567 config.status: creating Makefile
568 config.status: creating src/Makefile
569 @dots{}
570 ~/amhello-1.0 % @kbd{make}
571 @dots{}
572 ~/amhello-1.0 % @kbd{make check}
573 @dots{}
574 ~/amhello-1.0 % @kbd{su}
575 Password:
576 /home/adl/amhello-1.0 # @kbd{make install}
577 @dots{}
578 /home/adl/amhello-1.0 # @kbd{exit}
579 ~/amhello-1.0 % @kbd{make installcheck}
580 @dots{}
581 @end example
583 @cindex Unpacking
585 The user first unpacks the package.  Here, and in the following
586 examples, we will use the non-portable @code{tar zxf} command for
587 simplicity.  On a system without GNU @command{tar} installed, this
588 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
590 The user then enters the newly created directory to run the
591 @file{configure} script.  This script probes the system for various
592 features, and finally creates the @file{Makefile}s.  In this toy
593 example there are only two @file{Makefile}s, but in real-world projects,
594 there may be many more, usually one @file{Makefile} per directory.
596 It is now possible to run @code{make}.  This will construct all the
597 programs, libraries, and scripts that need to be constructed for the
598 package.  In our example, this compiles the @file{hello} program.
599 All files are constructed in place, in the source tree; we will see
600 later how this can be changed.
602 @code{make check} causes the package's tests to be run.  This step is
603 not mandatory, but it is often good to make sure the programs that
604 have been built behave as they should, before you decide to install
605 them.  Our example does not contain any tests, so running @code{make
606 check} is a no-op.
608 @cindex su, before @code{make install}
609 After everything has been built, and maybe tested, it is time to
610 install it on the system.  That means copying the programs,
611 libraries, header files, scripts, and other data files from the
612 source directory to their final destination on the system.  The
613 command @code{make install} will do that.  However, by default
614 everything will be installed in subdirectories of @file{/usr/local}:
615 binaries will go into @file{/usr/local/bin}, libraries will end up in
616 @file{/usr/local/lib}, etc.  This destination is usually not writable
617 by any user, so we assume that we have to become root before we can
618 run @code{make install}.  In our example, running @code{make install}
619 will copy the program @file{hello} into @file{/usr/local/bin}
620 and @file{README} into @file{/usr/local/share/doc/amhello}.
622 A last and optional step is to run @code{make installcheck}.  This
623 command may run tests on the installed files.  @code{make check} tests
624 the files in the source tree, while @code{make installcheck} tests
625 their installed copies.  The tests run by the latter can be different
626 from those run by the former.  For instance, there are tests that
627 cannot be run in the source tree.  Conversely, some packages are set
628 up so that @code{make installcheck} will run the very same tests as
629 @code{make check}, only on different files (non-installed
630 vs.@: installed).  It can make a difference, for instance when the
631 source tree's layout is different from that of the installation.
632 Furthermore it may help to diagnose an incomplete installation.
634 Presently most packages do not have any @code{installcheck} tests
635 because the existence of @code{installcheck} is little known, and its
636 usefulness is neglected.  Our little toy package is no better: @code{make
637 installcheck} does nothing.
639 @node Standard Targets
640 @subsection Standard @file{Makefile} Targets
642 So far we have come across four ways to run @command{make} in the GNU
643 Build System: @code{make}, @code{make check}, @code{make install}, and
644 @code{make installcheck}.  The words @code{check}, @code{install}, and
645 @code{installcheck}, passed as arguments to @command{make}, are called
646 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
647 @code{all} being the default target in the GNU Build System.
649 Here is a list of the most useful targets that the GNU Coding Standards
650 specify.
652 @table @code
653 @item make all
654 @trindex all
655 Build programs, libraries, documentation, etc.@: (same as @code{make}).
656 @item make install
657 @trindex install
658 Install what needs to be installed, copying the files from the
659 package's tree to system-wide directories.
660 @item make install-strip
661 @trindex install-strip
662 Same as @code{make install}, then strip debugging symbols.  Some
663 users like to trade space for useful bug reports@enddots{}
664 @item make uninstall
665 @trindex uninstall
666 The opposite of @code{make install}: erase the installed files.
667 (This needs to be run from the same build tree that was installed.)
668 @item make clean
669 @trindex clean
670 Erase from the build tree the files built by @code{make all}.
671 @item make distclean
672 @trindex distclean
673 Additionally erase anything @code{./configure} created.
674 @item make check
675 @trindex check
676 Run the test suite, if any.
677 @item make installcheck
678 @trindex installcheck
679 Check the installed programs or libraries, if supported.
680 @item make dist
681 @trindex dist
682 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
683 files.
684 @end table
686 @node Standard Directory Variables
687 @subsection Standard Directory Variables
688 @cindex directory variables
690 The GNU Coding Standards also specify a hierarchy of variables to
691 denote installation directories.  Some of these are:
693 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
694 @headitem Directory variable    @tab Default value
695 @item @code{prefix}              @tab @code{/usr/local}
696 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
697 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
698 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
699 @item @w{@ @ @ @ @dots{}}
700 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
701 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
702 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
703 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
704 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
705 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
706 @item @w{@ @ @dots{}}
707 @end multitable
709 @c We should provide a complete table somewhere, but not here.  The
710 @c complete list of directory variables it too confusing as-is.  It
711 @c requires some explanations that are too complicated for this
712 @c introduction.  Besides listing directories like localstatedir
713 @c would make the explanations in ``Two-Part Install'' harder.
715 Each of these directories has a role which is often obvious from its
716 name.  In a package, any installable file will be installed in one of
717 these directories.  For instance in @code{amhello-1.0}, the program
718 @file{hello} is to be installed in @var{bindir}, the directory for
719 binaries.  The default value for this directory is
720 @file{/usr/local/bin}, but the user can supply a different value when
721 calling @command{configure}.  Also the file @file{README} will be
722 installed into @var{docdir}, which defaults to
723 @file{/usr/local/share/doc/amhello}.
725 @opindex --prefix
727 A user who wishes to install a package on his own account could proceed
728 as follows:
730 @example
731 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
732 @dots{}
733 ~/amhello-1.0 % @kbd{make}
734 @dots{}
735 ~/amhello-1.0 % @kbd{make install}
736 @dots{}
737 @end example
739 This would install @file{~/usr/bin/hello} and
740 @file{~/usr/share/doc/amhello/README}.
742 The list of all such directory options is shown by
743 @code{./configure --help}.
745 @node Standard Configuration Variables
746 @subsection Standard Configuration Variables
747 @cindex configuration variables, overriding
749 The GNU Coding Standards also define a set of standard configuration
750 variables used during the build.  Here are some:
752 @table @asis
753 @item @code{CC}
754 C compiler command
755 @item @code{CFLAGS}
756 C compiler flags
757 @item @code{CXX}
758 C++ compiler command
759 @item @code{CXXFLAGS}
760 C++ compiler flags
761 @item @code{LDFLAGS}
762 linker flags
763 @item @code{CPPFLAGS}
764 C/C++ preprocessor flags
765 @item @dots{}
766 @end table
768 @command{configure} usually does a good job at setting appropriate
769 values for these variables, but there are cases where you may want to
770 override them.  For instance you may have several versions of a
771 compiler installed and would like to use another one, you may have
772 header files installed outside the default search path of the
773 compiler, or even libraries out of the way of the linker.
775 Here is how one would call @command{configure} to force it to use
776 @command{gcc-3} as C compiler, use header files from
777 @file{~/usr/include} when compiling, and libraries from
778 @file{~/usr/lib} when linking.
780 @example
781 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
782 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
783 @end example
785 Again, a full list of these variables appears in the output of
786 @code{./configure --help}.
788 @node config.site
789 @subsection Overriding Default Configuration Setting with @file{config.site}
790 @cindex @file{config.site} example
792 When installing several packages using the same setup, it can be
793 convenient to create a file to capture common settings.
794 If a file named @file{@var{prefix}/share/config.site} exists,
795 @command{configure} will source it at the beginning of its execution.
797 Recall the command from the previous section:
799 @example
800 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
801 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
802 @end example
804 Assuming we are installing many package in @file{~/usr}, and will
805 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
806 @code{LDFLAGS}, we can automate this by creating the following
807 @file{~/usr/share/config.site} file:
809 @example
810 test -z "$CC" && CC=gcc-3
811 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
812 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
813 @end example
815 Now, any time a @file{configure} script is using the @file{~/usr}
816 prefix, it will execute the above @file{config.site} and define
817 these three variables.
819 @example
820 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
821 configure: loading site script /home/adl/usr/share/config.site
822 @dots{}
823 @end example
825 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
826 Manual}, for more information about this feature.
829 @node VPATH Builds
830 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
831 @cindex Parallel build trees
832 @cindex VPATH builds
833 @cindex source tree and build tree
834 @cindex build tree and source tree
835 @cindex trees, source vs.@: build
837 The GNU Build System distinguishes two trees: the source tree, and
838 the build tree.
840 The source tree is rooted in the directory containing
841 @file{configure}.  It contains all the sources files (those that are
842 distributed), and may be arranged using several subdirectories.
844 The build tree is rooted in the directory in which @file{configure}
845 was run, and is populated with all object files, programs, libraries,
846 and other derived files built from the sources (and hence not
847 distributed).  The build tree usually has the same subdirectory layout
848 as the source tree; its subdirectories are created automatically by
849 the build system.
851 If @file{configure} is executed in its own directory, the source and
852 build trees are combined: derived files are constructed in the same
853 directories as their sources.  This was the case in our first
854 installation example (@pxref{Basic Installation}).
856 A common request from users is that they want to confine all derived
857 files to a single directory, to keep their source directories
858 uncluttered.  Here is how we could run @file{configure} to build
859 everything in a subdirectory called @file{build/}.
861 @example
862 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
863 ~ % @kbd{cd amhello-1.0}
864 ~/amhello-1.0 % @kbd{mkdir build && cd build}
865 ~/amhello-1.0/build % @kbd{../configure}
866 @dots{}
867 ~/amhello-1.0/build % @kbd{make}
868 @dots{}
869 @end example
871 These setups, where source and build trees are different, are often
872 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
873 @emph{parallel build} is misleading: the word @emph{parallel} is a
874 reference to the way the build tree shadows the source tree, it is not
875 about some concurrency in the way build commands are run.  For this
876 reason we refer to such setups using the name @emph{VPATH builds} in
877 the following.  @emph{VPATH} is the name of the @command{make} feature
878 used by the @file{Makefile}s to allow these builds (@pxref{General
879 Search, , @code{VPATH}: Search Path for All Prerequisites, make, The
880 GNU Make Manual}).
882 @cindex multiple configurations, example
883 @cindex debug build, example
884 @cindex optimized build, example
886 VPATH builds have other interesting uses.  One is to build the same
887 sources with multiple configurations.  For instance:
889 @example
890 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
891 ~ % @kbd{cd amhello-1.0}
892 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
893 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
894 @dots{}
895 ~/amhello-1.0/debug % @kbd{make}
896 @dots{}
897 ~/amhello-1.0/debug % cd ../optim
898 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
899 @dots{}
900 ~/amhello-1.0/optim % @kbd{make}
901 @dots{}
902 @end example
904 With network file systems, a similar approach can be used to build the
905 same sources on different machines.  For instance, suppose that the
906 sources are installed on a directory shared by two hosts: @code{HOST1}
907 and @code{HOST2}, which may be different platforms.
909 @example
910 ~ % @kbd{cd /nfs/src}
911 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
912 @end example
914 On the first host, you could create a local build directory:
915 @example
916 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
917 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
919 [HOST1] /tmp/amh % @kbd{make && sudo make install}
921 @end example
923 @noindent
924 (Here we assume that the installer has configured @command{sudo} so it
925 can execute @code{make install} with root privileges; it is more convenient
926 than using @command{su} like in @ref{Basic Installation}).
928 On the second host, you would do exactly the same, possibly at
929 the same time:
930 @example
931 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
932 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
934 [HOST2] /tmp/amh % @kbd{make && sudo make install}
936 @end example
938 @cindex read-only source tree
939 @cindex source tree, read-only
941 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
942 directory from being read-only.  In fact VPATH builds are also a means
943 of building packages from a read-only medium such as a CD-ROM.  (The
944 FSF used to sell CD-ROM with unpacked source code, before the GNU
945 project grew so big.)
947 @node Two-Part Install
948 @subsection Two-Part Installation
950 In our last example (@pxref{VPATH Builds}), a source tree was shared
951 by two hosts, but compilation and installation were done separately on
952 each host.
954 The GNU Build System also supports networked setups where part of the
955 installed files should be shared amongst multiple hosts.  It does so
956 by distinguishing architecture-dependent files from
957 architecture-independent files, and providing two @file{Makefile}
958 targets to install each of these classes of files.
960 @trindex install-exec
961 @trindex install-data
963 These targets are @code{install-exec} for architecture-dependent files
964 and @code{install-data} for architecture-independent files.
965 The command we used up to now, @code{make install}, can be thought of
966 as a shorthand for @code{make install-exec install-data}.
968 From the GNU Build System point of view, the distinction between
969 architecture-dependent files and architecture-independent files is
970 based exclusively on the directory variable used to specify their
971 installation destination.  In the list of directory variables we
972 provided earlier (@pxref{Standard Directory Variables}), all the
973 variables based on @var{exec-prefix} designate architecture-dependent
974 directories whose files will be installed by @code{make install-exec}.
975 The others designate architecture-independent directories and will
976 serve files installed by @code{make install-data}.  @xref{The Two Parts
977 of Install}, for more details.
979 Here is how we could revisit our two-host installation example,
980 assuming that (1) we want to install the package directly in
981 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
982 two hosts.
984 On the first host we would run
985 @example
986 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
987 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
989 [HOST1] /tmp/amh % @kbd{make && sudo make install}
991 @end example
993 On the second host, however, we need only install the
994 architecture-specific files.
995 @example
996 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
997 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
999 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1001 @end example
1003 In packages that have installation checks, it would make sense to run
1004 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1005 the package works correctly despite the apparent partial installation.
1007 @node Cross-Compilation
1008 @subsection Cross-Compilation
1009 @cindex cross-compilation
1011 To @dfn{cross-compile} is to build on one platform a binary that will
1012 run on another platform.  When speaking of cross-compilation, it is
1013 important to distinguish between the @dfn{build platform} on which
1014 the compilation is performed, and the @dfn{host platform} on which the
1015 resulting executable is expected to run.  The following
1016 @command{configure} options are used to specify each of them:
1018 @table @option
1019 @item --build=@var{BUILD}
1020 @opindex --build=@var{BUILD}
1021 The system on which the package is built.
1022 @item --host=@var{HOST}
1023 @opindex --host=@var{HOST}
1024 The system where built programs and libraries will run.
1025 @end table
1027 When the @option{--host} is used, @command{configure} will search for
1028 the cross-compiling suite for this platform.  Cross-compilation tools
1029 commonly have their target architecture as prefix of their name.  For
1030 instance my cross-compiler for MinGW32 has its binaries called
1031 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1032 @code{i586-mingw32msvc-as}, etc.
1034 @cindex MinGW cross-compilation example
1035 @cindex cross-compilation example
1037 Here is how we could build @code{amhello-1.0} for
1038 @code{i586-mingw32msvc} on a GNU/Linux PC.
1040 @smallexample
1041 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1042 checking for a BSD-compatible install... /usr/bin/install -c
1043 checking whether build environment is sane... yes
1044 checking for gawk... gawk
1045 checking whether make sets $(MAKE)... yes
1046 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1047 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1048 checking for C compiler default output file name... a.exe
1049 checking whether the C compiler works... yes
1050 checking whether we are cross compiling... yes
1051 checking for suffix of executables... .exe
1052 checking for suffix of object files... o
1053 checking whether we are using the GNU C compiler... yes
1054 checking whether i586-mingw32msvc-gcc accepts -g... yes
1055 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1056 @dots{}
1057 ~/amhello-1.0 % @kbd{make}
1058 @dots{}
1059 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1060 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1061 @end smallexample
1063 The @option{--host} and @option{--build} options are usually all we
1064 need for cross-compiling.  The only exception is if the package being
1065 built is itself a cross-compiler: we need a third option to specify
1066 its target architecture.
1068 @table @option
1069 @item --target=@var{TARGET}
1070 @opindex --target=@var{TARGET}
1071 When building compiler tools: the system for which the tools will
1072 create output.
1073 @end table
1075 For instance when installing GCC, the GNU Compiler Collection, we can
1076 use @option{--target=@/@var{TARGET}} to specify that we want to build
1077 GCC as a cross-compiler for @var{TARGET}.  Mixing @option{--build} and
1078 @option{--target}, we can actually cross-compile a cross-compiler;
1079 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1081 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1082 Autoconf Manual}, for more information about these @command{configure}
1083 options.
1085 @node Renaming
1086 @subsection Renaming Programs at Install Time
1087 @cindex Renaming programs
1088 @cindex Transforming program names
1089 @cindex Programs, renaming during installation
1091 The GNU Build System provides means to automatically rename
1092 executables and manpages before they are installed (@pxref{Man Pages}).
1093 This is especially convenient
1094 when installing a GNU package on a system that already has a
1095 proprietary implementation you do not want to overwrite.  For instance,
1096 you may want to install GNU @command{tar} as @command{gtar} so you can
1097 distinguish it from your vendor's @command{tar}.
1099 This can be done using one of these three @command{configure} options.
1101 @table @option
1102 @item --program-prefix=@var{PREFIX}
1103 @opindex --program-prefix=@var{PREFIX}
1104 Prepend @var{PREFIX} to installed program names.
1105 @item --program-suffix=@var{SUFFIX}
1106 @opindex --program-suffix=@var{SUFFIX}
1107 Append @var{SUFFIX} to installed program names.
1108 @item --program-transform-name=@var{PROGRAM}
1109 @opindex --program-transform-name=@var{PROGRAM}
1110 Run @code{sed @var{PROGRAM}} on installed program names.
1111 @end table
1113 The following commands would install @file{hello}
1114 as @file{/usr/local/bin/test-hello}, for instance.
1116 @example
1117 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1118 @dots{}
1119 ~/amhello-1.0 % @kbd{make}
1120 @dots{}
1121 ~/amhello-1.0 % @kbd{sudo make install}
1122 @dots{}
1123 @end example
1125 @node DESTDIR
1126 @subsection Building Binary Packages Using DESTDIR
1127 @vindex DESTDIR
1129 The GNU Build System's @code{make install} and @code{make uninstall}
1130 interface does not exactly fit the needs of a system administrator
1131 who has to deploy and upgrade packages on lots of hosts.  In other
1132 words, the GNU Build System does not replace a package manager.
1134 Such package managers usually need to know which files have been
1135 installed by a package, so a mere @code{make install} is
1136 inappropriate.
1138 @cindex Staged installation
1140 The @code{DESTDIR} variable can be used to perform a staged
1141 installation.  The package should be configured as if it was going to
1142 be installed in its final location (e.g., @code{--prefix /usr}), but
1143 when running @code{make install}, the @code{DESTDIR} should be set to
1144 the absolute name of a directory into which the installation will be
1145 diverted.  From this directory it is easy to review which files are
1146 being installed where, and finally copy them to their final location
1147 by some means.
1149 @cindex Binary package
1151 For instance here is how we could create a binary package containing a
1152 snapshot of all the files to be installed.
1154 @example
1155 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1156 @dots{}
1157 ~/amhello-1.0 % @kbd{make}
1158 @dots{}
1159 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1160 @dots{}
1161 ~/amhello-1.0 % @kbd{cd ~/inst}
1162 ~/inst % @kbd{find . -type f -print > ../files.lst}
1163 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1164 ./usr/bin/hello
1165 ./usr/share/doc/amhello/README
1166 @end example
1168 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1169 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1170 instead of @samp{.} as argument for @command{tar} avoids entries for
1171 each subdirectory in the archive: we would not like @command{tar} to
1172 restore the modification time of @file{/}, @file{/usr/}, etc.)
1174 Note that when building packages for several architectures, it might
1175 be convenient to use @code{make install-data} and @code{make
1176 install-exec} (@pxref{Two-Part Install}) to gather
1177 architecture-independent files in a single package.
1179 @xref{Install}, for more information.
1181 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1182 @c UNINSTALL counterparts.
1184 @node Preparing Distributions
1185 @subsection Preparing Distributions
1186 @cindex Preparing distributions
1187 @cindex Packages, preparation
1188 @cindex Distributions, preparation
1190 We have already mentioned @code{make dist}.  This target collects all
1191 your source files and the necessary parts of the build system to
1192 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1194 @cindex @code{distcheck} better than @code{dist}
1196 Another, more useful command is @code{make distcheck}.  The
1197 @code{distcheck} target constructs
1198 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1199 but it additionally ensures most of the use cases presented so far
1200 work:
1202 @itemize @bullet
1203 @item
1204 It attempts a full compilation of the package (@pxref{Basic
1205 Installation}), unpacking the newly constructed tarball, running
1206 @code{make}, @code{make check}, @code{make install}, as well as
1207 @code{make installcheck}, and even @code{make dist},
1208 @item
1209 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1210 @item
1211 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1212 uninstall} do not omit any file (@pxref{Standard Targets}),
1213 @item
1214 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1215 @end itemize
1217 All of these actions are performed in a temporary subdirectory, so
1218 that no root privileges are required.
1220 Releasing a package that fails @code{make distcheck} means that one of
1221 the scenarios we presented will not work and some users will be
1222 disappointed.  Therefore it is a good practice to release a package
1223 only after a successful @code{make distcheck}.  This of course does
1224 not imply that the package will be flawless, but at least it will
1225 prevent some of the embarrassing errors you may find in packages
1226 released by people who have never heard about @code{distcheck} (like
1227 @code{DESTDIR} not working because of a typo, or a distributed file
1228 being erased by @code{make clean}, or even @code{VPATH} builds not
1229 working).
1231 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1232 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1233 information about @code{distcheck}.
1235 @node Dependency Tracking
1236 @subsection Automatic Dependency Tracking
1237 @cindex Dependency tracking
1239 Dependency tracking is performed as a side-effect of compilation.
1240 Each time the build system compiles a source file, it computes its
1241 list of dependencies (in C these are the header files included by the
1242 source being compiled).  Later, any time @command{make} is run and a
1243 dependency appears to have changed, the dependent files will be
1244 rebuilt.
1246 When @command{configure} is executed, you can see it probing each
1247 compiler for the dependency mechanism it supports (several mechanisms
1248 can be used):
1250 @example
1251 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1252 @dots{}
1253 checking dependency style of gcc... gcc3
1254 @dots{}
1255 @end example
1257 Because dependencies are only computed as a side-effect of the
1258 compilation, no dependency information exists the first time a package
1259 is built.  This is OK because all the files need to be built anyway:
1260 @code{make} does not have to decide which files need to be rebuilt.
1261 In fact, dependency tracking is completely useless for one-time builds
1262 and there is a @command{configure} option to disable this:
1264 @table @option
1265 @item --disable-dependency-tracking
1266 @opindex --disable-dependency-tracking
1267 Speed up one-time builds.
1268 @end table
1270 Some compilers do not offer any practical way to derive the list of
1271 dependencies as a side-effect of the compilation, requiring a separate
1272 run (maybe of another tool) to compute these dependencies.  The
1273 performance penalty implied by these methods is important enough to
1274 disable them by default.  The option @option{--enable-dependency-tracking}
1275 must be passed to @command{configure} to activate them.
1277 @table @option
1278 @item --enable-dependency-tracking
1279 @opindex --enable-dependency-tracking
1280 Do not reject slow dependency extractors.
1281 @end table
1283 @xref{Dependency Tracking Evolution}, for some discussion about the
1284 different dependency tracking schemes used by Automake over the years.
1286 @node Nested Packages
1287 @subsection Nested Packages
1288 @cindex Nested packages
1289 @cindex Packages, nested
1290 @cindex Subpackages
1292 Although nesting packages isn't something we would recommend to
1293 someone who is discovering the Autotools, it is a nice feature worthy
1294 of mention in this small advertising tour.
1296 Autoconfiscated packages (that means packages whose build system have
1297 been created by Autoconf and friends) can be nested to arbitrary
1298 depth.
1300 A typical setup is that package A will distribute one of the libraries
1301 it needs in a subdirectory.  This library B is a complete package with
1302 its own GNU Build System.  The @command{configure} script of A will
1303 run the @command{configure} script of B as part of its execution,
1304 building and installing A will also build and install B.  Generating a
1305 distribution for A will also include B.
1307 It is possible to gather several package like this.  GCC is a heavy
1308 user of this feature.  This gives installers a single package to
1309 configure, build and install, while it allows developers to work on
1310 subpackages independently.
1312 When configuring nested packages, the @command{configure} options
1313 given to the top-level @command{configure} are passed recursively to
1314 nested @command{configure}s.  A package that does not understand an
1315 option will ignore it, assuming it is meaningful to some other
1316 package.
1318 @opindex --help=recursive
1320 The command @code{configure --help=recursive} can be used to display
1321 the options supported by all the included packages.
1323 @xref{Subpackages}, for an example setup.
1325 @node Why Autotools
1326 @section How Autotools Help
1327 @cindex Autotools, purpose
1329 There are several reasons why you may not want to implement the GNU
1330 Build System yourself (read: write a @file{configure} script and
1331 @file{Makefile}s yourself).
1333 @itemize @bullet
1334 @item
1335 As we have seen, the GNU Build System has a lot of
1336 features (@pxref{Use Cases}).
1337 Some users may expect features you have not implemented because
1338 you did not need them.
1339 @item
1340 Implementing these features portably is difficult and exhausting.
1341 Think of writing portable shell scripts, and portable
1342 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1343 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1344 convince yourself.
1345 @item
1346 You will have to upgrade your setup to follow changes to the GNU
1347 Coding Standards.
1348 @end itemize
1350 The GNU Autotools take all this burden off your back and provide:
1352 @itemize @bullet
1353 @item
1354 Tools to create a portable, complete, and self-contained GNU Build
1355 System, from simple instructions.
1356 @emph{Self-contained} meaning the resulting build system does not
1357 require the GNU Autotools.
1358 @item
1359 A central place where fixes and improvements are made:
1360 a bug-fix for a portability issue will benefit every package.
1361 @end itemize
1363 Yet there also exist reasons why you may want NOT to use the
1364 Autotools@enddots{} For instance you may be already using (or used to)
1365 another incompatible build system.  Autotools will only be useful if
1366 you do accept the concepts of the GNU Build System.  People who have their
1367 own idea of how a build system should work will feel frustrated by the
1368 Autotools.
1370 @node Hello World
1371 @section A Small Hello World
1372 @cindex Example Hello World
1373 @cindex Hello World example
1374 @cindex @file{amhello-1.0.tar.gz}, creation
1376 In this section we recreate the @file{amhello-1.0} package from
1377 scratch.  The first subsection shows how to call the Autotools to
1378 instantiate the GNU Build System, while the second explains the
1379 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1380 by the Autotools.
1382 @menu
1383 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1384 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
1385 @end menu
1387 @node Creating amhello
1388 @subsection Creating @file{amhello-1.0.tar.gz}
1390 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1391 The package is simple enough so that we will only need to write 5
1392 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1393 that is distributed with Automake if you do not want to write them.)
1395 Create the following files in an empty directory.
1397 @itemize @bullet
1399 @item
1400 @file{src/main.c} is the source file for the @file{hello} program.  We
1401 store it in the @file{src/} subdirectory, because later, when the package
1402 evolves, it will ease the addition of a @file{man/} directory for man
1403 pages, a @file{data/} directory for data files, etc.
1404 @example
1405 ~/amhello % @kbd{cat src/main.c}
1406 #include <config.h>
1407 #include <stdio.h>
1410 main (void)
1412   puts ("Hello World!");
1413   puts ("This is " PACKAGE_STRING ".");
1414   return 0;
1416 @end example
1418 @item
1419 @file{README} contains some very limited documentation for our little
1420 package.
1421 @example
1422 ~/amhello % @kbd{cat README}
1423 This is a demonstration package for GNU Automake.
1424 Type `info Automake' to read the Automake manual.
1425 @end example
1427 @item
1428 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1429 instructions for these two directories.
1431 @example
1432 ~/amhello % @kbd{cat src/Makefile.am}
1433 bin_PROGRAMS = hello
1434 hello_SOURCES = main.c
1435 ~/amhello % @kbd{cat Makefile.am}
1436 SUBDIRS = src
1437 dist_doc_DATA = README
1438 @end example
1440 @item
1441 Finally, @file{configure.ac} contains Autoconf instructions to
1442 create the @command{configure} script.
1444 @example
1445 ~/amhello % @kbd{cat configure.ac}
1446 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1447 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1448 AC_PROG_CC
1449 AC_CONFIG_HEADERS([config.h])
1450 AC_CONFIG_FILES([
1451  Makefile
1452  src/Makefile
1454 AC_OUTPUT
1455 @end example
1456 @end itemize
1458 @cindex @command{autoreconf}, example
1460 Once you have these five files, it is time to run the Autotools to
1461 instantiate the build system.  Do this using the @command{autoreconf}
1462 command as follows:
1464 @example
1465 ~/amhello % @kbd{autoreconf --install}
1466 configure.ac: installing `./install-sh'
1467 configure.ac: installing `./missing'
1468 src/Makefile.am: installing `./depcomp'
1469 @end example
1471 At this point the build system is complete.
1473 In addition to the three scripts mentioned in its output, you can see
1474 that @command{autoreconf} created four other files: @file{configure},
1475 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1476 The latter three files are templates that will be adapted to the
1477 system by @command{configure} under the names @file{config.h},
1478 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1480 @example
1481 ~/amhello % @kbd{./configure}
1482 checking for a BSD-compatible install... /usr/bin/install -c
1483 checking whether build environment is sane... yes
1484 checking for gawk... no
1485 checking for mawk... mawk
1486 checking whether make sets $(MAKE)... yes
1487 checking for gcc... gcc
1488 checking for C compiler default output file name... a.out
1489 checking whether the C compiler works... yes
1490 checking whether we are cross compiling... no
1491 checking for suffix of executables...
1492 checking for suffix of object files... o
1493 checking whether we are using the GNU C compiler... yes
1494 checking whether gcc accepts -g... yes
1495 checking for gcc option to accept ISO C89... none needed
1496 checking for style of include used by make... GNU
1497 checking dependency style of gcc... gcc3
1498 configure: creating ./config.status
1499 config.status: creating Makefile
1500 config.status: creating src/Makefile
1501 config.status: creating config.h
1502 config.status: executing depfiles commands
1503 @end example
1505 @trindex distcheck
1506 @cindex @code{distcheck} example
1508 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1509 being created at the end after @command{configure} has probed the
1510 system.  It is now possible to run all the targets we wish
1511 (@pxref{Standard Targets}).  For instance:
1513 @example
1514 ~/amhello % @kbd{make}
1515 @dots{}
1516 ~/amhello % @kbd{src/hello}
1517 Hello World!
1518 This is amhello 1.0.
1519 ~/amhello % @kbd{make distcheck}
1520 @dots{}
1521 =============================================
1522 amhello-1.0 archives ready for distribution:
1523 amhello-1.0.tar.gz
1524 =============================================
1525 @end example
1527 Note that running @command{autoreconf} is only needed initially when
1528 the GNU Build System does not exist.  When you later change some
1529 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1530 relevant part of the build system will be regenerated automatically
1531 when you execute @command{make}.
1533 @command{autoreconf} is a script that calls @command{autoconf},
1534 @command{automake}, and a bunch of other commands in the right order.
1535 If you are beginning with these tools, it is not important to figure
1536 out in which order all these tools should be invoked and why.  However,
1537 because Autoconf and Automake have separate manuals, the important
1538 point to understand is that @command{autoconf} is in charge of
1539 creating @file{configure} from @file{configure.ac}, while
1540 @command{automake} is in charge of creating @file{Makefile.in}s from
1541 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1542 direct you to the right manual when seeking answers.
1545 @node amhello Explained
1546 @subsection @file{amhello-1.0} Explained
1548 Let us begin with the contents of @file{configure.ac}.
1550 @example
1551 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1552 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1553 AC_PROG_CC
1554 AC_CONFIG_HEADERS([config.h])
1555 AC_CONFIG_FILES([
1556  Makefile
1557  src/Makefile
1559 AC_OUTPUT
1560 @end example
1562 This file is read by both @command{autoconf} (to create
1563 @file{configure}) and @command{automake} (to create the various
1564 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1565 expanded as shell code to finally form the @file{configure} script.
1566 We will not elaborate on the syntax of this file, because the Autoconf
1567 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1568 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1570 The macros prefixed with @code{AC_} are Autoconf macros, documented
1571 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1572 Index, autoconf, The Autoconf Manual}).  The macros that start with
1573 @code{AM_} are Automake macros, documented later in this manual
1574 (@pxref{Macro Index}).
1576 The first two lines of @file{configure.ac} initialize Autoconf and
1577 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1578 its version number, and a contact address for bug-reports about the
1579 package (this address is output at the end of @code{./configure
1580 --help}, for instance).  When adapting this setup to your own package,
1581 by all means please do not blindly copy Automake's address: use the
1582 mailing list of your package, or your own mail address.
1584 @opindex -Wall
1585 @opindex -Werror
1586 @opindex foreign
1588 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1589 @command{automake} (@pxref{Options}).  @option{-Wall} and
1590 @option{-Werror} ask @command{automake} to turn on all warnings and
1591 report them as errors.  We are speaking of @strong{Automake} warnings
1592 here, such as dubious instructions in @file{Makefile.am}.  This has
1593 absolutely nothing to do with how the compiler will be called, even
1594 though it may support options with similar names.  Using @option{-Wall
1595 -Werror} is a safe setting when starting to work on a package: you do
1596 not want to miss any issues.  Later you may decide to relax things a
1597 bit.  The @option{foreign} option tells Automake that this package
1598 will not follow the GNU Standards.  GNU packages should always
1599 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1600 etc.  We do not want @command{automake} to complain about these
1601 missing files in our small example.
1603 The @code{AC_PROG_CC} line causes the @command{configure} script to
1604 search for a C compiler and define the variable @code{CC} with its
1605 name.  The @file{src/Makefile.in} file generated by Automake uses the
1606 variable @code{CC} to build @file{hello}, so when @command{configure}
1607 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1608 @code{CC} with the value it has found.  If Automake is asked to create
1609 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1610 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1612 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1613 @command{configure} script to create a @file{config.h} file gathering
1614 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1615 case, the @code{AC_INIT} macro already defined a few of them.  Here
1616 is an excerpt of @file{config.h} after @command{configure} has run:
1618 @smallexample
1619 @dots{}
1620 /* Define to the address where bug reports for this package should be sent. */
1621 #define PACKAGE_BUGREPORT "bug-automake@@gnu.org"
1623 /* Define to the full name and version of this package. */
1624 #define PACKAGE_STRING "amhello 1.0"
1625 @dots{}
1626 @end smallexample
1628 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1629 it can use @code{PACKAGE_STRING}.  In a real-world project,
1630 @file{config.h} can grow really big, with one @samp{#define} per
1631 feature probed on the system.
1633 The @code{AC_CONFIG_FILES} macro declares the list of files that
1634 @command{configure} should create from their @file{*.in} templates.
1635 Automake also scans this list to find the @file{Makefile.am} files it must
1636 process.  (This is important to remember: when adding a new directory
1637 to your project, you should add its @file{Makefile} to this list,
1638 otherwise Automake will never process the new @file{Makefile.am} you
1639 wrote in that directory.)
1641 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1642 produces the part of the script in charge of creating the files
1643 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1645 @cindex @command{autoscan}
1647 When starting a new project, we suggest you start with such a simple
1648 @file{configure.ac}, and gradually add the other tests it requires.
1649 The command @command{autoscan} can also suggest a few of the tests
1650 your package may need (@pxref{autoscan Invocation, , Using
1651 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1652 Autoconf Manual}).
1654 @cindex @file{Makefile.am}, Hello World
1656 We now turn to @file{src/Makefile.am}.  This file contains
1657 Automake instructions to build and install @file{hello}.
1659 @example
1660 bin_PROGRAMS = hello
1661 hello_SOURCES = main.c
1662 @end example
1664 A @file{Makefile.am} has the same syntax as an ordinary
1665 @file{Makefile}.  When @command{automake} processes a
1666 @file{Makefile.am} it copies the entire file into the output
1667 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1668 @command{configure}) but will react to certain variable definitions
1669 by generating some build rules and other variables.
1670 Often @file{Makefile.am}s contain only a list of variable definitions as
1671 above, but they can also contain other variable and rule definitions that
1672 @command{automake} will pass along without interpretation.
1674 Variables that end with @code{_PROGRAMS} are special variables
1675 that list programs that the resulting @file{Makefile} should build.
1676 In Automake speak, this @code{_PROGRAMS} suffix is called a
1677 @dfn{primary}; Automake recognizes other primaries such as
1678 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1679 to different types of files.
1681 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1682 @command{automake} that the resulting programs should be installed in
1683 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1684 to denote destination directories and allow users to customize these
1685 locations (@pxref{Standard Directory Variables}).  Any such directory
1686 variable can be put in front of a primary (omitting the @code{dir}
1687 suffix) to tell @command{automake} where to install the listed files.
1689 Programs need to be built from source files, so for each program
1690 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1691 @command{automake} will look for another variable named
1692 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1693 than one source file: they will all be compiled and linked together.
1695 Automake also knows that source files need to be distributed when
1696 creating a tarball (unlike built programs).  So a side-effect of this
1697 @code{hello_SOURCES} declaration is that @file{main.c} will be
1698 part of the tarball created by @code{make dist}.
1700 Finally here are some explanations regarding the top-level
1701 @file{Makefile.am}.
1703 @example
1704 SUBDIRS = src
1705 dist_doc_DATA = README
1706 @end example
1708 @code{SUBDIRS} is a special variable listing all directories that
1709 @command{make} should recurse into before processing the current
1710 directory.  So this line is responsible for @command{make} building
1711 @file{src/hello} even though we run it from the top-level.  This line
1712 also causes @code{make install} to install @file{src/hello} before
1713 installing @file{README} (not that this order matters).
1715 The line @code{dist_doc_DATA = README} causes @file{README} to be
1716 distributed and installed in @var{docdir}.  Files listed with the
1717 @code{_DATA} primary are not automatically part of the tarball built
1718 with @code{make dist}, so we add the @code{dist_} prefix so they get
1719 distributed.  However, for @file{README} it would not have been
1720 necessary: @command{automake} automatically distributes any
1721 @file{README} file it encounters (the list of other files
1722 automatically distributed is presented by @code{automake --help}).
1723 The only important effect of this second line is therefore to install
1724 @file{README} during @code{make install}.
1727 @node Generalities
1728 @chapter General ideas
1730 The following sections cover a few basic ideas that will help you
1731 understand how Automake works.
1733 @menu
1734 * General Operation::           General operation of Automake
1735 * Strictness::                  Standards conformance checking
1736 * Uniform::                     The Uniform Naming Scheme
1737 * Canonicalization::            How derived variables are named
1738 * Length Limitations::          Staying below the command line length limit
1739 * User Variables::              Variables reserved for the user
1740 * Auxiliary Programs::          Programs automake might require
1741 @end menu
1744 @node General Operation
1745 @section General Operation
1747 Automake works by reading a @file{Makefile.am} and generating a
1748 @file{Makefile.in}.  Certain variables and rules defined in the
1749 @file{Makefile.am} instruct Automake to generate more specialized code;
1750 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1751 for compiling and linking programs to be generated.
1753 @cindex Non-standard targets
1754 @cindex @code{cvs-dist}, non-standard example
1755 @trindex cvs-dist
1756 @trindex git-dist
1758 The variable definitions and rules in the @file{Makefile.am} are
1759 copied verbatim into the generated file.  This allows you to add
1760 arbitrary code into the generated @file{Makefile.in}.  For instance,
1761 the Automake distribution includes a non-standard rule for the
1762 @code{git-dist} target, which the Automake maintainer uses to make
1763 distributions from his source control system.
1765 @cindex GNU make extensions
1767 Note that most GNU make extensions are not recognized by Automake.  Using
1768 such extensions in a @file{Makefile.am} will lead to errors or confusing
1769 behavior.
1771 @cindex Append operator
1772 @cmindex +=
1773 A special exception is that the GNU make append operator, @samp{+=}, is
1774 supported.  This operator appends its right hand argument to the variable
1775 specified on the left.  Automake will translate the operator into
1776 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1778 @cindex indentation
1779 Further note that variable assignments should not be indented with
1780 @key{TAB} characters, use spaces if necessary.  On the other hand,
1781 rule commands should be indented with a leading @key{TAB} character.
1783 Automake tries to keep comments grouped with any adjoining rules or
1784 variable definitions.
1786 @cindex Make targets, overriding
1787 @cindex Make rules, overriding
1788 @cindex Overriding make rules
1789 @cindex Overriding make targets
1791 A rule defined in @file{Makefile.am} generally overrides any such
1792 rule of a similar name that would be automatically generated by
1793 @command{automake}.  Although this is a supported feature, it is generally
1794 best to avoid making use of it, as sometimes the generated rules are
1795 very particular.
1797 @cindex Variables, overriding
1798 @cindex Overriding make variables
1800 Similarly, a variable defined in @file{Makefile.am} or
1801 @code{AC_SUBST}ed from @file{configure.ac} will override any
1802 definition of the variable that @command{automake} would ordinarily
1803 create.  This feature is more often useful than the ability to
1804 override a rule.  Be warned that many of the variables generated by
1805 @command{automake} are considered to be for internal use only, and their
1806 names might change in future releases.
1808 @cindex Recursive operation of Automake
1809 @cindex Automake, recursive operation
1810 @cindex Example of recursive operation
1812 When examining a variable definition, Automake will recursively examine
1813 variables referenced in the definition.  For example, if Automake is
1814 looking at the content of @code{foo_SOURCES} in this snippet
1816 @example
1817 xs = a.c b.c
1818 foo_SOURCES = c.c $(xs)
1819 @end example
1821 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1822 contents of @code{foo_SOURCES}.
1824 @cindex @code{##} (special Automake comment)
1825 @cindex Special Automake comment
1826 @cindex Comment, special to Automake
1828 Automake also allows a form of comment that is @emph{not} copied into
1829 the output; all lines beginning with @samp{##} (leading spaces allowed)
1830 are completely ignored by Automake.
1832 It is customary to make the first line of @file{Makefile.am} read:
1834 @cindex Makefile.am, first line
1835 @cindex First line of Makefile.am
1837 @example
1838 ## Process this file with automake to produce Makefile.in
1839 @end example
1841 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1842 @c I don't know quite what to say.
1844 @c FIXME document customary ordering of Makefile.am here!
1847 @node Strictness
1848 @section Strictness
1850 @cindex Non-GNU packages
1852 While Automake is intended to be used by maintainers of GNU packages, it
1853 does make some effort to accommodate those who wish to use it, but do
1854 not want to use all the GNU conventions.
1856 @cindex Strictness, defined
1857 @cindex Strictness, @option{foreign}
1858 @cindex @option{foreign} strictness
1859 @cindex Strictness, @option{gnu}
1860 @cindex @option{gnu} strictness
1861 @cindex Strictness, @option{gnits}
1862 @cindex @option{gnits} strictness
1864 To this end, Automake supports three levels of @dfn{strictness}---the
1865 strictness indicating how stringently Automake should check standards
1866 conformance.
1868 The valid strictness levels are:
1870 @table @option
1871 @item foreign
1872 Automake will check for only those things that are absolutely
1873 required for proper operations.  For instance, whereas GNU standards
1874 dictate the existence of a @file{NEWS} file, it will not be required in
1875 this mode.  The name comes from the fact that Automake is intended to be
1876 used for GNU programs; these relaxed rules are not the standard mode of
1877 operation.
1879 @item gnu
1880 Automake will check---as much as possible---for compliance to the GNU
1881 standards for packages.  This is the default.
1883 @item gnits
1884 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1885 standards}.  These are based on the GNU standards, but are even more
1886 detailed.  Unless you are a Gnits standards contributor, it is
1887 recommended that you avoid this option until such time as the Gnits
1888 standard is actually published (which may never happen).
1889 @end table
1891 @xref{Gnits}, for more information on the precise implications of the
1892 strictness level.
1894 Automake also has a special ``cygnus'' mode that is similar to
1895 strictness but handled differently.  This mode is useful for packages
1896 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
1897 @xref{Cygnus}, for more information on this mode.
1900 @node Uniform
1901 @section The Uniform Naming Scheme
1903 @cindex Uniform naming scheme
1905 Automake variables generally follow a @dfn{uniform naming scheme} that
1906 makes it easy to decide how programs (and other derived objects) are
1907 built, and how they are installed.  This scheme also supports
1908 @command{configure} time determination of what should be built.
1910 @cindex @code{_PROGRAMS} primary variable
1911 @cindex @code{PROGRAMS} primary variable
1912 @cindex Primary variable, @code{PROGRAMS}
1913 @cindex Primary variable, defined
1914 @vindex _PROGRAMS
1916 At @command{make} time, certain variables are used to determine which
1917 objects are to be built.  The variable names are made of several pieces
1918 that are concatenated together.
1920 The piece that tells @command{automake} what is being built is commonly called
1921 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1922 list of programs that are to be compiled and linked.
1923 @vindex PROGRAMS
1925 @cindex @code{pkgdatadir}, defined
1926 @cindex @code{pkgincludedir}, defined
1927 @cindex @code{pkglibdir}, defined
1928 @cindex @code{pkglibexecdir}, defined
1930 @vindex pkgdatadir
1931 @vindex pkgincludedir
1932 @vindex pkglibdir
1933 @vindex pkglibexecdir
1935 @cindex @code{PACKAGE}, directory
1936 A different set of names is used to decide where the built objects
1937 should be installed.  These names are prefixes to the primary, and they
1938 indicate which standard directory should be used as the installation
1939 directory.  The standard directory names are given in the GNU standards
1940 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1941 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
1942 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
1943 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
1944 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
1946 @cindex @code{EXTRA_}, prepending
1947 For each primary, there is one additional variable named by prepending
1948 @samp{EXTRA_} to the primary name.  This variable is used to list
1949 objects that may or may not be built, depending on what
1950 @command{configure} decides.  This variable is required because Automake
1951 must statically know the entire list of objects that may be built in
1952 order to generate a @file{Makefile.in} that will work in all cases.
1954 @cindex @code{EXTRA_PROGRAMS}, defined
1955 @cindex Example, @code{EXTRA_PROGRAMS}
1956 @cindex @command{cpio} example
1958 For instance, @command{cpio} decides at configure time which programs
1959 should be built.  Some of the programs are installed in @code{bindir},
1960 and some are installed in @code{sbindir}:
1962 @example
1963 EXTRA_PROGRAMS = mt rmt
1964 bin_PROGRAMS = cpio pax
1965 sbin_PROGRAMS = $(MORE_PROGRAMS)
1966 @end example
1968 Defining a primary without a prefix as a variable, e.g.,
1969 @samp{PROGRAMS}, is an error.
1971 Note that the common @samp{dir} suffix is left off when constructing the
1972 variable names; thus one writes @samp{bin_PROGRAMS} and not
1973 @samp{bindir_PROGRAMS}.
1975 Not every sort of object can be installed in every directory.  Automake
1976 will flag those attempts it finds in error.
1977 Automake will also diagnose obvious misspellings in directory names.
1979 @cindex Extending list of installation directories
1980 @cindex Installation directories, extending list
1982 Sometimes the standard directories---even as augmented by
1983 Automake---are not enough.  In particular it is sometimes useful, for
1984 clarity, to install objects in a subdirectory of some predefined
1985 directory.  To this end, Automake allows you to extend the list of
1986 possible installation directories.  A given prefix (e.g., @samp{zar})
1987 is valid if a variable of the same name with @samp{dir} appended is
1988 defined (e.g., @samp{zardir}).
1990 For instance, the following snippet will install @file{file.xml} into
1991 @samp{$(datadir)/xml}.
1993 @example
1994 xmldir = $(datadir)/xml
1995 xml_DATA = file.xml
1996 @end example
1998 @cindex @samp{noinst_} primary prefix, definition
1999 @vindex noinst_
2001 The special prefix @samp{noinst_} indicates that the objects in question
2002 should be built but not installed at all.  This is usually used for
2003 objects required to build the rest of your package, for instance static
2004 libraries (@pxref{A Library}), or helper scripts.
2006 @cindex @samp{check_} primary prefix, definition
2007 @vindex check_
2009 The special prefix @samp{check_} indicates that the objects in question
2010 should not be built until the @samp{make check} command is run.  Those
2011 objects are not installed either.
2013 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2014 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
2015 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
2016 @vindex PROGRAMS
2017 @vindex LIBRARIES
2018 @vindex LISP
2019 @vindex PYTHON
2020 @vindex JAVA
2021 @vindex SCRIPTS
2022 @vindex DATA
2023 @vindex HEADERS
2024 @vindex MANS
2025 @vindex TEXINFOS
2027 Some primaries also allow additional prefixes that control other
2028 aspects of @command{automake}'s behavior.  The currently defined prefixes
2029 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2030 These prefixes are explained later (@pxref{Program and Library Variables})
2031 (@pxref{Man Pages}).
2034 @node Length Limitations
2035 @section Staying below the command line length limit
2037 @cindex command line length limit
2038 @cindex ARG_MAX
2040 Traditionally, most unix-like systems have a length limitation for the
2041 command line arguments and environment contents when creating new
2042 processes (see for example
2043 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2044 overview on this issue),
2045 which of course also applies to commands spawned by @command{make}.
2046 POSIX requires this limit to be at least 4096 bytes, and most modern
2047 systems have quite high limits (or are unlimited).
2049 In order to create portable Makefiles that do not trip over these
2050 limits, it is necessary to keep the length of file lists bounded.
2051 Unfortunately, it is not possible to do so fully transparently within
2052 Automake, so your help may be needed.  Typically, you can split long
2053 file lists manually and use different installation directory names for
2054 each list.  For example,
2056 @example
2057 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2058 @end example
2060 @noindent
2061 may also be written as
2063 @example
2064 data_DATA = file1 @dots{} file@var{N}
2065 data2dir = $(datadir)
2066 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2067 @end example
2069 @noindent
2070 and will cause Automake to treat the two lists separately during
2071 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2072 directory names that will keep the ordering of the two parts of
2073 installation Note that @code{make dist} may still only work on a host
2074 with a higher length limit in this example.
2076 Automake itself employs a couple of strategies to avoid long command
2077 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2078 names, as can happen with above @code{$(data_DATA)} lists, it limits
2079 the amount of arguments passed to external commands.
2081 Unfortunately, some system's @command{make} commands may prepend
2082 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2083 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2084 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2085 may have to switch to use GNU Make, or refrain from using VPATH builds,
2086 in order to stay below the length limit.
2088 For libraries and programs built from many sources, convenience archives
2089 may be used as intermediates in order to limit the object list length
2090 (@pxref{Libtool Convenience Libraries}).
2093 @node Canonicalization
2094 @section How derived variables are named
2096 @cindex canonicalizing Automake variables
2098 Sometimes a Makefile variable name is derived from some text the
2099 maintainer supplies.  For instance, a program name listed in
2100 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2101 variable.  In cases like this, Automake canonicalizes the text, so that
2102 program names and the like do not have to follow Makefile variable naming
2103 rules.  All characters in the name except for letters, numbers, the
2104 strudel (@@), and the underscore are turned into underscores when making
2105 variable references.
2107 For example, if your program is named @file{sniff-glue}, the derived
2108 variable name would be @samp{sniff_glue_SOURCES}, not
2109 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2110 @file{libmumble++.a} should be listed in the
2111 @samp{libmumble___a_SOURCES} variable.
2113 The strudel is an addition, to make the use of Autoconf substitutions in
2114 variable names less obfuscating.
2117 @node User Variables
2118 @section Variables reserved for the user
2120 @cindex variables, reserved for the user
2121 @cindex user variables
2123 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2124 for the use of the ``user''---the person building the package.  For
2125 instance, @code{CFLAGS} is one such variable.
2127 Sometimes package developers are tempted to set user variables such as
2128 @code{CFLAGS} because it appears to make their job easier.  However,
2129 the package itself should never set a user variable, particularly not
2130 to include switches that are required for proper compilation of the
2131 package.  Since these variables are documented as being for the
2132 package builder, that person rightfully expects to be able to override
2133 any of these variables at build time.
2135 To get around this problem, Automake introduces an automake-specific
2136 shadow variable for each user flag variable.  (Shadow variables are
2137 not introduced for variables like @code{CC}, where they would make no
2138 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2139 user variable's name.  For instance, the shadow variable for
2140 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2141 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2142 files---may adjust these shadow variables however necessary.
2144 @xref{Flag Variables Ordering}, for more discussion about these
2145 variables and how they interact with per-target variables.
2147 @node Auxiliary Programs
2148 @section Programs automake might require
2150 @cindex Programs, auxiliary
2151 @cindex Auxiliary programs
2153 Automake sometimes requires helper programs so that the generated
2154 @file{Makefile} can do its work properly.  There are a fairly large
2155 number of them, and we list them here.
2157 Although all of these files are distributed and installed with
2158 Automake, a couple of them are maintained separately.  The Automake
2159 copies are updated before each release, but we mention the original
2160 source in case you need more recent versions.
2162 @table @code
2163 @item ansi2knr.c
2164 @itemx ansi2knr.1
2165 These two files are used for de-ANSI-fication support (obsolete
2166 @pxref{ANSI}).
2168 @item compile
2169 This is a wrapper for compilers that do not accept options @option{-c}
2170 and @option{-o} at the same time.  It is only used when absolutely
2171 required.  Such compilers are rare.
2173 @item config.guess
2174 @itemx config.sub
2175 These two programs compute the canonical triplets for the given build,
2176 host, or target architecture.  These programs are updated regularly to
2177 support new architectures and fix probes broken by changes in new
2178 kernel versions.  Each new release of Automake comes with up-to-date
2179 copies of these programs.  If your copy of Automake is getting old,
2180 you are encouraged to fetch the latest versions of these files from
2181 @url{http://savannah.gnu.org/git/?group=config} before making a
2182 release.
2184 @item config-ml.in
2185 This file is not a program, it is a @file{configure} fragment used for
2186 multilib support (@pxref{Multilibs}).  This file is maintained in the
2187 GCC tree at @url{http://gcc.gnu.org/svn.html}.
2189 @item depcomp
2190 This program understands how to run a compiler so that it will
2191 generate not only the desired output but also dependency information
2192 that is then used by the automatic dependency tracking feature
2193 (@pxref{Dependencies}).
2195 @item elisp-comp
2196 This program is used to byte-compile Emacs Lisp code.
2198 @item install-sh
2199 This is a replacement for the @command{install} program that works on
2200 platforms where @command{install} is unavailable or unusable.
2202 @item mdate-sh
2203 This script is used to generate a @file{version.texi} file.  It examines
2204 a file and prints some date information about it.
2206 @item missing
2207 This wraps a number of programs that are typically only required by
2208 maintainers.  If the program in question doesn't exist,
2209 @command{missing} prints an informative warning and attempts to fix
2210 things so that the build can continue.
2212 @item mkinstalldirs
2213 This script used to be a wrapper around @samp{mkdir -p}, which is not
2214 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2215 finds that @samp{mkdir -p} does not work, this makes one less script to
2216 distribute.
2218 For backward compatibility @file{mkinstalldirs} is still used and
2219 distributed when @command{automake} finds it in a package.  But it is no
2220 longer installed automatically, and it should be safe to remove it.
2222 @item py-compile
2223 This is used to byte-compile Python scripts.
2225 @item symlink-tree
2226 This program duplicates a tree of directories, using symbolic links
2227 instead of copying files.  Such an operation is performed when building
2228 multilibs (@pxref{Multilibs}).  This file is maintained in the GCC
2229 tree at @url{http://gcc.gnu.org/svn.html}.
2231 @item texinfo.tex
2232 Not a program, this file is required for @samp{make dvi}, @samp{make
2233 ps} and @samp{make pdf} to work when Texinfo sources are in the
2234 package.  The latest version can be downloaded from
2235 @url{http://www.gnu.org/software/texinfo/}.
2237 @item ylwrap
2238 This program wraps @command{lex} and @command{yacc} to rename their
2239 output files.  It also ensures that, for instance, multiple
2240 @command{yacc} instances can be invoked in a single directory in
2241 parallel.
2243 @end table
2246 @node Examples
2247 @chapter Some example packages
2249 This section contains two small examples.
2251 The first example (@pxref{Complete}) assumes you have an existing
2252 project already using Autoconf, with handcrafted @file{Makefile}s, and
2253 that you want to convert it to using Automake.  If you are discovering
2254 both tools, it is probably better that you look at the Hello World
2255 example presented earlier (@pxref{Hello World}).
2257 The second example (@pxref{true}) shows how two programs can be built
2258 from the same file, using different compilation parameters.  It
2259 contains some technical digressions that are probably best skipped on
2260 first read.
2262 @menu
2263 * Complete::                    A simple example, start to finish
2264 * true::                        Building true and false
2265 @end menu
2268 @node Complete
2269 @section A simple example, start to finish
2271 @cindex Complete example
2273 Let's suppose you just finished writing @code{zardoz}, a program to make
2274 your head float from vortex to vortex.  You've been using Autoconf to
2275 provide a portability framework, but your @file{Makefile.in}s have been
2276 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2278 @cindex @code{AM_INIT_AUTOMAKE}, example use
2280 The first step is to update your @file{configure.ac} to include the
2281 commands that @command{automake} needs.  The way to do this is to add an
2282 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2284 @example
2285 AC_INIT([zardoz], [1.0])
2286 AM_INIT_AUTOMAKE
2287 @dots{}
2288 @end example
2290 Since your program doesn't have any complicating factors (e.g., it
2291 doesn't use @code{gettext}, it doesn't want to build a shared library),
2292 you're done with this part.  That was easy!
2294 @cindex @command{aclocal} program, introduction
2295 @cindex @file{aclocal.m4}, preexisting
2296 @cindex @file{acinclude.m4}, defined
2298 Now you must regenerate @file{configure}.  But to do that, you'll need
2299 to tell @command{autoconf} how to find the new macro you've used.  The
2300 easiest way to do this is to use the @command{aclocal} program to
2301 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2302 already have an @file{aclocal.m4}, because you had to write some hairy
2303 macros for your program.  The @command{aclocal} program lets you put
2304 your own macros into @file{acinclude.m4}, so simply rename and then
2305 run:
2307 @example
2308 mv aclocal.m4 acinclude.m4
2309 aclocal
2310 autoconf
2311 @end example
2313 @cindex @command{zardoz} example
2315 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2316 Since @code{zardoz} is a user program, you want to install it where the
2317 rest of the user programs go: @code{bindir}.  Additionally,
2318 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2319 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2320 @samp{$(LIBOBJS)}.  So here's what you'd write:
2322 @example
2323 bin_PROGRAMS = zardoz
2324 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2325 zardoz_LDADD = $(LIBOBJS)
2327 info_TEXINFOS = zardoz.texi
2328 @end example
2330 Now you can run @samp{automake --add-missing} to generate your
2331 @file{Makefile.in} and grab any auxiliary files you might need, and
2332 you're done!
2335 @node true
2336 @section Building true and false
2338 @cindex Example, @command{false} and @command{true}
2339 @cindex @command{false} Example
2340 @cindex @command{true} Example
2342 Here is another, trickier example.  It shows how to generate two
2343 programs (@code{true} and @code{false}) from the same source file
2344 (@file{true.c}).  The difficult part is that each compilation of
2345 @file{true.c} requires different @code{cpp} flags.
2347 @example
2348 bin_PROGRAMS = true false
2349 false_SOURCES =
2350 false_LDADD = false.o
2352 true.o: true.c
2353         $(COMPILE) -DEXIT_CODE=0 -c true.c
2355 false.o: true.c
2356         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2357 @end example
2359 Note that there is no @code{true_SOURCES} definition.  Automake will
2360 implicitly assume that there is a source file named @file{true.c}
2361 (@pxref{Default _SOURCES}), and
2362 define rules to compile @file{true.o} and link @file{true}.  The
2363 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2364 will override the Automake generated rule to build @file{true.o}.
2366 @code{false_SOURCES} is defined to be empty---that way no implicit value
2367 is substituted.  Because we have not listed the source of
2368 @file{false}, we have to tell Automake how to link the program.  This is
2369 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2370 variable, holding the dependencies of the @file{false} target will be
2371 automatically generated by Automake from the content of
2372 @code{false_LDADD}.
2374 The above rules won't work if your compiler doesn't accept both
2375 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2376 bogus dependency (to avoid problems with a parallel @command{make}):
2378 @example
2379 true.o: true.c false.o
2380         $(COMPILE) -DEXIT_CODE=0 -c true.c
2382 false.o: true.c
2383         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2384 @end example
2386 Also, these explicit rules do not work if the obsolete de-ANSI-fication feature
2387 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
2388 more work:
2390 @example
2391 true_.o: true_.c false_.o
2392         $(COMPILE) -DEXIT_CODE=0 -c true_.c
2394 false_.o: true_.c
2395         $(COMPILE) -DEXIT_CODE=1 -c true_.c && mv true_.o false_.o
2396 @end example
2398 As it turns out, there is also a much easier way to do this same task.
2399 Some of the above techniques are useful enough that we've kept the
2400 example in the manual.  However if you were to build @code{true} and
2401 @code{false} in real life, you would probably use per-program
2402 compilation flags, like so:
2404 @example
2405 bin_PROGRAMS = false true
2407 false_SOURCES = true.c
2408 false_CPPFLAGS = -DEXIT_CODE=1
2410 true_SOURCES = true.c
2411 true_CPPFLAGS = -DEXIT_CODE=0
2412 @end example
2414 In this case Automake will cause @file{true.c} to be compiled twice,
2415 with different flags.  De-ANSI-fication will work automatically.  In
2416 this instance, the names of the object files would be chosen by
2417 automake; they would be @file{false-true.o} and @file{true-true.o}.
2418 (The name of the object files rarely matters.)
2421 @node Invoking Automake
2422 @chapter Creating a @file{Makefile.in}
2424 @cindex Multiple @file{configure.ac} files
2425 @cindex Invoking @command{automake}
2426 @cindex @command{automake}, invoking
2428 To create all the @file{Makefile.in}s for a package, run the
2429 @command{automake} program in the top level directory, with no
2430 arguments.  @command{automake} will automatically find each
2431 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2432 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2433 Note that @command{automake} has a rather simplistic view of what
2434 constitutes a package; it assumes that a package has only one
2435 @file{configure.ac}, at the top.  If your package has multiple
2436 @file{configure.ac}s, then you must run @command{automake} in each
2437 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2438 on Autoconf's @command{autoreconf}, which is able to recurse your
2439 package tree and run @command{automake} where appropriate.)
2441 You can optionally give @command{automake} an argument; @file{.am} is
2442 appended to the argument and the result is used as the name of the
2443 input file.  This feature is generally only used to automatically
2444 rebuild an out-of-date @file{Makefile.in}.  Note that
2445 @command{automake} must always be run from the topmost directory of a
2446 project, even if being used to regenerate the @file{Makefile.in} in
2447 some subdirectory.  This is necessary because @command{automake} must
2448 scan @file{configure.ac}, and because @command{automake} uses the
2449 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2450 behavior in some cases.
2452 @vindex AUTOCONF
2453 Automake will run @command{autoconf} to scan @file{configure.ac} and
2454 its dependencies (i.e., @file{aclocal.m4} and any included file),
2455 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2456 an @env{AUTOCONF} variable in your environment it will be used
2457 instead of @command{autoconf}, this allows you to select a particular
2458 version of Autoconf.  By the way, don't misunderstand this paragraph:
2459 @command{automake} runs @command{autoconf} to @strong{scan} your
2460 @file{configure.ac}, this won't build @file{configure} and you still
2461 have to run @command{autoconf} yourself for this purpose.
2463 @cindex @command{automake} options
2464 @cindex Options, @command{automake}
2465 @cindex Strictness, command line
2467 @command{automake} accepts the following options:
2469 @cindex Extra files distributed with Automake
2470 @cindex Files distributed with Automake
2471 @cindex @file{config.guess}
2473 @table @code
2474 @item -a
2475 @itemx --add-missing
2476 @opindex -a
2477 @opindex --add-missing
2478 Automake requires certain common files to exist in certain situations;
2479 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2480 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2481 files (@pxref{Auxiliary Programs}); this option will cause the missing
2482 ones to be automatically added to the package, whenever possible.  In
2483 general if Automake tells you a file is missing, try using this option.
2484 By default Automake tries to make a symbolic link pointing to its own
2485 copy of the missing file; this can be changed with @option{--copy}.
2487 Many of the potentially-missing files are common scripts whose
2488 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2489 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2490 file is considered missing, and where the missing file is added
2491 (@pxref{Optional}).
2493 In some strictness modes, additional files are installed, see @ref{Gnits}
2494 for more information.
2496 @item --libdir=@var{dir}
2497 @opindex --libdir
2498 Look for Automake data files in directory @var{dir} instead of in the
2499 installation directory.  This is typically used for debugging.
2501 @item -c
2502 @opindex -c
2503 @itemx --copy
2504 @opindex --copy
2505 When used with @option{--add-missing}, causes installed files to be
2506 copied.  The default is to make a symbolic link.
2508 @item --cygnus
2509 @opindex --cygnus
2510 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2511 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2513 @item -f
2514 @opindex -f
2515 @itemx --force-missing
2516 @opindex --force-missing
2517 When used with @option{--add-missing}, causes standard files to be reinstalled
2518 even if they already exist in the source tree.  This involves removing
2519 the file from the source tree before creating the new symlink (or, with
2520 @option{--copy}, copying the new file).
2522 @item --foreign
2523 @opindex --foreign
2524 Set the global strictness to @option{foreign}.  For more information, see
2525 @ref{Strictness}.
2527 @item --gnits
2528 @opindex --gnits
2529 Set the global strictness to @option{gnits}.  For more information, see
2530 @ref{Gnits}.
2532 @item --gnu
2533 @opindex --gnu
2534 Set the global strictness to @option{gnu}.  For more information, see
2535 @ref{Gnits}.  This is the default strictness.
2537 @item --help
2538 @opindex --help
2539 Print a summary of the command line options and exit.
2541 @item -i
2542 @itemx --ignore-deps
2543 @opindex -i
2544 This disables the dependency tracking feature in generated
2545 @file{Makefile}s; see @ref{Dependencies}.
2547 @item --include-deps
2548 @opindex --include-deps
2549 This enables the dependency tracking feature.  This feature is enabled
2550 by default.  This option is provided for historical reasons only and
2551 probably should not be used.
2553 @item --no-force
2554 @opindex --no-force
2555 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2556 @file{configure.ac}.  This option causes it to only update those
2557 @file{Makefile.in}s that are out of date with respect to one of their
2558 dependents.
2560 @item -o @var{dir}
2561 @itemx --output-dir=@var{dir}
2562 @opindex -o
2563 @opindex --output-dir
2564 Put the generated @file{Makefile.in} in the directory @var{dir}.
2565 Ordinarily each @file{Makefile.in} is created in the directory of the
2566 corresponding @file{Makefile.am}.  This option is deprecated and will be
2567 removed in a future release.
2569 @item -v
2570 @itemx --verbose
2571 @opindex -v
2572 @opindex --verbose
2573 Cause Automake to print information about which files are being read or
2574 created.
2576 @item --version
2577 @opindex --version
2578 Print the version number of Automake and exit.
2580 @item -W CATEGORY
2581 @itemx --warnings=@var{category}
2582 @opindex -W
2583 @opindex --warnings
2584 Output warnings falling in @var{category}.  @var{category} can be
2585 one of:
2586 @table @code
2587 @item gnu
2588 warnings related to the GNU Coding Standards
2589 (@pxref{Top, , , standards, The GNU Coding Standards}).
2590 @item obsolete
2591 obsolete features or constructions
2592 @item override
2593 user redefinitions of Automake rules or variables
2594 @item portability
2595 portability issues (e.g., use of @command{make} features that are
2596 known to be not portable)
2597 @item syntax
2598 weird syntax, unused variables, typos
2599 @item unsupported
2600 unsupported or incomplete features
2601 @item all
2602 all the warnings
2603 @item none
2604 turn off all the warnings
2605 @item error
2606 treat warnings as errors
2607 @end table
2609 A category can be turned off by prefixing its name with @samp{no-}.  For
2610 instance, @option{-Wno-syntax} will hide the warnings about unused
2611 variables.
2613 The categories output by default are @samp{syntax} and
2614 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2615 are enabled in @option{--gnu} and @option{--gnits} strictness.
2616 On the other hand, the @option{silent-rules} options (@pxref{Options})
2617 turns off portability warnings about recursive variable expansions.
2619 @vindex WARNINGS
2620 The environment variable @env{WARNINGS} can contain a comma separated
2621 list of categories to enable.  It will be taken into account before the
2622 command-line switches, this way @option{-Wnone} will also ignore any
2623 warning category enabled by @env{WARNINGS}.  This variable is also used
2624 by other tools like @command{autoconf}; unknown categories are ignored
2625 for this reason.
2627 @end table
2629 @vindex AUTOMAKE_JOBS
2630 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2631 number, it is taken as the maximum number of Perl threads to use in
2632 @command{automake} for generating multiple @file{Makefile.in} files
2633 concurrently.  This is an experimental feature.
2636 @node configure
2637 @chapter Scanning @file{configure.ac}
2639 @cindex @file{configure.ac}, scanning
2640 @cindex Scanning @file{configure.ac}
2642 Automake scans the package's @file{configure.ac} to determine certain
2643 information about the package.  Some @command{autoconf} macros are required
2644 and some variables must be defined in @file{configure.ac}.  Automake
2645 will also use information from @file{configure.ac} to further tailor its
2646 output.
2648 Automake also supplies some Autoconf macros to make the maintenance
2649 easier.  These macros can automatically be put into your
2650 @file{aclocal.m4} using the @command{aclocal} program.
2652 @menu
2653 * Requirements::                Configuration requirements
2654 * Optional::                    Other things Automake recognizes
2655 * Invoking aclocal::            Auto-generating aclocal.m4
2656 * Macros::                      Autoconf macros supplied with Automake
2657 @end menu
2660 @node Requirements
2661 @section Configuration requirements
2663 @cindex Automake requirements
2664 @cindex Requirements of Automake
2666 @acindex AM_INIT_AUTOMAKE
2667 The one real requirement of Automake is that your @file{configure.ac}
2668 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2669 required for proper Automake operation (@pxref{Macros}).
2671 Here are the other macros that Automake requires but which are not run
2672 by @code{AM_INIT_AUTOMAKE}:
2674 @table @code
2675 @item AC_CONFIG_FILES
2676 @itemx AC_OUTPUT
2677 @acindex AC_CONFIG_FILES
2678 @acindex AC_OUTPUT
2679 These two macros are usually invoked as follows near the end of
2680 @file{configure.ac}.
2682 @example
2683 @dots{}
2684 AC_CONFIG_FILES([
2685   Makefile
2686   doc/Makefile
2687   src/Makefile
2688   src/lib/Makefile
2689   @dots{}
2691 AC_OUTPUT
2692 @end example
2694 Automake uses these to determine which files to create (@pxref{Output, ,
2695 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2696 is considered to be an Automake generated @file{Makefile} if there
2697 exists a file with the same name and the @file{.am} extension appended.
2698 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2699 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2701 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2703 @example
2704 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2705 @end example
2707 @noindent
2708 @command{automake} will generate the first @file{.in} input file for
2709 which a @file{.am} file exists.  If no such file exists the output
2710 file is not considered to be generated by Automake.
2712 Files created by @code{AC_CONFIG_FILES}, be they Automake
2713 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2714 Their inputs are automatically distributed, unless they
2715 are the output of prior @code{AC_CONFIG_FILES} commands.
2716 Finally, rebuild rules are generated in the Automake @file{Makefile}
2717 existing in the subdirectory of the output file, if there is one, or
2718 in the top-level @file{Makefile} otherwise.
2720 The above machinery (cleaning, distributing, and rebuilding) works
2721 fine if the @code{AC_CONFIG_FILES} specifications contain only
2722 literals.  If part of the specification uses shell variables,
2723 @command{automake} will not be able to fulfill this setup, and you will
2724 have to complete the missing bits by hand.  For instance, on
2726 @example
2727 file=input
2728 @dots{}
2729 AC_CONFIG_FILES([output:$file],, [file=$file])
2730 @end example
2732 @noindent
2733 @command{automake} will output rules to clean @file{output}, and
2734 rebuild it.  However the rebuild rule will not depend on @file{input},
2735 and this file will not be distributed either.  (You must add
2736 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2737 source file.)
2739 Similarly
2741 @example
2742 file=output
2743 file2=out:in
2744 @dots{}
2745 AC_CONFIG_FILES([$file:input],, [file=$file])
2746 AC_CONFIG_FILES([$file2],, [file2=$file2])
2747 @end example
2749 @noindent
2750 will only cause @file{input} to be distributed.  No file will be
2751 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2752 yourself), and no rebuild rule will be output.
2754 Obviously @command{automake} cannot guess what value @samp{$file} is
2755 going to hold later when @file{configure} is run, and it cannot use
2756 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2757 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2758 that is compatible with @command{make}'s syntax) and furthermore use
2759 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2760 @file{Makefile}, then @command{automake} will be able to use
2761 @samp{$@{file@}} to generate all these rules.  For instance, here is
2762 how the Automake package itself generates versioned scripts for its
2763 test suite:
2765 @example
2766 AC_SUBST([APIVERSION], @dots{})
2767 @dots{}
2768 AC_CONFIG_FILES(
2769   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2770   [chmod +x tests/aclocal-$@{APIVERSION@}],
2771   [APIVERSION=$APIVERSION])
2772 AC_CONFIG_FILES(
2773   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2774   [chmod +x tests/automake-$@{APIVERSION@}])
2775 @end example
2777 @noindent
2778 Here cleaning, distributing, and rebuilding are done automatically,
2779 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2781 Note that you should not use shell variables to declare
2782 @file{Makefile} files for which @command{automake} must create
2783 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2784 @command{automake} needs to know the file name when it runs in order
2785 to check whether @file{Makefile.am} exists.  (In the very hairy case
2786 that your setup requires such use of variables, you will have to tell
2787 Automake which @file{Makefile.in}s to generate on the command-line.)
2789 It is possible to let @command{automake} emit conditional rules for
2790 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2791 (@pxref{Optional}).
2793 To summarize:
2794 @itemize @bullet
2795 @item
2796 Use literals for @file{Makefile}s, and for other files whenever possible.
2797 @item
2798 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2799 for files that @command{automake} should ignore.
2800 @item
2801 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2802 that @command{automake} should not ignore.
2803 @end itemize
2805 @end table
2808 @node Optional
2809 @section Other things Automake recognizes
2811 @cindex Macros Automake recognizes
2812 @cindex Recognized macros by Automake
2814 Every time Automake is run it calls Autoconf to trace
2815 @file{configure.ac}.  This way it can recognize the use of certain
2816 macros and tailor the generated @file{Makefile.in} appropriately.
2817 Currently recognized macros and their effects are:
2819 @ftable @code
2820 @item AC_CANONICAL_BUILD
2821 @itemx AC_CANONICAL_HOST
2822 @itemx AC_CANONICAL_TARGET
2823 @vindex build_triplet
2824 @vindex host_triplet
2825 @vindex target_triplet
2826 Automake will ensure that @file{config.guess} and @file{config.sub}
2827 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2828 @code{host_triplet} and @code{target_triplet} are introduced.  See
2829 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2830 The Autoconf Manual}.
2832 @item AC_CONFIG_AUX_DIR
2833 Automake will look for various helper scripts, such as
2834 @file{install-sh}, in the directory named in this macro invocation.
2835 @c This list is accurate relative to version 1.8
2836 (The full list of scripts is: @file{config.guess}, @file{config.sub},
2837 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
2838 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
2839 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
2840 scripts are always searched for; some scripts will only be sought if the
2841 generated @file{Makefile.in} requires them.
2843 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2844 their standard locations.  For @file{mdate-sh},
2845 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2846 source directory corresponding to the current @file{Makefile.am}.  For
2847 the rest, the standard location is the first one of @file{.}, @file{..},
2848 or @file{../..} (relative to the top source directory) that provides any
2849 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2850 autoconf, The Autoconf Manual}.
2852 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2853 distributed, even if there is no @file{Makefile.am} in this directory.
2855 @item AC_CONFIG_LIBOBJ_DIR
2856 Automake will require the sources file declared with
2857 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2858 macro.
2860 @item AC_CONFIG_HEADERS
2861 Automake will generate rules to rebuild these headers.  Older versions
2862 of Automake required the use of @code{AM_CONFIG_HEADER}
2863 (@pxref{Macros}); this is no longer the case.
2865 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2866 specification using shell variables will be ignored as far as
2867 cleaning, distributing, and rebuilding is concerned.
2869 @item AC_CONFIG_LINKS
2870 Automake will generate rules to remove @file{configure} generated
2871 links on @samp{make distclean} and to distribute named source files as
2872 part of @samp{make dist}.
2874 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2875 specification using shell variables will be ignored as far as cleaning
2876 and distributing is concerned.  (There are no rebuild rules for links.)
2878 @item AC_LIBOBJ
2879 @itemx AC_LIBSOURCE
2880 @itemx AC_LIBSOURCES
2881 @vindex LIBOBJS
2882 Automake will automatically distribute any file listed in
2883 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2885 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2886 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2887 @file{file.c} will be distributed automatically by Automake.  This
2888 encompasses many macros like @code{AC_FUNC_ALLOCA},
2889 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2891 By the way, direct assignments to @code{LIBOBJS} are no longer
2892 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2893 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2894 autoconf, The Autoconf Manual}.
2896 @item AC_PROG_RANLIB
2897 This is required if any libraries are built in the package.
2898 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2899 Autoconf Manual}.
2901 @item AC_PROG_CXX
2902 This is required if any C++ source is included.  @xref{Particular
2903 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2905 @item AC_PROG_OBJC
2906 This is required if any Objective C source is included.  @xref{Particular
2907 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2909 @item AC_PROG_F77
2910 This is required if any Fortran 77 source is included.  This macro is
2911 distributed with Autoconf version 2.13 and later.  @xref{Particular
2912 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2914 @item AC_F77_LIBRARY_LDFLAGS
2915 This is required for programs and shared libraries that are a mixture of
2916 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
2917 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
2919 @item AC_FC_SRCEXT
2920 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
2921 of files with the respective source extension (@pxref{Fortran Compiler, ,
2922 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
2924 @item AC_PROG_FC
2925 This is required if any Fortran 90/95 source is included.  This macro is
2926 distributed with Autoconf version 2.58 and later.  @xref{Particular
2927 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2929 @item AC_PROG_LIBTOOL
2930 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
2931 Introduction, libtool, The Libtool Manual}).
2933 @item AC_PROG_YACC
2934 @vindex YACC
2935 If a Yacc source file is seen, then you must either use this macro or
2936 define the variable @code{YACC} in @file{configure.ac}.  The former is
2937 preferred (@pxref{Particular Programs, , Particular Program Checks,
2938 autoconf, The Autoconf Manual}).
2940 @item AC_PROG_LEX
2941 If a Lex source file is seen, then this macro must be used.
2942 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2943 Autoconf Manual}.
2945 @item AC_REQUIRE_AUX_FILE
2946 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
2947 @command{automake} will ensure that @file{@var{file}} exists in the
2948 aux directory, and will complain otherwise.  It
2949 will also automatically distribute the file.  This macro should be
2950 used by third-party Autoconf macros that require some supporting
2951 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
2952 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
2953 The Autoconf Manual}.
2955 @item AC_SUBST
2956 The first argument is automatically defined as a variable in each
2957 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
2958 used for this variable.  @xref{Setting Output Variables, , Setting
2959 Output Variables, autoconf, The Autoconf Manual}.
2961 For every substituted variable @var{var}, @command{automake} will add
2962 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
2963 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
2964 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
2965 @code{X_LIBS}.  Thus, you can access these variables as
2966 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
2967 if @code{AC_PATH_XTRA} is called.
2969 @item AM_C_PROTOTYPES
2970 This is required when using the obsolete de-ANSI-fication feature; see
2971 @ref{ANSI}.
2973 @item AM_CONDITIONAL
2974 This introduces an Automake conditional (@pxref{Conditionals}).
2976 @item AM_COND_IF
2977 This macro allows @code{automake} to detect subsequent access within
2978 @file{configure.ac} to a conditional previously introduced with
2979 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
2980 (@pxref{Usage of Conditionals}).
2982 @item AM_GNU_GETTEXT
2983 This macro is required for packages that use GNU gettext
2984 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
2985 this macro it ensures that the package meets some of gettext's
2986 requirements.
2988 @item AM_GNU_GETTEXT_INTL_SUBDIR
2989 This macro specifies that the @file{intl/} subdirectory is to be built,
2990 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
2991 of @samp{external}.
2993 @item AM_MAINTAINER_MODE(@ovar{default-mode})
2994 @opindex --enable-maintainer-mode
2995 @opindex --disable-maintainer-mode
2996 This macro adds an @option{--enable-maintainer-mode} option to
2997 @command{configure}.  If this is used, @command{automake} will cause
2998 ``maintainer-only'' rules to be turned off by default in the
2999 generated @file{Makefile.in}s, unless @var{default-mode} is
3000 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3001 conditional, which you can use in your own @file{Makefile.am}.
3002 @xref{maintainer-mode}.
3004 @item AM_SUBST_NOTMAKE(@var{var})
3005 Prevent Automake from defining a variable @var{var}, even if it is
3006 substituted by @command{config.status}.  Normally, Automake defines a
3007 @command{make} variable for each @command{configure} substitution,
3008 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3009 definition from Automake.  If @code{AC_SUBST} has not been called
3010 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3011 Preventing variable definitions may be useful for substitution of
3012 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3013 unintended results.
3015 @item m4_include
3016 Files included by @file{configure.ac} using this macro will be
3017 detected by Automake and automatically distributed.  They will also
3018 appear as dependencies in @file{Makefile} rules.
3020 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3021 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3022 some required macros come from files local to your package (as opposed
3023 to macros installed in a system-wide directory, @pxref{Invoking
3024 aclocal}).
3026 @end ftable
3029 @node Invoking aclocal
3030 @section Auto-generating aclocal.m4
3032 @cindex Invoking @command{aclocal}
3033 @cindex @command{aclocal}, Invoking
3035 Automake includes a number of Autoconf macros that can be used in
3036 your package (@pxref{Macros}); some of them are actually required by
3037 Automake in certain situations.  These macros must be defined in your
3038 @file{aclocal.m4}; otherwise they will not be seen by
3039 @command{autoconf}.
3041 The @command{aclocal} program will automatically generate
3042 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3043 This provides a convenient way to get Automake-provided macros,
3044 without having to search around.  The @command{aclocal} mechanism
3045 allows other packages to supply their own macros (@pxref{Extending
3046 aclocal}).  You can also use it to maintain your own set of custom
3047 macros (@pxref{Local Macros}).
3049 At startup, @command{aclocal} scans all the @file{.m4} files it can
3050 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3051 it scans @file{configure.ac}.  Any mention of one of the macros found
3052 in the first step causes that macro, and any macros it in turn
3053 requires, to be put into @file{aclocal.m4}.
3055 @emph{Putting} the file that contains the macro definition into
3056 @file{aclocal.m4} is usually done by copying the entire text of this
3057 file, including unused macro definitions as well as both @samp{#} and
3058 @samp{dnl} comments.  If you want to make a comment that will be
3059 completely ignored by @command{aclocal}, use @samp{##} as the comment
3060 leader.
3062 When a file selected by @command{aclocal} is located in a subdirectory
3063 specified as a relative search path with @command{aclocal}'s @option{-I}
3064 argument, @command{aclocal} assumes the file belongs to the package
3065 and uses @code{m4_include} instead of copying it into
3066 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3067 tracking, and cause the file to be distributed automatically.
3068 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3069 system-wide directory, or via an absolute search path will be copied.
3070 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3071 some relative directory should be considered outside the package.
3073 The contents of @file{acinclude.m4}, if this file exists, are also
3074 automatically included in @file{aclocal.m4}.  We recommend against
3075 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3077 @vindex AUTOM4TE
3078 @cindex autom4te
3079 While computing @file{aclocal.m4}, @command{aclocal} runs
3080 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3081 autoconf, The Autoconf Manual}) in order to trace the macros that are
3082 really used, and omit from @file{aclocal.m4} all macros that are
3083 mentioned but otherwise unexpanded (this can happen when a macro is
3084 called conditionally).  @command{autom4te} is expected to be in the
3085 @env{PATH}, just as @command{autoconf}.  Its location can be
3086 overridden using the @env{AUTOM4TE} environment variable.
3088 @menu
3089 * aclocal Options::             Options supported by aclocal
3090 * Macro Search Path::           How aclocal finds .m4 files
3091 * Extending aclocal::           Writing your own aclocal macros
3092 * Local Macros::                Organizing local macros
3093 * Serials::                     Serial lines in Autoconf macros
3094 * Future of aclocal::           aclocal's scheduled death
3095 @end menu
3097 @node aclocal Options
3098 @subsection aclocal Options
3100 @cindex @command{aclocal}, Options
3101 @cindex Options, @command{aclocal}
3103 @command{aclocal} accepts the following options:
3105 @table @code
3106 @item --acdir=@var{dir}
3107 @opindex --acdir
3108 Look for the macro files in @var{dir} instead of the installation
3109 directory.  This is typically used for debugging.
3111 @item --diff[=@var{command}]
3112 @opindex --diff
3113 Run @var{command} on M4 file that would be installed or overwritten
3114 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3115 This option implies @option{--install} and @option{--dry-run}.
3117 @item --dry-run
3118 @opindex --dry-run
3119 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3120 files installed by @option{--install}.
3122 @item --help
3123 @opindex --help
3124 Print a summary of the command line options and exit.
3126 @item -I @var{dir}
3127 @opindex -I
3128 Add the directory @var{dir} to the list of directories searched for
3129 @file{.m4} files.
3131 @item --install
3132 @opindex --install
3133 Install system-wide third-party macros into the first directory
3134 specified with @samp{-I @var{dir}} instead of copying them in the
3135 output file.
3137 @cindex serial number and @option{--install}
3138 When this option is used, and only when this option is used,
3139 @command{aclocal} will also honor @samp{#serial @var{NUMBER}} lines
3140 that appear in macros: an M4 file is ignored if there exists another
3141 M4 file with the same basename and a greater serial number in the
3142 search path (@pxref{Serials}).
3144 @item --force
3145 @opindex --force
3146 Always overwrite the output file.  The default is to overwrite the output
3147 file only when really needed, i.e., when its contents changes or if one
3148 of its dependencies is younger.
3150 This option forces the update of @file{aclocal.m4} (or the file
3151 specified with @file{--output} below) and only this file, it has
3152 absolutely no influence on files that may need to be installed by
3153 @option{--install}.
3155 @item --output=@var{file}
3156 @opindex --output
3157 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3159 @item --print-ac-dir
3160 @opindex --print-ac-dir
3161 Prints the name of the directory that @command{aclocal} will search to
3162 find third-party @file{.m4} files.  When this option is given, normal
3163 processing is suppressed.  This option can be used by a package to
3164 determine where to install a macro file.
3166 @item --verbose
3167 @opindex --verbose
3168 Print the names of the files it examines.
3170 @item --version
3171 @opindex --version
3172 Print the version number of Automake and exit.
3174 @item -W CATEGORY
3175 @item --warnings=@var{category}
3176 @opindex -W
3177 @opindex --warnings
3178 Output warnings falling in @var{category}.  @var{category} can be
3179 one of:
3180 @table @code
3181 @item syntax
3182 dubious syntactic constructs, underquoted macros, unused macros, etc.
3183 @item unsupported
3184 unknown macros
3185 @item all
3186 all the warnings, this is the default
3187 @item none
3188 turn off all the warnings
3189 @item error
3190 treat warnings as errors
3191 @end table
3193 All warnings are output by default.
3195 @vindex WARNINGS
3196 The environment variable @env{WARNINGS} is honored in the same
3197 way as it is for @command{automake} (@pxref{Invoking Automake}).
3199 @end table
3201 @node Macro Search Path
3202 @subsection Macro Search Path
3204 @cindex Macro search path
3205 @cindex @command{aclocal} search path
3207 By default, @command{aclocal} searches for @file{.m4} files in the following
3208 directories, in this order:
3210 @table @code
3211 @item @var{acdir-APIVERSION}
3212 This is where the @file{.m4} macros distributed with Automake itself
3213 are stored.  @var{APIVERSION} depends on the Automake release used;
3214 for Automake 1.6.x, @var{APIVERSION} = @code{1.6}.
3216 @item @var{acdir}
3217 This directory is intended for third party @file{.m4} files, and is
3218 configured when @command{automake} itself is built.  This is
3219 @file{@@datadir@@/aclocal/}, which typically
3220 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3221 value of @var{acdir}, use the @option{--print-ac-dir} option
3222 (@pxref{aclocal Options}).
3223 @end table
3225 As an example, suppose that @command{automake-1.6.2} was configured with
3226 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3228 @enumerate
3229 @item @file{/usr/local/share/aclocal-1.6/}
3230 @item @file{/usr/local/share/aclocal/}
3231 @end enumerate
3233 As explained in (@pxref{aclocal Options}), there are several options that
3234 can be used to change or extend this search path.
3236 @subsubheading Modifying the Macro Search Path: @option{--acdir}
3238 The most erroneous option to modify the search path is
3239 @option{--acdir=@var{dir}}, which changes default directory and
3240 drops the @var{APIVERSION} directory.  For example, if one specifies
3241 @samp{--acdir=/opt/private/}, then the search path becomes:
3243 @enumerate
3244 @item @file{/opt/private/}
3245 @end enumerate
3247 This option, @option{--acdir}, is intended for use by the internal
3248 Automake test suite only; it is not ordinarily needed by end-users.
3250 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3252 Any extra directories specified using @option{-I} options
3253 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3254 @samp{aclocal -I /foo -I /bar} results in the following search path:
3256 @enumerate
3257 @item @file{/foo}
3258 @item @file{/bar}
3259 @item @var{acdir}-@var{APIVERSION}
3260 @item @var{acdir}
3261 @end enumerate
3263 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3264 @cindex @file{dirlist}
3266 There is a third mechanism for customizing the search path.  If a
3267 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3268 contain a list of directory patterns, one per line.  @command{aclocal}
3269 expands these patterns to directory names, and adds them to the search
3270 list @emph{after} all other directories.  @file{dirlist} entries may
3271 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3273 For example, suppose
3274 @file{@var{acdir}/dirlist} contains the following:
3276 @example
3277 /test1
3278 /test2
3279 /test3*
3280 @end example
3282 @noindent
3283 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3284 Then, the search path would be
3286 @c @code looks better than @file here
3287 @enumerate
3288 @item @code{/foo}
3289 @item @code{/bar}
3290 @item @var{acdir}-@var{APIVERSION}
3291 @item @var{acdir}
3292 @item @code{/test1}
3293 @item @code{/test2}
3294 @end enumerate
3296 @noindent
3297 and all directories with path names starting with @code{/test3}.
3299 If the @option{--acdir=@var{dir}} option is used, then @command{aclocal}
3300 will search for the @file{dirlist} file in @var{dir}.  In the
3301 @samp{--acdir=/opt/private/} example above, @command{aclocal} would look
3302 for @file{/opt/private/dirlist}.  Again, however, the @option{--acdir}
3303 option is intended for use by the internal Automake test suite only;
3304 @option{--acdir} is not ordinarily needed by end-users.
3306 @file{dirlist} is useful in the following situation: suppose that
3307 @command{automake} version @code{1.6.2} is installed with
3308 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3309 directories are
3311 @c @code looks better than @file here
3312 @enumerate
3313 @item @code{/usr/share/aclocal-1.6/}
3314 @item @code{/usr/share/aclocal/}
3315 @end enumerate
3317 However, suppose further that many packages have been manually
3318 installed on the system, with $prefix=/usr/local, as is typical.  In
3319 that case, many of these ``extra'' @file{.m4} files are in
3320 @file{/usr/local/share/aclocal}.  The only way to force
3321 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3322 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3323 inconvenient.  With @file{dirlist}, one may create a file
3324 @file{/usr/share/aclocal/dirlist} containing only the single line
3326 @example
3327 /usr/local/share/aclocal
3328 @end example
3330 Now, the ``default'' search path on the affected system is
3332 @c @code looks better than @file here
3333 @enumerate
3334 @item @code{/usr/share/aclocal-1.6/}
3335 @item @code{/usr/share/aclocal/}
3336 @item @code{/usr/local/share/aclocal/}
3337 @end enumerate
3339 without the need for @option{-I} options; @option{-I} options can be reserved
3340 for project-specific needs (@file{my-source-dir/m4/}), rather than
3341 using it to work around local system-dependent tool installation
3342 directories.
3344 Similarly, @file{dirlist} can be handy if you have installed a local
3345 copy of Automake in your account and want @command{aclocal} to look for
3346 macros installed at other places on the system.
3349 @node Extending aclocal
3350 @subsection Writing your own aclocal macros
3352 @cindex @command{aclocal}, extending
3353 @cindex Extending @command{aclocal}
3355 The @command{aclocal} program doesn't have any built-in knowledge of any
3356 macros, so it is easy to extend it with your own macros.
3358 This can be used by libraries that want to supply their own Autoconf
3359 macros for use by other programs.  For instance, the @command{gettext}
3360 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3361 any package using @command{gettext}.  When the library is installed, it
3362 installs this macro so that @command{aclocal} will find it.
3364 A macro file's name should end in @file{.m4}.  Such files should be
3365 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3367 @example
3368 aclocaldir = $(datadir)/aclocal
3369 aclocal_DATA = mymacro.m4 myothermacro.m4
3370 @end example
3372 @noindent
3373 Please do use @file{$(datadir)/aclocal}, and not something based on
3374 the result of @samp{aclocal --print-ac-dir}.  @xref{Hard-Coded Install
3375 Paths}, for arguments.
3377 A file of macros should be a series of properly quoted
3378 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3379 Autoconf Manual}).  The @command{aclocal} programs also understands
3380 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3381 Autoconf Manual}), so it is safe to put each macro in a separate file.
3382 Each file should have no side effects but macro definitions.
3383 Especially, any call to @code{AC_PREREQ} should be done inside the
3384 defined macro, not at the beginning of the file.
3386 @cindex underquoted @code{AC_DEFUN}
3387 @acindex AC_DEFUN
3388 @acindex AC_PREREQ
3390 Starting with Automake 1.8, @command{aclocal} will warn about all
3391 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3392 lot of people, because @command{aclocal} was not so strict in the past
3393 and many third party macros are underquoted; and we have to apologize
3394 for this temporary inconvenience.  The reason we have to be stricter
3395 is that a future implementation of @command{aclocal} (@pxref{Future of
3396 aclocal}) will have to temporarily include all these third party
3397 @file{.m4} files, maybe several times, including even files that are
3398 not actually needed.  Doing so should alleviate many problems of the
3399 current implementation, however it requires a stricter style from the
3400 macro authors.  Hopefully it is easy to revise the existing macros.
3401 For instance,
3402 @example
3403 # bad style
3404 AC_PREREQ(2.57)
3405 AC_DEFUN(AX_FOOBAR,
3406 [AC_REQUIRE([AX_SOMETHING])dnl
3407 AX_FOO
3408 AX_BAR
3410 @end example
3411 @noindent
3412 should be rewritten as
3413 @example
3414 AC_DEFUN([AX_FOOBAR],
3415 [AC_PREREQ([2.57])dnl
3416 AC_REQUIRE([AX_SOMETHING])dnl
3417 AX_FOO
3418 AX_BAR
3420 @end example
3422 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3423 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
3424 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3425 allows the macro to be redefined or included twice (otherwise this
3426 first argument would be expanded during the second definition).  For
3427 consistency we like to quote even arguments such as @code{2.57} that
3428 do not require it.
3430 If you have been directed here by the @command{aclocal} diagnostic but
3431 are not the maintainer of the implicated macro, you will want to
3432 contact the maintainer of that macro.  Please make sure you have the
3433 latest version of the macro and that the problem hasn't already been
3434 reported before doing so: people tend to work faster when they aren't
3435 flooded by mails.
3437 Another situation where @command{aclocal} is commonly used is to
3438 manage macros that are used locally by the package, @ref{Local
3439 Macros}.
3441 @node Local Macros
3442 @subsection Handling Local Macros
3444 Feature tests offered by Autoconf do not cover all needs.  People
3445 often have to supplement existing tests with their own macros, or
3446 with third-party macros.
3448 There are two ways to organize custom macros in a package.
3450 The first possibility (the historical practice) is to list all your
3451 macros in @file{acinclude.m4}.  This file will be included in
3452 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3453 henceforth be visible to @command{autoconf}.  However if it contains
3454 numerous macros, it will rapidly become difficult to maintain, and it
3455 will be almost impossible to share macros between packages.
3457 @vindex ACLOCAL_AMFLAGS
3458 The second possibility, which we do recommend, is to write each macro
3459 in its own file and gather all these files in a directory.  This
3460 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3461 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3462 From the command line, this is done with @samp{aclocal -I m4}.  The
3463 top-level @file{Makefile.am} should also be updated to define
3465 @example
3466 ACLOCAL_AMFLAGS = -I m4
3467 @end example
3469 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3470 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3471 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3472 Using @command{autoreconf} to Update @file{configure} Scripts,
3473 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3474 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3475 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3476 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3477 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3478 the place where Gettext's macros should be installed.  So even if you
3479 do not really care about the rebuild rules, you should define
3480 @code{ACLOCAL_AMFLAGS}.
3482 When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
3483 that @code{m4_include}s any file from @file{m4/} that defines a
3484 required macro.  Macros not found locally will still be searched in
3485 system-wide directories, as explained in @ref{Macro Search Path}.
3487 Custom macros should be distributed for the same reason that
3488 @file{configure.ac} is: so that other people have all the sources of
3489 your package if they want to work on it.  Actually, this distribution
3490 happens automatically because all @code{m4_include}d files are
3491 distributed.
3493 However there is no consensus on the distribution of third-party
3494 macros that your package may use.  Many libraries install their own
3495 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3496 aclocal}).  For instance, Guile ships with a file called
3497 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3498 be used to define setup compiler and linker flags appropriate for
3499 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3500 cause @command{aclocal} to copy @file{guile.m4} into
3501 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3502 it will not be distributed.  Technically, that means a user who
3503 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3504 This is probably OK, if Guile already is a requirement to build the
3505 package.  However, if Guile is only an optional feature, or if your
3506 package might run on architectures where Guile cannot be installed,
3507 this requirement will hinder development.  An easy solution is to copy
3508 such third-party macros in your local @file{m4/} directory so they get
3509 distributed.
3511 Since Automake 1.10, @command{aclocal} offers an option to copy these
3512 system-wide third-party macros in your local macro directory, solving
3513 the above problem.  Simply use:
3515 @example
3516 ACLOCAL_AMFLAGS = -I m4 --install
3517 @end example
3519 @noindent
3520 With this setup, system-wide macros will be copied to @file{m4/}
3521 the first time you run @command{autoreconf}.  Then the locally
3522 installed macros will have precedence over the system-wide installed
3523 macros each time @command{aclocal} is run again.
3525 One reason why you should keep @option{--install} in the flags even
3526 after the first run is that when you later edit @file{configure.ac}
3527 and depend on a new macro, this macro will be installed in your
3528 @file{m4/} automatically.  Another one is that serial numbers
3529 (@pxref{Serials}) can be used to update the macros in your source tree
3530 automatically when new system-wide versions are installed.  A serial
3531 number should be a single line of the form
3533 @example
3534 #serial @var{NNN}
3535 @end example
3537 @noindent
3538 where @var{NNN} contains only digits and dots.  It should appear in
3539 the M4 file before any macro definition.  It is a good practice to
3540 maintain a serial number for each macro you distribute, even if you do
3541 not use the @option{--install} option of @command{aclocal}: this allows
3542 other people to use it.
3545 @node Serials
3546 @subsection Serial Numbers
3547 @cindex serial numbers in macros
3548 @cindex macro serial numbers
3549 @cindex @code{#serial} syntax
3550 @cindex @command{aclocal} and serial numbers
3552 Because third-party macros defined in @file{*.m4} files are naturally
3553 shared between multiple projects, some people like to version them.
3554 This makes it easier to tell which of two M4 files is newer.  Since at
3555 least 1996, the tradition is to use a @samp{#serial} line for this.
3557 A serial number should be a single line of the form
3559 @example
3560 # serial @var{version}
3561 @end example
3563 @noindent
3564 where @var{version} is a version number containing only digits and
3565 dots.  Usually people use a single integer, and they increment it each
3566 time they change the macro (hence the name of ``serial'').  Such a
3567 line should appear in the M4 file before any macro definition.
3569 The @samp{#} must be the first character on the line,
3570 and it is OK to have extra words after the version, as in
3572 @example
3573 #serial @var{version} @var{garbage}
3574 @end example
3576 Normally these serial numbers are completely ignored by
3577 @command{aclocal} and @command{autoconf}, like any genuine comment.
3578 However when using @command{aclocal}'s @option{--install} feature, these
3579 serial numbers will modify the way @command{aclocal} selects the
3580 macros to install in the package: if two files with the same basename
3581 exist in your search path, and if at least one of them uses a
3582 @samp{#serial} line, @command{aclocal} will ignore the file that has
3583 the older @samp{#serial} line (or the file that has none).
3585 Note that a serial number applies to a whole M4 file, not to any macro
3586 it contains.  A file can contains multiple macros, but only one
3587 serial.
3589 Here is a use case that illustrates the use of @option{--install} and
3590 its interaction with serial numbers.  Let's assume we maintain a
3591 package called MyPackage, the @file{configure.ac} of which requires a
3592 third-party macro @code{AX_THIRD_PARTY} defined in
3593 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3595 @example
3596 # serial 1
3597 AC_DEFUN([AX_THIRD_PARTY], [...])
3598 @end example
3600 MyPackage uses an @file{m4/} directory to store local macros as
3601 explained in @ref{Local Macros}, and has
3603 @example
3604 ACLOCAL_AMFLAGS = -I m4 --install
3605 @end example
3607 @noindent
3608 in its top-level @file{Makefile.am}.
3610 Initially the @file{m4/} directory is empty.  The first time we run
3611 @command{autoreconf}, it will fetch the options to pass to
3612 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3613 --install}.  @command{aclocal} will notice that
3615 @itemize @bullet
3616 @item
3617 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3618 @item
3619 No local macros define @code{AX_THIRD_PARTY}
3620 @item
3621 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3622 with serial 1.
3623 @end itemize
3625 @noindent
3626 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3627 and @command{aclocal} was given the @option{--install} option, it will
3628 copy this file in @file{m4/thirdparty.m4}, and output an
3629 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3631 The next time @samp{aclocal -I m4 --install} is run (either via
3632 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3633 rules) something different happens.  @command{aclocal} notices that
3635 @itemize @bullet
3636 @item
3637 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3638 @item
3639 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3640 with serial 1.
3641 @item
3642 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3643 with serial 1.
3644 @end itemize
3646 @noindent
3647 Because both files have the same serial number, @command{aclocal} uses
3648 the first it found in its search path order (@pxref{Macro Search
3649 Path}).  @command{aclocal} therefore ignores
3650 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3651 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3653 Local directories specified with @option{-I} are always searched before
3654 system-wide directories, so a local file will always be preferred to
3655 the system-wide file in case of equal serial numbers.
3657 Now suppose the system-wide third-party macro is changed.  This can
3658 happen if the package installing this macro is updated.  Let's suppose
3659 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3660 --install} is run the situation is the following:
3662 @itemize @bullet
3663 @item
3664 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3665 @item
3666 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3667 with serial 1.
3668 @item
3669 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3670 with serial 2.
3671 @end itemize
3673 @noindent
3674 When @command{aclocal} sees a greater serial number, it immediately
3675 forgets anything it knows from files that have the same basename and a
3676 smaller serial number.  So after it has found
3677 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3678 @command{aclocal} will proceed as if it had never seen
3679 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3680 to that at the beginning of our example, where no local file defined
3681 the macro.  @command{aclocal} will install the new version of the
3682 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3683 version.  MyPackage just had its macro updated as a side effect of
3684 running @command{aclocal}.
3686 If you are leery of letting @command{aclocal} update your local macro,
3687 you can run @samp{aclocal -I m4 --diff} to review the changes
3688 @samp{aclocal -I m4 --install} would perform on these macros.
3690 Finally, note that the @option{--force} option of @command{aclocal} has
3691 absolutely no effect on the files installed by @option{--install}.  For
3692 instance, if you have modified your local macros, do not expect
3693 @option{--install --force} to replace the local macros by their
3694 system-wide versions.  If you want to do so, simply erase the local
3695 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3698 @node Future of aclocal
3699 @subsection The Future of @command{aclocal}
3700 @cindex @command{aclocal}'s scheduled death
3702 @command{aclocal} is expected to disappear.  This feature really
3703 should not be offered by Automake.  Automake should focus on
3704 generating @file{Makefile}s; dealing with M4 macros really is
3705 Autoconf's job.  The fact that some people install Automake just to use
3706 @command{aclocal}, but do not use @command{automake} otherwise is an
3707 indication of how that feature is misplaced.
3709 The new implementation will probably be done slightly differently.
3710 For instance, it could enforce the @file{m4/}-style layout discussed in
3711 @ref{Local Macros}.
3713 We have no idea when and how this will happen.  This has been
3714 discussed several times in the past, but someone still has to commit
3715 to that non-trivial task.
3717 From the user point of view, @command{aclocal}'s removal might turn
3718 out to be painful.  There is a simple precaution that you may take to
3719 make that switch more seamless: never call @command{aclocal} yourself.
3720 Keep this guy under the exclusive control of @command{autoreconf} and
3721 Automake's rebuild rules.  Hopefully you won't need to worry about
3722 things breaking, when @command{aclocal} disappears, because everything
3723 will have been taken care of.  If otherwise you used to call
3724 @command{aclocal} directly yourself or from some script, you will
3725 quickly notice the change.
3727 Many packages come with a script called @file{bootstrap.sh} or
3728 @file{autogen.sh}, that will just call @command{aclocal},
3729 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3730 @command{autoconf}, @command{autoheader}, and @command{automake} in
3731 the right order.  Actually this is precisely what @command{autoreconf}
3732 can do for you.  If your package has such a @file{bootstrap.sh} or
3733 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3734 should simplify its logic a lot (less things to maintain, yum!), it's
3735 even likely you will not need the script anymore, and more to the point
3736 you will not call @command{aclocal} directly anymore.
3738 For the time being, third-party packages should continue to install
3739 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3740 is replaced by another tool it might make sense to rename the
3741 directory, but supporting @file{/usr/share/aclocal/} for backward
3742 compatibility should be really easy provided all macros are properly
3743 written (@pxref{Extending aclocal}).
3747 @node Macros
3748 @section Autoconf macros supplied with Automake
3750 Automake ships with several Autoconf macros that you can use from your
3751 @file{configure.ac}.  When you use one of them it will be included by
3752 @command{aclocal} in @file{aclocal.m4}.
3754 @menu
3755 * Public Macros::               Macros that you can use.
3756 * Obsolete Macros::             Macros that you should stop using.
3757 * Private Macros::              Macros that you should not use.
3758 @end menu
3760 @c consider generating the following subsections automatically from m4 files.
3762 @node Public Macros
3763 @subsection Public Macros
3765 @table @code
3767 @item AM_ENABLE_MULTILIB
3768 @acindex AM_ENABLE_MULTILIB
3769 This is used when a ``multilib'' library is being built.  The first
3770 optional argument is the name of the @file{Makefile} being generated; it
3771 defaults to @samp{Makefile}.  The second optional argument is used to find
3772 the top source directory; it defaults to the empty string (generally
3773 this should not be used unless you are familiar with the internals).
3774 @xref{Multilibs}.
3776 @item AM_INIT_AUTOMAKE([OPTIONS])
3777 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
3778 @acindex AM_INIT_AUTOMAKE
3779 Runs many macros required for proper operation of the generated Makefiles.
3781 @vindex AUTOMAKE_OPTIONS
3782 This macro has two forms, the first of which is preferred.
3783 In this form, @code{AM_INIT_AUTOMAKE} is called with a
3784 single argument: a space-separated list of Automake options that should
3785 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3786 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3788 @acindex AC_INIT
3789 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
3790 arguments: the package and the version number.  This form is
3791 obsolete because the @var{package} and @var{version} can be obtained
3792 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
3793 form).
3795 If your @file{configure.ac} has:
3797 @example
3798 AC_INIT([src/foo.c])
3799 AM_INIT_AUTOMAKE([mumble], [1.5])
3800 @end example
3802 @noindent
3803 you can modernize it as follows:
3805 @example
3806 AC_INIT([mumble], [1.5])
3807 AC_CONFIG_SRCDIR([src/foo.c])
3808 AM_INIT_AUTOMAKE
3809 @end example
3811 Note that if you're upgrading your @file{configure.ac} from an earlier
3812 version of Automake, it is not always correct to simply move the
3813 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3814 @code{AC_INIT}, as in the example above.  The first argument to
3815 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3816 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3817 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3818 tarball name from the package name, which should work for most but not
3819 all package names.  (If it doesn't work for yours, you can use the
3820 four-argument form of @code{AC_INIT} to provide the tarball name
3821 explicitly).
3823 @cindex @code{PACKAGE}, prevent definition
3824 @cindex @code{VERSION}, prevent definition
3825 @opindex no-define
3826 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3827 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3828 option, as in:
3829 @example
3830 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3831 @end example
3832 or by passing a third non-empty argument to the obsolete form.
3834 @item AM_PATH_LISPDIR
3835 @acindex AM_PATH_LISPDIR
3836 @vindex EMACS
3837 @vindex lispdir
3838 Searches for the program @command{emacs}, and, if found, sets the
3839 output variable @code{lispdir} to the full path to Emacs' site-lisp
3840 directory.
3842 Note that this test assumes the @command{emacs} found to be a version
3843 that supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other
3844 emacsen can cause this test to hang (some, like old versions of
3845 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3846 exit, which is hardly obvious for a non-emacs user).  In most cases,
3847 however, you should be able to use @kbd{C-c} to kill the test.  In
3848 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3849 environment, or use the @option{--with-lispdir} option to
3850 @command{configure} to explicitly set the correct path (if you're sure
3851 you have an @command{emacs} that supports Emacs Lisp).
3853 @item AM_PROG_AS
3854 @acindex AM_PROG_AS
3855 @vindex CCAS
3856 @vindex CCASFLAGS
3857 Use this macro when you have assembly code in your project.  This will
3858 choose the assembler for you (by default the C compiler) and set
3859 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
3861 @item AM_PROG_CC_C_O
3862 @acindex AM_PROG_CC_C_O
3863 @acindex AC_PROG_CC_C_O
3864 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
3865 the manner required by Automake.  You must use this instead of
3866 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
3867 using per-target flags or subdir-objects with C sources.
3869 @item AM_PROG_LEX
3870 @acindex AM_PROG_LEX
3871 @acindex AC_PROG_LEX
3872 @cindex HP-UX 10, @command{lex} problems
3873 @cindex @command{lex} problems with HP-UX 10
3874 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
3875 Program Checks, autoconf, The Autoconf Manual}), but uses the
3876 @command{missing} script on systems that do not have @command{lex}.
3877 HP-UX 10 is one such system.
3879 @item AM_PROG_GCJ
3880 @acindex AM_PROG_GCJ
3881 @vindex GCJ
3882 @vindex GCJFLAGS
3883 This macro finds the @command{gcj} program or causes an error.  It sets
3884 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
3885 GNU Compiler Collection.
3887 @item AM_PROG_UPC([@var{compiler-search-list}])
3888 @acindex AM_PROG_UPC
3889 @vindex UPC
3890 Find a compiler for Unified Parallel C and define the @code{UPC}
3891 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
3892 This macro will abort @command{configure} if no Unified Parallel C
3893 compiler is found.
3895 @item AM_SILENT_RULES
3896 @acindex AM_SILENT_RULES
3897 Enable the machinery for less verbose build output (@pxref{Options}).
3899 @item AM_WITH_DMALLOC
3900 @acindex AM_WITH_DMALLOC
3901 @cindex @command{dmalloc}, support for
3902 @vindex WITH_DMALLOC
3903 @opindex --with-dmalloc
3904 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
3905 the user runs @command{configure} with @option{--with-dmalloc}, then
3906 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
3908 @item AM_WITH_REGEX
3909 @acindex AM_WITH_REGEX
3910 @vindex WITH_REGEX
3911 @opindex --with-regex
3912 @cindex regex package
3913 @cindex rx package
3914 Adds @option{--with-regex} to the @command{configure} command line.  If
3915 specified (the default), then the @samp{regex} regular expression
3916 library is used, @file{regex.o} is put into @code{LIBOBJS}, and
3917 @code{WITH_REGEX} is defined.  If @option{--without-regex} is given, then
3918 the @code{rx} regular expression library is used, and @file{rx.o} is put
3919 into @code{LIBOBJS}.
3921 @end table
3924 @node Obsolete Macros
3925 @subsection Obsolete Macros
3926 @cindex obsolete macros
3927 @cindex autoupdate
3929 Although using some of the following macros was required in past
3930 releases, you should not use any of them in new code.  Running
3931 @command{autoupdate} should adjust your @file{configure.ac}
3932 automatically (@pxref{autoupdate Invocation, , Using
3933 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
3934 Autoconf Manual}).
3936 @table @code
3937 @item AM_C_PROTOTYPES
3938 @acindex AM_C_PROTOTYPES
3939 @vindex ANSI2KNR
3940 @vindex U
3941 Check to see if function prototypes are understood by the compiler.  If
3942 so, define @samp{PROTOTYPES} and set the output variables @code{U} and
3943 @code{ANSI2KNR} to the empty string.  Otherwise, set @code{U} to
3944 @samp{_} and @code{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
3945 values to implement the obsolete de-ANSI-fication feature.
3947 @item AM_CONFIG_HEADER
3948 @acindex AM_CONFIG_HEADER
3949 Automake will generate rules to automatically regenerate the config
3950 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
3951 today (@pxref{Optional}).
3953 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3954 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3955 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
3956 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
3957 found in @file{<termios.h>}.  This macro is obsolete, you should
3958 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
3960 @item AM_PROG_MKDIR_P
3961 @acindex AM_PROG_MKDIR_P
3962 @cindex @code{mkdir -p}, macro check
3963 @vindex MKDIR_P
3964 @vindex mkdir_p
3966 From Automake 1.8 to 1.9.6 this macro used to define the output
3967 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
3968 -d}, or @code{mkinstalldirs}.
3970 Nowadays Autoconf provides a similar functionality with
3971 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
3972 Program Checks, autoconf, The Autoconf Manual}), however this defines
3973 the output variable @code{MKDIR_P} instead.  Therefore
3974 @code{AM_PROG_MKDIR_P} has been rewritten as a thin wrapper around
3975 @code{AC_PROG_MKDIR_P} to define @code{mkdir_p} to the same value as
3976 @code{MKDIR_P} for backward compatibility.
3978 If you are using Automake, there is normally no reason to call this
3979 macro, because @code{AM_INIT_AUTOMAKE} already does so.  However, make
3980 sure that the custom rules in your @file{Makefile}s use
3981 @code{$(MKDIR_P)} and not @code{$(mkdir_p)}.  Even if both variables
3982 still work, the latter should be considered obsolete.
3984 If you are not using Automake, please call @code{AC_PROG_MKDIR_P}
3985 instead of @code{AM_PROG_MKDIR_P}.
3987 @item AM_SYS_POSIX_TERMIOS
3988 @acindex AM_SYS_POSIX_TERMIOS
3989 @cindex POSIX termios headers
3990 @cindex termios POSIX headers
3991 Check to see if POSIX termios headers and functions are available on the
3992 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
3993 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
3994 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
3996 @end table
3999 @node Private Macros
4000 @subsection Private Macros
4002 The following macros are private macros you should not call directly.
4003 They are called by the other public macros when appropriate.  Do not
4004 rely on them, as they might be changed in a future version.  Consider
4005 them as implementation details; or better, do not consider them at all:
4006 skip this section!
4008 @ftable @code
4009 @item _AM_DEPENDENCIES
4010 @itemx AM_SET_DEPDIR
4011 @itemx AM_DEP_TRACK
4012 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4013 These macros are used to implement Automake's automatic dependency
4014 tracking scheme.  They are called automatically by Automake when
4015 required, and there should be no need to invoke them manually.
4017 @item AM_MAKE_INCLUDE
4018 This macro is used to discover how the user's @command{make} handles
4019 @code{include} statements.  This macro is automatically invoked when
4020 needed; there should be no need to invoke it manually.
4022 @item AM_PROG_INSTALL_STRIP
4023 This is used to find a version of @code{install} that can be used to
4024 strip a program at installation time.  This macro is automatically
4025 included when required.
4027 @item AM_SANITY_CHECK
4028 This checks to make sure that a file created in the build directory is
4029 newer than a file in the source directory.  This can fail on systems
4030 where the clock is set incorrectly.  This macro is automatically run
4031 from @code{AM_INIT_AUTOMAKE}.
4033 @end ftable
4036 @node Directories
4037 @chapter Directories
4039 For simple projects that distribute all files in the same directory
4040 it is enough to have a single @file{Makefile.am} that builds
4041 everything in place.
4043 In larger projects it is common to organize files in different
4044 directories, in a tree.  For instance one directory per program, per
4045 library or per module.  The traditional approach is to build these
4046 subdirectories recursively: each directory contains its @file{Makefile}
4047 (generated from @file{Makefile.am}), and when @command{make} is run
4048 from the top level directory it enters each subdirectory in turn to
4049 build its contents.
4051 @menu
4052 * Subdirectories::              Building subdirectories recursively
4053 * Conditional Subdirectories::  Conditionally not building directories
4054 * Alternative::                 Subdirectories without recursion
4055 * Subpackages::                 Nesting packages
4056 @end menu
4058 @node Subdirectories
4059 @section Recursing subdirectories
4061 @cindex @code{SUBDIRS}, explained
4063 In packages with subdirectories, the top level @file{Makefile.am} must
4064 tell Automake which subdirectories are to be built.  This is done via
4065 the @code{SUBDIRS} variable.
4066 @vindex SUBDIRS
4068 The @code{SUBDIRS} variable holds a list of subdirectories in which
4069 building of various sorts can occur.  The rules for many targets
4070 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4071 both locally and in all specified subdirectories.  Note that the
4072 directories listed in @code{SUBDIRS} are not required to contain
4073 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4074 This allows inclusion of libraries from packages that do not use
4075 Automake (such as @code{gettext}; see also @ref{Third-Party
4076 Makefiles}).
4078 In packages that use subdirectories, the top-level @file{Makefile.am} is
4079 often very short.  For instance, here is the @file{Makefile.am} from the
4080 GNU Hello distribution:
4082 @example
4083 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4084 SUBDIRS = doc intl po src tests
4085 @end example
4087 When Automake invokes @command{make} in a subdirectory, it uses the value
4088 of the @code{MAKE} variable.  It passes the value of the variable
4089 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4090 @file{Makefile.am} if there are flags you must always pass to
4091 @command{make}.
4092 @vindex MAKE
4093 @vindex AM_MAKEFLAGS
4095 The directories mentioned in @code{SUBDIRS} are usually direct
4096 children of the current directory, each subdirectory containing its
4097 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4098 subdirectories.  Automake can be used to construct packages of
4099 arbitrary depth this way.
4101 By default, Automake generates @file{Makefiles} that work depth-first
4102 in postfix order: the subdirectories are built before the current
4103 directory.  However, it is possible to change this ordering.  You can
4104 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4105 putting @samp{.} first will cause a prefix ordering of
4106 directories.
4108 Using
4110 @example
4111 SUBDIRS = lib src . test
4112 @end example
4114 @noindent
4115 will cause @file{lib/} to be built before @file{src/}, then the
4116 current directory will be built, finally the @file{test/} directory
4117 will be built.  It is customary to arrange test directories to be
4118 built after everything else since they are meant to test what has
4119 been constructed.
4121 All @code{clean} rules are run in reverse order of build rules.
4123 @node Conditional Subdirectories
4124 @section Conditional Subdirectories
4125 @cindex Subdirectories, building conditionally
4126 @cindex Conditional subdirectories
4127 @cindex @code{SUBDIRS}, conditional
4128 @cindex Conditional @code{SUBDIRS}
4130 It is possible to define the @code{SUBDIRS} variable conditionally if,
4131 like in the case of GNU Inetutils, you want to only build a subset of
4132 the entire package.
4134 To illustrate how this works, let's assume we have two directories
4135 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4136 want to decide in @command{configure} whether @file{opt/} will be built
4137 or not.  (For this example we will assume that @file{opt/} should be
4138 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4140 Running @command{make} should thus recurse into @file{src/} always, and
4141 then maybe in @file{opt/}.
4143 However @samp{make dist} should always recurse into both @file{src/}
4144 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4145 is not needed in the current configuration.  This means
4146 @file{opt/Makefile} should be created @emph{unconditionally}.
4148 There are two ways to setup a project like this.  You can use Automake
4149 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4150 variables (@pxref{Setting Output Variables, , Setting Output
4151 Variables, autoconf, The Autoconf Manual}).  Using Automake
4152 conditionals is the preferred solution.  Before we illustrate these
4153 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4155 @menu
4156 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4157 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4158 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4159 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4160 @end menu
4162 @node SUBDIRS vs DIST_SUBDIRS
4163 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4164 @cindex @code{DIST_SUBDIRS}, explained
4166 Automake considers two sets of directories, defined by the variables
4167 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4169 @code{SUBDIRS} contains the subdirectories of the current directory
4170 that must be built (@pxref{Subdirectories}).  It must be defined
4171 manually; Automake will never guess a directory is to be built.  As we
4172 will see in the next two sections, it is possible to define it
4173 conditionally so that some directory will be omitted from the build.
4175 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4176 directories, even those that have been conditionally left out of the
4177 build.  Recall our example where we may not want to build subdirectory
4178 @file{opt/}, but yet we want to distribute it?  This is where
4179 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4180 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4182 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4183 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4184 other recursive rules use @code{SUBDIRS}.
4186 If @code{SUBDIRS} is defined conditionally using Automake
4187 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4188 from the possible values of @code{SUBDIRS} in all conditions.
4190 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4191 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4192 does not know the possible values of these variables.  In this case
4193 @code{DIST_SUBDIRS} needs to be defined manually.
4195 @node Subdirectories with AM_CONDITIONAL
4196 @subsection Subdirectories with @code{AM_CONDITIONAL}
4197 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4198 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4200 @c The test case for the setup described here is
4201 @c     test/subdircond2.test
4202 @c Try to keep it in sync.
4204 @file{configure} should output the @file{Makefile} for each directory
4205 and define a condition into which @file{opt/} should be built.
4207 @example
4208 @dots{}
4209 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4210 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4211 @dots{}
4212 @end example
4214 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4215 as follows.
4217 @example
4218 if COND_OPT
4219   MAYBE_OPT = opt
4220 endif
4221 SUBDIRS = src $(MAYBE_OPT)
4222 @end example
4224 As you can see, running @command{make} will rightly recurse into
4225 @file{src/} and maybe @file{opt/}.
4227 @vindex DIST_SUBDIRS
4228 As you can't see, running @samp{make dist} will recurse into both
4229 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4230 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4231 @code{DIST_SUBDIRS} variable.
4233 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4234 automatically because it knows that @code{MAYBE_OPT} can contain
4235 @samp{opt} in some condition.
4237 @node Subdirectories with AC_SUBST
4238 @subsection Subdirectories with @code{AC_SUBST}
4239 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4240 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4242 @c The test case for the setup described here is
4243 @c     test/subdircond3.test
4244 @c Try to keep it in sync.
4246 Another possibility is to define @code{MAYBE_OPT} from
4247 @file{./configure} using @code{AC_SUBST}:
4249 @example
4250 @dots{}
4251 if test "$want_opt" = yes; then
4252   MAYBE_OPT=opt
4253 else
4254   MAYBE_OPT=
4256 AC_SUBST([MAYBE_OPT])
4257 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4258 @dots{}
4259 @end example
4261 In this case the top-level @file{Makefile.am} should look as follows.
4263 @example
4264 SUBDIRS = src $(MAYBE_OPT)
4265 DIST_SUBDIRS = src opt
4266 @end example
4268 The drawback is that since Automake cannot guess what the possible
4269 values of @code{MAYBE_OPT} are, it is necessary to define
4270 @code{DIST_SUBDIRS}.
4272 @node Unconfigured Subdirectories
4273 @subsection Unconfigured Subdirectories
4274 @cindex Subdirectories, configured conditionally
4276 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4277 users that try to @emph{configure and build} subdirectories
4278 conditionally.  Here by configuring we mean creating the
4279 @file{Makefile} (it might also involve running a nested
4280 @command{configure} script: this is a costly operation that explains
4281 why people want to do it conditionally, but only the @file{Makefile}
4282 is relevant to the discussion).
4284 The above examples all assume that every @file{Makefile} is created,
4285 even in directories that are not going to be built.  The simple reason
4286 is that we want @samp{make dist} to distribute even the directories
4287 that are not being built (e.g., platform-dependent code), hence
4288 @file{make dist} must recurse into the subdirectory, hence this
4289 directory must be configured and appear in @code{DIST_SUBDIRS}.
4291 Building packages that do not configure every subdirectory is a tricky
4292 business, and we do not recommend it to the novice as it is easy to
4293 produce an incomplete tarball by mistake.  We will not discuss this
4294 topic in depth here, yet for the adventurous here are a few rules to
4295 remember.
4297 @cartouche
4298 @itemize
4299 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4301 It makes little sense to have a directory in @code{SUBDIRS} that
4302 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4303 which directories listed in the latter should be built.
4304 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4305 must be configured.
4307 I.e., the @file{Makefile} must exists or the recursive @command{make}
4308 rules will not be able to process the directory.
4309 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4311 So that the cleaning rules remove the generated @file{Makefile}s.
4312 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4313 lists all the directories that have been configured.
4314 @end itemize
4315 @end cartouche
4317 In order to prevent recursion in some unconfigured directory you
4318 must therefore ensure that this directory does not appear in
4319 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4320 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4321 @code{DIST_SUBDIRS} explicitly, it will be default to
4322 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4323 = $(SUBDIRS)}.
4325 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4326 not be distributed unless you make other arrangements for this to
4327 happen (for instance, always running @samp{make dist} in a
4328 configuration where all directories are known to appear in
4329 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4330 distribute these directories).
4332 @cindex Subdirectories, not distributed
4333 In few packages, unconfigured directories are not even expected to
4334 be distributed.  Although these packages do not require the
4335 aforementioned extra arrangements, there is another pitfall.  If the
4336 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4337 @command{automake} will make sure the directory exists.  Consequently
4338 @command{automake} cannot be run on such a distribution when one
4339 directory has been omitted.  One way to avoid this check is to use the
4340 @code{AC_SUBST} method to declare conditional directories; since
4341 @command{automake} does not know the values of @code{AC_SUBST}
4342 variables it cannot ensure the corresponding directory exists.
4344 @node Alternative
4345 @section An Alternative Approach to Subdirectories
4347 If you've ever read Peter Miller's excellent paper,
4348 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
4349 Recursive Make Considered Harmful}, the preceding sections on the use of
4350 subdirectories will probably come as unwelcome advice.  For those who
4351 haven't read the paper, Miller's main thesis is that recursive
4352 @command{make} invocations are both slow and error-prone.
4354 Automake provides sufficient cross-directory support @footnote{We
4355 believe.  This work is new and there are probably warts.
4356 @xref{Introduction}, for information on reporting bugs.} to enable you
4357 to write a single @file{Makefile.am} for a complex multi-directory
4358 package.
4361 By default an installable file specified in a subdirectory will have its
4362 directory name stripped before installation.  For instance, in this
4363 example, the header file will be installed as
4364 @file{$(includedir)/stdio.h}:
4366 @example
4367 include_HEADERS = inc/stdio.h
4368 @end example
4370 @vindex nobase_
4371 @cindex @code{nobase_} prefix
4372 @cindex Path stripping, avoiding
4373 @cindex Avoiding path stripping
4375 However, the @samp{nobase_} prefix can be used to circumvent this path
4376 stripping.  In this example, the header file will be installed as
4377 @file{$(includedir)/sys/types.h}:
4379 @example
4380 nobase_include_HEADERS = sys/types.h
4381 @end example
4383 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4384 @cindex @code{dist_} and @code{nobase_}
4385 @cindex @code{nodist_} and @code{nobase_}
4386 @vindex dist_
4387 @vindex nodist_
4389 @samp{nobase_} should be specified first when used in conjunction with
4390 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4391 Control}).  For instance:
4393 @example
4394 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4395 @end example
4397 Finally, note that a variable using the @samp{nobase_} prefix can
4398 often be replaced by several variables, one for each destination
4399 directory (@pxref{Uniform}).  For instance, the last example could be
4400 rewritten as follows:
4402 @example
4403 imagesdir = $(pkgdatadir)/images
4404 soundsdir = $(pkgdatadir)/sounds
4405 dist_images_DATA = images/vortex.pgm
4406 dist_sounds_DATA = sounds/whirl.ogg
4407 @end example
4409 @noindent
4410 This latter syntax makes it possible to change one destination
4411 directory without changing the layout of the source tree.
4413 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4414 rule, in that there is no particular installation order guarantee for
4415 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4417 @node Subpackages
4418 @section Nesting Packages
4419 @cindex Nesting packages
4420 @cindex Subpackages
4421 @acindex AC_CONFIG_SUBDIRS
4422 @acindex AC_CONFIG_AUX_DIR
4425 In the GNU Build System, packages can be nested to arbitrary depth.
4426 This means that a package can embed other packages with their own
4427 @file{configure}, @file{Makefile}s, etc.
4429 These other packages should just appear as subdirectories of their
4430 parent package.  They must be listed in @code{SUBDIRS} like other
4431 ordinary directories.  However the subpackage's @file{Makefile}s
4432 should be output by its own @file{configure} script, not by the
4433 parent's @file{configure}.  This is achieved using the
4434 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4435 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4436 autoconf, The Autoconf Manual}).
4438 Here is an example package for an @code{arm} program that links with
4439 a @code{hand} library that is a nested package in subdirectory
4440 @file{hand/}.
4442 @code{arm}'s @file{configure.ac}:
4444 @example
4445 AC_INIT([arm], [1.0])
4446 AC_CONFIG_AUX_DIR([.])
4447 AM_INIT_AUTOMAKE
4448 AC_PROG_CC
4449 AC_CONFIG_FILES([Makefile])
4450 # Call hand's ./configure script recursively.
4451 AC_CONFIG_SUBDIRS([hand])
4452 AC_OUTPUT
4453 @end example
4455 @code{arm}'s @file{Makefile.am}:
4457 @example
4458 # Build the library in the hand subdirectory first.
4459 SUBDIRS = hand
4461 # Include hand's header when compiling this directory.
4462 AM_CPPFLAGS = -I$(srcdir)/hand
4464 bin_PROGRAMS = arm
4465 arm_SOURCES = arm.c
4466 # link with the hand library.
4467 arm_LDADD = hand/libhand.a
4468 @end example
4470 Now here is @code{hand}'s @file{hand/configure.ac}:
4472 @example
4473 AC_INIT([hand], [1.2])
4474 AC_CONFIG_AUX_DIR([.])
4475 AM_INIT_AUTOMAKE
4476 AC_PROG_CC
4477 AC_PROG_RANLIB
4478 AC_CONFIG_FILES([Makefile])
4479 AC_OUTPUT
4480 @end example
4482 @noindent
4483 and its @file{hand/Makefile.am}:
4485 @example
4486 lib_LIBRARIES = libhand.a
4487 libhand_a_SOURCES = hand.c
4488 @end example
4490 When @samp{make dist} is run from the top-level directory it will
4491 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4492 code as well as the @file{hand} subdirectory.  This package can be
4493 built and installed like any ordinary package, with the usual
4494 @samp{./configure && make && make install} sequence (the @code{hand}
4495 subpackage will be built and installed by the process).
4497 When @samp{make dist} is run from the hand directory, it will create a
4498 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4499 to be embedded in another package, it can still be used separately.
4501 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4502 force Automake and Autoconf to search for auxiliary scripts in the
4503 current directory.  For instance, this means that there will be two
4504 copies of @file{install-sh}: one in the top-level of the @code{arm}
4505 package, and another one in the @file{hand/} subdirectory for the
4506 @code{hand} package.
4508 The historical default is to search for these auxiliary scripts in
4509 the parent directory and the grandparent directory.  So if the
4510 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4511 @file{hand/configure.ac}, that subpackage would share the auxiliary
4512 script of the @code{arm} package.  This may looks like a gain in size
4513 (a few kilobytes), but it is actually a loss of modularity as the
4514 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4515 in the subdirectory will not work anymore).
4517 Packages that do not use Automake need more work to be integrated this
4518 way.  @xref{Third-Party Makefiles}.
4520 @node Programs
4521 @chapter Building Programs and Libraries
4523 A large part of Automake's functionality is dedicated to making it easy
4524 to build programs and libraries.
4526 @menu
4527 * A Program::                   Building a program
4528 * A Library::                   Building a library
4529 * A Shared Library::            Building a Libtool library
4530 * Program and Library Variables::  Variables controlling program and
4531                                 library builds
4532 * Default _SOURCES::            Default source files
4533 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4534 * Program Variables::           Variables used when building a program
4535 * Yacc and Lex::                Yacc and Lex support
4536 * C++ Support::                 Compiling C++ sources
4537 * Objective C Support::         Compiling Objective C sources
4538 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4539 * Assembly Support::            Compiling assembly sources
4540 * Fortran 77 Support::          Compiling Fortran 77 sources
4541 * Fortran 9x Support::          Compiling Fortran 9x sources
4542 * Java Support::                Compiling Java sources
4543 * Vala Support::                Compiling Vala sources
4544 * Support for Other Languages::  Compiling other languages
4545 * ANSI::                        Automatic de-ANSI-fication (obsolete)
4546 * Dependencies::                Automatic dependency tracking
4547 * EXEEXT::                      Support for executable extensions
4548 @end menu
4551 @node A Program
4552 @section Building a program
4554 In order to build a program, you need to tell Automake which sources
4555 are part of it, and which libraries it should be linked with.
4557 This section also covers conditional compilation of sources or
4558 programs.  Most of the comments about these also apply to libraries
4559 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4561 @menu
4562 * Program Sources::             Defining program sources
4563 * Linking::                     Linking with libraries or extra objects
4564 * Conditional Sources::         Handling conditional sources
4565 * Conditional Programs::        Building a program conditionally
4566 @end menu
4568 @node Program Sources
4569 @subsection Defining program sources
4571 @cindex @code{PROGRAMS}, @code{bindir}
4572 @vindex _PROGRAMS
4573 @vindex bin_PROGRAMS
4574 @vindex sbin_PROGRAMS
4575 @vindex libexec_PROGRAMS
4576 @vindex pkglib_PROGRAMS
4577 @vindex noinst_PROGRAMS
4578 @vindex check_PROGRAMS
4580 In a directory containing source that gets built into a program (as
4581 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4582 Programs can be installed in @code{bindir}, @code{sbindir},
4583 @code{libexecdir}, @code{pkglibdir}, @code{pkglibexecdir}, or not at all
4584 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4585 which case the prefix is @samp{check_}.
4587 For instance:
4589 @example
4590 bin_PROGRAMS = hello
4591 @end example
4593 In this simple case, the resulting @file{Makefile.in} will contain code
4594 to generate a program named @code{hello}.
4596 Associated with each program are several assisting variables that are
4597 named after the program.  These variables are all optional, and have
4598 reasonable defaults.  Each variable, its use, and default is spelled out
4599 below; we use the ``hello'' example throughout.
4601 The variable @code{hello_SOURCES} is used to specify which source files
4602 get built into an executable:
4604 @example
4605 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4606 @end example
4608 This causes each mentioned @file{.c} file to be compiled into the
4609 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4611 @cindex @code{_SOURCES} primary, defined
4612 @cindex @code{SOURCES} primary, defined
4613 @cindex Primary variable, @code{SOURCES}
4614 @vindex _SOURCES
4616 If @code{hello_SOURCES} is not specified, then it defaults to the single
4617 file @file{hello.c} (@pxref{Default _SOURCES}).
4618 @vindex _SOURCES
4619 @vindex SOURCES
4621 Multiple programs can be built in a single directory.  Multiple programs
4622 can share a single source file, which must be listed in each
4623 @code{_SOURCES} definition.
4625 @cindex Header files in @code{_SOURCES}
4626 @cindex @code{_SOURCES} and header files
4628 Header files listed in a @code{_SOURCES} definition will be included in
4629 the distribution but otherwise ignored.  In case it isn't obvious, you
4630 should not include the header file generated by @file{configure} in a
4631 @code{_SOURCES} variable; this file should not be distributed.  Lex
4632 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4633 and Lex}.
4636 @node Linking
4637 @subsection Linking the program
4639 If you need to link against libraries that are not found by
4640 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4641 used to specify additional objects or libraries to link with; it is
4642 inappropriate for specifying specific linker flags, you should use
4643 @code{AM_LDFLAGS} for this purpose.
4644 @vindex LDADD
4645 @vindex AM_LDFLAGS
4647 @cindex @code{prog_LDADD}, defined
4649 Sometimes, multiple programs are built in one directory but do not share
4650 the same link-time requirements.  In this case, you can use the
4651 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4652 program as it appears in some @code{_PROGRAMS} variable, and usually
4653 written in lowercase) to override @code{LDADD}.  If this variable exists
4654 for a given program, then that program is not linked using @code{LDADD}.
4655 @vindex maude_LDADD
4657 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4658 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4659 built in the same directory, and has no such link requirement.  Also,
4660 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4661 is what cpio's @file{src/Makefile.am} looks like (abridged):
4663 @example
4664 bin_PROGRAMS = cpio pax $(MT)
4665 libexec_PROGRAMS = $(RMT)
4666 EXTRA_PROGRAMS = mt rmt
4668 LDADD = ../lib/libcpio.a $(INTLLIBS)
4669 rmt_LDADD =
4671 cpio_SOURCES = @dots{}
4672 pax_SOURCES = @dots{}
4673 mt_SOURCES = @dots{}
4674 rmt_SOURCES = @dots{}
4675 @end example
4677 @cindex @code{_LDFLAGS}, defined
4678 @vindex maude_LDFLAGS
4679 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4680 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4681 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4682 this purpose.
4684 @cindex @code{_DEPENDENCIES}, defined
4685 @vindex maude_DEPENDENCIES
4686 It is also occasionally useful to have a program depend on some other
4687 target that is not actually part of that program.  This can be done
4688 using the @code{@var{prog}_DEPENDENCIES} variable.  Each program
4689 depends on the contents of such a variable, but no further
4690 interpretation is done.
4692 Since these dependencies are associated to the link rule used to
4693 create the programs they should normally list files used by the link
4694 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4695 files.  In rare cases you may need to add other kinds of files such as
4696 linker scripts, but @emph{listing a source file in
4697 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4698 before all the components of a program are built, consider using the
4699 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4701 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4702 Automake.  The automatically-assigned value is the contents of
4703 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4704 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4705 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4706 @samp{$(ALLOCA)}; these are left because it is known that they will not
4707 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4708 generated.
4710 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4711 may be used.
4713 @cindex @code{LDADD} and @option{-l}
4714 @cindex @option{-l} and @code{LDADD}
4715 We recommend that you avoid using @option{-l} options in @code{LDADD}
4716 or @code{@var{prog}_LDADD} when referring to libraries built by your
4717 package.  Instead, write the file name of the library explicitly as in
4718 the above @code{cpio} example.  Use @option{-l} only to list
4719 third-party libraries.  If you follow this rule, the default value of
4720 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4721 omit the other ones.
4724 @node Conditional Sources
4725 @subsection Conditional compilation of sources
4727 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4728 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4729 @code{_SOURCES} variable.  The reason for this is a bit hard to
4730 explain, but suffice to say that it simply won't work.  Automake will
4731 give an error if you try to do this.
4733 Fortunately there are two other ways to achieve the same result.  One is
4734 to use configure substitutions in @code{_LDADD} variables, the other is
4735 to use an Automake conditional.
4737 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4739 @cindex @code{EXTRA_prog_SOURCES}, defined
4741 Automake must know all the source files that could possibly go into a
4742 program, even if not all the files are built in every circumstance.  Any
4743 files that are only conditionally built should be listed in the
4744 appropriate @code{EXTRA_} variable.  For instance, if
4745 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4746 in @code{hello}, the @file{Makefile.am} would contain:
4748 @example
4749 bin_PROGRAMS = hello
4750 hello_SOURCES = hello-common.c
4751 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4752 hello_LDADD = $(HELLO_SYSTEM)
4753 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4754 @end example
4756 @noindent
4757 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4758 @file{configure.ac}:
4760 @example
4761 @dots{}
4762 case $host in
4763   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4764   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4765 esac
4766 AC_SUBST([HELLO_SYSTEM])
4767 @dots{}
4768 @end example
4770 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4771 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4772 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4773 built and linked in.
4775 @subsubheading Conditional Compilation using Automake Conditionals
4777 An often simpler way to compile source files conditionally is to use
4778 Automake conditionals.  For instance, you could use this
4779 @file{Makefile.am} construct to build the same @file{hello} example:
4781 @example
4782 bin_PROGRAMS = hello
4783 if LINUX
4784 hello_SOURCES = hello-linux.c hello-common.c
4785 else
4786 hello_SOURCES = hello-generic.c hello-common.c
4787 endif
4788 @end example
4790 In this case, @file{configure.ac} should setup the @code{LINUX}
4791 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4793 When using conditionals like this you don't need to use the
4794 @code{EXTRA_} variable, because Automake will examine the contents of
4795 each variable to construct the complete list of source files.
4797 If your program uses a lot of files, you will probably prefer a
4798 conditional @samp{+=}.
4800 @example
4801 bin_PROGRAMS = hello
4802 hello_SOURCES = hello-common.c
4803 if LINUX
4804 hello_SOURCES += hello-linux.c
4805 else
4806 hello_SOURCES += hello-generic.c
4807 endif
4808 @end example
4810 @node Conditional Programs
4811 @subsection Conditional compilation of programs
4812 @cindex Conditional programs
4813 @cindex Programs, conditional
4815 Sometimes it is useful to determine the programs that are to be built
4816 at configure time.  For instance, GNU @code{cpio} only builds
4817 @code{mt} and @code{rmt} under special circumstances.  The means to
4818 achieve conditional compilation of programs are the same you can use
4819 to compile source files conditionally: substitutions or conditionals.
4821 @subsubheading Conditional Programs using @command{configure} Substitutions
4823 @vindex EXTRA_PROGRAMS
4824 @cindex @code{EXTRA_PROGRAMS}, defined
4825 In this case, you must notify Automake of all the programs that can
4826 possibly be built, but at the same time cause the generated
4827 @file{Makefile.in} to use the programs specified by @command{configure}.
4828 This is done by having @command{configure} substitute values into each
4829 @code{_PROGRAMS} definition, while listing all optionally built programs
4830 in @code{EXTRA_PROGRAMS}.
4832 @example
4833 bin_PROGRAMS = cpio pax $(MT)
4834 libexec_PROGRAMS = $(RMT)
4835 EXTRA_PROGRAMS = mt rmt
4836 @end example
4838 As explained in @ref{EXEEXT}, Automake will rewrite
4839 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4840 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4841 Obviously it cannot rewrite values obtained at run-time through
4842 @command{configure} substitutions, therefore you should take care of
4843 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4844 ['mt$@{EXEEXT@}'])}.
4846 @subsubheading Conditional Programs using Automake Conditionals
4848 You can also use Automake conditionals (@pxref{Conditionals}) to
4849 select programs to be built.  In this case you don't have to worry
4850 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4852 @example
4853 bin_PROGRAMS = cpio pax
4854 if WANT_MT
4855   bin_PROGRAMS += mt
4856 endif
4857 if WANT_RMT
4858   libexec_PROGRAMS = rmt
4859 endif
4860 @end example
4863 @node A Library
4864 @section Building a library
4866 @cindex @code{_LIBRARIES} primary, defined
4867 @cindex @code{LIBRARIES} primary, defined
4868 @cindex Primary variable, @code{LIBRARIES}
4869 @vindex _LIBRARIES
4871 @vindex lib_LIBRARIES
4872 @vindex pkglib_LIBRARIES
4873 @vindex noinst_LIBRARIES
4875 Building a library is much like building a program.  In this case, the
4876 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
4877 @code{libdir} or @code{pkglibdir}.
4879 @xref{A Shared Library}, for information on how to build shared
4880 libraries using libtool and the @code{LTLIBRARIES} primary.
4882 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
4883 For instance, to create a library named @file{libcpio.a}, but not install
4884 it, you would write:
4886 @example
4887 noinst_LIBRARIES = libcpio.a
4888 libcpio_a_SOURCES = @dots{}
4889 @end example
4891 The sources that go into a library are determined exactly as they are
4892 for programs, via the @code{_SOURCES} variables.  Note that the library
4893 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
4894 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
4895 not @samp{libcpio.a_SOURCES}.
4897 @vindex maude_LIBADD
4898 Extra objects can be added to a library using the
4899 @code{@var{library}_LIBADD} variable.  This should be used for objects
4900 determined by @command{configure}.  Again from @code{cpio}:
4902 @example
4903 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4904 @end example
4906 In addition, sources for extra objects that will not exist until
4907 configure-time must be added to the @code{BUILT_SOURCES} variable
4908 (@pxref{Sources}).
4910 Building a static library is done by compiling all object files, then
4911 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
4912 library and the list of objects, and finally by calling
4913 @samp{$(RANLIB)} on that library.  You should call
4914 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
4915 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
4916 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
4917 can override these two variables my setting them in your
4918 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
4919 @file{configure.ac}, or by defining a per-library @code{maude_AR}
4920 variable (@pxref{Program and Library Variables}).
4922 @cindex Empty libraries
4923 Be careful when selecting library components conditionally.  Because
4924 building an empty library is not portable, you should ensure that any
4925 library always contains at least one object.
4927 To use a static library when building a program, add it to
4928 @code{LDADD} for this program.  In the following example, the program
4929 @file{cpio} is statically linked with the library @file{libcpio.a}.
4931 @example
4932 noinst_LIBRARIES = libcpio.a
4933 libcpio_a_SOURCES = @dots{}
4935 bin_PROGRAMS = cpio
4936 cpio_SOURCES = cpio.c @dots{}
4937 cpio_LDADD = libcpio.a
4938 @end example
4941 @node A Shared Library
4942 @section Building a Shared Library
4944 @cindex Shared libraries, support for
4946 Building shared libraries portably is a relatively complex matter.
4947 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
4948 Libtool Manual}) was created to help build shared libraries in a
4949 platform-independent way.
4951 @menu
4952 * Libtool Concept::             Introducing Libtool
4953 * Libtool Libraries::           Declaring Libtool Libraries
4954 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
4955 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
4956 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
4957 * Libtool Modules::             Building Libtool Modules
4958 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
4959 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
4960 * Libtool Issues::              Common Issues Related to Libtool's Use
4961 @end menu
4963 @node Libtool Concept
4964 @subsection The Libtool Concept
4966 @cindex @command{libtool}, introduction
4967 @cindex libtool library, definition
4968 @cindex suffix @file{.la}, defined
4969 @cindex @file{.la} suffix, defined
4971 Libtool abstracts shared and static libraries into a unified concept
4972 henceforth called @dfn{libtool libraries}.  Libtool libraries are
4973 files using the @file{.la} suffix, and can designate a static library,
4974 a shared library, or maybe both.  Their exact nature cannot be
4975 determined until @file{./configure} is run: not all platforms support
4976 all kinds of libraries, and users can explicitly select which
4977 libraries should be built.  (However the package's maintainers can
4978 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
4979 macro, libtool, The Libtool Manual}.)
4981 @cindex suffix @file{.lo}, defined
4982 Because object files for shared and static libraries must be compiled
4983 differently, libtool is also used during compilation.  Object files
4984 built by libtool are called @dfn{libtool objects}: these are files
4985 using the @file{.lo} suffix.  Libtool libraries are built from these
4986 libtool objects.
4988 You should not assume anything about the structure of @file{.la} or
4989 @file{.lo} files and how libtool constructs them: this is libtool's
4990 concern, and the last thing one wants is to learn about libtool's
4991 guts.  However the existence of these files matters, because they are
4992 used as targets and dependencies in @file{Makefile}s rules when
4993 building libtool libraries.  There are situations where you may have
4994 to refer to these, for instance when expressing dependencies for
4995 building source files conditionally (@pxref{Conditional Libtool
4996 Sources}).
4998 @cindex @file{libltdl}, introduction
5000 People considering writing a plug-in system, with dynamically loaded
5001 modules, should look into @file{libltdl}: libtool's dlopening library
5002 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5003 This offers a portable dlopening facility to load libtool libraries
5004 dynamically, and can also achieve static linking where unavoidable.
5006 Before we discuss how to use libtool with Automake in details, it
5007 should be noted that the libtool manual also has a section about how
5008 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5009 with Libtool, libtool, The Libtool Manual}).
5011 @node Libtool Libraries
5012 @subsection Building Libtool Libraries
5014 @cindex @code{_LTLIBRARIES} primary, defined
5015 @cindex @code{LTLIBRARIES} primary, defined
5016 @cindex Primary variable, @code{LTLIBRARIES}
5017 @cindex Example of shared libraries
5018 @vindex lib_LTLIBRARIES
5019 @vindex pkglib_LTLIBRARIES
5020 @vindex _LTLIBRARIES
5022 Automake uses libtool to build libraries declared with the
5023 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5024 list of libtool libraries to build.  For instance, to create a libtool
5025 library named @file{libgettext.la}, and install it in @code{libdir},
5026 write:
5028 @example
5029 lib_LTLIBRARIES = libgettext.la
5030 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5031 @end example
5033 Automake predefines the variable @code{pkglibdir}, so you can use
5034 @code{pkglib_LTLIBRARIES} to install libraries in
5035 @samp{$(libdir)/@@PACKAGE@@/}.
5037 If @file{gettext.h} is a public header file that needs to be installed
5038 in order for people to use the library, it should be declared using a
5039 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5040 Headers listed in the latter should be internal headers that are not
5041 part of the public interface.
5043 @example
5044 lib_LTLIBRARIES = libgettext.la
5045 libgettext_la_SOURCES = gettext.c @dots{}
5046 include_HEADERS = gettext.h @dots{}
5047 @end example
5049 A package can build and install such a library along with other
5050 programs that use it.  This dependency should be specified using
5051 @code{LDADD}.  The following example builds a program named
5052 @file{hello} that is linked with @file{libgettext.la}.
5054 @example
5055 lib_LTLIBRARIES = libgettext.la
5056 libgettext_la_SOURCES = gettext.c @dots{}
5058 bin_PROGRAMS = hello
5059 hello_SOURCES = hello.c @dots{}
5060 hello_LDADD = libgettext.la
5061 @end example
5063 @noindent
5064 Whether @file{hello} is statically or dynamically linked with
5065 @file{libgettext.la} is not yet known: this will depend on the
5066 configuration of libtool and the capabilities of the host.
5069 @node Conditional Libtool Libraries
5070 @subsection Building Libtool Libraries Conditionally
5071 @cindex libtool libraries, conditional
5072 @cindex conditional libtool libraries
5074 Like conditional programs (@pxref{Conditional Programs}), there are
5075 two main ways to build conditional libraries: using Automake
5076 conditionals or using Autoconf @code{AC_SUBST}itutions.
5078 The important implementation detail you have to be aware of is that
5079 the place where a library will be installed matters to libtool: it
5080 needs to be indicated @emph{at link-time} using the @option{-rpath}
5081 option.
5083 For libraries whose destination directory is known when Automake runs,
5084 Automake will automatically supply the appropriate @option{-rpath}
5085 option to libtool.  This is the case for libraries listed explicitly in
5086 some installable @code{_LTLIBRARIES} variables such as
5087 @code{lib_LTLIBRARIES}.
5089 However, for libraries determined at configure time (and thus
5090 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5091 final installation directory.  For such libraries you must add the
5092 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5093 hand.
5095 The examples below illustrate the differences between these two methods.
5097 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5098 variable set at @file{./configure}-time to either @file{libfoo.la},
5099 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5100 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5101 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5102 the link rule for these two libraries.  Therefore the @option{-rpath}
5103 argument must be explicitly supplied.
5105 @example
5106 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5107 lib_LTLIBRARIES = $(WANTEDLIBS)
5108 libfoo_la_SOURCES = foo.c @dots{}
5109 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5110 libbar_la_SOURCES = bar.c @dots{}
5111 libbar_la_LDFLAGS = -rpath '$(libdir)'
5112 @end example
5114 Here is how the same @file{Makefile.am} would look using Automake
5115 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5116 Automake is able to compute the @option{-rpath} setting itself, because
5117 it's clear that both libraries will end up in @samp{$(libdir)} if they
5118 are installed.
5120 @example
5121 lib_LTLIBRARIES =
5122 if WANT_LIBFOO
5123 lib_LTLIBRARIES += libfoo.la
5124 endif
5125 if WANT_LIBBAR
5126 lib_LTLIBRARIES += libbar.la
5127 endif
5128 libfoo_la_SOURCES = foo.c @dots{}
5129 libbar_la_SOURCES = bar.c @dots{}
5130 @end example
5132 @node Conditional Libtool Sources
5133 @subsection Libtool Libraries with Conditional Sources
5135 Conditional compilation of sources in a library can be achieved in the
5136 same way as conditional compilation of sources in a program
5137 (@pxref{Conditional Sources}).  The only difference is that
5138 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5139 should mention libtool objects (@file{.lo} files).
5141 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5142 we could build a @file{libhello.la} library using either
5143 @file{hello-linux.c} or @file{hello-generic.c} with the following
5144 @file{Makefile.am}.
5146 @example
5147 lib_LTLIBRARIES = libhello.la
5148 libhello_la_SOURCES = hello-common.c
5149 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5150 libhello_la_LIBADD = $(HELLO_SYSTEM)
5151 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5152 @end example
5154 @noindent
5155 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5156 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5158 Or we could simply use an Automake conditional as follows.
5160 @example
5161 lib_LTLIBRARIES = libhello.la
5162 libhello_la_SOURCES = hello-common.c
5163 if LINUX
5164 libhello_la_SOURCES += hello-linux.c
5165 else
5166 libhello_la_SOURCES += hello-generic.c
5167 endif
5168 @end example
5170 @node Libtool Convenience Libraries
5171 @subsection Libtool Convenience Libraries
5172 @cindex convenience libraries, libtool
5173 @cindex libtool convenience libraries
5174 @vindex noinst_LTLIBRARIES
5175 @vindex check_LTLIBRARIES
5177 Sometimes you want to build libtool libraries that should not be
5178 installed.  These are called @dfn{libtool convenience libraries} and
5179 are typically used to encapsulate many sublibraries, later gathered
5180 into one big installed library.
5182 Libtool convenience libraries are declared by directory-less variables
5183 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5184 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5185 not need an @option{-rpath} flag at link time (actually this is the only
5186 difference).
5188 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5189 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5190 @samp{make check}.  Finally, libraries listed in
5191 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5192 rules to build them, but if the library does not appear as a Makefile
5193 dependency anywhere it won't be built (this is why
5194 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5196 Here is a sample setup merging libtool convenience libraries from
5197 subdirectories into one main @file{libtop.la} library.
5199 @example
5200 # -- Top-level Makefile.am --
5201 SUBDIRS = sub1 sub2 @dots{}
5202 lib_LTLIBRARIES = libtop.la
5203 libtop_la_SOURCES =
5204 libtop_la_LIBADD = \
5205   sub1/libsub1.la \
5206   sub2/libsub2.la \
5207   @dots{}
5209 # -- sub1/Makefile.am --
5210 noinst_LTLIBRARIES = libsub1.la
5211 libsub1_la_SOURCES = @dots{}
5213 # -- sub2/Makefile.am --
5214 # showing nested convenience libraries
5215 SUBDIRS = sub2.1 sub2.2 @dots{}
5216 noinst_LTLIBRARIES = libsub2.la
5217 libsub2_la_SOURCES =
5218 libsub2_la_LIBADD = \
5219   sub21/libsub21.la \
5220   sub22/libsub22.la \
5221   @dots{}
5222 @end example
5224 When using such setup, beware that @command{automake} will assume
5225 @file{libtop.la} is to be linked with the C linker.  This is because
5226 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5227 default language.  If @code{libtop_la_SOURCES} was not empty,
5228 @command{automake} would select the linker as explained in @ref{How
5229 the Linker is Chosen}.
5231 If one of the sublibraries contains non-C source, it is important that
5232 the appropriate linker be chosen.  One way to achieve this is to
5233 pretend that there is such a non-C file among the sources of the
5234 library, thus forcing @command{automake} to select the appropriate
5235 linker.  Here is the top-level @file{Makefile} of our example updated
5236 to force C++ linking.
5238 @example
5239 SUBDIRS = sub1 sub2 @dots{}
5240 lib_LTLIBRARIES = libtop.la
5241 libtop_la_SOURCES =
5242 # Dummy C++ source to cause C++ linking.
5243 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5244 libtop_la_LIBADD = \
5245   sub1/libsub1.la \
5246   sub2/libsub2.la \
5247   @dots{}
5248 @end example
5250 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5251 files that might be compiled (this is mostly useful when doing
5252 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5253 Libtool Sources}), and the @code{nodist_} prefix means the listed
5254 sources are not to be distributed (@pxref{Program and Library
5255 Variables}).  In effect the file @file{dummy.cxx} does not need to
5256 exist in the source tree.  Of course if you have some real source file
5257 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5258 @code{nodist_EXTRA_libtop_la_SOURCES}.
5261 @node Libtool Modules
5262 @subsection Libtool Modules
5263 @cindex modules, libtool
5264 @cindex libtool modules
5265 @cindex @option{-module}, libtool
5267 These are libtool libraries meant to be dlopened.  They are
5268 indicated to libtool by passing @option{-module} at link-time.
5270 @example
5271 pkglib_LTLIBRARIES = mymodule.la
5272 mymodule_la_SOURCES = doit.c
5273 mymodule_la_LDFLAGS = -module
5274 @end example
5276 Ordinarily, Automake requires that a library's name start with
5277 @code{lib}.  However, when building a dynamically loadable module you
5278 might wish to use a "nonstandard" name.  Automake will not complain
5279 about such nonstandard names if it knows the library being built is a
5280 libtool module, i.e., if @option{-module} explicitly appears in the
5281 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5282 variable when no per-library @code{_LDFLAGS} variable is defined).
5284 As always, @code{AC_SUBST} variables are black boxes to Automake since
5285 their values are not yet known when @command{automake} is run.
5286 Therefore if @option{-module} is set via such a variable, Automake
5287 cannot notice it and will proceed as if the library was an ordinary
5288 libtool library, with strict naming.
5290 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5291 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5293 @node Libtool Flags
5294 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5295 @cindex @code{_LIBADD}, libtool
5296 @cindex @code{_LDFLAGS}, libtool
5297 @cindex @code{_LIBTOOLFLAGS}, libtool
5298 @vindex AM_LIBTOOLFLAGS
5299 @vindex LIBTOOLFLAGS
5300 @vindex maude_LIBTOOLFLAGS
5302 As shown in previous sections, the @samp{@var{library}_LIBADD}
5303 variable should be used to list extra libtool objects (@file{.lo}
5304 files) or libtool libraries (@file{.la}) to add to @var{library}.
5306 The @samp{@var{library}_LDFLAGS} variable is the place to list
5307 additional libtool linking flags, such as @option{-version-info},
5308 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5309 libtool, The Libtool Manual}.
5311 The @command{libtool} command has two kinds of options: mode-specific
5312 options and generic options.  Mode-specific options such as the
5313 aforementioned linking flags should be lumped with the other flags
5314 passed to the tool invoked by @command{libtool} (hence the use of
5315 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5316 options include @option{--tag=@var{TAG}} and @option{--silent}
5317 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5318 Libtool Manual} for more options) should appear before the mode
5319 selection on the command line; in @file{Makefile.am}s they should
5320 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5322 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5323 @code{AM_LIBTOOLFLAGS} is used instead.
5325 These flags are passed to libtool after the @option{--tag=@var{TAG}}
5326 option computed by Automake (if any), so
5327 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5328 good place to override or supplement the @option{--tag=@var{TAG}}
5329 setting.
5331 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5332 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5333 Variables Ordering}.  It allows users to run @samp{make
5334 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5335 @command{libtool} can also be influenced with the Automake
5336 @option{silent-rules} option (@pxref{Options}).
5339 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5340 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5341 @cindex @code{LTLIBOBJS}, special handling
5342 @cindex @code{LIBOBJS}, and Libtool
5343 @cindex @code{LTALLOCA}, special handling
5344 @cindex @code{ALLOCA}, and Libtool
5345 @vindex LTLIBOBJS
5346 @vindex LIBOBJS
5347 @vindex LTALLOCA
5348 @vindex ALLOCA
5349 @acindex AC_LIBOBJ
5351 Where an ordinary library might include @samp{$(LIBOBJS)} or
5352 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5353 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5354 the object files that libtool operates on do not necessarily end in
5355 @file{.o}.
5357 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5358 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5359 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5361 @node Libtool Issues
5362 @subsection Common Issues Related to Libtool's Use
5364 @menu
5365 * Error required file ltmain.sh not found::      The need to run libtoolize
5366 * Objects created both with libtool and without:: Avoid a specific build race
5367 @end menu
5369 @node Error required file ltmain.sh not found
5370 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5371 @cindex @file{ltmain.sh} not found
5372 @cindex @command{libtoolize}, no longer run by @command{automake}
5373 @cindex @command{libtoolize} and @command{autoreconf}
5374 @cindex @command{autoreconf} and @command{libtoolize}
5375 @cindex @file{bootstrap.sh} and @command{autoreconf}
5376 @cindex @file{autogen.sh} and @command{autoreconf}
5378 Libtool comes with a tool called @command{libtoolize} that will
5379 install libtool's supporting files into a package.  Running this
5380 command will install @file{ltmain.sh}.  You should execute it before
5381 @command{aclocal} and @command{automake}.
5383 People upgrading old packages to newer autotools are likely to face
5384 this issue because older Automake versions used to call
5385 @command{libtoolize}.  Therefore old build scripts do not call
5386 @command{libtoolize}.
5388 Since Automake 1.6, it has been decided that running
5389 @command{libtoolize} was none of Automake's business.  Instead, that
5390 functionality has been moved into the @command{autoreconf} command
5391 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5392 The Autoconf Manual}).  If you do not want to remember what to run and
5393 when, just learn the @command{autoreconf} command.  Hopefully,
5394 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5395 a call to @command{autoreconf} should also free you from any similar
5396 incompatible change in the future.
5398 @node Objects created both with libtool and without
5399 @subsubsection Objects @samp{created with both libtool and without}
5401 Sometimes, the same source file is used both to build a libtool
5402 library and to build another non-libtool target (be it a program or
5403 another library).
5405 Let's consider the following @file{Makefile.am}.
5407 @example
5408 bin_PROGRAMS = prog
5409 prog_SOURCES = prog.c foo.c @dots{}
5411 lib_LTLIBRARIES = libfoo.la
5412 libfoo_la_SOURCES = foo.c @dots{}
5413 @end example
5415 @noindent
5416 (In this trivial case the issue could be avoided by linking
5417 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5418 @code{prog_SOURCES}.  But let's assume we really want to keep
5419 @file{prog} and @file{libfoo.la} separate.)
5421 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5422 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5423 that in the course of creating @file{foo.lo}, libtool may erase (or
5424 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5426 Therefore, when Automake detects this situation it will complain
5427 with a message such as
5428 @example
5429 object `foo.$(OBJEXT)' created both with libtool and without
5430 @end example
5432 A workaround for this issue is to ensure that these two objects get
5433 different basenames.  As explained in @ref{Renamed Objects}, this
5434 happens automatically when per-targets flags are used.
5436 @example
5437 bin_PROGRAMS = prog
5438 prog_SOURCES = prog.c foo.c @dots{}
5439 prog_CFLAGS = $(AM_CFLAGS)
5441 lib_LTLIBRARIES = libfoo.la
5442 libfoo_la_SOURCES = foo.c @dots{}
5443 @end example
5445 @noindent
5446 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5447 when the @code{prog_CFLAGS} is defined, it is used instead of
5448 @code{AM_CFLAGS}.  However as a side effect it will cause
5449 @file{prog.c} and @file{foo.c} to be compiled as
5450 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5451 the issue.
5453 @node Program and Library Variables
5454 @section Program and Library Variables
5456 Associated with each program is a collection of variables that can be
5457 used to modify how that program is built.  There is a similar list of
5458 such variables for each library.  The canonical name of the program (or
5459 library) is used as a base for naming these variables.
5461 In the list below, we use the name ``maude'' to refer to the program or
5462 library.  In your @file{Makefile.am} you would replace this with the
5463 canonical name of your program.  This list also refers to ``maude'' as a
5464 program, but in general the same rules apply for both static and dynamic
5465 libraries; the documentation below notes situations where programs and
5466 libraries differ.
5468 @vtable @code
5469 @item maude_SOURCES
5470 This variable, if it exists, lists all the source files that are
5471 compiled to build the program.  These files are added to the
5472 distribution by default.  When building the program, Automake will cause
5473 each source file to be compiled to a single @file{.o} file (or
5474 @file{.lo} when using libtool).  Normally these object files are named
5475 after the source file, but other factors can change this.  If a file in
5476 the @code{_SOURCES} variable has an unrecognized extension, Automake
5477 will do one of two things with it.  If a suffix rule exists for turning
5478 files with the unrecognized extension into @file{.o} files, then
5479 @command{automake} will treat this file as it will any other source file
5480 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5481 ignored as though it were a header file.
5483 The prefixes @code{dist_} and @code{nodist_} can be used to control
5484 whether files listed in a @code{_SOURCES} variable are distributed.
5485 @code{dist_} is redundant, as sources are distributed by default, but it
5486 can be specified for clarity if desired.
5488 It is possible to have both @code{dist_} and @code{nodist_} variants of
5489 a given @code{_SOURCES} variable at once; this lets you easily
5490 distribute some files and not others, for instance:
5492 @example
5493 nodist_maude_SOURCES = nodist.c
5494 dist_maude_SOURCES = dist-me.c
5495 @end example
5497 By default the output file (on Unix systems, the @file{.o} file) will
5498 be put into the current build directory.  However, if the option
5499 @option{subdir-objects} is in effect in the current directory then the
5500 @file{.o} file will be put into the subdirectory named after the
5501 source file.  For instance, with @option{subdir-objects} enabled,
5502 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5503 people prefer this mode of operation.  You can specify
5504 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5505 @cindex Subdirectory, objects in
5506 @cindex Objects in subdirectory
5509 @item EXTRA_maude_SOURCES
5510 Automake needs to know the list of files you intend to compile
5511 @emph{statically}.  For one thing, this is the only way Automake has of
5512 knowing what sort of language support a given @file{Makefile.in}
5513 requires.  @footnote{There are other, more obscure reasons for
5514 this limitation as well.}  This means that, for example, you can't put a
5515 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5516 variable.  If you intend to conditionally compile source files and use
5517 @file{configure} to substitute the appropriate object names into, e.g.,
5518 @code{_LDADD} (see below), then you should list the corresponding source
5519 files in the @code{EXTRA_} variable.
5521 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5522 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5523 sources that may need to be built, but should not be distributed.
5525 @item maude_AR
5526 A static library is created by default by invoking @samp{$(AR)
5527 $(ARFLAGS)} followed by the name of the library and then the objects
5528 being put into the library.  You can override this by setting the
5529 @code{_AR} variable.  This is usually used with C++; some C++
5530 compilers require a special invocation in order to instantiate all the
5531 templates that should go into a library.  For instance, the SGI C++
5532 compiler likes this variable set like so:
5533 @example
5534 libmaude_a_AR = $(CXX) -ar -o
5535 @end example
5537 @item maude_LIBADD
5538 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5539 variable.  For instance, this should be used for objects determined by
5540 @command{configure} (@pxref{A Library}).
5542 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5543 to other libtool libraries.
5545 @item maude_LDADD
5546 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5547 @file{*.la}) can be added to a @emph{program} by listing them in the
5548 @code{_LDADD} variable.  For instance, this should be used for objects
5549 determined by @command{configure} (@pxref{Linking}).
5551 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5552 program-specific linker flags (except for @option{-l}, @option{-L},
5553 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5554 for this purpose.
5556 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5557 could link your program against the X libraries like so:
5559 @example
5560 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5561 @end example
5563 We recommend that you use @option{-l} and @option{-L} only when
5564 referring to third-party libraries, and give the explicit file names
5565 of any library built by your package.  Doing so will ensure that
5566 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5568 @item maude_LDFLAGS
5569 This variable is used to pass extra flags to the link step of a program
5570 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5572 @item maude_LIBTOOLFLAGS
5573 This variable is used to pass extra options to @command{libtool}.
5574 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5575 These options are output before @command{libtool}'s @option{--mode=@var{MODE}}
5576 option, so they should not be mode-specific options (those belong to
5577 the compiler or linker flags).  @xref{Libtool Flags}.
5579 @item maude_DEPENDENCIES
5580 It is also occasionally useful to have a target (program or library)
5581 depend on some other file that is not actually part of that target.
5582 This can be done using the @code{_DEPENDENCIES} variable.  Each
5583 target depends on the contents of such a variable, but no further
5584 interpretation is done.
5586 Since these dependencies are associated to the link rule used to
5587 create the programs they should normally list files used by the link
5588 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5589 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5590 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5591 may need to add other kinds of files such as linker scripts, but
5592 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5593 some source file needs to be built before all the components of a
5594 program are built, consider using the @code{BUILT_SOURCES} variable
5595 (@pxref{Sources}).
5597 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5598 The automatically-assigned value is the contents of @code{_LDADD} or
5599 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5600 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5601 substitutions that are left in are only @samp{$(LIBOBJS)} and
5602 @samp{$(ALLOCA)}; these are left because it is known that they will not
5603 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5605 @code{_DEPENDENCIES} is more likely used to perform conditional
5606 compilation using an @code{AC_SUBST} variable that contains a list of
5607 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5608 Sources}.
5610 @item maude_LINK
5611 You can override the linker on a per-program basis.  By default the
5612 linker is chosen according to the languages used by the program.  For
5613 instance, a program that includes C++ source code would use the C++
5614 compiler to link.  The @code{_LINK} variable must hold the name of a
5615 command that can be passed all the @file{.o} file names as arguments.
5616 Note that the name of the underlying program is @emph{not} passed to
5617 @code{_LINK}; typically one uses @samp{$@@}:
5619 @example
5620 maude_LINK = $(CCLD) -magic -o $@@
5621 @end example
5623 @item maude_CCASFLAGS
5624 @itemx maude_CFLAGS
5625 @itemx maude_CPPFLAGS
5626 @itemx maude_CXXFLAGS
5627 @itemx maude_FFLAGS
5628 @itemx maude_GCJFLAGS
5629 @itemx maude_LFLAGS
5630 @itemx maude_OBJCFLAGS
5631 @itemx maude_RFLAGS
5632 @itemx maude_UPCFLAGS
5633 @itemx maude_YFLAGS
5634 @cindex per-target compilation flags, defined
5635 Automake allows you to set compilation flags on a per-program (or
5636 per-library) basis.  A single source file can be included in several
5637 programs, and it will potentially be compiled with different flags for
5638 each program.  This works for any language directly supported by
5639 Automake.  These @dfn{per-target compilation flags} are
5640 @samp{_CCASFLAGS},
5641 @samp{_CFLAGS},
5642 @samp{_CPPFLAGS},
5643 @samp{_CXXFLAGS},
5644 @samp{_FFLAGS},
5645 @samp{_GCJFLAGS},
5646 @samp{_LFLAGS},
5647 @samp{_OBJCFLAGS},
5648 @samp{_RFLAGS},
5649 @samp{_UPCFLAGS}, and
5650 @samp{_YFLAGS}.
5652 When using a per-target compilation flag, Automake will choose a
5653 different name for the intermediate object files.  Ordinarily a file
5654 like @file{sample.c} will be compiled to produce @file{sample.o}.
5655 However, if the program's @code{_CFLAGS} variable is set, then the
5656 object file will be named, for instance, @file{maude-sample.o}.  (See
5657 also @ref{Renamed Objects}.)  The use of per-target compilation flags
5658 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5659 from @file{configure.ac}.
5661 In compilations with per-target flags, the ordinary @samp{AM_} form of
5662 the flags variable is @emph{not} automatically included in the
5663 compilation (however, the user form of the variable @emph{is} included).
5664 So for instance, if you want the hypothetical @file{maude} compilations
5665 to also use the value of @code{AM_CFLAGS}, you would need to write:
5667 @example
5668 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5669 @end example
5671 @xref{Flag Variables Ordering}, for more discussion about the
5672 interaction between user variables, @samp{AM_} shadow variables, and
5673 per-target variables.
5675 @item maude_SHORTNAME
5676 On some platforms the allowable file names are very short.  In order to
5677 support these systems and per-target compilation flags at the same
5678 time, Automake allows you to set a ``short name'' that will influence
5679 how intermediate object files are named.  For instance, in the following
5680 example,
5682 @example
5683 bin_PROGRAMS = maude
5684 maude_CPPFLAGS = -DSOMEFLAG
5685 maude_SHORTNAME = m
5686 maude_SOURCES = sample.c @dots{}
5687 @end example
5689 @noindent
5690 the object file would be named @file{m-sample.o} rather than
5691 @file{maude-sample.o}.
5693 This facility is rarely needed in practice,
5694 and we recommend avoiding it until you find it is required.
5695 @end vtable
5697 @node Default _SOURCES
5698 @section Default @code{_SOURCES}
5700 @vindex _SOURCES
5701 @vindex SOURCES
5702 @cindex @code{_SOURCES}, default
5703 @cindex default @code{_SOURCES}
5704 @vindex AM_DEFAULT_SOURCE_EXT
5706 @code{_SOURCES} variables are used to specify source files of programs
5707 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5708 libraries (@pxref{A Shared Library}).
5710 When no such variable is specified for a target, Automake will define
5711 one itself.  The default is to compile a single C file whose base name
5712 is the name of the target itself, with any extension replaced by
5713 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5715 For example if you have the following somewhere in your
5716 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5718 @example
5719 lib_LIBRARIES = libfoo.a sub/libc++.a
5720 @end example
5722 @noindent
5723 @file{libfoo.a} will be built using a default source file named
5724 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5725 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5726 would be built from @file{sub_libc___a.c}, i.e., the default source
5727 was the canonized name of the target, with @file{.c} appended.
5728 We believe the new behavior is more sensible, but for backward
5729 compatibility @command{automake} will use the old name if a file or a rule
5730 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5732 @cindex @code{check_PROGRAMS} example
5733 @vindex check_PROGRAMS
5734 Default sources are mainly useful in test suites, when building many
5735 test programs each from a single source.  For instance, in
5737 @example
5738 check_PROGRAMS = test1 test2 test3
5739 AM_DEFAULT_SOURCE_EXT = .cpp
5740 @end example
5742 @noindent
5743 @file{test1}, @file{test2}, and @file{test3} will be built
5744 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5745 Without the last line, they will be built from @file{test1.c},
5746 @file{test2.c}, and @file{test3.c}.
5748 @cindex Libtool modules, default source example
5749 @cindex default source, Libtool modules example
5750 Another case where this is convenient is building many Libtool modules
5751 (@file{module@var{N}.la}), each defined in its own file
5752 (@file{module@var{N}.c}).
5754 @example
5755 AM_LDFLAGS = -module
5756 lib_LTLIBRARIES = module1.la module2.la module3.la
5757 @end example
5759 @cindex empty @code{_SOURCES}
5760 @cindex @code{_SOURCES}, empty
5761 Finally, there is one situation where this default source computation
5762 needs to be avoided: when a target should not be built from sources.
5763 We already saw such an example in @ref{true}; this happens when all
5764 the constituents of a target have already been compiled and just need
5765 to be combined using a @code{_LDADD} variable.  Then it is necessary
5766 to define an empty @code{_SOURCES} variable, so that @command{automake} does not
5767 compute a default.
5769 @example
5770 bin_PROGRAMS = target
5771 target_SOURCES =
5772 target_LDADD = libmain.a libmisc.a
5773 @end example
5775 @node LIBOBJS
5776 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5778 @cindex @code{LIBOBJS}, example
5779 @cindex @code{ALLOCA}, example
5780 @cindex @code{LIBOBJS}, special handling
5781 @cindex @code{ALLOCA}, special handling
5782 @vindex LTLIBOBJS
5783 @vindex LIBOBJS
5784 @vindex LTALLOCA
5785 @vindex ALLOCA
5787 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5788 files that should be compiled into the project to provide an
5789 implementation for functions that are missing or broken on the host
5790 system.  They are substituted by @file{configure}.
5792 @acindex AC_LIBOBJ
5794 These variables are defined by Autoconf macros such as
5795 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5796 Generic Function Checks, autoconf, The Autoconf Manual}), or
5797 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5798 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5799 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5800 populate @samp{$(LIBOBJS)}.
5802 @acindex AC_LIBSOURCE
5804 Using these variables is very similar to doing conditional compilation
5805 using @code{AC_SUBST} variables, as described in @ref{Conditional
5806 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5807 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5808 variable, or to the @samp{*_LIBADD} variable when building a library.
5809 However there is no need to list the corresponding sources in
5810 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5811 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5812 dependencies, and it will discover the list of corresponding source
5813 files automatically (by tracing the invocations of the
5814 @code{AC_LIBSOURCE} Autoconf macros).  However, if you have already
5815 defined @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then
5816 you have to add these variables manually.
5818 These variables are usually used to build a portability library that
5819 is linked with all the programs of the project.  We now review a
5820 sample setup.  First, @file{configure.ac} contains some checks that
5821 affect either @code{LIBOBJS} or @code{ALLOCA}.
5823 @example
5824 # configure.ac
5825 @dots{}
5826 AC_CONFIG_LIBOBJ_DIR([lib])
5827 @dots{}
5828 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5829 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5830 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5831 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5832 @dots{}
5833 AC_CONFIG_FILES([
5834   lib/Makefile
5835   src/Makefile
5837 AC_OUTPUT
5838 @end example
5840 @acindex AC_CONFIG_LIBOBJ_DIR
5842 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
5843 of these object files are to be found in the @file{lib/} directory.
5844 Automake can also use this information, otherwise it expects the
5845 source files are to be in the directory where the @samp{$(LIBOBJS)}
5846 and @samp{$(ALLOCA)} variables are used.
5848 The @file{lib/} directory should therefore contain @file{malloc.c},
5849 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
5850 @file{Makefile.am}:
5852 @example
5853 # lib/Makefile.am
5855 noinst_LIBRARIES = libcompat.a
5856 libcompat_a_SOURCES =
5857 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5858 @end example
5860 The library can have any name, of course, and anyway it is not going
5861 to be installed: it just holds the replacement versions of the missing
5862 or broken functions so we can later link them in.  Many projects
5863 also include extra functions, specific to the project, in that
5864 library: they are simply added on the @code{_SOURCES} line.
5866 @cindex Empty libraries and @samp{$(LIBOBJS)}
5867 @cindex @samp{$(LIBOBJS)} and empty libraries
5868 There is a small trap here, though: @samp{$(LIBOBJS)} and
5869 @samp{$(ALLOCA)} might be empty, and building an empty library is not
5870 portable.  You should ensure that there is always something to put in
5871 @file{libcompat.a}.  Most projects will also add some utility
5872 functions in that directory, and list them in
5873 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
5874 be empty.
5876 Finally here is how this library could be used from the @file{src/}
5877 directory.
5879 @example
5880 # src/Makefile.am
5882 # Link all programs in this directory with libcompat.a
5883 LDADD = ../lib/libcompat.a
5885 bin_PROGRAMS = tool1 tool2 @dots{}
5886 tool1_SOURCES = @dots{}
5887 tool2_SOURCES = @dots{}
5888 @end example
5890 When option @option{subdir-objects} is not used, as in the above
5891 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
5892 be used in the directory where their sources lie.  E.g., here it would
5893 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
5894 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
5895 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
5896 in other directories.  For instance @file{src/Makefile.am} could be
5897 changed as follows.
5899 @example
5900 # src/Makefile.am
5902 AUTOMAKE_OPTIONS = subdir-objects
5903 LDADD = $(LIBOBJS) $(ALLOCA)
5905 bin_PROGRAMS = tool1 tool2 @dots{}
5906 tool1_SOURCES = @dots{}
5907 tool2_SOURCES = @dots{}
5908 @end example
5910 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
5911 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
5912 Libtool libraries (where the expected object extension is @file{.lo}):
5913 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
5915 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
5916 be defined by hand (as in the past), however at the time of writing
5917 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
5918 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
5919 autoconf, The Autoconf Manual}.
5922 @node Program Variables
5923 @section Variables used when building a program
5925 Occasionally it is useful to know which @file{Makefile} variables
5926 Automake uses for compilations, and in which order (@pxref{Flag
5927 Variables Ordering}); for instance, you might need to do your own
5928 compilation in some special cases.
5930 Some variables are inherited from Autoconf; these are @code{CC},
5931 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
5932 @code{LIBS}.
5933 @vindex CC
5934 @vindex CFLAGS
5935 @vindex CPPFLAGS
5936 @vindex DEFS
5937 @vindex LDFLAGS
5938 @vindex LIBS
5940 There are some additional variables that Automake defines on its own:
5942 @vtable @code
5943 @item AM_CPPFLAGS
5944 The contents of this variable are passed to every compilation that invokes
5945 the C preprocessor; it is a list of arguments to the preprocessor.  For
5946 instance, @option{-I} and @option{-D} options should be listed here.
5948 Automake already provides some @option{-I} options automatically, in a
5949 separate variable that is also passed to every compilation that invokes
5950 the C preprocessor.  In particular it generates @samp{-I.},
5951 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
5952 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS} or
5953 @code{AM_CONFIG_HEADER}).  You can disable the default @option{-I}
5954 options using the @option{nostdinc} option.
5956 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
5957 per-library) @code{_CPPFLAGS} variable if it is defined.
5959 @item INCLUDES
5960 This does the same job as @code{AM_CPPFLAGS} (or any per-target
5961 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
5962 same functionality.  This variable is deprecated; we suggest using
5963 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
5965 @item AM_CFLAGS
5966 This is the variable the @file{Makefile.am} author can use to pass
5967 in additional C compiler flags.  It is more fully documented elsewhere.
5968 In some situations, this is not used, in preference to the
5969 per-executable (or per-library) @code{_CFLAGS}.
5971 @item COMPILE
5972 This is the command used to actually compile a C source file.  The
5973 file name is appended to form the complete command line.
5975 @item AM_LDFLAGS
5976 This is the variable the @file{Makefile.am} author can use to pass
5977 in additional linker flags.  In some situations, this is not used, in
5978 preference to the per-executable (or per-library) @code{_LDFLAGS}.
5980 @item LINK
5981 This is the command used to actually link a C program.  It already
5982 includes @samp{-o $@@} and the usual variable references (for instance,
5983 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
5984 and libraries to link in.
5985 @end vtable
5988 @node Yacc and Lex
5989 @section Yacc and Lex support
5991 Automake has somewhat idiosyncratic support for Yacc and Lex.
5993 Automake assumes that the @file{.c} file generated by @command{yacc}
5994 (or @command{lex}) should be named using the basename of the input
5995 file.  That is, for a yacc source file @file{foo.y}, Automake will
5996 cause the intermediate file to be named @file{foo.c} (as opposed to
5997 @file{y.tab.c}, which is more traditional).
5999 The extension of a yacc source file is used to determine the extension
6000 of the resulting C or C++ file.  Files with the extension @file{.y}
6001 will be turned into @file{.c} files; likewise, @file{.yy} will become
6002 @file{.cc}; @file{.y++}, @file{c++}; @file{.yxx}, @file{.cxx}; and
6003 @file{.ypp}, @file{.cpp}.
6005 Likewise, lex source files can be used to generate C or C++; the
6006 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6007 @file{.lpp} are recognized.
6009 You should never explicitly mention the intermediate (C or C++) file
6010 in any @code{SOURCES} variable; only list the source file.
6012 The intermediate files generated by @command{yacc} (or @command{lex})
6013 will be included in any distribution that is made.  That way the user
6014 doesn't need to have @command{yacc} or @command{lex}.
6016 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6017 define the variable @code{YACC}.  This is most easily done by invoking
6018 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6019 Program Checks, autoconf, The Autoconf Manual}).
6021 @vindex YFLAGS
6022 @vindex AM_YFLAGS
6023 When @code{yacc} is invoked, it is passed @code{YFLAGS} and
6024 @code{AM_YFLAGS}.  The former is a user variable and the latter is
6025 intended for the @file{Makefile.am} author.
6027 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6028 @command{yacc}.  Automake knows what this means and will automatically
6029 adjust its rules to update and distribute the header file built by
6030 @samp{yacc -d}.  What Automake cannot guess, though, is where this
6031 header will be used: it is up to you to ensure the header gets built
6032 before it is first used.  Typically this is necessary in order for
6033 dependency tracking to work when the header is included by another
6034 file.  The common solution is listing the header file in
6035 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6037 @example
6038 BUILT_SOURCES = parser.h
6039 AM_YFLAGS = -d
6040 bin_PROGRAMS = foo
6041 foo_SOURCES = @dots{} parser.y @dots{}
6042 @end example
6044 If a @command{lex} source file is seen, then your @file{configure.ac}
6045 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6046 to do this (@pxref{Particular Programs, , Particular Program Checks,
6047 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6048 (@pxref{Macros}) is recommended.
6050 @vindex LFLAGS
6051 @vindex AM_LFLAGS
6052 When @command{lex} is invoked, it is passed @code{LFLAGS} and
6053 @code{AM_LFLAGS}.  The former is a user variable and the latter is
6054 intended for the @file{Makefile.am} author.
6056 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6057 rebuild rule for distributed Yacc and Lex sources are only used when
6058 @code{maintainer-mode} is enabled, or when the files have been erased.
6060 @cindex @command{ylwrap}
6061 @cindex @command{yacc}, multiple parsers
6062 @cindex Multiple @command{yacc} parsers
6063 @cindex Multiple @command{lex} lexers
6064 @cindex @command{lex}, multiple lexers
6066 When @command{lex} or @command{yacc} sources are used, @code{automake
6067 -i} automatically installs an auxiliary program called
6068 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
6069 program is used by the build rules to rename the output of these
6070 tools, and makes it possible to include multiple @command{yacc} (or
6071 @command{lex}) source files in a single directory.  (This is necessary
6072 because yacc's output file name is fixed, and a parallel make could
6073 conceivably invoke more than one instance of @command{yacc}
6074 simultaneously.)
6076 For @command{yacc}, simply managing locking is insufficient.  The output of
6077 @command{yacc} always uses the same symbol names internally, so it isn't
6078 possible to link two @command{yacc} parsers into the same executable.
6080 We recommend using the following renaming hack used in @command{gdb}:
6081 @example
6082 #define yymaxdepth c_maxdepth
6083 #define yyparse c_parse
6084 #define yylex   c_lex
6085 #define yyerror c_error
6086 #define yylval  c_lval
6087 #define yychar  c_char
6088 #define yydebug c_debug
6089 #define yypact  c_pact
6090 #define yyr1    c_r1
6091 #define yyr2    c_r2
6092 #define yydef   c_def
6093 #define yychk   c_chk
6094 #define yypgo   c_pgo
6095 #define yyact   c_act
6096 #define yyexca  c_exca
6097 #define yyerrflag c_errflag
6098 #define yynerrs c_nerrs
6099 #define yyps    c_ps
6100 #define yypv    c_pv
6101 #define yys     c_s
6102 #define yy_yys  c_yys
6103 #define yystate c_state
6104 #define yytmp   c_tmp
6105 #define yyv     c_v
6106 #define yy_yyv  c_yyv
6107 #define yyval   c_val
6108 #define yylloc  c_lloc
6109 #define yyreds  c_reds
6110 #define yytoks  c_toks
6111 #define yylhs   c_yylhs
6112 #define yylen   c_yylen
6113 #define yydefred c_yydefred
6114 #define yydgoto  c_yydgoto
6115 #define yysindex c_yysindex
6116 #define yyrindex c_yyrindex
6117 #define yygindex c_yygindex
6118 #define yytable  c_yytable
6119 #define yycheck  c_yycheck
6120 #define yyname   c_yyname
6121 #define yyrule   c_yyrule
6122 @end example
6124 For each define, replace the @samp{c_} prefix with whatever you like.
6125 These defines work for @command{bison}, @command{byacc}, and
6126 traditional @code{yacc}s.  If you find a parser generator that uses a
6127 symbol not covered here, please report the new name so it can be added
6128 to the list.
6131 @node C++ Support
6132 @section C++ Support
6134 @cindex C++ support
6135 @cindex Support for C++
6137 Automake includes full support for C++.
6139 Any package including C++ code must define the output variable
6140 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6141 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6142 Program Checks, autoconf, The Autoconf Manual}).
6144 A few additional variables are defined when a C++ source file is seen:
6146 @vtable @code
6147 @item CXX
6148 The name of the C++ compiler.
6150 @item CXXFLAGS
6151 Any flags to pass to the C++ compiler.
6153 @item AM_CXXFLAGS
6154 The maintainer's variant of @code{CXXFLAGS}.
6156 @item CXXCOMPILE
6157 The command used to actually compile a C++ source file.  The file name
6158 is appended to form the complete command line.
6160 @item CXXLINK
6161 The command used to actually link a C++ program.
6162 @end vtable
6165 @node Objective C Support
6166 @section Objective C Support
6168 @cindex Objective C support
6169 @cindex Support for Objective C
6171 Automake includes some support for Objective C.
6173 Any package including Objective C code must define the output variable
6174 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6175 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6176 Program Checks, autoconf, The Autoconf Manual}).
6178 A few additional variables are defined when an Objective C source file
6179 is seen:
6181 @vtable @code
6182 @item OBJC
6183 The name of the Objective C compiler.
6185 @item OBJCFLAGS
6186 Any flags to pass to the Objective C compiler.
6188 @item AM_OBJCFLAGS
6189 The maintainer's variant of @code{OBJCFLAGS}.
6191 @item OBJCCOMPILE
6192 The command used to actually compile an Objective C source file.  The
6193 file name is appended to form the complete command line.
6195 @item OBJCLINK
6196 The command used to actually link an Objective C program.
6197 @end vtable
6200 @node Unified Parallel C Support
6201 @section Unified Parallel C Support
6203 @cindex Unified Parallel C support
6204 @cindex Support for Unified Parallel C
6206 Automake includes some support for Unified Parallel C.
6208 Any package including Unified Parallel C code must define the output
6209 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6210 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6212 A few additional variables are defined when a Unified Parallel C
6213 source file is seen:
6215 @vtable @code
6216 @item UPC
6217 The name of the Unified Parallel C compiler.
6219 @item UPCFLAGS
6220 Any flags to pass to the Unified Parallel C compiler.
6222 @item AM_UPCFLAGS
6223 The maintainer's variant of @code{UPCFLAGS}.
6225 @item UPCCOMPILE
6226 The command used to actually compile a Unified Parallel C source file.
6227 The file name is appended to form the complete command line.
6229 @item UPCLINK
6230 The command used to actually link a Unified Parallel C program.
6231 @end vtable
6234 @node Assembly Support
6235 @section Assembly Support
6237 Automake includes some support for assembly code.  There are two forms
6238 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6239 (@file{*.S} or @file{*.sx}).
6241 @vindex CCAS
6242 @vindex CCASFLAGS
6243 @vindex CPPFLAGS
6244 @vindex AM_CCASFLAGS
6245 @vindex AM_CPPFLAGS
6246 The variable @code{CCAS} holds the name of the compiler used to build
6247 assembly code.  This compiler must work a bit like a C compiler; in
6248 particular it must accept @option{-c} and @option{-o}.  The values of
6249 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6250 definition) is passed to the compilation.  For preprocessed files,
6251 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6252 and @code{AM_CPPFLAGS} are also used.
6254 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6255 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6256 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6257 flags), but you are free to define these variables by other means.
6259 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6260 @command{automake} as being files containing assembly code.
6263 @node Fortran 77 Support
6264 @comment  node-name,  next,  previous,  up
6265 @section Fortran 77 Support
6267 @cindex Fortran 77 support
6268 @cindex Support for Fortran 77
6270 Automake includes full support for Fortran 77.
6272 Any package including Fortran 77 code must define the output variable
6273 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6274 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6275 Program Checks, autoconf, The Autoconf Manual}).
6277 A few additional variables are defined when a Fortran 77 source file is
6278 seen:
6280 @vtable @code
6282 @item F77
6283 The name of the Fortran 77 compiler.
6285 @item FFLAGS
6286 Any flags to pass to the Fortran 77 compiler.
6288 @item AM_FFLAGS
6289 The maintainer's variant of @code{FFLAGS}.
6291 @item RFLAGS
6292 Any flags to pass to the Ratfor compiler.
6294 @item AM_RFLAGS
6295 The maintainer's variant of @code{RFLAGS}.
6297 @item F77COMPILE
6298 The command used to actually compile a Fortran 77 source file.  The file
6299 name is appended to form the complete command line.
6301 @item FLINK
6302 The command used to actually link a pure Fortran 77 program or shared
6303 library.
6305 @end vtable
6307 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6308 addition to compiling them@footnote{Much, if not most, of the
6309 information in the following sections pertaining to preprocessing
6310 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6311 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6312 also contains some support for creating programs and shared libraries
6313 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6314 Fortran 77 With C and C++}).
6316 These issues are covered in the following sections.
6318 @menu
6319 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6320 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6321 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6322 @end menu
6325 @node Preprocessing Fortran 77
6326 @comment  node-name,  next,  previous,  up
6327 @subsection Preprocessing Fortran 77
6329 @cindex Preprocessing Fortran 77
6330 @cindex Fortran 77, Preprocessing
6331 @cindex Ratfor programs
6333 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6334 rule runs just the preprocessor to convert a preprocessable Fortran 77
6335 or Ratfor source file into a strict Fortran 77 source file.  The precise
6336 command used is as follows:
6338 @table @file
6340 @item .F
6341 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6342 $(AM_FFLAGS) $(FFLAGS)}
6344 @item .r
6345 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6347 @end table
6350 @node Compiling Fortran 77 Files
6351 @comment  node-name,  next,  previous,  up
6352 @subsection Compiling Fortran 77 Files
6354 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6355 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6356 is as follows:
6358 @table @file
6360 @item .f
6361 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6363 @item .F
6364 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6365 $(AM_FFLAGS) $(FFLAGS)}
6367 @item .r
6368 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6370 @end table
6373 @node Mixing Fortran 77 With C and C++
6374 @comment  node-name,  next,  previous,  up
6375 @subsection Mixing Fortran 77 With C and C++
6377 @cindex Fortran 77, mixing with C and C++
6378 @cindex Mixing Fortran 77 with C and C++
6379 @cindex Linking Fortran 77 with C and C++
6380 @cindex cfortran
6381 @cindex Mixing Fortran 77 with C and/or C++
6383 Automake currently provides @emph{limited} support for creating programs
6384 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6385 However, there are many other issues related to mixing Fortran 77 with
6386 other languages that are @emph{not} (currently) handled by Automake, but
6387 that are handled by other packages@footnote{For example,
6388 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6389 addresses all of these inter-language issues, and runs under nearly all
6390 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6391 @command{cfortran} is not yet Free Software, but it will be in the next
6392 major release.}.
6394 Automake can help in two ways:
6396 @enumerate
6397 @item
6398 Automatic selection of the linker depending on which combinations of
6399 source code.
6401 @item
6402 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6403 @option{-l}) to pass to the automatically selected linker in order to link
6404 in the appropriate Fortran 77 intrinsic and run-time libraries.
6406 @cindex @code{FLIBS}, defined
6407 @vindex FLIBS
6408 These extra Fortran 77 linker flags are supplied in the output variable
6409 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
6410 supplied with newer versions of Autoconf (Autoconf version 2.13 and
6411 later).  @xref{Fortran Compiler, , Fortran Compiler Characteristics,
6412 autoconf, The Autoconf Manual}.
6413 @end enumerate
6415 If Automake detects that a program or shared library (as mentioned in
6416 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6417 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6418 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6419 @file{configure.ac}, and that either @code{$(FLIBS)}
6420 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6421 (for shared libraries) variables.  It is the responsibility of the
6422 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6423 appears in the appropriate @code{_LDADD} or
6424 @code{_LIBADD} variable.
6426 @cindex Mixed language example
6427 @cindex Example, mixed language
6429 For example, consider the following @file{Makefile.am}:
6431 @example
6432 bin_PROGRAMS = foo
6433 foo_SOURCES  = main.cc foo.f
6434 foo_LDADD    = libfoo.la $(FLIBS)
6436 pkglib_LTLIBRARIES = libfoo.la
6437 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6438 libfoo_la_LIBADD   = $(FLIBS)
6439 @end example
6441 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6442 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6443 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6444 Automake would have issued a warning.
6446 @menu
6447 * How the Linker is Chosen::    Automatic linker selection
6448 @end menu
6450 @node How the Linker is Chosen
6451 @comment  node-name,  next,  previous,  up
6452 @subsubsection How the Linker is Chosen
6454 @cindex Automatic linker selection
6455 @cindex Selecting the linker automatically
6457 When a program or library mixes several languages, Automake choose the
6458 linker according to the following priorities.  (The names in
6459 parentheses are the variables containing the link command.)
6461 @enumerate
6462 @item
6463 @vindex GCJLINK
6464 Native Java (@code{GCJLINK})
6465 @item
6466 @vindex CXXLINK
6467 C++ (@code{CXXLINK})
6468 @item
6469 @vindex F77LINK
6470 Fortran 77 (@code{F77LINK})
6471 @item
6472 @vindex FCLINK
6473 Fortran (@code{FCLINK})
6474 @item
6475 @vindex OBJCLINK
6476 Objective C (@code{OBJCLINK})
6477 @item
6478 @vindex UPCLINK
6479 Unified Parallel C (@code{UPCLINK})
6480 @item
6481 @vindex LINK
6482 C (@code{LINK})
6483 @end enumerate
6485 For example, if Fortran 77, C and C++ source code is compiled
6486 into a program, then the C++ linker will be used.  In this case, if the
6487 C or Fortran 77 linkers required any special libraries that weren't
6488 included by the C++ linker, then they must be manually added to an
6489 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6490 @file{Makefile.am}.
6492 Automake only looks at the file names listed in @file{_SOURCES}
6493 variables to choose the linker, and defaults to the C linker.
6494 Sometimes this is inconvenient because you are linking against a
6495 library written in another language and would like to set the linker
6496 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6497 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6500 @node Fortran 9x Support
6501 @comment  node-name,  next,  previous,  up
6502 @section Fortran 9x Support
6504 @cindex Fortran 9x support
6505 @cindex Support for Fortran 9x
6507 Automake includes support for Fortran 9x.
6509 Any package including Fortran 9x code must define the output variable
6510 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6511 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6512 Program Checks, autoconf, The Autoconf Manual}).
6514 A few additional variables are defined when a Fortran 9x source file is
6515 seen:
6517 @vtable @code
6519 @item FC
6520 The name of the Fortran 9x compiler.
6522 @item FCFLAGS
6523 Any flags to pass to the Fortran 9x compiler.
6525 @item AM_FCFLAGS
6526 The maintainer's variant of @code{FCFLAGS}.
6528 @item FCCOMPILE
6529 The command used to actually compile a Fortran 9x source file.  The file
6530 name is appended to form the complete command line.
6532 @item FCLINK
6533 The command used to actually link a pure Fortran 9x program or shared
6534 library.
6536 @end vtable
6538 @menu
6539 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6540 @end menu
6542 @node Compiling Fortran 9x Files
6543 @comment  node-name,  next,  previous,  up
6544 @subsection Compiling Fortran 9x Files
6546 @file{@var{N}.o} is made automatically from @file{@var{N}.f90},
6547 @file{@var{N}.f95}, @file{@var{N}.f03}, or @file{@var{N}.f08}
6548 by running the Fortran 9x compiler.  The precise command used
6549 is as follows:
6551 @table @file
6553 @item .f90
6554 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6556 @item .f95
6557 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6559 @item .f03
6560 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6562 @item .f08
6563 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6565 @end table
6567 @node Java Support
6568 @comment  node-name,  next,  previous,  up
6569 @section Java Support
6571 @cindex Java support
6572 @cindex Support for Java
6574 Automake includes support for compiled Java, using @command{gcj}, the Java
6575 front end to the GNU Compiler Collection.
6577 Any package including Java code to be compiled must define the output
6578 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6579 must also be defined somehow (either in @file{configure.ac} or
6580 @file{Makefile.am}).  The simplest way to do this is to use the
6581 @code{AM_PROG_GCJ} macro.
6583 @vindex GCJFLAGS
6585 By default, programs including Java source files are linked with
6586 @command{gcj}.
6588 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6589 compilation invoking @command{gcj} (in its role as an ahead-of-time
6590 compiler, when invoking it to create @file{.class} files,
6591 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6592 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6593 the user variable @code{GCJFLAGS}, should be used.
6595 @vindex AM_GCJFLAGS
6597 @command{gcj} can be used to compile @file{.java}, @file{.class},
6598 @file{.zip}, or @file{.jar} files.
6600 When linking, @command{gcj} requires that the main class be specified
6601 using the @option{--main=} option.  The easiest way to do this is to use
6602 the @code{_LDFLAGS} variable for the program.
6605 @node Vala Support
6606 @comment  node-name,  next,  previous,  up
6607 @section Vala Support
6609 @cindex Vala Support
6610 @cindex Support for Vala
6612 Automake provides initial support for Vala
6613 (@uref{http://www.vala-project.org/}).
6614 This requires valac version 0.7.0 or later, and currently requires
6615 the user to use GNU @command{make}.
6617 @example
6618 foo_SOURCES = foo.vala bar.vala zardoc.c
6619 @end example
6621 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6622 compiled into C code by the Vala compiler. The generated @file{.c} files are
6623 distributed. The end user does not need to have a Vala compiler installed.
6625 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6626 that will locate the Vala compiler and optionally check its version
6627 number.
6629 @defmac AM_PROG_VALAC (@ovar{MINIMUM-VERSION})
6630 Try to find a Vala compiler in @env{PATH}. If it is found, the variable
6631 @code{VALAC} is set. Optionally a minimum release number of the compiler
6632 can be requested:
6634 @example
6635 AM_PROG_VALAC([0.7.0])
6636 @end example
6637 @end defmac
6639 There are a few variables that are used when compiling Vala sources:
6641 @vtable @code
6642 @item VALAC
6643 Path to the Vala compiler.
6645 @item VALAFLAGS
6646 Additional arguments for the Vala compiler.
6648 @item AM_VALAFLAGS
6649 The maintainer's variant of @code{VALAFLAGS}.
6651 @example
6652 lib_LTLIBRARIES = libfoo.la
6653 libfoo_la_SOURCES = foo.vala
6654 @end example
6655 @end vtable
6657 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
6658 (@pxref{Renamed Objects}) to produce different C files from one Vala
6659 source file.
6662 @node Support for Other Languages
6663 @comment  node-name,  next,  previous,  up
6664 @section Support for Other Languages
6666 Automake currently only includes full support for C, C++ (@pxref{C++
6667 Support}), Objective C (@pxref{Objective C Support}), Fortran 77
6668 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6669 and Java (@pxref{Java Support}).  There is only rudimentary support for other
6670 languages, support for which will be improved based on user demand.
6672 Some limited support for adding your own languages is available via the
6673 suffix rule handling (@pxref{Suffixes}).
6676 @node ANSI
6677 @section Automatic de-ANSI-fication
6679 @cindex de-ANSI-fication, defined
6681 The features described in this section are obsolete; you should not
6682 used any of them in new code, and they may be withdrawn in future
6683 Automake releases.
6685 When the C language was standardized in 1989, there was a long
6686 transition period where package developers needed to worry about
6687 porting to older systems that did not support ANSI C by default.
6688 These older systems are no longer in practical use and are no longer
6689 supported by their original suppliers, so developers need not worry
6690 about this problem any more.
6692 Automake allows you to write packages that are portable to K&R C by
6693 @dfn{de-ANSI-fying} each source file before the actual compilation takes
6694 place.
6696 @vindex AUTOMAKE_OPTIONS
6697 @opindex ansi2knr
6699 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
6700 (@pxref{Options}) contains the option @option{ansi2knr} then code to
6701 handle de-ANSI-fication is inserted into the generated
6702 @file{Makefile.in}.
6704 This causes each C source file in the directory to be treated as ANSI C@.
6705 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
6706 is available, the @command{ansi2knr} program is used to convert the source
6707 files into K&R C, which is then compiled.
6709 The @command{ansi2knr} program is simple-minded.  It assumes the source
6710 code will be formatted in a particular way; see the @command{ansi2knr} man
6711 page for details.
6713 @acindex AM_C_PROTOTYPES
6714 Support for the obsolete de-ANSI-fication feature
6715 requires the source files @file{ansi2knr.c}
6716 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
6717 these files are distributed with Automake.  Also, the package
6718 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
6719 (@pxref{Macros}).
6721 Automake also handles finding the @command{ansi2knr} support files in some
6722 other directory in the current package.  This is done by prepending the
6723 relative path to the appropriate directory to the @command{ansi2knr}
6724 option.  For instance, suppose the package has ANSI C code in the
6725 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
6726 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
6727 @file{src/Makefile.am}:
6729 @example
6730 AUTOMAKE_OPTIONS = ../lib/ansi2knr
6731 @end example
6733 If no directory prefix is given, the files are assumed to be in the
6734 current directory.
6736 Note that automatic de-ANSI-fication will not work when the package is
6737 being built for a different host architecture.  That is because @command{automake}
6738 currently has no way to build @command{ansi2knr} for the build machine.
6740 @c FIXME: this paragraph might be better moved to an `upgrading' section.
6741 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
6742 @cindex @code{LIBOBJS} and @code{ansi2knr}
6743 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
6744 @cindex @code{ansi2knr} and @code{LIBOBJS}
6745 Using @code{LIBOBJS} with source de-ANSI-fication used to require
6746 hand-crafted code in @file{configure} to append @samp{$U} to basenames
6747 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
6748 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
6749 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
6750 vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual})
6752 @node Dependencies
6753 @section Automatic dependency tracking
6755 As a developer it is often painful to continually update the
6756 @file{Makefile.in} whenever the include-file dependencies change in a
6757 project.  Automake supplies a way to automatically track dependency
6758 changes (@pxref{Dependency Tracking}).
6760 @cindex Dependency tracking
6761 @cindex Automatic dependency tracking
6763 Automake always uses complete dependencies for a compilation,
6764 including system headers.  Automake's model is that dependency
6765 computation should be a side effect of the build.  To this end,
6766 dependencies are computed by running all compilations through a
6767 special wrapper program called @command{depcomp}.  @command{depcomp}
6768 understands how to coax many different C and C++ compilers into
6769 generating dependency information in the format it requires.
6770 @samp{automake -a} will install @command{depcomp} into your source
6771 tree for you.  If @command{depcomp} can't figure out how to properly
6772 invoke your compiler, dependency tracking will simply be disabled for
6773 your build.
6775 @cindex @command{depcomp}
6777 Experience with earlier versions of Automake (@pxref{Dependency
6778 Tracking Evolution}) taught us that it is not reliable to generate
6779 dependencies only on the maintainer's system, as configurations vary
6780 too much.  So instead Automake implements dependency tracking at build
6781 time.
6783 Automatic dependency tracking can be suppressed by putting
6784 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6785 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6786 (this should be the preferred way).  Or, you can invoke @command{automake}
6787 with the @option{-i} option.  Dependency tracking is enabled by default.
6789 @vindex AUTOMAKE_OPTIONS
6790 @opindex no-dependencies
6792 The person building your package also can choose to disable dependency
6793 tracking by configuring with @option{--disable-dependency-tracking}.
6795 @cindex Disabling dependency tracking
6796 @cindex Dependency tracking, disabling
6799 @node EXEEXT
6800 @section Support for executable extensions
6802 @cindex Executable extension
6803 @cindex Extension, executable
6804 @cindex Windows
6806 On some platforms, such as Windows, executables are expected to have an
6807 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6808 among them) will automatically generate @file{foo.exe} when asked to
6809 generate @file{foo}.
6811 Automake provides mostly-transparent support for this.  Unfortunately
6812 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6813 dictionary is revised, you will have to assist Automake if your package
6814 must support those platforms.
6816 One thing you must be aware of is that, internally, Automake rewrites
6817 something like this:
6819 @example
6820 bin_PROGRAMS = liver
6821 @end example
6823 to this:
6825 @example
6826 bin_PROGRAMS = liver$(EXEEXT)
6827 @end example
6829 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6830 extension.
6832 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests}) are also
6833 rewritten if they contain filenames that have been declared as programs
6834 in the same @file{Makefile}.  (This is mostly useful when some programs
6835 from @code{check_PROGRAMS} are listed in @code{TESTS}.)
6837 However, Automake cannot apply this rewriting to @command{configure}
6838 substitutions.  This means that if you are conditionally building a
6839 program using such a substitution, then your @file{configure.ac} must
6840 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6842 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
6843 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
6844 automatically if you configure a compiler (say, through
6845 @code{AC_PROG_CC}).
6847 Sometimes maintainers like to write an explicit link rule for their
6848 program.  Without executable extension support, this is easy---you
6849 simply write a rule whose target is the name of the program.  However,
6850 when executable extension support is enabled, you must instead add the
6851 @samp{$(EXEEXT)} suffix.
6853 Unfortunately, due to the change in Autoconf 2.50, this means you must
6854 always add this extension.  However, this is a problem for maintainers
6855 who know their package will never run on a platform that has
6856 executable extensions.  For those maintainers, the @option{no-exeext}
6857 option (@pxref{Options}) will disable this feature.  This works in a
6858 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6859 rule for a target named @code{foo} in @file{Makefile.am} will override
6860 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
6861 the @option{no-exeext} option, this use will give a diagnostic.
6864 @node Other Objects
6865 @chapter Other Derived Objects
6867 Automake can handle derived objects that are not C programs.  Sometimes
6868 the support for actually building such objects must be explicitly
6869 supplied, but Automake will still automatically handle installation and
6870 distribution.
6872 @menu
6873 * Scripts::                     Executable scripts
6874 * Headers::                     Header files
6875 * Data::                        Architecture-independent data files
6876 * Sources::                     Derived sources
6877 @end menu
6880 @node Scripts
6881 @section Executable Scripts
6883 @cindex @code{_SCRIPTS} primary, defined
6884 @cindex @code{SCRIPTS} primary, defined
6885 @cindex Primary variable, @code{SCRIPTS}
6886 @vindex _SCRIPTS
6887 @cindex Installing scripts
6889 It is possible to define and install programs that are scripts.  Such
6890 programs are listed using the @code{SCRIPTS} primary name.  When the
6891 script is distributed in its final, installable form, the
6892 @file{Makefile} usually looks as follows:
6893 @vindex SCRIPTS
6895 @example
6896 # Install my_script in $(bindir) and distribute it.
6897 dist_bin_SCRIPTS = my_script
6898 @end example
6900 Script are not distributed by default; as we have just seen, those
6901 that should be distributed can be specified using a @code{dist_}
6902 prefix as with other primaries.
6904 @cindex @code{SCRIPTS}, installation directories
6905 @vindex bin_SCRIPTS
6906 @vindex sbin_SCRIPTS
6907 @vindex libexec_SCRIPTS
6908 @vindex pkgdata_SCRIPTS
6909 @vindex noinst_SCRIPTS
6910 @vindex check_SCRIPTS
6912 Scripts can be installed in @code{bindir}, @code{sbindir},
6913 @code{libexecdir}, or @code{pkgdatadir}.
6915 Scripts that need not be installed can be listed in
6916 @code{noinst_SCRIPTS}, and among them, those which are needed only by
6917 @samp{make check} should go in @code{check_SCRIPTS}.
6919 When a script needs to be built, the @file{Makefile.am} should include
6920 the appropriate rules.  For instance the @command{automake} program
6921 itself is a Perl script that is generated from @file{automake.in}.
6922 Here is how this is handled:
6924 @example
6925 bin_SCRIPTS = automake
6926 CLEANFILES = $(bin_SCRIPTS)
6927 EXTRA_DIST = automake.in
6929 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
6930             -e 's,[@@]PERL[@@],$(PERL),g' \
6931             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
6932             -e 's,[@@]VERSION[@@],$(VERSION),g' \
6933             @dots{}
6935 automake: automake.in Makefile
6936         $(do_subst) < $(srcdir)/automake.in > automake
6937         chmod +x automake
6938 @end example
6940 Such scripts for which a build rule has been supplied need to be
6941 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
6942 sources have to be distributed, usually with @code{EXTRA_DIST}
6943 (@pxref{Basics of Distribution}).
6945 Another common way to build scripts is to process them from
6946 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
6947 Automake knows which files should be cleaned and distributed, and what
6948 the rebuild rules should look like.
6950 For instance if @file{configure.ac} contains
6952 @example
6953 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
6954 @end example
6956 @noindent
6957 to build @file{src/my_script} from @file{src/my_script.in}, then a
6958 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
6959 be as simple as
6961 @example
6962 bin_SCRIPTS = my_script
6963 CLEANFILES = $(bin_SCRIPTS)
6964 @end example
6966 @noindent
6967 There is no need for @code{EXTRA_DIST} or any build rule: Automake
6968 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
6969 @code{CLEANFILES} is still useful, because by default Automake will
6970 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
6971 @code{clean}.
6973 Although this looks simpler, building scripts this way has one
6974 drawback: directory variables such as @code{$(datadir)} are not fully
6975 expanded and may refer to other directory variables.
6977 @node Headers
6978 @section Header files
6980 @cindex @code{_HEADERS} primary, defined
6981 @cindex @code{HEADERS} primary, defined
6982 @cindex Primary variable, @code{HEADERS}
6983 @vindex _HEADERS
6984 @vindex noinst_HEADERS
6985 @cindex @code{HEADERS}, installation directories
6986 @cindex Installing headers
6987 @vindex include_HEADERS
6988 @vindex oldinclude_HEADERS
6989 @vindex pkginclude_HEADERS
6992 Header files that must be installed are specified by the
6993 @code{HEADERS} family of variables.  Headers can be installed in
6994 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
6995 other directory you may have defined (@pxref{Uniform}).  For instance,
6997 @example
6998 include_HEADERS = foo.h bar/bar.h
6999 @end example
7001 @noindent
7002 will install the two files as @file{$(includedir)/foo.h} and
7003 @file{$(includedir)/bar.h}.
7005 The @code{nobase_} prefix is also supported,
7007 @example
7008 nobase_include_HEADERS = foo.h bar/bar.h
7009 @end example
7011 @noindent
7012 will install the two files as @file{$(includedir)/foo.h} and
7013 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7015 @vindex noinst_HEADERS
7016 Usually, only header files that accompany installed libraries need to
7017 be installed.  Headers used by programs or convenience libraries are
7018 not installed.  The @code{noinst_HEADERS} variable can be used for
7019 such headers.  However when the header actually belongs to a single
7020 convenience library or program, we recommend listing it in the
7021 program's or library's @code{_SOURCES} variable (@pxref{Program
7022 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7023 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7024 right variable to use in a directory containing only headers and no
7025 associated library or program.
7027 All header files must be listed somewhere; in a @code{_SOURCES}
7028 variable or in a @code{_HEADERS} variable.  Missing ones will not
7029 appear in the distribution.
7031 For header files that are built and must not be distributed, use the
7032 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7033 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7034 during the build, you must also ensure they exist before they are
7035 used (@pxref{Sources}).
7038 @node Data
7039 @section Architecture-independent data files
7041 @cindex @code{_DATA} primary, defined
7042 @cindex @code{DATA} primary, defined
7043 @cindex Primary variable, @code{DATA}
7044 @vindex _DATA
7046 Automake supports the installation of miscellaneous data files using the
7047 @code{DATA} family of variables.
7048 @vindex DATA
7050 @vindex data_DATA
7051 @vindex sysconf_DATA
7052 @vindex sharedstate_DATA
7053 @vindex localstate_DATA
7054 @vindex pkgdata_DATA
7056 Such data can be installed in the directories @code{datadir},
7057 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7058 @code{pkgdatadir}.
7060 By default, data files are @emph{not} included in a distribution.  Of
7061 course, you can use the @code{dist_} prefix to change this on a
7062 per-variable basis.
7064 Here is how Automake declares its auxiliary data files:
7066 @example
7067 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7068 @end example
7071 @node Sources
7072 @section Built Sources
7074 Because Automake's automatic dependency tracking works as a side-effect
7075 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7076 target should not be compiled before its dependencies are made, but
7077 these dependencies are unknown until the target is first compiled.
7079 Ordinarily this is not a problem, because dependencies are distributed
7080 sources: they preexist and do not need to be built.  Suppose that
7081 @file{foo.c} includes @file{foo.h}.  When it first compiles
7082 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7083 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7084 records the @file{foo.h} dependency so that following invocations of
7085 @command{make} will honor it.  In these conditions, it's clear there is
7086 no problem: either @file{foo.o} doesn't exist and has to be built
7087 (regardless of the dependencies), or accurate dependencies exist and
7088 they can be used to decide whether @file{foo.o} should be rebuilt.
7090 It's a different story if @file{foo.h} doesn't exist by the first
7091 @command{make} run.  For instance, there might be a rule to build
7092 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7093 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7094 rule to build @file{foo.h} first by lack of dependency information.
7096 @vindex BUILT_SOURCES
7097 @cindex @code{BUILT_SOURCES}, defined
7099 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7100 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7101 or @samp{make check} (or even @samp{make install}) before other
7102 targets are processed.  However, such a source file is not
7103 @emph{compiled} unless explicitly requested by mentioning it in some
7104 other @code{_SOURCES} variable.
7106 So, to conclude our introductory example, we could use
7107 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7108 any other target (including @file{foo.o}) during @samp{make all} or
7109 @samp{make check}.
7111 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7112 must be created early in the build process can be listed in this
7113 variable.  Moreover, all built sources do not necessarily have to be
7114 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7115 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7116 another source), because it's a known dependency of the associated
7117 object.
7119 It might be important to emphasize that @code{BUILT_SOURCES} is
7120 honored only by @samp{make all}, @samp{make check} and @samp{make
7121 install}.  This means you cannot build a specific target (e.g.,
7122 @samp{make foo}) in a clean tree if it depends on a built source.
7123 However it will succeed if you have run @samp{make all} earlier,
7124 because accurate dependencies are already available.
7126 The next section illustrates and discusses the handling of built sources
7127 on a toy example.
7129 @menu
7130 * Built Sources Example::       Several ways to handle built sources.
7131 @end menu
7133 @node Built Sources Example
7134 @subsection Built Sources Example
7136 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7137 installation-dependent and not distributed: it needs to be built.  Here
7138 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7139 value of the @command{make} variable @code{bindir} (inherited from
7140 @file{configure}).
7142 We suggest several implementations below.  It's not meant to be an
7143 exhaustive listing of all ways to handle built sources, but it will give
7144 you a few ideas if you encounter this issue.
7146 @subsubheading First Try
7148 This first implementation will illustrate the bootstrap issue mentioned
7149 in the previous section (@pxref{Sources}).
7151 Here is a tentative @file{Makefile.am}.
7153 @example
7154 # This won't work.
7155 bin_PROGRAMS = foo
7156 foo_SOURCES = foo.c
7157 nodist_foo_SOURCES = bindir.h
7158 CLEANFILES = bindir.h
7159 bindir.h: Makefile
7160         echo '#define bindir "$(bindir)"' >$@@
7161 @end example
7163 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7164 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7165 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7166 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7167 The symptom is as follows.
7169 @example
7170 % make
7171 source='foo.c' object='foo.o' libtool=no \
7172 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7173 depmode=gcc /bin/sh ./depcomp \
7174 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7175 foo.c:2: bindir.h: No such file or directory
7176 make: *** [foo.o] Error 1
7177 @end example
7179 In this example @file{bindir.h} is not distributed nor installed, and
7180 it is not even being built on-time.  One may wonder if the
7181 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7182 line simply states that @file{bindir.h} is a source of @code{foo}, so
7183 for instance, it should be inspected while generating tags
7184 (@pxref{Tags}).  In other words, it does not help our present problem,
7185 and the build would fail identically without it.
7187 @subsubheading Using @code{BUILT_SOURCES}
7189 A solution is to require @file{bindir.h} to be built before anything
7190 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7192 @example
7193 bin_PROGRAMS = foo
7194 foo_SOURCES = foo.c
7195 nodist_foo_SOURCES = bindir.h
7196 BUILT_SOURCES = bindir.h
7197 CLEANFILES = bindir.h
7198 bindir.h: Makefile
7199         echo '#define bindir "$(bindir)"' >$@@
7200 @end example
7202 See how @file{bindir.h} gets built first:
7204 @example
7205 % make
7206 echo '#define bindir "/usr/local/bin"' >bindir.h
7207 make  all-am
7208 make[1]: Entering directory `/home/adl/tmp'
7209 source='foo.c' object='foo.o' libtool=no \
7210 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7211 depmode=gcc /bin/sh ./depcomp \
7212 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7213 gcc  -g -O2   -o foo  foo.o
7214 make[1]: Leaving directory `/home/adl/tmp'
7215 @end example
7217 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7218 @code{all}, @code{check}, and @code{install} targets.  It still fails
7219 if you try to run @samp{make foo} explicitly:
7221 @example
7222 % make clean
7223 test -z "bindir.h" || rm -f bindir.h
7224 test -z "foo" || rm -f foo
7225 rm -f *.o
7226 % : > .deps/foo.Po # Suppress previously recorded dependencies
7227 % make foo
7228 source='foo.c' object='foo.o' libtool=no \
7229 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7230 depmode=gcc /bin/sh ./depcomp \
7231 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7232 foo.c:2: bindir.h: No such file or directory
7233 make: *** [foo.o] Error 1
7234 @end example
7236 @subsubheading Recording Dependencies manually
7238 Usually people are happy enough with @code{BUILT_SOURCES} because they
7239 never build targets such as @samp{make foo} before @samp{make all}, as
7240 in the previous example.  However if this matters to you, you can
7241 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7242 the @file{Makefile.am}.
7244 @example
7245 bin_PROGRAMS = foo
7246 foo_SOURCES = foo.c
7247 nodist_foo_SOURCES = bindir.h
7248 foo.$(OBJEXT): bindir.h
7249 CLEANFILES = bindir.h
7250 bindir.h: Makefile
7251         echo '#define bindir "$(bindir)"' >$@@
7252 @end example
7254 You don't have to list @emph{all} the dependencies of @file{foo.o}
7255 explicitly, only those that might need to be built.  If a dependency
7256 already exists, it will not hinder the first compilation and will be
7257 recorded by the normal dependency tracking code.  (Note that after
7258 this first compilation the dependency tracking code will also have
7259 recorded the dependency between @file{foo.o} and
7260 @file{bindir.h}; so our explicit dependency is really useful to
7261 the first build only.)
7263 Adding explicit dependencies like this can be a bit dangerous if you are
7264 not careful enough.  This is due to the way Automake tries not to
7265 overwrite your rules (it assumes you know better than it).
7266 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7267 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7268 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7269 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7270 Always check the generated @file{Makefile.in} if you do this.
7272 @subsubheading Build @file{bindir.h} from @file{configure}
7274 It's possible to define this preprocessor macro from @file{configure},
7275 either in @file{config.h} (@pxref{Defining Directories, , Defining
7276 Directories, autoconf, The Autoconf Manual}), or by processing a
7277 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7278 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7279 Autoconf Manual}).
7281 At this point it should be clear that building @file{bindir.h} from
7282 @file{configure} works well for this example.  @file{bindir.h} will exist
7283 before you build any target, hence will not cause any dependency issue.
7285 The Makefile can be shrunk as follows.  We do not even have to mention
7286 @file{bindir.h}.
7288 @example
7289 bin_PROGRAMS = foo
7290 foo_SOURCES = foo.c
7291 @end example
7293 However, it's not always possible to build sources from
7294 @file{configure}, especially when these sources are generated by a tool
7295 that needs to be built first.
7297 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7299 Another attractive idea is to define @code{bindir} as a variable or
7300 function exported from @file{bindir.o}, and build @file{bindir.c}
7301 instead of @file{bindir.h}.
7303 @example
7304 noinst_PROGRAMS = foo
7305 foo_SOURCES = foo.c bindir.h
7306 nodist_foo_SOURCES = bindir.c
7307 CLEANFILES = bindir.c
7308 bindir.c: Makefile
7309         echo 'const char bindir[] = "$(bindir)";' >$@@
7310 @end example
7312 @file{bindir.h} contains just the variable's declaration and doesn't
7313 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7314 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7315 first.
7317 @subsubheading Which is best?
7319 There is no panacea, of course.  Each solution has its merits and
7320 drawbacks.
7322 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7323 foo} on a clean tree is important to you.
7325 You won't add explicit dependencies if you are leery of overriding
7326 an Automake rule by mistake.
7328 Building files from @file{./configure} is not always possible, neither
7329 is converting @file{.h} files into @file{.c} files.
7332 @node Other GNU Tools
7333 @chapter Other GNU Tools
7335 Since Automake is primarily intended to generate @file{Makefile.in}s for
7336 use in GNU programs, it tries hard to interoperate with other GNU tools.
7338 @menu
7339 * Emacs Lisp::                  Emacs Lisp
7340 * gettext::                     Gettext
7341 * Libtool::                     Libtool
7342 * Java::                        Java
7343 * Python::                      Python
7344 @end menu
7347 @node Emacs Lisp
7348 @section Emacs Lisp
7350 @cindex @code{_LISP} primary, defined
7351 @cindex @code{LISP} primary, defined
7352 @cindex Primary variable, @code{LISP}
7354 @vindex _LISP
7355 @vindex lisp_LISP
7356 @vindex noinst_LISP
7358 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7359 is used to hold a list of @file{.el} files.  Possible prefixes for this
7360 primary are @code{lisp_} and @code{noinst_}.  Note that if
7361 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7362 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7364 @vindex dist_lisp_LISP
7365 @vindex dist_noinst_LISP
7366 Lisp sources are not distributed by default.  You can prefix the
7367 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7368 @code{dist_noinst_LISP}, to indicate that these files should be
7369 distributed.
7371 Automake will byte-compile all Emacs Lisp source files using the Emacs
7372 found by @code{AM_PATH_LISPDIR}, if any was found.
7374 Byte-compiled Emacs Lisp files are not portable among all versions of
7375 Emacs, so it makes sense to turn this off if you expect sites to have
7376 more than one version of Emacs installed.  Furthermore, many packages
7377 don't actually benefit from byte-compilation.  Still, we recommend
7378 that you byte-compile your Emacs Lisp sources.  It is probably better
7379 for sites with strange setups to cope for themselves than to make the
7380 installation less nice for everybody else.
7382 There are two ways to avoid byte-compiling.  Historically, we have
7383 recommended the following construct.
7384 @example
7385 lisp_LISP = file1.el file2.el
7386 ELCFILES =
7387 @end example
7388 @noindent
7389 @code{ELCFILES} is an internal Automake variable that normally lists
7390 all @file{.elc} files that must be byte-compiled.  Automake defines
7391 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7392 variable explicitly prevents byte-compilation.
7394 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead.  As
7396 @example
7397 lisp_DATA = file1.el file2.el
7398 @end example
7400 Note that these two constructs are not equivalent.  @code{_LISP} will
7401 not install a file if Emacs is not installed, while @code{_DATA} will
7402 always install its files.
7404 @node gettext
7405 @section Gettext
7407 @cindex GNU Gettext support
7408 @cindex Gettext support
7409 @cindex Support for GNU Gettext
7411 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7412 turns on support for GNU gettext, a message catalog system for
7413 internationalization
7414 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7416 The @code{gettext} support in Automake requires the addition of one or
7417 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7418 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7419 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7420 Automake ensures that these directories exist and are mentioned in
7421 @code{SUBDIRS}.
7423 @node Libtool
7424 @section Libtool
7426 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7427 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7428 @xref{A Shared Library}.
7431 @node Java
7432 @section Java
7434 @cindex @code{_JAVA} primary, defined
7435 @cindex @code{JAVA} primary, defined
7436 @cindex Primary variable, @code{JAVA}
7438 Automake provides some minimal support for Java compilation with the
7439 @code{JAVA} primary.
7441 Any @file{.java} files listed in a @code{_JAVA} variable will be
7442 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7443 files are not included in the distribution, you should use the
7444 @code{dist_} prefix to distribute them.
7446 Here is a typical setup for distributing @file{.java} files and
7447 installing the @file{.class} files resulting from their compilation.
7449 @example
7450 javadir = $(datadir)/java
7451 dist_java_JAVA = a.java b.java @dots{}
7452 @end example
7454 @cindex @code{JAVA} restrictions
7455 @cindex Restrictions for @code{JAVA}
7457 Currently Automake enforces the restriction that only one @code{_JAVA}
7458 primary can be used in a given @file{Makefile.am}.  The reason for this
7459 restriction is that, in general, it isn't possible to know which
7460 @file{.class} files were generated from which @file{.java} files, so
7461 it would be impossible to know which files to install where.  For
7462 instance, a @file{.java} file can define multiple classes; the resulting
7463 @file{.class} file names cannot be predicted without parsing the
7464 @file{.java} file.
7466 There are a few variables that are used when compiling Java sources:
7468 @vtable @code
7469 @item JAVAC
7470 The name of the Java compiler.  This defaults to @samp{javac}.
7472 @item JAVACFLAGS
7473 The flags to pass to the compiler.  This is considered to be a user
7474 variable (@pxref{User Variables}).
7476 @item AM_JAVACFLAGS
7477 More flags to pass to the Java compiler.  This, and not
7478 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7479 compiler flags into @file{Makefile.am}.
7481 @item JAVAROOT
7482 The value of this variable is passed to the @option{-d} option to
7483 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7485 @item CLASSPATH_ENV
7486 This variable is a shell expression that is used to set the
7487 @env{CLASSPATH} environment variable on the @code{javac} command line.
7488 (In the future we will probably handle class path setting differently.)
7489 @end vtable
7492 @node Python
7493 @section Python
7495 @cindex @code{_PYTHON} primary, defined
7496 @cindex @code{PYTHON} primary, defined
7497 @cindex Primary variable, @code{PYTHON}
7498 @vindex _PYTHON
7500 Automake provides support for Python compilation with the
7501 @code{PYTHON} primary.  A typical setup is to call
7502 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7503 following in @file{Makefile.am}:
7505 @example
7506 python_PYTHON = tree.py leave.py
7507 @end example
7509 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7510 with @command{py-compile} at install time.  @command{py-compile}
7511 actually creates both standard (@file{.pyc}) and optimized
7512 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7513 because byte-compilation occurs at install time, any files listed in
7514 @code{noinst_PYTHON} will not be compiled.  Python source files are
7515 included in the distribution by default, prepend @code{nodist_} (as in
7516 @code{nodist_python_PYTHON}) to omit them.
7518 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7519 that will determine some Python-related directory variables (see
7520 below).  If you have called @code{AM_PATH_PYTHON} from
7521 @file{configure.ac}, then you may use the variables
7522 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7523 files in your @file{Makefile.am}, depending on where you want your files
7524 installed (see the definitions of @code{pythondir} and
7525 @code{pkgpythondir} below).
7527 @defmac AM_PATH_PYTHON (@ovar{VERSION}, @ovar{ACTION-IF-FOUND}, @ovar{ACTION-IF-NOT-FOUND})
7529 Search for a Python interpreter on the system.  This macro takes three
7530 optional arguments.  The first argument, if present, is the minimum
7531 version of Python required for this package: @code{AM_PATH_PYTHON}
7532 will skip any Python interpreter that is older than @var{VERSION}.
7533 If an interpreter is found and satisfies @var{VERSION}, then
7534 @var{ACTION-IF-FOUND} is run.  Otherwise, @var{ACTION-IF-NOT-FOUND} is
7535 run.
7537 If @var{ACTION-IF-NOT-FOUND} is not specified, as in the following
7538 example, the default is to abort @command{configure}.
7540 @example
7541 AM_PATH_PYTHON([2.2])
7542 @end example
7544 @noindent
7545 This is fine when Python is an absolute requirement for the package.
7546 If Python >= 2.5 was only @emph{optional} to the package,
7547 @code{AM_PATH_PYTHON} could be called as follows.
7549 @example
7550 AM_PATH_PYTHON([2.5],, [:])
7551 @end example
7553 @code{AM_PATH_PYTHON} creates the following output variables based on
7554 the Python installation found during configuration.
7555 @end defmac
7557 @vtable @code
7558 @item PYTHON
7559 The name of the Python executable, or @samp{:} if no suitable
7560 interpreter could be found.
7562 Assuming @var{ACTION-IF-NOT-FOUND} is used (otherwise @file{./configure}
7563 will abort if Python is absent), the value of @code{PYTHON} can be used
7564 to setup a conditional in order to disable the relevant part of a build
7565 as follows.
7567 @example
7568   AM_PATH_PYTHON(,, [:])
7569   AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7570 @end example
7572 @item PYTHON_VERSION
7573 The Python version number, in the form @var{major}.@var{minor}
7574 (e.g., @samp{2.5}).  This is currently the value of
7575 @samp{sys.version[:3]}.
7577 @item PYTHON_PREFIX
7578 The string @samp{$@{prefix@}}.  This term may be used in future work
7579 that needs the contents of Python's @samp{sys.prefix}, but general
7580 consensus is to always use the value from @command{configure}.
7582 @item PYTHON_EXEC_PREFIX
7583 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7584 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7585 consensus is to always use the value from @command{configure}.
7587 @item PYTHON_PLATFORM
7588 The canonical name used by Python to describe the operating system, as
7589 given by @samp{sys.platform}.  This value is sometimes needed when
7590 building Python extensions.
7592 @item pythondir
7593 The directory name for the @file{site-packages} subdirectory of the
7594 standard Python install tree.
7596 @item pkgpythondir
7597 This is the directory under @code{pythondir} that is named after the
7598 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7599 as a convenience.
7601 @item pyexecdir
7602 This is the directory where Python extension modules (shared libraries)
7603 should be installed.  An extension module written in C could be declared
7604 as follows to Automake:
7606 @example
7607 pyexec_LTLIBRARIES = quaternion.la
7608 quaternion_SOURCES = quaternion.c support.c support.h
7609 quaternion_la_LDFLAGS = -avoid-version -module
7610 @end example
7612 @item pkgpyexecdir
7613 This is a convenience variable that is defined as
7614 @samp{$(pyexecdir)/$(PACKAGE)}.
7615 @end vtable
7617 All these directory variables have values that start with either
7618 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7619 fine in @file{Makefiles}, but it makes these variables hard to use in
7620 @file{configure}.  This is mandated by the GNU coding standards, so
7621 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7622 manual has a section with more details on this topic
7623 (@pxref{Installation Directory Variables, , Installation Directory
7624 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7625 Install Paths}.
7628 @node Documentation
7629 @chapter Building documentation
7631 Currently Automake provides support for Texinfo and man pages.
7633 @menu
7634 * Texinfo::                     Texinfo
7635 * Man Pages::                   Man pages
7636 @end menu
7639 @node Texinfo
7640 @section Texinfo
7642 @cindex @code{_TEXINFOS} primary, defined
7643 @cindex @code{TEXINFOS} primary, defined
7644 @cindex Primary variable, @code{TEXINFOS}
7645 @cindex HTML output using Texinfo
7646 @cindex PDF output using Texinfo
7647 @cindex PS output using Texinfo
7648 @cindex DVI output using Texinfo
7649 @vindex _TEXINFOS
7650 @vindex info_TEXINFOS
7652 If the current directory contains Texinfo source, you must declare it
7653 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7654 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7655 here.  Any Texinfo source file must end in the @file{.texi},
7656 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7657 for new manuals.
7659 Automake generates rules to build @file{.info}, @file{.dvi},
7660 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7661 sources.  Following the GNU Coding Standards, only the @file{.info}
7662 files are built by @samp{make all} and installed by @samp{make
7663 install} (unless you use @option{no-installinfo}, see below).
7664 Furthermore, @file{.info} files are automatically distributed so that
7665 Texinfo is not a prerequisite for installing your package.
7667 @trindex dvi
7668 @trindex html
7669 @trindex pdf
7670 @trindex ps
7671 @trindex install-dvi
7672 @trindex install-html
7673 @trindex install-pdf
7674 @trindex install-ps
7675 Other documentation formats can be built on request by @samp{make
7676 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7677 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7678 @samp{make install-pdf} and @samp{make install-html} explicitly.
7679 @samp{make uninstall} will remove everything: the Texinfo
7680 documentation installed by default as well as all the above optional
7681 formats.
7683 All these targets can be extended using @samp{-local} rules
7684 (@pxref{Extending}).
7686 @cindex Texinfo flag, @code{VERSION}
7687 @cindex Texinfo flag, @code{UPDATED}
7688 @cindex Texinfo flag, @code{EDITION}
7689 @cindex Texinfo flag, @code{UPDATED-MONTH}
7691 @cindex @code{VERSION} Texinfo flag
7692 @cindex @code{UPDATED} Texinfo flag
7693 @cindex @code{EDITION} Texinfo flag
7694 @cindex @code{UPDATED-MONTH} Texinfo flag
7696 @cindex @file{mdate-sh}
7698 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7699 that file will be automatically generated.  The file @file{version.texi}
7700 defines four Texinfo flag you can reference using
7701 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7702 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7704 @table @code
7705 @item EDITION
7706 @itemx VERSION
7707 Both of these flags hold the version number of your program.  They are
7708 kept separate for clarity.
7710 @item UPDATED
7711 This holds the date the primary @file{.texi} file was last modified.
7713 @item UPDATED-MONTH
7714 This holds the name of the month in which the primary @file{.texi} file
7715 was last modified.
7716 @end table
7718 The @file{version.texi} support requires the @command{mdate-sh}
7719 script; this script is supplied with Automake and automatically
7720 included when @command{automake} is invoked with the
7721 @option{--add-missing} option.
7723 If you have multiple Texinfo files, and you want to use the
7724 @file{version.texi} feature, then you have to have a separate version
7725 file for each Texinfo file.  Automake will treat any include in a
7726 Texinfo file that matches @file{vers*.texi} just as an automatically
7727 generated version file.
7729 Sometimes an info file actually depends on more than one @file{.texi}
7730 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7731 @file{gpl.texi}.  You can tell Automake about these dependencies using
7732 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7733 @vindex TEXINFOS
7734 @vindex _TEXINFOS
7736 @example
7737 info_TEXINFOS = hello.texi
7738 hello_TEXINFOS = gpl.texi
7739 @end example
7741 @cindex @file{texinfo.tex}
7743 By default, Automake requires the file @file{texinfo.tex} to appear in
7744 the same directory as the @file{Makefile.am} file that lists the
7745 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7746 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7747 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7748 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
7749 @option{--add-missing} is given, and takes care of its distribution.
7750 However, if you set the @code{TEXINFO_TEX} variable (see below),
7751 it overrides the location of the file and turns off its installation
7752 into the source as well as its distribution.
7754 The option @option{no-texinfo.tex} can be used to eliminate the
7755 requirement for the file @file{texinfo.tex}.  Use of the variable
7756 @code{TEXINFO_TEX} is preferable, however, because that allows the
7757 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7759 @cindex Option, @code{no-installinfo}
7760 @cindex Target, @code{install-info}
7761 @cindex @code{install-info} target
7762 @cindex @code{no-installinfo} option
7764 @opindex no-installinfo
7765 @trindex install-info
7767 Automake generates an @code{install-info} rule; some people apparently
7768 use this.  By default, info pages are installed by @samp{make
7769 install}, so running @code{make install-info} is pointless.  This can
7770 be prevented via the @code{no-installinfo} option.  In this case,
7771 @file{.info} files are not installed by default, and user must
7772 request this explicitly using @samp{make install-info}.
7774 The following variables are used by the Texinfo build rules.
7776 @vtable @code
7777 @item MAKEINFO
7778 The name of the program invoked to build @file{.info} files.  This
7779 variable is defined by Automake.  If the @command{makeinfo} program is
7780 found on the system then it will be used by default; otherwise
7781 @command{missing} will be used instead.
7783 @item MAKEINFOHTML
7784 The command invoked to build @file{.html} files.  Automake
7785 defines this to @samp{$(MAKEINFO) --html}.
7787 @item MAKEINFOFLAGS
7788 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7789 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7790 not expected to be defined in any @file{Makefile}; it can be used by
7791 users to pass extra flags to suit their needs.
7793 @item AM_MAKEINFOFLAGS
7794 @itemx AM_MAKEINFOHTMLFLAGS
7795 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7796 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7797 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7798 passed to @code{makeinfo} when building @file{.info} files; and
7799 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7800 files.
7802 For instance, the following setting can be used to obtain one single
7803 @file{.html} file per manual, without node separators.
7804 @example
7805 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7806 @end example
7808 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7809 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7810 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7811 and @file{.html} files.
7813 @item TEXI2DVI
7814 The name of the command that converts a @file{.texi} file into a
7815 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7816 with the Texinfo package.
7818 @item TEXI2PDF
7819 The name of the command that translates a @file{.texi} file into a
7820 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7822 @item DVIPS
7823 The name of the command that builds a @file{.ps} file out of a
7824 @file{.dvi} file.  This defaults to @samp{dvips}.
7826 @item TEXINFO_TEX
7828 If your package has Texinfo files in many directories, you can use the
7829 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7830 @file{texinfo.tex} for your package.  The value of this variable should
7831 be the relative path from the current @file{Makefile.am} to
7832 @file{texinfo.tex}:
7834 @example
7835 TEXINFO_TEX = ../doc/texinfo.tex
7836 @end example
7837 @end vtable
7840 @node Man Pages
7841 @section Man Pages
7843 @cindex @code{_MANS} primary, defined
7844 @cindex @code{MANS} primary, defined
7845 @cindex Primary variable, @code{MANS}
7847 @vindex _MANS
7848 @vindex man_MANS
7849 A package can also include man pages (but see the GNU standards on this
7850 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7851 pages are declared using the @code{MANS} primary.  Generally the
7852 @code{man_MANS} variable is used.  Man pages are automatically installed in
7853 the correct subdirectory of @code{mandir}, based on the file extension.
7855 File extensions such as @file{.1c} are handled by looking for the valid
7856 part of the extension and using that to determine the correct
7857 subdirectory of @code{mandir}.  Valid section names are the digits
7858 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7860 Sometimes developers prefer to name a man page something like
7861 @file{foo.man} in the source, and then rename it to have the correct
7862 suffix, for example @file{foo.1}, when installing the file.  Automake
7863 also supports this mode.  For a valid section named @var{SECTION},
7864 there is a corresponding directory named @samp{man@var{SECTION}dir},
7865 and a corresponding @code{_MANS} variable.  Files listed in such a
7866 variable are installed in the indicated section.  If the file already
7867 has a valid suffix, then it is installed as-is; otherwise the file
7868 suffix is changed to match the section.
7870 For instance, consider this example:
7871 @example
7872 man1_MANS = rename.man thesame.1 alsothesame.1c
7873 @end example
7875 @noindent
7876 In this case, @file{rename.man} will be renamed to @file{rename.1} when
7877 installed, but the other files will keep their names.
7879 @cindex Target, @code{install-man}
7880 @cindex Option, @option{no-installman}
7881 @cindex @code{install-man} target
7882 @cindex @option{no-installman} option
7883 @opindex no-installman
7884 @trindex install-man
7886 By default, man pages are installed by @samp{make install}.  However,
7887 since the GNU project does not require man pages, many maintainers do
7888 not expend effort to keep the man pages up to date.  In these cases, the
7889 @option{no-installman} option will prevent the man pages from being
7890 installed by default.  The user can still explicitly install them via
7891 @samp{make install-man}.
7893 For fast installation, with many files it is preferable to use
7894 @samp{man@var{SECTION}_MANS} over @samp{man_MANS} as well as files that
7895 do not need to be renamed.
7897 Man pages are not currently considered to be source, because it is not
7898 uncommon for man pages to be automatically generated.  Therefore they
7899 are not automatically included in the distribution.  However, this can
7900 be changed by use of the @code{dist_} prefix.  For instance here is
7901 how to distribute and install the two man pages of GNU @command{cpio}
7902 (which includes both Texinfo documentation and man pages):
7904 @example
7905 dist_man_MANS = cpio.1 mt.1
7906 @end example
7908 The @code{nobase_} prefix is meaningless for man pages and is
7909 disallowed.
7911 @vindex notrans_
7912 @cindex @code{notrans_} prefix
7913 @cindex Man page renaming, avoiding
7914 @cindex Avoiding man page renaming
7916 Executables and manpages may be renamed upon installation
7917 (@pxref{Renaming}).  For manpages this can be avoided by use of the
7918 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
7919 allowing to access a library function @samp{foo} from the command line.
7920 The way to avoid renaming of the @file{foo.3} manpage is:
7922 @example
7923 man_MANS = foo.1
7924 notrans_man_MANS = foo.3
7925 @end example
7927 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
7928 @cindex @code{dist_} and @code{notrans_}
7929 @cindex @code{nodist_} and @code{notrans_}
7931 @samp{notrans_} must be specified first when used in conjunction with
7932 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
7933 Control}).  For instance:
7935 @example
7936 notrans_dist_man3_MANS = bar.3
7937 @end example
7939 @node Install
7940 @chapter What Gets Installed
7942 @cindex Installation support
7943 @cindex @samp{make install} support
7945 Naturally, Automake handles the details of actually installing your
7946 program once it has been built.  All files named by the various
7947 primaries are automatically installed in the appropriate places when the
7948 user runs @samp{make install}.
7950 @menu
7951 * Basics of Installation::      What gets installed where
7952 * The Two Parts of Install::    Installing data and programs separately
7953 * Extending Installation::      Adding your own rules for installation
7954 * Staged Installs::             Installation in a temporary location
7955 * Install Rules for the User::  Useful additional rules
7956 @end menu
7958 @node Basics of Installation
7959 @section Basics of Installation
7961 A file named in a primary is installed by copying the built file into
7962 the appropriate directory.  The base name of the file is used when
7963 installing.
7965 @example
7966 bin_PROGRAMS = hello subdir/goodbye
7967 @end example
7969 In this example, both @samp{hello} and @samp{goodbye} will be installed
7970 in @samp{$(bindir)}.
7972 Sometimes it is useful to avoid the basename step at install time.  For
7973 instance, you might have a number of header files in subdirectories of
7974 the source tree that are laid out precisely how you want to install
7975 them.  In this situation you can use the @code{nobase_} prefix to
7976 suppress the base name step.  For example:
7978 @example
7979 nobase_include_HEADERS = stdio.h sys/types.h
7980 @end example
7982 @noindent
7983 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
7984 in @samp{$(includedir)/sys}.
7986 For most file types, Automake will install multiple files at once, while
7987 avoiding command line length issues (@pxref{Length Limitations}).  Since
7988 some @command{install} programs will not install the same file twice in
7989 one invocation, you may need to ensure that file lists are unique within
7990 one variable such as @samp{nobase_include_HEADERS} above.
7992 You should not rely on the order in which files listed in one variable
7993 are installed.  Likewise, to cater for parallel make, you should not
7994 rely on any particular file installation order even among different
7995 file types (library dependencies are an exception here).
7998 @node The Two Parts of Install
7999 @section The Two Parts of Install
8001 Automake generates separate @code{install-data} and @code{install-exec}
8002 rules, in case the installer is installing on multiple machines that
8003 share directory structure---these targets allow the machine-independent
8004 parts to be installed only once.  @code{install-exec} installs
8005 platform-dependent files, and @code{install-data} installs
8006 platform-independent files.  The @code{install} target depends on both
8007 of these targets.  While Automake tries to automatically segregate
8008 objects into the correct category, the @file{Makefile.am} author is, in
8009 the end, responsible for making sure this is done correctly.
8010 @trindex install-data
8011 @trindex install-exec
8012 @trindex install
8013 @cindex Install, two parts of
8015 Variables using the standard directory prefixes @samp{data},
8016 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8017 @samp{pkgdata}, or @samp{pkginclude} are installed by
8018 @code{install-data}.
8020 Variables using the standard directory prefixes @samp{bin},
8021 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8022 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8024 For instance, @code{data_DATA} files are installed by @code{install-data},
8025 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8027 Any variable using a user-defined directory prefix with @samp{exec} in
8028 the name (e.g., @code{myexecbin_PROGRAMS}) is installed by
8029 @code{install-exec}.  All other user-defined prefixes are installed by
8030 @code{install-data}.
8032 @node Extending Installation
8033 @section Extending Installation
8035 It is possible to extend this mechanism by defining an
8036 @code{install-exec-local} or @code{install-data-local} rule.  If these
8037 rules exist, they will be run at @samp{make install} time.  These
8038 rules can do almost anything; care is required.
8039 @trindex install-exec-local
8040 @trindex install-data-local
8042 Automake also supports two install hooks, @code{install-exec-hook} and
8043 @code{install-data-hook}.  These hooks are run after all other install
8044 rules of the appropriate type, exec or data, have completed.  So, for
8045 instance, it is possible to perform post-installation modifications
8046 using an install hook.  @xref{Extending}, for some examples.
8047 @cindex Install hook
8049 @node Staged Installs
8050 @section Staged Installs
8052 @vindex DESTDIR
8053 Automake generates support for the @code{DESTDIR} variable in all
8054 install rules.  @code{DESTDIR} is used during the @samp{make install}
8055 step to relocate install objects into a staging area.  Each object and
8056 path is prefixed with the value of @code{DESTDIR} before being copied
8057 into the install area.  Here is an example of typical DESTDIR usage:
8059 @example
8060 mkdir /tmp/staging &&
8061 make DESTDIR=/tmp/staging install
8062 @end example
8064 The @command{mkdir} command avoids a security problem if the attacker
8065 creates a symbolic link from @file{/tmp/staging} to a victim area;
8066 then @command{make} places install objects in a directory tree built under
8067 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8068 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8069 would install @file{/tmp/staging/gnu/bin/foo} and
8070 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8072 This feature is commonly used to build install images and packages
8073 (@pxref{DESTDIR}).
8075 Support for @code{DESTDIR} is implemented by coding it directly into
8076 the install rules.  If your @file{Makefile.am} uses a local install
8077 rule (e.g., @code{install-exec-local}) or an install hook, then you
8078 must write that code to respect @code{DESTDIR}.
8080 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8081 for another usage example.
8083 @node Install Rules for the User
8084 @section Install Rules for the User
8086 Automake also generates rules for targets @code{uninstall},
8087 @code{installdirs}, and @code{install-strip}.
8088 @trindex uninstall
8089 @trindex installdirs
8090 @trindex install-strip
8092 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8093 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8094 these features would not provide additional functionality.
8096 Note that @code{uninstall} is not meant as a replacement for a real
8097 packaging tool.
8100 @node Clean
8101 @chapter What Gets Cleaned
8103 @cindex @samp{make clean} support
8105 The GNU Makefile Standards specify a number of different clean rules.
8106 @xref{Standard Targets, , Standard Targets for Users, standards,
8107 The GNU Coding Standards}.
8109 Generally the files that can be cleaned are determined automatically by
8110 Automake.  Of course, Automake also recognizes some variables that can
8111 be defined to specify additional files to clean.  These variables are
8112 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8113 @code{MAINTAINERCLEANFILES}.
8114 @vindex MOSTLYCLEANFILES
8115 @vindex CLEANFILES
8116 @vindex DISTCLEANFILES
8117 @vindex MAINTAINERCLEANFILES
8119 @trindex mostlyclean-local
8120 @trindex clean-local
8121 @trindex distclean-local
8122 @trindex maintainer-clean-local
8123 When cleaning involves more than deleting some hard-coded list of
8124 files, it is also possible to supplement the cleaning rules with your
8125 own commands.  Simply define a rule for any of the
8126 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8127 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8128 case is deleting a directory, for instance, a directory created by the
8129 test suite:
8131 @example
8132 clean-local:
8133         -rm -rf testSubDir
8134 @end example
8136 Since @command{make} allows only one set of rules for a given target,
8137 a more extensible way of writing this is to use a separate target
8138 listed as a dependency:
8140 @example
8141 clean-local: clean-local-check
8142 .PHONY: clean-local-check
8143 clean-local-check:
8144         -rm -rf testSubDir
8145 @end example
8147 As the GNU Standards aren't always explicit as to which files should
8148 be removed by which rule, we've adopted a heuristic that we believe
8149 was first formulated by Fran@,{c}ois Pinard:
8151 @itemize @bullet
8152 @item
8153 If @command{make} built it, and it is commonly something that one would
8154 want to rebuild (for instance, a @file{.o} file), then
8155 @code{mostlyclean} should delete it.
8157 @item
8158 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8160 @item
8161 If @command{configure} built it, then @code{distclean} should delete it.
8163 @item
8164 If the maintainer built it (for instance, a @file{.info} file), then
8165 @code{maintainer-clean} should delete it.  However
8166 @code{maintainer-clean} should not delete anything that needs to exist
8167 in order to run @samp{./configure && make}.
8168 @end itemize
8170 We recommend that you follow this same set of heuristics in your
8171 @file{Makefile.am}.
8174 @node Dist
8175 @chapter What Goes in a Distribution
8177 @menu
8178 * Basics of Distribution::      Files distributed by default
8179 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8180 * The dist Hook::               A target for last-minute distribution changes
8181 * Checking the Distribution::   @samp{make distcheck} explained
8182 * The Types of Distributions::  A variety of formats and compression methods
8183 @end menu
8185 @node Basics of Distribution
8186 @section Basics of Distribution
8188 @cindex @samp{make dist}
8190 @vindex PACKAGE
8191 @vindex VERSION
8192 @trindex dist
8193 The @code{dist} rule in the generated @file{Makefile.in} can be used
8194 to generate a gzipped @code{tar} file and other flavors of archive for
8195 distribution.  The file is named based on the @code{PACKAGE} and
8196 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8197 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8198 @samp{@var{package}-@var{version}.tar.gz}.
8199 @vindex GZIP_ENV
8200 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8201 is run.  The default setting is @option{--best}.
8203 @cindex @code{m4_include}, distribution
8204 @cindex @code{include}, distribution
8205 @acindex m4_include
8206 @cmindex include
8207 For the most part, the files to distribute are automatically found by
8208 Automake: all source files are automatically included in a distribution,
8209 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
8210 has a built-in list of commonly used files that are automatically
8211 included if they are found in the current directory (either physically,
8212 or as the target of a @file{Makefile.am} rule).  This list is printed by
8213 @samp{automake --help}.  Also, files that are read by @command{configure}
8214 (i.e.@: the source files corresponding to the files specified in various
8215 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8216 automatically distributed.  Files included in @file{Makefile.am}s (using
8217 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8218 helper scripts installed with @samp{automake --add-missing} are also
8219 distributed.
8221 @vindex EXTRA_DIST
8222 Still, sometimes there are files that must be distributed, but which
8223 are not covered in the automatic rules.  These files should be listed in
8224 the @code{EXTRA_DIST} variable.  You can mention files from
8225 subdirectories in @code{EXTRA_DIST}.
8227 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8228 entire directory will be recursively copied into the distribution.
8229 Please note that this will also copy @emph{everything} in the directory,
8230 including CVS/RCS version control files.  We recommend against using
8231 this feature.
8233 @vindex SUBDIRS
8234 @vindex DIST_SUBDIRS
8235 If you define @code{SUBDIRS}, Automake will recursively include the
8236 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8237 conditionally (@pxref{Conditionals}), Automake will normally include
8238 all directories that could possibly appear in @code{SUBDIRS} in the
8239 distribution.  If you need to specify the set of directories
8240 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8241 exact list of subdirectories to include in the distribution
8242 (@pxref{Conditional Subdirectories}).
8245 @node Fine-grained Distribution Control
8246 @section Fine-grained Distribution Control
8248 @vindex dist_
8249 @vindex nodist_
8250 Sometimes you need tighter control over what does @emph{not} go into the
8251 distribution; for instance, you might have source files that are
8252 generated and that you do not want to distribute.  In this case
8253 Automake gives fine-grained control using the @code{dist} and
8254 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8255 prefixed with @code{dist_} to add the listed files to the distribution.
8256 Similarly, @code{nodist_} can be used to omit the files from the
8257 distribution.
8259 As an example, here is how you would cause some data to be distributed
8260 while leaving some source code out of the distribution:
8262 @example
8263 dist_data_DATA = distribute-this
8264 bin_PROGRAMS = foo
8265 nodist_foo_SOURCES = do-not-distribute.c
8266 @end example
8268 @node The dist Hook
8269 @section The dist Hook
8271 @trindex dist-hook
8273 Occasionally it is useful to be able to change the distribution before
8274 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8275 after the distribution directory is filled, but before the actual tar
8276 (or shar) file is created.  One way to use this is for distributing
8277 files in subdirectories for which a new @file{Makefile.am} is overkill:
8279 @example
8280 dist-hook:
8281         mkdir $(distdir)/random
8282         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
8283 @end example
8285 Another way to use this is for removing unnecessary files that get
8286 recursively included by specifying a directory in EXTRA_DIST:
8288 @example
8289 EXTRA_DIST = doc
8291 dist-hook:
8292         rm -rf `find $(distdir)/doc -name CVS`
8293 @end example
8295 @vindex distdir
8296 @vindex top_distdir
8297 Two variables that come handy when writing @code{dist-hook} rules are
8298 @samp{$(distdir)} and @samp{$(top_distdir)}.
8300 @samp{$(distdir)} points to the directory where the @code{dist} rule
8301 will copy files from the current directory before creating the
8302 tarball.  If you are at the top-level directory, then @samp{distdir =
8303 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8304 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8305 @samp{$(distdir)} can be a relative or absolute path, do not assume
8306 any form.
8308 @samp{$(top_distdir)} always points to the root directory of the
8309 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8310 In the @file{foo/} subdirectory
8311 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8312 @samp{$(top_distdir)} too can be a relative or absolute path.
8314 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8315 (@pxref{Subpackages}), then @samp{$(distdir)} and
8316 @samp{$(top_distdir)} are relative to the package where @samp{make
8317 dist} was run, not to any sub-packages involved.
8319 @node Checking the Distribution
8320 @section Checking the Distribution
8322 @cindex @samp{make distcheck}
8323 @cindex @samp{make distcleancheck}
8324 @vindex distcleancheck_listfiles
8325 @cindex @samp{make distuninstallcheck}
8326 @vindex distuninstallcheck_listfiles
8328 @trindex distcheck
8329 Automake also generates a @code{distcheck} rule that can be of help to
8330 ensure that a given distribution will actually work.  @code{distcheck}
8331 makes a distribution, then tries to do a @code{VPATH} build
8332 (@pxref{VPATH Builds}), run the test suite, and finally make another
8333 tarball to ensure the distribution is self-contained.
8335 @vindex DISTCHECK_CONFIGURE_FLAGS
8336 Building the package involves running @samp{./configure}.  If you need
8337 to supply additional flags to @command{configure}, define them in the
8338 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
8339 @file{Makefile.am}, or on the command line when invoking @command{make}.
8341 @trindex distcheck-hook
8342 If the @code{distcheck-hook} rule is defined in your top-level
8343 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8344 the new distribution has been unpacked, but before the unpacked copy
8345 is configured and built.  Your @code{distcheck-hook} can do almost
8346 anything, though as always caution is advised.  Generally this hook is
8347 used to check for potential distribution errors not caught by the
8348 standard mechanism.  Note that @code{distcheck-hook} as well as
8349 @code{DISTCHECK_CONFIGURE_FLAGS} are not honored in a subpackage
8350 @file{Makefile.am}, but the @code{DISTCHECK_CONFIGURE_FLAGS} are
8351 passed down to the @command{configure} script of the subpackage.
8353 @trindex distcleancheck
8354 @vindex DISTCLEANFILES
8355 @vindex distcleancheck_listfiles
8356 Speaking of potential distribution errors, @code{distcheck} also
8357 ensures that the @code{distclean} rule actually removes all built
8358 files.  This is done by running @samp{make distcleancheck} at the end of
8359 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8360 @code{distclean} and then make sure the build tree has been emptied by
8361 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8362 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8363 variable (@pxref{Clean}).
8365 The @code{distcleancheck} behavior should be OK for most packages,
8366 otherwise you have the possibility to override the definition of
8367 either the @code{distcleancheck} rule, or the
8368 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8369 @code{distcleancheck} completely, add the following rule to your
8370 top-level @file{Makefile.am}:
8372 @example
8373 distcleancheck:
8374         @@:
8375 @end example
8377 If you want @code{distcleancheck} to ignore built files that have not
8378 been cleaned because they are also part of the distribution, add the
8379 following definition instead:
8381 @example
8382 distcleancheck_listfiles = \
8383   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8384        sh '@{@}' ';'
8385 @end example
8387 The above definition is not the default because it's usually an error if
8388 your Makefiles cause some distributed files to be rebuilt when the user
8389 build the package.  (Think about the user missing the tool required to
8390 build the file; or if the required tool is built by your package,
8391 consider the cross-compilation case where it can't be run.)  There is
8392 an entry in the FAQ about this (@pxref{distcleancheck}), make sure you
8393 read it before playing with @code{distcleancheck_listfiles}.
8395 @code{distcheck} also checks that the @code{uninstall} rule works
8396 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8397 by invoking @samp{make uninstall}, and then it checks the install tree
8398 to see if any files are left over.  This check will make sure that you
8399 correctly coded your @code{uninstall}-related rules.
8401 By default, the checking is done by the @code{distuninstallcheck} rule,
8402 and the list of files in the install tree is generated by
8403 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8404 a shell command to run that prints the list of files to stdout).
8406 Either of these can be overridden to modify the behavior of
8407 @code{distcheck}.  For instance, to disable this check completely, you
8408 would write:
8410 @example
8411 distuninstallcheck:
8412         @@:
8413 @end example
8415 @node The Types of Distributions
8416 @section The Types of Distributions
8418 Automake generates rules to provide archives of the project for
8419 distributions in various formats.  Their targets are:
8421 @table @asis
8422 @item @code{dist-bzip2}
8423 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8424 frequently smaller than gzipped archives.
8425 @trindex dist-bzip2
8427 @item @code{dist-gzip}
8428 Generate a gzip tar archive of the distribution.
8429 @trindex dist-gzip
8431 @item @code{dist-lzma}
8432 Generate an @samp{lzma} tar archive of the distribution.  @command{lzma}
8433 archives are frequently smaller than @command{bzip2}-compressed archives.
8434 @trindex dist-lzma
8436 @item @code{dist-shar}
8437 Generate a shar archive of the distribution.
8438 @trindex dist-shar
8440 @item @code{dist-xz}
8441 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8442 archives are frequently smaller than @command{bzip2}-compressed archives.
8443 The @samp{xz} format will soon (early 2009) displace the @samp{lzma} format.
8444 @trindex dist-xz
8446 @item @code{dist-zip}
8447 Generate a zip archive of the distribution.
8448 @trindex dist-zip
8450 @item @code{dist-tarZ}
8451 Generate a compressed tar archive of
8452 the distribution.
8453 @trindex dist-tarZ
8454 @end table
8456 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8457 create archives in all the enabled formats, @ref{Options}.  By
8458 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8461 @node Tests
8462 @chapter Support for test suites
8464 @cindex Test suites
8465 @cindex @code{make check}
8466 @trindex check
8468 Automake supports three forms of test suites, the first two of which
8469 are very similar.
8471 @menu
8472 * Simple Tests::                Listing programs and scripts in @code{TESTS}
8473 * Simple Tests using parallel-tests::  More powerful test driver
8474 * DejaGnu Tests::               Interfacing with the external testing framework
8475 * Install Tests::               Running tests on installed packages
8476 @end menu
8478 @node Simple Tests
8479 @section Simple Tests
8481 If the variable @code{TESTS} is defined, its value is taken to be a
8482 list of programs or scripts to run in order to do the testing.
8483 Programs needing data files should look for them in @code{srcdir}
8484 (which is both an environment variable and a make variable) so they
8485 work when building in a separate directory (@pxref{Build Directories,
8486 , Build Directories , autoconf, The Autoconf Manual}), and in
8487 particular for the @code{distcheck} rule (@pxref{Checking the
8488 Distribution}).
8490 For each of the @code{TESTS}, the result of execution is printed along
8491 with the test name, where @code{PASS} denotes a successful test,
8492 @code{FAIL} denotes a failed test, @code{XFAIL} an expected failure,
8493 @code{XPASS} an unexpected pass for a test that is supposed to fail,
8494 and @code{SKIP} denotes a skipped test.
8496 @cindex Exit status 77, special interpretation
8498 The number of failures will be printed at the end of the run.  If a
8499 given test program exits with a status of 77, then its result is ignored
8500 in the final count.  This feature allows non-portable tests to be
8501 ignored in environments where they don't make sense.
8503 @vindex AM_COLOR_TESTS
8504 If the Automake option @code{color-tests} is used (@pxref{Options})
8505 and standard output is connected to a capable terminal, then the test
8506 results and the summary are colored appropriately.  The user can disable
8507 colored output by setting the @command{make} variable
8508 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8509 terminal with @samp{AM_COLOR_TESTS=always}.
8511 @vindex TESTS
8512 @vindex TESTS_ENVIRONMENT
8513 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
8514 variables for the test run; the environment variable @env{srcdir} is
8515 set in the rule.  If all your test programs are scripts, you can also
8516 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
8517 @samp{$(SHELL) -x} can be useful for debugging the tests), or any other
8518 interpreter.  For instance the following setup is used by the Automake
8519 package to run four tests in Perl.
8520 @example
8521 TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
8522 TESTS = Condition.pl DisjConditions.pl Version.pl Wrap.pl
8523 @end example
8526 @cindex Tests, expected failure
8527 @cindex Expected test failure
8529 You may define the variable @code{XFAIL_TESTS} to a list of tests
8530 (usually a subset of @code{TESTS}) that are expected to fail.  This will
8531 reverse the result of those tests.
8532 @vindex XFAIL_TESTS
8534 Automake ensures that each file listed in @code{TESTS} is built before
8535 any tests are run; you can list both source and derived programs (or
8536 scripts) in @code{TESTS}; the generated rule will look both in
8537 @code{srcdir} and @file{.}.  For instance, you might want to run a C
8538 program as a test.  To do this you would list its name in @code{TESTS}
8539 and also in @code{check_PROGRAMS}, and then specify it as you would
8540 any other program.
8542 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8543 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8544 not during @code{make all}.  You should list there any program needed
8545 by your tests that does not need to be built by @code{make all}.  Note
8546 that @code{check_PROGRAMS} are @emph{not} automatically added to
8547 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8548 by the tests, not the tests themselves.  Of course you can set
8549 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8552 @node Simple Tests using parallel-tests
8553 @section Simple Tests using @samp{parallel-tests}
8554 @cindex @option{parallel-tests}, Using
8556 The option @option{parallel-tests} (@pxref{Options}) enables a test
8557 suite driver that is mostly compatible to the simple test driver described
8558 in the previous section, but provides a few more features and slightly different
8559 semantics.  It features concurrent execution of tests with @code{make -j},
8560 allows to specify inter-test dependencies, lazy reruns of tests that
8561 have not completed in a prior run, summary and verbose output in
8562 @samp{RST} (reStructuredText) and @samp{HTML} format, and hard errors
8563 for exceptional failures.  Similar to the simple test driver,
8564 @code{TESTS_ENVIRONMENT}, @code{AM_COLOR_TESTS}, @code{XFAIL_TESTS}, and
8565 the @code{check_*} variables are honored, and the environment variable
8566 @env{srcdir} is set during test execution.
8568 This test driver is still experimental and may undergo changes in order
8569 to satisfy additional portability requirements.
8571 @vindex TEST_SUITE_LOG
8572 @vindex TESTS
8573 The driver operates by defining a set of @command{make} rules to create
8574 a summary log file, @code{TEST_SUITE_LOG}, which defaults to
8575 @file{test-suite.log} and requires a @file{.log} suffix.  This file
8576 depends upon log files created for each single test program listed in
8577 @code{TESTS}, which in turn contain all output produced by the
8578 corresponding tests.
8580 @vindex TEST_EXTENSIONS
8581 @vindex TEST_LOGS
8582 Each log file is created when the corresponding test has completed.
8583 The set of log files is listed in the read-only variable
8584 @code{TEST_LOGS}, and defaults to @code{TESTS}, with the executable
8585 extension if any (@pxref{EXEEXT}), as well as any suffix listed in
8586 @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
8587 @code{TEST_EXTENSIONS} defaults to @file{.test}.  Results are undefined
8588 if a test file name ends in several concatenated suffixes.
8590 @vindex _LOG_COMPILE
8591 @vindex _LOG_COMPILER
8592 @vindex _LOG_FLAGS
8593 @vindex LOG_COMPILE
8594 @vindex LOG_COMPILER
8595 @vindex LOG_FLAGS
8596 @vindex @var{EXT}_LOG_COMPILE
8597 @vindex @var{EXT}_LOG_COMPILER
8598 @vindex @var{EXT}_LOG_FLAGS
8599 @vindex AM_@var{EXT}_LOG_FLAGS
8600 @vindex AM_LOG_FLAGS
8601 For tests that match an extension @code{.@var{ext}} listed in
8602 @code{TEST_EXTENSIONS}, you can provide a test driver using the variable
8603 @code{@var{ext}_LOG_COMPILER} (note the upper-case extension) and pass
8604 options in @code{AM_@var{ext}_LOG_FLAGS} and allow the user to pass
8605 options in @code{@var{ext}_LOG_FLAGS}.  It will cause all tests with
8606 this extension to be called with this driver.  For all tests without a
8607 registered extension, the variables @code{LOG_COMPILER},
8608 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
8610 @example
8611 TESTS = foo.pl bar.py baz
8612 TEST_EXTENSIONS = .pl .py
8613 PL_LOG_COMPILER = $(PERL)
8614 AM_PL_LOG_FLAGS = -w
8615 PY_LOG_COMPILER = $(PYTHON)
8616 AM_PY_LOG_FLAGS = -v
8617 LOG_COMPILER = ./wrapper-script
8618 AM_LOG_FLAGS = -d
8619 @end example
8621 @noindent
8622 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
8623 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
8624 @file{bar.log}, and @file{baz.log}, respectively.  The
8625 @samp{TESTS_ENVIRONMENT} variable is still expanded before the driver,
8626 but should be reserved for the user.
8628 @vindex VERBOSE
8629 As with the simple driver above, by default one status line is printed
8630 per completed test, and a short summary after the suite has completed.
8631 However, standard output and standard error of the test are redirected
8632 to a per-test log file, so that parallel execution does not produce
8633 intermingled output.  The output from failed tests is collected in the
8634 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
8635 file is output after the summary.  For best results, the tests should be
8636 verbose by default now.
8638 @trindex mostlyclean
8639 @trindex check-html
8640 @vindex RST2HTML
8641 @vindex TEST_SUITE_HTML
8642 With @code{make check-html}, the log files may be converted from RST
8643 (reStructuredText, see @uref{http://docutils.sourceforge.net/@/rst.html})
8644 to HTML using @samp{RST2HTML}, which defaults to @command{rst2html} or
8645 @command{rst2html.py}.  The variable @samp{TEST_SUITE_HTML} contains the
8646 set of converted log files.  The log and HTML files are removed upon
8647 @code{make mostlyclean}.
8649 @vindex DISABLE_HARD_ERRORS
8650 @cindex Exit status 99, special interpretation
8651 @cindex hard error
8652 Even in the presence of expected failures (see @code{XFAIL_TESTS}, there
8653 may be conditions under which a test outcome needs attention.  For
8654 example, with test-driven development, you may write tests for features
8655 that you have not implemented yet, and thus mark these tests as expected
8656 to fail.  However, you may still be interested in exceptional conditions,
8657 for example, tests that fail due to a segmentation violation or another
8658 error that is independent of the feature awaiting implementation.
8659 Tests can exit with an exit status of 99 to signal such a @emph{hard
8660 error}.  Unless the variable @code{DISABLE_HARD_ERRORS} is set to a
8661 nonempty value, such tests will be counted as failed.
8663 By default, the test suite driver will run all tests, but there are
8664 several ways to limit the set of tests that are run:
8666 @itemize @bullet
8667 @item
8668 You can set the @code{TESTS} variable, similarly to how you can with
8669 the simple test driver from the previous section.  For example, you can
8670 use a command like this to run only a subset of the tests:
8672 @example
8673 env TESTS="foo.test bar.test" make -e check
8674 @end example
8676 @item
8677 You can set the @code{TEST_LOGS} variable.  By default, this variable is
8678 computed at @command{make} run time from the value of @code{TESTS} as
8679 described above.  For example, you can use the following:
8681 @example
8682 set x subset*.log; shift
8683 env TEST_LOGS="foo.log $*" make -e check
8684 @end example
8686 @item
8687 @vindex RECHECK_LOGS
8688 @cindex lazy test execution
8689 By default, the test driver removes all old per-test log files before it
8690 starts running tests to regenerate them.  The variable
8691 @code{RECHECK_LOGS} contains the set of log files which are removed.
8692 @code{RECHECK_LOGS} defaults to @code{TEST_LOGS}, which means all tests
8693 need to be rechecked.  By overriding this variable, you can choose which
8694 tests need to be reconsidered.  For example, you can lazily rerun only
8695 those tests which are outdated, i.e., older than their prerequisite test
8696 files, by setting this variable to the empty value:
8698 @example
8699 env RECHECK_LOGS= make -e check
8700 @end example
8702 @item
8703 @trindex recheck
8704 @trindex recheck-html
8705 You can ensure that all tests are rerun which have failed or passed
8706 unexpectedly, by running @code{make recheck} in the test directory.
8707 This convenience target will set @code{RECHECK_LOGS} appropriately
8708 before invoking the main test driver.  The @code{recheck-html} target
8709 does the same as @code{recheck} but again converts the resulting log
8710 file in HTML format, like the @code{check-html} target.
8711 @end itemize
8713 In order to guarantee an ordering between tests even with @code{make
8714 -j@var{N}}, dependencies between the corresponding log files may be
8715 specified through usual @command{make} dependencies.  For example, the
8716 following snippet lets the test named @file{foo-execute.test} depend
8717 upon completion of the test @file{foo-compile.test}:
8719 @example
8720 TESTS = foo-compile.test foo-execute.test
8721 foo-execute.log: foo-compile.log
8722 @end example
8724 @noindent
8725 Please note that this ordering ignores the @emph{results} of required
8726 tests, thus the test @file{foo-execute.test} is run even if the test
8727 @file{foo-compile.test} failed or was skipped beforehand.  Further,
8728 please note that specifying such dependencies currently works only for
8729 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
8731 Tests without such specified dependencies may be run concurrently with
8732 parallel @command{make -j@var{N}}, so be sure they are prepared for
8733 concurrent execution.
8735 @cindex Unit tests
8736 The combination of lazy test execution and correct dependencies between
8737 tests and their sources may be exploited for efficient unit testing
8738 during development.  To further speed up the edit-compile-test cycle, it
8739 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
8740 instead of with @code{check_PROGRAMS}, as the former allows intertwined
8741 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
8742 not cleaned automatically, @pxref{Uniform}).
8744 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
8745 conditional parts as well as configure substitutions.  In the latter
8746 case, however, certain restrictions apply: substituted test names
8747 must end with a nonempty test suffix like @file{.test}, so that one of
8748 the inference rules generated by @command{automake} can apply.  For
8749 literal test names, @command{automake} can generate per-target rules
8750 to avoid this limitation.
8752 Please note that it is currently not possible to use @code{$(srcdir)/}
8753 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
8754 limitation is necessary to avoid generating test logs in the source tree
8755 and has the unfortunate consequence that it is not possible to specify
8756 distributed tests that are themselves generated by means of explicit
8757 rules, in a way that is portable to all @command{make} implementations
8758 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
8759 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
8760 In case of doubt you may want to require to use GNU @command{make},
8761 or work around the issue with inference rules to generate the tests.
8764 @node DejaGnu Tests
8765 @section DejaGnu Tests
8767 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
8768 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
8769 assumed.  The variable @code{DEJATOOL} is a list of names that are
8770 passed, one at a time, as the @option{--tool} argument to
8771 @command{runtest} invocations; it defaults to the name of the package.
8773 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
8774 @option{--srcdir} flags that are passed to dejagnu by default; this can be
8775 overridden if necessary.
8776 @vindex RUNTESTDEFAULTFLAGS
8778 The variables @code{EXPECT} and @code{RUNTEST} can
8779 also be overridden to provide project-specific values.  For instance,
8780 you will need to do this if you are testing a compiler toolchain,
8781 because the default values do not take into account host and target
8782 names.
8783 @opindex dejagnu
8784 @vindex DEJATOOL
8785 @vindex EXPECT
8786 @vindex RUNTEST
8788 The contents of the variable @code{RUNTESTFLAGS} are passed to the
8789 @code{runtest} invocation.  This is considered a ``user variable''
8790 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
8791 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
8792 @vindex RUNTESTFLAGS
8793 @vindex AM_RUNTESTFLAGS
8795 @cindex @file{site.exp}
8796 Automake will generate rules to create a local @file{site.exp} file,
8797 defining various variables detected by @command{configure}.  This file
8798 is automatically read by DejaGnu.  It is OK for the user of a package
8799 to edit this file in order to tune the test suite.  However this is
8800 not the place where the test suite author should define new variables:
8801 this should be done elsewhere in the real test suite code.
8802 Especially, @file{site.exp} should not be distributed.
8804 For more information regarding DejaGnu test suites, see @ref{Top, , ,
8805 dejagnu, The DejaGnu Manual}.
8807 In either case, the testing is done via @samp{make check}.
8809 @node Install Tests
8810 @section Install Tests
8812 The @code{installcheck} target is available to the user as a way to
8813 run any tests after the package has been installed.  You can add tests
8814 to this by writing an @code{installcheck-local} rule.
8817 @node Rebuilding
8818 @chapter Rebuilding Makefiles
8819 @cindex rebuild rules
8821 Automake generates rules to automatically rebuild @file{Makefile}s,
8822 @file{configure}, and other derived files like @file{Makefile.in}.
8824 @acindex AM_MAINTAINER_MODE
8825 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
8826 these automatic rebuilding rules are only enabled in maintainer mode.
8828 @vindex ACLOCAL_AMFLAGS
8829 Sometimes you need to run @command{aclocal} with an argument like
8830 @option{-I} to tell it where to find @file{.m4} files.  Since
8831 sometimes @command{make} will automatically run @command{aclocal}, you
8832 need a way to specify these arguments.  You can do this by defining
8833 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
8834 to @command{aclocal}.  This variable is only useful in the top-level
8835 @file{Makefile.am}.
8837 @vindex CONFIG_STATUS_DEPENDENCIES
8838 @vindex CONFIGURE_DEPENDENCIES
8839 @cindex @file{version.sh}, example
8840 @cindex @file{version.m4}, example
8842 Sometimes it is convenient to supplement the rebuild rules for
8843 @file{configure} or @file{config.status} with additional dependencies.
8844 The variables @code{CONFIGURE_DEPENDENCIES} and
8845 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
8846 dependencies.  These variable should be defined in all
8847 @file{Makefile}s of the tree (because these two rebuild rules are
8848 output in all them), so it is safer and easier to @code{AC_SUBST} them
8849 from @file{configure.ac}.  For instance, the following statement will
8850 cause @file{configure} to be rerun each time @file{version.sh} is
8851 changed.
8852 @example
8853 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
8854 @end example
8855 @noindent
8856 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
8857 is to be used in all @file{Makefile}s, its value must be sensible at
8858 any level in the build hierarchy.
8860 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
8861 @code{CONFIG_STATUS_DEPENDENCIES}.
8863 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
8864 @file{configure} rule, whose effect is to run @command{autoconf}.  This
8865 variable should be seldom used, because @command{automake} already tracks
8866 @code{m4_include}d files.  However it can be useful when playing
8867 tricky games with @code{m4_esyscmd} or similar non-recommendable
8868 macros with side effects.
8870 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
8871 @file{config.status} rule, whose effect is to run @file{configure}.
8872 This variable should therefore carry any non-standard source that may
8873 be read as a side effect of running @command{configure}, like @file{version.sh}
8874 in the example above.
8876 Speaking of @file{version.sh} scripts, we recommend against them
8877 today.  They are mainly used when the version of a package is updated
8878 automatically by a script (e.g., in daily builds).  Here is what some
8879 old-style @file{configure.ac}s may look like:
8880 @example
8881 AC_INIT
8882 . $srcdir/version.sh
8883 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
8884 @dots{}
8885 @end example
8886 @noindent
8887 Here, @file{version.sh} is a shell fragment that sets
8888 @code{VERSION_NUMBER}.  The problem with this example is that
8889 @command{automake} cannot track dependencies (listing @file{version.sh}
8890 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
8891 to the user), and that it uses the obsolete form of @code{AC_INIT} and
8892 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
8893 straightforward, because shell variables are not allowed in
8894 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
8895 replaced by an M4 file that is included by @file{configure.ac}:
8896 @example
8897 m4_include([version.m4])
8898 AC_INIT([name], VERSION_NUMBER)
8899 AM_INIT_AUTOMAKE
8900 @dots{}
8901 @end example
8902 @noindent
8903 Here @file{version.m4} could contain something like
8904 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
8905 second form is that @command{automake} will take care of the
8906 dependencies when defining the rebuild rule, and will also distribute
8907 the file automatically.  An inconvenience is that @command{autoconf}
8908 will now be rerun each time the version number is bumped, when only
8909 @file{configure} had to be rerun in the previous setup.
8912 @node Options
8913 @chapter Changing Automake's Behavior
8915 Various features of Automake can be controlled by options.  Except where
8916 noted otherwise, options can be specified in one of several ways: Most
8917 options can be applied on a per-@file{Makefile} basis when listed in a
8918 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
8919 of these options only make sense when specified in the toplevel
8920 @file{Makefile.am} file.  Options are applied globally to all processed
8921 @file{Makefile} files when listed in the first argument of
8922 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
8923 require changes to the @command{configure} script can only be specified
8924 there.  These are annotated below.
8926 Currently understood options are:
8927 @vindex AUTOMAKE_OPTIONS
8929 @table @asis
8930 @item @option{gnits}
8931 @itemx @option{gnu}
8932 @itemx @option{foreign}
8933 @itemx @option{cygnus}
8934 @cindex Option, @option{gnits}
8935 @cindex Option, @option{gnu}
8936 @cindex Option, @option{foreign}
8937 @cindex Option, @option{cygnus}
8938 @opindex gnits
8939 @opindex gnu
8940 @opindex foreign
8941 @opindex cygnus
8943 Set the strictness as appropriate.  The @option{gnits} option also
8944 implies options @option{readme-alpha} and @option{check-news}.
8946 @item @option{ansi2knr}
8947 @itemx @option{@var{path}/ansi2knr}
8948 @cindex Option, @option{ansi2knr}
8949 @opindex ansi2knr
8950 Turn on the obsolete de-ANSI-fication feature.  @xref{ANSI}.  If preceded by a
8951 path, the generated @file{Makefile.in} will look in the specified
8952 directory to find the @file{ansi2knr} program.  The path should be a
8953 relative path to another directory in the same distribution (Automake
8954 currently does not check this).
8956 @item @option{check-news}
8957 @cindex Option, @option{check-news}
8958 @opindex check-news
8959 Cause @samp{make dist} to fail unless the current version number appears
8960 in the first few lines of the @file{NEWS} file.
8962 @item @option{color-tests}
8963 @cindex Option, @option{color-tests}
8964 @opindex color-tests
8965 Cause output of the simple test suite (@pxref{Simple Tests}) to be
8966 colorized on capable terminals.
8968 @item @option{dejagnu}
8969 @cindex Option, @option{dejagnu}
8970 @opindex dejagnu
8971 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
8973 @item @option{dist-bzip2}
8974 @cindex Option, @option{dist-bzip2}
8975 @opindex dist-bzip2
8976 Hook @code{dist-bzip2} to @code{dist}.
8977 @trindex dist-bzip2
8979 @item @option{dist-lzma}
8980 @cindex Option, @option{dist-lzma}
8981 @opindex dist-lzma
8982 Hook @code{dist-lzma} to @code{dist}.
8983 @trindex dist-lzma
8985 @item @option{dist-shar}
8986 @cindex Option, @option{dist-shar}
8987 @opindex dist-shar
8988 Hook @code{dist-shar} to @code{dist}.
8989 @trindex dist-shar
8991 @item @option{dist-zip}
8992 @cindex Option, @option{dist-zip}
8993 @opindex dist-zip
8994 Hook @code{dist-zip} to @code{dist}.
8995 @trindex dist-zip
8997 @item @option{dist-tarZ}
8998 @cindex Option, @option{dist-tarZ}
8999 @opindex dist-tarZ
9000 Hook @code{dist-tarZ} to @code{dist}.
9001 @trindex dist-tarZ
9003 @item @option{filename-length-max=99}
9004 @cindex Option, @option{filename-length-max=99}
9005 @opindex filename-length-max=99
9006 Abort if file names longer than 99 characters are found during
9007 @samp{make dist}.  Such long file names are generally considered not to
9008 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
9009 options below.  This option should be used in the top-level
9010 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
9011 @file{configure.ac}, it will be ignored otherwise.  It will also be
9012 ignored in sub-packages of nested packages (@pxref{Subpackages}).
9014 @item @option{no-define}
9015 @cindex Option, @option{no-define}
9016 @opindex no-define
9017 This option is meaningful only when passed as an argument to
9018 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
9019 @code{VERSION} variables from being @code{AC_DEFINE}d.
9021 @item @option{no-dependencies}
9022 @cindex Option, @option{no-dependencies}
9023 @opindex no-dependencies
9024 This is similar to using @option{--ignore-deps} on the command line,
9025 but is useful for those situations where you don't have the necessary
9026 bits to make automatic dependency tracking work
9027 (@pxref{Dependencies}).  In this case the effect is to effectively
9028 disable automatic dependency tracking.
9030 @item @option{no-dist}
9031 @cindex Option, @option{no-dist}
9032 @opindex no-dist
9033 Don't emit any code related to @code{dist} target.  This is useful
9034 when a package has its own method for making distributions.
9036 @item @option{no-dist-gzip}
9037 @cindex Option, @option{no-dist-gzip}
9038 @opindex no-dist-gzip
9039 Do not hook @code{dist-gzip} to @code{dist}.
9040 @trindex no-dist-gzip
9042 @item @option{no-exeext}
9043 @cindex Option, @option{no-exeext}
9044 @opindex no-exeext
9045 If your @file{Makefile.am} defines a rule for target @code{foo}, it
9046 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
9047 necessary when @code{EXEEXT} is found to be empty.  However, by
9048 default @command{automake} will generate an error for this use.  The
9049 @option{no-exeext} option will disable this error.  This is intended for
9050 use only where it is known in advance that the package will not be
9051 ported to Windows, or any other operating system using extensions on
9052 executables.
9054 @item @option{no-installinfo}
9055 @cindex Option, @option{no-installinfo}
9056 @opindex no-installinfo
9057 The generated @file{Makefile.in} will not cause info pages to be built
9058 or installed by default.  However, @code{info} and @code{install-info}
9059 targets will still be available.  This option is disallowed at
9060 @option{gnu} strictness and above.
9061 @trindex info
9062 @trindex install-info
9064 @item @option{no-installman}
9065 @cindex Option, @option{no-installman}
9066 @opindex no-installman
9067 The generated @file{Makefile.in} will not cause man pages to be
9068 installed by default.  However, an @code{install-man} target will still
9069 be available for optional installation.  This option is disallowed at
9070 @option{gnu} strictness and above.
9071 @trindex install-man
9073 @item @option{nostdinc}
9074 @cindex Option, @option{nostdinc}
9075 @opindex nostdinc
9076 This option can be used to disable the standard @option{-I} options that
9077 are ordinarily automatically provided by Automake.
9079 @item @option{no-texinfo.tex}
9080 @cindex Option, @option{no-texinfo.tex}
9081 @opindex no-texinfo.tex
9082 Don't require @file{texinfo.tex}, even if there are texinfo files in
9083 this directory.
9085 @item @option{parallel-tests}
9086 @cindex Option, @option{parallel-tests}
9087 @opindex parallel-tests
9088 Enable test suite driver for @code{TESTS} that can run tests in parallel
9089 (@pxref{Simple Tests using parallel-tests}, for more information).
9091 @item @option{readme-alpha}
9092 @cindex Option, @option{readme-alpha}
9093 @opindex readme-alpha
9094 If this release is an alpha release, and the file @file{README-alpha}
9095 exists, then it will be added to the distribution.  If this option is
9096 given, version numbers are expected to follow one of two forms.  The
9097 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
9098 element is a number; the final period and number should be left off for
9099 non-alpha releases.  The second form is
9100 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
9101 letter; it should be omitted for non-alpha releases.
9103 @item @option{silent-rules}
9104 @cindex Option, @option{silent-rules}
9105 @opindex silent-rules
9106 Enable less verbose build rules.  This can be used to let build rules
9107 output a status line of the form
9109 @example
9110   GEN @var{output-file}
9111 @end example
9113 @noindent
9114 instead of printing the command that will be executed to update
9115 @var{output-file}.  It can also silence @command{libtool} output.
9117 To enable less verbose build rules, both the developer and the user
9118 of the package have to take a number of steps.  The developer needs
9119 to do either of the following:
9121 @itemize @bullet
9122 @item
9123 Add the @option{silent-rules} option as argument to @code{AM_INIT_AUTOMAKE}.
9124 @item
9125 Call the @code{AM_SILENT_RULES} macro from within the @file{configure.ac}
9126 file.
9127 @end itemize
9129 It is not possible to instead specify @option{silent-rules} in a
9130 @file{Makefile.am} file.
9132 @cindex default verbosity for silent-rules
9133 If the developer has done either of the above, then the user of the
9134 package may influence the verbosity at @command{configure} run time as
9135 well as at @command{make} run time:
9137 @itemize @bullet
9138 @item
9139 @opindex --enable-silent-rules
9140 @opindex --disable-silent-rules
9141 Passing @option{--enable-silent-rules} to @command{configure} will cause
9142 build rules to be less verbose; the option @option{--disable-silent-rules}
9143 is the default and will cause normal verbose output.
9144 @item
9145 @vindex @code{V}
9146 At @command{make} run time, the default chosen at @command{configure}
9147 time may be overridden: @code{make V=1} will produce verbose output,
9148 @code{make V=0} less verbose output.
9149 @end itemize
9151 For portability to different @command{make} implementations, package authors
9152 are advised to not set the variable @code{V} inside the @file{Makefile.am}
9153 file, to allow the user to override the value for subdirectories as well.
9155 The current implementation of this feature relies on a non-POSIX, but in
9156 practice rather widely supported @file{Makefile} construct of nested
9157 variable expansion @samp{$(@var{var1}$(V))}.  Do not use the
9158 @option{silent-rules} option if your package needs to build with
9159 @command{make} implementations that do not support it.  The
9160 @option{silent-rules} option turns off warnings about recursive variable
9161 expansion, which are in turn enabled by @option{-Wportability}
9162 (@pxref{Invoking Automake}).
9164 @vindex @code{AM_V_GEN}
9165 @vindex @code{AM_V_at}
9166 @vindex @code{AM_DEFAULT_VERBOSITY}
9167 To extend the silent mode to your own rules, you have two choices:
9169 @itemize @bullet
9170 @item
9171 You can use the predefined variable @code{AM_V_GEN} as a prefix to
9172 commands that should output a status line in silent mode, and
9173 @code{AM_V_at} as a prefix to commands that should not output anything
9174 in silent mode.  When output is to be verbose, both of these variables
9175 will expand to the empty string.
9176 @item
9177 You can add your own variables, so strings of your own choice are shown.
9178 The following snippet shows how you would define your own equivalent of
9179 @code{AM_V_GEN}:
9181 @example
9182 pkg_verbose = $(pkg_verbose_$(V))
9183 pkg_verbose_ = $(pkg_verbose_$(AM_DEFAULT_VERBOSITY))
9184 pkg_verbose_0 = @@echo GEN $@@;
9186 foo: foo.in
9187         $(pkg_verbose)cp $(srcdir)/foo.in $@@
9188 @end example
9189 @end itemize
9192 @item @option{std-options}
9193 @cindex Options, @option{std-options}
9194 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
9195 @cindex @option{--help} check
9196 @cindex @option{--version} check
9197 @opindex std-options
9199 Make the @code{installcheck} rule check that installed scripts and
9200 programs support the @option{--help} and @option{--version} options.
9201 This also provides a basic check that the program's
9202 run-time dependencies are satisfied after installation.
9204 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
9205 In a few situations, programs (or scripts) have to be exempted from this
9206 test.  For instance, @command{false} (from GNU sh-utils) is never
9207 successful, even for @option{--help} or @option{--version}.  You can list
9208 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
9209 Programs (not scripts) listed in this variable should be suffixed by
9210 @samp{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance, suppose we
9211 build @file{false} as a program but @file{true.sh} as a script, and that
9212 neither of them support @option{--help} or @option{--version}:
9214 @example
9215 AUTOMAKE_OPTIONS = std-options
9216 bin_PROGRAMS = false ...
9217 bin_SCRIPTS = true.sh ...
9218 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
9219 @end example
9221 @item @option{subdir-objects}
9222 @cindex Options, @option{subdir-objects}
9223 @opindex subdir-objects
9224 If this option is specified, then objects are placed into the
9225 subdirectory of the build directory corresponding to the subdirectory of
9226 the source file.  For instance, if the source file is
9227 @file{subdir/file.cxx}, then the output file would be
9228 @file{subdir/file.o}.
9230 In order to use this option with C sources, you should add
9231 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
9233 @anchor{tar-formats}
9234 @item @option{tar-v7}
9235 @itemx @option{tar-ustar}
9236 @itemx @option{tar-pax}
9237 @cindex Option, @option{tar-v7}
9238 @cindex Option, @option{tar-ustar}
9239 @cindex Option, @option{tar-pax}
9240 @cindex @command{tar} formats
9241 @cindex v7 @command{tar} format
9242 @cindex ustar format
9243 @cindex pax format
9244 @opindex tar-v7
9245 @opindex tar-ustar
9246 @opindex tar-pax
9248 These three mutually exclusive options select the tar format to use
9249 when generating tarballs with @samp{make dist}.  (The tar file created
9250 is then compressed according to the set of @option{no-dist-gzip},
9251 @option{dist-bzip2}, @option{dist-lzma} and @option{dist-tarZ} options in use.)
9253 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
9254 (@pxref{Macros}) because they can require additional configure checks.
9255 Automake will complain if it sees such options in an
9256 @code{AUTOMAKE_OPTIONS} variable.
9258 @option{tar-v7} selects the old V7 tar format.  This is the historical
9259 default.  This antiquated format is understood by all tar
9260 implementations and supports file names with up to 99 characters.  When
9261 given longer file names some tar implementations will diagnose the
9262 problem while other will generate broken tarballs or use non-portable
9263 extensions.  Furthermore, the V7 format cannot store empty
9264 directories.  When using this format, consider using the
9265 @option{filename-length-max=99} option to catch file names too long.
9267 @option{tar-ustar} selects the ustar format defined by POSIX
9268 1003.1-1988.  This format is believed to be old enough to be portable.
9269 It fully supports empty directories.  It can store file names with up
9270 to 256 characters, provided that the file name can be split at
9271 directory separator in two parts, first of them being at most 155
9272 bytes long.  So, in most cases the maximum file name length will be
9273 shorter than 256 characters.  However you may run against broken tar
9274 implementations that incorrectly handle file names longer than 99
9275 characters (please report them to @email{bug-automake@@gnu.org} so we
9276 can document this accurately).
9278 @option{tar-pax} selects the new pax interchange format defined by POSIX
9279 1003.1-2001.  It does not limit the length of file names.  However,
9280 this format is very young and should probably be restricted to
9281 packages that target only very modern platforms.  There are moves to
9282 change the pax format in an upward-compatible way, so this option may
9283 refer to a more recent version in the future.
9285 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
9286 further discussion about tar formats.
9288 @command{configure} knows several ways to construct these formats.  It
9289 will not abort if it cannot find a tool up to the task (so that the
9290 package can still be built), but @samp{make dist} will fail.
9292 @item @var{version}
9293 @cindex Option, @var{version}
9294 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
9295 newer than the version specified, creation of the @file{Makefile.in}
9296 will be suppressed.
9298 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
9299 @cindex Option, warnings
9300 @cindex Option, @option{-W@var{category}}
9301 @cindex Option, @option{--warnings=@var{category}}
9302 These options behave exactly like their command-line counterpart
9303 (@pxref{Invoking Automake}).  This allows you to enable or disable some
9304 warning categories on a per-file basis.  You can also setup some warnings
9305 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
9306 in your @file{configure.ac}.
9308 @end table
9310 Unrecognized options are diagnosed by @command{automake}.
9312 If you want an option to apply to all the files in the tree, you can use
9313 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
9314 @xref{Macros}.
9317 @node Miscellaneous
9318 @chapter Miscellaneous Rules
9320 There are a few rules and variables that didn't fit anywhere else.
9322 @menu
9323 * Tags::                        Interfacing to etags and mkid
9324 * Suffixes::                    Handling new file extensions
9325 * Multilibs::                   Support for multilibs.
9326 @end menu
9329 @node Tags
9330 @section Interfacing to @command{etags}
9332 @cindex @file{TAGS} support
9334 Automake will generate rules to generate @file{TAGS} files for use with
9335 GNU Emacs under some circumstances.
9337 @trindex tags
9338 If any C, C++ or Fortran 77 source code or headers are present, then
9339 @code{tags} and @code{TAGS} rules will be generated for the directory.
9340 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
9341 @code{_LISP} primaries will be used to generate tags.  Note that
9342 generated source files that are not distributed must be declared in
9343 variables like @code{nodist_noinst_HEADERS} or
9344 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
9346 A @code{tags} rule will be output at the topmost directory of a
9347 multi-directory package.  When run from this topmost directory,
9348 @samp{make tags} will generate a @file{TAGS} file that includes by
9349 reference all @file{TAGS} files from subdirectories.
9351 The @code{tags} rule will also be generated if the variable
9352 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
9353 directories that contain taggable source that @command{etags} does
9354 not understand.  The user can use the @code{ETAGSFLAGS} to pass
9355 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
9356 available for use in @file{Makefile.am}.
9357 @vindex ETAGS_ARGS
9358 @vindex ETAGSFLAGS
9359 @vindex AM_ETAGSFLAGS
9361 Here is how Automake generates tags for its source, and for nodes in its
9362 Texinfo file:
9364 @example
9365 ETAGS_ARGS = automake.in --lang=none \
9366  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
9367 @end example
9369 If you add file names to @code{ETAGS_ARGS}, you will probably also
9370 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
9371 are added directly to the dependencies for the @code{tags} rule.
9372 @vindex TAGS_DEPENDENCIES
9374 Automake also generates a @code{ctags} rule that can be used to
9375 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
9376 is the name of the program to invoke (by default @command{ctags});
9377 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
9378 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
9380 Automake will also generate an @code{ID} rule that will run
9381 @command{mkid} on the source.  This is only supported on a
9382 directory-by-directory basis.
9383 @trindex id
9385 Finally, Automake also emits rules to support the
9386 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
9387 The @code{GTAGS} rule runs Global Tags and puts the
9388 result in the top build directory.  The variable @code{GTAGS_ARGS}
9389 holds arguments that are passed to @command{gtags}.
9390 @vindex GTAGS_ARGS
9393 @node Suffixes
9394 @section Handling new file extensions
9396 @cindex Adding new @code{SUFFIXES}
9397 @cindex @code{SUFFIXES}, adding
9398 @vindex SUFFIXES
9400 It is sometimes useful to introduce a new implicit rule to handle a file
9401 type that Automake does not know about.
9403 For instance, suppose you had a compiler that could compile @file{.foo}
9404 files to @file{.o} files.  You would simply define a suffix rule for
9405 your language:
9407 @example
9408 .foo.o:
9409         foocc -c -o $@@ $<
9410 @end example
9412 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
9413 variable and expect the correct results:
9415 @example
9416 bin_PROGRAMS = doit
9417 doit_SOURCES = doit.foo
9418 @end example
9420 This was the simpler and more common case.  In other cases, you will
9421 have to help Automake to figure out which extensions you are defining your
9422 suffix rule for.  This usually happens when your extension does not
9423 start with a dot.  Then, all you have to do is to put a list of new
9424 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
9425 implicit rule.
9427 For instance, the following definition prevents Automake from misinterpreting
9428 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
9429 @file{.cpp} files.
9431 @example
9432 SUFFIXES = .idl C.cpp
9433 .idlC.cpp:
9434         # whatever
9435 @end example
9437 As you may have noted, the @code{SUFFIXES} variable behaves like the
9438 @code{.SUFFIXES} special target of @command{make}.  You should not touch
9439 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
9440 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
9441 @code{SUFFIXES} go at the start of the generated suffixes list, followed
9442 by Automake generated suffixes not already in the list.
9444 @node Multilibs
9445 @section Support for Multilibs
9447 Automake has support for an obscure feature called multilibs.  A
9448 @dfn{multilib} is a library that is built for multiple different ABIs
9449 at a single time; each time the library is built with a different target
9450 flag combination.  This is only useful when the library is intended to
9451 be cross-compiled, and it is almost exclusively used for compiler
9452 support libraries.
9454 The multilib support is still experimental.  Only use it if you are
9455 familiar with multilibs and can debug problems you might encounter.
9458 @node Include
9459 @chapter Include
9461 @cmindex include
9462 @cindex Including @file{Makefile} fragment
9463 @cindex @file{Makefile} fragment, including
9465 Automake supports an @code{include} directive that  can be used to
9466 include other @file{Makefile} fragments when @command{automake} is run.
9467 Note that these fragments are read and interpreted by @command{automake},
9468 not by @command{make}.  As with conditionals, @command{make} has no idea that
9469 @code{include} is in use.
9471 There are two forms of @code{include}:
9473 @table @code
9474 @item include $(srcdir)/file
9475 Include a fragment that is found relative to the current source
9476 directory.
9478 @item include $(top_srcdir)/file
9479 Include a fragment that is found relative to the top source directory.
9480 @end table
9482 Note that if a fragment is included inside a conditional, then the
9483 condition applies to the entire contents of that fragment.
9485 Makefile fragments included this way are always distributed because
9486 they are needed to rebuild @file{Makefile.in}.
9488 @node Conditionals
9489 @chapter Conditionals
9491 @cindex Conditionals
9493 Automake supports a simple type of conditionals.
9495 These conditionals are not the same as conditionals in
9496 GNU Make.  Automake conditionals are checked at configure time by the
9497 @file{configure} script, and affect the translation from
9498 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
9499 to @file{configure} and on results that @file{configure} has discovered
9500 about the host system.  GNU Make conditionals are checked at @command{make}
9501 time, and are based on variables passed to the make program or defined
9502 in the @file{Makefile}.
9504 Automake conditionals will work with any make program.
9506 @menu
9507 * Usage of Conditionals::       Declaring conditional content
9508 * Limits of Conditionals::      Enclosing complete statements
9509 @end menu
9511 @node Usage of Conditionals
9512 @section Usage of Conditionals
9514 @acindex AM_CONDITIONAL
9515 Before using a conditional, you must define it by using
9516 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
9518 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
9519 The conditional name, @var{conditional}, should be a simple string
9520 starting with a letter and containing only letters, digits, and
9521 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
9522 that are reserved by Automake.
9524 The shell @var{condition} (suitable for use in a shell @code{if}
9525 statement) is evaluated when @command{configure} is run.  Note that you
9526 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
9527 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
9528 conditionally (e.g., in a shell @code{if} statement), then the result
9529 will confuse @command{automake}.
9530 @end defmac
9532 @cindex @option{--enable-debug}, example
9533 @cindex Example conditional @option{--enable-debug}
9534 @cindex Conditional example, @option{--enable-debug}
9536 Conditionals typically depend upon options that the user provides to
9537 the @command{configure} script.  Here is an example of how to write a
9538 conditional that is true if the user uses the @option{--enable-debug}
9539 option.
9541 @example
9542 AC_ARG_ENABLE([debug],
9543 [  --enable-debug    Turn on debugging],
9544 [case "$@{enableval@}" in
9545   yes) debug=true ;;
9546   no)  debug=false ;;
9547   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
9548 esac],[debug=false])
9549 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
9550 @end example
9552 Here is an example of how to use that conditional in @file{Makefile.am}:
9554 @cmindex if
9555 @cmindex endif
9556 @cmindex else
9558 @example
9559 if DEBUG
9560 DBG = debug
9561 else
9562 DBG =
9563 endif
9564 noinst_PROGRAMS = $(DBG)
9565 @end example
9567 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
9568 (@pxref{Conditional Programs}).
9570 You may only test a single variable in an @code{if} statement, possibly
9571 negated using @samp{!}.  The @code{else} statement may be omitted.
9572 Conditionals may be nested to any depth.  You may specify an argument to
9573 @code{else} in which case it must be the negation of the condition used
9574 for the current @code{if}.  Similarly you may specify the condition
9575 that is closed by an @code{end}:
9577 @example
9578 if DEBUG
9579 DBG = debug
9580 else !DEBUG
9581 DBG =
9582 endif !DEBUG
9583 @end example
9585 @noindent
9586 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
9587 @code{endif} statements should not be indented, i.e., start on column
9588 one.
9590 The @code{else} branch of the above two examples could be omitted,
9591 since assigning the empty string to an otherwise undefined variable
9592 makes no difference.
9594 @acindex AM_COND_IF
9595 In order to allow access to the condition registered by
9596 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
9597 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
9599 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
9600 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
9601 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
9602 it will cause @command{automake} to output the rules for the respective
9603 files only for the given condition.
9604 @end defmac
9606 @code{AM_COND_IF} macros may be nested when m4 quotation is used
9607 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
9609 @cindex Example conditional @code{AC_CONFIG_FILES}
9610 @cindex @code{AC_CONFIG_FILES}, conditional
9612 Here is an example of how to define a conditional config file:
9614 @example
9615 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
9616 AM_COND_IF([SHELL_WRAPPER],
9617            [AC_CONFIG_FILES([wrapper:wrapper.in])])
9618 @end example
9620 @node Limits of Conditionals
9621 @section Limits of Conditionals
9623 Conditionals should enclose complete statements like variables or
9624 rules definitions.  Automake cannot deal with conditionals used inside
9625 a variable definition, for instance, and is not even able to diagnose
9626 this situation.  The following example would not work:
9628 @example
9629 # This syntax is not understood by Automake
9630 AM_CPPFLAGS = \
9631   -DFEATURE_A \
9632 if WANT_DEBUG
9633   -DDEBUG \
9634 endif
9635   -DFEATURE_B
9636 @end example
9638 However the intended definition of @code{AM_CPPFLAGS} can be achieved
9639 with
9641 @example
9642 if WANT_DEBUG
9643   DEBUGFLAGS = -DDEBUG
9644 endif
9645 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
9646 @end example
9648 @noindent
9651 @example
9652 AM_CPPFLAGS = -DFEATURE_A
9653 if WANT_DEBUG
9654 AM_CPPFLAGS += -DDEBUG
9655 endif
9656 AM_CPPFLAGS += -DFEATURE_B
9657 @end example
9659 More details and examples of conditionals are described alongside
9660 various Automake features in this manual (@pxref{Conditional
9661 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
9662 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
9663 Libtool Sources}).
9665 @node Gnits
9666 @chapter The effect of @option{--gnu} and @option{--gnits}
9668 @cindex @option{--gnu}, required files
9669 @cindex @option{--gnu}, complete description
9671 The @option{--gnu} option (or @option{gnu} in the
9672 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
9673 the following:
9675 @itemize @bullet
9676 @item
9677 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
9678 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
9679 or @file{COPYING}, are required at the topmost directory of the package.
9681 If the @option{--add-missing} option is given, @command{automake} will
9682 add a generic version of the @file{INSTALL} file as well as the
9683 @file{COPYING} file containing the text of the current version of the
9684 GNU General Public License existing at the time of this Automake release
9685 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
9686 However, an existing @file{COPYING} file will never be overwritten by
9687 @command{automake}.
9689 @item
9690 The options @option{no-installman} and @option{no-installinfo} are
9691 prohibited.
9692 @end itemize
9694 Note that this option will be extended in the future to do even more
9695 checking; it is advisable to be familiar with the precise requirements
9696 of the GNU standards.  Also, @option{--gnu} can require certain
9697 non-standard GNU programs to exist for use by various maintainer-only
9698 rules; for instance, in the future @command{pathchk} might be required for
9699 @samp{make dist}.
9701 @cindex @option{--gnits}, complete description
9703 The @option{--gnits} option does everything that @option{--gnu} does, and
9704 checks the following as well:
9706 @itemize @bullet
9707 @item
9708 @samp{make installcheck} will check to make sure that the @option{--help}
9709 and @option{--version} really print a usage message and a version string,
9710 respectively.  This is the @option{std-options} option (@pxref{Options}).
9712 @item
9713 @samp{make dist} will check to make sure the @file{NEWS} file has been
9714 updated to the current version.
9716 @item
9717 @code{VERSION} is checked to make sure its format complies with Gnits
9718 standards.
9719 @c FIXME xref when standards are finished
9721 @item
9722 @cindex @file{README-alpha}
9723 If @code{VERSION} indicates that this is an alpha release, and the file
9724 @file{README-alpha} appears in the topmost directory of a package, then
9725 it is included in the distribution.  This is done in @option{--gnits}
9726 mode, and no other, because this mode is the only one where version
9727 number formats are constrained, and hence the only mode where Automake
9728 can automatically determine whether @file{README-alpha} should be
9729 included.
9731 @item
9732 The file @file{THANKS} is required.
9733 @end itemize
9736 @node Cygnus
9737 @chapter The effect of @option{--cygnus}
9739 @cindex @option{cygnus} strictness
9741 Some packages, notably GNU GCC and GNU gdb, have a build environment
9742 originally written at Cygnus Support (subsequently renamed Cygnus
9743 Solutions, and then later purchased by Red Hat).  Packages with this
9744 ancestry are sometimes referred to as ``Cygnus'' trees.
9746 A Cygnus tree has slightly different rules for how a
9747 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
9748 @command{automake} will cause any generated @file{Makefile.in} to
9749 comply with Cygnus rules.
9751 Here are the precise effects of @option{--cygnus}:
9753 @itemize @bullet
9754 @item
9755 Info files are always created in the build directory, and not in the
9756 source directory.
9758 @item
9759 @file{texinfo.tex} is not required if a Texinfo source file is
9760 specified.  The assumption is that the file will be supplied, but in a
9761 place that Automake cannot find.  This assumption is an artifact of how
9762 Cygnus packages are typically bundled.
9764 @item
9765 @samp{make dist} is not supported, and the rules for it are not
9766 generated.  Cygnus-style trees use their own distribution mechanism.
9768 @item
9769 Certain tools will be searched for in the build tree as well as in the
9770 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
9771 @command{makeinfo} and @command{texi2dvi}.
9773 @item
9774 @option{--foreign} is implied.
9776 @item
9777 The options @option{no-installinfo} and @option{no-dependencies} are
9778 implied.
9780 @item
9781 The macros @code{AM_MAINTAINER_MODE} and @code{AM_CYGWIN32} are
9782 required.
9784 @item
9785 The @code{check} target doesn't depend on @code{all}.
9786 @end itemize
9788 GNU maintainers are advised to use @option{gnu} strictness in preference
9789 to the special Cygnus mode.  Some day, perhaps, the differences between
9790 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
9791 more standards compliant).  At that time the special Cygnus mode will be
9792 removed.
9795 @node Not Enough
9796 @chapter When Automake Isn't Enough
9798 In some situations, where Automake is not up to one task, one has to
9799 resort to handwritten rules or even handwritten @file{Makefile}s.
9801 @menu
9802 * Extending::                   Adding new rules or overriding existing ones.
9803 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
9804 @end menu
9806 @node Extending
9807 @section Extending Automake Rules
9809 With some minor exceptions (for example @code{_PROGRAMS} variables,
9810 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
9811 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
9812 @file{Makefile.in} verbatim.
9814 @cindex copying semantics
9816 These copying semantics mean that many problems can be worked around
9817 by simply adding some @command{make} variables and rules to
9818 @file{Makefile.am}.  Automake will ignore these additions.
9820 @cindex conflicting definitions
9821 @cindex rules, conflicting
9822 @cindex variables, conflicting
9823 @cindex definitions, conflicts
9825 Since a @file{Makefile.in} is built from data gathered from three
9826 different places (@file{Makefile.am}, @file{configure.ac}, and
9827 @command{automake} itself), it is possible to have conflicting
9828 definitions of rules or variables.  When building @file{Makefile.in}
9829 the following priorities are respected by @command{automake} to ensure
9830 the user always has the last word:
9832 @itemize
9833 @item
9834 User defined variables in @file{Makefile.am} have priority over
9835 variables @code{AC_SUBST}ed from @file{configure.ac}, and
9836 @code{AC_SUBST}ed variables have priority over
9837 @command{automake}-defined variables.
9838 @item
9839 As far as rules are concerned, a user-defined rule overrides any
9840 @command{automake}-defined rule for the same target.
9841 @end itemize
9843 @cindex overriding rules
9844 @cindex overriding semantics
9845 @cindex rules, overriding
9847 These overriding semantics make it possible to fine tune some default
9848 settings of Automake, or replace some of its rules.  Overriding
9849 Automake rules is often inadvisable, particularly in the topmost
9850 directory of a package with subdirectories.  The @option{-Woverride}
9851 option (@pxref{Invoking Automake}) comes in handy to catch overridden
9852 definitions.
9854 Note that Automake does not make any distinction between rules with
9855 commands and rules that only specify dependencies.  So it is not
9856 possible to append new dependencies to an @command{automake}-defined
9857 target without redefining the entire rule.
9859 @cindex @option{-local} targets
9860 @cindex local targets
9862 However, various useful targets have a @samp{-local} version you can
9863 specify in your @file{Makefile.am}.  Automake will supplement the
9864 standard target with these user-supplied targets.
9866 @trindex  all
9867 @trindex  all-local
9868 @trindex  info
9869 @trindex  info-local
9870 @trindex  dvi
9871 @trindex  dvi-local
9872 @trindex  ps
9873 @trindex  ps-local
9874 @trindex  pdf
9875 @trindex  pdf-local
9876 @trindex  html
9877 @trindex  html-local
9878 @trindex  check
9879 @trindex  check-local
9880 @trindex  install
9881 @trindex  install-data
9882 @trindex  install-data-local
9883 @trindex  install-dvi
9884 @trindex  install-dvi-local
9885 @trindex  install-exec
9886 @trindex  install-exec-local
9887 @trindex  install-html
9888 @trindex  install-html-local
9889 @trindex  install-info
9890 @trindex  install-info-local
9891 @trindex  install-pdf
9892 @trindex  install-pdf-local
9893 @trindex  install-ps
9894 @trindex  install-ps-local
9895 @trindex  uninstall
9896 @trindex  uninstall-local
9897 @trindex  mostlyclean
9898 @trindex  mostlyclean-local
9899 @trindex  clean
9900 @trindex  clean-local
9901 @trindex  distclean
9902 @trindex  distclean-local
9903 @trindex  installdirs
9904 @trindex  installdirs-local
9905 @trindex  installcheck
9906 @trindex  installcheck-local
9908 The targets that support a local version are @code{all}, @code{info},
9909 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
9910 @code{install-data}, @code{install-dvi}, @code{install-exec},
9911 @code{install-html}, @code{install-info}, @code{install-pdf},
9912 @code{install-ps}, @code{uninstall}, @code{installdirs},
9913 @code{installcheck} and the various @code{clean} targets
9914 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
9915 @code{maintainer-clean}).
9917 Note that there are no @code{uninstall-exec-local} or
9918 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
9919 It doesn't make sense to uninstall just data or just executables.
9921 For instance, here is one way to erase a subdirectory during
9922 @samp{make clean} (@pxref{Clean}).
9924 @example
9925 clean-local:
9926         -rm -rf testSubDir
9927 @end example
9929 You may be tempted to use @code{install-data-local} to install a file
9930 to some hard-coded location, but you should avoid this
9931 (@pxref{Hard-Coded Install Paths}).
9933 With the @code{-local} targets, there is no particular guarantee of
9934 execution order; typically, they are run early, but with parallel
9935 make, there is no way to be sure of that.
9937 @cindex @option{-hook} targets
9938 @cindex hook targets
9939 @trindex install-data-hook
9940 @trindex install-exec-hook
9941 @trindex uninstall-hook
9942 @trindex dist-hook
9944 In contrast, some rules also have a way to run another rule, called a
9945 @dfn{hook}; hooks are always executed after the main rule's work is done.
9946 The hook is named after the principal target, with @samp{-hook} appended.
9947 The targets allowing hooks are @code{install-data},
9948 @code{install-exec}, @code{uninstall}, @code{dist}, and
9949 @code{distcheck}.
9951 For instance, here is how to create a hard link to an installed program:
9953 @example
9954 install-exec-hook:
9955         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
9956            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
9957 @end example
9959 Although cheaper and more portable than symbolic links, hard links
9960 will not work everywhere (for instance, OS/2 does not have
9961 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
9962 @command{ln} does not work.  An easy way, if symbolic links are
9963 acceptable to you, is to add @code{AC_PROG_LN_S} to
9964 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
9965 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
9966 @file{Makefile.am}.
9968 @cindex versioned binaries, installing
9969 @cindex installing versioned binaries
9970 @cindex @code{LN_S} example
9971 For instance, here is how you could install a versioned copy of a
9972 program using @samp{$(LN_S)}:
9974 @example
9975 install-exec-hook:
9976         cd $(DESTDIR)$(bindir) && \
9977           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
9978           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
9979 @end example
9981 Note that we rename the program so that a new version will erase the
9982 symbolic link, not the real binary.  Also we @command{cd} into the
9983 destination directory in order to create relative links.
9985 When writing @code{install-exec-hook} or @code{install-data-hook},
9986 please bear in mind that the exec/data distinction is based on the
9987 installation directory, not on the primary used (@pxref{The Two Parts of
9988 Install}).  So a @code{foo_SCRIPTS} will be installed by
9989 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
9990 @code{install-exec}.  You should define your hooks consequently.
9992 @c FIXME should include discussion of variables you can use in these
9993 @c rules
9995 @node Third-Party Makefiles
9996 @section Third-Party @file{Makefile}s
9998 @cindex Third-party packages, interfacing with
9999 @cindex Interfacing with third-party packages
10001 In most projects all @file{Makefile}s are generated by Automake.  In
10002 some cases, however, projects need to embed subdirectories with
10003 handwritten @file{Makefile}s.  For instance, one subdirectory could be
10004 a third-party project with its own build system, not using Automake.
10006 It is possible to list arbitrary directories in @code{SUBDIRS} or
10007 @code{DIST_SUBDIRS} provided each of these directories has a
10008 @file{Makefile} that recognizes all the following recursive targets.
10010 @cindex recursive targets and third-party @file{Makefile}s
10011 When a user runs one of these targets, that target is run recursively
10012 in all subdirectories.  This is why it is important that even
10013 third-party @file{Makefile}s support them.
10015 @table @code
10016 @item all
10017 Compile the entire package.  This is the default target in
10018 Automake-generated @file{Makefile}s, but it does not need to be the
10019 default in third-party @file{Makefile}s.
10021 @item distdir
10022 @trindex distdir
10023 @vindex distdir
10024 @vindex top_distdir
10025 Copy files to distribute into @samp{$(distdir)}, before a tarball is
10026 constructed.  Of course this target is not required if the
10027 @option{no-dist} option (@pxref{Options}) is used.
10029 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
10030 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
10031 when the @code{distdir} target is invoked.  These two variables have
10032 been adjusted for the directory that is being recursed into, so they
10033 are ready to use.
10035 @item install
10036 @itemx install-data
10037 @itemx install-exec
10038 @itemx uninstall
10039 Install or uninstall files (@pxref{Install}).
10041 @item install-dvi
10042 @itemx install-html
10043 @itemx install-info
10044 @itemx install-ps
10045 @itemx install-pdf
10046 Install only some specific documentation format (@pxref{Texinfo}).
10048 @item installdirs
10049 Create install directories, but do not install any files.
10051 @item check
10052 @itemx installcheck
10053 Check the package (@pxref{Tests}).
10055 @item mostlyclean
10056 @itemx clean
10057 @itemx distclean
10058 @itemx maintainer-clean
10059 Cleaning rules (@pxref{Clean}).
10061 @item dvi
10062 @itemx pdf
10063 @itemx ps
10064 @itemx info
10065 @itemx html
10066 Build the documentation in various formats (@pxref{Texinfo}).
10068 @item tags
10069 @itemx ctags
10070 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
10071 @end table
10073 If you have ever used Gettext in a project, this is a good example of
10074 how third-party @file{Makefile}s can be used with Automake.  The
10075 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
10076 @file{intl/} directories are handwritten @file{Makefile}s that
10077 implement all these targets.  That way they can be added to
10078 @code{SUBDIRS} in Automake packages.
10080 Directories that are only listed in @code{DIST_SUBDIRS} but not in
10081 @code{SUBDIRS} need only the @code{distclean},
10082 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
10083 Subdirectories}).
10085 Usually, many of these rules are irrelevant to the third-party
10086 subproject, but they are required for the whole package to work.  It's
10087 OK to have a rule that does nothing, so if you are integrating a
10088 third-party project with no documentation or tag support, you could
10089 simply augment its @file{Makefile} as follows:
10091 @example
10092 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
10093 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
10094 $(EMPTY_AUTOMAKE_TARGETS):
10095 @end example
10097 Another aspect of integrating third-party build systems is whether
10098 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
10099 subpackage does not support VPATH builds the whole package will not
10100 support VPATH builds.  This in turns means that @samp{make distcheck}
10101 will not work, because it relies on VPATH builds.  Some people can
10102 live without this (actually, many Automake users have never heard of
10103 @samp{make distcheck}).  Other people may prefer to revamp the
10104 existing @file{Makefile}s to support VPATH@.  Doing so does not
10105 necessarily require Automake, only Autoconf is needed (@pxref{Build
10106 Directories, , Build Directories, autoconf, The Autoconf Manual}).
10107 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
10108 and @samp{@@top_builddir@@} are defined by @file{configure} when it
10109 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
10110 Output Variables, autoconf, The Autoconf Manual}), they are not
10111 computed by the Makefile like the aforementioned @samp{$(distdir)} and
10112 @samp{$(top_distdir)} variables.
10114 It is sometimes inconvenient to modify a third-party @file{Makefile}
10115 to introduce the above required targets.  For instance, one may want to
10116 keep the third-party sources untouched to ease upgrades to new
10117 versions.
10119 @cindex @file{GNUmakefile} including @file{Makefile}
10120 Here are two other ideas.  If GNU make is assumed, one possibility is
10121 to add to that subdirectory a @file{GNUmakefile} that defines the
10122 required targets and includes the third-party @file{Makefile}.  For
10123 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
10124 directory; the easiest way to do this is to write a
10125 @file{GNUmakefile.in} instead, and have it processed with
10126 @code{AC_CONFIG_FILES} from the outer package.  For example if we
10127 assume @file{Makefile} defines all targets except the documentation
10128 targets, and that the @code{check} target is actually called
10129 @code{test}, we could write @file{GNUmakefile} (or
10130 @file{GNUmakefile.in}) like this:
10132 @example
10133 # First, include the real Makefile
10134 include Makefile
10135 # Then, define the other targets needed by Automake Makefiles.
10136 .PHONY: dvi pdf ps info html check
10137 dvi pdf ps info html:
10138 check: test
10139 @end example
10141 @cindex Proxy @file{Makefile} for third-party packages
10142 A similar idea that does not use @code{include} is to write a proxy
10143 @file{Makefile} that dispatches rules to the real @file{Makefile},
10144 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
10145 it's OK to rename the original @file{Makefile}) or with @samp{cd
10146 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
10147 subdirectory project one directory deeper).  The good news is that
10148 this proxy @file{Makefile} can be generated with Automake.  All we
10149 need are @option{-local} targets (@pxref{Extending}) that perform the
10150 dispatch.  Of course the other Automake features are available, so you
10151 could decide to let Automake perform distribution or installation.
10152 Here is a possible @file{Makefile.am}:
10154 @example
10155 all-local:
10156         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
10157 check-local:
10158         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
10159 clean-local:
10160         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
10162 # Assuming the package knows how to install itself
10163 install-data-local:
10164         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
10165 install-exec-local:
10166         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
10167 uninstall-local:
10168         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
10170 # Distribute files from here.
10171 EXTRA_DIST = subdir/Makefile subdir/program.c ...
10172 @end example
10174 Pushing this idea to the extreme, it is also possible to ignore the
10175 subproject build system and build everything from this proxy
10176 @file{Makefile.am}.  This might sound very sensible if you need VPATH
10177 builds but the subproject does not support them.
10179 @node Distributing
10180 @chapter Distributing @file{Makefile.in}s
10182 Automake places no restrictions on the distribution of the resulting
10183 @file{Makefile.in}s.  We still encourage software authors to
10184 distribute their work under terms like those of the GPL, but doing so
10185 is not required to use Automake.
10187 Some of the files that can be automatically installed via the
10188 @option{--add-missing} switch do fall under the GPL@.  However, these also
10189 have a special exception allowing you to distribute them with your
10190 package, regardless of the licensing you choose.
10193 @node API Versioning
10194 @chapter Automake API Versioning
10196 New Automake releases usually include bug fixes and new features.
10197 Unfortunately they may also introduce new bugs and incompatibilities.
10198 This makes four reasons why a package may require a particular Automake
10199 version.
10201 Things get worse when maintaining a large tree of packages, each one
10202 requiring a different version of Automake.  In the past, this meant that
10203 any developer (and sometimes users) had to install several versions of
10204 Automake in different places, and switch @samp{$PATH} appropriately for
10205 each package.
10207 Starting with version 1.6, Automake installs versioned binaries.  This
10208 means you can install several versions of Automake in the same
10209 @samp{$prefix}, and can select an arbitrary Automake version by running
10210 @command{automake-1.6} or @command{automake-1.7} without juggling with
10211 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
10212 will use @command{automake-1.6} explicitly in their rebuild rules.
10214 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
10215 not Automake's version.  If a bug fix release is made, for instance
10216 Automake 1.6.1, the API version will remain 1.6.  This means that a
10217 package that works with Automake 1.6 should also work with 1.6.1; after
10218 all, this is what people expect from bug fix releases.
10220 If your package relies on a feature or a bug fix introduced in
10221 a release, you can pass this version as an option to Automake to ensure
10222 older releases will not be used.  For instance, use this in your
10223 @file{configure.ac}:
10225 @example
10226   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
10227 @end example
10228 @noindent
10229 or, in a particular @file{Makefile.am}:
10231 @example
10232   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
10233 @end example
10234 @noindent
10235 Automake will print an error message if its version is
10236 older than the requested version.
10239 @heading What is in the API
10241 Automake's programming interface is not easy to define.  Basically it
10242 should include at least all @strong{documented} variables and targets
10243 that a @file{Makefile.am} author can use, any behavior associated with
10244 them (e.g., the places where @samp{-hook}'s are run), the command line
10245 interface of @command{automake} and @command{aclocal}, @dots{}
10247 @heading What is not in the API
10249 Every undocumented variable, target, or command line option, is not part
10250 of the API@.  You should avoid using them, as they could change from one
10251 version to the other (even in bug fix releases, if this helps to fix a
10252 bug).
10254 If it turns out you need to use such an undocumented feature, contact
10255 @email{automake@@gnu.org} and try to get it documented and exercised by
10256 the test-suite.
10258 @node Upgrading
10259 @chapter Upgrading a Package to a Newer Automake Version
10261 Automake maintains three kind of files in a package.
10263 @itemize
10264 @item @file{aclocal.m4}
10265 @item @file{Makefile.in}s
10266 @item auxiliary tools like @file{install-sh} or @file{py-compile}
10267 @end itemize
10269 @file{aclocal.m4} is generated by @command{aclocal} and contains some
10270 Automake-supplied M4 macros.  Auxiliary tools are installed by
10271 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
10272 built from @file{Makefile.am} by @command{automake}, and rely on the
10273 definitions of the M4 macros put in @file{aclocal.m4} as well as the
10274 behavior of the auxiliary tools installed.
10276 Because all these files are closely related, it is important to
10277 regenerate all of them when upgrading to a newer Automake release.
10278 The usual way to do that is
10280 @example
10281 aclocal # with any option needed (such a -I m4)
10282 autoconf
10283 automake --add-missing --force-missing
10284 @end example
10286 @noindent
10287 or more conveniently:
10289 @example
10290 autoreconf -vfi
10291 @end example
10293 The use of @option{--force-missing} ensures that auxiliary tools will be
10294 overridden by new versions (@pxref{Invoking Automake}).
10296 It is important to regenerate all these files each time Automake is
10297 upgraded, even between bug fixes releases.  For instance, it is not
10298 unusual for a bug fix to involve changes to both the rules generated
10299 in @file{Makefile.in} and the supporting M4 macros copied to
10300 @file{aclocal.m4}.
10302 Presently @command{automake} is able to diagnose situations where
10303 @file{aclocal.m4} has been generated with another version of
10304 @command{aclocal}.  However it never checks whether auxiliary scripts
10305 are up-to-date.  In other words, @command{automake} will tell you when
10306 @command{aclocal} needs to be rerun, but it will never diagnose a
10307 missing @option{--force-missing}.
10309 Before upgrading to a new major release, it is a good idea to read the
10310 file @file{NEWS}.  This file lists all changes between releases: new
10311 features, obsolete constructs, known incompatibilities, and
10312 workarounds.
10314 @node FAQ
10315 @chapter Frequently Asked Questions about Automake
10317 This chapter covers some questions that often come up on the mailing
10318 lists.
10320 @menu
10321 * CVS::                         CVS and generated files
10322 * maintainer-mode::             missing and AM_MAINTAINER_MODE
10323 * Wildcards::                   Why doesn't Automake support wildcards?
10324 * Limitations on File Names::   Limitations on source and installed file names
10325 * distcleancheck::              Files left in build directory after distclean
10326 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
10327 * Renamed Objects::             Why are object files sometimes renamed?
10328 * Per-Object Flags::            How to simulate per-object flags?
10329 * Multiple Outputs::            Writing rules for tools with many output files
10330 * Hard-Coded Install Paths::    Installing to hard-coded locations
10331 * Debugging Make Rules::        Strategies when things don't work as expected
10332 @end menu
10334 @node CVS
10335 @section CVS and generated files
10337 @subheading Background: distributed generated Files
10338 @cindex generated files, distributed
10339 @cindex rebuild rules
10341 Packages made with Autoconf and Automake ship with some generated
10342 files like @file{configure} or @file{Makefile.in}.  These files were
10343 generated on the developer's host and are distributed so that
10344 end-users do not have to install the maintainer tools required to
10345 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
10346 or Info documentation, are usually distributed on similar grounds.
10348 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
10349 instance, @command{make} will run @command{autoconf} to rebuild
10350 @file{configure} whenever @file{configure.ac} is changed.  This makes
10351 development safer by ensuring a @file{configure} is never out-of-date
10352 with respect to @file{configure.ac}.
10354 As generated files shipped in packages are up-to-date, and because
10355 @command{tar} preserves times-tamps, these rebuild rules are not
10356 triggered when a user unpacks and builds a package.
10358 @subheading Background: CVS and Timestamps
10359 @cindex timestamps and CVS
10360 @cindex CVS and timestamps
10362 Unless you use CVS keywords (in which case files must be updated at
10363 commit time), CVS preserves timestamp during @samp{cvs commit} and
10364 @samp{cvs import -d} operations.
10366 When you check out a file using @samp{cvs checkout} its timestamp is
10367 set to that of the revision that is being checked out.
10369 However, during @command{cvs update}, files will have the date of the
10370 update, not the original timestamp of this revision.  This is meant to
10371 make sure that @command{make} notices sources files have been updated.
10373 This timestamp shift is troublesome when both sources and generated
10374 files are kept under CVS@.  Because CVS processes files in lexical
10375 order, @file{configure.ac} will appear newer than @file{configure}
10376 after a @command{cvs update} that updates both files, even if
10377 @file{configure} was newer than @file{configure.ac} when it was
10378 checked in.  Calling @command{make} will then trigger a spurious rebuild
10379 of @file{configure}.
10381 @subheading Living with CVS in Autoconfiscated Projects
10382 @cindex CVS and generated files
10383 @cindex generated files and CVS
10385 There are basically two clans amongst maintainers: those who keep all
10386 distributed files under CVS, including generated files, and those who
10387 keep generated files @emph{out} of CVS.
10389 @subsubheading All Files in CVS
10391 @itemize @bullet
10392 @item
10393 The CVS repository contains all distributed files so you know exactly
10394 what is distributed, and you can checkout any prior version entirely.
10396 @item
10397 Maintainers can see how generated files evolve (for instance, you can
10398 see what happens to your @file{Makefile.in}s when you upgrade Automake
10399 and make sure they look OK).
10401 @item
10402 Users do not need the autotools to build a checkout of the project, it
10403 works just like a released tarball.
10405 @item
10406 If users use @command{cvs update} to update their copy, instead of
10407 @command{cvs checkout} to fetch a fresh one, timestamps will be
10408 inaccurate.  Some rebuild rules will be triggered and attempt to
10409 run developer tools such as @command{autoconf} or @command{automake}.
10411 Actually, calls to such tools are all wrapped into a call to the
10412 @command{missing} script discussed later (@pxref{maintainer-mode}).
10413 @command{missing} will take care of fixing the timestamps when these
10414 tools are not installed, so that the build can continue.
10416 @item
10417 In distributed development, developers are likely to have different
10418 version of the maintainer tools installed.  In this case rebuilds
10419 triggered by timestamp lossage will lead to spurious changes
10420 to generated files.  There are several solutions to this:
10422 @itemize
10423 @item
10424 All developers should use the same versions, so that the rebuilt files
10425 are identical to files in CVS@.  (This starts to be difficult when each
10426 project you work on uses different versions.)
10427 @item
10428 Or people use a script to fix the timestamp after a checkout (the GCC
10429 folks have such a script).
10430 @item
10431 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
10432 disable all these rebuild rules by default.  This is further discussed
10433 in @ref{maintainer-mode}.
10434 @end itemize
10436 @item
10437 Although we focused on spurious rebuilds, the converse can also
10438 happen.  CVS's timestamp handling can also let you think an
10439 out-of-date file is up-to-date.
10441 For instance, suppose a developer has modified @file{Makefile.am} and
10442 has rebuilt @file{Makefile.in}.  He then decides to do a last-minute
10443 change to @file{Makefile.am} right before checking in both files
10444 (without rebuilding @file{Makefile.in} to account for the change).
10446 This last change to @file{Makefile.am} makes the copy of
10447 @file{Makefile.in} out-of-date.  Since CVS processes files
10448 alphabetically, when another developer @samp{cvs update}s his or her
10449 tree, @file{Makefile.in} will happen to be newer than
10450 @file{Makefile.am}.  This other developer will not see that
10451 @file{Makefile.in} is out-of-date.
10453 @end itemize
10455 @subsubheading Generated Files out of CVS
10457 One way to get CVS and @command{make} working peacefully is to never
10458 store generated files in CVS, i.e., do not CVS-control files that
10459 are @file{Makefile} targets (also called @emph{derived} files).
10461 This way developers are not annoyed by changes to generated files.  It
10462 does not matter if they all have different versions (assuming they are
10463 compatible, of course).  And finally, timestamps are not lost, changes
10464 to sources files can't be missed as in the
10465 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
10467 The drawback is that the CVS repository is not an exact copy of what
10468 is distributed and that users now need to install various development
10469 tools (maybe even specific versions) before they can build a checkout.
10470 But, after all, CVS's job is versioning, not distribution.
10472 Allowing developers to use different versions of their tools can also
10473 hide bugs during distributed development.  Indeed, developers will be
10474 using (hence testing) their own generated files, instead of the
10475 generated files that will be released actually.  The developer who
10476 prepares the tarball might be using a version of the tool that
10477 produces bogus output (for instance a non-portable C file), something
10478 other developers could have noticed if they weren't using their own
10479 versions of this tool.
10481 @subheading Third-party Files
10482 @cindex CVS and third-party files
10483 @cindex third-party files and CVS
10485 Another class of files not discussed here (because they do not cause
10486 timestamp issues) are files that are shipped with a package, but
10487 maintained elsewhere.  For instance, tools like @command{gettextize}
10488 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
10489 Libtool), will install or update files in your package.
10491 These files, whether they are kept under CVS or not, raise similar
10492 concerns about version mismatch between developers' tools.  The
10493 Gettext manual has a section about this, see @ref{CVS Issues, CVS
10494 Issues, Integrating with CVS, gettext, GNU gettext tools}.
10496 @node maintainer-mode
10497 @section @command{missing} and @code{AM_MAINTAINER_MODE}
10499 @subheading @command{missing}
10500 @cindex @command{missing}, purpose
10502 The @command{missing} script is a wrapper around several maintainer
10503 tools, designed to warn users if a maintainer tool is required but
10504 missing.  Typical maintainer tools are @command{autoconf},
10505 @command{automake}, @command{bison}, etc.  Because file generated by
10506 these tools are shipped with the other sources of a package, these
10507 tools shouldn't be required during a user build and they are not
10508 checked for in @file{configure}.
10510 However, if for some reason a rebuild rule is triggered and involves a
10511 missing tool, @command{missing} will notice it and warn the user.
10512 Besides the warning, when a tool is missing, @command{missing} will
10513 attempt to fix timestamps in a way that allows the build to continue.
10514 For instance, @command{missing} will touch @file{configure} if
10515 @command{autoconf} is not installed.  When all distributed files are
10516 kept under CVS, this feature of @command{missing} allows a user
10517 @emph{with no maintainer tools} to build a package off CVS, bypassing
10518 any timestamp inconsistency implied by @samp{cvs update}.
10520 If the required tool is installed, @command{missing} will run it and
10521 won't attempt to continue after failures.  This is correct during
10522 development: developers love fixing failures.  However, users with
10523 wrong versions of maintainer tools may get an error when the rebuild
10524 rule is spuriously triggered, halting the build.  This failure to let
10525 the build continue is one of the arguments of the
10526 @code{AM_MAINTAINER_MODE} advocates.
10528 @subheading @code{AM_MAINTAINER_MODE}
10529 @cindex @code{AM_MAINTAINER_MODE}, purpose
10530 @acindex AM_MAINTAINER_MODE
10532 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
10533 "rebuild rules" should be enabled or disabled.  With
10534 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
10535 otherwise they are disabled by default.  In the latter case, if
10536 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
10537 @samp{./configure && make}, then @command{make} will *never* attempt to
10538 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
10539 I.e., this disables build rules for files that are usually distributed
10540 and that users should normally not have to update.
10542 The user can override the default setting by passing either
10543 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
10544 to @command{configure}.
10546 People use @code{AM_MAINTAINER_MODE} either because they do not want their
10547 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
10548 because they simply can't stand the rebuild rules and prefer running
10549 maintainer tools explicitly.
10551 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
10552 rules conditionally.  Some developers use this feature to disable
10553 rules that need exotic tools that users may not have available.
10555 Several years ago Fran@,{c}ois Pinard pointed out several arguments
10556 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
10557 insecurity.  By removing dependencies you get non-dependable builds:
10558 changes to sources files can have no effect on generated files and this
10559 can be very confusing when unnoticed.  He adds that security shouldn't
10560 be reserved to maintainers (what @option{--enable-maintainer-mode}
10561 suggests), on the contrary.  If one user has to modify a
10562 @file{Makefile.am}, then either @file{Makefile.in} should be updated
10563 or a warning should be output (this is what Automake uses
10564 @command{missing} for) but the last thing you want is that nothing
10565 happens and the user doesn't notice it (this is what happens when
10566 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
10568 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
10569 swayed by Fran@,{c}ois's arguments, and got rid of
10570 @code{AM_MAINTAINER_MODE} in all of his packages.
10572 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
10573 it helps them working on projects where all files are kept under CVS,
10574 and because @command{missing} isn't enough if you have the wrong
10575 version of the tools.
10578 @node Wildcards
10579 @section Why doesn't Automake support wildcards?
10580 @cindex wildcards
10582 Developers are lazy.  They would often like to use wildcards in
10583 @file{Makefile.am}s, so that they would not need to remember to
10584 update @file{Makefile.am}s every time they add, delete, or rename
10585 a file.
10587 There are several objections to this:
10588 @itemize
10589 @item
10590 When using CVS (or similar) developers need to remember they have to
10591 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
10592 @file{Makefile.am} accordingly quickly becomes a reflex.
10594 Conversely, if your application doesn't compile
10595 because you forgot to add a file in @file{Makefile.am}, it will help
10596 you remember to @samp{cvs add} it.
10598 @item
10599 Using wildcards makes it easy to distribute files by mistake.  For
10600 instance, some code a developer is experimenting with (a test case,
10601 say) that should not be part of the distribution.
10603 @item
10604 Using wildcards it's easy to omit some files by mistake.  For
10605 instance, one developer creates a new file, uses it in many places,
10606 but forgets to commit it.  Another developer then checks out the
10607 incomplete project and is able to run @samp{make dist} successfully,
10608 even though a file is missing. By listing files, @samp{make dist}
10609 @emph{will} complain.
10611 @item
10612 Finally, it's really hard to @emph{forget} to add a file to
10613 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
10614 not compiled or installed, so you can't even test them.
10615 @end itemize
10617 Still, these are philosophical objections, and as such you may disagree,
10618 or find enough value in wildcards to dismiss all of them.  Before you
10619 start writing a patch against Automake to teach it about wildcards,
10620 let's see the main technical issue: portability.
10622 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
10623 not portable to other @command{make} implementations.
10625 The only way Automake could support @command{$(wildcard ...)} is by
10626 expending @command{$(wildcard ...)} when @command{automake} is run.
10627 The resulting @file{Makefile.in}s would be portable since they would
10628 list all files and not use @samp{$(wildcard ...)}.  However that
10629 means developers would need to remember to run @command{automake} each
10630 time they add, delete, or rename files.
10632 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
10633 it's easier and faster to type @samp{automake; make} than to type
10634 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
10635 patch to add support for this syntax.  Some people use scripts to
10636 generate file lists in @file{Makefile.am} or in separate
10637 @file{Makefile} fragments.
10639 Even if you don't care about portability, and are tempted to use
10640 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
10641 should know there are many places where Automake needs to know exactly
10642 which files should be processed.  As Automake doesn't know how to
10643 expand @samp{$(wildcard ...)}, you cannot use it in these places.
10644 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
10645 variables as far Automake is concerned.
10647 You can get warnings about @samp{$(wildcard ...}) constructs using the
10648 @option{-Wportability} flag.
10650 @node Limitations on File Names
10651 @section Limitations on File Names
10652 @cindex file names, limitations on
10654 Automake attempts to support all kinds of file names, even those that
10655 contain unusual characters or are unusually long.  However, some
10656 limitations are imposed by the underlying operating system and tools.
10658 Most operating systems prohibit the use of the null byte in file
10659 names, and reserve @samp{/} as a directory separator.  Also, they
10660 require that file names are properly encoded for the user's locale.
10661 Automake is subject to these limits.
10663 Portable packages should limit themselves to @acronym{POSIX} file
10664 names.  These can contain @acronym{ASCII} letters and digits,
10665 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
10666 separated by @samp{/}.  File name components cannot begin with
10667 @samp{-}.
10669 Portable POSIX file names cannot contain components that exceed a
10670 14-byte limit, but nowadays it's normally safe to assume the
10671 more-generous @acronym{XOPEN} limit of 255 bytes.  @acronym{POSIX}
10672 limits file names to 255 bytes (@acronym{XOPEN} allows 1023 bytes),
10673 but you may want to limit a source tarball to file names of 99 bytes
10674 to avoid interoperability problems with old versions of @command{tar}.
10676 If you depart from these rules (e.g., by using non-@acronym{ASCII}
10677 characters in file names, or by using lengthy file names), your
10678 installers may have problems for reasons unrelated to Automake.
10679 However, if this does not concern you, you should know about the
10680 limitations imposed by Automake itself.  These limitations are
10681 undesirable, but some of them seem to be inherent to underlying tools
10682 like Autoconf, Make, M4, and the shell.  They fall into three
10683 categories: install directories, build directories, and file names.
10685 The following characters:
10687 @example
10688 @r{newline} " # $ ' `
10689 @end example
10691 should not appear in the names of install directories.  For example,
10692 the operand of @command{configure}'s @option{--prefix} option should
10693 not contain these characters.
10695 Build directories suffer the same limitations as install directories,
10696 and in addition should not contain the following characters:
10698 @example
10699 & @@ \
10700 @end example
10702 For example, the full name of the directory containing the source
10703 files should not contain these characters.
10705 Source and installation file names like @file{main.c} are limited even
10706 further: they should conform to the @acronym{POSIX}/@acronym{XOPEN}
10707 rules described above.  In addition, if you plan to port to
10708 non-@acronym{POSIX} environments, you should avoid file names that
10709 differ only in case (e.g., @file{makefile} and @file{Makefile}).
10710 Nowadays it is no longer worth worrying about the 8.3 limits of
10711 @acronym{DOS} file systems.
10713 @node distcleancheck
10714 @section Files left in build directory after distclean
10715 @cindex @code{distclean}, diagnostic
10716 @cindex @samp{make distclean}, diagnostic
10717 @cindex dependencies and distributed files
10718 @trindex distclean
10719 @trindex distcleancheck
10721 This is a diagnostic you might encounter while running @samp{make
10722 distcheck}.
10724 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
10725 attempts to build and check your package for errors like this one.
10727 @samp{make distcheck} will perform a @code{VPATH} build of your
10728 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
10729 Files left in the build directory after @samp{make distclean} has run
10730 are listed after this error.
10732 This diagnostic really covers two kinds of errors:
10734 @itemize @bullet
10735 @item
10736 files that are forgotten by distclean;
10737 @item
10738 distributed files that are erroneously rebuilt.
10739 @end itemize
10741 The former left-over files are not distributed, so the fix is to mark
10742 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
10743 more explanations.
10745 The latter bug is not always easy to understand and fix, so let's
10746 proceed with an example.  Suppose our package contains a program for
10747 which we want to build a man page using @command{help2man}.  GNU
10748 @command{help2man} produces simple manual pages from the @option{--help}
10749 and @option{--version} output of other commands (@pxref{Top, , Overview,
10750 help2man, The Help2man Manual}).  Because we don't want to force our
10751 users to install @command{help2man}, we decide to distribute the
10752 generated man page using the following setup.
10754 @example
10755 # This Makefile.am is bogus.
10756 bin_PROGRAMS = foo
10757 foo_SOURCES = foo.c
10758 dist_man_MANS = foo.1
10760 foo.1: foo$(EXEEXT)
10761         help2man --output=foo.1 ./foo$(EXEEXT)
10762 @end example
10764 This will effectively distribute the man page.  However,
10765 @samp{make distcheck} will fail with:
10767 @example
10768 ERROR: files left in build directory after distclean:
10769 ./foo.1
10770 @end example
10772 Why was @file{foo.1} rebuilt?  Because although distributed,
10773 @file{foo.1} depends on a non-distributed built file:
10774 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
10775 will always appear to be newer than the distributed @file{foo.1}.
10777 @samp{make distcheck} caught an inconsistency in our package.  Our
10778 intent was to distribute @file{foo.1} so users do not need to install
10779 @command{help2man}, however since this rule causes this file to be
10780 always rebuilt, users @emph{do} need @command{help2man}.  Either we
10781 should ensure that @file{foo.1} is not rebuilt by users, or there is
10782 no point in distributing @file{foo.1}.
10784 More generally, the rule is that distributed files should never depend
10785 on non-distributed built files.  If you distribute something
10786 generated, distribute its sources.
10788 One way to fix the above example, while still distributing
10789 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
10790 assuming @command{foo --version} and @command{foo --help} do not
10791 change unless @file{foo.c} or @file{configure.ac} change, we could
10792 write the following @file{Makefile.am}:
10794 @example
10795 bin_PROGRAMS = foo
10796 foo_SOURCES = foo.c
10797 dist_man_MANS = foo.1
10799 foo.1: foo.c $(top_srcdir)/configure.ac
10800         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
10801         help2man --output=foo.1 ./foo$(EXEEXT)
10802 @end example
10804 This way, @file{foo.1} will not get rebuilt every time
10805 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
10806 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
10807 way to ensure this would be to use separate directories for binaries
10808 and man pages, and set @code{SUBDIRS} so that binaries are built
10809 before man pages.
10811 We could also decide not to distribute @file{foo.1}.  In
10812 this case it's fine to have @file{foo.1} dependent upon
10813 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
10814 However it would be impossible to build the package in a
10815 cross-compilation, because building @file{foo.1} involves
10816 an @emph{execution} of @file{foo$(EXEEXT)}.
10818 Another context where such errors are common is when distributed files
10819 are built by tools that are built by the package.  The pattern is
10820 similar:
10822 @example
10823 distributed-file: built-tools distributed-sources
10824         build-command
10825 @end example
10827 @noindent
10828 should be changed to
10830 @example
10831 distributed-file: distributed-sources
10832         $(MAKE) $(AM_MAKEFLAGS) built-tools
10833         build-command
10834 @end example
10836 @noindent
10837 or you could choose not to distribute @file{distributed-file}, if
10838 cross-compilation does not matter.
10840 The points made through these examples are worth a summary:
10842 @cartouche
10843 @itemize
10844 @item
10845 Distributed files should never depend upon non-distributed built
10846 files.
10847 @item
10848 Distributed files should be distributed with all their dependencies.
10849 @item
10850 If a file is @emph{intended} to be rebuilt by users, then there is no point
10851 in distributing it.
10852 @end itemize
10853 @end cartouche
10855 @vrindex distcleancheck_listfiles
10856 For desperate cases, it's always possible to disable this check by
10857 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
10858 the Distribution}.
10859 Make sure you do understand the reason why @samp{make distcheck}
10860 complains before you do this.  @code{distcleancheck_listfiles} is a
10861 way to @emph{hide} errors, not to fix them.  You can always do better.
10863 @node Flag Variables Ordering
10864 @section Flag Variables Ordering
10865 @cindex Ordering flag variables
10866 @cindex Flag variables, ordering
10868 @display
10869 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
10870 @code{mumble_CFLAGS}?
10871 @end display
10873 @display
10874 Why does @command{automake} output @code{CPPFLAGS} after
10875 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
10876 @end display
10878 @display
10879 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
10880 one @file{Makefile.am} I would like to append a new flag, however if I
10881 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
10882 flags, not appended.
10883 @end display
10885 @subheading Compile Flag Variables
10886 @cindex Flag Variables, Ordering
10887 @cindex Compile Flag Variables
10888 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
10889 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
10890 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
10891 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
10892 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
10893 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
10894 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
10895 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
10896 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
10897 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
10898 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
10899 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
10900 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
10901 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
10902 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
10903 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
10904 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
10905 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
10906 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
10907 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
10908 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
10909 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
10910 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
10911 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
10912 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
10913 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
10914 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
10915 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
10917 This section attempts to answer all the above questions.  We will
10918 mostly discuss @code{CPPFLAGS} in our examples, but actually the
10919 answer holds for all the compile flags used in Automake:
10920 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
10921 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
10922 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
10923 @code{UPCFLAGS}, and @code{YFLAGS}.
10925 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
10926 three variables that can be used to pass flags to the C preprocessor
10927 (actually these variables are also used for other languages like C++
10928 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
10929 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
10930 and @code{mumble_CPPFLAGS} is the variable specific to the
10931 @code{mumble} target (we call this a per-target variable,
10932 @pxref{Program and Library Variables}).
10934 Automake always uses two of these variables when compiling C sources
10935 files.  When compiling an object file for the @code{mumble} target,
10936 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
10937 @code{AM_CPPFLAGS} otherwise.  The second variable is always
10938 @code{CPPFLAGS}.
10940 In the following example,
10942 @example
10943 bin_PROGRAMS = foo bar
10944 foo_SOURCES = xyz.c
10945 bar_SOURCES = main.c
10946 foo_CPPFLAGS = -DFOO
10947 AM_CPPFLAGS = -DBAZ
10948 @end example
10950 @noindent
10951 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
10952 (because @file{xyz.o} is part of the @code{foo} target), while
10953 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
10954 (because there is no per-target variable for target @code{bar}).
10956 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
10957 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
10958 is a user variable, i.e., a variable that users are entitled to modify
10959 in order to compile the package.  This variable, like many others,
10960 is documented at the end of the output of @samp{configure --help}.
10962 For instance, someone who needs to add @file{/home/my/usr/include} to
10963 the C compiler's search path would configure a package with
10965 @example
10966 ./configure CPPFLAGS='-I /home/my/usr/include'
10967 @end example
10969 @noindent
10970 and this flag would be propagated to the compile rules of all
10971 @file{Makefile}s.
10973 It is also not uncommon to override a user variable at
10974 @command{make}-time.  Many installers do this with @code{prefix}, but
10975 this can be useful with compiler flags too.  For instance, if, while
10976 debugging a C++ project, you need to disable optimization in one
10977 specific object file, you can run something like
10979 @example
10980 rm file.o
10981 make CXXFLAGS=-O0 file.o
10982 make
10983 @end example
10985 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
10986 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
10987 should always have the last say.  It probably makes more sense if you
10988 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
10989 should supersede any other switch from @code{AM_CXXFLAGS} or
10990 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
10991 of @code{CXXFLAGS}).
10993 You should never redefine a user variable such as @code{CPPFLAGS} in
10994 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
10995 mistakes.  Even something like
10997 @example
10998 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
10999 @end example
11001 @noindent
11002 is erroneous.  Although this preserves @file{configure}'s value of
11003 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
11004 user attempts to override @code{CPPFLAGS} from the @command{make}
11005 command line.
11007 @example
11008 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
11009 @end example
11011 @noindent
11012 is all that is needed here if no per-target flags are used.
11014 You should not add options to these user variables within
11015 @file{configure} either, for the same reason.  Occasionally you need
11016 to modify these variables to perform a test, but you should reset
11017 their values afterwards.  In contrast, it is OK to modify the
11018 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
11019 them, but it is rather rare that you need to do this, unless you
11020 really want to change the default definitions of the @samp{AM_}
11021 variables in all @file{Makefile}s.
11023 What we recommend is that you define extra flags in separate
11024 variables.  For instance, you may write an Autoconf macro that computes
11025 a set of warning options for the C compiler, and @code{AC_SUBST} them
11026 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
11027 determines which compiler and which linker flags should be used to
11028 link with library @file{libfoo}, and @code{AC_SUBST} these in
11029 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
11030 @file{Makefile.am} could use these variables as follows:
11032 @example
11033 AM_CFLAGS = $(WARNINGCFLAGS)
11034 bin_PROGRAMS = prog1 prog2
11035 prog1_SOURCES = @dots{}
11036 prog2_SOURCES = @dots{}
11037 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
11038 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
11039 @end example
11041 In this example both programs will be compiled with the flags
11042 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
11043 additionally be compiled with the flags required to link with
11044 @file{libfoo}.
11046 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
11047 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
11048 every target in a @file{Makefile.in}.
11050 Using variables like this gives you full control over the ordering of
11051 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
11052 you want to negate for a particular target, you can use something like
11053 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
11054 been forcefully appended to @code{CFLAGS}, there would be no way to
11055 disable one flag.  Yet another reason to leave user variables to
11056 users.
11058 Finally, we have avoided naming the variable of the example
11059 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
11060 Automake to think that this is actually a per-target variable (like
11061 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
11063 @subheading Other Variables
11065 There are other variables in Automake that follow similar principles
11066 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
11067 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
11068 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
11069 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
11070 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
11071 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
11072 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
11073 of these rules support per-target flags (yet).
11075 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
11076 obeys this naming scheme.  The slight difference is that
11077 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
11078 @command{make} itself.
11080 However you should not think that all variables ending with
11081 @code{FLAGS} follow this convention.  For instance,
11082 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Checking the Distribution}) and
11083 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
11084 are two variables that are only useful to the maintainer and have no
11085 user counterpart.
11087 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
11088 has neither @code{AM_} nor per-target cousin.
11090 Finally you should not think that the existence of a per-target
11091 variable implies the existance of an @code{AM_} variable or of a user
11092 variable.  For instance, the @code{mumble_LDADD} per-target variable
11093 overrides the makefile-wide @code{LDADD} variable (which is not a user
11094 variable), and @code{mumble_LIBADD} exists only as a per-target
11095 variable.  @xref{Program and Library Variables}.
11098 @node Renamed Objects
11099 @section Why are object files sometimes renamed?
11101 This happens when per-target compilation flags are used.  Object
11102 files need to be renamed just in case they would clash with object
11103 files compiled from the same sources, but with different flags.
11104 Consider the following example.
11106 @example
11107 bin_PROGRAMS = true false
11108 true_SOURCES = generic.c
11109 true_CPPFLAGS = -DEXIT_CODE=0
11110 false_SOURCES = generic.c
11111 false_CPPFLAGS = -DEXIT_CODE=1
11112 @end example
11113 @noindent
11114 Obviously the two programs are built from the same source, but it
11115 would be bad if they shared the same object, because @file{generic.o}
11116 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
11117 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
11118 build two different objects: @file{true-generic.o} and
11119 @file{false-generic.o}.
11121 @command{automake} doesn't actually look whether source files are
11122 shared to decide if it must rename objects.  It will just rename all
11123 objects of a target as soon as it sees per-target compilation flags
11124 used.
11126 It's OK to share object files when per-target compilation flags are not
11127 used.  For instance, @file{true} and @file{false} will both use
11128 @file{version.o} in the following example.
11130 @example
11131 AM_CPPFLAGS = -DVERSION=1.0
11132 bin_PROGRAMS = true false
11133 true_SOURCES = true.c version.c
11134 false_SOURCES = false.c version.c
11135 @end example
11137 Note that the renaming of objects is also affected by the
11138 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
11141 @node Per-Object Flags
11142 @section Per-Object Flags Emulation
11143 @cindex Per-object flags, emulated
11145 @display
11146 One of my source files needs to be compiled with different flags.  How
11147 do I do?
11148 @end display
11150 Automake supports per-program and per-library compilation flags (see
11151 @ref{Program and Library Variables} and @ref{Flag Variables
11152 Ordering}).  With this you can define compilation flags that apply to
11153 all files compiled for a target.  For instance, in
11155 @example
11156 bin_PROGRAMS = foo
11157 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
11158 foo_CFLAGS = -some -flags
11159 @end example
11161 @noindent
11162 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
11163 compiled with @samp{-some -flags}.  (If you wonder about the names of
11164 these object files, see @ref{Renamed Objects}.)  Note that
11165 @code{foo_CFLAGS} gives the flags to use when compiling all the C
11166 sources of the @emph{program} @code{foo}, it has nothing to do with
11167 @file{foo.c} or @file{foo-foo.o} specifically.
11169 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
11170 specific flags, that none of the other files requires?  Obviously
11171 per-program flags are not directly applicable here.  Something like
11172 per-object flags are expected, i.e., flags that would be used only
11173 when creating @file{foo-foo.o}.  Automake does not support that,
11174 however this is easy to simulate using a library that contains only
11175 that object, and compiling this library with per-library flags.
11177 @example
11178 bin_PROGRAMS = foo
11179 foo_SOURCES = bar.c bar.h main.c
11180 foo_CFLAGS = -some -flags
11181 foo_LDADD = libfoo.a
11182 noinst_LIBRARIES = libfoo.a
11183 libfoo_a_SOURCES = foo.c foo.h
11184 libfoo_a_CFLAGS = -some -other -flags
11185 @end example
11187 Here @file{foo-bar.o} and @file{foo-main.o} will all be
11188 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
11189 be compiled using @samp{-some -other -flags}.  Eventually, all
11190 three objects will be linked to form @file{foo}.
11192 This trick can also be achieved using Libtool convenience libraries,
11193 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
11194 Convenience Libraries}).
11196 Another tempting idea to implement per-object flags is to override the
11197 compile rules @command{automake} would output for these files.
11198 Automake will not define a rule for a target you have defined, so you
11199 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
11200 We recommend against this, because this is error prone.  For instance,
11201 if you add such a rule to the first example, it will break the day you
11202 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
11203 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
11204 Objects}).  Also in order to support dependency tracking, the two
11205 @file{.o}/@file{.obj} extensions, and all the other flags variables
11206 involved in a compilation, you will end up modifying a copy of the
11207 rule previously output by @command{automake} for this file.  If a new
11208 release of Automake generates a different rule, your copy will need to
11209 be updated by hand.
11211 @node Multiple Outputs
11212 @section Handling Tools that Produce Many Outputs
11213 @cindex multiple outputs, rules with
11214 @cindex many outputs, rules with
11215 @cindex rules with multiple outputs
11217 This section describes a @command{make} idiom that can be used when a
11218 tool produces multiple output files.  It is not specific to Automake
11219 and can be used in ordinary @file{Makefile}s.
11221 Suppose we have a program called @command{foo} that will read one file
11222 called @file{data.foo} and produce two files named @file{data.c} and
11223 @file{data.h}.  We want to write a @file{Makefile} rule that captures
11224 this one-to-two dependency.
11226 The naive rule is incorrect:
11228 @example
11229 # This is incorrect.
11230 data.c data.h: data.foo
11231         foo data.foo
11232 @end example
11234 @noindent
11235 What the above rule really says is that @file{data.c} and
11236 @file{data.h} each depend on @file{data.foo}, and can each be built by
11237 running @samp{foo data.foo}.  In other words it is equivalent to:
11239 @example
11240 # We do not want this.
11241 data.c: data.foo
11242         foo data.foo
11243 data.h: data.foo
11244         foo data.foo
11245 @end example
11247 @noindent
11248 which means that @command{foo} can be run twice.  Usually it will not
11249 be run twice, because @command{make} implementations are smart enough
11250 to check for the existence of the second file after the first one has
11251 been built; they will therefore detect that it already exists.
11252 However there are a few situations where it can run twice anyway:
11254 @itemize
11255 @item
11256 The most worrying case is when running a parallel @command{make}.  If
11257 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
11258 data.foo} commands will run concurrently.  This is harmful.
11259 @item
11260 Another case is when the dependency (here @file{data.foo}) is
11261 (or depends upon) a phony target.
11262 @end itemize
11264 A solution that works with parallel @command{make} but not with
11265 phony dependencies is the following:
11267 @example
11268 data.c data.h: data.foo
11269         foo data.foo
11270 data.h: data.c
11271 @end example
11273 @noindent
11274 The above rules are equivalent to
11276 @example
11277 data.c: data.foo
11278         foo data.foo
11279 data.h: data.foo data.c
11280         foo data.foo
11281 @end example
11282 @noindent
11283 therefore a parallel @command{make} will have to serialize the builds
11284 of @file{data.c} and @file{data.h}, and will detect that the second is
11285 no longer needed once the first is over.
11287 Using this pattern is probably enough for most cases.  However it does
11288 not scale easily to more output files (in this scheme all output files
11289 must be totally ordered by the dependency relation), so we will
11290 explore a more complicated solution.
11292 Another idea is to write the following:
11294 @example
11295 # There is still a problem with this one.
11296 data.c: data.foo
11297         foo data.foo
11298 data.h: data.c
11299 @end example
11301 @noindent
11302 The idea is that @samp{foo data.foo} is run only when @file{data.c}
11303 needs to be updated, but we further state that @file{data.h} depends
11304 upon @file{data.c}.  That way, if @file{data.h} is required and
11305 @file{data.foo} is out of date, the dependency on @file{data.c} will
11306 trigger the build.
11308 This is almost perfect, but suppose we have built @file{data.h} and
11309 @file{data.c}, and then we erase @file{data.h}.  Then, running
11310 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
11311 just state that @file{data.c} must be up-to-date with respect to
11312 @file{data.foo}, and this is already the case.
11314 What we need is a rule that forces a rebuild when @file{data.h} is
11315 missing.  Here it is:
11317 @example
11318 data.c: data.foo
11319         foo data.foo
11320 data.h: data.c
11321 ## Recover from the removal of $@@
11322         @@if test -f $@@; then :; else \
11323           rm -f data.c; \
11324           $(MAKE) $(AM_MAKEFLAGS) data.c; \
11325         fi
11326 @end example
11328 The above scheme can be extended to handle more outputs and more
11329 inputs.  One of the outputs is selected to serve as a witness to the
11330 successful completion of the command, it depends upon all inputs, and
11331 all other outputs depend upon it.  For instance, if @command{foo}
11332 should additionally read @file{data.bar} and also produce
11333 @file{data.w} and @file{data.x}, we would write:
11335 @example
11336 data.c: data.foo data.bar
11337         foo data.foo data.bar
11338 data.h data.w data.x: data.c
11339 ## Recover from the removal of $@@
11340         @@if test -f $@@; then :; else \
11341           rm -f data.c; \
11342           $(MAKE) $(AM_MAKEFLAGS) data.c; \
11343         fi
11344 @end example
11346 However there are now two minor problems in this setup.  One is related
11347 to the timestamp ordering of @file{data.h}, @file{data.w},
11348 @file{data.x}, and @file{data.c}.  The other one is a race condition
11349 if a parallel @command{make} attempts to run multiple instances of the
11350 recover block at once.
11352 Let us deal with the first problem.  @command{foo} outputs four files,
11353 but we do not know in which order these files are created.  Suppose
11354 that @file{data.h} is created before @file{data.c}.  Then we have a
11355 weird situation.  The next time @command{make} is run, @file{data.h}
11356 will appear older than @file{data.c}, the second rule will be
11357 triggered, a shell will be started to execute the @samp{if@dots{}fi}
11358 command, but actually it will just execute the @code{then} branch,
11359 that is: nothing.  In other words, because the witness we selected is
11360 not the first file created by @command{foo}, @command{make} will start
11361 a shell to do nothing each time it is run.
11363 A simple riposte is to fix the timestamps when this happens.
11365 @example
11366 data.c: data.foo data.bar
11367         foo data.foo data.bar
11368 data.h data.w data.x: data.c
11369         @@if test -f $@@; then \
11370           touch $@@; \
11371         else \
11372 ## Recover from the removal of $@@
11373           rm -f data.c; \
11374           $(MAKE) $(AM_MAKEFLAGS) data.c; \
11375         fi
11376 @end example
11378 Another solution is to use a different and dedicated file as witness,
11379 rather than using any of @command{foo}'s outputs.
11381 @example
11382 data.stamp: data.foo data.bar
11383         @@rm -f data.tmp
11384         @@touch data.tmp
11385         foo data.foo data.bar
11386         @@mv -f data.tmp $@@
11387 data.c data.h data.w data.x: data.stamp
11388 ## Recover from the removal of $@@
11389         @@if test -f $@@; then :; else \
11390           rm -f data.stamp; \
11391           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
11392         fi
11393 @end example
11395 @file{data.tmp} is created before @command{foo} is run, so it has a
11396 timestamp older than output files output by @command{foo}.  It is then
11397 renamed to @file{data.stamp} after @command{foo} has run, because we
11398 do not want to update @file{data.stamp} if @command{foo} fails.
11400 This solution still suffers from the second problem: the race
11401 condition in the recover rule.  If, after a successful build, a user
11402 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
11403 @command{make} may start both recover rules in parallel.  If the two
11404 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
11405 data.stamp} concurrently the build is likely to fail (for instance, the
11406 two rules will create @file{data.tmp}, but only one can rename it).
11408 Admittedly, such a weird situation does not arise during ordinary
11409 builds.  It occurs only when the build tree is mutilated.  Here
11410 @file{data.c} and @file{data.h} have been explicitly removed without
11411 also removing @file{data.stamp} and the other output files.
11412 @code{make clean; make} will always recover from these situations even
11413 with parallel makes, so you may decide that the recover rule is solely
11414 to help non-parallel make users and leave things as-is.  Fixing this
11415 requires some locking mechanism to ensure only one instance of the
11416 recover rule rebuilds @file{data.stamp}.  One could imagine something
11417 along the following lines.
11419 @example
11420 data.c data.h data.w data.x: data.stamp
11421 ## Recover from the removal of $@@
11422         @@if test -f $@@; then :; else \
11423           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
11424 ## mkdir is a portable test-and-set
11425           if mkdir data.lock 2>/dev/null; then \
11426 ## This code is being executed by the first process.
11427             rm -f data.stamp; \
11428             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
11429             result=$$?; rm -rf data.lock; exit $$result; \
11430           else \
11431 ## This code is being executed by the follower processes.
11432 ## Wait until the first process is done.
11433             while test -d data.lock; do sleep 1; done; \
11434 ## Succeed if and only if the first process succeeded.
11435             test -f data.stamp; \
11436           fi; \
11437         fi
11438 @end example
11440 Using a dedicated witness, like @file{data.stamp}, is very handy when
11441 the list of output files is not known beforehand.  As an illustration,
11442 consider the following rules to compile many @file{*.el} files into
11443 @file{*.elc} files in a single command.  It does not matter how
11444 @code{ELFILES} is defined (as long as it is not empty: empty targets
11445 are not accepted by POSIX).
11447 @example
11448 ELFILES = one.el two.el three.el @dots{}
11449 ELCFILES = $(ELFILES:=c)
11451 elc-stamp: $(ELFILES)
11452         @@rm -f elc-temp
11453         @@touch elc-temp
11454         $(elisp_comp) $(ELFILES)
11455         @@mv -f elc-temp $@@
11457 $(ELCFILES): elc-stamp
11458 ## Recover from the removal of $@@
11459         @@if test -f $@@; then :; else \
11460           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
11461           if mkdir elc-lock 2>/dev/null; then \
11462 ## This code is being executed by the first process.
11463             rm -f elc-stamp; \
11464             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
11465             rmdir elc-lock; \
11466           else \
11467 ## This code is being executed by the follower processes.
11468 ## Wait until the first process is done.
11469             while test -d elc-lock; do sleep 1; done; \
11470 ## Succeed if and only if the first process succeeded.
11471             test -f elc-stamp; exit $$?; \
11472           fi; \
11473         fi
11474 @end example
11475 @c $$
11477 For completeness it should be noted that GNU @command{make} is able to
11478 express rules with multiple output files using pattern rules
11479 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
11480 Manual}).  We do not discuss pattern rules here because they are not
11481 portable, but they can be convenient in packages that assume GNU
11482 @command{make}.
11485 @node Hard-Coded Install Paths
11486 @section Installing to Hard-Coded Locations
11488 @display
11489 My package needs to install some configuration file.  I tried to use
11490 the following rule, but @samp{make distcheck} fails.  Why?
11492 @example
11493 # Do not do this.
11494 install-data-local:
11495         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
11496 @end example
11497 @end display
11499 @display
11500 My package needs to populate the installation directory of another
11501 package at install-time.  I can easily compute that installation
11502 directory in @file{configure}, but if I install files therein,
11503 @samp{make distcheck} fails.  How else should I do?
11504 @end display
11506 These two setups share their symptoms: @samp{make distcheck} fails
11507 because they are installing files to hard-coded paths.  In the later
11508 case the path is not really hard-coded in the package, but we can
11509 consider it to be hard-coded in the system (or in whichever tool that
11510 supplies the path).  As long as the path does not use any of the
11511 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
11512 @samp{$(datadir)}, etc.), the effect will be the same:
11513 user-installations are impossible.
11515 When a (non-root) user wants to install a package, he usually has no
11516 right to install anything in @file{/usr} or @file{/usr/local}.  So he
11517 does something like @samp{./configure --prefix ~/usr} to install
11518 package in his own @file{~/usr} tree.
11520 If a package attempts to install something to some hard-coded path
11521 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
11522 then the installation will fail.  @samp{make distcheck} performs such
11523 a @option{--prefix} installation, hence it will fail too.
11525 Now, there are some easy solutions.
11527 The above @code{install-data-local} example for installing
11528 @file{/etc/afile} would be better replaced by
11530 @example
11531 sysconf_DATA = afile
11532 @end example
11534 @noindent
11535 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
11536 this is what the GNU Standards require.  When such a package is
11537 installed on an FHS compliant system, the installer will have to set
11538 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
11539 should not be concerned by such site policies: use the appropriate
11540 standard directory variable to install your files so that the installer
11541 can easily redefine these variables to match their site conventions.
11543 Installing files that should be used by another package is slightly
11544 more involved.  Let's take an example and assume you want to install
11545 a shared library that is a Python extension module.  If you ask Python
11546 where to install the library, it will answer something like this:
11548 @example
11549 % @kbd{python -c 'from distutils import sysconfig;
11550              print sysconfig.get_python_lib(1,0)'}
11551 /usr/lib/python2.5/site-packages
11552 @end example
11554 If you indeed use this absolute path to install your shared library,
11555 non-root users will not be able to install the package, hence
11556 distcheck fails.
11558 Let's do better.  The @samp{sysconfig.get_python_lib()} function
11559 actually accepts a third argument that will replace Python's
11560 installation prefix.
11562 @example
11563 % @kbd{python -c 'from distutils import sysconfig;
11564              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
11565 $@{exec_prefix@}/lib/python2.5/site-packages
11566 @end example
11568 You can also use this new path.  If you do
11569 @itemize @bullet
11570 @item
11571 root users can install your package with the same @option{--prefix}
11572 as Python (you get the behavior of the previous attempt)
11574 @item
11575 non-root users can install your package too, they will have the
11576 extension module in a place that is not searched by Python but they
11577 can work around this using environment variables (and if you installed
11578 scripts that use this shared library, it's easy to tell Python were to
11579 look in the beginning of your script, so the script works in both
11580 cases).
11581 @end itemize
11583 The @code{AM_PATH_PYTHON} macro uses similar commands to define
11584 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
11586 Of course not all tools are as advanced as Python regarding that
11587 substitution of @var{prefix}.  So another strategy is to figure the
11588 part of the installation directory that must be preserved.  For
11589 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
11590 computes @samp{$(lispdir)}:
11592 @example
11593 $EMACS -batch -q -eval '(while load-path
11594   (princ (concat (car load-path) "\n"))
11595   (setq load-path (cdr load-path)))' >conftest.out
11596 lispdir=`sed -n
11597   -e 's,/$,,'
11598   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
11599         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
11600       @}'
11601   -e '/.*\/share\/x*emacs\/site-lisp$/@{
11602         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
11603       @}'
11604   conftest.out`
11605 @end example
11607 I.e., it just picks the first directory that looks like
11608 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
11609 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
11610 @samp{$@{datadir@}} appropriately.
11612 The emacs case looks complicated because it processes a list and
11613 expects two possible layouts, otherwise it's easy, and the benefits for
11614 non-root users are really worth the extra @command{sed} invocation.
11617 @node Debugging Make Rules
11618 @section Debugging Make Rules
11619 @cindex debugging rules
11620 @cindex rules, debugging
11622 The rules and dependency trees generated by @command{automake} can get
11623 rather complex, and leave the developer head-scratching when things
11624 don't work as expected.  Besides the debug options provided by the
11625 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
11626 Manual}), here's a couple of further hints for debugging makefiles
11627 generated by @command{automake} effectively:
11629 @itemize
11630 @item
11631 If less verbose output has been enabled in the package with the
11632 @samp{silent-rules} option (@pxref{Options}), you can use
11633 @code{make V=1} to see the commands being executed.
11634 @item
11635 @code{make -n} can help show what would be done without actually doing
11636 it.  Note however, that this will @emph{still execute} commands prefixed
11637 with @samp{+}, and, when using GNU @command{make}, commands that contain
11638 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
11639 Execution,,, make, The GNU Make Manual}).
11640 Typically, this is helpful to show what recursive rules would do, but it
11641 means that, in your own rules, you should not mix such recursion with
11642 actions that change any files.@footnote{Automake's @samp{dist} and
11643 @samp{distcheck} rules had a bug in this regard in that they created
11644 directories even with @option{-n}, but this has been fixed in Automake
11645 1.11.}  Furthermore, note that GNU @command{make} will update
11646 prerequisites for the @file{Makefile} file itself even with @option{-n}
11647 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
11648 @item
11649 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
11650 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
11651 portability quirks associated with this construct.
11652 @end itemize
11655 @node History
11656 @chapter History of Automake
11658 This chapter presents various aspects of the history of Automake.  The
11659 exhausted reader can safely skip it; this will be more of interest to
11660 nostalgic people, or to those curious to learn about the evolution of
11661 Automake.
11663 @menu
11664 * Timeline::                    The Automake story.
11665 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
11666 * Releases::                    Statistics about Automake Releases
11667 @end menu
11669 @node Timeline
11670 @section Timeline
11672 @table @asis
11673 @item 1994-09-19 First CVS commit.
11675 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
11676 working on Automake (or AutoMake, as it was spelt then) this Monday.
11678 The first version of the @command{automake} script looks as follows.
11680 @example
11681 #!/bin/sh
11683 status=0
11685 for makefile
11687   if test ! -f $@{makefile@}.am; then
11688     echo "automake: $@{makefile@}.am: No such honkin' file"
11689     status=1
11690     continue
11691   fi
11693   exec 4> $@{makefile@}.in
11695 done
11696 @end example
11698 From this you can already see that Automake will be about reading
11699 @file{*.am} file and producing @file{*.in} files.  You cannot see
11700 anything else, but if you also know that David is the one who created
11701 Autoconf two years before you can guess the rest.
11703 Several commits follow, and by the end of the day Automake is
11704 reported to work for GNU fileutils and GNU m4.
11706 The modus operandi is the one that is still used today: variable
11707 assignments in @file{Makefile.am} files trigger injections of
11708 precanned @file{Makefile} fragments into the generated
11709 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
11710 by the 4.4BSD @command{make} and include files, however Automake aims
11711 to be portable and to conform to the GNU standards for @file{Makefile}
11712 variables and targets.
11714 At this point, the most recent release of Autoconf is version 1.11,
11715 and David is preparing to release Autoconf 2.0 in late October.  As a
11716 matter of fact, he will barely touch Automake after September.
11718 @item 1994-11-05 David MacKenzie's last commit.
11720 At this point Automake is a 200 line portable shell script, plus 332
11721 lines of @file{Makefile} fragments.  In the @file{README}, David
11722 states his ambivalence between ``portable shell'' and ``more
11723 appropriate language'':
11725 @quotation
11726 I wrote it keeping in mind the possibility of it becoming an Autoconf
11727 macro, so it would run at configure-time.  That would slow
11728 configuration down a bit, but allow users to modify the Makefile.am
11729 without needing to fetch the AutoMake package.  And, the Makefile.in
11730 files wouldn't need to be distributed.  But all of AutoMake would.  So
11731 I might reimplement AutoMake in Perl, m4, or some other more
11732 appropriate language.
11733 @end quotation
11735 Automake is described as ``an experimental Makefile generator''.
11736 There is no documentation.  Adventurous users are referred to the
11737 examples and patches needed to use Automake with GNU m4 1.3, fileutils
11738 3.9, time 1.6, and development versions of find and indent.
11740 These examples seem to have been lost.  However at the time of writing
11741 (10 years later in September, 2004) the FSF still distributes a
11742 package that uses this version of Automake: check out GNU termutils
11743 2.0.
11745 @item 1995-11-12 Tom Tromey's first commit.
11747 After one year of inactivity, Tom Tromey takes over the package.
11748 Tom was working on GNU cpio back then, and doing this just for fun,
11749 having trouble finding a project to contribute to.  So while hacking
11750 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
11751 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
11752 grabbed it and tried it out.
11754 Tom didn't talk to djm about it until later, just to make sure he
11755 didn't mind if he made a release.  He did a bunch of early releases to
11756 the Gnits folks.
11758 Gnits was (and still is) totally informal, just a few GNU friends who
11759 Fran@,cois Pinard knew, who were all interested in making a common
11760 infrastructure for GNU projects, and shared a similar outlook on how
11761 to do it.  So they were able to make some progress.  It came along
11762 with Autoconf and extensions thereof, and then Automake from David and
11763 Tom (who were both gnitsians).  One of their ideas was to write a
11764 document paralleling the GNU standards, that was more strict in some
11765 ways and more detailed.  They never finished the GNITS standards, but
11766 the ideas mostly made their way into Automake.
11768 @item 1995-11-23 Automake 0.20
11770 Besides introducing automatic dependency tracking (@pxref{Dependency
11771 Tracking Evolution}), this version also supplies a 9-page manual.
11773 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
11774 exist, so many things had to be done by hand.  For instance, here is
11775 what a configure.in (this is the former name of the
11776 @file{configure.ac} we use today) must contain in order to use
11777 Automake 0.20:
11779 @example
11780 PACKAGE=cpio
11781 VERSION=2.3.911
11782 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
11783 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
11784 AC_SUBST(PACKAGE)
11785 AC_SUBST(VERSION)
11786 AC_ARG_PROGRAM
11787 AC_PROG_INSTALL
11788 @end example
11790 (Today all of the above is achieved by @code{AC_INIT} and
11791 @code{AM_INIT_AUTOMAKE}.)
11793 Here is how programs are specified in @file{Makefile.am}:
11795 @example
11796 PROGRAMS = hello
11797 hello_SOURCES = hello.c
11798 @end example
11800 This looks pretty much like what we do today, except the
11801 @code{PROGRAMS} variable has no directory prefix specifying where
11802 @file{hello} should be installed: all programs are installed in
11803 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
11804 that must be built but not installed (it is called
11805 @code{noinst_PROGRAMS} nowadays).
11807 Programs can be built conditionally using @code{AC_SUBST}itutions:
11809 @example
11810 PROGRAMS = @@progs@@
11811 AM_PROGRAMS = foo bar baz
11812 @end example
11814 (@code{AM_PROGRAMS} has since then been renamed to
11815 @code{EXTRA_PROGRAMS}.)
11817 Similarly scripts, static libraries, and data can be built and installed
11818 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
11819 However @code{LIBRARIES} were treated a bit specially in that Automake
11820 did automatically supply the @file{lib} and @file{.a} prefixes.
11821 Therefore to build @file{libcpio.a}, one had to write
11823 @example
11824 LIBRARIES = cpio
11825 cpio_SOURCES = ...
11826 @end example
11828 Extra files to distribute must be listed in @code{DIST_OTHER} (the
11829 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
11830 distributed should appear in @code{DIST_SUBDIRS}, but the manual
11831 describes this as a temporary ugly hack (today extra directories should
11832 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
11833 for another purpose, @pxref{Conditional Subdirectories}).
11835 @item 1995-11-26 Automake 0.21
11837 In less time than it takes to cook a frozen pizza, Tom rewrites
11838 Automake using Perl.  At this time Perl 5 is only one year old, and
11839 Perl 4.036 is in use at many sites.  Supporting several Perl versions
11840 has been a source of problems through the whole history of Automake.
11842 If you never used Perl 4, imagine Perl 5 without objects, without
11843 @samp{my} variables (only dynamically scoped @samp{local} variables),
11844 without function prototypes, with function calls that needs to be
11845 prefixed with @samp{&}, etc.  Traces of this old style can still be
11846 found in today's @command{automake}.
11848 @item 1995-11-28 Automake 0.22
11849 @itemx 1995-11-29 Automake 0.23
11851 Bug fixes.
11853 @item 1995-12-08 Automake 0.24
11854 @itemx 1995-12-10 Automake 0.25
11856 Releases are raining.  0.24 introduces the uniform naming scheme we
11857 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
11858 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
11859 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
11860 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
11861 prefixes.)  Adding support for prefixes like that was one of the major
11862 ideas in @command{automake}; it has lasted pretty well.
11864 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
11865 Pinard's doing).
11867 0.25 fixes a Perl 4 portability bug.
11869 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
11870 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
11872 @item 1996-01-03 Automake 0.26
11873 @itemx 1996-01-03 Automake 0.27
11875 Of the many changes and suggestions sent by Fran@,cois Pinard and
11876 included in 0.26, perhaps the most important is the advice that to
11877 ease customization a user rule or variable definition should always
11878 override an Automake rule or definition.
11880 Gordon Matzigkeit and Jim Meyering are two other early contributors
11881 that have been sending fixes.
11883 0.27 fixes yet another Perl 4 portability bug.
11885 @item 1996-01-13 Automake 0.28
11887 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
11888 support.  This is an important step because until this version
11889 Automake only knew about the @file{Makefile.am}s it processed.
11890 @file{configure.in} was Autoconf's world and the link between Autoconf
11891 and Automake had to be done by the @file{Makefile.am} author.  For
11892 instance, if @file{config.h} was generated by @file{configure}, it was the
11893 package maintainer's responsibility to define the @code{CONFIG_HEADER}
11894 variable in each @file{Makefile.am}.
11896 Succeeding releases will rely more and more on scanning
11897 @file{configure.in} to better automate the Autoconf integration.
11899 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
11900 @option{--gnu} and @option{--gnits} options, the latter being stricter.
11902 @item 1996-02-07 Automake 0.29
11904 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
11905 and rebuild rules for @file{configure}-generated file are
11906 automatically output.
11908 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
11909 scheme.
11911 @item 1996-02-24 Automake 0.30
11913 The test suite is born.  It contains 9 tests.  From now on test cases
11914 will be added pretty regularly (@pxref{Releases}), and this proved to
11915 be really helpful later on.
11917 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
11919 All the third-party Autoconf macros, written mostly by Fran@,cois
11920 Pinard (and later Jim Meyering), are distributed in Automake's
11921 hand-written @file{aclocal.m4} file.  Package maintainers are expected
11922 to extract the necessary macros from this file.  (In previous versions
11923 you had to copy and paste them from the manual...)
11925 @item 1996-03-11 Automake 0.31
11927 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
11928 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
11929 whenever the @code{TESTS} variable is defined.
11931 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
11932 prefix is introduced.  The syntax is now the same as today.
11934 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
11936 @item 1996-04-27 Automake 0.32
11938 @code{-hook} targets are introduced; an idea from Dieter Baron.
11940 @file{*.info} files, which were output in the build directory are
11941 now built in the source directory, because they are distributed.  It
11942 seems these files like to move back and forth as that will happen
11943 again in future versions.
11945 @item 1996-05-18 Automake 0.33
11947 Gord Matzigkeit's main two contributions:
11949 @itemize
11950 @item very preliminary libtool support
11951 @item the distcheck rule
11952 @end itemize
11954 Although they were very basic at this point, these are probably
11955 among the top features for Automake today.
11957 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
11958 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
11959 author (@pxref{maintainer-mode}).
11961 @item 1996-05-28 Automake 1.0
11963 After only six months of heavy development, the @command{automake} script is
11964 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
11965 package has 30 pages of documentation, and 38 test cases.
11966 @file{aclocal.m4} contains 4 macros.
11968 From now on and until version 1.4, new releases will occur at a rate
11969 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
11970 been the name of beta releases for 1.2.  This is the first time
11971 Automake uses suffix letters to designate beta releases, a habit that
11972 lasts.
11974 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
11976 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
11978 Between June and October, the Autoconf development is almost stalled.
11979 Roland McGrath has been working at the beginning of the year.  David
11980 comes back in November to release 2.12, but he won't touch Autoconf
11981 anymore after this year, and Autoconf then really stagnates.  The
11982 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
11984 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
11986 The mailing list is announced as follows:
11987 @smallexample
11988 I've created the "automake" mailing list.  It is
11989 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
11990 automake-request@@gnu.ai.mit.edu.
11992 The charter of this list is discussion of automake, autoconf, and
11993 other configuration/portability tools (e.g., libtool).  It is expected
11994 that discussion will range from pleas for help all the way up to
11995 patches.
11997 This list is archived on the FSF machines.  Offhand I don't know if
11998 you can get the archive without an account there.
12000 This list is open to anybody who wants to join.  Tell all your
12001 friends!
12002 -- Tom Tromey
12003 @end smallexample
12005 Before that people were discussing Automake privately, on the Gnits
12006 mailing list (which is not public either), and less frequently on
12007 @code{gnu.misc.discuss}.
12009 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
12010 noticed.  The archives of the early years of the
12011 @code{automake@@gnu.org} list have been lost, so today it is almost
12012 impossible to find traces of discussions that occurred before 1999.
12013 This has been annoying more than once, as such discussions can be
12014 useful to understand the rationale behind a piece of uncommented code
12015 that was introduced back then.
12017 @item 1997-06-22 Automake 1.2
12019 Automake developments continues, and more and more new Autoconf macros
12020 are required.  Distributing them in @file{aclocal.m4} and requiring
12021 people to browse this file to extract the relevant macros becomes
12022 uncomfortable.  Ideally, some of them should be contributed to
12023 Autoconf so that they can be used directly, however Autoconf is
12024 currently inactive.  Automake 1.2 consequently introduces
12025 @command{aclocal} (@command{aclocal} was actually started on
12026 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
12027 file from a repository of third-party macros.  Because Autoconf has
12028 stalled, Automake also becomes a kind of repository for such
12029 third-party macros, even macros completely unrelated to Automake (for
12030 instance macros that fix broken Autoconf macros).
12032 The 1.2 release contains 20 macros, including the
12033 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
12034 @file{configure.in}.
12036 Libtool is fully supported using @code{*_LTLIBRARIES}.
12038 The missing script is introduced by Fran@,cois Pinard; it is meant to be
12039 a better solution than @code{AM_MAINTAINER_MODE}
12040 (@pxref{maintainer-mode}).
12042 Conditionals support was implemented by Ian Lance Taylor.  At the
12043 time, Tom and Ian were working on an internal project at Cygnus.  They
12044 were using ILU, which is pretty similar to CORBA@.  They wanted to
12045 integrate ILU into their build, which was all @file{configure}-based,
12046 and Ian thought that adding conditionals to @command{automake} was
12047 simpler than doing all the work in @file{configure} (which was the
12048 standard at the time).  So this was actually funded by Cygnus.
12050 This very useful but tricky feature will take a lot of time to
12051 stabilize.  (At the time this text is written, there are still
12052 primaries that have not been updated to support conditional
12053 definitions in Automake 1.9.)
12055 The @command{automake} script has almost doubled: 6089 lines of Perl,
12056 plus 1294 lines of @file{Makefile} fragments.
12058 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
12060 @item 1998-04-05 Automake 1.3
12062 This is a small advance compared to 1.2.
12063 It adds support for assembly, and preliminary support for Java.
12065 Perl 5.004_04 is out, but fixes to support Perl 4 are still
12066 regularly submitted whenever Automake breaks it.
12068 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
12070 Sourceware was setup by Jason Molenda to host open source projects.
12072 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
12073 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake:
12074 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
12075 publicly accessible CVS repository.  This CVS repository is a copy of
12076 the one Tom was using on his machine, which in turn is based on
12077 a copy of the CVS repository of David MacKenzie.  This is why we still
12078 have to full source history.  (Automake was on Sourceware until 2007-10-29,
12079 when it moved to a git repository on @code{savannah.gnu.org},
12080 but the Sourceware host had been renamed to @code{sources.redhat.com}.)
12082 The oldest file in the administrative directory of the CVS repository
12083 that was created on Sourceware is dated 1998-09-19, while the
12084 announcement that @command{automake} and @command{autoconf} had joined
12085 @command{sourceware} was made on 1998-10-26.  They were among the
12086 first projects to be hosted there.
12088 The heedful reader will have noticed Automake was exactly 4 years old
12089 on 1998-09-19.
12091 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
12093 @item 1999-01-14 Automake 1.4
12095 This release adds support for Fortran 77 and for the @code{include}
12096 statement.  Also, @samp{+=} assignments are introduced, but it is
12097 still quite easy to fool Automake when mixing this with conditionals.
12099 These two releases, Automake 1.4 and Autoconf 2.13 make a duo that
12100 will be used together for years.
12102 @command{automake} is 7228 lines, plus 1591 lines of Makefile
12103 fragment, 20 macros (some 1.3 macros were finally contributed back to
12104 Autoconf), 197 test cases, and 51 pages of documentation.
12106 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
12108 This implements a new dependency tracking schemed that should be
12109 able to handle automatic dependency tracking using any compiler (not
12110 just gcc) and any make (not just GNU @command{make}).  In addition,
12111 the new scheme should be more reliable than the old one, as
12112 dependencies are generated on the end user's machine.  Alexandre Oliva
12113 creates depcomp for this purpose.
12115 @xref{Dependency Tracking Evolution}, for more details about the
12116 evolution of automatic dependency tracking in Automake.
12118 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
12120 This was a huge problem since we also had patches going in on the
12121 trunk.  The merge took a long time and was very painful.
12123 @item 2000-05-10
12125 Since September 1999 and until 2003, Akim Demaille will be zealously
12126 revamping Autoconf.
12128 @quotation
12129 I think the next release should be called "3.0".@*
12130 Let's face it: you've basically rewritten autoconf.@*
12131 Every weekend there are 30 new patches.@*
12132 I don't see how we could call this "2.15" with a straight face.@*
12133 -- Tom Tromey on @email{autoconf@@gnu.org}
12134 @end quotation
12136 Actually Akim works like a submarine: he will pile up patches while he
12137 works off-line during the weekend, and flush them in batch when he
12138 resurfaces on Monday.
12140 @item 2001-01-24
12142 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
12143 is out, and Akim has to find something to do during his week-end :)
12145 @item 2001-01-28
12147 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
12149 @quotation
12150 Aiieeee!  I was dreading the day that the Demaillator turned his
12151 sights on automake@dots{} and now it has arrived! -- Tom Tromey
12152 @end quotation
12154 It's only the beginning: in two months he will send 192 patches.  Then
12155 he would slow down so Tom can catch up and review all this.  Initially
12156 Tom actually read all these patches, then he probably trustingly
12157 answered OK to most of them, and finally gave up and let Akim apply
12158 whatever he wanted.  There was no way to keep up with that patch rate.
12160 @quotation
12161 Anyway the patch below won't apply since it predates Akim's
12162 sourcequake; I have yet to figure where the relevant passage has
12163 been moved :) -- Alexandre Duret-Lutz
12164 @end quotation
12166 All these patches were sent to and discussed on
12167 @email{automake@@gnu.org}, so subscribed users were literally drowning in
12168 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
12169 mailing list was created in May.
12171 Year after year, Automake had drifted away from its initial design:
12172 construct @file{Makefile.in} by assembling various @file{Makefile}
12173 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
12174 various places in the @command{automake} script itself; this does not
12175 help ensuring a consistent treatment of these rules (for instance
12176 making sure that user-defined rules override Automake's own rules).
12177 One of Akim's goal was moving all these hard-coded rules to separate
12178 @file{Makefile} fragments, so the logic could be centralized in a
12179 @file{Makefile} fragment processor.
12181 Another significant contribution of Akim is the interface with the
12182 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
12183 this time was to read the file and grep the various macro of interest
12184 to Automake.  Doing so could break in many unexpected ways; @command{automake}
12185 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
12186 where the arguments are known only when M4 is run), or conversely it
12187 could detect some macro that was not expanded (because it is called
12188 conditionally).  In the CVS version of Autoconf, Akim had implemented
12189 the @option{--trace} option, which provides accurate information about
12190 where macros are actually called and with what arguments.  Akim will
12191 equip Automake with a second @file{configure.in} scanner that uses
12192 this @option{--trace} interface.  Since it was not sensible to drop the
12193 Autoconf 2.13 compatibility yet, this experimental scanner was only
12194 used when an environment variable was set, the traditional
12195 grep-scanner being still the default.
12197 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
12199 It has been more than two years since Automake 1.4, CVS Automake has
12200 suffered lot's of heavy changes and still is not ready for release.
12201 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
12203 @item 2001-05-08 Automake 1.4-p1
12204 @itemx 2001-05-24 Automake 1.4-p2
12206 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
12207 release'' of Automake:
12209 @quotation
12210 The main purpose of this release is to have a stable automake
12211 which is compatible with the latest stable libtool.
12212 @end quotation
12214 The release also contains obvious fixes for bugs in Automake 1.4,
12215 some of which were reported almost monthly.
12217 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
12219 @item 2001-06-07 Automake 1.4-p3
12220 @itemx 2001-06-10 Automake 1.4-p4
12221 @itemx 2001-07-15 Automake 1.4-p5
12223 Gary continues his patch-release series.  These also add support for
12224 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
12225 @file{configure.ac} over @file{configure.in}, and it introduces a new
12226 syntax for @code{AC_OUTPUT}ing files.
12228 @item 2001-08-23 Automake 1.5
12230 A major and long-awaited release, that comes more than two years after
12231 1.4.  It brings many changes, among which:
12232 @itemize
12233 @item The new dependency tracking scheme that uses @command{depcomp}.
12234 Aside from the improvement on the dependency tracking itself
12235 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
12236 of @command{automake}-generated @file{Makefile.in}s as the @file{Makefile.in}s
12237 used during development are now the same as those used in
12238 distributions.  Before that the @file{Makefile.in}s generated for
12239 maintainers required GNU @command{make} and GCC, they were different
12240 from the portable @file{Makefile} generated for distribution; this was
12241 causing some confusion.
12243 @item Support for per-target compilation flags.
12245 @item Support for reference to files in subdirectories in most
12246 @file{Makefile.am} variables.
12248 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
12249 prefixes.
12250 @item Perl 4 support is finally dropped.
12251 @end itemize
12253 1.5 did break several packages that worked with 1.4.  Enough so that
12254 Linux distributions could not easily install the new Automake version
12255 without breaking many of the packages for which they had to run
12256 @command{automake}.
12258 Some of these breakages were effectively bugs that would eventually be
12259 fixed in the next release.  However, a lot of damage was caused by
12260 some changes made deliberately to render Automake stricter on some
12261 setup we did consider bogus.  For instance, @samp{make distcheck} was
12262 improved to check that @samp{make uninstall} did remove all the files
12263 @samp{make install} installed, that @samp{make distclean} did not omit
12264 some file, and that a VPATH build would work even if the source
12265 directory was read-only.  Similarly, Automake now rejects multiple
12266 definitions of the same variable (because that would mix very badly
12267 with conditionals), and @samp{+=} assignments with no previous
12268 definition.  Because these changes all occurred suddenly after 1.4 had
12269 been established for more than two years, it hurt users.
12271 To make matter worse, meanwhile Autoconf (now at version 2.52) was
12272 facing similar troubles, for similar reasons.
12274 @item 2002-03-05 Automake 1.6
12276 This release introduced versioned installation (@pxref{API
12277 Versioning}).  This was mainly pushed by Havoc Pennington, taking the
12278 GNOME source tree as motive: due to incompatibilities between the
12279 autotools it's impossible for the GNOME packages to switch to Autoconf
12280 2.53 and Automake 1.5 all at once, so they are currently stuck with
12281 Autoconf 2.13 and Automake 1.4.
12283 The idea was to call this version @file{automake-1.6}, call all its
12284 bug-fix versions identically, and switch to @file{automake-1.7} for
12285 the next release that adds new features or changes some rules.  This
12286 scheme implies maintaining a bug-fix branch in addition to the
12287 development trunk, which means more work from the maintainer, but
12288 providing regular bug-fix releases proved to be really worthwhile.
12290 Like 1.5, 1.6 also introduced a bunch of incompatibilities, intentional or
12291 not.  Perhaps the more annoying was the dependence on the newly
12292 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
12293 since its explosive 2.50 release and included changes required to fix
12294 some bugs in Automake.  In order to upgrade to Automake 1.6, people
12295 now had to upgrade Autoconf too; for some packages it was no picnic.
12297 While versioned installation helped people to upgrade, it also
12298 unfortunately allowed people not to upgrade.  At the time of writing,
12299 some Linux distributions are shipping packages for Automake 1.4, 1.5,
12300 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
12301 Some distribution also call 1.4 the ``stable'' version, and present
12302 ``1.9'' as the development version; this does not really makes sense
12303 since 1.9 is way more solid than 1.4.  All this does not help the
12304 newcomer.
12306 @item 2002-04-11 Automake 1.6.1
12308 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
12309 This one and those following will be handled by Alexandre
12310 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
12311 but his interest into Automake is drifting away towards projects like
12312 @command{gcj}.
12314 Alexandre has been using Automake since 2000, and started to
12315 contribute mostly on Akim's incitement (Akim and Alexandre have been
12316 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
12317 a lot of free time to enjoy hacking Automake.
12319 @item 2002-06-14 Automake 1.6.2
12321 @item 2002-07-28 Automake 1.6.3
12322 @itemx 2002-07-28 Automake 1.4-p6
12324 Two releases on the same day.  1.6.3 is a bug-fix release.
12326 Tom Tromey backported the versioned installation mechanism on the 1.4
12327 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
12328 side by side.  Another request from the GNOME folks.
12330 @item 2002-09-25 Automake 1.7
12332 This release switches to the new @file{configure.ac} scanner Akim
12333 was experimenting in 1.5.
12335 @item 2002-10-16 Automake 1.7.1
12336 @itemx 2002-12-06 Automake 1.7.2
12337 @itemx 2003-02-20 Automake 1.7.3
12338 @itemx 2003-04-23 Automake 1.7.4
12339 @itemx 2003-05-18 Automake 1.7.5
12340 @itemx 2003-07-10 Automake 1.7.6
12341 @itemx 2003-09-07 Automake 1.7.7
12342 @itemx 2003-10-07 Automake 1.7.8
12344 Many bug-fix releases.  1.7 lasted because the development version
12345 (upcoming 1.8) was suffering some major internal revamping.
12347 @item 2003-10-26 Automake on screen
12349 Episode 49, `Repercussions', in the third season of the `Alias' TV
12350 show is first aired.
12352 Marshall, one of the characters, is working on a computer virus that he
12353 has to modify before it gets into the wrong hands or something like
12354 that.  The screenshots you see do not show any program code, they show
12355 a @file{Makefile.in} @code{generated by automake}...
12357 @item 2003-11-09 Automake 1.7.9
12359 @item 2003-12-10 Automake 1.8
12361 The most striking update is probably that of @command{aclocal}.
12363 @command{aclocal} now uses @code{m4_include} in the produced
12364 @file{aclocal.m4} when the included macros are already distributed
12365 with the package (an idiom used in many packages), which reduces code
12366 duplication.  Many people liked that, but in fact this change was
12367 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
12368 must be rebuilt whenever a dependency of @file{configure} changes, but
12369 all the @file{m4} files included in @file{aclocal.m4} where unknown
12370 from @command{automake}.  Now @command{automake} can just trace the
12371 @code{m4_include}s to discover the dependencies.
12373 @command{aclocal} also starts using the @option{--trace} Autoconf option
12374 in order to discover used macros more accurately.  This will turn out
12375 to be very tricky (later releases will improve this) as people had
12376 devised many ways to cope with the limitation of previous
12377 @command{aclocal} versions, notably using handwritten
12378 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
12379 rule that is already included by such statement.
12381 Automake also has seen its guts rewritten.  Although this rewriting
12382 took a lot of efforts, it is only apparent to the users in that some
12383 constructions previously disallowed by the implementation now work
12384 nicely.  Conditionals, Locations, Variable and Rule definitions,
12385 Options: these items on which Automake works have been rewritten as
12386 separate Perl modules, and documented.
12388 @itemx 2004-01-11 Automake 1.8.1
12389 @itemx 2004-01-12 Automake 1.8.2
12390 @itemx 2004-03-07 Automake 1.8.3
12391 @itemx 2004-04-25 Automake 1.8.4
12392 @itemx 2004-05-16 Automake 1.8.5
12394 @item 2004-07-28 Automake 1.9
12396 This release tries to simplify the compilation rules it outputs to
12397 reduce the size of the Makefile.  The complaint initially come from
12398 the libgcj developers.  Their @file{Makefile.in} generated with
12399 Automake 1.4 and custom build rules (1.4 did not support compiled
12400 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
12401 down to 1.2MB@.
12403 Aside from this it contains mainly minor changes and bug-fixes.
12405 @itemx 2004-08-11 Automake 1.9.1
12406 @itemx 2004-09-19 Automake 1.9.2
12408 Automake has ten years.  This chapter of the manual was initially
12409 written for this occasion.
12411 @itemx 2007-10-29 Automake repository moves to @code{savannah.gnu.org} and uses
12412 git as primary repository.
12414 @end table
12416 @node Dependency Tracking Evolution
12417 @section Dependency Tracking in Automake
12419 Over the years Automake has deployed three different dependency
12420 tracking methods.  Each method, including the current one, has had
12421 flaws of various sorts.  Here we lay out the different dependency
12422 tracking methods, their flaws, and their fixes.  We conclude with
12423 recommendations for tool writers, and by indicating future directions
12424 for dependency tracking work in Automake.
12426 @menu
12427 * First Take on Dependencies::  Precomputed dependency tracking
12428 * Dependencies As Side Effects::  Update at developer compile time
12429 * Dependencies for the User::   Update at user compile time
12430 * Techniques for Dependencies:: Alternative approaches
12431 * Recommendations for Tool Writers::  What tool writers can do to help
12432 * Future Directions for Dependencies::  Languages Automake does not know
12433 @end menu
12435 @node First Take on Dependencies
12436 @subsection First Take on Dependency Tracking
12437 @unnumberedsubsubsec Description
12439 Our first attempt at automatic dependency tracking was based on the
12440 method recommended by GNU @command{make}.  (@pxref{Automatic
12441 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
12442 make Manual})
12444 This version worked by precomputing dependencies ahead of time.  For
12445 each source file, it had a special @file{.P} file that held the
12446 dependencies.  There was a rule to generate a @file{.P} file by
12447 invoking the compiler appropriately.  All such @file{.P} files were
12448 included by the @file{Makefile}, thus implicitly becoming dependencies
12449 of @file{Makefile}.
12451 @unnumberedsubsubsec Bugs
12453 This approach had several critical bugs.
12455 @itemize
12456 @item
12457 The code to generate the @file{.P} file relied on @command{gcc}.
12458 (A limitation, not technically a bug.)
12459 @item
12460 The dependency tracking mechanism itself relied on GNU @command{make}.
12461 (A limitation, not technically a bug.)
12462 @item
12463 Because each @file{.P} file was a dependency of @file{Makefile}, this
12464 meant that dependency tracking was done eagerly by @command{make}.
12465 For instance, @samp{make clean} would cause all the dependency files
12466 to be updated, and then immediately removed.  This eagerness also
12467 caused problems with some configurations; if a certain source file
12468 could not be compiled on a given architecture for some reason,
12469 dependency tracking would fail, aborting the entire build.
12470 @item
12471 As dependency tracking was done as a pre-pass, compile times were
12472 doubled--the compiler had to be run twice per source file.
12473 @item
12474 @samp{make dist} re-ran @command{automake} to generate a
12475 @file{Makefile} that did not have automatic dependency tracking (and
12476 that was thus portable to any version of @command{make}).  In order to
12477 do this portably, Automake had to scan the dependency files and remove
12478 any reference that was to a source file not in the distribution.
12479 This process was error-prone.  Also, if @samp{make dist} was run in an
12480 environment where some object file had a dependency on a source file
12481 that was only conditionally created, Automake would generate a
12482 @file{Makefile} that referred to a file that might not appear in the
12483 end user's build.  A special, hacky mechanism was required to work
12484 around this.
12485 @end itemize
12487 @unnumberedsubsubsec Historical Note
12489 The code generated by Automake is often inspired by the
12490 @file{Makefile} style of a particular author.  In the case of the first
12491 implementation of dependency tracking, I believe the impetus and
12492 inspiration was Jim Meyering.  (I could be mistaken.  If you know
12493 otherwise feel free to correct me.)
12495 @node Dependencies As Side Effects
12496 @subsection Dependencies As Side Effects
12497 @unnumberedsubsubsec Description
12499 The next refinement of Automake's automatic dependency tracking scheme
12500 was to implement dependencies as side effects of the compilation.
12501 This was aimed at solving the most commonly reported problems with the
12502 first approach.  In particular we were most concerned with eliminating
12503 the weird rebuilding effect associated with make clean.
12505 In this approach, the @file{.P} files were included using the
12506 @code{-include} command, which let us create these files lazily.  This
12507 avoided the @samp{make clean} problem.
12509 We only computed dependencies when a file was actually compiled.  This
12510 avoided the performance penalty associated with scanning each file
12511 twice.  It also let us avoid the other problems associated with the
12512 first, eager, implementation.  For instance, dependencies would never
12513 be generated for a source file that was not compilable on a given
12514 architecture (because it in fact would never be compiled).
12516 @unnumberedsubsubsec Bugs
12518 @itemize
12519 @item
12520 This approach also relied on the existence of @command{gcc} and GNU
12521 @command{make}.  (A limitation, not technically a bug.)
12522 @item
12523 Dependency tracking was still done by the developer, so the problems
12524 from the first implementation relating to massaging of dependencies by
12525 @samp{make dist} were still in effect.
12526 @item
12527 This implementation suffered from the ``deleted header file'' problem.
12528 Suppose a lazily-created @file{.P} file includes a dependency on a
12529 given header file, like this:
12531 @example
12532 maude.o: maude.c something.h
12533 @end example
12535 Now suppose that the developer removes @file{something.h} and updates
12536 @file{maude.c} so that this include is no longer needed.  If he runs
12537 @command{make}, he will get an error because there is no way to create
12538 @file{something.h}.
12540 We fixed this problem in a later release by further massaging the
12541 output of @command{gcc} to include a dummy dependency for each header
12542 file.
12543 @end itemize
12545 @node Dependencies for the User
12546 @subsection Dependencies for the User
12547 @unnumberedsubsubsec Description
12549 The bugs associated with @samp{make dist}, over time, became a real
12550 problem.  Packages using Automake were being built on a large number
12551 of platforms, and were becoming increasingly complex.  Broken
12552 dependencies were distributed in ``portable'' @file{Makefile.in}s,
12553 leading to user complaints.  Also, the requirement for @command{gcc}
12554 and GNU @command{make} was a constant source of bug reports.  The next
12555 implementation of dependency tracking aimed to remove these problems.
12557 We realized that the only truly reliable way to automatically track
12558 dependencies was to do it when the package itself was built.  This
12559 meant discovering a method portable to any version of make and any
12560 compiler.  Also, we wanted to preserve what we saw as the best point
12561 of the second implementation: dependency computation as a side effect
12562 of compilation.
12564 In the end we found that most modern make implementations support some
12565 form of include directive.  Also, we wrote a wrapper script that let
12566 us abstract away differences between dependency tracking methods for
12567 compilers.  For instance, some compilers cannot generate dependencies
12568 as a side effect of compilation.  In this case we simply have the
12569 script run the compiler twice.  Currently our wrapper script
12570 (@command{depcomp}) knows about twelve different compilers (including
12571 a "compiler" that simply invokes @command{makedepend} and then the
12572 real compiler, which is assumed to be a standard Unix-like C compiler
12573 with no way to do dependency tracking).
12575 @unnumberedsubsubsec Bugs
12577 @itemize
12578 @item
12579 Running a wrapper script for each compilation slows down the build.
12580 @item
12581 Many users don't really care about precise dependencies.
12582 @item
12583 This implementation, like every other automatic dependency tracking
12584 scheme in common use today (indeed, every one we've ever heard of),
12585 suffers from the ``duplicated new header'' bug.
12587 This bug occurs because dependency tracking tools, such as the
12588 compiler, only generate dependencies on the successful opening of a
12589 file, and not on every probe.
12591 Suppose for instance that the compiler searches three directories for
12592 a given header, and that the header is found in the third directory.
12593 If the programmer erroneously adds a header file with the same name to
12594 the first directory, then a clean rebuild from scratch could fail
12595 (suppose the new header file is buggy), whereas an incremental rebuild
12596 will succeed.
12598 What has happened here is that people have a misunderstanding of what
12599 a dependency is.  Tool writers think a dependency encodes information
12600 about which files were read by the compiler.  However, a dependency
12601 must actually encode information about what the compiler tried to do.
12603 This problem is not serious in practice.  Programmers typically do not
12604 use the same name for a header file twice in a given project.  (At
12605 least, not in C or C++.  This problem may be more troublesome in
12606 Java.)  This problem is easy to fix, by modifying dependency
12607 generators to record every probe, instead of every successful open.
12609 @item
12610 Since Automake generates dependencies as a side effect of compilation,
12611 there is a bootstrapping problem when header files are generated by
12612 running a program.  The problem is that, the first time the build is
12613 done, there is no way by default to know that the headers are
12614 required, so make might try to run a compilation for which the headers
12615 have not yet been built.
12617 This was also a problem in the previous dependency tracking implementation.
12619 The current fix is to use @code{BUILT_SOURCES} to list built headers
12620 (@pxref{Sources}).  This causes them to be built before any other
12621 build rules are run.  This is unsatisfactory as a general solution,
12622 however in practice it seems sufficient for most actual programs.
12623 @end itemize
12625 This code is used since Automake 1.5.
12627 In GCC 3.0, we managed to convince the maintainers to add special
12628 command-line options to help Automake more efficiently do its job.  We
12629 hoped this would let us avoid the use of a wrapper script when
12630 Automake's automatic dependency tracking was used with @command{gcc}.
12632 Unfortunately, this code doesn't quite do what we want.  In
12633 particular, it removes the dependency file if the compilation fails;
12634 we'd prefer that it instead only touch the file in any way if the
12635 compilation succeeds.
12637 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
12638 detected at @command{configure} time, we inline the
12639 dependency-generation code and do not use the @command{depcomp}
12640 wrapper script.  This makes compilations faster for those using this
12641 compiler (probably our primary user base).  The counterpart is that
12642 because we have to encode two compilation rules in @file{Makefile}
12643 (with or without @command{depcomp}), the produced @file{Makefile}s are
12644 larger.
12646 @node Techniques for Dependencies
12647 @subsection Techniques for Computing Dependencies
12649 There are actually several ways for a build tool like Automake to
12650 cause tools to generate dependencies.
12652 @table @asis
12653 @item @command{makedepend}
12654 This was a commonly-used method in the past.  The idea is to run a
12655 special program over the source and have it generate dependency
12656 information.  Traditional implementations of @command{makedepend} are
12657 not completely precise; ordinarily they were conservative and
12658 discovered too many dependencies.
12659 @item The tool
12660 An obvious way to generate dependencies is to simply write the tool so
12661 that it can generate the information needed by the build tool.  This is
12662 also the most portable method.  Many compilers have an option to
12663 generate dependencies.  Unfortunately, not all tools provide such an
12664 option.
12665 @item The file system
12666 It is possible to write a special file system that tracks opens,
12667 reads, writes, etc, and then feed this information back to the build
12668 tool.  @command{clearmake} does this.  This is a very powerful
12669 technique, as it doesn't require cooperation from the
12670 tool.  Unfortunately it is also very difficult to implement and also
12671 not practical in the general case.
12672 @item @code{LD_PRELOAD}
12673 Rather than use the file system, one could write a special library to
12674 intercept @code{open} and other syscalls.  This technique is also quite
12675 powerful, but unfortunately it is not portable enough for use in
12676 @command{automake}.
12677 @end table
12679 @node Recommendations for Tool Writers
12680 @subsection Recommendations for Tool Writers
12682 We think that every compilation tool ought to be able to generate
12683 dependencies as a side effect of compilation.  Furthermore, at least
12684 while @command{make}-based tools are nearly universally in use (at
12685 least in the free software community), the tool itself should generate
12686 dummy dependencies for header files, to avoid the deleted header file
12687 bug.  Finally, the tool should generate a dependency for each probe,
12688 instead of each successful file open, in order to avoid the duplicated
12689 new header bug.
12691 @node Future Directions for Dependencies
12692 @subsection Future Directions for Dependencies
12694 Currently, only languages and compilers understood by Automake can
12695 have dependency tracking enabled.  We would like to see if it is
12696 practical (and worthwhile) to let this support be extended by the user
12697 to languages unknown to Automake.
12699 @node Releases
12700 @section Release Statistics
12702 The following table (inspired by @samp{perlhist(1)}) quantifies the
12703 evolution of Automake using these metrics:
12705 @table @asis
12706 @item Date, Rel
12707 The date and version of the release.
12708 @item am
12709 The number of lines of the @command{automake} script.
12710 @item acl
12711 The number of lines of the @command{aclocal} script.
12712 @item pm
12713 The number of lines of the @command{Perl} supporting modules.
12714 @item @file{*.am}
12715 The number of lines of the @file{Makefile} fragments.  The number in
12716 parentheses is the number of files.
12717 @item m4
12718 The number of lines (and files) of Autoconf macros.
12719 @item doc
12720 The number of pages of the documentation (the Postscript version).
12721 @item t
12722 The number of test cases in the test suite.  Of those, the number in
12723 parentheses is the number of generated test cases.
12724 @end table
12726 @multitable {8888-88-88} {8.8-p8} {8888} {8888} {8888} {8888 (88)} {8888 (88)} {888} {888 (88)}
12727 @headitem Date   @tab Rel    @tab   am @tab acl @tab   pm @tab @file{*.am} @tab m4 @tab doc @tab t
12728 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
12729 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
12730 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
12731 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
12732 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
12733 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
12734 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
12735 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
12736 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
12737 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
12738 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
12739 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
12740 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
12741 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
12742 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
12743 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
12744 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
12745 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (20) @tab  37 @tab 126
12746 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (23) @tab  39 @tab 156
12747 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
12748 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
12749 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
12750 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
12751 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 198
12752 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (20) @tab  51 @tab 198
12753 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (29) @tab  63 @tab 327
12754 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (27) @tab  66 @tab 365
12755 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (27) @tab  66 @tab 372
12756 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (27) @tab  67 @tab 386
12757 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (27) @tab  67 @tab 391
12758 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (20) @tab  49 @tab 197
12759 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (28) @tab  73 @tab 430
12760 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (28) @tab  73 @tab 437
12761 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (28) @tab  77 @tab 445
12762 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (29) @tab  84 @tab 448
12763 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (29) @tab  85 @tab 458
12764 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (29) @tab  85 @tab 459
12765 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (29) @tab  85 @tab 461
12766 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 467
12767 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 468
12768 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (29) @tab  90 @tab 468
12769 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (31) @tab 104 @tab 521
12770 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (31) @tab 104 @tab 525
12771 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (31) @tab 104 @tab 526
12772 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (31) @tab 111 @tab 530
12773 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (31) @tab 112 @tab 531
12774 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (31) @tab 112 @tab 533
12775 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (32) @tab 115 @tab 551
12776 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 115 @tab 552
12777 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 132 @tab 554
12778 @item 2004-11-01 @tab 1.9.3  @tab 7507 @tab 718 @tab 7804 @tab 3354 (40) @tab 1812 (32) @tab 134 @tab 556
12779 @item 2004-12-18 @tab 1.9.4  @tab 7508 @tab 718 @tab 7856 @tab 3361 (40) @tab 1811 (32) @tab 140 @tab 560
12780 @item 2005-02-13 @tab 1.9.5  @tab 7523 @tab 719 @tab 7859 @tab 3373 (40) @tab 1453 (32) @tab 142 @tab 562
12781 @item 2005-07-10 @tab 1.9.6  @tab 7539 @tab 699 @tab 7867 @tab 3400 (40) @tab 1453 (32) @tab 144 @tab 570
12782 @item 2006-10-15 @tab 1.10   @tab 7859 @tab 1072 @tab 8024 @tab 3512 (40) @tab 1496 (34) @tab 172 @tab 604
12783 @item 2008-01-19 @tab 1.10.1 @tab 7870 @tab 1089 @tab 8025 @tab 3520 (40) @tab 1499 (34) @tab 173 @tab 617
12784 @item 2008-11-23 @tab 1.10.2 @tab 7882 @tab 1089 @tab 8027 @tab 3540 (40) @tab 1509 (34) @tab 176 @tab 628
12785 @item 2009-05-17 @tab 1.11   @tab 8721 @tab 1092 @tab 8289 @tab 4164 (42) @tab 1714 (37) @tab 181 @tab 732 (20)
12786 @end multitable
12789 @c ========================================================== Appendices
12791 @page
12792 @node Copying This Manual
12793 @appendix Copying This Manual
12795 @menu
12796 * GNU Free Documentation License::  License for copying this manual
12797 @end menu
12799 @node GNU Free Documentation License
12800 @appendixsec GNU Free Documentation License
12801 @include fdl.texi
12803 @page
12804 @node Indices
12805 @appendix Indices
12807 @menu
12808 * Macro Index::                 Index of Autoconf macros
12809 * Variable Index::              Index of Makefile variables
12810 * General Index::               General index
12811 @end menu
12813 @node Macro Index
12814 @appendixsec Macro Index
12816 @printindex fn
12818 @node Variable Index
12819 @appendixsec Variable Index
12821 @printindex vr
12823 @node General Index
12824 @appendixsec General Index
12826 @printindex cp
12829 @page
12830 @contents
12831 @bye
12833 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
12834 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
12835 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
12836 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
12837 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
12838 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
12839 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
12840 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
12841 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
12842 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
12843 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
12844 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
12845 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
12846 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
12847 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
12848 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
12849 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
12850 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
12851 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
12852 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
12853 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
12854 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
12855 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
12856 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
12857 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
12858 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
12859 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
12860 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
12861 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
12862 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
12863 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
12864 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
12865 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
12866 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
12867 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
12868 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
12869 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
12870 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
12871 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
12872 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
12873 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
12874 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
12875 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
12876 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
12877 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
12878 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
12879 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
12880 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
12881 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
12882 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
12883 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
12884 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
12885 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
12886 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
12887 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
12888 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
12889 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
12890 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
12891 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
12892 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
12893 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
12894 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
12895 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
12896 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
12897 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
12898 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
12899 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
12900 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
12901 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
12902 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
12903 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
12904 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
12905 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
12906 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
12907 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
12908 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
12909 @c  LocalWords:  barexec Pinard's automatize initialize lzma xz