Avoid expand-before-require warning from newer autoconf.
[automake/ericb.git] / doc / automake.texi
blobce4cbcc47fabecc0143c03f7492bfa908128a975
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @setchapternewpage off
6 @c %**end of header
8 @include version.texi
10 @c @ovar(ARG, DEFAULT)
11 @c -------------------
12 @c The ARG is an optional argument.  To be used for macro arguments in
13 @c their documentation (@defmac).
14 @macro ovar{varname}
15 @r{[}@var{\varname\}@r{]}
16 @end macro
18 @copying
20 This manual is for @acronym{GNU} Automake (version @value{VERSION},
21 @value{UPDATED}), a program that creates GNU standards-compliant
22 Makefiles from template files.
24 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
25 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
27 @quotation
28 Permission is granted to copy, distribute and/or modify this document
29 under the terms of the @acronym{GNU} Free Documentation License,
30 Version 1.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 Building Programs and Libraries
204 * A Program::                   Building a program
205 * A Library::                   Building a library
206 * A Shared Library::            Building a Libtool library
207 * Program and Library Variables::  Variables controlling program and
208                                 library builds
209 * Default _SOURCES::            Default source files
210 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
211 * Program variables::           Variables used when building a program
212 * Yacc and Lex::                Yacc and Lex support
213 * C++ Support::                 Compiling C++ sources
214 * Objective C Support::         Compiling Objective C sources
215 * Unified Parallel C Support::  Compiling Unified Parallel C sources
216 * Assembly Support::            Compiling assembly sources
217 * Fortran 77 Support::          Compiling Fortran 77 sources
218 * Fortran 9x Support::          Compiling Fortran 9x sources
219 * Java Support::                Compiling Java sources
220 * Support for Other Languages::  Compiling other languages
221 * ANSI::                        Automatic de-ANSI-fication (obsolete)
222 * Dependencies::                Automatic dependency tracking
223 * EXEEXT::                      Support for executable extensions
225 Building a program
227 * Program Sources::             Defining program sources
228 * Linking::                     Linking with libraries or extra objects
229 * Conditional Sources::         Handling conditional sources
230 * Conditional Programs::        Building program conditionally
232 Building a Shared Library
234 * Libtool Concept::             Introducing Libtool
235 * Libtool Libraries::           Declaring Libtool Libraries
236 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
237 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
238 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
239 * Libtool Modules::             Building Libtool Modules
240 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
241 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
242 * Libtool Issues::              Common Issues Related to Libtool's Use
244 Fortran 77 Support
246 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
247 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
248 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
250 Mixing Fortran 77 With C and C++
252 * How the Linker is Chosen::    Automatic linker selection
254 Fortran 9x Support
256 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
258 Other Derived Objects
260 * Scripts::                     Executable scripts
261 * Headers::                     Header files
262 * Data::                        Architecture-independent data files
263 * Sources::                     Derived sources
265 Built sources
267 * Built sources example::       Several ways to handle built sources.
269 Other GNU Tools
271 * Emacs Lisp::                  Emacs Lisp
272 * gettext::                     Gettext
273 * Libtool::                     Libtool
274 * Java::                        Java
275 * Python::                      Python
277 Building documentation
279 * Texinfo::                     Texinfo
280 * Man pages::                   Man pages
282 Miscellaneous Rules
284 * Tags::                        Interfacing to etags and mkid
285 * Suffixes::                    Handling new file extensions
286 * Multilibs::                   Support for multilibs.
288 When Automake Isn't Enough
290 * Extending::                   Adding new rules or overriding existing ones.
291 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
293 Frequently Asked Questions about Automake
295 * CVS::                         CVS and generated files
296 * maintainer-mode::             missing and AM_MAINTAINER_MODE
297 * wildcards::                   Why doesn't Automake support wildcards?
298 * limitations on file names::   Limitations on source and installed file names
299 * distcleancheck::              Files left in build directory after distclean
300 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
301 * renamed objects::             Why are object files sometimes renamed?
302 * Per-Object Flags::            How to simulate per-object flags?
303 * Multiple Outputs::            Writing rules for tools with many output files
304 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
306 History of Automake
308 * Timeline::                    The Automake story.
309 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
310 * Releases::                    Statistics about Automake Releases
312 Copying This Manual
314 * GNU Free Documentation License::  License for copying this manual
316 Indices
318 * Macro Index::                 Index of Autoconf macros
319 * Variable Index::              Index of Makefile variables
320 * General Index::               General index
322 @end detailmenu
323 @end menu
325 @end ifnottex
328 @node Introduction
329 @chapter Introduction
331 Automake is a tool for automatically generating @file{Makefile.in}s
332 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
333 basically a series of @command{make} variable
334 definitions@footnote{These variables are also called @dfn{make macros}
335 in Make terminology, however in this manual we reserve the term
336 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
337 occasionally.  The generated @file{Makefile.in}s are compliant with
338 the GNU Makefile standards.
340 @cindex GNU Makefile standards
342 The GNU Makefile Standards Document
343 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
344 is long, complicated, and subject to change.  The goal of Automake is to
345 remove the burden of Makefile maintenance from the back of the
346 individual GNU maintainer (and put it on the back of the Automake
347 maintainers).
349 The typical Automake input file is simply a series of variable definitions.
350 Each such file is processed to create a @file{Makefile.in}.  There
351 should generally be one @file{Makefile.am} per directory of a project.
353 @cindex Constraints of Automake
354 @cindex Automake constraints
356 Automake does constrain a project in certain ways; for instance, it
357 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
358 autoconf, The Autoconf Manual}), and enforces certain restrictions on
359 the @file{configure.ac} contents@footnote{Older Autoconf versions used
360 @file{configure.in}.  Autoconf 2.50 and greater promotes
361 @file{configure.ac} over @file{configure.in}.  The rest of this
362 documentation will refer to @file{configure.ac}, but Automake also
363 supports @file{configure.in} for backward compatibility.}.
365 @cindex Automake requirements
366 @cindex Requirements, Automake
368 Automake requires @command{perl} in order to generate the
369 @file{Makefile.in}s.  However, the distributions created by Automake are
370 fully GNU standards-compliant, and do not require @command{perl} in order
371 to be built.
373 @cindex Bugs, reporting
374 @cindex Reporting bugs
375 @cindex E-mail, bug reports
377 Mail suggestions and bug reports for Automake to
378 @email{bug-automake@@gnu.org}.
380 @node Autotools Introduction
381 @chapter An Introduction to the Autotools
383 If you are new to Automake, maybe you know that it is part of a set of
384 tools called @emph{The Autotools}.  Maybe you've already delved into a
385 package full of files named @file{configure}, @file{configure.ac},
386 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
387 some of them claiming to be @emph{generated by} Autoconf or Automake.
388 But the exact purpose of these files and their relations is probably
389 fuzzy.  The goal of this chapter is to introduce you to this machinery,
390 to show you how it works and how powerful it is.  If you've never
391 installed or seen such a package, do not worry: this chapter will walk
392 you through it.
394 If you need some teaching material, more illustrations, or a less
395 @command{automake}-centered continuation, some slides for this
396 introduction are available in Alexandre Duret-Lutz's
397 @uref{http://www-src.lip6.fr/@/~Alexandre.Duret-Lutz/@/autotools.html,
398 Autotools Tutorial}.
399 This chapter is the written version of the first part of his tutorial.
401 @menu
402 * GNU Build System::            Introducing the GNU Build System
403 * Use Cases::                   Use Cases for the GNU Build System
404 * Why Autotools::               How Autotools Help
405 * Hello World::                 A Small Hello World Package
406 @end menu
408 @node GNU Build System
409 @section Introducing the GNU Build System
410 @cindex GNU Build System, introduction
412 It is a truth universally acknowledged, that a developer in
413 possession of a new package, must be in want of a build system.
415 In the Unix world, such a build system is traditionally achieved using
416 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
417 Manual}).  The developer expresses the recipe to build his package in
418 a @file{Makefile}.  This file is a set of rules to build the files in
419 the package.  For instance the program @file{prog} may be built by
420 running the linker on the files @file{main.o}, @file{foo.o}, and
421 @file{bar.o}; the file @file{main.o} may be built by running the
422 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
423 reads @file{Makefile}, checks the existence and modification time of
424 the files mentioned, decides what files need to be built (or rebuilt),
425 and runs the associated commands.
427 When a package needs to be built on a different platform than the one
428 it was developed on, its @file{Makefile} usually needs to be adjusted.
429 For instance the compiler may have another name or require more
430 options.  In 1991, David J. MacKenzie got tired of customizing
431 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
432 handcrafted a little shell script called @file{configure} to
433 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
434 autoconf, The Autoconf Manual}).  Compiling his package was now
435 as simple as running @code{./configure && make}.
437 @cindex GNU Coding Standards
439 Today this process has been standardized in the GNU project.  The GNU
440 Coding Standards (@pxref{Managing Releases, The Release Process, ,
441 standards, The GNU Coding Standards}) explains how each package of the
442 GNU project should have a @file{configure} script, and the minimal
443 interface it should have.  The @file{Makefile} too should follow some
444 established conventions.  The result?  A unified build system that
445 makes all packages almost indistinguishable by the installer.  In its
446 simplest scenario, all the installer has to do is to unpack the
447 package, run @code{./configure && make && make install}, and repeat
448 with the next package to install.
450 We call this build system the @dfn{GNU Build System}, since it was
451 grown out of the GNU project.  However it is used by a vast number of
452 other packages: following any existing convention has its advantages.
454 @cindex Autotools, introduction
456 The Autotools are tools that will create a GNU Build System for your
457 package.  Autoconf mostly focuses on @file{configure} and Automake on
458 @file{Makefile}s.  It is entirely possible to create a GNU Build
459 System without the help of these tools.  However it is rather
460 burdensome and error-prone.  We will discuss this again after some
461 illustration of the GNU Build System in action.
463 @node Use Cases
464 @section Use Cases for the GNU Build System
465 @cindex GNU Build System, use cases
466 @cindex GNU Build System, features
467 @cindex Features of the GNU Build System
468 @cindex Use Cases for the GNU Build System
469 @cindex @file{amhello-1.0.tar.gz}, location
470 @cindex @file{amhello-1.0.tar.gz}, use cases
472 In this section we explore several use cases for the GNU Build System.
473 You can replay all these examples on the @file{amhello-1.0.tar.gz}
474 package distributed with Automake.  If Automake is installed on your
475 system, you should find a copy of this file in
476 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
477 @var{prefix} is the installation prefix specified during configuration
478 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
479 installed by some GNU/Linux distribution it most likely has been set
480 to @file{/usr}).  If you do not have a copy of Automake installed,
481 you can find a copy of this file inside the @file{doc/} directory of
482 the Automake package.
484 Some of the following use cases present features that are in fact
485 extensions to the GNU Build System.  Read: they are not specified by
486 the GNU Coding Standards, but they are nonetheless part of the build
487 system created by the Autotools.  To keep things simple, we do not
488 point out the difference.  Our objective is to show you many of the
489 features that the build system created by the Autotools will offer to
490 you.
492 @menu
493 * Basic Installation::          Common installation procedure
494 * Standard Targets::            A list of standard Makefile targets
495 * Standard Directory Variables::  A list of standard directory variables
496 * Standard Configuration Variables::  Using configuration variables
497 * config.site::                 Using a config.site file
498 * VPATH Builds::                Parallel build trees
499 * Two-Part Install::            Installing data and programs separately
500 * Cross-Compilation::           Building for other architectures
501 * Renaming::                    Renaming programs at install time
502 * DESTDIR::                     Building binary packages with DESTDIR
503 * Preparing Distributions::     Rolling out tarballs
504 * Dependency Tracking::         Automatic dependency tracking
505 * Nested Packages::             The GNU Build Systems can be nested
506 @end menu
508 @node Basic Installation
509 @subsection Basic Installation
510 @cindex Configuration, basics
511 @cindex Installation, basics
512 @cindex GNU Build System, basics
514 The most common installation procedure looks as follows.
516 @example
517 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
518 ~ % @kbd{cd amhello-1.0}
519 ~/amhello-1.0 % @kbd{./configure}
520 @dots{}
521 config.status: creating Makefile
522 config.status: creating src/Makefile
523 @dots{}
524 ~/amhello-1.0 % @kbd{make}
525 @dots{}
526 ~/amhello-1.0 % @kbd{make check}
527 @dots{}
528 ~/amhello-1.0 % @kbd{su}
529 Password:
530 /home/adl/amhello-1.0 # @kbd{make install}
531 @dots{}
532 /home/adl/amhello-1.0 # @kbd{exit}
533 ~/amhello-1.0 % @kbd{make installcheck}
534 @dots{}
535 @end example
537 @cindex Unpacking
539 The user first unpacks the package.  Here, and in the following
540 examples, we will use the non-portable @code{tar zxf} command for
541 simplicity.  On a system without GNU @command{tar} installed, this
542 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
544 The user then enters the newly created directory to run the
545 @file{configure} script.  This script probes the system for various
546 features, and finally creates the @file{Makefile}s.  In this toy
547 example there are only two @file{Makefile}s, but in real-world projects,
548 there may be many more, usually one @file{Makefile} per directory.
550 It is now possible to run @code{make}.  This will construct all the
551 programs, libraries, and scripts that need to be constructed for the
552 package.  In our example, this compiles the @file{hello} program.
553 All files are constructed in place, in the source tree; we will see
554 later how this can be changed.
556 @code{make check} causes the package's tests to be run.  This step is
557 not mandatory, but it is often good to make sure the programs that
558 have been built behave as they should, before you decide to install
559 them.  Our example does not contain any tests, so running @code{make
560 check} is a no-op.
562 @cindex su, before @code{make install}
563 After everything has been built, and maybe tested, it is time to
564 install it on the system.  That means copying the programs,
565 libraries, header files, scripts, and other data files from the
566 source directory to their final destination on the system.  The
567 command @code{make install} will do that.  However, by default
568 everything will be installed in subdirectories of @file{/usr/local}:
569 binaries will go into @file{/usr/local/bin}, libraries will end up in
570 @file{/usr/local/lib}, etc.  This destination is usually not writable
571 by any user, so we assume that we have to become root before we can
572 run @code{make install}.  In our example, running @code{make install}
573 will copy the program @file{hello} into @file{/usr/local/bin}
574 and @file{README} into @file{/usr/local/share/doc/amhello}.
576 A last and optional step is to run @code{make installcheck}.  This
577 command may run tests on the installed files.  @code{make check} tests
578 the files in the source tree, while @code{make installcheck} tests
579 their installed copies.  The tests run by the latter can be different
580 from those run by the former.  For instance, there are tests that
581 cannot be run in the source tree.  Conversely, some packages are set
582 up so that @code{make installcheck} will run the very same tests as
583 @code{make check}, only on different files (non-installed
584 vs.@: installed).  It can make a difference, for instance when the
585 source tree's layout is different from that of the installation.
586 Furthermore it may help to diagnose an incomplete installation.
588 Presently most packages do not have any @code{installcheck} tests
589 because the existence of @code{installcheck} is little known, and its
590 usefulness is neglected.  Our little toy package is no better: @code{make
591 installcheck} does nothing.
593 @node Standard Targets
594 @subsection Standard @file{Makefile} Targets
596 So far we have come across four ways to run @command{make} in the GNU
597 Build System: @code{make}, @code{make check}, @code{make install}, and
598 @code{make installcheck}.  The words @code{check}, @code{install}, and
599 @code{installcheck}, passed as arguments to @command{make}, are called
600 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
601 @code{all} being the default target in the GNU Build System.
603 Here is a list of the most useful targets that the GNU Coding Standards
604 specify.
606 @table @code
607 @item make all
608 @trindex all
609 Build programs, libraries, documentation, etc.@: (same as @code{make}).
610 @item make install
611 @trindex install
612 Install what needs to be installed, copying the files from the
613 package's tree to system-wide directories.
614 @item make install-strip
615 @trindex install-strip
616 Same as @code{make install}, then strip debugging symbols.  Some
617 users like to trade space for useful bug reports@enddots{}
618 @item make uninstall
619 @trindex uninstall
620 The opposite of @code{make install}: erase the installed files.
621 (This needs to be run from the same build tree that was installed.)
622 @item make clean
623 @trindex clean
624 Erase from the build tree the files built by @code{make all}.
625 @item make distclean
626 @trindex distclean
627 Additionally erase anything @code{./configure} created.
628 @item make check
629 @trindex check
630 Run the test suite, if any.
631 @item make installcheck
632 @trindex installcheck
633 Check the installed programs or libraries, if supported.
634 @item make dist
635 @trindex dist
636 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
637 files.
638 @end table
640 @node Standard Directory Variables
641 @subsection Standard Directory Variables
642 @cindex directory variables
644 The GNU Coding Standards also specify a hierarchy of variables to
645 denote installation directories.  Some of these are:
647 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
648 @headitem Directory variable    @tab Default value
649 @item @code{prefix}              @tab @code{/usr/local}
650 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
651 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
652 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
653 @item @w{@ @ @ @ @dots{}}
654 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
655 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
656 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
657 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
658 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
659 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
660 @item @w{@ @ @dots{}}
661 @end multitable
663 @c We should provide a complete table somewhere, but not here.  The
664 @c complete list of directory variables it too confusing as-is.  It
665 @c requires some explanations that are too complicated for this
666 @c introduction.  Besides listing directories like localstatedir
667 @c would make the explanations in ``Two-Part Install'' harder.
669 Each of these directories has a role which is often obvious from its
670 name.  In a package, any installable file will be installed in one of
671 these directories.  For instance in @code{amhello-1.0}, the program
672 @file{hello} is to be installed in @var{bindir}, the directory for
673 binaries.  The default value for this directory is
674 @file{/usr/local/bin}, but the user can supply a different value when
675 calling @command{configure}.  Also the file @file{README} will be
676 installed into @var{docdir}, which defaults to
677 @file{/usr/local/share/doc/amhello}.
679 @opindex --prefix
681 A user who wishes to install a package on his own account could proceed
682 as follows:
684 @example
685 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
686 @dots{}
687 ~/amhello-1.0 % @kbd{make}
688 @dots{}
689 ~/amhello-1.0 % @kbd{make install}
690 @dots{}
691 @end example
693 This would install @file{~/usr/bin/hello} and
694 @file{~/usr/share/doc/amhello/README}.
696 The list of all such directory options is shown by
697 @code{./configure --help}.
699 @node Standard Configuration Variables
700 @subsection Standard Configuration Variables
701 @cindex configuration variables, overriding
703 The GNU Coding Standards also define a set of standard configuration
704 variables used during the build.  Here are some:
706 @table @asis
707 @item @code{CC}
708 C compiler command
709 @item @code{CFLAGS}
710 C compiler flags
711 @item @code{CXX}
712 C++ compiler command
713 @item @code{CXXFLAGS}
714 C++ compiler flags
715 @item @code{LDFLAGS}
716 linker flags
717 @item @code{CPPFLAGS}
718 C/C++ preprocessor flags
719 @item @dots{}
720 @end table
722 @command{configure} usually does a good job at setting appropriate
723 values for these variables, but there are cases where you may want to
724 override them.  For instance you may have several versions of a
725 compiler installed and would like to use another one, you may have
726 header files installed outside the default search path of the
727 compiler, or even libraries out of the way of the linker.
729 Here is how one would call @command{configure} to force it to use
730 @command{gcc-3} as C compiler, use header files from
731 @file{~/usr/include} when compiling, and libraries from
732 @file{~/usr/lib} when linking.
734 @example
735 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
736 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
737 @end example
739 Again, a full list of these variables appears in the output of
740 @code{./configure --help}.
742 @node config.site
743 @subsection Overriding Default Configuration Setting with @file{config.site}
744 @cindex @file{config.site} example
746 When installing several packages using the same setup, it can be
747 convenient to create a file to capture common settings.
748 If a file named @file{@var{prefix}/share/config.site} exists,
749 @command{configure} will source it at the beginning of its execution.
751 Recall the command from the previous section:
753 @example
754 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
755 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
756 @end example
758 Assuming we are installing many package in @file{~/usr}, and will
759 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
760 @code{LDFLAGS}, we can automate this by creating the following
761 @file{~/usr/share/config.site} file:
763 @example
764 test -z "$CC" && CC=gcc-3
765 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
766 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
767 @end example
769 Now, any time a @file{configure} script is using the @file{~/usr}
770 prefix, it will execute the above @file{config.site} and define
771 these three variables.
773 @example
774 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
775 configure: loading site script /home/adl/usr/share/config.site
776 @dots{}
777 @end example
779 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
780 Manual}, for more information about this feature.
783 @node VPATH Builds
784 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
785 @cindex Parallel build trees
786 @cindex VPATH builds
787 @cindex source tree and build tree
788 @cindex build tree and source tree
789 @cindex trees, source vs.@: build
791 The GNU Build System distinguishes two trees: the source tree, and
792 the build tree.
794 The source tree is rooted in the directory containing
795 @file{configure}.  It contains all the sources files (those that are
796 distributed), and may be arranged using several subdirectories.
798 The build tree is rooted in the directory in which @file{configure}
799 was run, and is populated with all object files, programs, libraries,
800 and other derived files built from the sources (and hence not
801 distributed).  The build tree usually has the same subdirectory layout
802 as the source tree; its subdirectories are created automatically by
803 the build system.
805 If @file{configure} is executed in its own directory, the source and
806 build trees are combined: derived files are constructed in the same
807 directories as their sources.  This was the case in our first
808 installation example (@pxref{Basic Installation}).
810 A common request from users is that they want to confine all derived
811 files to a single directory, to keep their source directories
812 uncluttered.  Here is how we could run @file{configure} to build
813 everything in a subdirectory called @file{build/}.
815 @example
816 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
817 ~ % @kbd{cd amhello-1.0}
818 ~/amhello-1.0 % @kbd{mkdir build && cd build}
819 ~/amhello-1.0/build % @kbd{../configure}
820 @dots{}
821 ~/amhello-1.0/build % @kbd{make}
822 @dots{}
823 @end example
825 These setups, where source and build trees are different, are often
826 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
827 @emph{parallel build} is misleading: the word @emph{parallel} is a
828 reference to the way the build tree shadows the source tree, it is not
829 about some concurrency in the way build commands are run.  For this
830 reason we refer to such setups using the name @emph{VPATH builds} in
831 the following.  @emph{VPATH} is the name of the @command{make} feature
832 used by the @file{Makefile}s to allow these builds (@pxref{General
833 Search, , @code{VPATH}: Search Path for All Prerequisites, make, The
834 GNU Make Manual}).
836 @cindex multiple configurations, example
837 @cindex debug build, example
838 @cindex optimized build, example
840 VPATH builds have other interesting uses.  One is to build the same
841 sources with multiple configurations.  For instance:
843 @example
844 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
845 ~ % @kbd{cd amhello-1.0}
846 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
847 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
848 @dots{}
849 ~/amhello-1.0/debug % @kbd{make}
850 @dots{}
851 ~/amhello-1.0/debug % cd ../optim
852 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
853 @dots{}
854 ~/amhello-1.0/optim % @kbd{make}
855 @dots{}
856 @end example
858 With network file systems, a similar approach can be used to build the
859 same sources on different machines.  For instance, suppose that the
860 sources are installed on a directory shared by two hosts: @code{HOST1}
861 and @code{HOST2}, which may be different platforms.
863 @example
864 ~ % @kbd{cd /nfs/src}
865 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
866 @end example
868 On the first host, you could create a local build directory:
869 @example
870 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
871 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
873 [HOST1] /tmp/amh % @kbd{make && sudo make install}
875 @end example
877 @noindent
878 (Here we assume that the installer has configured @command{sudo} so it
879 can execute @code{make install} with root privileges; it is more convenient
880 than using @command{su} like in @ref{Basic Installation}).
882 On the second host, you would do exactly the same, possibly at
883 the same time:
884 @example
885 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
886 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
888 [HOST2] /tmp/amh % @kbd{make && sudo make install}
890 @end example
892 @cindex read-only source tree
893 @cindex source tree, read-only
895 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
896 directory from being read-only.  In fact VPATH builds are also a means
897 of building packages from a read-only medium such as a CD-ROM.  (The
898 FSF used to sell CD-ROM with unpacked source code, before the GNU
899 project grew so big.)
901 @node Two-Part Install
902 @subsection Two-Part Installation
904 In our last example (@pxref{VPATH Builds}), a source tree was shared
905 by two hosts, but compilation and installation were done separately on
906 each host.
908 The GNU Build System also supports networked setups where part of the
909 installed files should be shared amongst multiple hosts.  It does so
910 by distinguishing architecture-dependent files from
911 architecture-independent files, and providing two @file{Makefile}
912 targets to install each of these classes of files.
914 @trindex install-exec
915 @trindex install-data
917 These targets are @code{install-exec} for architecture-dependent files
918 and @code{install-data} for architecture-independent files.
919 The command we used up to now, @code{make install}, can be thought of
920 as a shorthand for @code{make install-exec install-data}.
922 From the GNU Build System point of view, the distinction between
923 architecture-dependent files and architecture-independent files is
924 based exclusively on the directory variable used to specify their
925 installation destination.  In the list of directory variables we
926 provided earlier (@pxref{Standard Directory Variables}), all the
927 variables based on @var{exec-prefix} designate architecture-dependent
928 directories whose files will be installed by @code{make install-exec}.
929 The others designate architecture-independent directories and will
930 serve files installed by @code{make install-data}.  @xref{Install},
931 for more details.
933 Here is how we could revisit our two-host installation example,
934 assuming that (1) we want to install the package directly in
935 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
936 two hosts.
938 On the first host we would run
939 @example
940 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
941 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
943 [HOST1] /tmp/amh % @kbd{make && sudo make install}
945 @end example
947 On the second host, however, we need only install the
948 architecture-specific files.
949 @example
950 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
951 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
953 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
955 @end example
957 In packages that have installation checks, it would make sense to run
958 @code{make installcheck} (@pxref{Basic Installation}) to verify that
959 the package works correctly despite the apparent partial installation.
961 @node Cross-Compilation
962 @subsection Cross-Compilation
963 @cindex cross-compilation
965 To @dfn{cross-compile} is to build on one platform a binary that will
966 run on another platform.  When speaking of cross-compilation, it is
967 important to distinguish between the @dfn{build platform} on which
968 the compilation is performed, and the @dfn{host platform} on which the
969 resulting executable is expected to run.  The following
970 @command{configure} options are used to specify each of them:
972 @table @option
973 @item --build=@var{BUILD}
974 @opindex --build=@var{BUILD}
975 The system on which the package is built.
976 @item --host=@var{HOST}
977 @opindex --host=@var{HOST}
978 The system where built programs and libraries will run.
979 @end table
981 When the @option{--host} is used, @command{configure} will search for
982 the cross-compiling suite for this platform.  Cross-compilation tools
983 commonly have their target architecture as prefix of their name.  For
984 instance my cross-compiler for MinGW32 has its binaries called
985 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
986 @code{i586-mingw32msvc-as}, etc.
988 @cindex MinGW cross-compilation example
989 @cindex cross-compilation example
991 Here is how we could build @code{amhello-1.0} for
992 @code{i586-mingw32msvc} on a GNU/Linux PC.
994 @smallexample
995 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
996 checking for a BSD-compatible install... /usr/bin/install -c
997 checking whether build environment is sane... yes
998 checking for gawk... gawk
999 checking whether make sets $(MAKE)... yes
1000 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1001 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1002 checking for C compiler default output file name... a.exe
1003 checking whether the C compiler works... yes
1004 checking whether we are cross compiling... yes
1005 checking for suffix of executables... .exe
1006 checking for suffix of object files... o
1007 checking whether we are using the GNU C compiler... yes
1008 checking whether i586-mingw32msvc-gcc accepts -g... yes
1009 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1010 @dots{}
1011 ~/amhello-1.0 % @kbd{make}
1012 @dots{}
1013 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1014 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1015 @end smallexample
1017 The @option{--host} and @option{--build} options are usually all we
1018 need for cross-compiling.  The only exception is if the package being
1019 built is itself a cross-compiler: we need a third option to specify
1020 its target architecture.
1022 @table @option
1023 @item --target=@var{TARGET}
1024 @opindex --target=@var{TARGET}
1025 When building compiler tools: the system for which the tools will
1026 create output.
1027 @end table
1029 For instance when installing GCC, the GNU Compiler Collection, we can
1030 use @option{--target=@var{TARGET}} to specify that we want to build
1031 GCC as a cross-compiler for @var{TARGET}.  Mixing @option{--build} and
1032 @option{--target}, we can actually cross-compile a cross-compiler;
1033 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1035 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1036 Autoconf Manual}, for more information about these @command{configure}
1037 options.
1039 @node Renaming
1040 @subsection Renaming Programs at Install Time
1041 @cindex Renaming programs
1042 @cindex Transforming program names
1043 @cindex Programs, renaming during installation
1045 The GNU Build System provides means to automatically rename
1046 executables and manpages before they are installed (@pxref{Man pages}).
1047 This is especially convenient
1048 when installing a GNU package on a system that already has a
1049 proprietary implementation you do not want to overwrite.  For instance,
1050 you may want to install GNU @command{tar} as @command{gtar} so you can
1051 distinguish it from your vendor's @command{tar}.
1053 This can be done using one of these three @command{configure} options.
1055 @table @option
1056 @item --program-prefix=@var{PREFIX}
1057 @opindex --program-prefix=@var{PREFIX}
1058 Prepend @var{PREFIX} to installed program names.
1059 @item --program-suffix=@var{SUFFIX}
1060 @opindex --program-suffix=@var{SUFFIX}
1061 Append @var{SUFFIX} to installed program names.
1062 @item --program-transform-name=@var{PROGRAM}
1063 @opindex --program-transform-name=@var{PROGRAM}
1064 Run @code{sed @var{PROGRAM}} on installed program names.
1065 @end table
1067 The following commands would install @file{hello}
1068 as @file{/usr/local/bin/test-hello}, for instance.
1070 @example
1071 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1072 @dots{}
1073 ~/amhello-1.0 % @kbd{make}
1074 @dots{}
1075 ~/amhello-1.0 % @kbd{sudo make install}
1076 @dots{}
1077 @end example
1079 @node DESTDIR
1080 @subsection Building Binary Packages Using DESTDIR
1081 @vindex DESTDIR
1083 The GNU Build System's @code{make install} and @code{make uninstall}
1084 interface does not exactly fit the needs of a system administrator
1085 who has to deploy and upgrade packages on lots of hosts.  In other
1086 words, the GNU Build System does not replace a package manager.
1088 Such package managers usually need to know which files have been
1089 installed by a package, so a mere @code{make install} is
1090 inappropriate.
1092 @cindex Staged installation
1094 The @code{DESTDIR} variable can be used to perform a staged
1095 installation.  The package should be configured as if it was going to
1096 be installed in its final location (e.g., @code{--prefix /usr}), but
1097 when running @code{make install}, the @code{DESTDIR} should be set to
1098 the absolute name of a directory into which the installation will be
1099 diverted.  From this directory it is easy to review which files are
1100 being installed where, and finally copy them to their final location
1101 by some means.
1103 @cindex Binary package
1105 For instance here is how we could create a binary package containing a
1106 snapshot of all the files to be installed.
1108 @example
1109 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1110 @dots{}
1111 ~/amhello-1.0 % @kbd{make}
1112 @dots{}
1113 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1114 @dots{}
1115 ~/amhello-1.0 % @kbd{cd ~/inst}
1116 ~/inst % @kbd{find . -type f -print > ../files.lst}
1117 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1118 ./usr/bin/hello
1119 ./usr/share/doc/amhello/README
1120 @end example
1122 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1123 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1124 instead of @samp{.} as argument for @command{tar} avoids entries for
1125 each subdirectory in the archive: we would not like @command{tar} to
1126 restore the modification time of @file{/}, @file{/usr/}, etc.)
1128 Note that when building packages for several architectures, it might
1129 be convenient to use @code{make install-data} and @code{make
1130 install-exec} (@pxref{Two-Part Install}) to gather
1131 architecture-independent files in a single package.
1133 @xref{Install}, for more information.
1135 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1136 @c UNINSTALL counterparts.
1138 @node Preparing Distributions
1139 @subsection Preparing Distributions
1140 @cindex Preparing distributions
1141 @cindex Packages, preparation
1142 @cindex Distributions, preparation
1144 We have already mentioned @code{make dist}.  This target collects all
1145 your source files and the necessary parts of the build system to
1146 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1148 @cindex @code{distcheck} better than @code{dist}
1150 Another, more useful command is @code{make distcheck}.  The
1151 @code{distcheck} target constructs
1152 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1153 but it additionally ensures most of the use cases presented so far
1154 work:
1156 @itemize @bullet
1157 @item
1158 It attempts a full compilation of the package (@pxref{Basic
1159 Installation}), unpacking the newly constructed tarball, running
1160 @code{make}, @code{make check}, @code{make install}, as well as
1161 @code{make installcheck}, and even @code{make dist},
1162 @item
1163 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1164 @item
1165 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1166 uninstall} do not omit any file (@pxref{Standard Targets}),
1167 @item
1168 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1169 @end itemize
1171 All of these actions are performed in a temporary subdirectory, so
1172 that no root privileges are required.
1174 Releasing a package that fails @code{make distcheck} means that one of
1175 the scenarios we presented will not work and some users will be
1176 disappointed.  Therefore it is a good practice to release a package
1177 only after a successful @code{make distcheck}.  This of course does
1178 not imply that the package will be flawless, but at least it will
1179 prevent some of the embarrassing errors you may find in packages
1180 released by people who have never heard about @code{distcheck} (like
1181 @code{DESTDIR} not working because of a typo, or a distributed file
1182 being erased by @code{make clean}, or even @code{VPATH} builds not
1183 working).
1185 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1186 @code{make distcheck}.  @xref{Dist}, for more information about
1187 @code{distcheck}.
1189 @node Dependency Tracking
1190 @subsection Automatic Dependency Tracking
1191 @cindex Dependency tracking
1193 Dependency tracking is performed as a side-effect of compilation.
1194 Each time the build system compiles a source file, it computes its
1195 list of dependencies (in C these are the header files included by the
1196 source being compiled).  Later, any time @command{make} is run and a
1197 dependency appears to have changed, the dependent files will be
1198 rebuilt.
1200 When @command{configure} is executed, you can see it probing each
1201 compiler for the dependency mechanism it supports (several mechanisms
1202 can be used):
1204 @example
1205 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1206 @dots{}
1207 checking dependency style of gcc... gcc3
1208 @dots{}
1209 @end example
1211 Because dependencies are only computed as a side-effect of the
1212 compilation, no dependency information exists the first time a package
1213 is built.  This is OK because all the files need to be built anyway:
1214 @code{make} does not have to decide which files need to be rebuilt.
1215 In fact, dependency tracking is completely useless for one-time builds
1216 and there is a @command{configure} option to disable this:
1218 @table @option
1219 @item --disable-dependency-tracking
1220 @opindex --disable-dependency-tracking
1221 Speed up one-time builds.
1222 @end table
1224 Some compilers do not offer any practical way to derive the list of
1225 dependencies as a side-effect of the compilation, requiring a separate
1226 run (maybe of another tool) to compute these dependencies.  The
1227 performance penalty implied by these methods is important enough to
1228 disable them by default.  The option @option{--enable-dependency-tracking}
1229 must be passed to @command{configure} to activate them.
1231 @table @option
1232 @item --enable-dependency-tracking
1233 @opindex --enable-dependency-tracking
1234 Do not reject slow dependency extractors.
1235 @end table
1237 @xref{Dependency Tracking Evolution}, for some discussion about the
1238 different dependency tracking schemes used by Automake over the years.
1240 @node Nested Packages
1241 @subsection Nested Packages
1242 @cindex Nested packages
1243 @cindex Packages, nested
1244 @cindex Subpackages
1246 Although nesting packages isn't something we would recommend to
1247 someone who is discovering the Autotools, it is a nice feature worthy
1248 of mention in this small advertising tour.
1250 Autoconfiscated packages (that means packages whose build system have
1251 been created by Autoconf and friends) can be nested to arbitrary
1252 depth.
1254 A typical setup is that package A will distribute one of the libraries
1255 it needs in a subdirectory.  This library B is a complete package with
1256 its own GNU Build System.  The @command{configure} script of A will
1257 run the @command{configure} script of B as part of its execution,
1258 building and installing A will also build and install B.  Generating a
1259 distribution for A will also include B.
1261 It is possible to gather several package like this.  GCC is a heavy
1262 user of this feature.  This gives installers a single package to
1263 configure, build and install, while it allows developers to work on
1264 subpackages independently.
1266 When configuring nested packages, the @command{configure} options
1267 given to the top-level @command{configure} are passed recursively to
1268 nested @command{configure}s.  A package that does not understand an
1269 option will ignore it, assuming it is meaningful to some other
1270 package.
1272 @opindex --help=recursive
1274 The command @code{configure --help=recursive} can be used to display
1275 the options supported by all the included packages.
1277 @xref{Subpackages}, for an example setup.
1279 @node Why Autotools
1280 @section How Autotools Help
1281 @cindex Autotools, purpose
1283 There are several reasons why you may not want to implement the GNU
1284 Build System yourself (read: write a @file{configure} script and
1285 @file{Makefile}s yourself).
1287 @itemize @bullet
1288 @item
1289 As we have seen, the GNU Build System has a lot of
1290 features (@pxref{Use Cases}).
1291 Some users may expect features you have not implemented because
1292 you did not need them.
1293 @item
1294 Implementing these features portably is difficult and exhausting.
1295 Think of writing portable shell scripts, and portable
1296 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1297 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1298 convince yourself.
1299 @item
1300 You will have to upgrade your setup to follow changes to the GNU
1301 Coding Standards.
1302 @end itemize
1304 The GNU Autotools take all this burden off your back and provide:
1306 @itemize @bullet
1307 @item
1308 Tools to create a portable, complete, and self-contained GNU Build
1309 System, from simple instructions.
1310 @emph{Self-contained} meaning the resulting build system does not
1311 require the GNU Autotools.
1312 @item
1313 A central place where fixes and improvements are made:
1314 a bug-fix for a portability issue will benefit every package.
1315 @end itemize
1317 Yet there also exist reasons why you may want NOT to use the
1318 Autotools@enddots{} For instance you may be already using (or used to)
1319 another incompatible build system.  Autotools will only be useful if
1320 you do accept the concepts of the GNU Build System.  People who have their
1321 own idea of how a build system should work will feel frustrated by the
1322 Autotools.
1324 @node Hello World
1325 @section A Small Hello World
1326 @cindex Example Hello World
1327 @cindex Hello World example
1328 @cindex @file{amhello-1.0.tar.gz}, creation
1330 In this section we recreate the @file{amhello-1.0} package from
1331 scratch.  The first subsection shows how to call the Autotools to
1332 instantiate the GNU Build System, while the second explains the
1333 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1334 by the Autotools.
1336 @menu
1337 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1338 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
1339 @end menu
1341 @node Creating amhello
1342 @subsection Creating @file{amhello-1.0.tar.gz}
1344 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1345 The package is simple enough so that we will only need to write 5
1346 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1347 that is distributed with Automake if you do not want to write them.)
1349 Create the following files in an empty directory.
1351 @itemize @bullet
1353 @item
1354 @file{src/main.c} is the source file for the @file{hello} program.  We
1355 store it in the @file{src/} subdirectory, because later, when the package
1356 evolves, it will ease the addition of a @file{man/} directory for man
1357 pages, a @file{data/} directory for data files, etc.
1358 @example
1359 ~/amhello % @kbd{cat src/main.c}
1360 #include <config.h>
1361 #include <stdio.h>
1364 main (void)
1366   puts ("Hello World!");
1367   puts ("This is " PACKAGE_STRING ".");
1368   return 0;
1370 @end example
1372 @item
1373 @file{README} contains some very limited documentation for our little
1374 package.
1375 @example
1376 ~/amhello % @kbd{cat README}
1377 This is a demonstration package for GNU Automake.
1378 Type `info Automake' to read the Automake manual.
1379 @end example
1381 @item
1382 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1383 instructions for these two directories.
1385 @example
1386 ~/amhello % @kbd{cat src/Makefile.am}
1387 bin_PROGRAMS = hello
1388 hello_SOURCES = main.c
1389 ~/amhello % @kbd{cat Makefile.am}
1390 SUBDIRS = src
1391 dist_doc_DATA = README
1392 @end example
1394 @item
1395 Finally, @file{configure.ac} contains Autoconf instructions to
1396 create the @command{configure} script.
1398 @example
1399 ~/amhello % @kbd{cat configure.ac}
1400 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1401 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1402 AC_PROG_CC
1403 AC_CONFIG_HEADERS([config.h])
1404 AC_CONFIG_FILES([
1405  Makefile
1406  src/Makefile
1408 AC_OUTPUT
1409 @end example
1410 @end itemize
1412 @cindex @command{autoreconf}, example
1414 Once you have these five files, it is time to run the Autotools to
1415 instantiate the build system.  Do this using the @command{autoreconf}
1416 command as follows:
1418 @example
1419 ~/amhello % @kbd{autoreconf --install}
1420 configure.ac: installing `./install-sh'
1421 configure.ac: installing `./missing'
1422 src/Makefile.am: installing `./depcomp'
1423 @end example
1425 At this point the build system is complete.
1427 In addition to the three scripts mentioned in its output, you can see
1428 that @command{autoreconf} created four other files: @file{configure},
1429 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1430 The latter three files are templates that will be adapted to the
1431 system by @command{configure} under the names @file{config.h},
1432 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1434 @example
1435 ~/amhello % @kbd{./configure}
1436 checking for a BSD-compatible install... /usr/bin/install -c
1437 checking whether build environment is sane... yes
1438 checking for gawk... no
1439 checking for mawk... mawk
1440 checking whether make sets $(MAKE)... yes
1441 checking for gcc... gcc
1442 checking for C compiler default output file name... a.out
1443 checking whether the C compiler works... yes
1444 checking whether we are cross compiling... no
1445 checking for suffix of executables...
1446 checking for suffix of object files... o
1447 checking whether we are using the GNU C compiler... yes
1448 checking whether gcc accepts -g... yes
1449 checking for gcc option to accept ISO C89... none needed
1450 checking for style of include used by make... GNU
1451 checking dependency style of gcc... gcc3
1452 configure: creating ./config.status
1453 config.status: creating Makefile
1454 config.status: creating src/Makefile
1455 config.status: creating config.h
1456 config.status: executing depfiles commands
1457 @end example
1459 @trindex distcheck
1460 @cindex @code{distcheck} example
1462 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1463 being created at the end after @command{configure} has probed the
1464 system.  It is now possible to run all the targets we wish
1465 (@pxref{Standard Targets}).  For instance:
1467 @example
1468 ~/amhello % @kbd{make}
1469 @dots{}
1470 ~/amhello % @kbd{src/hello}
1471 Hello World!
1472 This is amhello 1.0.
1473 ~/amhello % @kbd{make distcheck}
1474 @dots{}
1475 =============================================
1476 amhello-1.0 archives ready for distribution:
1477 amhello-1.0.tar.gz
1478 =============================================
1479 @end example
1481 Note that running @command{autoreconf} is only needed initially when
1482 the GNU Build System does not exist.  When you later change some
1483 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1484 relevant part of the build system will be regenerated automatically
1485 when you execute @command{make}.
1487 @command{autoreconf} is a script that calls @command{autoconf},
1488 @command{automake}, and a bunch of other commands in the right order.
1489 If you are beginning with these tools, it is not important to figure
1490 out in which order all these tools should be invoked and why.  However,
1491 because Autoconf and Automake have separate manuals, the important
1492 point to understand is that @command{autoconf} is in charge of
1493 creating @file{configure} from @file{configure.ac}, while
1494 @command{automake} is in charge of creating @file{Makefile.in}s from
1495 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1496 direct you to the right manual when seeking answers.
1499 @node amhello Explained
1500 @subsection @file{amhello-1.0} Explained
1502 Let us begin with the contents of @file{configure.ac}.
1504 @example
1505 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1506 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1507 AC_PROG_CC
1508 AC_CONFIG_HEADERS([config.h])
1509 AC_CONFIG_FILES([
1510  Makefile
1511  src/Makefile
1513 AC_OUTPUT
1514 @end example
1516 This file is read by both @command{autoconf} (to create
1517 @file{configure}) and @command{automake} (to create the various
1518 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1519 expanded as shell code to finally form the @file{configure} script.
1520 We will not elaborate on the syntax of this file, because the Autoconf
1521 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1522 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1524 The macros prefixed with @code{AC_} are Autoconf macros, documented
1525 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1526 Index, autoconf, The Autoconf Manual}).  The macros that start with
1527 @code{AM_} are Automake macros, documented later in this manual
1528 (@pxref{Macro Index}).
1530 The first two lines of @file{configure.ac} initialize Autoconf and
1531 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1532 its version number, and a contact address for bug-reports about the
1533 package (this address is output at the end of @code{./configure
1534 --help}, for instance).  When adapting this setup to your own package,
1535 by all means please do not blindly copy Automake's address: use the
1536 mailing list of your package, or your own mail address.
1538 @opindex -Wall
1539 @opindex -Werror
1540 @opindex foreign
1542 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1543 @command{automake} (@pxref{Options}).  @option{-Wall} and
1544 @option{-Werror} ask @command{automake} to turn on all warnings and
1545 report them as errors.  We are speaking of @strong{Automake} warnings
1546 here, such as dubious instructions in @file{Makefile.am}.  This has
1547 absolutely nothing to do with how the compiler will be called, even
1548 though it may support options with similar names.  Using @option{-Wall
1549 -Werror} is a safe setting when starting to work on a package: you do
1550 not want to miss any issues.  Later you may decide to relax things a
1551 bit.  The @option{foreign} option tells Automake that this package
1552 will not follow the GNU Standards.  GNU packages should always
1553 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1554 etc.  We do not want @command{automake} to complain about these
1555 missing files in our small example.
1557 The @code{AC_PROG_CC} line causes the @command{configure} script to
1558 search for a C compiler and define the variable @code{CC} with its
1559 name.  The @file{src/Makefile.in} file generated by Automake uses the
1560 variable @code{CC} to build @file{hello}, so when @command{configure}
1561 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1562 @code{CC} with the value it has found.  If Automake is asked to create
1563 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1564 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1566 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1567 @command{configure} script to create a @file{config.h} file gathering
1568 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1569 case, the @code{AC_INIT} macro already defined a few of them.  Here
1570 is an excerpt of @file{config.h} after @command{configure} has run:
1572 @smallexample
1573 @dots{}
1574 /* Define to the address where bug reports for this package should be sent. */
1575 #define PACKAGE_BUGREPORT "bug-automake@@gnu.org"
1577 /* Define to the full name and version of this package. */
1578 #define PACKAGE_STRING "amhello 1.0"
1579 @dots{}
1580 @end smallexample
1582 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1583 it can use @code{PACKAGE_STRING}.  In a real-world project,
1584 @file{config.h} can grow really big, with one @samp{#define} per
1585 feature probed on the system.
1587 The @code{AC_CONFIG_FILES} macro declares the list of files that
1588 @command{configure} should create from their @file{*.in} templates.
1589 Automake also scans this list to find the @file{Makefile.am} files it must
1590 process.  (This is important to remember: when adding a new directory
1591 to your project, you should add its @file{Makefile} to this list,
1592 otherwise Automake will never process the new @file{Makefile.am} you
1593 wrote in that directory.)
1595 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1596 produces the part of the script in charge of creating the files
1597 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1599 @cindex @command{autoscan}
1601 When starting a new project, we suggest you start with such a simple
1602 @file{configure.ac}, and gradually add the other tests it requires.
1603 The command @command{autoscan} can also suggest a few of the tests
1604 your package may need (@pxref{autoscan Invocation, , Using
1605 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1606 Autoconf Manual}).
1608 @cindex @file{Makefile.am}, Hello World
1610 We now turn to @file{src/Makefile.am}.  This file contains
1611 Automake instructions to build and install @file{hello}.
1613 @example
1614 bin_PROGRAMS = hello
1615 hello_SOURCES = main.c
1616 @end example
1618 A @file{Makefile.am} has the same syntax as an ordinary
1619 @file{Makefile}.  When @command{automake} processes a
1620 @file{Makefile.am} it copies the entire file into the output
1621 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1622 @command{configure}) but will react to certain variable definitions
1623 by generating some build rules and other variables.
1624 Often @file{Makefile.am}s contain only a list of variable definitions as
1625 above, but they can also contain other variable and rule definitions that
1626 @command{automake} will pass along without interpretation.
1628 Variables that end with @code{_PROGRAMS} are special variables
1629 that list programs that the resulting @file{Makefile} should build.
1630 In Automake speak, this @code{_PROGRAMS} suffix is called a
1631 @dfn{primary}; Automake recognizes other primaries such as
1632 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1633 to different types of files.
1635 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1636 @command{automake} that the resulting programs should be installed in
1637 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1638 to denote destination directories and allow users to customize these
1639 locations (@pxref{Standard Directory Variables}).  Any such directory
1640 variable can be put in front of a primary (omitting the @code{dir}
1641 suffix) to tell @command{automake} where to install the listed files.
1643 Programs need to be built from source files, so for each program
1644 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1645 @command{automake} will look for another variable named
1646 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1647 than one source file: they will all be compiled and linked together.
1649 Automake also knows that source files need to be distributed when
1650 creating a tarball (unlike built programs).  So a side-effect of this
1651 @code{hello_SOURCES} declaration is that @file{main.c} will be
1652 part of the tarball created by @code{make dist}.
1654 Finally here are some explanations regarding the top-level
1655 @file{Makefile.am}.
1657 @example
1658 SUBDIRS = src
1659 dist_doc_DATA = README
1660 @end example
1662 @code{SUBDIRS} is a special variable listing all directories that
1663 @command{make} should recurse into before processing the current
1664 directory.  So this line is responsible for @command{make} building
1665 @file{src/hello} even though we run it from the top-level.  This line
1666 also causes @code{make install} to install @file{src/hello} before
1667 installing @file{README} (not that this order matters).
1669 The line @code{dist_doc_DATA = README} causes @file{README} to be
1670 distributed and installed in @var{docdir}.  Files listed with the
1671 @code{_DATA} primary are not automatically part of the tarball built
1672 with @code{make dist}, so we add the @code{dist_} prefix so they get
1673 distributed.  However, for @file{README} it would not have been
1674 necessary: @command{automake} automatically distributes any
1675 @file{README} file it encounters (the list of other files
1676 automatically distributed is presented by @code{automake --help}).
1677 The only important effect of this second line is therefore to install
1678 @file{README} during @code{make install}.
1681 @node Generalities
1682 @chapter General ideas
1684 The following sections cover a few basic ideas that will help you
1685 understand how Automake works.
1687 @menu
1688 * General Operation::           General operation of Automake
1689 * Strictness::                  Standards conformance checking
1690 * Uniform::                     The Uniform Naming Scheme
1691 * Canonicalization::            How derived variables are named
1692 * Length limitations::          Staying below the command line length limit
1693 * User Variables::              Variables reserved for the user
1694 * Auxiliary Programs::          Programs automake might require
1695 @end menu
1698 @node General Operation
1699 @section General Operation
1701 Automake works by reading a @file{Makefile.am} and generating a
1702 @file{Makefile.in}.  Certain variables and rules defined in the
1703 @file{Makefile.am} instruct Automake to generate more specialized code;
1704 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1705 for compiling and linking programs to be generated.
1707 @cindex Non-standard targets
1708 @cindex @code{cvs-dist}, non-standard example
1709 @trindex cvs-dist
1710 @trindex git-dist
1712 The variable definitions and rules in the @file{Makefile.am} are
1713 copied verbatim into the generated file.  This allows you to add
1714 arbitrary code into the generated @file{Makefile.in}.  For instance,
1715 the Automake distribution includes a non-standard rule for the
1716 @code{git-dist} target, which the Automake maintainer uses to make
1717 distributions from his source control system.
1719 @cindex GNU make extensions
1721 Note that most GNU make extensions are not recognized by Automake.  Using
1722 such extensions in a @file{Makefile.am} will lead to errors or confusing
1723 behavior.
1725 @cindex Append operator
1726 @cmindex +=
1727 A special exception is that the GNU make append operator, @samp{+=}, is
1728 supported.  This operator appends its right hand argument to the variable
1729 specified on the left.  Automake will translate the operator into
1730 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1732 Automake tries to keep comments grouped with any adjoining rules or
1733 variable definitions.
1735 @cindex Make targets, overriding
1736 @cindex Make rules, overriding
1737 @cindex Overriding make rules
1738 @cindex Overriding make targets
1740 A rule defined in @file{Makefile.am} generally overrides any such
1741 rule of a similar name that would be automatically generated by
1742 @command{automake}.  Although this is a supported feature, it is generally
1743 best to avoid making use of it, as sometimes the generated rules are
1744 very particular.
1746 @cindex Variables, overriding
1747 @cindex Overriding make variables
1749 Similarly, a variable defined in @file{Makefile.am} or
1750 @code{AC_SUBST}ed from @file{configure.ac} will override any
1751 definition of the variable that @command{automake} would ordinarily
1752 create.  This feature is more often useful than the ability to
1753 override a rule.  Be warned that many of the variables generated by
1754 @command{automake} are considered to be for internal use only, and their
1755 names might change in future releases.
1757 @cindex Recursive operation of Automake
1758 @cindex Automake, recursive operation
1759 @cindex Example of recursive operation
1761 When examining a variable definition, Automake will recursively examine
1762 variables referenced in the definition.  For example, if Automake is
1763 looking at the content of @code{foo_SOURCES} in this snippet
1765 @example
1766 xs = a.c b.c
1767 foo_SOURCES = c.c $(xs)
1768 @end example
1770 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1771 contents of @code{foo_SOURCES}.
1773 @cindex @code{##} (special Automake comment)
1774 @cindex Special Automake comment
1775 @cindex Comment, special to Automake
1777 Automake also allows a form of comment that is @emph{not} copied into
1778 the output; all lines beginning with @samp{##} (leading spaces allowed)
1779 are completely ignored by Automake.
1781 It is customary to make the first line of @file{Makefile.am} read:
1783 @cindex Makefile.am, first line
1784 @cindex First line of Makefile.am
1786 @example
1787 ## Process this file with automake to produce Makefile.in
1788 @end example
1790 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1791 @c I don't know quite what to say.
1793 @c FIXME document customary ordering of Makefile.am here!
1796 @node Strictness
1797 @section Strictness
1799 @cindex Non-GNU packages
1801 While Automake is intended to be used by maintainers of GNU packages, it
1802 does make some effort to accommodate those who wish to use it, but do
1803 not want to use all the GNU conventions.
1805 @cindex Strictness, defined
1806 @cindex Strictness, @option{foreign}
1807 @cindex @option{foreign} strictness
1808 @cindex Strictness, @option{gnu}
1809 @cindex @option{gnu} strictness
1810 @cindex Strictness, @option{gnits}
1811 @cindex @option{gnits} strictness
1813 To this end, Automake supports three levels of @dfn{strictness}---the
1814 strictness indicating how stringently Automake should check standards
1815 conformance.
1817 The valid strictness levels are:
1819 @table @option
1820 @item foreign
1821 Automake will check for only those things that are absolutely
1822 required for proper operations.  For instance, whereas GNU standards
1823 dictate the existence of a @file{NEWS} file, it will not be required in
1824 this mode.  The name comes from the fact that Automake is intended to be
1825 used for GNU programs; these relaxed rules are not the standard mode of
1826 operation.
1828 @item gnu
1829 Automake will check---as much as possible---for compliance to the GNU
1830 standards for packages.  This is the default.
1832 @item gnits
1833 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1834 standards}.  These are based on the GNU standards, but are even more
1835 detailed.  Unless you are a Gnits standards contributor, it is
1836 recommended that you avoid this option until such time as the Gnits
1837 standard is actually published (which may never happen).
1838 @end table
1840 @xref{Gnits}, for more information on the precise implications of the
1841 strictness level.
1843 Automake also has a special ``cygnus'' mode that is similar to
1844 strictness but handled differently.  This mode is useful for packages
1845 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
1846 @xref{Cygnus}, for more information on this mode.
1849 @node Uniform
1850 @section The Uniform Naming Scheme
1852 @cindex Uniform naming scheme
1854 Automake variables generally follow a @dfn{uniform naming scheme} that
1855 makes it easy to decide how programs (and other derived objects) are
1856 built, and how they are installed.  This scheme also supports
1857 @command{configure} time determination of what should be built.
1859 @cindex @code{_PROGRAMS} primary variable
1860 @cindex @code{PROGRAMS} primary variable
1861 @cindex Primary variable, @code{PROGRAMS}
1862 @cindex Primary variable, defined
1863 @vindex _PROGRAMS
1865 At @command{make} time, certain variables are used to determine which
1866 objects are to be built.  The variable names are made of several pieces
1867 that are concatenated together.
1869 The piece that tells automake what is being built is commonly called
1870 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1871 list of programs that are to be compiled and linked.
1872 @vindex PROGRAMS
1874 @cindex @code{pkgdatadir}, defined
1875 @cindex @code{pkgincludedir}, defined
1876 @cindex @code{pkglibdir}, defined
1877 @cindex @code{pkglibexecdir}, defined
1879 @vindex pkgdatadir
1880 @vindex pkgincludedir
1881 @vindex pkglibdir
1882 @vindex pkglibexecdir
1884 @cindex @code{PACKAGE}, directory
1885 A different set of names is used to decide where the built objects
1886 should be installed.  These names are prefixes to the primary, and they
1887 indicate which standard directory should be used as the installation
1888 directory.  The standard directory names are given in the GNU standards
1889 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1890 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
1891 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
1892 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
1893 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
1895 @cindex @code{EXTRA_}, prepending
1896 For each primary, there is one additional variable named by prepending
1897 @samp{EXTRA_} to the primary name.  This variable is used to list
1898 objects that may or may not be built, depending on what
1899 @command{configure} decides.  This variable is required because Automake
1900 must statically know the entire list of objects that may be built in
1901 order to generate a @file{Makefile.in} that will work in all cases.
1903 @cindex @code{EXTRA_PROGRAMS}, defined
1904 @cindex Example, @code{EXTRA_PROGRAMS}
1905 @cindex @command{cpio} example
1907 For instance, @command{cpio} decides at configure time which programs
1908 should be built.  Some of the programs are installed in @code{bindir},
1909 and some are installed in @code{sbindir}:
1911 @example
1912 EXTRA_PROGRAMS = mt rmt
1913 bin_PROGRAMS = cpio pax
1914 sbin_PROGRAMS = $(MORE_PROGRAMS)
1915 @end example
1917 Defining a primary without a prefix as a variable, e.g.,
1918 @samp{PROGRAMS}, is an error.
1920 Note that the common @samp{dir} suffix is left off when constructing the
1921 variable names; thus one writes @samp{bin_PROGRAMS} and not
1922 @samp{bindir_PROGRAMS}.
1924 Not every sort of object can be installed in every directory.  Automake
1925 will flag those attempts it finds in error.
1926 Automake will also diagnose obvious misspellings in directory names.
1928 @cindex Extending list of installation directories
1929 @cindex Installation directories, extending list
1931 Sometimes the standard directories---even as augmented by
1932 Automake---are not enough.  In particular it is sometimes useful, for
1933 clarity, to install objects in a subdirectory of some predefined
1934 directory.  To this end, Automake allows you to extend the list of
1935 possible installation directories.  A given prefix (e.g., @samp{zar})
1936 is valid if a variable of the same name with @samp{dir} appended is
1937 defined (e.g., @samp{zardir}).
1939 For instance, the following snippet will install @file{file.xml} into
1940 @samp{$(datadir)/xml}.
1942 @example
1943 xmldir = $(datadir)/xml
1944 xml_DATA = file.xml
1945 @end example
1947 @cindex @samp{noinst_} primary prefix, definition
1948 @vindex noinst_
1950 The special prefix @samp{noinst_} indicates that the objects in question
1951 should be built but not installed at all.  This is usually used for
1952 objects required to build the rest of your package, for instance static
1953 libraries (@pxref{A Library}), or helper scripts.
1955 @cindex @samp{check_} primary prefix, definition
1956 @vindex check_
1958 The special prefix @samp{check_} indicates that the objects in question
1959 should not be built until the @samp{make check} command is run.  Those
1960 objects are not installed either.
1962 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
1963 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
1964 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
1965 @vindex PROGRAMS
1966 @vindex LIBRARIES
1967 @vindex LISP
1968 @vindex PYTHON
1969 @vindex JAVA
1970 @vindex SCRIPTS
1971 @vindex DATA
1972 @vindex HEADERS
1973 @vindex MANS
1974 @vindex TEXINFOS
1976 Some primaries also allow additional prefixes that control other
1977 aspects of @command{automake}'s behavior.  The currently defined prefixes
1978 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
1979 These prefixes are explained later (@pxref{Program and Library Variables})
1980 (@pxref{Man pages}).
1983 @node Length limitations
1984 @section Staying below the command line length limit
1986 @cindex command line length limit
1987 @cindex ARG_MAX
1989 Traditionally, most unix-like systems have a length limitation for the
1990 command line arguments and environment contents when creating new
1991 processes (see for example
1992 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
1993 overview on this issue),
1994 which of course also applies to commands spawned by @command{make}.
1995 POSIX requires this limit to be at least 4096 bytes, and most modern
1996 systems have quite high limits (or are unlimited).
1998 In order to create portable Makefiles that do not trip over these
1999 limits, it is necessary to keep the length of file lists bounded.
2000 Unfortunately, it is not possible to do so fully transparently within
2001 Automake, so your help may be needed.  Typically, you can split long
2002 file lists manually and use different installation directory names for
2003 each list.  For example,
2005 @example
2006 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2007 @end example
2009 @noindent
2010 may also be written as
2012 @example
2013 data_DATA = file1 @dots{} file@var{N}
2014 data2dir = $(datadir)
2015 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2016 @end example
2018 @noindent
2019 and will cause Automake to treat the two lists separately during
2020 @code{make install}.  See @ref{Install} for choosing directory names
2021 that will keep the ordering of the two parts of installation
2022 (@pxref{Two-Part Install}).  Note that @code{make dist} may still
2023 only work on a host with a higher length limit in this example.
2025 Automake itself employs a couple of strategies to avoid long command
2026 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2027 names, as can happen with above @code{$(data_DATA)} lists, it limits
2028 the amount of arguments passed to external commands.
2030 Unfortunately, some system's @command{make} commands may prepend
2031 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2032 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2033 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2034 may have to switch to use GNU Make, or refrain from using VPATH builds,
2035 in order to stay below the length limit.
2037 For libraries and programs built from many sources, convenience archives
2038 may be used as intermediates in order to limit the object list length
2039 (@pxref{Libtool Convenience Libraries}).
2042 @node Canonicalization
2043 @section How derived variables are named
2045 @cindex canonicalizing Automake variables
2047 Sometimes a Makefile variable name is derived from some text the
2048 maintainer supplies.  For instance, a program name listed in
2049 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2050 variable.  In cases like this, Automake canonicalizes the text, so that
2051 program names and the like do not have to follow Makefile variable naming
2052 rules.  All characters in the name except for letters, numbers, the
2053 strudel (@@), and the underscore are turned into underscores when making
2054 variable references.
2056 For example, if your program is named @file{sniff-glue}, the derived
2057 variable name would be @samp{sniff_glue_SOURCES}, not
2058 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2059 @file{libmumble++.a} should be listed in the
2060 @samp{libmumble___a_SOURCES} variable.
2062 The strudel is an addition, to make the use of Autoconf substitutions in
2063 variable names less obfuscating.
2066 @node User Variables
2067 @section Variables reserved for the user
2069 @cindex variables, reserved for the user
2070 @cindex user variables
2072 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2073 for the use of the ``user''---the person building the package.  For
2074 instance, @code{CFLAGS} is one such variable.
2076 Sometimes package developers are tempted to set user variables such as
2077 @code{CFLAGS} because it appears to make their job easier.  However,
2078 the package itself should never set a user variable, particularly not
2079 to include switches that are required for proper compilation of the
2080 package.  Since these variables are documented as being for the
2081 package builder, that person rightfully expects to be able to override
2082 any of these variables at build time.
2084 To get around this problem, Automake introduces an automake-specific
2085 shadow variable for each user flag variable.  (Shadow variables are
2086 not introduced for variables like @code{CC}, where they would make no
2087 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2088 user variable's name.  For instance, the shadow variable for
2089 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2090 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2091 files---may adjust these shadow variables however necessary.
2093 @xref{Flag Variables Ordering}, for more discussion about these
2094 variables and how they interact with per-target variables.
2096 @node Auxiliary Programs
2097 @section Programs automake might require
2099 @cindex Programs, auxiliary
2100 @cindex Auxiliary programs
2102 Automake sometimes requires helper programs so that the generated
2103 @file{Makefile} can do its work properly.  There are a fairly large
2104 number of them, and we list them here.
2106 Although all of these files are distributed and installed with
2107 Automake, a couple of them are maintained separately.  The Automake
2108 copies are updated before each release, but we mention the original
2109 source in case you need more recent versions.
2111 @table @code
2112 @item ansi2knr.c
2113 @itemx ansi2knr.1
2114 These two files are used for de-ANSI-fication support (obsolete
2115 @pxref{ANSI}).
2117 @item compile
2118 This is a wrapper for compilers that do not accept options @option{-c}
2119 and @option{-o} at the same time.  It is only used when absolutely
2120 required.  Such compilers are rare.
2122 @item config.guess
2123 @itemx config.sub
2124 These two programs compute the canonical triplets for the given build,
2125 host, or target architecture.  These programs are updated regularly to
2126 support new architectures and fix probes broken by changes in new
2127 kernel versions.  Each new release of Automake comes with up-to-date
2128 copies of these programs.  If your copy of Automake is getting old,
2129 you are encouraged to fetch the latest versions of these files from
2130 @url{http://savannah.gnu.org/git/?group=config} before making a
2131 release.
2133 @item config-ml.in
2134 This file is not a program, it is a @file{configure} fragment used for
2135 multilib support (@pxref{Multilibs}).  This file is maintained in the
2136 GCC tree at @url{http://gcc.gnu.org/svn.html}.
2138 @item depcomp
2139 This program understands how to run a compiler so that it will
2140 generate not only the desired output but also dependency information
2141 that is then used by the automatic dependency tracking feature
2142 (@pxref{Dependencies}).
2144 @item elisp-comp
2145 This program is used to byte-compile Emacs Lisp code.
2147 @item install-sh
2148 This is a replacement for the @command{install} program that works on
2149 platforms where @command{install} is unavailable or unusable.
2151 @item mdate-sh
2152 This script is used to generate a @file{version.texi} file.  It examines
2153 a file and prints some date information about it.
2155 @item missing
2156 This wraps a number of programs that are typically only required by
2157 maintainers.  If the program in question doesn't exist,
2158 @command{missing} prints an informative warning and attempts to fix
2159 things so that the build can continue.
2161 @item mkinstalldirs
2162 This script used to be a wrapper around @samp{mkdir -p}, which is not
2163 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2164 finds that @samp{mkdir -p} does not work, this makes one less script to
2165 distribute.
2167 For backward compatibility @file{mkinstalldirs} is still used and
2168 distributed when @command{automake} finds it in a package.  But it is no
2169 longer installed automatically, and it should be safe to remove it.
2171 @item py-compile
2172 This is used to byte-compile Python scripts.
2174 @item symlink-tree
2175 This program duplicates a tree of directories, using symbolic links
2176 instead of copying files.  Such an operation is performed when building
2177 multilibs (@pxref{Multilibs}).  This file is maintained in the GCC
2178 tree at @url{http://gcc.gnu.org/svn.html}.
2180 @item texinfo.tex
2181 Not a program, this file is required for @samp{make dvi}, @samp{make
2182 ps} and @samp{make pdf} to work when Texinfo sources are in the
2183 package.  The latest version can be downloaded from
2184 @url{http://www.gnu.org/software/texinfo/}.
2186 @item ylwrap
2187 This program wraps @command{lex} and @command{yacc} to rename their
2188 output files.  It also ensures that, for instance, multiple
2189 @command{yacc} instances can be invoked in a single directory in
2190 parallel.
2192 @end table
2195 @node Examples
2196 @chapter Some example packages
2198 This section contains two small examples.
2200 The first example (@pxref{Complete}) assumes you have an existing
2201 project already using Autoconf, with handcrafted @file{Makefile}s, and
2202 that you want to convert it to using Automake.  If you are discovering
2203 both tools, it is probably better that you look at the Hello World
2204 example presented earlier (@pxref{Hello World}).
2206 The second example (@pxref{true}) shows how two programs can be built
2207 from the same file, using different compilation parameters.  It
2208 contains some technical digressions that are probably best skipped on
2209 first read.
2211 @menu
2212 * Complete::                    A simple example, start to finish
2213 * true::                        Building true and false
2214 @end menu
2217 @node Complete
2218 @section A simple example, start to finish
2220 @cindex Complete example
2222 Let's suppose you just finished writing @code{zardoz}, a program to make
2223 your head float from vortex to vortex.  You've been using Autoconf to
2224 provide a portability framework, but your @file{Makefile.in}s have been
2225 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2227 @cindex @code{AM_INIT_AUTOMAKE}, example use
2229 The first step is to update your @file{configure.ac} to include the
2230 commands that @command{automake} needs.  The way to do this is to add an
2231 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2233 @example
2234 AC_INIT([zardoz], [1.0])
2235 AM_INIT_AUTOMAKE
2236 @dots{}
2237 @end example
2239 Since your program doesn't have any complicating factors (e.g., it
2240 doesn't use @code{gettext}, it doesn't want to build a shared library),
2241 you're done with this part.  That was easy!
2243 @cindex @command{aclocal} program, introduction
2244 @cindex @file{aclocal.m4}, preexisting
2245 @cindex @file{acinclude.m4}, defined
2247 Now you must regenerate @file{configure}.  But to do that, you'll need
2248 to tell @command{autoconf} how to find the new macro you've used.  The
2249 easiest way to do this is to use the @command{aclocal} program to
2250 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2251 already have an @file{aclocal.m4}, because you had to write some hairy
2252 macros for your program.  The @command{aclocal} program lets you put
2253 your own macros into @file{acinclude.m4}, so simply rename and then
2254 run:
2256 @example
2257 mv aclocal.m4 acinclude.m4
2258 aclocal
2259 autoconf
2260 @end example
2262 @cindex @command{zardoz} example
2264 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2265 Since @code{zardoz} is a user program, you want to install it where the
2266 rest of the user programs go: @code{bindir}.  Additionally,
2267 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2268 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2269 @samp{$(LIBOBJS)}.  So here's what you'd write:
2271 @example
2272 bin_PROGRAMS = zardoz
2273 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2274 zardoz_LDADD = $(LIBOBJS)
2276 info_TEXINFOS = zardoz.texi
2277 @end example
2279 Now you can run @samp{automake --add-missing} to generate your
2280 @file{Makefile.in} and grab any auxiliary files you might need, and
2281 you're done!
2284 @node true
2285 @section Building true and false
2287 @cindex Example, @command{false} and @command{true}
2288 @cindex @command{false} Example
2289 @cindex @command{true} Example
2291 Here is another, trickier example.  It shows how to generate two
2292 programs (@code{true} and @code{false}) from the same source file
2293 (@file{true.c}).  The difficult part is that each compilation of
2294 @file{true.c} requires different @code{cpp} flags.
2296 @example
2297 bin_PROGRAMS = true false
2298 false_SOURCES =
2299 false_LDADD = false.o
2301 true.o: true.c
2302         $(COMPILE) -DEXIT_CODE=0 -c true.c
2304 false.o: true.c
2305         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2306 @end example
2308 Note that there is no @code{true_SOURCES} definition.  Automake will
2309 implicitly assume that there is a source file named @file{true.c}
2310 (@pxref{Default _SOURCES}), and
2311 define rules to compile @file{true.o} and link @file{true}.  The
2312 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2313 will override the Automake generated rule to build @file{true.o}.
2315 @code{false_SOURCES} is defined to be empty---that way no implicit value
2316 is substituted.  Because we have not listed the source of
2317 @file{false}, we have to tell Automake how to link the program.  This is
2318 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2319 variable, holding the dependencies of the @file{false} target will be
2320 automatically generated by Automake from the content of
2321 @code{false_LDADD}.
2323 The above rules won't work if your compiler doesn't accept both
2324 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2325 bogus dependency (to avoid problems with a parallel @command{make}):
2327 @example
2328 true.o: true.c false.o
2329         $(COMPILE) -DEXIT_CODE=0 -c true.c
2331 false.o: true.c
2332         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2333 @end example
2335 Also, these explicit rules do not work if the obsolete de-ANSI-fication feature
2336 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
2337 more work:
2339 @example
2340 true_.o: true_.c false_.o
2341         $(COMPILE) -DEXIT_CODE=0 -c true_.c
2343 false_.o: true_.c
2344         $(COMPILE) -DEXIT_CODE=1 -c true_.c && mv true_.o false_.o
2345 @end example
2347 As it turns out, there is also a much easier way to do this same task.
2348 Some of the above techniques are useful enough that we've kept the
2349 example in the manual.  However if you were to build @code{true} and
2350 @code{false} in real life, you would probably use per-program
2351 compilation flags, like so:
2353 @example
2354 bin_PROGRAMS = false true
2356 false_SOURCES = true.c
2357 false_CPPFLAGS = -DEXIT_CODE=1
2359 true_SOURCES = true.c
2360 true_CPPFLAGS = -DEXIT_CODE=0
2361 @end example
2363 In this case Automake will cause @file{true.c} to be compiled twice,
2364 with different flags.  De-ANSI-fication will work automatically.  In
2365 this instance, the names of the object files would be chosen by
2366 automake; they would be @file{false-true.o} and @file{true-true.o}.
2367 (The name of the object files rarely matters.)
2370 @node Invoking Automake
2371 @chapter Creating a @file{Makefile.in}
2373 @cindex Multiple @file{configure.ac} files
2374 @cindex Invoking @command{automake}
2375 @cindex @command{automake}, invoking
2377 To create all the @file{Makefile.in}s for a package, run the
2378 @command{automake} program in the top level directory, with no
2379 arguments.  @command{automake} will automatically find each
2380 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2381 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2382 Note that @command{automake} has a rather simplistic view of what
2383 constitutes a package; it assumes that a package has only one
2384 @file{configure.ac}, at the top.  If your package has multiple
2385 @file{configure.ac}s, then you must run @command{automake} in each
2386 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2387 on Autoconf's @command{autoreconf}, which is able to recurse your
2388 package tree and run @command{automake} where appropriate.)
2390 You can optionally give @command{automake} an argument; @file{.am} is
2391 appended to the argument and the result is used as the name of the
2392 input file.  This feature is generally only used to automatically
2393 rebuild an out-of-date @file{Makefile.in}.  Note that
2394 @command{automake} must always be run from the topmost directory of a
2395 project, even if being used to regenerate the @file{Makefile.in} in
2396 some subdirectory.  This is necessary because @command{automake} must
2397 scan @file{configure.ac}, and because @command{automake} uses the
2398 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2399 behavior in some cases.
2401 @vindex AUTOCONF
2402 Automake will run @command{autoconf} to scan @file{configure.ac} and
2403 its dependencies (i.e., @file{aclocal.m4} and any included file),
2404 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2405 an @env{AUTOCONF} variable in your environment it will be used
2406 instead of @command{autoconf}, this allows you to select a particular
2407 version of Autoconf.  By the way, don't misunderstand this paragraph:
2408 @command{automake} runs @command{autoconf} to @strong{scan} your
2409 @file{configure.ac}, this won't build @file{configure} and you still
2410 have to run @command{autoconf} yourself for this purpose.
2412 @cindex @command{automake} options
2413 @cindex Options, @command{automake}
2414 @cindex Strictness, command line
2416 @command{automake} accepts the following options:
2418 @cindex Extra files distributed with Automake
2419 @cindex Files distributed with Automake
2420 @cindex @file{config.guess}
2422 @table @code
2423 @item -a
2424 @itemx --add-missing
2425 @opindex -a
2426 @opindex --add-missing
2427 Automake requires certain common files to exist in certain situations;
2428 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2429 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2430 files (@pxref{Auxiliary Programs}); this option will cause the missing
2431 ones to be automatically added to the package, whenever possible.  In
2432 general if Automake tells you a file is missing, try using this option.
2433 By default Automake tries to make a symbolic link pointing to its own
2434 copy of the missing file; this can be changed with @option{--copy}.
2436 Many of the potentially-missing files are common scripts whose
2437 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2438 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2439 file is considered missing, and where the missing file is added
2440 (@pxref{Optional}).
2442 In some strictness modes, additional files are installed, see @ref{Gnits}
2443 for more information.
2445 @item --libdir=@var{dir}
2446 @opindex --libdir
2447 Look for Automake data files in directory @var{dir} instead of in the
2448 installation directory.  This is typically used for debugging.
2450 @item -c
2451 @opindex -c
2452 @itemx --copy
2453 @opindex --copy
2454 When used with @option{--add-missing}, causes installed files to be
2455 copied.  The default is to make a symbolic link.
2457 @item --cygnus
2458 @opindex --cygnus
2459 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2460 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2462 @item -f
2463 @opindex -f
2464 @itemx --force-missing
2465 @opindex --force-missing
2466 When used with @option{--add-missing}, causes standard files to be reinstalled
2467 even if they already exist in the source tree.  This involves removing
2468 the file from the source tree before creating the new symlink (or, with
2469 @option{--copy}, copying the new file).
2471 @item --foreign
2472 @opindex --foreign
2473 Set the global strictness to @option{foreign}.  For more information, see
2474 @ref{Strictness}.
2476 @item --gnits
2477 @opindex --gnits
2478 Set the global strictness to @option{gnits}.  For more information, see
2479 @ref{Gnits}.
2481 @item --gnu
2482 @opindex --gnu
2483 Set the global strictness to @option{gnu}.  For more information, see
2484 @ref{Gnits}.  This is the default strictness.
2486 @item --help
2487 @opindex --help
2488 Print a summary of the command line options and exit.
2490 @item -i
2491 @itemx --ignore-deps
2492 @opindex -i
2493 This disables the dependency tracking feature in generated
2494 @file{Makefile}s; see @ref{Dependencies}.
2496 @item --include-deps
2497 @opindex --include-deps
2498 This enables the dependency tracking feature.  This feature is enabled
2499 by default.  This option is provided for historical reasons only and
2500 probably should not be used.
2502 @item --no-force
2503 @opindex --no-force
2504 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2505 @file{configure.ac}.  This option causes it to only update those
2506 @file{Makefile.in}s that are out of date with respect to one of their
2507 dependents.
2509 @item -o @var{dir}
2510 @itemx --output-dir=@var{dir}
2511 @opindex -o
2512 @opindex --output-dir
2513 Put the generated @file{Makefile.in} in the directory @var{dir}.
2514 Ordinarily each @file{Makefile.in} is created in the directory of the
2515 corresponding @file{Makefile.am}.  This option is deprecated and will be
2516 removed in a future release.
2518 @item -v
2519 @itemx --verbose
2520 @opindex -v
2521 @opindex --verbose
2522 Cause Automake to print information about which files are being read or
2523 created.
2525 @item --version
2526 @opindex --version
2527 Print the version number of Automake and exit.
2529 @item -W CATEGORY
2530 @itemx --warnings=@var{category}
2531 @opindex -W
2532 @opindex --warnings
2533 Output warnings falling in @var{category}.  @var{category} can be
2534 one of:
2535 @table @code
2536 @item gnu
2537 warnings related to the GNU Coding Standards
2538 (@pxref{Top, , , standards, The GNU Coding Standards}).
2539 @item obsolete
2540 obsolete features or constructions
2541 @item override
2542 user redefinitions of Automake rules or variables
2543 @item portability
2544 portability issues (e.g., use of @command{make} features that are
2545 known to be not portable)
2546 @item syntax
2547 weird syntax, unused variables, typos
2548 @item unsupported
2549 unsupported or incomplete features
2550 @item all
2551 all the warnings
2552 @item none
2553 turn off all the warnings
2554 @item error
2555 treat warnings as errors
2556 @end table
2558 A category can be turned off by prefixing its name with @samp{no-}.  For
2559 instance, @option{-Wno-syntax} will hide the warnings about unused
2560 variables.
2562 The categories output by default are @samp{syntax} and
2563 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2564 are enabled in @option{--gnu} and @option{--gnits} strictness.
2566 @vindex WARNINGS
2567 The environment variable @env{WARNINGS} can contain a comma separated
2568 list of categories to enable.  It will be taken into account before the
2569 command-line switches, this way @option{-Wnone} will also ignore any
2570 warning category enabled by @env{WARNINGS}.  This variable is also used
2571 by other tools like @command{autoconf}; unknown categories are ignored
2572 for this reason.
2574 @end table
2576 @vindex AUTOMAKE_JOBS
2577 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2578 number, it is taken as the maximum number of Perl threads to use in
2579 @command{automake} for generating multiple @file{Makefile.in} files
2580 concurrently.  This is an experimental feature.
2583 @node configure
2584 @chapter Scanning @file{configure.ac}
2586 @cindex @file{configure.ac}, scanning
2587 @cindex Scanning @file{configure.ac}
2589 Automake scans the package's @file{configure.ac} to determine certain
2590 information about the package.  Some @command{autoconf} macros are required
2591 and some variables must be defined in @file{configure.ac}.  Automake
2592 will also use information from @file{configure.ac} to further tailor its
2593 output.
2595 Automake also supplies some Autoconf macros to make the maintenance
2596 easier.  These macros can automatically be put into your
2597 @file{aclocal.m4} using the @command{aclocal} program.
2599 @menu
2600 * Requirements::                Configuration requirements
2601 * Optional::                    Other things Automake recognizes
2602 * Invoking aclocal::            Auto-generating aclocal.m4
2603 * Macros::                      Autoconf macros supplied with Automake
2604 @end menu
2607 @node Requirements
2608 @section Configuration requirements
2610 @cindex Automake requirements
2611 @cindex Requirements of Automake
2613 @acindex AM_INIT_AUTOMAKE
2614 The one real requirement of Automake is that your @file{configure.ac}
2615 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2616 required for proper Automake operation (@pxref{Macros}).
2618 Here are the other macros that Automake requires but which are not run
2619 by @code{AM_INIT_AUTOMAKE}:
2621 @table @code
2622 @item AC_CONFIG_FILES
2623 @itemx AC_OUTPUT
2624 @acindex AC_CONFIG_FILES
2625 @acindex AC_OUTPUT
2626 These two macros are usually invoked as follows near the end of
2627 @file{configure.ac}.
2629 @example
2630 @dots{}
2631 AC_CONFIG_FILES([
2632   Makefile
2633   doc/Makefile
2634   src/Makefile
2635   src/lib/Makefile
2636   @dots{}
2638 AC_OUTPUT
2639 @end example
2641 Automake uses these to determine which files to create (@pxref{Output, ,
2642 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2643 is considered to be an Automake generated @file{Makefile} if there
2644 exists a file with the same name and the @file{.am} extension appended.
2645 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2646 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2648 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2650 @example
2651 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2652 @end example
2654 @noindent
2655 @command{automake} will generate the first @file{.in} input file for
2656 which a @file{.am} file exists.  If no such file exists the output
2657 file is not considered to be generated by Automake.
2659 Files created by @code{AC_CONFIG_FILES}, be they Automake
2660 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2661 Their inputs are automatically distributed, unless they
2662 are the output of prior @code{AC_CONFIG_FILES} commands.
2663 Finally, rebuild rules are generated in the Automake @file{Makefile}
2664 existing in the subdirectory of the output file, if there is one, or
2665 in the top-level @file{Makefile} otherwise.
2667 The above machinery (cleaning, distributing, and rebuilding) works
2668 fine if the @code{AC_CONFIG_FILES} specifications contain only
2669 literals.  If part of the specification uses shell variables,
2670 @command{automake} will not be able to fulfill this setup, and you will
2671 have to complete the missing bits by hand.  For instance, on
2673 @example
2674 file=input
2675 @dots{}
2676 AC_CONFIG_FILES([output:$file],, [file=$file])
2677 @end example
2679 @noindent
2680 @command{automake} will output rules to clean @file{output}, and
2681 rebuild it.  However the rebuild rule will not depend on @file{input},
2682 and this file will not be distributed either.  (You must add
2683 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2684 source file.)
2686 Similarly
2688 @example
2689 file=output
2690 file2=out:in
2691 @dots{}
2692 AC_CONFIG_FILES([$file:input],, [file=$file])
2693 AC_CONFIG_FILES([$file2],, [file2=$file2])
2694 @end example
2696 @noindent
2697 will only cause @file{input} to be distributed.  No file will be
2698 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2699 yourself), and no rebuild rule will be output.
2701 Obviously @command{automake} cannot guess what value @samp{$file} is
2702 going to hold later when @file{configure} is run, and it cannot use
2703 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2704 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2705 that is compatible with @command{make}'s syntax) and furthermore use
2706 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2707 @file{Makefile}, then @command{automake} will be able to use
2708 @samp{$@{file@}} to generate all these rules.  For instance, here is
2709 how the Automake package itself generates versioned scripts for its
2710 test suite:
2712 @example
2713 AC_SUBST([APIVERSION], @dots{})
2714 @dots{}
2715 AC_CONFIG_FILES(
2716   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2717   [chmod +x tests/aclocal-$@{APIVERSION@}],
2718   [APIVERSION=$APIVERSION])
2719 AC_CONFIG_FILES(
2720   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2721   [chmod +x tests/automake-$@{APIVERSION@}])
2722 @end example
2724 @noindent
2725 Here cleaning, distributing, and rebuilding are done automatically,
2726 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2728 Note that you should not use shell variables to declare
2729 @file{Makefile} files for which @command{automake} must create
2730 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2731 @command{automake} needs to know the file name when it runs in order
2732 to check whether @file{Makefile.am} exists.  (In the very hairy case
2733 that your setup requires such use of variables, you will have to tell
2734 Automake which @file{Makefile.in}s to generate on the command-line.)
2736 It is possible to let @command{automake} emit conditional rules for
2737 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2738 (@pxref{Optional}).
2740 To summarize:
2741 @itemize @bullet
2742 @item
2743 Use literals for @file{Makefile}s, and for other files whenever possible.
2744 @item
2745 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2746 for files that @command{automake} should ignore.
2747 @item
2748 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2749 that @command{automake} should not ignore.
2750 @end itemize
2752 @end table
2755 @node Optional
2756 @section Other things Automake recognizes
2758 @cindex Macros Automake recognizes
2759 @cindex Recognized macros by Automake
2761 Every time Automake is run it calls Autoconf to trace
2762 @file{configure.ac}.  This way it can recognize the use of certain
2763 macros and tailor the generated @file{Makefile.in} appropriately.
2764 Currently recognized macros and their effects are:
2766 @ftable @code
2767 @item AC_CANONICAL_BUILD
2768 @itemx AC_CANONICAL_HOST
2769 @itemx AC_CANONICAL_TARGET
2770 @vindex build_triplet
2771 @vindex host_triplet
2772 @vindex target_triplet
2773 Automake will ensure that @file{config.guess} and @file{config.sub}
2774 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2775 @code{host_triplet} and @code{target_triplet} are introduced.  See
2776 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2777 The Autoconf Manual}.
2779 @item AC_CONFIG_AUX_DIR
2780 Automake will look for various helper scripts, such as
2781 @file{install-sh}, in the directory named in this macro invocation.
2782 @c This list is accurate relative to version 1.8
2783 (The full list of scripts is: @file{config.guess}, @file{config.sub},
2784 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
2785 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
2786 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
2787 scripts are always searched for; some scripts will only be sought if the
2788 generated @file{Makefile.in} requires them.
2790 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2791 their standard locations.  For @file{mdate-sh},
2792 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2793 source directory corresponding to the current @file{Makefile.am}.  For
2794 the rest, the standard location is the first one of @file{.}, @file{..},
2795 or @file{../..} (relative to the top source directory) that provides any
2796 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2797 autoconf, The Autoconf Manual}.
2799 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2800 distributed, even if there is no @file{Makefile.am} in this directory.
2802 @item AC_CONFIG_LIBOBJ_DIR
2803 Automake will require the sources file declared with
2804 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2805 macro.
2807 @item AC_CONFIG_HEADERS
2808 Automake will generate rules to rebuild these headers.  Older versions
2809 of Automake required the use of @code{AM_CONFIG_HEADER}
2810 (@pxref{Macros}); this is no longer the case.
2812 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2813 specification using shell variables will be ignored as far as
2814 cleaning, distributing, and rebuilding is concerned.
2816 @item AC_CONFIG_LINKS
2817 Automake will generate rules to remove @file{configure} generated
2818 links on @samp{make distclean} and to distribute named source files as
2819 part of @samp{make dist}.
2821 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2822 specification using shell variables will be ignored as far as cleaning
2823 and distributing is concerned.  (There are no rebuild rules for links.)
2825 @item AC_LIBOBJ
2826 @itemx AC_LIBSOURCE
2827 @itemx AC_LIBSOURCES
2828 @vindex LIBOBJS
2829 Automake will automatically distribute any file listed in
2830 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2832 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2833 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2834 @file{file.c} will be distributed automatically by Automake.  This
2835 encompasses many macros like @code{AC_FUNC_ALLOCA},
2836 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2838 By the way, direct assignments to @code{LIBOBJS} are no longer
2839 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2840 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2841 autoconf, The Autoconf Manual}.
2843 @item AC_PROG_RANLIB
2844 This is required if any libraries are built in the package.
2845 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2846 Autoconf Manual}.
2848 @item AC_PROG_CXX
2849 This is required if any C++ source is included.  @xref{Particular
2850 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2852 @item AC_PROG_OBJC
2853 This is required if any Objective C source is included.  @xref{Particular
2854 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2856 @item AC_PROG_F77
2857 This is required if any Fortran 77 source is included.  This macro is
2858 distributed with Autoconf version 2.13 and later.  @xref{Particular
2859 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2861 @item AC_F77_LIBRARY_LDFLAGS
2862 This is required for programs and shared libraries that are a mixture of
2863 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
2864 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
2866 @item AC_FC_SRCEXT
2867 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
2868 of files with the respective source extension (@pxref{Fortran Compiler, ,
2869 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
2871 @item AC_PROG_FC
2872 This is required if any Fortran 90/95 source is included.  This macro is
2873 distributed with Autoconf version 2.58 and later.  @xref{Particular
2874 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2876 @item AC_PROG_LIBTOOL
2877 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
2878 Introduction, libtool, The Libtool Manual}).
2880 @item AC_PROG_YACC
2881 @vindex YACC
2882 If a Yacc source file is seen, then you must either use this macro or
2883 define the variable @code{YACC} in @file{configure.ac}.  The former is
2884 preferred (@pxref{Particular Programs, , Particular Program Checks,
2885 autoconf, The Autoconf Manual}).
2887 @item AC_PROG_LEX
2888 If a Lex source file is seen, then this macro must be used.
2889 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2890 Autoconf Manual}.
2892 @item AC_REQUIRE_AUX_FILE
2893 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
2894 @command{automake} will ensure that @file{@var{file}} exists in the
2895 aux directory, and will complain otherwise.  It
2896 will also automatically distribute the file.  This macro should be
2897 used by third-party Autoconf macros that require some supporting
2898 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
2899 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
2900 The Autoconf Manual}.
2902 @item AC_SUBST
2903 The first argument is automatically defined as a variable in each
2904 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
2905 used for this variable.  @xref{Setting Output Variables, , Setting
2906 Output Variables, autoconf, The Autoconf Manual}.
2908 For every substituted variable @var{var}, @command{automake} will add
2909 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
2910 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
2911 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
2912 @code{X_LIBS}.  Thus, you can access these variables as
2913 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
2914 if @code{AC_PATH_XTRA} is called.
2916 @item AM_C_PROTOTYPES
2917 This is required when using the obsolete de-ANSI-fication feature; see
2918 @ref{ANSI}.
2920 @item AM_CONDITIONAL
2921 This introduces an Automake conditional (@pxref{Conditionals}).
2923 @item AM_COND_IF
2924 This macro allows @code{automake} to detect subsequent access within
2925 @file{configure.ac} to a conditional previously introduced with
2926 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
2927 (@pxref{Conditionals}).
2929 @item AM_GNU_GETTEXT
2930 This macro is required for packages that use GNU gettext
2931 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
2932 this macro it ensures that the package meets some of gettext's
2933 requirements.
2935 @item AM_GNU_GETTEXT_INTL_SUBDIR
2936 This macro specifies that the @file{intl/} subdirectory is to be built,
2937 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
2938 of @samp{external}.
2940 @item AM_MAINTAINER_MODE(@ovar{default-mode})
2941 @opindex --enable-maintainer-mode
2942 @opindex --disable-maintainer-mode
2943 This macro adds an @option{--enable-maintainer-mode} option to
2944 @command{configure}.  If this is used, @command{automake} will cause
2945 ``maintainer-only'' rules to be turned off by default in the
2946 generated @file{Makefile.in}s, unless @var{default-mode} is
2947 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
2948 conditional, which you can use in your own @file{Makefile.am}.
2949 @xref{maintainer-mode}.
2951 @item AM_SUBST_NOTMAKE(@var{var})
2952 Prevent Automake from defining a variable @var{var}, even if it is
2953 substituted by @command{config.status}.  Normally, Automake defines a
2954 @command{make} variable for each @command{configure} substitution,
2955 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
2956 definition from Automake.  If @code{AC_SUBST} has not been called
2957 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
2958 Preventing variable definitions may be useful for substitution of
2959 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
2960 unintended results.
2962 @item m4_include
2963 Files included by @file{configure.ac} using this macro will be
2964 detected by Automake and automatically distributed.  They will also
2965 appear as dependencies in @file{Makefile} rules.
2967 @code{m4_include} is seldom used by @file{configure.ac} authors, but
2968 can appear in @file{aclocal.m4} when @command{aclocal} detects that
2969 some required macros come from files local to your package (as opposed
2970 to macros installed in a system-wide directory, @pxref{Invoking
2971 aclocal}).
2973 @end ftable
2976 @node Invoking aclocal
2977 @section Auto-generating aclocal.m4
2979 @cindex Invoking @command{aclocal}
2980 @cindex @command{aclocal}, Invoking
2982 Automake includes a number of Autoconf macros that can be used in
2983 your package (@pxref{Macros}); some of them are actually required by
2984 Automake in certain situations.  These macros must be defined in your
2985 @file{aclocal.m4}; otherwise they will not be seen by
2986 @command{autoconf}.
2988 The @command{aclocal} program will automatically generate
2989 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
2990 This provides a convenient way to get Automake-provided macros,
2991 without having to search around.  The @command{aclocal} mechanism
2992 allows other packages to supply their own macros (@pxref{Extending
2993 aclocal}).  You can also use it to maintain your own set of custom
2994 macros (@pxref{Local Macros}).
2996 At startup, @command{aclocal} scans all the @file{.m4} files it can
2997 find, looking for macro definitions (@pxref{Macro search path}).  Then
2998 it scans @file{configure.ac}.  Any mention of one of the macros found
2999 in the first step causes that macro, and any macros it in turn
3000 requires, to be put into @file{aclocal.m4}.
3002 @emph{Putting} the file that contains the macro definition into
3003 @file{aclocal.m4} is usually done by copying the entire text of this
3004 file, including unused macro definitions as well as both @samp{#} and
3005 @samp{dnl} comments.  If you want to make a comment that will be
3006 completely ignored by @command{aclocal}, use @samp{##} as the comment
3007 leader.
3009 When a file selected by @command{aclocal} is located in a subdirectory
3010 specified as a relative search path with @command{aclocal}'s @option{-I}
3011 argument, @command{aclocal} assumes the file belongs to the package
3012 and uses @code{m4_include} instead of copying it into
3013 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3014 tracking, and cause the file to be distributed automatically.
3015 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3016 system-wide directory, or via an absolute search path will be copied.
3017 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3018 some relative directory need to be considered outside the package.
3020 The contents of @file{acinclude.m4}, if this file exists, are also
3021 automatically included in @file{aclocal.m4}.  We recommend against
3022 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3024 @vindex AUTOM4TE
3025 @cindex autom4te
3026 While computing @file{aclocal.m4}, @command{aclocal} runs
3027 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3028 autoconf, The Autoconf Manual}) in order to trace the macros that are
3029 really used, and omit from @file{aclocal.m4} all macros that are
3030 mentioned but otherwise unexpanded (this can happen when a macro is
3031 called conditionally).  @command{autom4te} is expected to be in the
3032 @env{PATH}, just as @command{autoconf}.  Its location can be
3033 overridden using the @env{AUTOM4TE} environment variable.
3035 @menu
3036 * aclocal options::             Options supported by aclocal
3037 * Macro search path::           How aclocal finds .m4 files
3038 * Extending aclocal::           Writing your own aclocal macros
3039 * Local Macros::                Organizing local macros
3040 * Serials::                     Serial lines in Autoconf macros
3041 * Future of aclocal::           aclocal's scheduled death
3042 @end menu
3044 @node aclocal options
3045 @subsection aclocal options
3047 @cindex @command{aclocal}, Options
3048 @cindex Options, @command{aclocal}
3050 @command{aclocal} accepts the following options:
3052 @table @code
3053 @item --acdir=@var{dir}
3054 @opindex --acdir
3055 Look for the macro files in @var{dir} instead of the installation
3056 directory.  This is typically used for debugging.
3058 @item --diff[=@var{command}]
3059 @opindex --diff
3060 Run @var{command} on M4 file that would be installed or overwritten
3061 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3062 This option implies @option{--install} and @option{--dry-run}.
3064 @item --dry-run
3065 @opindex --dry-run
3066 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3067 files installed by @option{--install}.
3069 @item --help
3070 @opindex --help
3071 Print a summary of the command line options and exit.
3073 @item -I @var{dir}
3074 @opindex -I
3075 Add the directory @var{dir} to the list of directories searched for
3076 @file{.m4} files.
3078 @item --install
3079 @opindex --install
3080 Install system-wide third-party macros into the first directory
3081 specified with @samp{-I @var{dir}} instead of copying them in the
3082 output file.
3084 @cindex serial number and @option{--install}
3085 When this option is used, and only when this option is used,
3086 @command{aclocal} will also honor @samp{#serial @var{NUMBER}} lines
3087 that appear in macros: an M4 file is ignored if there exists another
3088 M4 file with the same basename and a greater serial number in the
3089 search path (@pxref{Serials}).
3091 @item --force
3092 @opindex --force
3093 Always overwrite the output file.  The default is to overwrite the output
3094 file only when really needed, i.e., when its contents changes or if one
3095 of its dependencies is younger.
3097 This option forces the update of @file{aclocal.m4} (or the file
3098 specified with @file{--output} below) and only this file, it has
3099 absolutely no influence on files that may need to be installed by
3100 @option{--install}.
3102 @item --output=@var{file}
3103 @opindex --output
3104 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3106 @item --print-ac-dir
3107 @opindex --print-ac-dir
3108 Prints the name of the directory that @command{aclocal} will search to
3109 find third-party @file{.m4} files.  When this option is given, normal
3110 processing is suppressed.  This option can be used by a package to
3111 determine where to install a macro file.
3113 @item --verbose
3114 @opindex --verbose
3115 Print the names of the files it examines.
3117 @item --version
3118 @opindex --version
3119 Print the version number of Automake and exit.
3121 @item -W CATEGORY
3122 @item --warnings=@var{category}
3123 @opindex -W
3124 @opindex --warnings
3125 Output warnings falling in @var{category}.  @var{category} can be
3126 one of:
3127 @table @code
3128 @item syntax
3129 dubious syntactic constructs, underquoted macros, unused macros, etc.
3130 @item unsupported
3131 unknown macros
3132 @item all
3133 all the warnings, this is the default
3134 @item none
3135 turn off all the warnings
3136 @item error
3137 treat warnings as errors
3138 @end table
3140 All warnings are output by default.
3142 @vindex WARNINGS
3143 The environment variable @env{WARNINGS} is honored in the same
3144 way as it is for @command{automake} (@pxref{Invoking Automake}).
3146 @end table
3148 @node Macro search path
3149 @subsection Macro search path
3151 @cindex Macro search path
3152 @cindex @command{aclocal} search path
3154 By default, @command{aclocal} searches for @file{.m4} files in the following
3155 directories, in this order:
3157 @table @code
3158 @item @var{acdir-APIVERSION}
3159 This is where the @file{.m4} macros distributed with automake itself
3160 are stored.  @var{APIVERSION} depends on the automake release used;
3161 for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
3163 @item @var{acdir}
3164 This directory is intended for third party @file{.m4} files, and is
3165 configured when @command{automake} itself is built.  This is
3166 @file{@@datadir@@/aclocal/}, which typically
3167 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3168 value of @var{acdir}, use the @option{--print-ac-dir} option
3169 (@pxref{aclocal options}).
3170 @end table
3172 As an example, suppose that @command{automake-1.6.2} was configured with
3173 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3175 @enumerate
3176 @item @file{/usr/local/share/aclocal-1.6/}
3177 @item @file{/usr/local/share/aclocal/}
3178 @end enumerate
3180 As explained in (@pxref{aclocal options}), there are several options that
3181 can be used to change or extend this search path.
3183 @subsubsection Modifying the macro search path: @option{--acdir}
3185 The most erroneous option to modify the search path is
3186 @option{--acdir=@var{dir}}, which changes default directory and
3187 drops the @var{APIVERSION} directory.  For example, if one specifies
3188 @samp{--acdir=/opt/private/}, then the search path becomes:
3190 @enumerate
3191 @item @file{/opt/private/}
3192 @end enumerate
3194 This option, @option{--acdir}, is intended for use by the internal
3195 automake test suite only; it is not ordinarily needed by end-users.
3197 @subsubsection Modifying the macro search path: @samp{-I @var{dir}}
3199 Any extra directories specified using @option{-I} options
3200 (@pxref{aclocal options}) are @emph{prepended} to this search list.  Thus,
3201 @samp{aclocal -I /foo -I /bar} results in the following search path:
3203 @enumerate
3204 @item @file{/foo}
3205 @item @file{/bar}
3206 @item @var{acdir}-@var{APIVERSION}
3207 @item @var{acdir}
3208 @end enumerate
3210 @subsubsection Modifying the macro search path: @file{dirlist}
3211 @cindex @file{dirlist}
3213 There is a third mechanism for customizing the search path.  If a
3214 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3215 contain a list of directory patterns, one per line.  @command{aclocal}
3216 expands these patterns to directory names, and adds them to the search
3217 list @emph{after} all other directories.  @file{dirlist} entries may
3218 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3220 For example, suppose
3221 @file{@var{acdir}/dirlist} contains the following:
3223 @example
3224 /test1
3225 /test2
3226 /test3*
3227 @end example
3229 @noindent
3230 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3231 Then, the search path would be
3233 @c @code looks better than @file here
3234 @enumerate
3235 @item @code{/foo}
3236 @item @code{/bar}
3237 @item @var{acdir}-@var{APIVERSION}
3238 @item @var{acdir}
3239 @item @code{/test1}
3240 @item @code{/test2}
3241 @end enumerate
3243 @noindent
3244 and all directories with path names starting with @code{/test3}.
3246 If the @option{--acdir=@var{dir}} option is used, then @command{aclocal}
3247 will search for the @file{dirlist} file in @var{dir}.  In the
3248 @samp{--acdir=/opt/private/} example above, @command{aclocal} would look
3249 for @file{/opt/private/dirlist}.  Again, however, the @option{--acdir}
3250 option is intended for use by the internal automake test suite only;
3251 @option{--acdir} is not ordinarily needed by end-users.
3253 @file{dirlist} is useful in the following situation: suppose that
3254 @command{automake} version @code{1.6.2} is installed with
3255 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3256 directories are
3258 @c @code looks better than @file here
3259 @enumerate
3260 @item @code{/usr/share/aclocal-1.6/}
3261 @item @code{/usr/share/aclocal/}
3262 @end enumerate
3264 However, suppose further that many packages have been manually
3265 installed on the system, with $prefix=/usr/local, as is typical.  In
3266 that case, many of these ``extra'' @file{.m4} files are in
3267 @file{/usr/local/share/aclocal}.  The only way to force
3268 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3269 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3270 inconvenient.  With @file{dirlist}, one may create a file
3271 @file{/usr/share/aclocal/dirlist} containing only the single line
3273 @example
3274 /usr/local/share/aclocal
3275 @end example
3277 Now, the ``default'' search path on the affected system is
3279 @c @code looks better than @file here
3280 @enumerate
3281 @item @code{/usr/share/aclocal-1.6/}
3282 @item @code{/usr/share/aclocal/}
3283 @item @code{/usr/local/share/aclocal/}
3284 @end enumerate
3286 without the need for @option{-I} options; @option{-I} options can be reserved
3287 for project-specific needs (@file{my-source-dir/m4/}), rather than
3288 using it to work around local system-dependent tool installation
3289 directories.
3291 Similarly, @file{dirlist} can be handy if you have installed a local
3292 copy of Automake in your account and want @command{aclocal} to look for
3293 macros installed at other places on the system.
3296 @node Extending aclocal
3297 @subsection Writing your own aclocal macros
3299 @cindex @command{aclocal}, extending
3300 @cindex Extending @command{aclocal}
3302 The @command{aclocal} program doesn't have any built-in knowledge of any
3303 macros, so it is easy to extend it with your own macros.
3305 This can be used by libraries that want to supply their own Autoconf
3306 macros for use by other programs.  For instance, the @command{gettext}
3307 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3308 any package using @command{gettext}.  When the library is installed, it
3309 installs this macro so that @command{aclocal} will find it.
3311 A macro file's name should end in @file{.m4}.  Such files should be
3312 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3314 @example
3315 aclocaldir = $(datadir)/aclocal
3316 aclocal_DATA = mymacro.m4 myothermacro.m4
3317 @end example
3319 @noindent
3320 Please do use @file{$(datadir)/aclocal}, and not something based on
3321 the result of @samp{aclocal --print-ac-dir}.  @xref{Hard-Coded Install
3322 Paths}, for arguments.
3324 A file of macros should be a series of properly quoted
3325 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3326 Autoconf Manual}).  The @command{aclocal} programs also understands
3327 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3328 Autoconf Manual}), so it is safe to put each macro in a separate file.
3329 Each file should have no side effects but macro definitions.
3330 Especially, any call to @code{AC_PREREQ} should be done inside the
3331 defined macro, not at the beginning of the file.
3333 @cindex underquoted @code{AC_DEFUN}
3334 @acindex AC_DEFUN
3335 @acindex AC_PREREQ
3337 Starting with Automake 1.8, @command{aclocal} will warn about all
3338 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3339 lot of people, because @command{aclocal} was not so strict in the past
3340 and many third party macros are underquoted; and we have to apologize
3341 for this temporary inconvenience.  The reason we have to be stricter
3342 is that a future implementation of @command{aclocal} (@pxref{Future of
3343 aclocal}) will have to temporarily include all these third party
3344 @file{.m4} files, maybe several times, including even files that are
3345 not actually needed.  Doing so should alleviate many problems of the
3346 current implementation, however it requires a stricter style from the
3347 macro authors.  Hopefully it is easy to revise the existing macros.
3348 For instance,
3349 @example
3350 # bad style
3351 AC_PREREQ(2.57)
3352 AC_DEFUN(AX_FOOBAR,
3353 [AC_REQUIRE([AX_SOMETHING])dnl
3354 AX_FOO
3355 AX_BAR
3357 @end example
3358 @noindent
3359 should be rewritten as
3360 @example
3361 AC_DEFUN([AX_FOOBAR],
3362 [AC_PREREQ([2.57])dnl
3363 AC_REQUIRE([AX_SOMETHING])dnl
3364 AX_FOO
3365 AX_BAR
3367 @end example
3369 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3370 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
3371 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3372 allows the macro to be redefined or included twice (otherwise this
3373 first argument would be expanded during the second definition).  For
3374 consistency we like to quote even arguments such as @code{2.57} that
3375 do not require it.
3377 If you have been directed here by the @command{aclocal} diagnostic but
3378 are not the maintainer of the implicated macro, you will want to
3379 contact the maintainer of that macro.  Please make sure you have the
3380 latest version of the macro and that the problem hasn't already been
3381 reported before doing so: people tend to work faster when they aren't
3382 flooded by mails.
3384 Another situation where @command{aclocal} is commonly used is to
3385 manage macros that are used locally by the package, @ref{Local
3386 Macros}.
3388 @node Local Macros
3389 @subsection Handling Local Macros
3391 Feature tests offered by Autoconf do not cover all needs.  People
3392 often have to supplement existing tests with their own macros, or
3393 with third-party macros.
3395 There are two ways to organize custom macros in a package.
3397 The first possibility (the historical practice) is to list all your
3398 macros in @file{acinclude.m4}.  This file will be included in
3399 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3400 henceforth be visible to @command{autoconf}.  However if it contains
3401 numerous macros, it will rapidly become difficult to maintain, and it
3402 will be almost impossible to share macros between packages.
3404 @vindex ACLOCAL_AMFLAGS
3405 The second possibility, which we do recommend, is to write each macro
3406 in its own file and gather all these files in a directory.  This
3407 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3408 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3409 From the command line, this is done with @samp{aclocal -I m4}.  The
3410 top-level @file{Makefile.am} should also be updated to define
3412 @example
3413 ACLOCAL_AMFLAGS = -I m4
3414 @end example
3416 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3417 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3418 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3419 Using @command{autoreconf} to Update @file{configure} Scripts,
3420 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3421 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3422 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3423 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3424 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3425 the place where Gettext's macros should be installed.  So even if you
3426 do not really care about the rebuild rules, you should define
3427 @code{ACLOCAL_AMFLAGS}.
3429 When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
3430 that @code{m4_include}s any file from @file{m4/} that defines a
3431 required macro.  Macros not found locally will still be searched in
3432 system-wide directories, as explained in @ref{Macro search path}.
3434 Custom macros should be distributed for the same reason that
3435 @file{configure.ac} is: so that other people have all the sources of
3436 your package if they want to work on it.  Actually, this distribution
3437 happens automatically because all @code{m4_include}d files are
3438 distributed.
3440 However there is no consensus on the distribution of third-party
3441 macros that your package may use.  Many libraries install their own
3442 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3443 aclocal}).  For instance, Guile ships with a file called
3444 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3445 be used to define setup compiler and linker flags appropriate for
3446 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3447 cause @command{aclocal} to copy @file{guile.m4} into
3448 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3449 it will not be distributed.  Technically, that means a user who
3450 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3451 This is probably OK, if Guile already is a requirement to build the
3452 package.  However, if Guile is only an optional feature, or if your
3453 package might run on architectures where Guile cannot be installed,
3454 this requirement will hinder development.  An easy solution is to copy
3455 such third-party macros in your local @file{m4/} directory so they get
3456 distributed.
3458 Since Automake 1.10, @command{aclocal} offers an option to copy these
3459 system-wide third-party macros in your local macro directory, solving
3460 the above problem.  Simply use:
3462 @example
3463 ACLOCAL_AMFLAGS = -I m4 --install
3464 @end example
3466 @noindent
3467 With this setup, system-wide macros will be copied to @file{m4/}
3468 the first time you run @command{autoreconf}.  Then the locally
3469 installed macros will have precedence over the system-wide installed
3470 macros each time @command{aclocal} is run again.
3472 One reason why you should keep @option{--install} in the flags even
3473 after the first run is that when you later edit @file{configure.ac}
3474 and depend on a new macro, this macro will be installed in your
3475 @file{m4/} automatically.  Another one is that serial numbers
3476 (@pxref{Serials}) can be used to update the macros in your source tree
3477 automatically when new system-wide versions are installed.  A serial
3478 number should be a single line of the form
3480 @example
3481 #serial @var{NNN}
3482 @end example
3484 @noindent
3485 where @var{NNN} contains only digits and dots.  It should appear in
3486 the M4 file before any macro definition.  It is a good practice to
3487 maintain a serial number for each macro you distribute, even if you do
3488 not use the @option{--install} option of @command{aclocal}: this allows
3489 other people to use it.
3492 @node Serials
3493 @subsection Serial Numbers
3494 @cindex serial numbers in macros
3495 @cindex macro serial numbers
3496 @cindex @code{#serial} syntax
3497 @cindex @command{aclocal} and serial numbers
3499 Because third-party macros defined in @file{*.m4} files are naturally
3500 shared between multiple projects, some people like to version them.
3501 This makes it easier to tell which of two M4 files is newer.  Since at
3502 least 1996, the tradition is to use a @samp{#serial} line for this.
3504 A serial number should be a single line of the form
3506 @example
3507 # serial @var{version}
3508 @end example
3510 @noindent
3511 where @var{version} is a version number containing only digits and
3512 dots.  Usually people use a single integer, and they increment it each
3513 time they change the macro (hence the name of ``serial'').  Such a
3514 line should appear in the M4 file before any macro definition.
3516 The @samp{#} must be the first character on the line,
3517 and it is OK to have extra words after the version, as in
3519 @example
3520 #serial @var{version} @var{garbage}
3521 @end example
3523 Normally these serial numbers are completely ignored by
3524 @command{aclocal} and @command{autoconf}, like any genuine comment.
3525 However when using @command{aclocal}'s @option{--install} feature, these
3526 serial numbers will modify the way @command{aclocal} selects the
3527 macros to install in the package: if two files with the same basename
3528 exist in your search path, and if at least one of them uses a
3529 @samp{#serial} line, @command{aclocal} will ignore the file that has
3530 the older @samp{#serial} line (or the file that has none).
3532 Note that a serial number applies to a whole M4 file, not to any macro
3533 it contains.  A file can contains multiple macros, but only one
3534 serial.
3536 Here is a use case that illustrates the use of @option{--install} and
3537 its interaction with serial numbers.  Let's assume we maintain a
3538 package called MyPackage, the @file{configure.ac} of which requires a
3539 third-party macro @code{AX_THIRD_PARTY} defined in
3540 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3542 @example
3543 # serial 1
3544 AC_DEFUN([AX_THIRD_PARTY], [...])
3545 @end example
3547 MyPackage uses an @file{m4/} directory to store local macros as
3548 explained in @ref{Local Macros}, and has
3550 @example
3551 ACLOCAL_AMFLAGS = -I m4 --install
3552 @end example
3554 @noindent
3555 in its top-level @file{Makefile.am}.
3557 Initially the @file{m4/} directory is empty.  The first time we run
3558 @command{autoreconf}, it will fetch the options to pass to
3559 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3560 --install}.  @command{aclocal} will notice that
3562 @itemize @bullet
3563 @item
3564 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3565 @item
3566 No local macros define @code{AX_THIRD_PARTY}
3567 @item
3568 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3569 with serial 1.
3570 @end itemize
3572 @noindent
3573 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3574 and @command{aclocal} was given the @option{--install} option, it will
3575 copy this file in @file{m4/thirdparty.m4}, and output an
3576 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3578 The next time @samp{aclocal -I m4 --install} is run (either via
3579 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3580 rules) something different happens.  @command{aclocal} notices that
3582 @itemize @bullet
3583 @item
3584 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3585 @item
3586 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3587 with serial 1.
3588 @item
3589 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3590 with serial 1.
3591 @end itemize
3593 @noindent
3594 Because both files have the same serial number, @command{aclocal} uses
3595 the first it found in its search path order (@pxref{Macro search
3596 path}).  @command{aclocal} therefore ignores
3597 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3598 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3600 Local directories specified with @option{-I} are always searched before
3601 system-wide directories, so a local file will always be preferred to
3602 the system-wide file in case of equal serial numbers.
3604 Now suppose the system-wide third-party macro is changed.  This can
3605 happen if the package installing this macro is updated.  Let's suppose
3606 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3607 --install} is run the situation is the following:
3609 @itemize @bullet
3610 @item
3611 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3612 @item
3613 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3614 with serial 1.
3615 @item
3616 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3617 with serial 2.
3618 @end itemize
3620 @noindent
3621 When @command{aclocal} sees a greater serial number, it immediately
3622 forgets anything it knows from files that have the same basename and a
3623 smaller serial number.  So after it has found
3624 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3625 @command{aclocal} will proceed as if it had never seen
3626 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3627 to that at the beginning of our example, where no local file defined
3628 the macro.  @command{aclocal} will install the new version of the
3629 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3630 version.  MyPackage just had its macro updated as a side effect of
3631 running @command{aclocal}.
3633 If you are leery of letting @command{aclocal} update your local macro,
3634 you can run @samp{aclocal -I m4 --diff} to review the changes
3635 @samp{aclocal -I m4 --install} would perform on these macros.
3637 Finally, note that the @option{--force} option of @command{aclocal} has
3638 absolutely no effect on the files installed by @option{--install}.  For
3639 instance, if you have modified your local macros, do not expect
3640 @option{--install --force} to replace the local macros by their
3641 system-wide versions.  If you want to do so, simply erase the local
3642 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3645 @node Future of aclocal
3646 @subsection The Future of @command{aclocal}
3647 @cindex @command{aclocal}'s scheduled death
3649 @command{aclocal} is expected to disappear.  This feature really
3650 should not be offered by Automake.  Automake should focus on
3651 generating @file{Makefile}s; dealing with M4 macros really is
3652 Autoconf's job.  The fact that some people install Automake just to use
3653 @command{aclocal}, but do not use @command{automake} otherwise is an
3654 indication of how that feature is misplaced.
3656 The new implementation will probably be done slightly differently.
3657 For instance, it could enforce the @file{m4/}-style layout discussed in
3658 @ref{Local Macros}.
3660 We have no idea when and how this will happen.  This has been
3661 discussed several times in the past, but someone still has to commit
3662 to that non-trivial task.
3664 From the user point of view, @command{aclocal}'s removal might turn
3665 out to be painful.  There is a simple precaution that you may take to
3666 make that switch more seamless: never call @command{aclocal} yourself.
3667 Keep this guy under the exclusive control of @command{autoreconf} and
3668 Automake's rebuild rules.  Hopefully you won't need to worry about
3669 things breaking, when @command{aclocal} disappears, because everything
3670 will have been taken care of.  If otherwise you used to call
3671 @command{aclocal} directly yourself or from some script, you will
3672 quickly notice the change.
3674 Many packages come with a script called @file{bootstrap.sh} or
3675 @file{autogen.sh}, that will just call @command{aclocal},
3676 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3677 @command{autoconf}, @command{autoheader}, and @command{automake} in
3678 the right order.  Actually this is precisely what @command{autoreconf}
3679 can do for you.  If your package has such a @file{bootstrap.sh} or
3680 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3681 should simplify its logic a lot (less things to maintain, yum!), it's
3682 even likely you will not need the script anymore, and more to the point
3683 you will not call @command{aclocal} directly anymore.
3685 For the time being, third-party packages should continue to install
3686 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3687 is replaced by another tool it might make sense to rename the
3688 directory, but supporting @file{/usr/share/aclocal/} for backward
3689 compatibility should be really easy provided all macros are properly
3690 written (@pxref{Extending aclocal}).
3694 @node Macros
3695 @section Autoconf macros supplied with Automake
3697 Automake ships with several Autoconf macros that you can use from your
3698 @file{configure.ac}.  When you use one of them it will be included by
3699 @command{aclocal} in @file{aclocal.m4}.
3701 @menu
3702 * Public macros::               Macros that you can use.
3703 * Obsolete macros::             Macros that you should stop using.
3704 * Private macros::              Macros that you should not use.
3705 @end menu
3707 @c consider generating the following subsections automatically from m4 files.
3709 @node Public macros
3710 @subsection Public macros
3712 @table @code
3714 @item AM_ENABLE_MULTILIB
3715 @acindex AM_ENABLE_MULTILIB
3716 This is used when a ``multilib'' library is being built.  The first
3717 optional argument is the name of the @file{Makefile} being generated; it
3718 defaults to @samp{Makefile}.  The second optional argument is used to find
3719 the top source directory; it defaults to the empty string (generally
3720 this should not be used unless you are familiar with the internals).
3721 @xref{Multilibs}.
3723 @item AM_INIT_AUTOMAKE([OPTIONS])
3724 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
3725 @acindex AM_INIT_AUTOMAKE
3726 Runs many macros required for proper operation of the generated Makefiles.
3728 @vindex AUTOMAKE_OPTIONS
3729 This macro has two forms, the first of which is preferred.
3730 In this form, @code{AM_INIT_AUTOMAKE} is called with a
3731 single argument: a space-separated list of Automake options that should
3732 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3733 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3735 @acindex AC_INIT
3736 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
3737 arguments: the package and the version number.  This form is
3738 obsolete because the @var{package} and @var{version} can be obtained
3739 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
3740 form).
3742 If your @file{configure.ac} has:
3744 @example
3745 AC_INIT([src/foo.c])
3746 AM_INIT_AUTOMAKE([mumble], [1.5])
3747 @end example
3749 @noindent
3750 you can modernize it as follows:
3752 @example
3753 AC_INIT([mumble], [1.5])
3754 AC_CONFIG_SRCDIR([src/foo.c])
3755 AM_INIT_AUTOMAKE
3756 @end example
3758 Note that if you're upgrading your @file{configure.ac} from an earlier
3759 version of Automake, it is not always correct to simply move the
3760 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3761 @code{AC_INIT}, as in the example above.  The first argument to
3762 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3763 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3764 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3765 tarball name from the package name, which should work for most but not
3766 all package names.  (If it doesn't work for yours, you can use the
3767 four-argument form of @code{AC_INIT} to provide the tarball name
3768 explicitly).
3770 @cindex @code{PACKAGE}, prevent definition
3771 @cindex @code{VERSION}, prevent definition
3772 @opindex no-define
3773 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3774 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3775 option, as in:
3776 @example
3777 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3778 @end example
3779 or by passing a third non-empty argument to the obsolete form.
3781 @item AM_PATH_LISPDIR
3782 @acindex AM_PATH_LISPDIR
3783 @vindex EMACS
3784 @vindex lispdir
3785 Searches for the program @command{emacs}, and, if found, sets the
3786 output variable @code{lispdir} to the full path to Emacs' site-lisp
3787 directory.
3789 Note that this test assumes the @command{emacs} found to be a version
3790 that supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other
3791 emacsen can cause this test to hang (some, like old versions of
3792 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3793 exit, which is hardly obvious for a non-emacs user).  In most cases,
3794 however, you should be able to use @kbd{C-c} to kill the test.  In
3795 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3796 environment, or use the @option{--with-lispdir} option to
3797 @command{configure} to explicitly set the correct path (if you're sure
3798 you have an @command{emacs} that supports Emacs Lisp).
3800 @item AM_PROG_AS
3801 @acindex AM_PROG_AS
3802 @vindex CCAS
3803 @vindex CCASFLAGS
3804 Use this macro when you have assembly code in your project.  This will
3805 choose the assembler for you (by default the C compiler) and set
3806 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
3808 @item AM_PROG_CC_C_O
3809 @acindex AM_PROG_CC_C_O
3810 @acindex AC_PROG_CC_C_O
3811 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
3812 the manner required by automake.  You must use this instead of
3813 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
3814 using per-target flags or subdir-objects with C sources.
3816 @item AM_PROG_LEX
3817 @acindex AM_PROG_LEX
3818 @acindex AC_PROG_LEX
3819 @cindex HP-UX 10, @command{lex} problems
3820 @cindex @command{lex} problems with HP-UX 10
3821 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
3822 Program Checks, autoconf, The Autoconf Manual}), but uses the
3823 @command{missing} script on systems that do not have @command{lex}.
3824 HP-UX 10 is one such system.
3826 @item AM_PROG_GCJ
3827 @acindex AM_PROG_GCJ
3828 @vindex GCJ
3829 @vindex GCJFLAGS
3830 This macro finds the @command{gcj} program or causes an error.  It sets
3831 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
3832 GNU Compiler Collection.
3834 @item AM_PROG_UPC([@var{compiler-search-list}])
3835 @acindex AM_PROG_UPC
3836 @vindex UPC
3837 Find a compiler for Unified Parallel C and define the @code{UPC}
3838 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
3839 This macro will abort @command{configure} if no Unified Parallel C
3840 compiler is found.
3842 @item AM_WITH_DMALLOC
3843 @acindex AM_WITH_DMALLOC
3844 @cindex @command{dmalloc}, support for
3845 @vindex WITH_DMALLOC
3846 @opindex --with-dmalloc
3847 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
3848 the user runs @command{configure} with @option{--with-dmalloc}, then
3849 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
3851 @item AM_WITH_REGEX
3852 @acindex AM_WITH_REGEX
3853 @vindex WITH_REGEX
3854 @opindex --with-regex
3855 @cindex regex package
3856 @cindex rx package
3857 Adds @option{--with-regex} to the @command{configure} command line.  If
3858 specified (the default), then the @samp{regex} regular expression
3859 library is used, @file{regex.o} is put into @code{LIBOBJS}, and
3860 @code{WITH_REGEX} is defined.  If @option{--without-regex} is given, then
3861 the @code{rx} regular expression library is used, and @file{rx.o} is put
3862 into @code{LIBOBJS}.
3864 @end table
3867 @node Obsolete macros
3868 @subsection Obsolete macros
3869 @cindex obsolete macros
3870 @cindex autoupdate
3872 Although using some of the following macros was required in past
3873 releases, you should not use any of them in new code.  Running
3874 @command{autoupdate} should adjust your @file{configure.ac}
3875 automatically (@pxref{autoupdate Invocation, , Using
3876 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
3877 Autoconf Manual}).
3879 @table @code
3880 @item AM_C_PROTOTYPES
3881 @acindex AM_C_PROTOTYPES
3882 @vindex ANSI2KNR
3883 @vindex U
3884 Check to see if function prototypes are understood by the compiler.  If
3885 so, define @samp{PROTOTYPES} and set the output variables @code{U} and
3886 @code{ANSI2KNR} to the empty string.  Otherwise, set @code{U} to
3887 @samp{_} and @code{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
3888 values to implement the obsolete de-ANSI-fication feature.
3890 @item AM_CONFIG_HEADER
3891 @acindex AM_CONFIG_HEADER
3892 Automake will generate rules to automatically regenerate the config
3893 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
3894 today (@pxref{Optional}).
3896 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3897 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3898 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
3899 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
3900 found in @file{<termios.h>}.  This macro is obsolete, you should
3901 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
3903 @item AM_PROG_MKDIR_P
3904 @acindex AM_PROG_MKDIR_P
3905 @cindex @code{mkdir -p}, macro check
3906 @vindex MKDIR_P
3907 @vindex mkdir_p
3909 From Automake 1.8 to 1.9.6 this macro used to define the output
3910 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
3911 -d}, or @code{mkinstalldirs}.
3913 Nowadays Autoconf provides a similar functionality with
3914 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
3915 Program Checks, autoconf, The Autoconf Manual}), however this defines
3916 the output variable @code{MKDIR_P} instead.  Therefore
3917 @code{AM_PROG_MKDIR_P} has been rewritten as a thin wrapper around
3918 @code{AC_PROG_MKDIR_P} to define @code{mkdir_p} to the same value as
3919 @code{MKDIR_P} for backward compatibility.
3921 If you are using Automake, there is normally no reason to call this
3922 macro, because @code{AM_INIT_AUTOMAKE} already does so.  However, make
3923 sure that the custom rules in your @file{Makefile}s use
3924 @code{$(MKDIR_P)} and not @code{$(mkdir_p)}.  Even if both variables
3925 still work, the latter should be considered obsolete.
3927 If you are not using Automake, please call @code{AC_PROG_MKDIR_P}
3928 instead of @code{AM_PROG_MKDIR_P}.
3930 @item AM_SYS_POSIX_TERMIOS
3931 @acindex AM_SYS_POSIX_TERMIOS
3932 @cindex POSIX termios headers
3933 @cindex termios POSIX headers
3934 Check to see if POSIX termios headers and functions are available on the
3935 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
3936 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
3937 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
3939 @end table
3942 @node Private macros
3943 @subsection Private macros
3945 The following macros are private macros you should not call directly.
3946 They are called by the other public macros when appropriate.  Do not
3947 rely on them, as they might be changed in a future version.  Consider
3948 them as implementation details; or better, do not consider them at all:
3949 skip this section!
3951 @ftable @code
3952 @item _AM_DEPENDENCIES
3953 @itemx AM_SET_DEPDIR
3954 @itemx AM_DEP_TRACK
3955 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
3956 These macros are used to implement Automake's automatic dependency
3957 tracking scheme.  They are called automatically by automake when
3958 required, and there should be no need to invoke them manually.
3960 @item AM_MAKE_INCLUDE
3961 This macro is used to discover how the user's @command{make} handles
3962 @code{include} statements.  This macro is automatically invoked when
3963 needed; there should be no need to invoke it manually.
3965 @item AM_PROG_INSTALL_STRIP
3966 This is used to find a version of @code{install} that can be used to
3967 strip a program at installation time.  This macro is automatically
3968 included when required.
3970 @item AM_SANITY_CHECK
3971 This checks to make sure that a file created in the build directory is
3972 newer than a file in the source directory.  This can fail on systems
3973 where the clock is set incorrectly.  This macro is automatically run
3974 from @code{AM_INIT_AUTOMAKE}.
3976 @end ftable
3979 @node Directories
3980 @chapter Directories
3982 For simple projects that distribute all files in the same directory
3983 it is enough to have a single @file{Makefile.am} that builds
3984 everything in place.
3986 In larger projects it is common to organize files in different
3987 directories, in a tree.  For instance one directory per program, per
3988 library or per module.  The traditional approach is to build these
3989 subdirectories recursively: each directory contains its @file{Makefile}
3990 (generated from @file{Makefile.am}), and when @command{make} is run
3991 from the top level directory it enters each subdirectory in turn to
3992 build its contents.
3994 @menu
3995 * Subdirectories::              Building subdirectories recursively
3996 * Conditional Subdirectories::  Conditionally not building directories
3997 * Alternative::                 Subdirectories without recursion
3998 * Subpackages::                 Nesting packages
3999 @end menu
4001 @node Subdirectories
4002 @section Recursing subdirectories
4004 @cindex @code{SUBDIRS}, explained
4006 In packages with subdirectories, the top level @file{Makefile.am} must
4007 tell Automake which subdirectories are to be built.  This is done via
4008 the @code{SUBDIRS} variable.
4009 @vindex SUBDIRS
4011 The @code{SUBDIRS} variable holds a list of subdirectories in which
4012 building of various sorts can occur.  The rules for many targets
4013 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4014 both locally and in all specified subdirectories.  Note that the
4015 directories listed in @code{SUBDIRS} are not required to contain
4016 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4017 This allows inclusion of libraries from packages that do not use
4018 Automake (such as @code{gettext}; see also @ref{Third-Party
4019 Makefiles}).
4021 In packages that use subdirectories, the top-level @file{Makefile.am} is
4022 often very short.  For instance, here is the @file{Makefile.am} from the
4023 GNU Hello distribution:
4025 @example
4026 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4027 SUBDIRS = doc intl po src tests
4028 @end example
4030 When Automake invokes @command{make} in a subdirectory, it uses the value
4031 of the @code{MAKE} variable.  It passes the value of the variable
4032 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4033 @file{Makefile.am} if there are flags you must always pass to
4034 @command{make}.
4035 @vindex MAKE
4036 @vindex AM_MAKEFLAGS
4038 The directories mentioned in @code{SUBDIRS} are usually direct
4039 children of the current directory, each subdirectory containing its
4040 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4041 subdirectories.  Automake can be used to construct packages of
4042 arbitrary depth this way.
4044 By default, Automake generates @file{Makefiles} that work depth-first
4045 in postfix order: the subdirectories are built before the current
4046 directory.  However, it is possible to change this ordering.  You can
4047 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4048 putting @samp{.} first will cause a prefix ordering of
4049 directories.
4051 Using
4053 @example
4054 SUBDIRS = lib src . test
4055 @end example
4057 @noindent
4058 will cause @file{lib/} to be built before @file{src/}, then the
4059 current directory will be built, finally the @file{test/} directory
4060 will be built.  It is customary to arrange test directories to be
4061 built after everything else since they are meant to test what has
4062 been constructed.
4064 All @code{clean} rules are run in reverse order of build rules.
4066 @node Conditional Subdirectories
4067 @section Conditional Subdirectories
4068 @cindex Subdirectories, building conditionally
4069 @cindex Conditional subdirectories
4070 @cindex @code{SUBDIRS}, conditional
4071 @cindex Conditional @code{SUBDIRS}
4073 It is possible to define the @code{SUBDIRS} variable conditionally if,
4074 like in the case of GNU Inetutils, you want to only build a subset of
4075 the entire package.
4077 To illustrate how this works, let's assume we have two directories
4078 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4079 want to decide in @command{configure} whether @file{opt/} will be built
4080 or not.  (For this example we will assume that @file{opt/} should be
4081 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4083 Running @command{make} should thus recurse into @file{src/} always, and
4084 then maybe in @file{opt/}.
4086 However @samp{make dist} should always recurse into both @file{src/}
4087 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4088 is not needed in the current configuration.  This means
4089 @file{opt/Makefile} should be created @emph{unconditionally}.
4091 There are two ways to setup a project like this.  You can use Automake
4092 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4093 variables (@pxref{Setting Output Variables, , Setting Output
4094 Variables, autoconf, The Autoconf Manual}).  Using Automake
4095 conditionals is the preferred solution.  Before we illustrate these
4096 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4098 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4099 @cindex @code{DIST_SUBDIRS}, explained
4101 Automake considers two sets of directories, defined by the variables
4102 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4104 @code{SUBDIRS} contains the subdirectories of the current directory
4105 that must be built (@pxref{Subdirectories}).  It must be defined
4106 manually; Automake will never guess a directory is to be built.  As we
4107 will see in the next two sections, it is possible to define it
4108 conditionally so that some directory will be omitted from the build.
4110 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4111 directories, even those that have been conditionally left out of the
4112 build.  Recall our example where we may not want to build subdirectory
4113 @file{opt/}, but yet we want to distribute it?  This is where
4114 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4115 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4117 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4118 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4119 other recursive rules use @code{SUBDIRS}.
4121 If @code{SUBDIRS} is defined conditionally using Automake
4122 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4123 from the possible values of @code{SUBDIRS} in all conditions.
4125 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4126 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4127 does not know the possible values of these variables.  In this case
4128 @code{DIST_SUBDIRS} needs to be defined manually.
4130 @subsection Conditional subdirectories with @code{AM_CONDITIONAL}
4131 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4132 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4134 @c The test case for the setup described here is
4135 @c     test/subdircond2.test
4136 @c Try to keep it in sync.
4138 @file{configure} should output the @file{Makefile} for each directory
4139 and define a condition into which @file{opt/} should be built.
4141 @example
4142 @dots{}
4143 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4144 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4145 @dots{}
4146 @end example
4148 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4149 as follows.
4151 @example
4152 if COND_OPT
4153   MAYBE_OPT = opt
4154 endif
4155 SUBDIRS = src $(MAYBE_OPT)
4156 @end example
4158 As you can see, running @command{make} will rightly recurse into
4159 @file{src/} and maybe @file{opt/}.
4161 @vindex DIST_SUBDIRS
4162 As you can't see, running @samp{make dist} will recurse into both
4163 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4164 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4165 @code{DIST_SUBDIRS} variable.
4167 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4168 automatically because it knows that @code{MAYBE_OPT} can contain
4169 @samp{opt} in some condition.
4171 @subsection Conditional Subdirectories with @code{AC_SUBST}
4172 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4173 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4175 @c The test case for the setup described here is
4176 @c     test/subdircond3.test
4177 @c Try to keep it in sync.
4179 Another possibility is to define @code{MAYBE_OPT} from
4180 @file{./configure} using @code{AC_SUBST}:
4182 @example
4183 @dots{}
4184 if test "$want_opt" = yes; then
4185   MAYBE_OPT=opt
4186 else
4187   MAYBE_OPT=
4189 AC_SUBST([MAYBE_OPT])
4190 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4191 @dots{}
4192 @end example
4194 In this case the top-level @file{Makefile.am} should look as follows.
4196 @example
4197 SUBDIRS = src $(MAYBE_OPT)
4198 DIST_SUBDIRS = src opt
4199 @end example
4201 The drawback is that since Automake cannot guess what the possible
4202 values of @code{MAYBE_OPT} are, it is necessary to define
4203 @code{DIST_SUBDIRS}.
4205 @subsection Non-configured Subdirectories
4206 @cindex Subdirectories, configured conditionally
4208 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4209 users that try to @emph{configure and build} subdirectories
4210 conditionally.  Here by configuring we mean creating the
4211 @file{Makefile} (it might also involve running a nested
4212 @command{configure} script: this is a costly operation that explains
4213 why people want to do it conditionally, but only the @file{Makefile}
4214 is relevant to the discussion).
4216 The above examples all assume that every @file{Makefile} is created,
4217 even in directories that are not going to be built.  The simple reason
4218 is that we want @samp{make dist} to distribute even the directories
4219 that are not being built (e.g., platform-dependent code), hence
4220 @file{make dist} must recurse into the subdirectory, hence this
4221 directory must be configured and appear in @code{DIST_SUBDIRS}.
4223 Building packages that do not configure every subdirectory is a tricky
4224 business, and we do not recommend it to the novice as it is easy to
4225 produce an incomplete tarball by mistake.  We will not discuss this
4226 topic in depth here, yet for the adventurous here are a few rules to
4227 remember.
4229 @cartouche
4230 @itemize
4231 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4233 It makes little sense to have a directory in @code{SUBDIRS} that
4234 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4235 which directories listed in the latter should be built.
4236 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4237 must be configured.
4239 I.e., the @file{Makefile} must exists or the recursive @command{make}
4240 rules will not be able to process the directory.
4241 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4243 So that the cleaning rules remove the generated @file{Makefile}s.
4244 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4245 lists all the directories that have been configured.
4246 @end itemize
4247 @end cartouche
4249 In order to prevent recursion in some non-configured directory you
4250 must therefore ensure that this directory does not appear in
4251 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4252 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4253 @code{DIST_SUBDIRS} explicitly, it will be default to
4254 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4255 = $(SUBDIRS)}.
4257 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4258 not be distributed unless you make other arrangements for this to
4259 happen (for instance, always running @samp{make dist} in a
4260 configuration where all directories are known to appear in
4261 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4262 distribute these directories).
4264 @cindex Subdirectories, not distributed
4265 In few packages, non-configured directories are not even expected to
4266 be distributed.  Although these packages do not require the
4267 aforementioned extra arrangements, there is another pitfall.  If the
4268 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4269 @command{automake} will make sure the directory exists.  Consequently
4270 @command{automake} cannot be run on such a distribution when one
4271 directory has been omitted.  One way to avoid this check is to use the
4272 @code{AC_SUBST} method to declare conditional directories; since
4273 @command{automake} does not know the values of @code{AC_SUBST}
4274 variables it cannot ensure the corresponding directory exists.
4276 @node Alternative
4277 @section An Alternative Approach to Subdirectories
4279 If you've ever read Peter Miller's excellent paper,
4280 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
4281 Recursive Make Considered Harmful}, the preceding sections on the use of
4282 subdirectories will probably come as unwelcome advice.  For those who
4283 haven't read the paper, Miller's main thesis is that recursive
4284 @command{make} invocations are both slow and error-prone.
4286 Automake provides sufficient cross-directory support @footnote{We
4287 believe.  This work is new and there are probably warts.
4288 @xref{Introduction}, for information on reporting bugs.} to enable you
4289 to write a single @file{Makefile.am} for a complex multi-directory
4290 package.
4293 By default an installable file specified in a subdirectory will have its
4294 directory name stripped before installation.  For instance, in this
4295 example, the header file will be installed as
4296 @file{$(includedir)/stdio.h}:
4298 @example
4299 include_HEADERS = inc/stdio.h
4300 @end example
4302 @vindex nobase_
4303 @cindex @code{nobase_} prefix
4304 @cindex Path stripping, avoiding
4305 @cindex Avoiding path stripping
4307 However, the @samp{nobase_} prefix can be used to circumvent this path
4308 stripping.  In this example, the header file will be installed as
4309 @file{$(includedir)/sys/types.h}:
4311 @example
4312 nobase_include_HEADERS = sys/types.h
4313 @end example
4315 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4316 @cindex @code{dist_} and @code{nobase_}
4317 @cindex @code{nodist_} and @code{nobase_}
4318 @vindex dist_
4319 @vindex nodist_
4321 @samp{nobase_} should be specified first when used in conjunction with
4322 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
4324 @example
4325 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4326 @end example
4328 Finally, note that a variable using the @samp{nobase_} prefix can
4329 often be replaced by several variables, one for each destination
4330 directory (@pxref{Uniform}).  For instance, the last example could be
4331 rewritten as follows:
4333 @example
4334 imagesdir = $(pkgdatadir)/images
4335 soundsdir = $(pkgdatadir)/sounds
4336 dist_images_DATA = images/vortex.pgm
4337 dist_sounds_DATA = sounds/whirl.ogg
4338 @end example
4340 @noindent
4341 This latter syntax makes it possible to change one destination
4342 directory without changing the layout of the source tree.
4344 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4345 rule, in that there is no particular installation order guarantee for
4346 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4348 @node Subpackages
4349 @section Nesting Packages
4350 @cindex Nesting packages
4351 @cindex Subpackages
4352 @acindex AC_CONFIG_SUBDIRS
4353 @acindex AC_CONFIG_AUX_DIR
4356 In the GNU Build System, packages can be nested to arbitrary depth.
4357 This means that a package can embed other packages with their own
4358 @file{configure}, @file{Makefile}s, etc.
4360 These other packages should just appear as subdirectories of their
4361 parent package.  They must be listed in @code{SUBDIRS} like other
4362 ordinary directories.  However the subpackage's @file{Makefile}s
4363 should be output by its own @file{configure} script, not by the
4364 parent's @file{configure}.  This is achieved using the
4365 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4366 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4367 autoconf, The Autoconf Manual}).
4369 Here is an example package for an @code{arm} program that links with
4370 an @code{hand} library that is a nested package in subdirectory
4371 @file{hand/}.
4373 @code{arm}'s @file{configure.ac}:
4375 @example
4376 AC_INIT([arm], [1.0])
4377 AC_CONFIG_AUX_DIR([.])
4378 AM_INIT_AUTOMAKE
4379 AC_PROG_CC
4380 AC_CONFIG_FILES([Makefile])
4381 # Call hand's ./configure script recursively.
4382 AC_CONFIG_SUBDIRS([hand])
4383 AC_OUTPUT
4384 @end example
4386 @code{arm}'s @file{Makefile.am}:
4388 @example
4389 # Build the library in the hand subdirectory first.
4390 SUBDIRS = hand
4392 # Include hand's header when compiling this directory.
4393 AM_CPPFLAGS = -I$(srcdir)/hand
4395 bin_PROGRAMS = arm
4396 arm_SOURCES = arm.c
4397 # link with the hand library.
4398 arm_LDADD = hand/libhand.a
4399 @end example
4401 Now here is @code{hand}'s @file{hand/configure.ac}:
4403 @example
4404 AC_INIT([hand], [1.2])
4405 AC_CONFIG_AUX_DIR([.])
4406 AM_INIT_AUTOMAKE
4407 AC_PROG_CC
4408 AC_PROG_RANLIB
4409 AC_CONFIG_FILES([Makefile])
4410 AC_OUTPUT
4411 @end example
4413 @noindent
4414 and its @file{hand/Makefile.am}:
4416 @example
4417 lib_LIBRARIES = libhand.a
4418 libhand_a_SOURCES = hand.c
4419 @end example
4421 When @samp{make dist} is run from the top-level directory it will
4422 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4423 code as well as the @file{hand} subdirectory.  This package can be
4424 built and installed like any ordinary package, with the usual
4425 @samp{./configure && make && make install} sequence (the @code{hand}
4426 subpackage will be built and installed by the process).
4428 When @samp{make dist} is run from the hand directory, it will create a
4429 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4430 to be embedded in another package, it can still be used separately.
4432 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4433 force Automake and Autoconf to search for auxiliary scripts in the
4434 current directory.  For instance, this means that there will be two
4435 copies of @file{install-sh}: one in the top-level of the @code{arm}
4436 package, and another one in the @file{hand/} subdirectory for the
4437 @code{hand} package.
4439 The historical default is to search for these auxiliary scripts in
4440 the parent directory and the grandparent directory.  So if the
4441 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4442 @file{hand/configure.ac}, that subpackage would share the auxiliary
4443 script of the @code{arm} package.  This may looks like a gain in size
4444 (a few kilobytes), but it is actually a loss of modularity as the
4445 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4446 in the subdirectory will not work anymore).
4448 Packages that do not use Automake need more work to be integrated this
4449 way.  @xref{Third-Party Makefiles}.
4451 @node Programs
4452 @chapter Building Programs and Libraries
4454 A large part of Automake's functionality is dedicated to making it easy
4455 to build programs and libraries.
4457 @menu
4458 * A Program::                   Building a program
4459 * A Library::                   Building a library
4460 * A Shared Library::            Building a Libtool library
4461 * Program and Library Variables::  Variables controlling program and
4462                                 library builds
4463 * Default _SOURCES::            Default source files
4464 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4465 * Program variables::           Variables used when building a program
4466 * Yacc and Lex::                Yacc and Lex support
4467 * C++ Support::                 Compiling C++ sources
4468 * Objective C Support::         Compiling Objective C sources
4469 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4470 * Assembly Support::            Compiling assembly sources
4471 * Fortran 77 Support::          Compiling Fortran 77 sources
4472 * Fortran 9x Support::          Compiling Fortran 9x sources
4473 * Java Support::                Compiling Java sources
4474 * Support for Other Languages::  Compiling other languages
4475 * ANSI::                        Automatic de-ANSI-fication (obsolete)
4476 * Dependencies::                Automatic dependency tracking
4477 * EXEEXT::                      Support for executable extensions
4478 @end menu
4481 @node A Program
4482 @section Building a program
4484 In order to build a program, you need to tell Automake which sources
4485 are part of it, and which libraries it should be linked with.
4487 This section also covers conditional compilation of sources or
4488 programs.  Most of the comments about these also apply to libraries
4489 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4491 @menu
4492 * Program Sources::             Defining program sources
4493 * Linking::                     Linking with libraries or extra objects
4494 * Conditional Sources::         Handling conditional sources
4495 * Conditional Programs::        Building a program conditionally
4496 @end menu
4498 @node Program Sources
4499 @subsection Defining program sources
4501 @cindex @code{PROGRAMS}, @code{bindir}
4502 @vindex _PROGRAMS
4503 @vindex bin_PROGRAMS
4504 @vindex sbin_PROGRAMS
4505 @vindex libexec_PROGRAMS
4506 @vindex pkglib_PROGRAMS
4507 @vindex noinst_PROGRAMS
4508 @vindex check_PROGRAMS
4510 In a directory containing source that gets built into a program (as
4511 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4512 Programs can be installed in @code{bindir}, @code{sbindir},
4513 @code{libexecdir}, @code{pkglibdir}, @code{pkglibexecdir}, or not at all
4514 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4515 which case the prefix is @samp{check_}.
4517 For instance:
4519 @example
4520 bin_PROGRAMS = hello
4521 @end example
4523 In this simple case, the resulting @file{Makefile.in} will contain code
4524 to generate a program named @code{hello}.
4526 Associated with each program are several assisting variables that are
4527 named after the program.  These variables are all optional, and have
4528 reasonable defaults.  Each variable, its use, and default is spelled out
4529 below; we use the ``hello'' example throughout.
4531 The variable @code{hello_SOURCES} is used to specify which source files
4532 get built into an executable:
4534 @example
4535 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4536 @end example
4538 This causes each mentioned @file{.c} file to be compiled into the
4539 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4541 @cindex @code{_SOURCES} primary, defined
4542 @cindex @code{SOURCES} primary, defined
4543 @cindex Primary variable, @code{SOURCES}
4544 @vindex _SOURCES
4546 If @code{hello_SOURCES} is not specified, then it defaults to the single
4547 file @file{hello.c} (@pxref{Default _SOURCES}).
4548 @vindex _SOURCES
4549 @vindex SOURCES
4551 Multiple programs can be built in a single directory.  Multiple programs
4552 can share a single source file, which must be listed in each
4553 @code{_SOURCES} definition.
4555 @cindex Header files in @code{_SOURCES}
4556 @cindex @code{_SOURCES} and header files
4558 Header files listed in a @code{_SOURCES} definition will be included in
4559 the distribution but otherwise ignored.  In case it isn't obvious, you
4560 should not include the header file generated by @file{configure} in a
4561 @code{_SOURCES} variable; this file should not be distributed.  Lex
4562 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4563 and Lex}.
4566 @node Linking
4567 @subsection Linking the program
4569 If you need to link against libraries that are not found by
4570 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4571 used to specify additional objects or libraries to link with; it is
4572 inappropriate for specifying specific linker flags, you should use
4573 @code{AM_LDFLAGS} for this purpose.
4574 @vindex LDADD
4575 @vindex AM_LDFLAGS
4577 @cindex @code{prog_LDADD}, defined
4579 Sometimes, multiple programs are built in one directory but do not share
4580 the same link-time requirements.  In this case, you can use the
4581 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4582 program as it appears in some @code{_PROGRAMS} variable, and usually
4583 written in lowercase) to override @code{LDADD}.  If this variable exists
4584 for a given program, then that program is not linked using @code{LDADD}.
4585 @vindex maude_LDADD
4587 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4588 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4589 built in the same directory, and has no such link requirement.  Also,
4590 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4591 is what cpio's @file{src/Makefile.am} looks like (abridged):
4593 @example
4594 bin_PROGRAMS = cpio pax $(MT)
4595 libexec_PROGRAMS = $(RMT)
4596 EXTRA_PROGRAMS = mt rmt
4598 LDADD = ../lib/libcpio.a $(INTLLIBS)
4599 rmt_LDADD =
4601 cpio_SOURCES = @dots{}
4602 pax_SOURCES = @dots{}
4603 mt_SOURCES = @dots{}
4604 rmt_SOURCES = @dots{}
4605 @end example
4607 @cindex @code{_LDFLAGS}, defined
4608 @vindex maude_LDFLAGS
4609 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4610 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4611 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4612 this purpose.
4614 @cindex @code{_DEPENDENCIES}, defined
4615 @vindex maude_DEPENDENCIES
4616 It is also occasionally useful to have a program depend on some other
4617 target that is not actually part of that program.  This can be done
4618 using the @code{@var{prog}_DEPENDENCIES} variable.  Each program
4619 depends on the contents of such a variable, but no further
4620 interpretation is done.
4622 Since these dependencies are associated to the link rule used to
4623 create the programs they should normally list files used by the link
4624 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4625 files.  In rare cases you may need to add other kinds of files such as
4626 linker scripts, but @emph{listing a source file in
4627 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4628 before all the components of a program are built, consider using the
4629 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4631 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4632 Automake.  The automatically-assigned value is the contents of
4633 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4634 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4635 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4636 @samp{$(ALLOCA)}; these are left because it is known that they will not
4637 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4638 generated.
4640 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4641 may be used.
4643 @cindex @code{LDADD} and @option{-l}
4644 @cindex @option{-l} and @code{LDADD}
4645 We recommend that you avoid using @option{-l} options in @code{LDADD}
4646 or @code{@var{prog}_LDADD} when referring to libraries built by your
4647 package.  Instead, write the file name of the library explicitly as in
4648 the above @code{cpio} example.  Use @option{-l} only to list
4649 third-party libraries.  If you follow this rule, the default value of
4650 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4651 omit the other ones.
4654 @node Conditional Sources
4655 @subsection Conditional compilation of sources
4657 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4658 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4659 @code{_SOURCES} variable.  The reason for this is a bit hard to
4660 explain, but suffice to say that it simply won't work.  Automake will
4661 give an error if you try to do this.
4663 Fortunately there are two other ways to achieve the same result.  One is
4664 to use configure substitutions in @code{_LDADD} variables, the other is
4665 to use an Automake conditional.
4667 @subsubsection Conditional compilation using @code{_LDADD} substitutions
4669 @cindex @code{EXTRA_prog_SOURCES}, defined
4671 Automake must know all the source files that could possibly go into a
4672 program, even if not all the files are built in every circumstance.  Any
4673 files that are only conditionally built should be listed in the
4674 appropriate @code{EXTRA_} variable.  For instance, if
4675 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4676 in @code{hello}, the @file{Makefile.am} would contain:
4678 @example
4679 bin_PROGRAMS = hello
4680 hello_SOURCES = hello-common.c
4681 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4682 hello_LDADD = $(HELLO_SYSTEM)
4683 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4684 @end example
4686 @noindent
4687 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4688 @file{configure.ac}:
4690 @example
4691 @dots{}
4692 case $host in
4693   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4694   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4695 esac
4696 AC_SUBST([HELLO_SYSTEM])
4697 @dots{}
4698 @end example
4700 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4701 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4702 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4703 built and linked in.
4705 @subsubsection Conditional compilation using Automake conditionals
4707 An often simpler way to compile source files conditionally is to use
4708 Automake conditionals.  For instance, you could use this
4709 @file{Makefile.am} construct to build the same @file{hello} example:
4711 @example
4712 bin_PROGRAMS = hello
4713 if LINUX
4714 hello_SOURCES = hello-linux.c hello-common.c
4715 else
4716 hello_SOURCES = hello-generic.c hello-common.c
4717 endif
4718 @end example
4720 In this case, @file{configure.ac} should setup the @code{LINUX}
4721 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4723 When using conditionals like this you don't need to use the
4724 @code{EXTRA_} variable, because Automake will examine the contents of
4725 each variable to construct the complete list of source files.
4727 If your program uses a lot of files, you will probably prefer a
4728 conditional @samp{+=}.
4730 @example
4731 bin_PROGRAMS = hello
4732 hello_SOURCES = hello-common.c
4733 if LINUX
4734 hello_SOURCES += hello-linux.c
4735 else
4736 hello_SOURCES += hello-generic.c
4737 endif
4738 @end example
4740 @node Conditional Programs
4741 @subsection Conditional compilation of programs
4742 @cindex Conditional programs
4743 @cindex Programs, conditional
4745 Sometimes it is useful to determine the programs that are to be built
4746 at configure time.  For instance, GNU @code{cpio} only builds
4747 @code{mt} and @code{rmt} under special circumstances.  The means to
4748 achieve conditional compilation of programs are the same you can use
4749 to compile source files conditionally: substitutions or conditionals.
4751 @subsubsection Conditional programs using @command{configure} substitutions
4753 @vindex EXTRA_PROGRAMS
4754 @cindex @code{EXTRA_PROGRAMS}, defined
4755 In this case, you must notify Automake of all the programs that can
4756 possibly be built, but at the same time cause the generated
4757 @file{Makefile.in} to use the programs specified by @command{configure}.
4758 This is done by having @command{configure} substitute values into each
4759 @code{_PROGRAMS} definition, while listing all optionally built programs
4760 in @code{EXTRA_PROGRAMS}.
4762 @example
4763 bin_PROGRAMS = cpio pax $(MT)
4764 libexec_PROGRAMS = $(RMT)
4765 EXTRA_PROGRAMS = mt rmt
4766 @end example
4768 As explained in @ref{EXEEXT}, Automake will rewrite
4769 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4770 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4771 Obviously it cannot rewrite values obtained at run-time through
4772 @command{configure} substitutions, therefore you should take care of
4773 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4774 ['mt$@{EXEEXT@}'])}.
4776 @subsubsection Conditional programs using Automake conditionals
4778 You can also use Automake conditionals (@pxref{Conditionals}) to
4779 select programs to be built.  In this case you don't have to worry
4780 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4782 @example
4783 bin_PROGRAMS = cpio pax
4784 if WANT_MT
4785   bin_PROGRAMS += mt
4786 endif
4787 if WANT_RMT
4788   libexec_PROGRAMS = rmt
4789 endif
4790 @end example
4793 @node A Library
4794 @section Building a library
4796 @cindex @code{_LIBRARIES} primary, defined
4797 @cindex @code{LIBRARIES} primary, defined
4798 @cindex Primary variable, @code{LIBRARIES}
4799 @vindex _LIBRARIES
4801 @vindex lib_LIBRARIES
4802 @vindex pkglib_LIBRARIES
4803 @vindex noinst_LIBRARIES
4805 Building a library is much like building a program.  In this case, the
4806 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
4807 @code{libdir} or @code{pkglibdir}.
4809 @xref{A Shared Library}, for information on how to build shared
4810 libraries using libtool and the @code{LTLIBRARIES} primary.
4812 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
4813 For instance, to create a library named @file{libcpio.a}, but not install
4814 it, you would write:
4816 @example
4817 noinst_LIBRARIES = libcpio.a
4818 libcpio_a_SOURCES = @dots{}
4819 @end example
4821 The sources that go into a library are determined exactly as they are
4822 for programs, via the @code{_SOURCES} variables.  Note that the library
4823 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
4824 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
4825 not @samp{libcpio.a_SOURCES}.
4827 @vindex maude_LIBADD
4828 Extra objects can be added to a library using the
4829 @code{@var{library}_LIBADD} variable.  This should be used for objects
4830 determined by @command{configure}.  Again from @code{cpio}:
4832 @example
4833 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4834 @end example
4836 In addition, sources for extra objects that will not exist until
4837 configure-time must be added to the @code{BUILT_SOURCES} variable
4838 (@pxref{Sources}).
4840 Building a static library is done by compiling all object files, then
4841 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
4842 library and the list of objects, and finally by calling
4843 @samp{$(RANLIB)} on that library.  You should call
4844 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
4845 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
4846 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
4847 can override these two variables my setting them in your
4848 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
4849 @file{configure.ac}, or by defining a per-library @code{maude_AR}
4850 variable (@pxref{Program and Library Variables}).
4852 @cindex Empty libraries
4853 Be careful when selecting library components conditionally.  Because
4854 building an empty library is not portable, you should ensure that any
4855 library always contains at least one object.
4857 To use a static library when building a program, add it to
4858 @code{LDADD} for this program.  In the following example, the program
4859 @file{cpio} is statically linked with the library @file{libcpio.a}.
4861 @example
4862 noinst_LIBRARIES = libcpio.a
4863 libcpio_a_SOURCES = @dots{}
4865 bin_PROGRAMS = cpio
4866 cpio_SOURCES = cpio.c @dots{}
4867 cpio_LDADD = libcpio.a
4868 @end example
4871 @node A Shared Library
4872 @section Building a Shared Library
4874 @cindex Shared libraries, support for
4876 Building shared libraries portably is a relatively complex matter.
4877 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
4878 Libtool Manual}) was created to help build shared libraries in a
4879 platform-independent way.
4881 @menu
4882 * Libtool Concept::             Introducing Libtool
4883 * Libtool Libraries::           Declaring Libtool Libraries
4884 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
4885 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
4886 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
4887 * Libtool Modules::             Building Libtool Modules
4888 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
4889 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
4890 * Libtool Issues::              Common Issues Related to Libtool's Use
4891 @end menu
4893 @node Libtool Concept
4894 @subsection The Libtool Concept
4896 @cindex @command{libtool}, introduction
4897 @cindex libtool library, definition
4898 @cindex suffix @file{.la}, defined
4899 @cindex @file{.la} suffix, defined
4901 Libtool abstracts shared and static libraries into a unified concept
4902 henceforth called @dfn{libtool libraries}.  Libtool libraries are
4903 files using the @file{.la} suffix, and can designate a static library,
4904 a shared library, or maybe both.  Their exact nature cannot be
4905 determined until @file{./configure} is run: not all platforms support
4906 all kinds of libraries, and users can explicitly select which
4907 libraries should be built.  (However the package's maintainers can
4908 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
4909 macro, libtool, The Libtool Manual}.)
4911 @cindex suffix @file{.lo}, defined
4912 Because object files for shared and static libraries must be compiled
4913 differently, libtool is also used during compilation.  Object files
4914 built by libtool are called @dfn{libtool objects}: these are files
4915 using the @file{.lo} suffix.  Libtool libraries are built from these
4916 libtool objects.
4918 You should not assume anything about the structure of @file{.la} or
4919 @file{.lo} files and how libtool constructs them: this is libtool's
4920 concern, and the last thing one wants is to learn about libtool's
4921 guts.  However the existence of these files matters, because they are
4922 used as targets and dependencies in @file{Makefile}s rules when
4923 building libtool libraries.  There are situations where you may have
4924 to refer to these, for instance when expressing dependencies for
4925 building source files conditionally (@pxref{Conditional Libtool
4926 Sources}).
4928 @cindex @file{libltdl}, introduction
4930 People considering writing a plug-in system, with dynamically loaded
4931 modules, should look into @file{libltdl}: libtool's dlopening library
4932 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
4933 This offers a portable dlopening facility to load libtool libraries
4934 dynamically, and can also achieve static linking where unavoidable.
4936 Before we discuss how to use libtool with Automake in details, it
4937 should be noted that the libtool manual also has a section about how
4938 to use Automake with libtool (@pxref{Using Automake, , Using Automake
4939 with Libtool, libtool, The Libtool Manual}).
4941 @node Libtool Libraries
4942 @subsection Building Libtool Libraries
4944 @cindex @code{_LTLIBRARIES} primary, defined
4945 @cindex @code{LTLIBRARIES} primary, defined
4946 @cindex Primary variable, @code{LTLIBRARIES}
4947 @cindex Example of shared libraries
4948 @vindex lib_LTLIBRARIES
4949 @vindex pkglib_LTLIBRARIES
4950 @vindex _LTLIBRARIES
4952 Automake uses libtool to build libraries declared with the
4953 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
4954 list of libtool libraries to build.  For instance, to create a libtool
4955 library named @file{libgettext.la}, and install it in @code{libdir},
4956 write:
4958 @example
4959 lib_LTLIBRARIES = libgettext.la
4960 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
4961 @end example
4963 Automake predefines the variable @code{pkglibdir}, so you can use
4964 @code{pkglib_LTLIBRARIES} to install libraries in
4965 @samp{$(libdir)/@@PACKAGE@@/}.
4967 If @file{gettext.h} is a public header file that needs to be installed
4968 in order for people to use the library, it should be declared using a
4969 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
4970 Headers listed in the latter should be internal headers that are not
4971 part of the public interface.
4973 @example
4974 lib_LTLIBRARIES = libgettext.la
4975 libgettext_la_SOURCES = gettext.c @dots{}
4976 include_HEADERS = gettext.h @dots{}
4977 @end example
4979 A package can build and install such a library along with other
4980 programs that use it.  This dependency should be specified using
4981 @code{LDADD}.  The following example builds a program named
4982 @file{hello} that is linked with @file{libgettext.la}.
4984 @example
4985 lib_LTLIBRARIES = libgettext.la
4986 libgettext_la_SOURCES = gettext.c @dots{}
4988 bin_PROGRAMS = hello
4989 hello_SOURCES = hello.c @dots{}
4990 hello_LDADD = libgettext.la
4991 @end example
4993 @noindent
4994 Whether @file{hello} is statically or dynamically linked with
4995 @file{libgettext.la} is not yet known: this will depend on the
4996 configuration of libtool and the capabilities of the host.
4999 @node Conditional Libtool Libraries
5000 @subsection Building Libtool Libraries Conditionally
5001 @cindex libtool libraries, conditional
5002 @cindex conditional libtool libraries
5004 Like conditional programs (@pxref{Conditional Programs}), there are
5005 two main ways to build conditional libraries: using Automake
5006 conditionals or using Autoconf @code{AC_SUBST}itutions.
5008 The important implementation detail you have to be aware of is that
5009 the place where a library will be installed matters to libtool: it
5010 needs to be indicated @emph{at link-time} using the @option{-rpath}
5011 option.
5013 For libraries whose destination directory is known when Automake runs,
5014 Automake will automatically supply the appropriate @option{-rpath}
5015 option to libtool.  This is the case for libraries listed explicitly in
5016 some installable @code{_LTLIBRARIES} variables such as
5017 @code{lib_LTLIBRARIES}.
5019 However, for libraries determined at configure time (and thus
5020 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5021 final installation directory.  For such libraries you must add the
5022 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5023 hand.
5025 The examples below illustrate the differences between these two methods.
5027 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5028 variable set at @file{./configure}-time to either @file{libfoo.la},
5029 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5030 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5031 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5032 the link rule for these two libraries.  Therefore the @option{-rpath}
5033 argument must be explicitly supplied.
5035 @example
5036 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5037 lib_LTLIBRARIES = $(WANTEDLIBS)
5038 libfoo_la_SOURCES = foo.c @dots{}
5039 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5040 libbar_la_SOURCES = bar.c @dots{}
5041 libbar_la_LDFLAGS = -rpath '$(libdir)'
5042 @end example
5044 Here is how the same @file{Makefile.am} would look using Automake
5045 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5046 Automake is able to compute the @option{-rpath} setting itself, because
5047 it's clear that both libraries will end up in @samp{$(libdir)} if they
5048 are installed.
5050 @example
5051 lib_LTLIBRARIES =
5052 if WANT_LIBFOO
5053 lib_LTLIBRARIES += libfoo.la
5054 endif
5055 if WANT_LIBBAR
5056 lib_LTLIBRARIES += libbar.la
5057 endif
5058 libfoo_la_SOURCES = foo.c @dots{}
5059 libbar_la_SOURCES = bar.c @dots{}
5060 @end example
5062 @node Conditional Libtool Sources
5063 @subsection Libtool Libraries with Conditional Sources
5065 Conditional compilation of sources in a library can be achieved in the
5066 same way as conditional compilation of sources in a program
5067 (@pxref{Conditional Sources}).  The only difference is that
5068 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5069 should mention libtool objects (@file{.lo} files).
5071 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5072 we could build a @file{libhello.la} library using either
5073 @file{hello-linux.c} or @file{hello-generic.c} with the following
5074 @file{Makefile.am}.
5076 @example
5077 lib_LTLIBRARIES = libhello.la
5078 libhello_la_SOURCES = hello-common.c
5079 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5080 libhello_la_LIBADD = $(HELLO_SYSTEM)
5081 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5082 @end example
5084 @noindent
5085 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5086 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5088 Or we could simply use an Automake conditional as follows.
5090 @example
5091 lib_LTLIBRARIES = libhello.la
5092 libhello_la_SOURCES = hello-common.c
5093 if LINUX
5094 libhello_la_SOURCES += hello-linux.c
5095 else
5096 libhello_la_SOURCES += hello-generic.c
5097 endif
5098 @end example
5100 @node Libtool Convenience Libraries
5101 @subsection Libtool Convenience Libraries
5102 @cindex convenience libraries, libtool
5103 @cindex libtool convenience libraries
5104 @vindex noinst_LTLIBRARIES
5105 @vindex check_LTLIBRARIES
5107 Sometimes you want to build libtool libraries that should not be
5108 installed.  These are called @dfn{libtool convenience libraries} and
5109 are typically used to encapsulate many sublibraries, later gathered
5110 into one big installed library.
5112 Libtool convenience libraries are declared by directory-less variables
5113 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5114 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5115 not need an @option{-rpath} flag at link time (actually this is the only
5116 difference).
5118 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5119 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5120 @samp{make check}.  Finally, libraries listed in
5121 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5122 rules to build them, but if the library does not appear as a Makefile
5123 dependency anywhere it won't be built (this is why
5124 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5126 Here is a sample setup merging libtool convenience libraries from
5127 subdirectories into one main @file{libtop.la} library.
5129 @example
5130 # -- Top-level Makefile.am --
5131 SUBDIRS = sub1 sub2 @dots{}
5132 lib_LTLIBRARIES = libtop.la
5133 libtop_la_SOURCES =
5134 libtop_la_LIBADD = \
5135   sub1/libsub1.la \
5136   sub2/libsub2.la \
5137   @dots{}
5139 # -- sub1/Makefile.am --
5140 noinst_LTLIBRARIES = libsub1.la
5141 libsub1_la_SOURCES = @dots{}
5143 # -- sub2/Makefile.am --
5144 # showing nested convenience libraries
5145 SUBDIRS = sub2.1 sub2.2 @dots{}
5146 noinst_LTLIBRARIES = libsub2.la
5147 libsub2_la_SOURCES =
5148 libsub2_la_LIBADD = \
5149   sub21/libsub21.la \
5150   sub22/libsub22.la \
5151   @dots{}
5152 @end example
5154 When using such setup, beware that @command{automake} will assume
5155 @file{libtop.la} is to be linked with the C linker.  This is because
5156 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5157 default language.  If @code{libtop_la_SOURCES} was not empty,
5158 @command{automake} would select the linker as explained in @ref{How
5159 the Linker is Chosen}.
5161 If one of the sublibraries contains non-C source, it is important that
5162 the appropriate linker be chosen.  One way to achieve this is to
5163 pretend that there is such a non-C file among the sources of the
5164 library, thus forcing @command{automake} to select the appropriate
5165 linker.  Here is the top-level @file{Makefile} of our example updated
5166 to force C++ linking.
5168 @example
5169 SUBDIRS = sub1 sub2 @dots{}
5170 lib_LTLIBRARIES = libtop.la
5171 libtop_la_SOURCES =
5172 # Dummy C++ source to cause C++ linking.
5173 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5174 libtop_la_LIBADD = \
5175   sub1/libsub1.la \
5176   sub2/libsub2.la \
5177   @dots{}
5178 @end example
5180 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5181 files that might be compiled (this is mostly useful when doing
5182 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5183 Libtool Sources}), and the @code{nodist_} prefix means the listed
5184 sources are not to be distributed (@pxref{Program and Library
5185 Variables}).  In effect the file @file{dummy.cxx} does not need to
5186 exist in the source tree.  Of course if you have some real source file
5187 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5188 @code{nodist_EXTRA_libtop_la_SOURCES}.
5191 @node Libtool Modules
5192 @subsection Libtool Modules
5193 @cindex modules, libtool
5194 @cindex libtool modules
5195 @cindex @option{-module}, libtool
5197 These are libtool libraries meant to be dlopened.  They are
5198 indicated to libtool by passing @option{-module} at link-time.
5200 @example
5201 pkglib_LTLIBRARIES = mymodule.la
5202 mymodule_la_SOURCES = doit.c
5203 mymodule_la_LDFLAGS = -module
5204 @end example
5206 Ordinarily, Automake requires that a library's name start with
5207 @code{lib}.  However, when building a dynamically loadable module you
5208 might wish to use a "nonstandard" name.  Automake will not complain
5209 about such nonstandard names if it knows the library being built is a
5210 libtool module, i.e., if @option{-module} explicitly appears in the
5211 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5212 variable when no per-library @code{_LDFLAGS} variable is defined).
5214 As always, @code{AC_SUBST} variables are black boxes to Automake since
5215 their values are not yet known when @command{automake} is run.
5216 Therefore if @option{-module} is set via such a variable, Automake
5217 cannot notice it and will proceed as if the library was an ordinary
5218 libtool library, with strict naming.
5220 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5221 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5223 @node Libtool Flags
5224 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5225 @cindex @code{_LIBADD}, libtool
5226 @cindex @code{_LDFLAGS}, libtool
5227 @cindex @code{_LIBTOOLFLAGS}, libtool
5228 @vindex AM_LIBTOOLFLAGS
5229 @vindex LIBTOOLFLAGS
5230 @vindex maude_LIBTOOLFLAGS
5232 As shown in previous sections, the @samp{@var{library}_LIBADD}
5233 variable should be used to list extra libtool objects (@file{.lo}
5234 files) or libtool libraries (@file{.la}) to add to @var{library}.
5236 The @samp{@var{library}_LDFLAGS} variable is the place to list
5237 additional libtool linking flags, such as @option{-version-info},
5238 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5239 libtool, The Libtool Manual}.
5241 The @command{libtool} command has two kinds of options: mode-specific
5242 options and generic options.  Mode-specific options such as the
5243 aforementioned linking flags should be lumped with the other flags
5244 passed to the tool invoked by @command{libtool} (hence the use of
5245 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5246 options include @option{--tag=@var{TAG}} and @option{--silent}
5247 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5248 Libtool Manual} for more options) should appear before the mode
5249 selection on the command line; in @file{Makefile.am}s they should
5250 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5252 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5253 @code{AM_LIBTOOLFLAGS} is used instead.
5255 These flags are passed to libtool after the @option{--tag=@var{TAG}}
5256 option computed by Automake (if any), so
5257 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5258 good place to override or supplement the @option{--tag=@var{TAG}}
5259 setting.
5261 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5262 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5263 Variables Ordering}.  It allows users to run @samp{make
5264 LIBTOOLFLAGS=--silent}, for instance.
5267 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5268 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5269 @cindex @code{LTLIBOBJS}, special handling
5270 @cindex @code{LIBOBJS}, and Libtool
5271 @cindex @code{LTALLOCA}, special handling
5272 @cindex @code{ALLOCA}, and Libtool
5273 @vindex LTLIBOBJS
5274 @vindex LIBOBJS
5275 @vindex LTALLOCA
5276 @vindex ALLOCA
5277 @acindex AC_LIBOBJ
5279 Where an ordinary library might include @samp{$(LIBOBJS)} or
5280 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5281 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5282 the object files that libtool operates on do not necessarily end in
5283 @file{.o}.
5285 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5286 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5287 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5289 @node Libtool Issues
5290 @subsection Common Issues Related to Libtool's Use
5292 @subsubsection @samp{required file `./ltmain.sh' not found}
5293 @cindex @file{ltmain.sh} not found
5294 @cindex @command{libtoolize}, no longer run by @command{automake}
5295 @cindex @command{libtoolize} and @command{autoreconf}
5296 @cindex @command{autoreconf} and @command{libtoolize}
5297 @cindex @file{bootstrap.sh} and @command{autoreconf}
5298 @cindex @file{autogen.sh} and @command{autoreconf}
5300 Libtool comes with a tool called @command{libtoolize} that will
5301 install libtool's supporting files into a package.  Running this
5302 command will install @file{ltmain.sh}.  You should execute it before
5303 @command{aclocal} and @command{automake}.
5305 People upgrading old packages to newer autotools are likely to face
5306 this issue because older Automake versions used to call
5307 @command{libtoolize}.  Therefore old build scripts do not call
5308 @command{libtoolize}.
5310 Since Automake 1.6, it has been decided that running
5311 @command{libtoolize} was none of Automake's business.  Instead, that
5312 functionality has been moved into the @command{autoreconf} command
5313 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5314 The Autoconf Manual}).  If you do not want to remember what to run and
5315 when, just learn the @command{autoreconf} command.  Hopefully,
5316 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5317 a call to @command{autoreconf} should also free you from any similar
5318 incompatible change in the future.
5320 @subsubsection Objects @samp{created with both libtool and without}
5322 Sometimes, the same source file is used both to build a libtool
5323 library and to build another non-libtool target (be it a program or
5324 another library).
5326 Let's consider the following @file{Makefile.am}.
5328 @example
5329 bin_PROGRAMS = prog
5330 prog_SOURCES = prog.c foo.c @dots{}
5332 lib_LTLIBRARIES = libfoo.la
5333 libfoo_la_SOURCES = foo.c @dots{}
5334 @end example
5336 @noindent
5337 (In this trivial case the issue could be avoided by linking
5338 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5339 @code{prog_SOURCES}.  But let's assume we really want to keep
5340 @file{prog} and @file{libfoo.la} separate.)
5342 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5343 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5344 that in the course of creating @file{foo.lo}, libtool may erase (or
5345 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5347 Therefore, when Automake detects this situation it will complain
5348 with a message such as
5349 @example
5350 object `foo.$(OBJEXT)' created both with libtool and without
5351 @end example
5353 A workaround for this issue is to ensure that these two objects get
5354 different basenames.  As explained in @ref{renamed objects}, this
5355 happens automatically when per-targets flags are used.
5357 @example
5358 bin_PROGRAMS = prog
5359 prog_SOURCES = prog.c foo.c @dots{}
5360 prog_CFLAGS = $(AM_CFLAGS)
5362 lib_LTLIBRARIES = libfoo.la
5363 libfoo_la_SOURCES = foo.c @dots{}
5364 @end example
5366 @noindent
5367 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5368 when the @code{prog_CFLAGS} is defined, it is used instead of
5369 @code{AM_CFLAGS}.  However as a side effect it will cause
5370 @file{prog.c} and @file{foo.c} to be compiled as
5371 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5372 the issue.
5374 @node Program and Library Variables
5375 @section Program and Library Variables
5377 Associated with each program is a collection of variables that can be
5378 used to modify how that program is built.  There is a similar list of
5379 such variables for each library.  The canonical name of the program (or
5380 library) is used as a base for naming these variables.
5382 In the list below, we use the name ``maude'' to refer to the program or
5383 library.  In your @file{Makefile.am} you would replace this with the
5384 canonical name of your program.  This list also refers to ``maude'' as a
5385 program, but in general the same rules apply for both static and dynamic
5386 libraries; the documentation below notes situations where programs and
5387 libraries differ.
5389 @vtable @code
5390 @item maude_SOURCES
5391 This variable, if it exists, lists all the source files that are
5392 compiled to build the program.  These files are added to the
5393 distribution by default.  When building the program, Automake will cause
5394 each source file to be compiled to a single @file{.o} file (or
5395 @file{.lo} when using libtool).  Normally these object files are named
5396 after the source file, but other factors can change this.  If a file in
5397 the @code{_SOURCES} variable has an unrecognized extension, Automake
5398 will do one of two things with it.  If a suffix rule exists for turning
5399 files with the unrecognized extension into @file{.o} files, then
5400 automake will treat this file as it will any other source file
5401 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5402 ignored as though it were a header file.
5404 The prefixes @code{dist_} and @code{nodist_} can be used to control
5405 whether files listed in a @code{_SOURCES} variable are distributed.
5406 @code{dist_} is redundant, as sources are distributed by default, but it
5407 can be specified for clarity if desired.
5409 It is possible to have both @code{dist_} and @code{nodist_} variants of
5410 a given @code{_SOURCES} variable at once; this lets you easily
5411 distribute some files and not others, for instance:
5413 @example
5414 nodist_maude_SOURCES = nodist.c
5415 dist_maude_SOURCES = dist-me.c
5416 @end example
5418 By default the output file (on Unix systems, the @file{.o} file) will
5419 be put into the current build directory.  However, if the option
5420 @option{subdir-objects} is in effect in the current directory then the
5421 @file{.o} file will be put into the subdirectory named after the
5422 source file.  For instance, with @option{subdir-objects} enabled,
5423 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5424 people prefer this mode of operation.  You can specify
5425 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5426 @cindex Subdirectory, objects in
5427 @cindex Objects in subdirectory
5430 @item EXTRA_maude_SOURCES
5431 Automake needs to know the list of files you intend to compile
5432 @emph{statically}.  For one thing, this is the only way Automake has of
5433 knowing what sort of language support a given @file{Makefile.in}
5434 requires.  @footnote{There are other, more obscure reasons for
5435 this limitation as well.}  This means that, for example, you can't put a
5436 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5437 variable.  If you intend to conditionally compile source files and use
5438 @file{configure} to substitute the appropriate object names into, e.g.,
5439 @code{_LDADD} (see below), then you should list the corresponding source
5440 files in the @code{EXTRA_} variable.
5442 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5443 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5444 sources that may need to be built, but should not be distributed.
5446 @item maude_AR
5447 A static library is created by default by invoking @samp{$(AR)
5448 $(ARFLAGS)} followed by the name of the library and then the objects
5449 being put into the library.  You can override this by setting the
5450 @code{_AR} variable.  This is usually used with C++; some C++
5451 compilers require a special invocation in order to instantiate all the
5452 templates that should go into a library.  For instance, the SGI C++
5453 compiler likes this variable set like so:
5454 @example
5455 libmaude_a_AR = $(CXX) -ar -o
5456 @end example
5458 @item maude_LIBADD
5459 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5460 variable.  For instance, this should be used for objects determined by
5461 @command{configure} (@pxref{A Library}).
5463 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5464 to other libtool libraries.
5466 @item maude_LDADD
5467 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5468 @file{*.la}) can be added to a @emph{program} by listing them in the
5469 @code{_LDADD} variable.  For instance, this should be used for objects
5470 determined by @command{configure} (@pxref{Linking}).
5472 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5473 program-specific linker flags (except for @option{-l}, @option{-L},
5474 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5475 for this purpose.
5477 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5478 could link your program against the X libraries like so:
5480 @example
5481 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5482 @end example
5484 We recommend that you use @option{-l} and @option{-L} only when
5485 referring to third-party libraries, and give the explicit file names
5486 of any library built by your package.  Doing so will ensure that
5487 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5489 @item maude_LDFLAGS
5490 This variable is used to pass extra flags to the link step of a program
5491 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5493 @item maude_LIBTOOLFLAGS
5494 This variable is used to pass extra options to @command{libtool}.
5495 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5496 These options are output before @command{libtool}'s @option{--mode=@var{MODE}}
5497 option, so they should not be mode-specific options (those belong to
5498 the compiler or linker flags).  @xref{Libtool Flags}.
5500 @item maude_DEPENDENCIES
5501 It is also occasionally useful to have a target (program or library)
5502 depend on some other file that is not actually part of that target.
5503 This can be done using the @code{_DEPENDENCIES} variable.  Each
5504 target depends on the contents of such a variable, but no further
5505 interpretation is done.
5507 Since these dependencies are associated to the link rule used to
5508 create the programs they should normally list files used by the link
5509 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5510 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5511 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5512 may need to add other kinds of files such as linker scripts, but
5513 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5514 some source file needs to be built before all the components of a
5515 program are built, consider using the @code{BUILT_SOURCES} variable
5516 (@pxref{Sources}).
5518 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5519 The automatically-assigned value is the contents of @code{_LDADD} or
5520 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5521 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5522 substitutions that are left in are only @samp{$(LIBOBJS)} and
5523 @samp{$(ALLOCA)}; these are left because it is known that they will not
5524 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5526 @code{_DEPENDENCIES} is more likely used to perform conditional
5527 compilation using an @code{AC_SUBST} variable that contains a list of
5528 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5529 Sources}.
5531 @item maude_LINK
5532 You can override the linker on a per-program basis.  By default the
5533 linker is chosen according to the languages used by the program.  For
5534 instance, a program that includes C++ source code would use the C++
5535 compiler to link.  The @code{_LINK} variable must hold the name of a
5536 command that can be passed all the @file{.o} file names as arguments.
5537 Note that the name of the underlying program is @emph{not} passed to
5538 @code{_LINK}; typically one uses @samp{$@@}:
5540 @example
5541 maude_LINK = $(CCLD) -magic -o $@@
5542 @end example
5544 @item maude_CCASFLAGS
5545 @itemx maude_CFLAGS
5546 @itemx maude_CPPFLAGS
5547 @itemx maude_CXXFLAGS
5548 @itemx maude_FFLAGS
5549 @itemx maude_GCJFLAGS
5550 @itemx maude_LFLAGS
5551 @itemx maude_OBJCFLAGS
5552 @itemx maude_RFLAGS
5553 @itemx maude_UPCFLAGS
5554 @itemx maude_YFLAGS
5555 @cindex per-target compilation flags, defined
5556 Automake allows you to set compilation flags on a per-program (or
5557 per-library) basis.  A single source file can be included in several
5558 programs, and it will potentially be compiled with different flags for
5559 each program.  This works for any language directly supported by
5560 Automake.  These @dfn{per-target compilation flags} are
5561 @samp{_CCASFLAGS},
5562 @samp{_CFLAGS},
5563 @samp{_CPPFLAGS},
5564 @samp{_CXXFLAGS},
5565 @samp{_FFLAGS},
5566 @samp{_GCJFLAGS},
5567 @samp{_LFLAGS},
5568 @samp{_OBJCFLAGS},
5569 @samp{_RFLAGS},
5570 @samp{_UPCFLAGS}, and
5571 @samp{_YFLAGS}.
5573 When using a per-target compilation flag, Automake will choose a
5574 different name for the intermediate object files.  Ordinarily a file
5575 like @file{sample.c} will be compiled to produce @file{sample.o}.
5576 However, if the program's @code{_CFLAGS} variable is set, then the
5577 object file will be named, for instance, @file{maude-sample.o}.  (See
5578 also @ref{renamed objects}.)  The use of per-target compilation flags
5579 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5580 from @file{configure.ac}.
5582 In compilations with per-target flags, the ordinary @samp{AM_} form of
5583 the flags variable is @emph{not} automatically included in the
5584 compilation (however, the user form of the variable @emph{is} included).
5585 So for instance, if you want the hypothetical @file{maude} compilations
5586 to also use the value of @code{AM_CFLAGS}, you would need to write:
5588 @example
5589 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5590 @end example
5592 @xref{Flag Variables Ordering}, for more discussion about the
5593 interaction between user variables, @samp{AM_} shadow variables, and
5594 per-target variables.
5596 @item maude_SHORTNAME
5597 On some platforms the allowable file names are very short.  In order to
5598 support these systems and per-target compilation flags at the same
5599 time, Automake allows you to set a ``short name'' that will influence
5600 how intermediate object files are named.  For instance, in the following
5601 example,
5603 @example
5604 bin_PROGRAMS = maude
5605 maude_CPPFLAGS = -DSOMEFLAG
5606 maude_SHORTNAME = m
5607 maude_SOURCES = sample.c @dots{}
5608 @end example
5610 @noindent
5611 the object file would be named @file{m-sample.o} rather than
5612 @file{maude-sample.o}.
5614 This facility is rarely needed in practice,
5615 and we recommend avoiding it until you find it is required.
5616 @end vtable
5618 @node Default _SOURCES
5619 @section Default @code{_SOURCES}
5621 @vindex _SOURCES
5622 @vindex SOURCES
5623 @cindex @code{_SOURCES}, default
5624 @cindex default @code{_SOURCES}
5625 @vindex AM_DEFAULT_SOURCE_EXT
5627 @code{_SOURCES} variables are used to specify source files of programs
5628 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5629 libraries (@pxref{A Shared Library}).
5631 When no such variable is specified for a target, Automake will define
5632 one itself.  The default is to compile a single C file whose base name
5633 is the name of the target itself, with any extension replaced by
5634 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5636 For example if you have the following somewhere in your
5637 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5639 @example
5640 lib_LIBRARIES = libfoo.a sub/libc++.a
5641 @end example
5643 @noindent
5644 @file{libfoo.a} will be built using a default source file named
5645 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5646 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5647 would be built from @file{sub_libc___a.c}, i.e., the default source
5648 was the canonized name of the target, with @file{.c} appended.
5649 We believe the new behavior is more sensible, but for backward
5650 compatibility automake will use the old name if a file or a rule
5651 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5653 @cindex @code{check_PROGRAMS} example
5654 @vindex check_PROGRAMS
5655 Default sources are mainly useful in test suites, when building many
5656 test programs each from a single source.  For instance, in
5658 @example
5659 check_PROGRAMS = test1 test2 test3
5660 AM_DEFAULT_SOURCE_EXT = .cpp
5661 @end example
5663 @noindent
5664 @file{test1}, @file{test2}, and @file{test3} will be built
5665 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5666 Without the last line, they will be built from @file{test1.c},
5667 @file{test2.c}, and @file{test3.c}.
5669 @cindex Libtool modules, default source example
5670 @cindex default source, Libtool modules example
5671 Another case where this is convenient is building many Libtool modules
5672 (@file{module@var{N}.la}), each defined in its own file
5673 (@file{module@var{N}.c}).
5675 @example
5676 AM_LDFLAGS = -module
5677 lib_LTLIBRARIES = module1.la module2.la module3.la
5678 @end example
5680 @cindex empty @code{_SOURCES}
5681 @cindex @code{_SOURCES}, empty
5682 Finally, there is one situation where this default source computation
5683 needs to be avoided: when a target should not be built from sources.
5684 We already saw such an example in @ref{true}; this happens when all
5685 the constituents of a target have already been compiled and just need
5686 to be combined using a @code{_LDADD} variable.  Then it is necessary
5687 to define an empty @code{_SOURCES} variable, so that automake does not
5688 compute a default.
5690 @example
5691 bin_PROGRAMS = target
5692 target_SOURCES =
5693 target_LDADD = libmain.a libmisc.a
5694 @end example
5696 @node LIBOBJS
5697 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5699 @cindex @code{LIBOBJS}, example
5700 @cindex @code{ALLOCA}, example
5701 @cindex @code{LIBOBJS}, special handling
5702 @cindex @code{ALLOCA}, special handling
5703 @vindex LTLIBOBJS
5704 @vindex LIBOBJS
5705 @vindex LTALLOCA
5706 @vindex ALLOCA
5708 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5709 files that should be compiled into the project to provide an
5710 implementation for functions that are missing or broken on the host
5711 system.  They are substituted by @file{configure}.
5713 @acindex AC_LIBOBJ
5715 These variables are defined by Autoconf macros such as
5716 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5717 Generic Function Checks, autoconf, The Autoconf Manual}), or
5718 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5719 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5720 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5721 populate @samp{$(LIBOBJS)}.
5723 @acindex AC_LIBSOURCE
5725 Using these variables is very similar to doing conditional compilation
5726 using @code{AC_SUBST} variables, as described in @ref{Conditional
5727 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5728 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5729 variable, or to the @samp{*_LIBADD} variable when building a library.
5730 However there is no need to list the corresponding sources in
5731 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5732 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5733 dependencies, and it will discover the list of corresponding source
5734 files automatically (by tracing the invocations of the
5735 @code{AC_LIBSOURCE} Autoconf macros).  However, if you have already
5736 defined @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then
5737 you have to add these variables manually.
5739 These variables are usually used to build a portability library that
5740 is linked with all the programs of the project.  We now review a
5741 sample setup.  First, @file{configure.ac} contains some checks that
5742 affect either @code{LIBOBJS} or @code{ALLOCA}.
5744 @example
5745 # configure.ac
5746 @dots{}
5747 AC_CONFIG_LIBOBJ_DIR([lib])
5748 @dots{}
5749 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5750 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5751 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5752 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5753 @dots{}
5754 AC_CONFIG_FILES([
5755   lib/Makefile
5756   src/Makefile
5758 AC_OUTPUT
5759 @end example
5761 @acindex AC_CONFIG_LIBOBJ_DIR
5763 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
5764 of these object files are to be found in the @file{lib/} directory.
5765 Automake can also use this information, otherwise it expects the
5766 source files are to be in the directory where the @samp{$(LIBOBJS)}
5767 and @samp{$(ALLOCA)} variables are used.
5769 The @file{lib/} directory should therefore contain @file{malloc.c},
5770 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
5771 @file{Makefile.am}:
5773 @example
5774 # lib/Makefile.am
5776 noinst_LIBRARIES = libcompat.a
5777 libcompat_a_SOURCES =
5778 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5779 @end example
5781 The library can have any name, of course, and anyway it is not going
5782 to be installed: it just holds the replacement versions of the missing
5783 or broken functions so we can later link them in.  Many projects
5784 also include extra functions, specific to the project, in that
5785 library: they are simply added on the @code{_SOURCES} line.
5787 @cindex Empty libraries and @samp{$(LIBOBJS)}
5788 @cindex @samp{$(LIBOBJS)} and empty libraries
5789 There is a small trap here, though: @samp{$(LIBOBJS)} and
5790 @samp{$(ALLOCA)} might be empty, and building an empty library is not
5791 portable.  You should ensure that there is always something to put in
5792 @file{libcompat.a}.  Most projects will also add some utility
5793 functions in that directory, and list them in
5794 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
5795 be empty.
5797 Finally here is how this library could be used from the @file{src/}
5798 directory.
5800 @example
5801 # src/Makefile.am
5803 # Link all programs in this directory with libcompat.a
5804 LDADD = ../lib/libcompat.a
5806 bin_PROGRAMS = tool1 tool2 @dots{}
5807 tool1_SOURCES = @dots{}
5808 tool2_SOURCES = @dots{}
5809 @end example
5811 When option @option{subdir-objects} is not used, as in the above
5812 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
5813 be used in the directory where their sources lie.  E.g., here it would
5814 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
5815 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
5816 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
5817 in other directories.  For instance @file{src/Makefile.am} could be
5818 changed as follows.
5820 @example
5821 # src/Makefile.am
5823 AUTOMAKE_OPTIONS = subdir-objects
5824 LDADD = $(LIBOBJS) $(ALLOCA)
5826 bin_PROGRAMS = tool1 tool2 @dots{}
5827 tool1_SOURCES = @dots{}
5828 tool2_SOURCES = @dots{}
5829 @end example
5831 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
5832 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
5833 Libtool libraries (where the expected object extension is @file{.lo}):
5834 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
5836 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
5837 be defined by hand (as in the past), however at the time of writing
5838 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
5839 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
5840 autoconf, The Autoconf Manual}.
5843 @node Program variables
5844 @section Variables used when building a program
5846 Occasionally it is useful to know which @file{Makefile} variables
5847 Automake uses for compilations; for instance, you might need to do your
5848 own compilation in some special cases.
5850 Some variables are inherited from Autoconf; these are @code{CC},
5851 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
5852 @code{LIBS}.
5853 @vindex CC
5854 @vindex CFLAGS
5855 @vindex CPPFLAGS
5856 @vindex DEFS
5857 @vindex LDFLAGS
5858 @vindex LIBS
5860 There are some additional variables that Automake defines on its own:
5862 @vtable @code
5863 @item AM_CPPFLAGS
5864 The contents of this variable are passed to every compilation that invokes
5865 the C preprocessor; it is a list of arguments to the preprocessor.  For
5866 instance, @option{-I} and @option{-D} options should be listed here.
5868 Automake already provides some @option{-I} options automatically, in a
5869 separate variable that is also passed to every compilation that invokes
5870 the C preprocessor.  In particular it generates @samp{-I.},
5871 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
5872 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS} or
5873 @code{AM_CONFIG_HEADER}).  You can disable the default @option{-I}
5874 options using the @option{nostdinc} option.
5876 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
5877 per-library) @code{_CPPFLAGS} variable if it is defined.
5879 @item INCLUDES
5880 This does the same job as @code{AM_CPPFLAGS} (or any per-target
5881 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
5882 same functionality.  This variable is deprecated; we suggest using
5883 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
5885 @item AM_CFLAGS
5886 This is the variable the @file{Makefile.am} author can use to pass
5887 in additional C compiler flags.  It is more fully documented elsewhere.
5888 In some situations, this is not used, in preference to the
5889 per-executable (or per-library) @code{_CFLAGS}.
5891 @item COMPILE
5892 This is the command used to actually compile a C source file.  The
5893 file name is appended to form the complete command line.
5895 @item AM_LDFLAGS
5896 This is the variable the @file{Makefile.am} author can use to pass
5897 in additional linker flags.  In some situations, this is not used, in
5898 preference to the per-executable (or per-library) @code{_LDFLAGS}.
5900 @item LINK
5901 This is the command used to actually link a C program.  It already
5902 includes @samp{-o $@@} and the usual variable references (for instance,
5903 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
5904 and libraries to link in.
5905 @end vtable
5908 @node Yacc and Lex
5909 @section Yacc and Lex support
5911 Automake has somewhat idiosyncratic support for Yacc and Lex.
5913 Automake assumes that the @file{.c} file generated by @command{yacc}
5914 (or @command{lex}) should be named using the basename of the input
5915 file.  That is, for a yacc source file @file{foo.y}, Automake will
5916 cause the intermediate file to be named @file{foo.c} (as opposed to
5917 @file{y.tab.c}, which is more traditional).
5919 The extension of a yacc source file is used to determine the extension
5920 of the resulting C or C++ file.  Files with the extension @file{.y}
5921 will be turned into @file{.c} files; likewise, @file{.yy} will become
5922 @file{.cc}; @file{.y++}, @file{c++}; @file{.yxx}, @file{.cxx}; and
5923 @file{.ypp}, @file{.cpp}.
5925 Likewise, lex source files can be used to generate C or C++; the
5926 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
5927 @file{.lpp} are recognized.
5929 You should never explicitly mention the intermediate (C or C++) file
5930 in any @code{SOURCES} variable; only list the source file.
5932 The intermediate files generated by @command{yacc} (or @command{lex})
5933 will be included in any distribution that is made.  That way the user
5934 doesn't need to have @command{yacc} or @command{lex}.
5936 If a @command{yacc} source file is seen, then your @file{configure.ac} must
5937 define the variable @code{YACC}.  This is most easily done by invoking
5938 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
5939 Program Checks, autoconf, The Autoconf Manual}).
5941 @vindex YFLAGS
5942 @vindex AM_YFLAGS
5943 When @code{yacc} is invoked, it is passed @code{YFLAGS} and
5944 @code{AM_YFLAGS}.  The former is a user variable and the latter is
5945 intended for the @file{Makefile.am} author.
5947 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
5948 @command{yacc}.  Automake knows what this means and will automatically
5949 adjust its rules to update and distribute the header file built by
5950 @samp{yacc -d}.  What Automake cannot guess, though, is where this
5951 header will be used: it is up to you to ensure the header gets built
5952 before it is first used.  Typically this is necessary in order for
5953 dependency tracking to work when the header is included by another
5954 file.  The common solution is listing the header file in
5955 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
5957 @example
5958 BUILT_SOURCES = parser.h
5959 AM_YFLAGS = -d
5960 bin_PROGRAMS = foo
5961 foo_SOURCES = @dots{} parser.y @dots{}
5962 @end example
5964 If a @command{lex} source file is seen, then your @file{configure.ac}
5965 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
5966 to do this (@pxref{Particular Programs, , Particular Program Checks,
5967 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
5968 (@pxref{Macros}) is recommended.
5970 @vindex LFLAGS
5971 @vindex AM_LFLAGS
5972 When @command{lex} is invoked, it is passed @code{LFLAGS} and
5973 @code{AM_LFLAGS}.  The former is a user variable and the latter is
5974 intended for the @file{Makefile.am} author.
5976 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
5977 rebuild rule for distributed Yacc and Lex sources are only used when
5978 @code{maintainer-mode} is enabled, or when the files have been erased.
5980 @cindex @command{ylwrap}
5981 @cindex @command{yacc}, multiple parsers
5982 @cindex Multiple @command{yacc} parsers
5983 @cindex Multiple @command{lex} lexers
5984 @cindex @command{lex}, multiple lexers
5986 When @command{lex} or @command{yacc} sources are used, @code{automake
5987 -i} automatically installs an auxiliary program called
5988 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
5989 program is used by the build rules to rename the output of these
5990 tools, and makes it possible to include multiple @command{yacc} (or
5991 @command{lex}) source files in a single directory.  (This is necessary
5992 because yacc's output file name is fixed, and a parallel make could
5993 conceivably invoke more than one instance of @command{yacc}
5994 simultaneously.)
5996 For @command{yacc}, simply managing locking is insufficient.  The output of
5997 @command{yacc} always uses the same symbol names internally, so it isn't
5998 possible to link two @command{yacc} parsers into the same executable.
6000 We recommend using the following renaming hack used in @command{gdb}:
6001 @example
6002 #define yymaxdepth c_maxdepth
6003 #define yyparse c_parse
6004 #define yylex   c_lex
6005 #define yyerror c_error
6006 #define yylval  c_lval
6007 #define yychar  c_char
6008 #define yydebug c_debug
6009 #define yypact  c_pact
6010 #define yyr1    c_r1
6011 #define yyr2    c_r2
6012 #define yydef   c_def
6013 #define yychk   c_chk
6014 #define yypgo   c_pgo
6015 #define yyact   c_act
6016 #define yyexca  c_exca
6017 #define yyerrflag c_errflag
6018 #define yynerrs c_nerrs
6019 #define yyps    c_ps
6020 #define yypv    c_pv
6021 #define yys     c_s
6022 #define yy_yys  c_yys
6023 #define yystate c_state
6024 #define yytmp   c_tmp
6025 #define yyv     c_v
6026 #define yy_yyv  c_yyv
6027 #define yyval   c_val
6028 #define yylloc  c_lloc
6029 #define yyreds  c_reds
6030 #define yytoks  c_toks
6031 #define yylhs   c_yylhs
6032 #define yylen   c_yylen
6033 #define yydefred c_yydefred
6034 #define yydgoto c_yydgoto
6035 #define yysindex c_yysindex
6036 #define yyrindex c_yyrindex
6037 #define yygindex c_yygindex
6038 #define yytable  c_yytable
6039 #define yycheck  c_yycheck
6040 #define yyname   c_yyname
6041 #define yyrule   c_yyrule
6042 @end example
6044 For each define, replace the @samp{c_} prefix with whatever you like.
6045 These defines work for @command{bison}, @command{byacc}, and
6046 traditional @code{yacc}s.  If you find a parser generator that uses a
6047 symbol not covered here, please report the new name so it can be added
6048 to the list.
6051 @node C++ Support
6052 @section C++ Support
6054 @cindex C++ support
6055 @cindex Support for C++
6057 Automake includes full support for C++.
6059 Any package including C++ code must define the output variable
6060 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6061 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6062 Program Checks, autoconf, The Autoconf Manual}).
6064 A few additional variables are defined when a C++ source file is seen:
6066 @vtable @code
6067 @item CXX
6068 The name of the C++ compiler.
6070 @item CXXFLAGS
6071 Any flags to pass to the C++ compiler.
6073 @item AM_CXXFLAGS
6074 The maintainer's variant of @code{CXXFLAGS}.
6076 @item CXXCOMPILE
6077 The command used to actually compile a C++ source file.  The file name
6078 is appended to form the complete command line.
6080 @item CXXLINK
6081 The command used to actually link a C++ program.
6082 @end vtable
6085 @node Objective C Support
6086 @section Objective C Support
6088 @cindex Objective C support
6089 @cindex Support for Objective C
6091 Automake includes some support for Objective C.
6093 Any package including Objective C code must define the output variable
6094 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6095 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6096 Program Checks, autoconf, The Autoconf Manual}).
6098 A few additional variables are defined when an Objective C source file
6099 is seen:
6101 @vtable @code
6102 @item OBJC
6103 The name of the Objective C compiler.
6105 @item OBJCFLAGS
6106 Any flags to pass to the Objective C compiler.
6108 @item AM_OBJCFLAGS
6109 The maintainer's variant of @code{OBJCFLAGS}.
6111 @item OBJCCOMPILE
6112 The command used to actually compile an Objective C source file.  The
6113 file name is appended to form the complete command line.
6115 @item OBJCLINK
6116 The command used to actually link an Objective C program.
6117 @end vtable
6120 @node Unified Parallel C Support
6121 @section Unified Parallel C Support
6123 @cindex Unified Parallel C support
6124 @cindex Support for Unified Parallel C
6126 Automake includes some support for Unified Parallel C.
6128 Any package including Unified Parallel C code must define the output
6129 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6130 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public macros}).
6132 A few additional variables are defined when a Unified Parallel C
6133 source file is seen:
6135 @vtable @code
6136 @item UPC
6137 The name of the Unified Parallel C compiler.
6139 @item UPCFLAGS
6140 Any flags to pass to the Unified Parallel C compiler.
6142 @item AM_UPCFLAGS
6143 The maintainer's variant of @code{UPCFLAGS}.
6145 @item UPCCOMPILE
6146 The command used to actually compile a Unified Parallel C source file.
6147 The file name is appended to form the complete command line.
6149 @item UPCLINK
6150 The command used to actually link a Unified Parallel C program.
6151 @end vtable
6154 @node Assembly Support
6155 @section Assembly Support
6157 Automake includes some support for assembly code.  There are two forms
6158 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6159 (@file{*.S} or @file{*.sx}).
6161 @vindex CCAS
6162 @vindex CCASFLAGS
6163 @vindex CPPFLAGS
6164 @vindex AM_CCASFLAGS
6165 @vindex AM_CPPFLAGS
6166 The variable @code{CCAS} holds the name of the compiler used to build
6167 assembly code.  This compiler must work a bit like a C compiler; in
6168 particular it must accept @option{-c} and @option{-o}.  The values of
6169 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6170 definition) is passed to the compilation.  For preprocessed files,
6171 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6172 and @code{AM_CPPFLAGS} are also used.
6174 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6175 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6176 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6177 flags), but you are free to define these variables by other means.
6179 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6180 @command{automake} as being files containing assembly code.
6183 @node Fortran 77 Support
6184 @comment  node-name,  next,  previous,  up
6185 @section Fortran 77 Support
6187 @cindex Fortran 77 support
6188 @cindex Support for Fortran 77
6190 Automake includes full support for Fortran 77.
6192 Any package including Fortran 77 code must define the output variable
6193 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6194 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6195 Program Checks, autoconf, The Autoconf Manual}).
6197 A few additional variables are defined when a Fortran 77 source file is
6198 seen:
6200 @vtable @code
6202 @item F77
6203 The name of the Fortran 77 compiler.
6205 @item FFLAGS
6206 Any flags to pass to the Fortran 77 compiler.
6208 @item AM_FFLAGS
6209 The maintainer's variant of @code{FFLAGS}.
6211 @item RFLAGS
6212 Any flags to pass to the Ratfor compiler.
6214 @item AM_RFLAGS
6215 The maintainer's variant of @code{RFLAGS}.
6217 @item F77COMPILE
6218 The command used to actually compile a Fortran 77 source file.  The file
6219 name is appended to form the complete command line.
6221 @item FLINK
6222 The command used to actually link a pure Fortran 77 program or shared
6223 library.
6225 @end vtable
6227 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6228 addition to compiling them@footnote{Much, if not most, of the
6229 information in the following sections pertaining to preprocessing
6230 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6231 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6232 also contains some support for creating programs and shared libraries
6233 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6234 Fortran 77 With C and C++}).
6236 These issues are covered in the following sections.
6238 @menu
6239 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6240 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6241 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6242 @end menu
6245 @node Preprocessing Fortran 77
6246 @comment  node-name,  next,  previous,  up
6247 @subsection Preprocessing Fortran 77
6249 @cindex Preprocessing Fortran 77
6250 @cindex Fortran 77, Preprocessing
6251 @cindex Ratfor programs
6253 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6254 rule runs just the preprocessor to convert a preprocessable Fortran 77
6255 or Ratfor source file into a strict Fortran 77 source file.  The precise
6256 command used is as follows:
6258 @table @file
6260 @item .F
6261 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6262 $(AM_FFLAGS) $(FFLAGS)}
6264 @item .r
6265 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6267 @end table
6270 @node Compiling Fortran 77 Files
6271 @comment  node-name,  next,  previous,  up
6272 @subsection Compiling Fortran 77 Files
6274 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6275 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6276 is as follows:
6278 @table @file
6280 @item .f
6281 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6283 @item .F
6284 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6285 $(AM_FFLAGS) $(FFLAGS)}
6287 @item .r
6288 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6290 @end table
6293 @node Mixing Fortran 77 With C and C++
6294 @comment  node-name,  next,  previous,  up
6295 @subsection Mixing Fortran 77 With C and C++
6297 @cindex Fortran 77, mixing with C and C++
6298 @cindex Mixing Fortran 77 with C and C++
6299 @cindex Linking Fortran 77 with C and C++
6300 @cindex cfortran
6301 @cindex Mixing Fortran 77 with C and/or C++
6303 Automake currently provides @emph{limited} support for creating programs
6304 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6305 However, there are many other issues related to mixing Fortran 77 with
6306 other languages that are @emph{not} (currently) handled by Automake, but
6307 that are handled by other packages@footnote{For example,
6308 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6309 addresses all of these inter-language issues, and runs under nearly all
6310 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6311 @command{cfortran} is not yet Free Software, but it will be in the next
6312 major release.}.
6314 @page
6315 Automake can help in two ways:
6317 @enumerate
6318 @item
6319 Automatic selection of the linker depending on which combinations of
6320 source code.
6322 @item
6323 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6324 @option{-l}) to pass to the automatically selected linker in order to link
6325 in the appropriate Fortran 77 intrinsic and run-time libraries.
6327 @cindex @code{FLIBS}, defined
6328 @vindex FLIBS
6329 These extra Fortran 77 linker flags are supplied in the output variable
6330 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
6331 supplied with newer versions of Autoconf (Autoconf version 2.13 and
6332 later).  @xref{Fortran Compiler, , Fortran Compiler Characteristics,
6333 autoconf, The Autoconf Manual}.
6334 @end enumerate
6336 If Automake detects that a program or shared library (as mentioned in
6337 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6338 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6339 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6340 @file{configure.ac}, and that either @code{$(FLIBS)}
6341 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6342 (for shared libraries) variables.  It is the responsibility of the
6343 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6344 appears in the appropriate @code{_LDADD} or
6345 @code{_LIBADD} variable.
6347 @cindex Mixed language example
6348 @cindex Example, mixed language
6350 For example, consider the following @file{Makefile.am}:
6352 @example
6353 bin_PROGRAMS = foo
6354 foo_SOURCES  = main.cc foo.f
6355 foo_LDADD    = libfoo.la $(FLIBS)
6357 pkglib_LTLIBRARIES = libfoo.la
6358 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6359 libfoo_la_LIBADD   = $(FLIBS)
6360 @end example
6362 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6363 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6364 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6365 Automake would have issued a warning.
6368 @page
6369 @menu
6370 * How the Linker is Chosen::    Automatic linker selection
6371 @end menu
6373 @node How the Linker is Chosen
6374 @comment  node-name,  next,  previous,  up
6375 @subsubsection How the Linker is Chosen
6377 @cindex Automatic linker selection
6378 @cindex Selecting the linker automatically
6380 When a program or library mixes several languages, Automake choose the
6381 linker according to the following priorities.  (The names in
6382 parentheses are the variables containing the link command.)
6384 @enumerate
6385 @item
6386 @vindex GCJLINK
6387 Native Java (@code{GCJLINK})
6388 @item
6389 @vindex CXXLINK
6390 C++ (@code{CXXLINK})
6391 @item
6392 @vindex F77LINK
6393 Fortran 77 (@code{F77LINK})
6394 @item
6395 @vindex FCLINK
6396 Fortran (@code{FCLINK})
6397 @item
6398 @vindex OBJCLINK
6399 Objective C (@code{OBJCLINK})
6400 @item
6401 @vindex UPCLINK
6402 Unified Parallel C (@code{UPCLINK})
6403 @item
6404 @vindex LINK
6405 C (@code{LINK})
6406 @end enumerate
6408 For example, if Fortran 77, C and C++ source code is compiled
6409 into a program, then the C++ linker will be used.  In this case, if the
6410 C or Fortran 77 linkers required any special libraries that weren't
6411 included by the C++ linker, then they must be manually added to an
6412 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6413 @file{Makefile.am}.
6415 Automake only looks at the file names listed in @file{_SOURCES}
6416 variables to choose the linker, and defaults to the C linker.
6417 Sometimes this is inconvenient because you are linking against a
6418 library written in another language and would like to set the linker
6419 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6420 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6423 @node Fortran 9x Support
6424 @comment  node-name,  next,  previous,  up
6425 @section Fortran 9x Support
6427 @cindex Fortran 9x support
6428 @cindex Support for Fortran 9x
6430 Automake includes support for Fortran 9x.
6432 Any package including Fortran 9x code must define the output variable
6433 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6434 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6435 Program Checks, autoconf, The Autoconf Manual}).
6437 A few additional variables are defined when a Fortran 9x source file is
6438 seen:
6440 @vtable @code
6442 @item FC
6443 The name of the Fortran 9x compiler.
6445 @item FCFLAGS
6446 Any flags to pass to the Fortran 9x compiler.
6448 @item AM_FCFLAGS
6449 The maintainer's variant of @code{FCFLAGS}.
6451 @item FCCOMPILE
6452 The command used to actually compile a Fortran 9x source file.  The file
6453 name is appended to form the complete command line.
6455 @item FCLINK
6456 The command used to actually link a pure Fortran 9x program or shared
6457 library.
6459 @end vtable
6461 @menu
6462 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6463 @end menu
6465 @node Compiling Fortran 9x Files
6466 @comment  node-name,  next,  previous,  up
6467 @subsection Compiling Fortran 9x Files
6469 @file{@var{N}.o} is made automatically from @file{@var{N}.f90},
6470 @file{@var{N}.f95}, @file{@var{N}.f03}, or @file{@var{N}.f08}
6471 by running the Fortran 9x compiler.  The precise command used
6472 is as follows:
6474 @table @file
6476 @item .f90
6477 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6479 @item .f95
6480 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6482 @item .f03
6483 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6485 @item .f08
6486 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6488 @end table
6490 @node Java Support
6491 @comment  node-name,  next,  previous,  up
6492 @section Java Support
6494 @cindex Java support
6495 @cindex Support for Java
6497 Automake includes support for compiled Java, using @command{gcj}, the Java
6498 front end to the GNU Compiler Collection.
6500 Any package including Java code to be compiled must define the output
6501 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6502 must also be defined somehow (either in @file{configure.ac} or
6503 @file{Makefile.am}).  The simplest way to do this is to use the
6504 @code{AM_PROG_GCJ} macro.
6506 @vindex GCJFLAGS
6508 By default, programs including Java source files are linked with
6509 @command{gcj}.
6511 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6512 compilation invoking @command{gcj} (in its role as an ahead-of-time
6513 compiler, when invoking it to create @file{.class} files,
6514 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6515 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6516 the user variable @code{GCJFLAGS}, should be used.
6518 @vindex AM_GCJFLAGS
6520 @command{gcj} can be used to compile @file{.java}, @file{.class},
6521 @file{.zip}, or @file{.jar} files.
6523 When linking, @command{gcj} requires that the main class be specified
6524 using the @option{--main=} option.  The easiest way to do this is to use
6525 the @code{_LDFLAGS} variable for the program.
6528 @node Support for Other Languages
6529 @comment  node-name,  next,  previous,  up
6530 @section Support for Other Languages
6532 Automake currently only includes full support for C, C++ (@pxref{C++
6533 Support}), Objective C (@pxref{Objective C Support}), Fortran 77
6534 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6535 and Java (@pxref{Java Support}).  There is only rudimentary support for other
6536 languages, support for which will be improved based on user demand.
6538 Some limited support for adding your own languages is available via the
6539 suffix rule handling (@pxref{Suffixes}).
6542 @node ANSI
6543 @section Automatic de-ANSI-fication
6545 @cindex de-ANSI-fication, defined
6547 The features described in this section are obsolete; you should not
6548 used any of them in new code, and they may be withdrawn in future
6549 Automake releases.
6551 When the C language was standardized in 1989, there was a long
6552 transition period where package developers needed to worry about
6553 porting to older systems that did not support ANSI C by default.
6554 These older systems are no longer in practical use and are no longer
6555 supported by their original suppliers, so developers need not worry
6556 about this problem any more.
6558 Automake allows you to write packages that are portable to K&R C by
6559 @dfn{de-ANSI-fying} each source file before the actual compilation takes
6560 place.
6562 @vindex AUTOMAKE_OPTIONS
6563 @opindex ansi2knr
6565 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
6566 (@pxref{Options}) contains the option @option{ansi2knr} then code to
6567 handle de-ANSI-fication is inserted into the generated
6568 @file{Makefile.in}.
6570 This causes each C source file in the directory to be treated as ANSI C@.
6571 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
6572 is available, the @command{ansi2knr} program is used to convert the source
6573 files into K&R C, which is then compiled.
6575 The @command{ansi2knr} program is simple-minded.  It assumes the source
6576 code will be formatted in a particular way; see the @command{ansi2knr} man
6577 page for details.
6579 @acindex AM_C_PROTOTYPES
6580 Support for the obsolete de-ANSI-fication feature
6581 requires the source files @file{ansi2knr.c}
6582 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
6583 these files are distributed with Automake.  Also, the package
6584 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
6585 (@pxref{Macros}).
6587 Automake also handles finding the @command{ansi2knr} support files in some
6588 other directory in the current package.  This is done by prepending the
6589 relative path to the appropriate directory to the @command{ansi2knr}
6590 option.  For instance, suppose the package has ANSI C code in the
6591 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
6592 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
6593 @file{src/Makefile.am}:
6595 @example
6596 AUTOMAKE_OPTIONS = ../lib/ansi2knr
6597 @end example
6599 If no directory prefix is given, the files are assumed to be in the
6600 current directory.
6602 Note that automatic de-ANSI-fication will not work when the package is
6603 being built for a different host architecture.  That is because automake
6604 currently has no way to build @command{ansi2knr} for the build machine.
6606 @c FIXME: this paragraph might be better moved to an `upgrading' section.
6607 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
6608 @cindex @code{LIBOBJS} and @code{ansi2knr}
6609 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
6610 @cindex @code{ansi2knr} and @code{LIBOBJS}
6611 Using @code{LIBOBJS} with source de-ANSI-fication used to require
6612 hand-crafted code in @file{configure} to append @samp{$U} to basenames
6613 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
6614 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
6615 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
6616 vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual})
6618 @node Dependencies
6619 @section Automatic dependency tracking
6621 As a developer it is often painful to continually update the
6622 @file{Makefile.in} whenever the include-file dependencies change in a
6623 project.  Automake supplies a way to automatically track dependency
6624 changes (@pxref{Dependency Tracking}).
6626 @cindex Dependency tracking
6627 @cindex Automatic dependency tracking
6629 Automake always uses complete dependencies for a compilation,
6630 including system headers.  Automake's model is that dependency
6631 computation should be a side effect of the build.  To this end,
6632 dependencies are computed by running all compilations through a
6633 special wrapper program called @command{depcomp}.  @command{depcomp}
6634 understands how to coax many different C and C++ compilers into
6635 generating dependency information in the format it requires.
6636 @samp{automake -a} will install @command{depcomp} into your source
6637 tree for you.  If @command{depcomp} can't figure out how to properly
6638 invoke your compiler, dependency tracking will simply be disabled for
6639 your build.
6641 @cindex @command{depcomp}
6643 Experience with earlier versions of Automake (@pxref{Dependency
6644 Tracking Evolution}) taught us that it is not reliable to generate
6645 dependencies only on the maintainer's system, as configurations vary
6646 too much.  So instead Automake implements dependency tracking at build
6647 time.
6649 Automatic dependency tracking can be suppressed by putting
6650 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6651 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6652 (this should be the preferred way).  Or, you can invoke @command{automake}
6653 with the @option{-i} option.  Dependency tracking is enabled by default.
6655 @vindex AUTOMAKE_OPTIONS
6656 @opindex no-dependencies
6658 The person building your package also can choose to disable dependency
6659 tracking by configuring with @option{--disable-dependency-tracking}.
6661 @cindex Disabling dependency tracking
6662 @cindex Dependency tracking, disabling
6665 @node EXEEXT
6666 @section Support for executable extensions
6668 @cindex Executable extension
6669 @cindex Extension, executable
6670 @cindex Windows
6672 On some platforms, such as Windows, executables are expected to have an
6673 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6674 among them) will automatically generate @file{foo.exe} when asked to
6675 generate @file{foo}.
6677 Automake provides mostly-transparent support for this.  Unfortunately
6678 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6679 dictionary is revised, you will have to assist Automake if your package
6680 must support those platforms.
6682 One thing you must be aware of is that, internally, Automake rewrites
6683 something like this:
6685 @example
6686 bin_PROGRAMS = liver
6687 @end example
6689 to this:
6691 @example
6692 bin_PROGRAMS = liver$(EXEEXT)
6693 @end example
6695 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6696 extension.
6698 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Tests}) are also
6699 rewritten if they contain filenames that have been declared as programs
6700 in the same @file{Makefile}.  (This is mostly useful when some programs
6701 from @code{check_PROGRAMS} are listed in @code{TESTS}.)
6703 However, Automake cannot apply this rewriting to @command{configure}
6704 substitutions.  This means that if you are conditionally building a
6705 program using such a substitution, then your @file{configure.ac} must
6706 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6708 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
6709 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
6710 automatically if you configure a compiler (say, through
6711 @code{AC_PROG_CC}).
6713 Sometimes maintainers like to write an explicit link rule for their
6714 program.  Without executable extension support, this is easy---you
6715 simply write a rule whose target is the name of the program.  However,
6716 when executable extension support is enabled, you must instead add the
6717 @samp{$(EXEEXT)} suffix.
6719 Unfortunately, due to the change in Autoconf 2.50, this means you must
6720 always add this extension.  However, this is a problem for maintainers
6721 who know their package will never run on a platform that has
6722 executable extensions.  For those maintainers, the @option{no-exeext}
6723 option (@pxref{Options}) will disable this feature.  This works in a
6724 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6725 rule for a target named @code{foo} in @file{Makefile.am} will override
6726 an automake-generated rule for @samp{foo$(EXEEXT)}.  Without
6727 the @option{no-exeext} option, this use will give a diagnostic.
6730 @node Other objects
6731 @chapter Other Derived Objects
6733 Automake can handle derived objects that are not C programs.  Sometimes
6734 the support for actually building such objects must be explicitly
6735 supplied, but Automake will still automatically handle installation and
6736 distribution.
6738 @menu
6739 * Scripts::                     Executable scripts
6740 * Headers::                     Header files
6741 * Data::                        Architecture-independent data files
6742 * Sources::                     Derived sources
6743 @end menu
6746 @node Scripts
6747 @section Executable Scripts
6749 @cindex @code{_SCRIPTS} primary, defined
6750 @cindex @code{SCRIPTS} primary, defined
6751 @cindex Primary variable, @code{SCRIPTS}
6752 @vindex _SCRIPTS
6753 @cindex Installing scripts
6755 It is possible to define and install programs that are scripts.  Such
6756 programs are listed using the @code{SCRIPTS} primary name.  When the
6757 script is distributed in its final, installable form, the
6758 @file{Makefile} usually looks as follows:
6759 @vindex SCRIPTS
6761 @example
6762 # Install my_script in $(bindir) and distribute it.
6763 dist_bin_SCRIPTS = my_script
6764 @end example
6766 Script are not distributed by default; as we have just seen, those
6767 that should be distributed can be specified using a @code{dist_}
6768 prefix as with other primaries.
6770 @cindex @code{SCRIPTS}, installation directories
6771 @vindex bin_SCRIPTS
6772 @vindex sbin_SCRIPTS
6773 @vindex libexec_SCRIPTS
6774 @vindex pkgdata_SCRIPTS
6775 @vindex noinst_SCRIPTS
6776 @vindex check_SCRIPTS
6778 Scripts can be installed in @code{bindir}, @code{sbindir},
6779 @code{libexecdir}, or @code{pkgdatadir}.
6781 Scripts that need not be installed can be listed in
6782 @code{noinst_SCRIPTS}, and among them, those which are needed only by
6783 @samp{make check} should go in @code{check_SCRIPTS}.
6785 When a script needs to be built, the @file{Makefile.am} should include
6786 the appropriate rules.  For instance the @command{automake} program
6787 itself is a Perl script that is generated from @file{automake.in}.
6788 Here is how this is handled:
6790 @example
6791 bin_SCRIPTS = automake
6792 CLEANFILES = $(bin_SCRIPTS)
6793 EXTRA_DIST = automake.in
6795 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
6796             -e 's,[@@]PERL[@@],$(PERL),g' \
6797             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
6798             -e 's,[@@]VERSION[@@],$(VERSION),g' \
6799             @dots{}
6801 automake: automake.in Makefile
6802         $(do_subst) < $(srcdir)/automake.in > automake
6803         chmod +x automake
6804 @end example
6806 Such scripts for which a build rule has been supplied need to be
6807 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
6808 sources have to be distributed, usually with @code{EXTRA_DIST}
6809 (@pxref{Dist}).
6811 Another common way to build scripts is to process them from
6812 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
6813 Automake knows which files should be cleaned and distributed, and what
6814 the rebuild rules should look like.
6816 For instance if @file{configure.ac} contains
6818 @example
6819 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
6820 @end example
6822 @noindent
6823 to build @file{src/my_script} from @file{src/my_script.in}, then a
6824 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
6825 be as simple as
6827 @example
6828 bin_SCRIPTS = my_script
6829 CLEANFILES = $(bin_SCRIPTS)
6830 @end example
6832 @noindent
6833 There is no need for @code{EXTRA_DIST} or any build rule: Automake
6834 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
6835 @code{CLEANFILES} is still useful, because by default Automake will
6836 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
6837 @code{clean}.
6839 Although this looks simpler, building scripts this way has one
6840 drawback: directory variables such as @code{$(datadir)} are not fully
6841 expanded and may refer to other directory variables.
6843 @node Headers
6844 @section Header files
6846 @cindex @code{_HEADERS} primary, defined
6847 @cindex @code{HEADERS} primary, defined
6848 @cindex Primary variable, @code{HEADERS}
6849 @vindex _HEADERS
6850 @vindex noinst_HEADERS
6851 @cindex @code{HEADERS}, installation directories
6852 @cindex Installing headers
6853 @vindex include_HEADERS
6854 @vindex oldinclude_HEADERS
6855 @vindex pkginclude_HEADERS
6858 Header files that must be installed are specified by the
6859 @code{HEADERS} family of variables.  Headers can be installed in
6860 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
6861 other directory you may have defined (@pxref{Uniform}).  For instance,
6863 @example
6864 include_HEADERS = foo.h bar/bar.h
6865 @end example
6867 @noindent
6868 will install the two files as @file{$(includedir)/foo.h} and
6869 @file{$(includedir)/bar.h}.
6871 The @code{nobase_} prefix is also supported,
6873 @example
6874 nobase_include_HEADERS = foo.h bar/bar.h
6875 @end example
6877 @noindent
6878 will install the two files as @file{$(includedir)/foo.h} and
6879 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
6881 @vindex noinst_HEADERS
6882 Usually, only header files that accompany installed libraries need to
6883 be installed.  Headers used by programs or convenience libraries are
6884 not installed.  The @code{noinst_HEADERS} variable can be used for
6885 such headers.  However when the header actually belongs to one
6886 convenient library or program, we recommend listing it in the
6887 program's or library's @code{_SOURCES} variable (@pxref{Program
6888 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
6889 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
6890 right variable to use in a directory containing only headers and no
6891 associated library or program.
6893 All header files must be listed somewhere; in a @code{_SOURCES}
6894 variable or in a @code{_HEADERS} variable.  Missing ones will not
6895 appear in the distribution.
6897 For header files that are built and must not be distributed, use the
6898 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
6899 @code{nodist_prog_SOURCES}.  If these generated headers are needed
6900 during the build, you must also ensure they exist before they are
6901 used (@pxref{Sources}).
6904 @node Data
6905 @section Architecture-independent data files
6907 @cindex @code{_DATA} primary, defined
6908 @cindex @code{DATA} primary, defined
6909 @cindex Primary variable, @code{DATA}
6910 @vindex _DATA
6912 Automake supports the installation of miscellaneous data files using the
6913 @code{DATA} family of variables.
6914 @vindex DATA
6916 @vindex data_DATA
6917 @vindex sysconf_DATA
6918 @vindex sharedstate_DATA
6919 @vindex localstate_DATA
6920 @vindex pkgdata_DATA
6922 Such data can be installed in the directories @code{datadir},
6923 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
6924 @code{pkgdatadir}.
6926 By default, data files are @emph{not} included in a distribution.  Of
6927 course, you can use the @code{dist_} prefix to change this on a
6928 per-variable basis.
6930 Here is how Automake declares its auxiliary data files:
6932 @example
6933 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
6934 @end example
6937 @node Sources
6938 @section Built sources
6940 Because Automake's automatic dependency tracking works as a side-effect
6941 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
6942 target should not be compiled before its dependencies are made, but
6943 these dependencies are unknown until the target is first compiled.
6945 Ordinarily this is not a problem, because dependencies are distributed
6946 sources: they preexist and do not need to be built.  Suppose that
6947 @file{foo.c} includes @file{foo.h}.  When it first compiles
6948 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
6949 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
6950 records the @file{foo.h} dependency so that following invocations of
6951 @command{make} will honor it.  In these conditions, it's clear there is
6952 no problem: either @file{foo.o} doesn't exist and has to be built
6953 (regardless of the dependencies), or accurate dependencies exist and
6954 they can be used to decide whether @file{foo.o} should be rebuilt.
6956 It's a different story if @file{foo.h} doesn't exist by the first
6957 @command{make} run.  For instance, there might be a rule to build
6958 @file{foo.h}.  This time @file{file.o}'s build will fail because the
6959 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
6960 rule to build @file{foo.h} first by lack of dependency information.
6962 @vindex BUILT_SOURCES
6963 @cindex @code{BUILT_SOURCES}, defined
6965 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
6966 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
6967 or @samp{make check} (or even @samp{make install}) before other
6968 targets are processed.  However, such a source file is not
6969 @emph{compiled} unless explicitly requested by mentioning it in some
6970 other @code{_SOURCES} variable.
6972 So, to conclude our introductory example, we could use
6973 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
6974 any other target (including @file{foo.o}) during @samp{make all} or
6975 @samp{make check}.
6977 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
6978 must be created early in the build process can be listed in this
6979 variable.  Moreover, all built sources do not necessarily have to be
6980 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
6981 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
6982 another source), because it's a known dependency of the associated
6983 object.
6985 It might be important to emphasize that @code{BUILT_SOURCES} is
6986 honored only by @samp{make all}, @samp{make check} and @samp{make
6987 install}.  This means you cannot build a specific target (e.g.,
6988 @samp{make foo}) in a clean tree if it depends on a built source.
6989 However it will succeed if you have run @samp{make all} earlier,
6990 because accurate dependencies are already available.
6992 The next section illustrates and discusses the handling of built sources
6993 on a toy example.
6995 @menu
6996 * Built sources example::       Several ways to handle built sources.
6997 @end menu
6999 @node Built sources example
7000 @subsection Built sources example
7002 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7003 installation-dependent and not distributed: it needs to be built.  Here
7004 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7005 value of the @command{make} variable @code{bindir} (inherited from
7006 @file{configure}).
7008 We suggest several implementations below.  It's not meant to be an
7009 exhaustive listing of all ways to handle built sources, but it will give
7010 you a few ideas if you encounter this issue.
7012 @unnumberedsubsec First try
7014 This first implementation will illustrate the bootstrap issue mentioned
7015 in the previous section (@pxref{Sources}).
7017 Here is a tentative @file{Makefile.am}.
7019 @example
7020 # This won't work.
7021 bin_PROGRAMS = foo
7022 foo_SOURCES = foo.c
7023 nodist_foo_SOURCES = bindir.h
7024 CLEANFILES = bindir.h
7025 bindir.h: Makefile
7026         echo '#define bindir "$(bindir)"' >$@@
7027 @end example
7029 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7030 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7031 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7032 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7033 The symptom is as follows.
7035 @example
7036 % make
7037 source='foo.c' object='foo.o' libtool=no \
7038 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7039 depmode=gcc /bin/sh ./depcomp \
7040 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7041 foo.c:2: bindir.h: No such file or directory
7042 make: *** [foo.o] Error 1
7043 @end example
7045 In this example @file{bindir.h} is not distributed nor installed, and
7046 it is not even being built on-time.  One may wonder if the
7047 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7048 line simply states that @file{bindir.h} is a source of @code{foo}, so
7049 for instance, it should be inspected while generating tags
7050 (@pxref{Tags}).  In other words, it does not help our present problem,
7051 and the build would fail identically without it.
7053 @unnumberedsubsec Using @code{BUILT_SOURCES}
7055 A solution is to require @file{bindir.h} to be built before anything
7056 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7058 @example
7059 bin_PROGRAMS = foo
7060 foo_SOURCES = foo.c
7061 nodist_foo_SOURCES = bindir.h
7062 BUILT_SOURCES = bindir.h
7063 CLEANFILES = bindir.h
7064 bindir.h: Makefile
7065         echo '#define bindir "$(bindir)"' >$@@
7066 @end example
7068 See how @file{bindir.h} gets built first:
7070 @example
7071 % make
7072 echo '#define bindir "/usr/local/bin"' >bindir.h
7073 make  all-am
7074 make[1]: Entering directory `/home/adl/tmp'
7075 source='foo.c' object='foo.o' libtool=no \
7076 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7077 depmode=gcc /bin/sh ./depcomp \
7078 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7079 gcc  -g -O2   -o foo  foo.o
7080 make[1]: Leaving directory `/home/adl/tmp'
7081 @end example
7083 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7084 @code{all}, @code{check}, and @code{install} targets.  It still fails
7085 if you try to run @samp{make foo} explicitly:
7087 @example
7088 % make clean
7089 test -z "bindir.h" || rm -f bindir.h
7090 test -z "foo" || rm -f foo
7091 rm -f *.o
7092 % : > .deps/foo.Po # Suppress previously recorded dependencies
7093 % make foo
7094 source='foo.c' object='foo.o' libtool=no \
7095 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7096 depmode=gcc /bin/sh ./depcomp \
7097 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7098 foo.c:2: bindir.h: No such file or directory
7099 make: *** [foo.o] Error 1
7100 @end example
7102 @unnumberedsubsec Recording dependencies manually
7104 Usually people are happy enough with @code{BUILT_SOURCES} because they
7105 never build targets such as @samp{make foo} before @samp{make all}, as
7106 in the previous example.  However if this matters to you, you can
7107 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7108 the @file{Makefile.am}.
7110 @example
7111 bin_PROGRAMS = foo
7112 foo_SOURCES = foo.c
7113 nodist_foo_SOURCES = bindir.h
7114 foo.$(OBJEXT): bindir.h
7115 CLEANFILES = bindir.h
7116 bindir.h: Makefile
7117         echo '#define bindir "$(bindir)"' >$@@
7118 @end example
7120 You don't have to list @emph{all} the dependencies of @file{foo.o}
7121 explicitly, only those that might need to be built.  If a dependency
7122 already exists, it will not hinder the first compilation and will be
7123 recorded by the normal dependency tracking code.  (Note that after
7124 this first compilation the dependency tracking code will also have
7125 recorded the dependency between @file{foo.o} and
7126 @file{bindir.h}; so our explicit dependency is really useful to
7127 the first build only.)
7129 Adding explicit dependencies like this can be a bit dangerous if you are
7130 not careful enough.  This is due to the way Automake tries not to
7131 overwrite your rules (it assumes you know better than it).
7132 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7133 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7134 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7135 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7136 Always check the generated @file{Makefile.in} if you do this.
7138 @unnumberedsubsec Build @file{bindir.h} from @file{configure}
7140 It's possible to define this preprocessor macro from @file{configure},
7141 either in @file{config.h} (@pxref{Defining Directories, , Defining
7142 Directories, autoconf, The Autoconf Manual}), or by processing a
7143 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7144 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7145 Autoconf Manual}).
7147 At this point it should be clear that building @file{bindir.h} from
7148 @file{configure} works well for this example.  @file{bindir.h} will exist
7149 before you build any target, hence will not cause any dependency issue.
7151 The Makefile can be shrunk as follows.  We do not even have to mention
7152 @file{bindir.h}.
7154 @example
7155 bin_PROGRAMS = foo
7156 foo_SOURCES = foo.c
7157 @end example
7159 However, it's not always possible to build sources from
7160 @file{configure}, especially when these sources are generated by a tool
7161 that needs to be built first.
7163 @unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
7165 Another attractive idea is to define @code{bindir} as a variable or
7166 function exported from @file{bindir.o}, and build @file{bindir.c}
7167 instead of @file{bindir.h}.
7169 @example
7170 noinst_PROGRAMS = foo
7171 foo_SOURCES = foo.c bindir.h
7172 nodist_foo_SOURCES = bindir.c
7173 CLEANFILES = bindir.c
7174 bindir.c: Makefile
7175         echo 'const char bindir[] = "$(bindir)";' >$@@
7176 @end example
7178 @file{bindir.h} contains just the variable's declaration and doesn't
7179 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7180 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7181 first.
7183 @unnumberedsubsec Which is best?
7185 There is no panacea, of course.  Each solution has its merits and
7186 drawbacks.
7188 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7189 foo} on a clean tree is important to you.
7191 You won't add explicit dependencies if you are leery of overriding
7192 an Automake rule by mistake.
7194 Building files from @file{./configure} is not always possible, neither
7195 is converting @file{.h} files into @file{.c} files.
7198 @node Other GNU Tools
7199 @chapter Other GNU Tools
7201 Since Automake is primarily intended to generate @file{Makefile.in}s for
7202 use in GNU programs, it tries hard to interoperate with other GNU tools.
7204 @menu
7205 * Emacs Lisp::                  Emacs Lisp
7206 * gettext::                     Gettext
7207 * Libtool::                     Libtool
7208 * Java::                        Java
7209 * Python::                      Python
7210 @end menu
7213 @node Emacs Lisp
7214 @section Emacs Lisp
7216 @cindex @code{_LISP} primary, defined
7217 @cindex @code{LISP} primary, defined
7218 @cindex Primary variable, @code{LISP}
7220 @vindex _LISP
7221 @vindex lisp_LISP
7222 @vindex noinst_LISP
7224 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7225 is used to hold a list of @file{.el} files.  Possible prefixes for this
7226 primary are @code{lisp_} and @code{noinst_}.  Note that if
7227 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7228 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7230 @vindex dist_lisp_LISP
7231 @vindex dist_noinst_LISP
7232 Lisp sources are not distributed by default.  You can prefix the
7233 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7234 @code{dist_noinst_LISP}, to indicate that these files should be
7235 distributed.
7237 Automake will byte-compile all Emacs Lisp source files using the Emacs
7238 found by @code{AM_PATH_LISPDIR}, if any was found.
7240 Byte-compiled Emacs Lisp files are not portable among all versions of
7241 Emacs, so it makes sense to turn this off if you expect sites to have
7242 more than one version of Emacs installed.  Furthermore, many packages
7243 don't actually benefit from byte-compilation.  Still, we recommend
7244 that you byte-compile your Emacs Lisp sources.  It is probably better
7245 for sites with strange setups to cope for themselves than to make the
7246 installation less nice for everybody else.
7248 There are two ways to avoid byte-compiling.  Historically, we have
7249 recommended the following construct.
7250 @example
7251 lisp_LISP = file1.el file2.el
7252 ELCFILES =
7253 @end example
7254 @noindent
7255 @code{ELCFILES} is an internal Automake variable that normally lists
7256 all @file{.elc} files that must be byte-compiled.  Automake defines
7257 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7258 variable explicitly prevents byte-compilation.
7260 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead.  As
7262 @example
7263 lisp_DATA = file1.el file2.el
7264 @end example
7266 Note that these two constructs are not equivalent.  @code{_LISP} will
7267 not install a file if Emacs is not installed, while @code{_DATA} will
7268 always install its files.
7270 @node gettext
7271 @section Gettext
7273 @cindex GNU Gettext support
7274 @cindex Gettext support
7275 @cindex Support for GNU Gettext
7277 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7278 turns on support for GNU gettext, a message catalog system for
7279 internationalization
7280 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7282 The @code{gettext} support in Automake requires the addition of one or
7283 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7284 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7285 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7286 Automake ensures that these directories exist and are mentioned in
7287 @code{SUBDIRS}.
7289 @node Libtool
7290 @section Libtool
7292 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7293 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7294 @xref{A Shared Library}.
7297 @node Java
7298 @section Java
7300 @cindex @code{_JAVA} primary, defined
7301 @cindex @code{JAVA} primary, defined
7302 @cindex Primary variable, @code{JAVA}
7304 Automake provides some minimal support for Java compilation with the
7305 @code{JAVA} primary.
7307 Any @file{.java} files listed in a @code{_JAVA} variable will be
7308 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7309 files are not included in the distribution, you should use the
7310 @code{dist_} prefix to distribute them.
7312 Here is a typical setup for distributing @file{.java} files and
7313 installing the @file{.class} files resulting from their compilation.
7315 @example
7316 javadir = $(datadir)/java
7317 dist_java_JAVA = a.java b.java @dots{}
7318 @end example
7320 @cindex @code{JAVA} restrictions
7321 @cindex Restrictions for @code{JAVA}
7323 Currently Automake enforces the restriction that only one @code{_JAVA}
7324 primary can be used in a given @file{Makefile.am}.  The reason for this
7325 restriction is that, in general, it isn't possible to know which
7326 @file{.class} files were generated from which @file{.java} files, so
7327 it would be impossible to know which files to install where.  For
7328 instance, a @file{.java} file can define multiple classes; the resulting
7329 @file{.class} file names cannot be predicted without parsing the
7330 @file{.java} file.
7332 There are a few variables that are used when compiling Java sources:
7334 @vtable @code
7335 @item JAVAC
7336 The name of the Java compiler.  This defaults to @samp{javac}.
7338 @item JAVACFLAGS
7339 The flags to pass to the compiler.  This is considered to be a user
7340 variable (@pxref{User Variables}).
7342 @item AM_JAVACFLAGS
7343 More flags to pass to the Java compiler.  This, and not
7344 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7345 compiler flags into @file{Makefile.am}.
7347 @item JAVAROOT
7348 The value of this variable is passed to the @option{-d} option to
7349 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7351 @item CLASSPATH_ENV
7352 This variable is an @code{sh} expression that is used to set the
7353 @env{CLASSPATH} environment variable on the @code{javac} command line.
7354 (In the future we will probably handle class path setting differently.)
7355 @end vtable
7358 @node Python
7359 @section Python
7361 @cindex @code{_PYTHON} primary, defined
7362 @cindex @code{PYTHON} primary, defined
7363 @cindex Primary variable, @code{PYTHON}
7364 @vindex _PYTHON
7366 Automake provides support for Python compilation with the
7367 @code{PYTHON} primary.  A typical setup is to call
7368 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7369 following in @file{Makefile.am}:
7371 @example
7372 python_PYTHON = tree.py leave.py
7373 @end example
7375 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7376 with @command{py-compile} at install time.  @command{py-compile}
7377 actually creates both standard (@file{.pyc}) and optimized
7378 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7379 because byte-compilation occurs at install time, any files listed in
7380 @code{noinst_PYTHON} will not be compiled.  Python source files are
7381 included in the distribution by default, prepend @code{nodist_} (as in
7382 @code{nodist_python_PYTHON}) to omit them.
7384 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7385 that will determine some Python-related directory variables (see
7386 below).  If you have called @code{AM_PATH_PYTHON} from
7387 @file{configure.ac}, then you may use the variables
7388 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7389 files in your @file{Makefile.am}, depending on where you want your files
7390 installed (see the definitions of @code{pythondir} and
7391 @code{pkgpythondir} below).
7393 @defmac AM_PATH_PYTHON (@ovar{VERSION}, @ovar{ACTION-IF-FOUND}, @ovar{ACTION-IF-NOT-FOUND})
7395 Search for a Python interpreter on the system.  This macro takes three
7396 optional arguments.  The first argument, if present, is the minimum
7397 version of Python required for this package: @code{AM_PATH_PYTHON}
7398 will skip any Python interpreter that is older than @var{VERSION}.
7399 If an interpreter is found and satisfies @var{VERSION}, then
7400 @var{ACTION-IF-FOUND} is run.  Otherwise, @var{ACTION-IF-NOT-FOUND} is
7401 run.
7403 If @var{ACTION-IF-NOT-FOUND} is not specified, as in the following
7404 example, the default is to abort @command{configure}.
7406 @example
7407 AM_PATH_PYTHON([2.2])
7408 @end example
7410 @noindent
7411 This is fine when Python is an absolute requirement for the package.
7412 If Python >= 2.5 was only @emph{optional} to the package,
7413 @code{AM_PATH_PYTHON} could be called as follows.
7415 @example
7416 AM_PATH_PYTHON([2.5],, [:])
7417 @end example
7419 @code{AM_PATH_PYTHON} creates the following output variables based on
7420 the Python installation found during configuration.
7421 @end defmac
7423 @vtable @code
7424 @item PYTHON
7425 The name of the Python executable, or @samp{:} if no suitable
7426 interpreter could be found.
7428 Assuming @var{ACTION-IF-NOT-FOUND} is used (otherwise @file{./configure}
7429 will abort if Python is absent), the value of @code{PYTHON} can be used
7430 to setup a conditional in order to disable the relevant part of a build
7431 as follows.
7433 @example
7434   AM_PATH_PYTHON(,, [:])
7435   AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7436 @end example
7438 @item PYTHON_VERSION
7439 The Python version number, in the form @var{major}.@var{minor}
7440 (e.g., @samp{2.5}).  This is currently the value of
7441 @samp{sys.version[:3]}.
7443 @item PYTHON_PREFIX
7444 The string @samp{$@{prefix@}}.  This term may be used in future work
7445 that needs the contents of Python's @samp{sys.prefix}, but general
7446 consensus is to always use the value from @command{configure}.
7448 @item PYTHON_EXEC_PREFIX
7449 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7450 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7451 consensus is to always use the value from @command{configure}.
7453 @item PYTHON_PLATFORM
7454 The canonical name used by Python to describe the operating system, as
7455 given by @samp{sys.platform}.  This value is sometimes needed when
7456 building Python extensions.
7458 @item pythondir
7459 The directory name for the @file{site-packages} subdirectory of the
7460 standard Python install tree.
7462 @item pkgpythondir
7463 This is the directory under @code{pythondir} that is named after the
7464 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7465 as a convenience.
7467 @item pyexecdir
7468 This is the directory where Python extension modules (shared libraries)
7469 should be installed.  An extension module written in C could be declared
7470 as follows to Automake:
7472 @example
7473 pyexec_LTLIBRARIES = quaternion.la
7474 quaternion_SOURCES = quaternion.c support.c support.h
7475 quaternion_la_LDFLAGS = -avoid-version -module
7476 @end example
7478 @item pkgpyexecdir
7479 This is a convenience variable that is defined as
7480 @samp{$(pyexecdir)/$(PACKAGE)}.
7481 @end vtable
7483 All these directory variables have values that start with either
7484 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7485 fine in @file{Makefiles}, but it makes these variables hard to use in
7486 @file{configure}.  This is mandated by the GNU coding standards, so
7487 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7488 manual has a section with more details on this topic
7489 (@pxref{Installation Directory Variables, , Installation Directory
7490 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7491 Install Paths}.
7494 @node Documentation
7495 @chapter Building documentation
7497 Currently Automake provides support for Texinfo and man pages.
7499 @menu
7500 * Texinfo::                     Texinfo
7501 * Man pages::                   Man pages
7502 @end menu
7505 @node Texinfo
7506 @section Texinfo
7508 @cindex @code{_TEXINFOS} primary, defined
7509 @cindex @code{TEXINFOS} primary, defined
7510 @cindex Primary variable, @code{TEXINFOS}
7511 @cindex HTML output using Texinfo
7512 @cindex PDF output using Texinfo
7513 @cindex PS output using Texinfo
7514 @cindex DVI output using Texinfo
7515 @vindex _TEXINFOS
7516 @vindex info_TEXINFOS
7518 If the current directory contains Texinfo source, you must declare it
7519 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7520 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7521 here.  Any Texinfo source file must end in the @file{.texi},
7522 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7523 for new manuals.
7525 Automake generates rules to build @file{.info}, @file{.dvi},
7526 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7527 sources.  Following the GNU Coding Standards, only the @file{.info}
7528 files are built by @samp{make all} and installed by @samp{make
7529 install} (unless you use @option{no-installinfo}, see below).
7530 Furthermore, @file{.info} files are automatically distributed so that
7531 Texinfo is not a prerequisite for installing your package.
7533 @trindex dvi
7534 @trindex html
7535 @trindex pdf
7536 @trindex ps
7537 @trindex install-dvi
7538 @trindex install-html
7539 @trindex install-pdf
7540 @trindex install-ps
7541 Other documentation formats can be built on request by @samp{make
7542 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7543 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7544 @samp{make install-pdf} and @samp{make install-html} explicitly.
7545 @samp{make uninstall} will remove everything: the Texinfo
7546 documentation installed by default as well as all the above optional
7547 formats.
7549 All these targets can be extended using @samp{-local} rules
7550 (@pxref{Extending}).
7552 @cindex Texinfo flag, @code{VERSION}
7553 @cindex Texinfo flag, @code{UPDATED}
7554 @cindex Texinfo flag, @code{EDITION}
7555 @cindex Texinfo flag, @code{UPDATED-MONTH}
7557 @cindex @code{VERSION} Texinfo flag
7558 @cindex @code{UPDATED} Texinfo flag
7559 @cindex @code{EDITION} Texinfo flag
7560 @cindex @code{UPDATED-MONTH} Texinfo flag
7562 @cindex @file{mdate-sh}
7564 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7565 that file will be automatically generated.  The file @file{version.texi}
7566 defines four Texinfo flag you can reference using
7567 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7568 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7570 @table @code
7571 @item EDITION
7572 @itemx VERSION
7573 Both of these flags hold the version number of your program.  They are
7574 kept separate for clarity.
7576 @item UPDATED
7577 This holds the date the primary @file{.texi} file was last modified.
7579 @item UPDATED-MONTH
7580 This holds the name of the month in which the primary @file{.texi} file
7581 was last modified.
7582 @end table
7584 The @file{version.texi} support requires the @command{mdate-sh}
7585 script; this script is supplied with Automake and automatically
7586 included when @command{automake} is invoked with the
7587 @option{--add-missing} option.
7589 If you have multiple Texinfo files, and you want to use the
7590 @file{version.texi} feature, then you have to have a separate version
7591 file for each Texinfo file.  Automake will treat any include in a
7592 Texinfo file that matches @file{vers*.texi} just as an automatically
7593 generated version file.
7595 Sometimes an info file actually depends on more than one @file{.texi}
7596 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7597 @file{gpl.texi}.  You can tell Automake about these dependencies using
7598 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7599 @vindex TEXINFOS
7600 @vindex _TEXINFOS
7602 @example
7603 info_TEXINFOS = hello.texi
7604 hello_TEXINFOS = gpl.texi
7605 @end example
7607 @cindex @file{texinfo.tex}
7609 By default, Automake requires the file @file{texinfo.tex} to appear in
7610 the same directory as the @file{Makefile.am} file that lists the
7611 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7612 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7613 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7614 there.  In both cases, automake then supplies @file{texinfo.tex} if
7615 @option{--add-missing} is given, and takes care of its distribution.
7616 However, if you set the @code{TEXINFO_TEX} variable (see below),
7617 it overrides the location of the file and turns off its installation
7618 into the source as well as its distribution.
7620 The option @option{no-texinfo.tex} can be used to eliminate the
7621 requirement for the file @file{texinfo.tex}.  Use of the variable
7622 @code{TEXINFO_TEX} is preferable, however, because that allows the
7623 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7625 @cindex Option, @code{no-installinfo}
7626 @cindex Target, @code{install-info}
7627 @cindex @code{install-info} target
7628 @cindex @code{no-installinfo} option
7630 @opindex no-installinfo
7631 @trindex install-info
7633 Automake generates an @code{install-info} rule; some people apparently
7634 use this.  By default, info pages are installed by @samp{make
7635 install}, so running @code{make install-info} is pointless.  This can
7636 be prevented via the @code{no-installinfo} option.  In this case,
7637 @file{.info} files are not installed by default, and user must
7638 request this explicitly using @samp{make install-info}.
7640 The following variables are used by the Texinfo build rules.
7642 @vtable @code
7643 @item MAKEINFO
7644 The name of the program invoked to build @file{.info} files.  This
7645 variable is defined by Automake.  If the @command{makeinfo} program is
7646 found on the system then it will be used by default; otherwise
7647 @command{missing} will be used instead.
7649 @item MAKEINFOHTML
7650 The command invoked to build @file{.html} files.  Automake
7651 defines this to @samp{$(MAKEINFO) --html}.
7653 @item MAKEINFOFLAGS
7654 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7655 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7656 not expected to be defined in any @file{Makefile}; it can be used by
7657 users to pass extra flags to suit their needs.
7659 @item AM_MAKEINFOFLAGS
7660 @itemx AM_MAKEINFOHTMLFLAGS
7661 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7662 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7663 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7664 passed to @code{makeinfo} when building @file{.info} files; and
7665 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7666 files.
7668 For instance, the following setting can be used to obtain one single
7669 @file{.html} file per manual, without node separators.
7670 @example
7671 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7672 @end example
7674 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7675 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7676 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7677 and @file{.html} files.
7679 @item TEXI2DVI
7680 The name of the command that converts a @file{.texi} file into a
7681 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7682 with the Texinfo package.
7684 @item TEXI2PDF
7685 The name of the command that translates a @file{.texi} file into a
7686 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7688 @item DVIPS
7689 The name of the command that builds a @file{.ps} file out of a
7690 @file{.dvi} file.  This defaults to @samp{dvips}.
7692 @item TEXINFO_TEX
7694 If your package has Texinfo files in many directories, you can use the
7695 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7696 @file{texinfo.tex} for your package.  The value of this variable should
7697 be the relative path from the current @file{Makefile.am} to
7698 @file{texinfo.tex}:
7700 @example
7701 TEXINFO_TEX = ../doc/texinfo.tex
7702 @end example
7703 @end vtable
7706 @node Man pages
7707 @section Man pages
7709 @cindex @code{_MANS} primary, defined
7710 @cindex @code{MANS} primary, defined
7711 @cindex Primary variable, @code{MANS}
7713 @vindex _MANS
7714 @vindex man_MANS
7715 A package can also include man pages (but see the GNU standards on this
7716 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7717 pages are declared using the @code{MANS} primary.  Generally the
7718 @code{man_MANS} variable is used.  Man pages are automatically installed in
7719 the correct subdirectory of @code{mandir}, based on the file extension.
7721 File extensions such as @file{.1c} are handled by looking for the valid
7722 part of the extension and using that to determine the correct
7723 subdirectory of @code{mandir}.  Valid section names are the digits
7724 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7726 Sometimes developers prefer to name a man page something like
7727 @file{foo.man} in the source, and then rename it to have the correct
7728 suffix, for example @file{foo.1}, when installing the file.  Automake
7729 also supports this mode.  For a valid section named @var{SECTION},
7730 there is a corresponding directory named @samp{man@var{SECTION}dir},
7731 and a corresponding @code{_MANS} variable.  Files listed in such a
7732 variable are installed in the indicated section.  If the file already
7733 has a valid suffix, then it is installed as-is; otherwise the file
7734 suffix is changed to match the section.
7736 For instance, consider this example:
7737 @example
7738 man1_MANS = rename.man thesame.1 alsothesame.1c
7739 @end example
7741 @noindent
7742 In this case, @file{rename.man} will be renamed to @file{rename.1} when
7743 installed, but the other files will keep their names.
7745 @cindex Target, @code{install-man}
7746 @cindex Option, @option{no-installman}
7747 @cindex @code{install-man} target
7748 @cindex @option{no-installman} option
7749 @opindex no-installman
7750 @trindex install-man
7752 By default, man pages are installed by @samp{make install}.  However,
7753 since the GNU project does not require man pages, many maintainers do
7754 not expend effort to keep the man pages up to date.  In these cases, the
7755 @option{no-installman} option will prevent the man pages from being
7756 installed by default.  The user can still explicitly install them via
7757 @samp{make install-man}.
7759 For fast installation, with many files it is preferable to use
7760 @samp{man@var{SECTION}_MANS} over @samp{man_MANS} as well as files that
7761 do not need to be renamed.
7763 Man pages are not currently considered to be source, because it is not
7764 uncommon for man pages to be automatically generated.  Therefore they
7765 are not automatically included in the distribution.  However, this can
7766 be changed by use of the @code{dist_} prefix.  For instance here is
7767 how to distribute and install the two man pages of GNU @command{cpio}
7768 (which includes both Texinfo documentation and man pages):
7770 @example
7771 dist_man_MANS = cpio.1 mt.1
7772 @end example
7774 The @code{nobase_} prefix is meaningless for man pages and is
7775 disallowed.
7777 @vindex notrans_
7778 @cindex @code{notrans_} prefix
7779 @cindex Man page renaming, avoiding
7780 @cindex Avoiding man page renaming
7782 Executables and manpages may be renamed upon installation
7783 (@pxref{Renaming}).  For manpages this can be avoided by use of the
7784 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
7785 allowing to access a library function @samp{foo} from the command line.
7786 The way to avoid renaming of the @file{foo.3} manpage is:
7788 @example
7789 man_MANS = foo.1
7790 notrans_man_MANS = foo.3
7791 @end example
7793 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
7794 @cindex @code{dist_} and @code{notrans_}
7795 @cindex @code{nodist_} and @code{notrans_}
7797 @samp{notrans_} must be specified first when used in conjunction with
7798 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
7800 @example
7801 notrans_dist_man3_MANS = bar.3
7802 @end example
7804 @node Install
7805 @chapter What Gets Installed
7807 @cindex Installation support
7808 @cindex @samp{make install} support
7810 @section Basics of installation
7812 Naturally, Automake handles the details of actually installing your
7813 program once it has been built.  All files named by the various
7814 primaries are automatically installed in the appropriate places when the
7815 user runs @samp{make install}.
7817 A file named in a primary is installed by copying the built file into
7818 the appropriate directory.  The base name of the file is used when
7819 installing.
7821 @example
7822 bin_PROGRAMS = hello subdir/goodbye
7823 @end example
7825 In this example, both @samp{hello} and @samp{goodbye} will be installed
7826 in @samp{$(bindir)}.
7828 Sometimes it is useful to avoid the basename step at install time.  For
7829 instance, you might have a number of header files in subdirectories of
7830 the source tree that are laid out precisely how you want to install
7831 them.  In this situation you can use the @code{nobase_} prefix to
7832 suppress the base name step.  For example:
7834 @example
7835 nobase_include_HEADERS = stdio.h sys/types.h
7836 @end example
7838 @noindent
7839 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
7840 in @samp{$(includedir)/sys}.
7842 For most file types, Automake will install multiple files at once, while
7843 avoiding command line length issues (@pxref{Length limitations}).  Since
7844 some @command{install} programs will not install the same file twice in
7845 one invocation, you may need to ensure that file lists are unique within
7846 one variable such as @samp{nobase_include_HEADERS} above.
7848 You should not rely on the order in which files listed in one variable
7849 are installed.  Likewise, to cater for parallel make, you should not
7850 rely on any particular file installation order even among different
7851 file types (library dependencies are an exception here).
7854 @section The two parts of install
7856 Automake generates separate @code{install-data} and @code{install-exec}
7857 rules, in case the installer is installing on multiple machines that
7858 share directory structure---these targets allow the machine-independent
7859 parts to be installed only once.  @code{install-exec} installs
7860 platform-dependent files, and @code{install-data} installs
7861 platform-independent files.  The @code{install} target depends on both
7862 of these targets.  While Automake tries to automatically segregate
7863 objects into the correct category, the @file{Makefile.am} author is, in
7864 the end, responsible for making sure this is done correctly.
7865 @trindex install-data
7866 @trindex install-exec
7867 @trindex install
7868 @cindex Install, two parts of
7870 Variables using the standard directory prefixes @samp{data},
7871 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
7872 @samp{pkgdata}, or @samp{pkginclude} are installed by
7873 @code{install-data}.
7875 Variables using the standard directory prefixes @samp{bin},
7876 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
7877 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
7879 For instance, @code{data_DATA} files are installed by @code{install-data},
7880 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
7882 Any variable using a user-defined directory prefix with @samp{exec} in
7883 the name (e.g., @code{myexecbin_PROGRAMS}) is installed by
7884 @code{install-exec}.  All other user-defined prefixes are installed by
7885 @code{install-data}.
7887 @section Extending installation
7889 It is possible to extend this mechanism by defining an
7890 @code{install-exec-local} or @code{install-data-local} rule.  If these
7891 rules exist, they will be run at @samp{make install} time.  These
7892 rules can do almost anything; care is required.
7893 @trindex install-exec-local
7894 @trindex install-data-local
7896 Automake also supports two install hooks, @code{install-exec-hook} and
7897 @code{install-data-hook}.  These hooks are run after all other install
7898 rules of the appropriate type, exec or data, have completed.  So, for
7899 instance, it is possible to perform post-installation modifications
7900 using an install hook.  @xref{Extending}, for some examples.
7901 @cindex Install hook
7903 @section Staged installs
7905 @vindex DESTDIR
7906 Automake generates support for the @code{DESTDIR} variable in all
7907 install rules.  @code{DESTDIR} is used during the @samp{make install}
7908 step to relocate install objects into a staging area.  Each object and
7909 path is prefixed with the value of @code{DESTDIR} before being copied
7910 into the install area.  Here is an example of typical DESTDIR usage:
7912 @example
7913 mkdir /tmp/staging &&
7914 make DESTDIR=/tmp/staging install
7915 @end example
7917 The @command{mkdir} command avoids a security problem if the attacker
7918 creates a symbolic link from @file{/tmp/staging} to a victim area;
7919 then @command{make} places install objects in a directory tree built under
7920 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
7921 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
7922 would install @file{/tmp/staging/gnu/bin/foo} and
7923 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
7925 This feature is commonly used to build install images and packages
7926 (@pxref{DESTDIR}).
7928 Support for @code{DESTDIR} is implemented by coding it directly into
7929 the install rules.  If your @file{Makefile.am} uses a local install
7930 rule (e.g., @code{install-exec-local}) or an install hook, then you
7931 must write that code to respect @code{DESTDIR}.
7933 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
7934 for another usage example.
7936 @section Rules for the user
7938 Automake also generates rules for targets @code{uninstall},
7939 @code{installdirs}, and @code{install-strip}.
7940 @trindex uninstall
7941 @trindex installdirs
7942 @trindex install-strip
7944 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
7945 There is no notion of separate uninstalls for ``exec'' and ``data'', as
7946 these features would not provide additional functionality.
7948 Note that @code{uninstall} is not meant as a replacement for a real
7949 packaging tool.
7952 @node Clean
7953 @chapter What Gets Cleaned
7955 @cindex @samp{make clean} support
7957 The GNU Makefile Standards specify a number of different clean rules.
7958 @xref{Standard Targets, , Standard Targets for Users, standards,
7959 The GNU Coding Standards}.
7961 Generally the files that can be cleaned are determined automatically by
7962 Automake.  Of course, Automake also recognizes some variables that can
7963 be defined to specify additional files to clean.  These variables are
7964 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
7965 @code{MAINTAINERCLEANFILES}.
7966 @vindex MOSTLYCLEANFILES
7967 @vindex CLEANFILES
7968 @vindex DISTCLEANFILES
7969 @vindex MAINTAINERCLEANFILES
7971 @trindex mostlyclean-local
7972 @trindex clean-local
7973 @trindex distclean-local
7974 @trindex maintainer-clean-local
7975 When cleaning involves more than deleting some hard-coded list of
7976 files, it is also possible to supplement the cleaning rules with your
7977 own commands.  Simply define a rule for any of the
7978 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
7979 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
7980 case is deleting a directory, for instance, a directory created by the
7981 test suite:
7983 @example
7984 clean-local:
7985         -rm -rf testSubDir
7986 @end example
7988 As the GNU Standards aren't always explicit as to which files should
7989 be removed by which rule, we've adopted a heuristic that we believe
7990 was first formulated by Fran@,{c}ois Pinard:
7992 @itemize @bullet
7993 @item
7994 If @command{make} built it, and it is commonly something that one would
7995 want to rebuild (for instance, a @file{.o} file), then
7996 @code{mostlyclean} should delete it.
7998 @item
7999 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8001 @item
8002 If @command{configure} built it, then @code{distclean} should delete it.
8004 @item
8005 If the maintainer built it (for instance, a @file{.info} file), then
8006 @code{maintainer-clean} should delete it.  However
8007 @code{maintainer-clean} should not delete anything that needs to exist
8008 in order to run @samp{./configure && make}.
8009 @end itemize
8011 We recommend that you follow this same set of heuristics in your
8012 @file{Makefile.am}.
8015 @node Dist
8016 @chapter What Goes in a Distribution
8018 @section Basics of distribution
8020 @cindex @samp{make dist}
8022 @vindex PACKAGE
8023 @vindex VERSION
8024 @trindex dist
8025 The @code{dist} rule in the generated @file{Makefile.in} can be used
8026 to generate a gzipped @code{tar} file and other flavors of archive for
8027 distribution.  The file is named based on the @code{PACKAGE} and
8028 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8029 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8030 @samp{@var{package}-@var{version}.tar.gz}.
8031 @vindex GZIP_ENV
8032 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8033 is run.  The default setting is @option{--best}.
8035 @cindex @code{m4_include}, distribution
8036 @cindex @code{include}, distribution
8037 @acindex m4_include
8038 @cmindex include
8039 For the most part, the files to distribute are automatically found by
8040 Automake: all source files are automatically included in a distribution,
8041 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
8042 has a built-in list of commonly used files that are automatically
8043 included if they are found in the current directory (either physically,
8044 or as the target of a @file{Makefile.am} rule).  This list is printed by
8045 @samp{automake --help}.  Also, files that are read by @command{configure}
8046 (i.e.@: the source files corresponding to the files specified in various
8047 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8048 automatically distributed.  Files included in @file{Makefile.am}s (using
8049 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8050 helper scripts installed with @samp{automake --add-missing} are also
8051 distributed.
8053 @vindex EXTRA_DIST
8054 Still, sometimes there are files that must be distributed, but which
8055 are not covered in the automatic rules.  These files should be listed in
8056 the @code{EXTRA_DIST} variable.  You can mention files from
8057 subdirectories in @code{EXTRA_DIST}.
8059 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8060 entire directory will be recursively copied into the distribution.
8061 Please note that this will also copy @emph{everything} in the directory,
8062 including CVS/RCS version control files.  We recommend against using
8063 this feature.
8065 @vindex SUBDIRS
8066 @vindex DIST_SUBDIRS
8067 If you define @code{SUBDIRS}, Automake will recursively include the
8068 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8069 conditionally (@pxref{Conditionals}), Automake will normally include
8070 all directories that could possibly appear in @code{SUBDIRS} in the
8071 distribution.  If you need to specify the set of directories
8072 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8073 exact list of subdirectories to include in the distribution
8074 (@pxref{Conditional Subdirectories}).
8077 @section Fine-grained distribution control
8079 @vindex dist_
8080 @vindex nodist_
8081 Sometimes you need tighter control over what does @emph{not} go into the
8082 distribution; for instance, you might have source files that are
8083 generated and that you do not want to distribute.  In this case
8084 Automake gives fine-grained control using the @code{dist} and
8085 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8086 prefixed with @code{dist_} to add the listed files to the distribution.
8087 Similarly, @code{nodist_} can be used to omit the files from the
8088 distribution.
8090 As an example, here is how you would cause some data to be distributed
8091 while leaving some source code out of the distribution:
8093 @example
8094 dist_data_DATA = distribute-this
8095 bin_PROGRAMS = foo
8096 nodist_foo_SOURCES = do-not-distribute.c
8097 @end example
8099 @section The dist hook
8101 @trindex dist-hook
8103 Occasionally it is useful to be able to change the distribution before
8104 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8105 after the distribution directory is filled, but before the actual tar
8106 (or shar) file is created.  One way to use this is for distributing
8107 files in subdirectories for which a new @file{Makefile.am} is overkill:
8109 @example
8110 dist-hook:
8111         mkdir $(distdir)/random
8112         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
8113 @end example
8115 Another way to use this is for removing unnecessary files that get
8116 recursively included by specifying a directory in EXTRA_DIST:
8118 @example
8119 EXTRA_DIST = doc
8121 dist-hook:
8122         rm -rf `find $(distdir)/doc -name CVS`
8123 @end example
8125 @vindex distdir
8126 @vindex top_distdir
8127 Two variables that come handy when writing @code{dist-hook} rules are
8128 @samp{$(distdir)} and @samp{$(top_distdir)}.
8130 @samp{$(distdir)} points to the directory where the @code{dist} rule
8131 will copy files from the current directory before creating the
8132 tarball.  If you are at the top-level directory, then @samp{distdir =
8133 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8134 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8135 @samp{$(distdir)} can be a relative or absolute path, do not assume
8136 any form.
8138 @samp{$(top_distdir)} always points to the root directory of the
8139 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8140 In the @file{foo/} subdirectory
8141 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8142 @samp{$(top_distdir)} too can be a relative or absolute path.
8144 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8145 (@pxref{Subpackages}), then @samp{$(distdir)} and
8146 @samp{$(top_distdir)} are relative to the package where @samp{make
8147 dist} was run, not to any sub-packages involved.
8149 @section Checking the distribution
8151 @cindex @samp{make distcheck}
8152 @cindex @samp{make distcleancheck}
8153 @vindex distcleancheck_listfiles
8154 @cindex @samp{make distuninstallcheck}
8155 @vindex distuninstallcheck_listfiles
8157 @trindex distcheck
8158 Automake also generates a @code{distcheck} rule that can be of help to
8159 ensure that a given distribution will actually work.  @code{distcheck}
8160 makes a distribution, then tries to do a @code{VPATH} build
8161 (@pxref{VPATH Builds}), run the test suite, and finally make another
8162 tarball to ensure the distribution is self-contained.
8164 @vindex DISTCHECK_CONFIGURE_FLAGS
8165 Building the package involves running @samp{./configure}.  If you need
8166 to supply additional flags to @command{configure}, define them in the
8167 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
8168 @file{Makefile.am}, or on the command line when invoking @command{make}.
8170 @trindex distcheck-hook
8171 If the @code{distcheck-hook} rule is defined in your top-level
8172 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8173 the new distribution has been unpacked, but before the unpacked copy
8174 is configured and built.  Your @code{distcheck-hook} can do almost
8175 anything, though as always caution is advised.  Generally this hook is
8176 used to check for potential distribution errors not caught by the
8177 standard mechanism.  Note that @code{distcheck-hook} as well as
8178 @code{DISTCHECK_CONFIGURE_FLAGS} are not honored in a subpackage
8179 @file{Makefile.am}, but the @code{DISTCHECK_CONFIGURE_FLAGS} are
8180 passed down to the @command{configure} script of the subpackage.
8182 @trindex distcleancheck
8183 @vindex DISTCLEANFILES
8184 @vindex distcleancheck_listfiles
8185 Speaking of potential distribution errors, @code{distcheck} also
8186 ensures that the @code{distclean} rule actually removes all built
8187 files.  This is done by running @samp{make distcleancheck} at the end of
8188 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8189 @code{distclean} and then make sure the build tree has been emptied by
8190 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8191 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8192 variable (@pxref{Clean}).
8194 The @code{distcleancheck} behavior should be OK for most packages,
8195 otherwise you have the possibility to override the definition of
8196 either the @code{distcleancheck} rule, or the
8197 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8198 @code{distcleancheck} completely, add the following rule to your
8199 top-level @file{Makefile.am}:
8201 @example
8202 distcleancheck:
8203         @@:
8204 @end example
8206 If you want @code{distcleancheck} to ignore built files that have not
8207 been cleaned because they are also part of the distribution, add the
8208 following definition instead:
8210 @example
8211 distcleancheck_listfiles = \
8212   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8213        sh '@{@}' ';'
8214 @end example
8216 The above definition is not the default because it's usually an error if
8217 your Makefiles cause some distributed files to be rebuilt when the user
8218 build the package.  (Think about the user missing the tool required to
8219 build the file; or if the required tool is built by your package,
8220 consider the cross-compilation case where it can't be run.)  There is
8221 a FAQ entry about this (@pxref{distcleancheck}), make sure you read it
8222 before playing with @code{distcleancheck_listfiles}.
8224 @code{distcheck} also checks that the @code{uninstall} rule works
8225 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8226 by invoking @samp{make uninstall}, and then it checks the install tree
8227 to see if any files are left over.  This check will make sure that you
8228 correctly coded your @code{uninstall}-related rules.
8230 By default, the checking is done by the @code{distuninstallcheck} rule,
8231 and the list of files in the install tree is generated by
8232 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8233 a shell command to run that prints the list of files to stdout).
8235 Either of these can be overridden to modify the behavior of
8236 @code{distcheck}.  For instance, to disable this check completely, you
8237 would write:
8239 @example
8240 distuninstallcheck:
8241         @@:
8242 @end example
8244 @section The types of distributions
8246 Automake generates rules to provide archives of the project for
8247 distributions in various formats.  Their targets are:
8249 @table @asis
8250 @item @code{dist-bzip2}
8251 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8252 frequently smaller than gzipped archives.
8253 @trindex dist-bzip2
8255 @item @code{dist-gzip}
8256 Generate a gzip tar archive of the distribution.
8257 @trindex dist-gzip
8259 @item @code{dist-lzma}
8260 Generate an @samp{lzma} tar archive of the distribution.  @command{lzma}
8261 archives are frequently smaller than @command{bzip2}-compressed archives.
8262 @trindex dist-lzma
8264 @item @code{dist-shar}
8265 Generate a shar archive of the distribution.
8266 @trindex dist-shar
8268 @item @code{dist-xz}
8269 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8270 archives are frequently smaller than @command{bzip2}-compressed archives.
8271 The @samp{xz} format will soon (early 2009) displace the @samp{lzma} format.
8272 @trindex dist-xz
8274 @item @code{dist-zip}
8275 Generate a zip archive of the distribution.
8276 @trindex dist-zip
8278 @item @code{dist-tarZ}
8279 Generate a compressed tar archive of
8280 the distribution.
8281 @trindex dist-tarZ
8282 @end table
8284 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8285 create archives in all the enabled formats, @ref{Options}.  By
8286 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8289 @node Tests
8290 @chapter Support for test suites
8292 @cindex Test suites
8293 @cindex @code{make check}
8294 @trindex check
8296 Automake supports two forms of test suites.
8298 @section Simple Tests
8300 If the variable @code{TESTS} is defined, its value is taken to be a
8301 list of programs or scripts to run in order to do the testing.
8302 Programs needing data files should look for them in @code{srcdir}
8303 (which is both an environment variable and a make variable) so they
8304 work when building in a separate directory (@pxref{Build Directories,
8305 , Build Directories , autoconf, The Autoconf Manual}), and in
8306 particular for the @code{distcheck} rule (@pxref{Dist}).
8308 For each of the @code{TESTS}, the result of execution is printed along
8309 with the test name, where @code{PASS} denotes a successful test,
8310 @code{FAIL} denotes a failed test, @code{XFAIL} an expected failure,
8311 @code{XPASS} an unexpected pass for a test that is supposed to fail,
8312 and @code{SKIP} denotes a skipped test.
8314 @cindex Exit status 77, special interpretation
8316 The number of failures will be printed at the end of the run.  If a
8317 given test program exits with a status of 77, then its result is ignored
8318 in the final count.  This feature allows non-portable tests to be
8319 ignored in environments where they don't make sense.
8321 @vindex AM_COLOR_TESTS
8322 If the Automake option @code{color-tests} is used (@pxref{Options})
8323 and standard output is connected to a capable terminal, then the test
8324 results and the summary are colored appropriately.  The user can disable
8325 colored output by setting the @command{make} variable
8326 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8327 terminal with @samp{AM_COLOR_TESTS=always}.
8329 @vindex TESTS
8330 @vindex TESTS_ENVIRONMENT
8331 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
8332 variables for the test run; the environment variable @code{srcdir} is
8333 set in the rule.  If all your test programs are scripts, you can also
8334 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
8335 @samp{$(SHELL) -x} can be useful for debugging the tests), or any other
8336 interpreter.  For instance the following setup is used by the Automake
8337 package to run four tests in Perl.
8338 @example
8339 TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
8340 TESTS = Condition.pl DisjConditions.pl Version.pl Wrap.pl
8341 @end example
8344 @cindex Tests, expected failure
8345 @cindex Expected test failure
8347 You may define the variable @code{XFAIL_TESTS} to a list of tests
8348 (usually a subset of @code{TESTS}) that are expected to fail.  This will
8349 reverse the result of those tests.
8350 @vindex XFAIL_TESTS
8352 Automake ensures that each file listed in @code{TESTS} is built before
8353 any tests are run; you can list both source and derived programs (or
8354 scripts) in @code{TESTS}; the generated rule will look both in
8355 @code{srcdir} and @file{.}.  For instance, you might want to run a C
8356 program as a test.  To do this you would list its name in @code{TESTS}
8357 and also in @code{check_PROGRAMS}, and then specify it as you would
8358 any other program.
8360 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8361 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8362 not during @code{make all}.  You should list there any program needed
8363 by your tests that does not need to be built by @code{make all}.  Note
8364 that @code{check_PROGRAMS} are @emph{not} automatically added to
8365 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8366 by the tests, not the tests themselves.  Of course you can set
8367 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8369 @section DejaGnu Tests
8371 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
8372 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
8373 assumed.  The variable @code{DEJATOOL} is a list of names that are
8374 passed, one at a time, as the @option{--tool} argument to
8375 @command{runtest} invocations; it defaults to the name of the package.
8377 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
8378 @option{--srcdir} flags that are passed to dejagnu by default; this can be
8379 overridden if necessary.
8380 @vindex RUNTESTDEFAULTFLAGS
8382 The variables @code{EXPECT} and @code{RUNTEST} can
8383 also be overridden to provide project-specific values.  For instance,
8384 you will need to do this if you are testing a compiler toolchain,
8385 because the default values do not take into account host and target
8386 names.
8387 @opindex dejagnu
8388 @vindex DEJATOOL
8389 @vindex EXPECT
8390 @vindex RUNTEST
8392 The contents of the variable @code{RUNTESTFLAGS} are passed to the
8393 @code{runtest} invocation.  This is considered a ``user variable''
8394 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
8395 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
8396 @vindex RUNTESTFLAGS
8397 @vindex AM_RUNTESTFLAGS
8399 @cindex @file{site.exp}
8400 Automake will generate rules to create a local @file{site.exp} file,
8401 defining various variables detected by @command{configure}.  This file
8402 is automatically read by DejaGnu.  It is OK for the user of a package
8403 to edit this file in order to tune the test suite.  However this is
8404 not the place where the test suite author should define new variables:
8405 this should be done elsewhere in the real test suite code.
8406 Especially, @file{site.exp} should not be distributed.
8408 For more information regarding DejaGnu test suites, see @ref{Top, , ,
8409 dejagnu, The DejaGnu Manual}.
8411 In either case, the testing is done via @samp{make check}.
8413 @section Install Tests
8415 The @code{installcheck} target is available to the user as a way to
8416 run any tests after the package has been installed.  You can add tests
8417 to this by writing an @code{installcheck-local} rule.
8420 @node Rebuilding
8421 @chapter Rebuilding Makefiles
8422 @cindex rebuild rules
8424 Automake generates rules to automatically rebuild @file{Makefile}s,
8425 @file{configure}, and other derived files like @file{Makefile.in}.
8427 @acindex AM_MAINTAINER_MODE
8428 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
8429 these automatic rebuilding rules are only enabled in maintainer mode.
8431 @vindex ACLOCAL_AMFLAGS
8432 Sometimes you need to run @command{aclocal} with an argument like
8433 @option{-I} to tell it where to find @file{.m4} files.  Since
8434 sometimes @command{make} will automatically run @command{aclocal}, you
8435 need a way to specify these arguments.  You can do this by defining
8436 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
8437 to @command{aclocal}.  This variable is only useful in the top-level
8438 @file{Makefile.am}.
8440 @vindex CONFIG_STATUS_DEPENDENCIES
8441 @vindex CONFIGURE_DEPENDENCIES
8442 @cindex @file{version.sh}, example
8443 @cindex @file{version.m4}, example
8445 Sometimes it is convenient to supplement the rebuild rules for
8446 @file{configure} or @file{config.status} with additional dependencies.
8447 The variables @code{CONFIGURE_DEPENDENCIES} and
8448 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
8449 dependencies.  These variable should be defined in all
8450 @file{Makefile}s of the tree (because these two rebuild rules are
8451 output in all them), so it is safer and easier to @code{AC_SUBST} them
8452 from @file{configure.ac}.  For instance, the following statement will
8453 cause @file{configure} to be rerun each time @file{version.sh} is
8454 changed.
8455 @example
8456 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
8457 @end example
8458 @noindent
8459 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
8460 is to be used in all @file{Makefile}s, its value must be sensible at
8461 any level in the build hierarchy.
8463 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
8464 @code{CONFIG_STATUS_DEPENDENCIES}.
8466 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
8467 @file{configure} rule, whose effect is to run @command{autoconf}.  This
8468 variable should be seldom used, because @command{automake} already tracks
8469 @code{m4_include}d files.  However it can be useful when playing
8470 tricky games with @code{m4_esyscmd} or similar non-recommendable
8471 macros with side effects.
8473 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
8474 @file{config.status} rule, whose effect is to run @file{configure}.
8475 This variable should therefore carry any non-standard source that may
8476 be read as a side effect of running @command{configure}, like @file{version.sh}
8477 in the example above.
8479 Speaking of @file{version.sh} scripts, we recommend against them
8480 today.  They are mainly used when the version of a package is updated
8481 automatically by a script (e.g., in daily builds).  Here is what some
8482 old-style @file{configure.ac}s may look like:
8483 @example
8484 AC_INIT
8485 . $srcdir/version.sh
8486 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
8487 @dots{}
8488 @end example
8489 @noindent
8490 Here, @file{version.sh} is a shell fragment that sets
8491 @code{VERSION_NUMBER}.  The problem with this example is that
8492 @command{automake} cannot track dependencies (listing @file{version.sh}
8493 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
8494 to the user), and that it uses the obsolete form of @code{AC_INIT} and
8495 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
8496 straightforward, because shell variables are not allowed in
8497 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
8498 replaced by an M4 file that is included by @file{configure.ac}:
8499 @example
8500 m4_include([version.m4])
8501 AC_INIT([name], VERSION_NUMBER)
8502 AM_INIT_AUTOMAKE
8503 @dots{}
8504 @end example
8505 @noindent
8506 Here @file{version.m4} could contain something like
8507 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
8508 second form is that @command{automake} will take care of the
8509 dependencies when defining the rebuild rule, and will also distribute
8510 the file automatically.  An inconvenience is that @command{autoconf}
8511 will now be rerun each time the version number is bumped, when only
8512 @file{configure} had to be rerun in the previous setup.
8515 @node Options
8516 @chapter Changing Automake's Behavior
8518 Various features of Automake can be controlled by options in the
8519 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
8520 basis when listed in a special @file{Makefile} variable named
8521 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
8522 @file{Makefiles} when listed in the first argument of
8523 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}.  Currently understood
8524 options are:
8525 @vindex AUTOMAKE_OPTIONS
8527 @table @asis
8528 @item @option{gnits}
8529 @itemx @option{gnu}
8530 @itemx @option{foreign}
8531 @itemx @option{cygnus}
8532 @cindex Option, @option{gnits}
8533 @cindex Option, @option{gnu}
8534 @cindex Option, @option{foreign}
8535 @cindex Option, @option{cygnus}
8536 @opindex gnits
8537 @opindex gnu
8538 @opindex foreign
8539 @opindex cygnus
8541 Set the strictness as appropriate.  The @option{gnits} option also
8542 implies options @option{readme-alpha} and @option{check-news}.
8544 @item @option{ansi2knr}
8545 @itemx @option{@var{path}/ansi2knr}
8546 @cindex Option, @option{ansi2knr}
8547 @opindex ansi2knr
8548 Turn on the obsolete de-ANSI-fication feature.  @xref{ANSI}.  If preceded by a
8549 path, the generated @file{Makefile.in} will look in the specified
8550 directory to find the @file{ansi2knr} program.  The path should be a
8551 relative path to another directory in the same distribution (Automake
8552 currently does not check this).
8554 @item @option{check-news}
8555 @cindex Option, @option{check-news}
8556 @opindex check-news
8557 Cause @samp{make dist} to fail unless the current version number appears
8558 in the first few lines of the @file{NEWS} file.
8560 @item @option{color-tests}
8561 @cindex Option, @option{color-tests}
8562 @opindex color-tests
8563 Cause output of the simple test suite (@pxref{Tests}) to be
8564 colorized on capable terminals.
8566 @item @option{dejagnu}
8567 @cindex Option, @option{dejagnu}
8568 @opindex dejagnu
8569 Cause @command{dejagnu}-specific rules to be generated.  @xref{Tests}.
8571 @item @option{dist-bzip2}
8572 @cindex Option, @option{dist-bzip2}
8573 @opindex dist-bzip2
8574 Hook @code{dist-bzip2} to @code{dist}.
8575 @trindex dist-bzip2
8577 @item @option{dist-lzma}
8578 @cindex Option, @option{dist-lzma}
8579 @opindex dist-lzma
8580 Hook @code{dist-lzma} to @code{dist}.
8581 @trindex dist-lzma
8583 @item @option{dist-shar}
8584 @cindex Option, @option{dist-shar}
8585 @opindex dist-shar
8586 Hook @code{dist-shar} to @code{dist}.
8587 @trindex dist-shar
8589 @item @option{dist-zip}
8590 @cindex Option, @option{dist-zip}
8591 @opindex dist-zip
8592 Hook @code{dist-zip} to @code{dist}.
8593 @trindex dist-zip
8595 @item @option{dist-tarZ}
8596 @cindex Option, @option{dist-tarZ}
8597 @opindex dist-tarZ
8598 Hook @code{dist-tarZ} to @code{dist}.
8599 @trindex dist-tarZ
8601 @item @option{filename-length-max=99}
8602 @cindex Option, @option{filename-length-max=99}
8603 @opindex filename-length-max=99
8604 Abort if file names longer than 99 characters are found during
8605 @samp{make dist}.  Such long file names are generally considered not to
8606 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
8607 options below.  This option should be used in the top-level
8608 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
8609 @file{configure.ac}, it will be ignored otherwise.  It will also be
8610 ignored in sub-packages of nested packages (@pxref{Subpackages}).
8612 @item @option{no-define}
8613 @cindex Option, @option{no-define}
8614 @opindex no-define
8615 This option is meaningful only when passed as an argument to
8616 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
8617 @code{VERSION} variables from being @code{AC_DEFINE}d.
8619 @item @option{no-dependencies}
8620 @cindex Option, @option{no-dependencies}
8621 @opindex no-dependencies
8622 This is similar to using @option{--ignore-deps} on the command line,
8623 but is useful for those situations where you don't have the necessary
8624 bits to make automatic dependency tracking work
8625 (@pxref{Dependencies}).  In this case the effect is to effectively
8626 disable automatic dependency tracking.
8628 @item @option{no-dist}
8629 @cindex Option, @option{no-dist}
8630 @opindex no-dist
8631 Don't emit any code related to @code{dist} target.  This is useful
8632 when a package has its own method for making distributions.
8634 @item @option{no-dist-gzip}
8635 @cindex Option, @option{no-dist-gzip}
8636 @opindex no-dist-gzip
8637 Do not hook @code{dist-gzip} to @code{dist}.
8638 @trindex no-dist-gzip
8640 @item @option{no-exeext}
8641 @cindex Option, @option{no-exeext}
8642 @opindex no-exeext
8643 If your @file{Makefile.am} defines a rule for target @code{foo}, it
8644 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
8645 necessary when @code{EXEEXT} is found to be empty.  However, by
8646 default automake will generate an error for this use.  The
8647 @option{no-exeext} option will disable this error.  This is intended for
8648 use only where it is known in advance that the package will not be
8649 ported to Windows, or any other operating system using extensions on
8650 executables.
8652 @item @option{no-installinfo}
8653 @cindex Option, @option{no-installinfo}
8654 @opindex no-installinfo
8655 The generated @file{Makefile.in} will not cause info pages to be built
8656 or installed by default.  However, @code{info} and @code{install-info}
8657 targets will still be available.  This option is disallowed at
8658 @option{gnu} strictness and above.
8659 @trindex info
8660 @trindex install-info
8662 @item @option{no-installman}
8663 @cindex Option, @option{no-installman}
8664 @opindex no-installman
8665 The generated @file{Makefile.in} will not cause man pages to be
8666 installed by default.  However, an @code{install-man} target will still
8667 be available for optional installation.  This option is disallowed at
8668 @option{gnu} strictness and above.
8669 @trindex install-man
8671 @item @option{nostdinc}
8672 @cindex Option, @option{nostdinc}
8673 @opindex nostdinc
8674 This option can be used to disable the standard @option{-I} options that
8675 are ordinarily automatically provided by Automake.
8677 @item @option{no-texinfo.tex}
8678 @cindex Option, @option{no-texinfo.tex}
8679 @opindex no-texinfo.tex
8680 Don't require @file{texinfo.tex}, even if there are texinfo files in
8681 this directory.
8683 @item @option{readme-alpha}
8684 @cindex Option, @option{readme-alpha}
8685 @opindex readme-alpha
8686 If this release is an alpha release, and the file @file{README-alpha}
8687 exists, then it will be added to the distribution.  If this option is
8688 given, version numbers are expected to follow one of two forms.  The
8689 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
8690 element is a number; the final period and number should be left off for
8691 non-alpha releases.  The second form is
8692 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
8693 letter; it should be omitted for non-alpha releases.
8695 @item @option{std-options}
8696 @cindex Options, @option{std-options}
8697 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
8698 @cindex @option{--help} check
8699 @cindex @option{--version} check
8700 @opindex std-options
8702 Make the @code{installcheck} rule check that installed scripts and
8703 programs support the @option{--help} and @option{--version} options.
8704 This also provides a basic check that the program's
8705 run-time dependencies are satisfied after installation.
8707 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
8708 In a few situations, programs (or scripts) have to be exempted from this
8709 test.  For instance, @command{false} (from GNU sh-utils) is never
8710 successful, even for @option{--help} or @option{--version}.  You can list
8711 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
8712 Programs (not scripts) listed in this variable should be suffixed by
8713 @samp{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance, suppose we
8714 build @file{false} as a program but @file{true.sh} as a script, and that
8715 neither of them support @option{--help} or @option{--version}:
8717 @example
8718 AUTOMAKE_OPTIONS = std-options
8719 bin_PROGRAMS = false ...
8720 bin_SCRIPTS = true.sh ...
8721 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
8722 @end example
8724 @item @option{subdir-objects}
8725 @cindex Options, @option{subdir-objects}
8726 @opindex subdir-objects
8727 If this option is specified, then objects are placed into the
8728 subdirectory of the build directory corresponding to the subdirectory of
8729 the source file.  For instance, if the source file is
8730 @file{subdir/file.cxx}, then the output file would be
8731 @file{subdir/file.o}.
8733 In order to use this option with C sources, you should add
8734 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
8736 @anchor{tar-formats}
8737 @item @option{tar-v7}
8738 @itemx @option{tar-ustar}
8739 @itemx @option{tar-pax}
8740 @cindex Option, @option{tar-v7}
8741 @cindex Option, @option{tar-ustar}
8742 @cindex Option, @option{tar-pax}
8743 @cindex @command{tar} formats
8744 @cindex v7 @command{tar} format
8745 @cindex ustar format
8746 @cindex pax format
8747 @opindex tar-v7
8748 @opindex tar-ustar
8749 @opindex tar-pax
8751 These three mutually exclusive options select the tar format to use
8752 when generating tarballs with @samp{make dist}.  (The tar file created
8753 is then compressed according to the set of @option{no-dist-gzip},
8754 @option{dist-bzip2}, @option{dist-lzma} and @option{dist-tarZ} options in use.)
8756 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
8757 (@pxref{Macros}) because they can require additional configure checks.
8758 Automake will complain if it sees such options in an
8759 @code{AUTOMAKE_OPTIONS} variable.
8761 @option{tar-v7} selects the old V7 tar format.  This is the historical
8762 default.  This antiquated format is understood by all tar
8763 implementations and supports file names with up to 99 characters.  When
8764 given longer file names some tar implementations will diagnose the
8765 problem while other will generate broken tarballs or use non-portable
8766 extensions.  Furthermore, the V7 format cannot store empty
8767 directories.  When using this format, consider using the
8768 @option{filename-length-max=99} option to catch file names too long.
8770 @option{tar-ustar} selects the ustar format defined by POSIX
8771 1003.1-1988.  This format is believed to be old enough to be portable.
8772 It fully supports empty directories.  It can store file names with up
8773 to 256 characters, provided that the file name can be split at
8774 directory separator in two parts, first of them being at most 155
8775 bytes long.  So, in most cases the maximum file name length will be
8776 shorter than 256 characters.  However you may run against broken tar
8777 implementations that incorrectly handle file names longer than 99
8778 characters (please report them to @email{bug-automake@@gnu.org} so we
8779 can document this accurately).
8781 @option{tar-pax} selects the new pax interchange format defined by POSIX
8782 1003.1-2001.  It does not limit the length of file names.  However,
8783 this format is very young and should probably be restricted to
8784 packages that target only very modern platforms.  There are moves to
8785 change the pax format in an upward-compatible way, so this option may
8786 refer to a more recent version in the future.
8788 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
8789 further discussion about tar formats.
8791 @command{configure} knows several ways to construct these formats.  It
8792 will not abort if it cannot find a tool up to the task (so that the
8793 package can still be built), but @samp{make dist} will fail.
8795 @item @var{version}
8796 @cindex Option, @var{version}
8797 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
8798 newer than the version specified, creation of the @file{Makefile.in}
8799 will be suppressed.
8801 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
8802 @cindex Option, warnings
8803 @cindex Option, @option{-W@var{category}}
8804 @cindex Option, @option{--warnings=@var{category}}
8805 These options behave exactly like their command-line counterpart
8806 (@pxref{Invoking Automake}).  This allows you to enable or disable some
8807 warning categories on a per-file basis.  You can also setup some warnings
8808 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
8809 in your @file{configure.ac}.
8811 @end table
8813 Unrecognized options are diagnosed by @command{automake}.
8815 If you want an option to apply to all the files in the tree, you can use
8816 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
8817 @xref{Macros}.
8820 @node Miscellaneous
8821 @chapter Miscellaneous Rules
8823 There are a few rules and variables that didn't fit anywhere else.
8825 @menu
8826 * Tags::                        Interfacing to etags and mkid
8827 * Suffixes::                    Handling new file extensions
8828 * Multilibs::                   Support for multilibs.
8829 @end menu
8832 @node Tags
8833 @section Interfacing to @command{etags}
8835 @cindex @file{TAGS} support
8837 Automake will generate rules to generate @file{TAGS} files for use with
8838 GNU Emacs under some circumstances.
8840 @trindex tags
8841 If any C, C++ or Fortran 77 source code or headers are present, then
8842 @code{tags} and @code{TAGS} rules will be generated for the directory.
8843 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
8844 @code{_LISP} primaries will be used to generate tags.  Note that
8845 generated source files that are not distributed must be declared in
8846 variables like @code{nodist_noinst_HEADERS} or
8847 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
8849 A @code{tags} rule will be output at the topmost directory of a
8850 multi-directory package.  When run from this topmost directory,
8851 @samp{make tags} will generate a @file{TAGS} file that includes by
8852 reference all @file{TAGS} files from subdirectories.
8854 The @code{tags} rule will also be generated if the variable
8855 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
8856 directories that contain taggable source that @command{etags} does
8857 not understand.  The user can use the @code{ETAGSFLAGS} to pass
8858 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
8859 available for use in @file{Makefile.am}.
8860 @vindex ETAGS_ARGS
8861 @vindex ETAGSFLAGS
8862 @vindex AM_ETAGSFLAGS
8864 Here is how Automake generates tags for its source, and for nodes in its
8865 Texinfo file:
8867 @example
8868 ETAGS_ARGS = automake.in --lang=none \
8869  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
8870 @end example
8872 If you add file names to @code{ETAGS_ARGS}, you will probably also
8873 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
8874 are added directly to the dependencies for the @code{tags} rule.
8875 @vindex TAGS_DEPENDENCIES
8877 Automake also generates a @code{ctags} rule that can be used to
8878 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
8879 is the name of the program to invoke (by default @command{ctags});
8880 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
8881 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
8883 Automake will also generate an @code{ID} rule that will run
8884 @command{mkid} on the source.  This is only supported on a
8885 directory-by-directory basis.
8886 @trindex id
8888 Finally, Automake also emits rules to support the
8889 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
8890 The @code{GTAGS} rule runs Global Tags and puts the
8891 result in the top build directory.  The variable @code{GTAGS_ARGS}
8892 holds arguments that are passed to @command{gtags}.
8893 @vindex GTAGS_ARGS
8896 @node Suffixes
8897 @section Handling new file extensions
8899 @cindex Adding new @code{SUFFIXES}
8900 @cindex @code{SUFFIXES}, adding
8901 @vindex SUFFIXES
8903 It is sometimes useful to introduce a new implicit rule to handle a file
8904 type that Automake does not know about.
8906 For instance, suppose you had a compiler that could compile @file{.foo}
8907 files to @file{.o} files.  You would simply define a suffix rule for
8908 your language:
8910 @example
8911 .foo.o:
8912         foocc -c -o $@@ $<
8913 @end example
8915 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
8916 variable and expect the correct results:
8918 @example
8919 bin_PROGRAMS = doit
8920 doit_SOURCES = doit.foo
8921 @end example
8923 This was the simpler and more common case.  In other cases, you will
8924 have to help Automake to figure out which extensions you are defining your
8925 suffix rule for.  This usually happens when your extension does not
8926 start with a dot.  Then, all you have to do is to put a list of new
8927 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
8928 implicit rule.
8930 For instance, the following definition prevents Automake from misinterpreting
8931 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
8932 @file{.cpp} files.
8934 @example
8935 SUFFIXES = .idl C.cpp
8936 .idlC.cpp:
8937         # whatever
8938 @end example
8940 As you may have noted, the @code{SUFFIXES} variable behaves like the
8941 @code{.SUFFIXES} special target of @command{make}.  You should not touch
8942 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
8943 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
8944 @code{SUFFIXES} go at the start of the generated suffixes list, followed
8945 by Automake generated suffixes not already in the list.
8947 @node Multilibs
8948 @section Support for Multilibs
8950 Automake has support for an obscure feature called multilibs.  A
8951 @dfn{multilib} is a library that is built for multiple different ABIs
8952 at a single time; each time the library is built with a different target
8953 flag combination.  This is only useful when the library is intended to
8954 be cross-compiled, and it is almost exclusively used for compiler
8955 support libraries.
8957 The multilib support is still experimental.  Only use it if you are
8958 familiar with multilibs and can debug problems you might encounter.
8961 @node Include
8962 @chapter Include
8964 @cmindex include
8965 @cindex Including @file{Makefile} fragment
8966 @cindex @file{Makefile} fragment, including
8968 Automake supports an @code{include} directive that  can be used to
8969 include other @file{Makefile} fragments when @command{automake} is run.
8970 Note that these fragments are read and interpreted by @command{automake},
8971 not by @command{make}.  As with conditionals, @command{make} has no idea that
8972 @code{include} is in use.
8974 There are two forms of @code{include}:
8976 @table @code
8977 @item include $(srcdir)/file
8978 Include a fragment that is found relative to the current source
8979 directory.
8981 @item include $(top_srcdir)/file
8982 Include a fragment that is found relative to the top source directory.
8983 @end table
8985 Note that if a fragment is included inside a conditional, then the
8986 condition applies to the entire contents of that fragment.
8988 Makefile fragments included this way are always distributed because
8989 they are needed to rebuild @file{Makefile.in}.
8991 @node Conditionals
8992 @chapter Conditionals
8994 @cindex Conditionals
8996 Automake supports a simple type of conditionals.
8998 @unnumberedsec Usage
9000 @acindex AM_CONDITIONAL
9001 Before using a conditional, you must define it by using
9002 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
9004 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
9005 The conditional name, @var{conditional}, should be a simple string
9006 starting with a letter and containing only letters, digits, and
9007 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
9008 that are reserved by Automake.
9010 The shell @var{condition} (suitable for use in a shell @code{if}
9011 statement) is evaluated when @command{configure} is run.  Note that you
9012 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
9013 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
9014 conditionally (e.g., in a shell @code{if} statement), then the result
9015 will confuse automake.
9016 @end defmac
9018 @cindex @option{--enable-debug}, example
9019 @cindex Example conditional @option{--enable-debug}
9020 @cindex Conditional example, @option{--enable-debug}
9022 Conditionals typically depend upon options that the user provides to
9023 the @command{configure} script.  Here is an example of how to write a
9024 conditional that is true if the user uses the @option{--enable-debug}
9025 option.
9027 @example
9028 AC_ARG_ENABLE([debug],
9029 [  --enable-debug    Turn on debugging],
9030 [case "$@{enableval@}" in
9031   yes) debug=true ;;
9032   no)  debug=false ;;
9033   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
9034 esac],[debug=false])
9035 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
9036 @end example
9038 Here is an example of how to use that conditional in @file{Makefile.am}:
9040 @cmindex if
9041 @cmindex endif
9042 @cmindex else
9044 @example
9045 if DEBUG
9046 DBG = debug
9047 else
9048 DBG =
9049 endif
9050 noinst_PROGRAMS = $(DBG)
9051 @end example
9053 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
9054 (@pxref{Conditional Programs}).
9056 You may only test a single variable in an @code{if} statement, possibly
9057 negated using @samp{!}.  The @code{else} statement may be omitted.
9058 Conditionals may be nested to any depth.  You may specify an argument to
9059 @code{else} in which case it must be the negation of the condition used
9060 for the current @code{if}.  Similarly you may specify the condition
9061 that is closed by an @code{end}:
9063 @example
9064 if DEBUG
9065 DBG = debug
9066 else !DEBUG
9067 DBG =
9068 endif !DEBUG
9069 @end example
9071 @noindent
9072 Unbalanced conditions are errors.
9074 The @code{else} branch of the above two examples could be omitted,
9075 since assigning the empty string to an otherwise undefined variable
9076 makes no difference.
9078 @acindex AM_COND_IF
9079 In order to allow access to the condition registered by
9080 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
9081 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
9083 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
9084 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
9085 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
9086 it will cause @command{automake} to output the rules for the respective
9087 files only for the given condition.
9088 @end defmac
9090 @code{AM_COND_IF} macros may be nested when m4 quotation is used
9091 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
9093 @cindex Example conditional @code{AC_CONFIG_FILES}
9094 @cindex @code{AC_CONFIG_FILES}, conditional
9096 Here is an example of how to define a conditional config file:
9098 @example
9099 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
9100 AM_COND_IF([SHELL_WRAPPER],
9101            [AC_CONFIG_FILES([wrapper:wrapper.in])])
9102 @end example
9104 @unnumberedsec Portability
9106 Note that conditionals in Automake are not the same as conditionals in
9107 GNU Make.  Automake conditionals are checked at configure time by the
9108 @file{configure} script, and affect the translation from
9109 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
9110 to @file{configure} and on results that @file{configure} has discovered
9111 about the host system.  GNU Make conditionals are checked at @command{make}
9112 time, and are based on variables passed to the make program or defined
9113 in the @file{Makefile}.
9115 Automake conditionals will work with any make program.
9117 @unnumberedsec Limits
9119 Conditionals should enclose complete statements like variables or
9120 rules definitions.  Automake cannot deal with conditionals used inside
9121 a variable definition, for instance, and is not even able to diagnose
9122 this situation.  The following example would not work:
9124 @example
9125 # This syntax is not understood by Automake
9126 AM_CPPFLAGS = \
9127   -DFEATURE_A \
9128 if WANT_DEBUG
9129   -DDEBUG \
9130 endif
9131   -DFEATURE_B
9132 @end example
9134 However the intended definition of @code{AM_CPPFLAGS} can be achieved
9135 with
9137 @example
9138 if WANT_DEBUG
9139   DEBUGFLAGS = -DDEBUG
9140 endif
9141 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
9142 @end example
9144 @noindent or
9146 @example
9147 AM_CPPFLAGS = -DFEATURE_A
9148 if WANT_DEBUG
9149 AM_CPPFLAGS += -DDEBUG
9150 endif
9151 AM_CPPFLAGS += -DFEATURE_B
9152 @end example
9154 @node Gnits
9155 @chapter The effect of @option{--gnu} and @option{--gnits}
9157 @cindex @option{--gnu}, required files
9158 @cindex @option{--gnu}, complete description
9160 The @option{--gnu} option (or @option{gnu} in the
9161 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
9162 the following:
9164 @itemize @bullet
9165 @item
9166 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
9167 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
9168 or @file{COPYING}, are required at the topmost directory of the package.
9170 If the @option{--add-missing} option is given, @command{automake} will
9171 add a generic version of the @file{INSTALL} file as well as the
9172 @file{COPYING} file containing the text of the current version of the
9173 GNU General Public License existing at the time of this Automake release
9174 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
9175 However, an existing @file{COPYING} file will never be overwritten by
9176 @command{automake}.
9178 @item
9179 The options @option{no-installman} and @option{no-installinfo} are
9180 prohibited.
9181 @end itemize
9183 Note that this option will be extended in the future to do even more
9184 checking; it is advisable to be familiar with the precise requirements
9185 of the GNU standards.  Also, @option{--gnu} can require certain
9186 non-standard GNU programs to exist for use by various maintainer-only
9187 rules; for instance, in the future @command{pathchk} might be required for
9188 @samp{make dist}.
9190 @cindex @option{--gnits}, complete description
9192 The @option{--gnits} option does everything that @option{--gnu} does, and
9193 checks the following as well:
9195 @itemize @bullet
9196 @item
9197 @samp{make installcheck} will check to make sure that the @option{--help}
9198 and @option{--version} really print a usage message and a version string,
9199 respectively.  This is the @option{std-options} option (@pxref{Options}).
9201 @item
9202 @samp{make dist} will check to make sure the @file{NEWS} file has been
9203 updated to the current version.
9205 @item
9206 @code{VERSION} is checked to make sure its format complies with Gnits
9207 standards.
9208 @c FIXME xref when standards are finished
9210 @item
9211 @cindex @file{README-alpha}
9212 If @code{VERSION} indicates that this is an alpha release, and the file
9213 @file{README-alpha} appears in the topmost directory of a package, then
9214 it is included in the distribution.  This is done in @option{--gnits}
9215 mode, and no other, because this mode is the only one where version
9216 number formats are constrained, and hence the only mode where Automake
9217 can automatically determine whether @file{README-alpha} should be
9218 included.
9220 @item
9221 The file @file{THANKS} is required.
9222 @end itemize
9225 @node Cygnus
9226 @chapter The effect of @option{--cygnus}
9228 @cindex @option{cygnus} strictness
9230 Some packages, notably GNU GCC and GNU gdb, have a build environment
9231 originally written at Cygnus Support (subsequently renamed Cygnus
9232 Solutions, and then later purchased by Red Hat).  Packages with this
9233 ancestry are sometimes referred to as ``Cygnus'' trees.
9235 A Cygnus tree has slightly different rules for how a
9236 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
9237 @command{automake} will cause any generated @file{Makefile.in} to
9238 comply with Cygnus rules.
9240 Here are the precise effects of @option{--cygnus}:
9242 @itemize @bullet
9243 @item
9244 Info files are always created in the build directory, and not in the
9245 source directory.
9247 @item
9248 @file{texinfo.tex} is not required if a Texinfo source file is
9249 specified.  The assumption is that the file will be supplied, but in a
9250 place that Automake cannot find.  This assumption is an artifact of how
9251 Cygnus packages are typically bundled.
9253 @item
9254 @samp{make dist} is not supported, and the rules for it are not
9255 generated.  Cygnus-style trees use their own distribution mechanism.
9257 @item
9258 Certain tools will be searched for in the build tree as well as in the
9259 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
9260 @command{makeinfo} and @command{texi2dvi}.
9262 @item
9263 @option{--foreign} is implied.
9265 @item
9266 The options @option{no-installinfo} and @option{no-dependencies} are
9267 implied.
9269 @item
9270 The macros @code{AM_MAINTAINER_MODE} and @code{AM_CYGWIN32} are
9271 required.
9273 @item
9274 The @code{check} target doesn't depend on @code{all}.
9275 @end itemize
9277 GNU maintainers are advised to use @option{gnu} strictness in preference
9278 to the special Cygnus mode.  Some day, perhaps, the differences between
9279 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
9280 more standards compliant).  At that time the special Cygnus mode will be
9281 removed.
9284 @node Not Enough
9285 @chapter When Automake Isn't Enough
9287 In some situations, where Automake is not up to one task, one has to
9288 resort to handwritten rules or even handwritten @file{Makefile}s.
9290 @menu
9291 * Extending::                   Adding new rules or overriding existing ones.
9292 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
9293 @end menu
9295 @node Extending
9296 @section Extending Automake Rules
9298 With some minor exceptions (for example @code{_PROGRAMS} variables,
9299 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
9300 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
9301 @file{Makefile.in} verbatim.
9303 @cindex copying semantics
9305 These copying semantics mean that many problems can be worked around
9306 by simply adding some @command{make} variables and rules to
9307 @file{Makefile.am}.  Automake will ignore these additions.
9309 @cindex conflicting definitions
9310 @cindex rules, conflicting
9311 @cindex variables, conflicting
9312 @cindex definitions, conflicts
9314 Since a @file{Makefile.in} is built from data gathered from three
9315 different places (@file{Makefile.am}, @file{configure.ac}, and
9316 @command{automake} itself), it is possible to have conflicting
9317 definitions of rules or variables.  When building @file{Makefile.in}
9318 the following priorities are respected by @command{automake} to ensure
9319 the user always has the last word.  User defined variables in
9320 @file{Makefile.am} have priority over variables @code{AC_SUBST}ed from
9321 @file{configure.ac}, and @code{AC_SUBST}ed variables have priority
9322 over @command{automake}-defined variables.  As far as rules are
9323 concerned, a user-defined rule overrides any
9324 @command{automake}-defined rule for the same target.
9326 @cindex overriding rules
9327 @cindex overriding semantics
9328 @cindex rules, overriding
9330 These overriding semantics make it possible to fine tune some default
9331 settings of Automake, or replace some of its rules.  Overriding
9332 Automake rules is often inadvisable, particularly in the topmost
9333 directory of a package with subdirectories.  The @option{-Woverride}
9334 option (@pxref{Invoking Automake}) comes in handy to catch overridden
9335 definitions.
9337 Note that Automake does not make any distinction between rules with
9338 commands and rules that only specify dependencies.  So it is not
9339 possible to append new dependencies to an @command{automake}-defined
9340 target without redefining the entire rule.
9342 @cindex @option{-local} targets
9343 @cindex local targets
9345 However, various useful targets have a @samp{-local} version you can
9346 specify in your @file{Makefile.am}.  Automake will supplement the
9347 standard target with these user-supplied targets.
9349 @trindex  all
9350 @trindex  all-local
9351 @trindex  info
9352 @trindex  info-local
9353 @trindex  dvi
9354 @trindex  dvi-local
9355 @trindex  ps
9356 @trindex  ps-local
9357 @trindex  pdf
9358 @trindex  pdf-local
9359 @trindex  html
9360 @trindex  html-local
9361 @trindex  check
9362 @trindex  check-local
9363 @trindex  install
9364 @trindex  install-data
9365 @trindex  install-data-local
9366 @trindex  install-dvi
9367 @trindex  install-dvi-local
9368 @trindex  install-exec
9369 @trindex  install-exec-local
9370 @trindex  install-html
9371 @trindex  install-html-local
9372 @trindex  install-info
9373 @trindex  install-info-local
9374 @trindex  install-pdf
9375 @trindex  install-pdf-local
9376 @trindex  install-ps
9377 @trindex  install-ps-local
9378 @trindex  uninstall
9379 @trindex  uninstall-local
9380 @trindex  mostlyclean
9381 @trindex  mostlyclean-local
9382 @trindex  clean
9383 @trindex  clean-local
9384 @trindex  distclean
9385 @trindex  distclean-local
9386 @trindex  installdirs
9387 @trindex  installdirs-local
9388 @trindex  installcheck
9389 @trindex  installcheck-local
9391 The targets that support a local version are @code{all}, @code{info},
9392 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
9393 @code{install-data}, @code{install-dvi}, @code{install-exec},
9394 @code{install-html}, @code{install-info}, @code{install-pdf},
9395 @code{install-ps}, @code{uninstall}, @code{installdirs},
9396 @code{installcheck} and the various @code{clean} targets
9397 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
9398 @code{maintainer-clean}).
9400 Note that there are no @code{uninstall-exec-local} or
9401 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
9402 It doesn't make sense to uninstall just data or just executables.
9404 For instance, here is one way to erase a subdirectory during
9405 @samp{make clean} (@pxref{Clean}).
9407 @example
9408 clean-local:
9409         -rm -rf testSubDir
9410 @end example
9412 You may be tempted to use @code{install-data-local} to install a file
9413 to some hard-coded location, but you should avoid this
9414 (@pxref{Hard-Coded Install Paths}).
9416 With the @code{-local} targets, there is no particular guarantee of
9417 execution order; typically, they are run early, but with parallel
9418 make, there is no way to be sure of that.
9420 @cindex @option{-hook} targets
9421 @cindex hook targets
9422 @trindex install-data-hook
9423 @trindex install-exec-hook
9424 @trindex uninstall-hook
9425 @trindex dist-hook
9427 In contrast, some rules also have a way to run another rule, called a
9428 @dfn{hook}; hooks are always executed after the main rule's work is done.
9429 The hook is named after the principal target, with @samp{-hook} appended.
9430 The targets allowing hooks are @code{install-data},
9431 @code{install-exec}, @code{uninstall}, @code{dist}, and
9432 @code{distcheck}.
9434 For instance, here is how to create a hard link to an installed program:
9436 @example
9437 install-exec-hook:
9438         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
9439            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
9440 @end example
9442 Although cheaper and more portable than symbolic links, hard links
9443 will not work everywhere (for instance, OS/2 does not have
9444 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
9445 @command{ln} does not work.  An easy way, if symbolic links are
9446 acceptable to you, is to add @code{AC_PROG_LN_S} to
9447 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
9448 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
9449 @file{Makefile.am}.
9451 @cindex versioned binaries, installing
9452 @cindex installing versioned binaries
9453 @cindex @code{LN_S} example
9454 For instance, here is how you could install a versioned copy of a
9455 program using @samp{$(LN_S)}:
9457 @example
9458 install-exec-hook:
9459         cd $(DESTDIR)$(bindir) && \
9460           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
9461           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
9462 @end example
9464 Note that we rename the program so that a new version will erase the
9465 symbolic link, not the real binary.  Also we @command{cd} into the
9466 destination directory in order to create relative links.
9468 When writing @code{install-exec-hook} or @code{install-data-hook},
9469 please bear in mind that the exec/data distinction is based on the
9470 installation directory, not on the primary used (@pxref{Install}).  So
9471 a @code{foo_SCRIPTS} will be installed by @code{install-data}, and a
9472 @code{barexec_SCRIPTS} will be installed by @code{install-exec}.  You
9473 should define your hooks consequently.
9475 @c FIXME should include discussion of variables you can use in these
9476 @c rules
9478 @node Third-Party Makefiles
9479 @section Third-Party @file{Makefile}s
9481 @cindex Third-party packages, interfacing with
9482 @cindex Interfacing with third-party packages
9484 In most projects all @file{Makefile}s are generated by Automake.  In
9485 some cases, however, projects need to embed subdirectories with
9486 handwritten @file{Makefile}s.  For instance, one subdirectory could be
9487 a third-party project with its own build system, not using Automake.
9489 It is possible to list arbitrary directories in @code{SUBDIRS} or
9490 @code{DIST_SUBDIRS} provided each of these directories has a
9491 @file{Makefile} that recognizes all the following recursive targets.
9493 @cindex recursive targets and third-party @file{Makefile}s
9494 When a user runs one of these targets, that target is run recursively
9495 in all subdirectories.  This is why it is important that even
9496 third-party @file{Makefile}s support them.
9498 @table @code
9499 @item all
9500 Compile the entire package.  This is the default target in
9501 Automake-generated @file{Makefile}s, but it does not need to be the
9502 default in third-party @file{Makefile}s.
9504 @item distdir
9505 @trindex distdir
9506 @vindex distdir
9507 @vindex top_distdir
9508 Copy files to distribute into @samp{$(distdir)}, before a tarball is
9509 constructed.  Of course this target is not required if the
9510 @option{no-dist} option (@pxref{Options}) is used.
9512 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
9513 (@pxref{Dist}) will be passed from the outer package to the subpackage
9514 when the @code{distdir} target is invoked.  These two variables have
9515 been adjusted for the directory that is being recursed into, so they
9516 are ready to use.
9518 @item install
9519 @itemx install-data
9520 @itemx install-exec
9521 @itemx uninstall
9522 Install or uninstall files (@pxref{Install}).
9524 @item install-dvi
9525 @itemx install-html
9526 @itemx install-info
9527 @itemx install-ps
9528 @itemx install-pdf
9529 Install only some specific documentation format (@pxref{Texinfo}).
9531 @item installdirs
9532 Create install directories, but do not install any files.
9534 @item check
9535 @itemx installcheck
9536 Check the package (@pxref{Tests}).
9538 @item mostlyclean
9539 @itemx clean
9540 @itemx distclean
9541 @itemx maintainer-clean
9542 Cleaning rules (@pxref{Clean}).
9544 @item dvi
9545 @itemx pdf
9546 @itemx ps
9547 @itemx info
9548 @itemx html
9549 Build the documentation in various formats (@pxref{Texinfo}).
9551 @item tags
9552 @itemx ctags
9553 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
9554 @end table
9556 If you have ever used Gettext in a project, this is a good example of
9557 how third-party @file{Makefile}s can be used with Automake.  The
9558 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
9559 @file{intl/} directories are handwritten @file{Makefile}s that
9560 implement all these targets.  That way they can be added to
9561 @code{SUBDIRS} in Automake packages.
9563 Directories that are only listed in @code{DIST_SUBDIRS} but not in
9564 @code{SUBDIRS} need only the @code{distclean},
9565 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
9566 Subdirectories}).
9568 Usually, many of these rules are irrelevant to the third-party
9569 subproject, but they are required for the whole package to work.  It's
9570 OK to have a rule that does nothing, so if you are integrating a
9571 third-party project with no documentation or tag support, you could
9572 simply augment its @file{Makefile} as follows:
9574 @example
9575 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
9576 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
9577 $(EMPTY_AUTOMAKE_TARGETS):
9578 @end example
9580 Another aspect of integrating third-party build systems is whether
9581 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
9582 subpackage does not support VPATH builds the whole package will not
9583 support VPATH builds.  This in turns means that @samp{make distcheck}
9584 will not work, because it relies on VPATH builds.  Some people can
9585 live without this (actually, many Automake users have never heard of
9586 @samp{make distcheck}).  Other people may prefer to revamp the
9587 existing @file{Makefile}s to support VPATH@.  Doing so does not
9588 necessarily require Automake, only Autoconf is needed (@pxref{Build
9589 Directories, , Build Directories, autoconf, The Autoconf Manual}).
9590 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
9591 and @samp{@@top_builddir@@} are defined by @file{configure} when it
9592 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
9593 Output Variables, autoconf, The Autoconf Manual}), they are not
9594 computed by the Makefile like the aforementioned @samp{$(distdir)} and
9595 @samp{$(top_distdir)} variables.
9597 It is sometimes inconvenient to modify a third-party @file{Makefile}
9598 to introduce the above required targets.  For instance, one may want to
9599 keep the third-party sources untouched to ease upgrades to new
9600 versions.
9602 @cindex @file{GNUmakefile} including @file{Makefile}
9603 Here are two other ideas.  If GNU make is assumed, one possibility is
9604 to add to that subdirectory a @file{GNUmakefile} that defines the
9605 required targets and includes the third-party @file{Makefile}.  For
9606 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
9607 directory; the easiest way to do this is to write a
9608 @file{GNUmakefile.in} instead, and have it processed with
9609 @code{AC_CONFIG_FILES} from the outer package.  For example if we
9610 assume @file{Makefile} defines all targets except the documentation
9611 targets, and that the @code{check} target is actually called
9612 @code{test}, we could write @file{GNUmakefile} (or
9613 @file{GNUmakefile.in}) like this:
9615 @example
9616 # First, include the real Makefile
9617 include Makefile
9618 # Then, define the other targets needed by Automake Makefiles.
9619 .PHONY: dvi pdf ps info html check
9620 dvi pdf ps info html:
9621 check: test
9622 @end example
9624 @cindex Proxy @file{Makefile} for third-party packages
9625 A similar idea that does not use @code{include} is to write a proxy
9626 @file{Makefile} that dispatches rules to the real @file{Makefile},
9627 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
9628 it's OK to rename the original @file{Makefile}) or with @samp{cd
9629 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
9630 subdirectory project one directory deeper).  The good news is that
9631 this proxy @file{Makefile} can be generated with Automake.  All we
9632 need are @option{-local} targets (@pxref{Extending}) that perform the
9633 dispatch.  Of course the other Automake features are available, so you
9634 could decide to let Automake perform distribution or installation.
9635 Here is a possible @file{Makefile.am}:
9637 @example
9638 all-local:
9639         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
9640 check-local:
9641         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
9642 clean-local:
9643         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
9645 # Assuming the package knows how to install itself
9646 install-data-local:
9647         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
9648 install-exec-local:
9649         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
9650 uninstall-local:
9651         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
9653 # Distribute files from here.
9654 EXTRA_DIST = subdir/Makefile subdir/program.c ...
9655 @end example
9657 Pushing this idea to the extreme, it is also possible to ignore the
9658 subproject build system and build everything from this proxy
9659 @file{Makefile.am}.  This might sound very sensible if you need VPATH
9660 builds but the subproject does not support them.
9662 @node Distributing
9663 @chapter Distributing @file{Makefile.in}s
9665 Automake places no restrictions on the distribution of the resulting
9666 @file{Makefile.in}s.  We still encourage software authors to
9667 distribute their work under terms like those of the GPL, but doing so
9668 is not required to use Automake.
9670 Some of the files that can be automatically installed via the
9671 @option{--add-missing} switch do fall under the GPL@.  However, these also
9672 have a special exception allowing you to distribute them with your
9673 package, regardless of the licensing you choose.
9676 @node API versioning
9677 @chapter Automake API versioning
9679 New Automake releases usually include bug fixes and new features.
9680 Unfortunately they may also introduce new bugs and incompatibilities.
9681 This makes four reasons why a package may require a particular Automake
9682 version.
9684 Things get worse when maintaining a large tree of packages, each one
9685 requiring a different version of Automake.  In the past, this meant that
9686 any developer (and sometimes users) had to install several versions of
9687 Automake in different places, and switch @samp{$PATH} appropriately for
9688 each package.
9690 Starting with version 1.6, Automake installs versioned binaries.  This
9691 means you can install several versions of Automake in the same
9692 @samp{$prefix}, and can select an arbitrary Automake version by running
9693 @command{automake-1.6} or @command{automake-1.7} without juggling with
9694 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
9695 will use @command{automake-1.6} explicitly in their rebuild rules.
9697 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
9698 not Automake's version.  If a bug fix release is made, for instance
9699 Automake 1.6.1, the API version will remain 1.6.  This means that a
9700 package that works with Automake 1.6 should also work with 1.6.1; after
9701 all, this is what people expect from bug fix releases.
9703 If your package relies on a feature or a bug fix introduced in
9704 a release, you can pass this version as an option to Automake to ensure
9705 older releases will not be used.  For instance, use this in your
9706 @file{configure.ac}:
9708 @example
9709   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
9710 @end example
9711 @noindent
9712 or, in a particular @file{Makefile.am}:
9714 @example
9715   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
9716 @end example
9717 @noindent
9718 Automake will print an error message if its version is
9719 older than the requested version.
9722 @heading What is in the API
9724 Automake's programming interface is not easy to define.  Basically it
9725 should include at least all @strong{documented} variables and targets
9726 that a @file{Makefile.am} author can use, any behavior associated with
9727 them (e.g., the places where @samp{-hook}'s are run), the command line
9728 interface of @command{automake} and @command{aclocal}, @dots{}
9730 @heading What is not in the API
9732 Every undocumented variable, target, or command line option, is not part
9733 of the API@.  You should avoid using them, as they could change from one
9734 version to the other (even in bug fix releases, if this helps to fix a
9735 bug).
9737 If it turns out you need to use such a undocumented feature, contact
9738 @email{automake@@gnu.org} and try to get it documented and exercised by
9739 the test-suite.
9741 @node Upgrading
9742 @chapter Upgrading a Package to a Newer Automake Version
9744 Automake maintains three kind of files in a package.
9746 @itemize
9747 @item @file{aclocal.m4}
9748 @item @file{Makefile.in}s
9749 @item auxiliary tools like @file{install-sh} or @file{py-compile}
9750 @end itemize
9752 @file{aclocal.m4} is generated by @command{aclocal} and contains some
9753 Automake-supplied M4 macros.  Auxiliary tools are installed by
9754 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
9755 built from @file{Makefile.am} by @command{automake}, and rely on the
9756 definitions of the M4 macros put in @file{aclocal.m4} as well as the
9757 behavior of the auxiliary tools installed.
9759 Because all these files are closely related, it is important to
9760 regenerate all of them when upgrading to a newer Automake release.
9761 The usual way to do that is
9763 @example
9764 aclocal # with any option needed (such a -I m4)
9765 autoconf
9766 automake --add-missing --force-missing
9767 @end example
9769 @noindent
9770 or more conveniently:
9772 @example
9773 autoreconf -vfi
9774 @end example
9776 The use of @option{--force-missing} ensures that auxiliary tools will be
9777 overridden by new versions (@pxref{Invoking Automake}).
9779 It is important to regenerate all these files each time Automake is
9780 upgraded, even between bug fixes releases.  For instance, it is not
9781 unusual for a bug fix to involve changes to both the rules generated
9782 in @file{Makefile.in} and the supporting M4 macros copied to
9783 @file{aclocal.m4}.
9785 Presently @command{automake} is able to diagnose situations where
9786 @file{aclocal.m4} has been generated with another version of
9787 @command{aclocal}.  However it never checks whether auxiliary scripts
9788 are up-to-date.  In other words, @command{automake} will tell you when
9789 @command{aclocal} needs to be rerun, but it will never diagnose a
9790 missing @option{--force-missing}.
9792 Before upgrading to a new major release, it is a good idea to read the
9793 file @file{NEWS}.  This file lists all changes between releases: new
9794 features, obsolete constructs, known incompatibilities, and
9795 workarounds.
9797 @node FAQ
9798 @chapter Frequently Asked Questions about Automake
9800 This chapter covers some questions that often come up on the mailing
9801 lists.
9803 @menu
9804 * CVS::                         CVS and generated files
9805 * maintainer-mode::             missing and AM_MAINTAINER_MODE
9806 * wildcards::                   Why doesn't Automake support wildcards?
9807 * limitations on file names::   Limitations on source and installed file names
9808 * distcleancheck::              Files left in build directory after distclean
9809 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
9810 * renamed objects::             Why are object files sometimes renamed?
9811 * Per-Object Flags::            How to simulate per-object flags?
9812 * Multiple Outputs::            Writing rules for tools with many output files
9813 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
9814 @end menu
9816 @node CVS
9817 @section CVS and generated files
9819 @subsection Background: distributed generated files
9820 @cindex generated files, distributed
9821 @cindex rebuild rules
9823 Packages made with Autoconf and Automake ship with some generated
9824 files like @file{configure} or @file{Makefile.in}.  These files were
9825 generated on the developer's host and are distributed so that
9826 end-users do not have to install the maintainer tools required to
9827 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
9828 or Info documentation, are usually distributed on similar grounds.
9830 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
9831 instance, @command{make} will run @command{autoconf} to rebuild
9832 @file{configure} whenever @file{configure.ac} is changed.  This makes
9833 development safer by ensuring a @file{configure} is never out-of-date
9834 with respect to @file{configure.ac}.
9836 As generated files shipped in packages are up-to-date, and because
9837 @command{tar} preserves times-tamps, these rebuild rules are not
9838 triggered when a user unpacks and builds a package.
9840 @subsection Background: CVS and timestamps
9841 @cindex timestamps and CVS
9842 @cindex CVS and timestamps
9844 Unless you use CVS keywords (in which case files must be updated at
9845 commit time), CVS preserves timestamp during @samp{cvs commit} and
9846 @samp{cvs import -d} operations.
9848 When you check out a file using @samp{cvs checkout} its timestamp is
9849 set to that of the revision that is being checked out.
9851 However, during @command{cvs update}, files will have the date of the
9852 update, not the original timestamp of this revision.  This is meant to
9853 make sure that @command{make} notices sources files have been updated.
9855 This timestamp shift is troublesome when both sources and generated
9856 files are kept under CVS@.  Because CVS processes files in lexical
9857 order, @file{configure.ac} will appear newer than @file{configure}
9858 after a @command{cvs update} that updates both files, even if
9859 @file{configure} was newer than @file{configure.ac} when it was
9860 checked in.  Calling @command{make} will then trigger a spurious rebuild
9861 of @file{configure}.
9863 @subsection Living with CVS in Autoconfiscated projects
9864 @cindex CVS and generated files
9865 @cindex generated files and CVS
9867 There are basically two clans amongst maintainers: those who keep all
9868 distributed files under CVS, including generated files, and those who
9869 keep generated files @emph{out} of CVS.
9871 @subsubheading All files in CVS
9873 @itemize @bullet
9874 @item
9875 The CVS repository contains all distributed files so you know exactly
9876 what is distributed, and you can checkout any prior version entirely.
9878 @item
9879 Maintainers can see how generated files evolve (for instance, you can
9880 see what happens to your @file{Makefile.in}s when you upgrade Automake
9881 and make sure they look OK).
9883 @item
9884 Users do not need the autotools to build a checkout of the project, it
9885 works just like a released tarball.
9887 @item
9888 If users use @command{cvs update} to update their copy, instead of
9889 @command{cvs checkout} to fetch a fresh one, timestamps will be
9890 inaccurate.  Some rebuild rules will be triggered and attempt to
9891 run developer tools such as @command{autoconf} or @command{automake}.
9893 Actually, calls to such tools are all wrapped into a call to the
9894 @command{missing} script discussed later (@pxref{maintainer-mode}).
9895 @command{missing} will take care of fixing the timestamps when these
9896 tools are not installed, so that the build can continue.
9898 @item
9899 In distributed development, developers are likely to have different
9900 version of the maintainer tools installed.  In this case rebuilds
9901 triggered by timestamp lossage will lead to spurious changes
9902 to generated files.  There are several solutions to this:
9904 @itemize
9905 @item
9906 All developers should use the same versions, so that the rebuilt files
9907 are identical to files in CVS@.  (This starts to be difficult when each
9908 project you work on uses different versions.)
9909 @item
9910 Or people use a script to fix the timestamp after a checkout (the GCC
9911 folks have such a script).
9912 @item
9913 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
9914 disable all these rebuild rules by default.  This is further discussed
9915 in @ref{maintainer-mode}.
9916 @end itemize
9918 @item
9919 Although we focused on spurious rebuilds, the converse can also
9920 happen.  CVS's timestamp handling can also let you think an
9921 out-of-date file is up-to-date.
9923 For instance, suppose a developer has modified @file{Makefile.am} and
9924 has rebuilt @file{Makefile.in}.  He then decides to do a last-minute
9925 change to @file{Makefile.am} right before checking in both files
9926 (without rebuilding @file{Makefile.in} to account for the change).
9928 This last change to @file{Makefile.am} makes the copy of
9929 @file{Makefile.in} out-of-date.  Since CVS processes files
9930 alphabetically, when another developer @samp{cvs update}s his or her
9931 tree, @file{Makefile.in} will happen to be newer than
9932 @file{Makefile.am}.  This other developer will not see that
9933 @file{Makefile.in} is out-of-date.
9935 @end itemize
9937 @subsubheading Generated files out of CVS
9939 One way to get CVS and @command{make} working peacefully is to never
9940 store generated files in CVS, i.e., do not CVS-control files that
9941 are @file{Makefile} targets (also called @emph{derived} files).
9943 This way developers are not annoyed by changes to generated files.  It
9944 does not matter if they all have different versions (assuming they are
9945 compatible, of course).  And finally, timestamps are not lost, changes
9946 to sources files can't be missed as in the
9947 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
9949 The drawback is that the CVS repository is not an exact copy of what
9950 is distributed and that users now need to install various development
9951 tools (maybe even specific versions) before they can build a checkout.
9952 But, after all, CVS's job is versioning, not distribution.
9954 Allowing developers to use different versions of their tools can also
9955 hide bugs during distributed development.  Indeed, developers will be
9956 using (hence testing) their own generated files, instead of the
9957 generated files that will be released actually.  The developer who
9958 prepares the tarball might be using a version of the tool that
9959 produces bogus output (for instance a non-portable C file), something
9960 other developers could have noticed if they weren't using their own
9961 versions of this tool.
9963 @subsection Third-party files
9964 @cindex CVS and third-party files
9965 @cindex third-party files and CVS
9967 Another class of files not discussed here (because they do not cause
9968 timestamp issues) are files that are shipped with a package, but
9969 maintained elsewhere.  For instance, tools like @command{gettextize}
9970 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
9971 Libtool), will install or update files in your package.
9973 These files, whether they are kept under CVS or not, raise similar
9974 concerns about version mismatch between developers' tools.  The
9975 Gettext manual has a section about this, see @ref{CVS Issues, CVS
9976 Issues, Integrating with CVS, gettext, GNU gettext tools}.
9978 @node maintainer-mode
9979 @section @command{missing} and @code{AM_MAINTAINER_MODE}
9981 @subsection @command{missing}
9982 @cindex @command{missing}, purpose
9984 The @command{missing} script is a wrapper around several maintainer
9985 tools, designed to warn users if a maintainer tool is required but
9986 missing.  Typical maintainer tools are @command{autoconf},
9987 @command{automake}, @command{bison}, etc.  Because file generated by
9988 these tools are shipped with the other sources of a package, these
9989 tools shouldn't be required during a user build and they are not
9990 checked for in @file{configure}.
9992 However, if for some reason a rebuild rule is triggered and involves a
9993 missing tool, @command{missing} will notice it and warn the user.
9994 Besides the warning, when a tool is missing, @command{missing} will
9995 attempt to fix timestamps in a way that allows the build to continue.
9996 For instance, @command{missing} will touch @file{configure} if
9997 @command{autoconf} is not installed.  When all distributed files are
9998 kept under CVS, this feature of @command{missing} allows a user
9999 @emph{with no maintainer tools} to build a package off CVS, bypassing
10000 any timestamp inconsistency implied by @samp{cvs update}.
10002 If the required tool is installed, @command{missing} will run it and
10003 won't attempt to continue after failures.  This is correct during
10004 development: developers love fixing failures.  However, users with
10005 wrong versions of maintainer tools may get an error when the rebuild
10006 rule is spuriously triggered, halting the build.  This failure to let
10007 the build continue is one of the arguments of the
10008 @code{AM_MAINTAINER_MODE} advocates.
10010 @subsection @code{AM_MAINTAINER_MODE}
10011 @cindex @code{AM_MAINTAINER_MODE}, purpose
10012 @acindex AM_MAINTAINER_MODE
10014 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
10015 "rebuild rules" should be enabled or disabled.  With
10016 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
10017 otherwise they are disabled by default.  In the latter case, if
10018 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
10019 @samp{./configure && make}, then @command{make} will *never* attempt to
10020 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
10021 I.e., this disables build rules for files that are usually distributed
10022 and that users should normally not have to update.
10024 The user can override the default setting by passing either
10025 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
10026 to @command{configure}.
10028 People use @code{AM_MAINTAINER_MODE} either because they do want their
10029 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
10030 because they simply can't stand the rebuild rules and prefer running
10031 maintainer tools explicitly.
10033 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
10034 rules conditionally.  Some developers use this feature to disable
10035 rules that need exotic tools that users may not have available.
10037 Several years ago Fran@,{c}ois Pinard pointed out several arguments
10038 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
10039 insecurity.  By removing dependencies you get non-dependable builds:
10040 changes to sources files can have no effect on generated files and this
10041 can be very confusing when unnoticed.  He adds that security shouldn't
10042 be reserved to maintainers (what @option{--enable-maintainer-mode}
10043 suggests), on the contrary.  If one user has to modify a
10044 @file{Makefile.am}, then either @file{Makefile.in} should be updated
10045 or a warning should be output (this is what Automake uses
10046 @command{missing} for) but the last thing you want is that nothing
10047 happens and the user doesn't notice it (this is what happens when
10048 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
10050 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
10051 swayed by Fran@,{c}ois's arguments, and got rid of
10052 @code{AM_MAINTAINER_MODE} in all of his packages.
10054 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
10055 it helps them working on projects where all files are kept under CVS,
10056 and because @command{missing} isn't enough if you have the wrong
10057 version of the tools.
10060 @node wildcards
10061 @section Why doesn't Automake support wildcards?
10062 @cindex wildcards
10064 Developers are lazy.  They would often like to use wildcards in
10065 @file{Makefile.am}s, so that they would not need to remember to
10066 update @file{Makefile.am}s every time they add, delete, or rename
10067 a file.
10069 There are several objections to this:
10070 @itemize
10071 @item
10072 When using CVS (or similar) developers need to remember they have to
10073 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
10074 @file{Makefile.am} accordingly quickly becomes a reflex.
10076 Conversely, if your application doesn't compile
10077 because you forgot to add a file in @file{Makefile.am}, it will help
10078 you remember to @samp{cvs add} it.
10080 @item
10081 Using wildcards makes it easy to distribute files by mistake.  For
10082 instance, some code a developer is experimenting with (a test case,
10083 say) that should not be part of the distribution.
10085 @item
10086 Using wildcards it's easy to omit some files by mistake.  For
10087 instance, one developer creates a new file, uses it in many places,
10088 but forgets to commit it.  Another developer then checks out the
10089 incomplete project and is able to run @samp{make dist} successfully,
10090 even though a file is missing. By listing files, @samp{make dist}
10091 @emph{will} complain.
10093 @item
10094 Finally, it's really hard to @emph{forget} to add a file to
10095 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
10096 not compiled or installed, so you can't even test them.
10097 @end itemize
10099 Still, these are philosophical objections, and as such you may disagree,
10100 or find enough value in wildcards to dismiss all of them.  Before you
10101 start writing a patch against Automake to teach it about wildcards,
10102 let's see the main technical issue: portability.
10104 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
10105 not portable to other @command{make} implementations.
10107 The only way Automake could support @command{$(wildcard ...)} is by
10108 expending @command{$(wildcard ...)} when @command{automake} is run.
10109 The resulting @file{Makefile.in}s would be portable since they would
10110 list all files and not use @samp{$(wildcard ...)}.  However that
10111 means developers would need to remember to run @command{automake} each
10112 time they add, delete, or rename files.
10114 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
10115 it's easier and faster to type @samp{automake; make} than to type
10116 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
10117 patch to add support for this syntax.  Some people use scripts to
10118 generate file lists in @file{Makefile.am} or in separate
10119 @file{Makefile} fragments.
10121 Even if you don't care about portability, and are tempted to use
10122 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
10123 should know there are many places where Automake needs to know exactly
10124 which files should be processed.  As Automake doesn't know how to
10125 expand @samp{$(wildcard ...)}, you cannot use it in these places.
10126 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
10127 variables as far Automake is concerned.
10129 You can get warnings about @samp{$(wildcard ...}) constructs using the
10130 @option{-Wportability} flag.
10132 @node limitations on file names
10133 @section Limitations on file names
10134 @cindex file names, limitations on
10136 Automake attempts to support all kinds of file names, even those that
10137 contain unusual characters or are unusually long.  However, some
10138 limitations are imposed by the underlying operating system and tools.
10140 Most operating systems prohibit the use of the null byte in file
10141 names, and reserve @samp{/} as a directory separator.  Also, they
10142 require that file names are properly encoded for the user's locale.
10143 Automake is subject to these limits.
10145 Portable packages should limit themselves to @acronym{POSIX} file
10146 names.  These can contain @acronym{ASCII} letters and digits,
10147 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
10148 separated by @samp{/}.  File name components cannot begin with
10149 @samp{-}.
10151 Portable POSIX file names cannot contain components that exceed a
10152 14-byte limit, but nowadays it's normally safe to assume the
10153 more-generous @acronym{XOPEN} limit of 255 bytes.  @acronym{POSIX}
10154 limits file names to 255 bytes (@acronym{XOPEN} allows 1023 bytes),
10155 but you may want to limit a source tarball to file names of 99 bytes
10156 to avoid interoperability problems with old versions of @command{tar}.
10158 If you depart from these rules (e.g., by using non-@acronym{ASCII}
10159 characters in file names, or by using lengthy file names), your
10160 installers may have problems for reasons unrelated to Automake.
10161 However, if this does not concern you, you should know about the
10162 limitations imposed by Automake itself.  These limitations are
10163 undesirable, but some of them seem to be inherent to underlying tools
10164 like Autoconf, Make, M4, and the shell.  They fall into three
10165 categories: install directories, build directories, and file names.
10167 The following characters:
10169 @example
10170 @r{newline} " # $ ' `
10171 @end example
10173 should not appear in the names of install directories.  For example,
10174 the operand of @command{configure}'s @option{--prefix} option should
10175 not contain these characters.
10177 Build directories suffer the same limitations as install directories,
10178 and in addition should not contain the following characters:
10180 @example
10181 & @@ \
10182 @end example
10184 For example, the full name of the directory containing the source
10185 files should not contain these characters.
10187 Source and installation file names like @file{main.c} are limited even
10188 further: they should conform to the @acronym{POSIX}/@acronym{XOPEN}
10189 rules described above.  In addition, if you plan to port to
10190 non-@acronym{POSIX} environments, you should avoid file names that
10191 differ only in case (e.g., @file{makefile} and @file{Makefile}).
10192 Nowadays it is no longer worth worrying about the 8.3 limits of
10193 @acronym{DOS} file systems.
10195 @node distcleancheck
10196 @section Files left in build directory after distclean
10197 @cindex @code{distclean}, diagnostic
10198 @cindex @samp{make distclean}, diagnostic
10199 @cindex dependencies and distributed files
10200 @trindex distclean
10201 @trindex distcleancheck
10203 This is a diagnostic you might encounter while running @samp{make
10204 distcheck}.
10206 As explained in @ref{Dist}, @samp{make distcheck} attempts to build
10207 and check your package for errors like this one.
10209 @samp{make distcheck} will perform a @code{VPATH} build of your
10210 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
10211 Files left in the build directory after @samp{make distclean} has run
10212 are listed after this error.
10214 This diagnostic really covers two kinds of errors:
10216 @itemize @bullet
10217 @item
10218 files that are forgotten by distclean;
10219 @item
10220 distributed files that are erroneously rebuilt.
10221 @end itemize
10223 The former left-over files are not distributed, so the fix is to mark
10224 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
10225 more explanations.
10227 The latter bug is not always easy to understand and fix, so let's
10228 proceed with an example.  Suppose our package contains a program for
10229 which we want to build a man page using @command{help2man}.  GNU
10230 @command{help2man} produces simple manual pages from the @option{--help}
10231 and @option{--version} output of other commands (@pxref{Top, , Overview,
10232 help2man, The Help2man Manual}).  Because we don't want to force our
10233 users to install @command{help2man}, we decide to distribute the
10234 generated man page using the following setup.
10236 @example
10237 # This Makefile.am is bogus.
10238 bin_PROGRAMS = foo
10239 foo_SOURCES = foo.c
10240 dist_man_MANS = foo.1
10242 foo.1: foo$(EXEEXT)
10243         help2man --output=foo.1 ./foo$(EXEEXT)
10244 @end example
10246 This will effectively distribute the man page.  However,
10247 @samp{make distcheck} will fail with:
10249 @example
10250 ERROR: files left in build directory after distclean:
10251 ./foo.1
10252 @end example
10254 Why was @file{foo.1} rebuilt?  Because although distributed,
10255 @file{foo.1} depends on a non-distributed built file:
10256 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
10257 will always appear to be newer than the distributed @file{foo.1}.
10259 @samp{make distcheck} caught an inconsistency in our package.  Our
10260 intent was to distribute @file{foo.1} so users do not need to install
10261 @command{help2man}, however since this rule causes this file to be
10262 always rebuilt, users @emph{do} need @command{help2man}.  Either we
10263 should ensure that @file{foo.1} is not rebuilt by users, or there is
10264 no point in distributing @file{foo.1}.
10266 More generally, the rule is that distributed files should never depend
10267 on non-distributed built files.  If you distribute something
10268 generated, distribute its sources.
10270 One way to fix the above example, while still distributing
10271 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
10272 assuming @command{foo --version} and @command{foo --help} do not
10273 change unless @file{foo.c} or @file{configure.ac} change, we could
10274 write the following @file{Makefile.am}:
10276 @example
10277 bin_PROGRAMS = foo
10278 foo_SOURCES = foo.c
10279 dist_man_MANS = foo.1
10281 foo.1: foo.c $(top_srcdir)/configure.ac
10282         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
10283         help2man --output=foo.1 ./foo$(EXEEXT)
10284 @end example
10286 This way, @file{foo.1} will not get rebuilt every time
10287 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
10288 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
10289 way to ensure this would be to use separate directories for binaries
10290 and man pages, and set @code{SUBDIRS} so that binaries are built
10291 before man pages.
10293 We could also decide not to distribute @file{foo.1}.  In
10294 this case it's fine to have @file{foo.1} dependent upon
10295 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
10296 However it would be impossible to build the package in a
10297 cross-compilation, because building @file{foo.1} involves
10298 an @emph{execution} of @file{foo$(EXEEXT)}.
10300 Another context where such errors are common is when distributed files
10301 are built by tools that are built by the package.  The pattern is
10302 similar:
10304 @example
10305 distributed-file: built-tools distributed-sources
10306         build-command
10307 @end example
10309 @noindent
10310 should be changed to
10312 @example
10313 distributed-file: distributed-sources
10314         $(MAKE) $(AM_MAKEFLAGS) built-tools
10315         build-command
10316 @end example
10318 @noindent
10319 or you could choose not to distribute @file{distributed-file}, if
10320 cross-compilation does not matter.
10322 The points made through these examples are worth a summary:
10324 @cartouche
10325 @itemize
10326 @item
10327 Distributed files should never depend upon non-distributed built
10328 files.
10329 @item
10330 Distributed files should be distributed with all their dependencies.
10331 @item
10332 If a file is @emph{intended} to be rebuilt by users, then there is no point
10333 in distributing it.
10334 @end itemize
10335 @end cartouche
10337 @vrindex distcleancheck_listfiles
10338 For desperate cases, it's always possible to disable this check by
10339 setting @code{distcleancheck_listfiles} as documented in @ref{Dist}.
10340 Make sure you do understand the reason why @samp{make distcheck}
10341 complains before you do this.  @code{distcleancheck_listfiles} is a
10342 way to @emph{hide} errors, not to fix them.  You can always do better.
10344 @node Flag Variables Ordering
10345 @section Flag Variables Ordering
10346 @cindex Ordering flag variables
10347 @cindex Flag variables, ordering
10349 @display
10350 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
10351 @code{mumble_CFLAGS}?
10352 @end display
10354 @display
10355 Why does @command{automake} output @code{CPPFLAGS} after
10356 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
10357 @end display
10359 @display
10360 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
10361 one @file{Makefile.am} I would like to append a new flag, however if I
10362 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
10363 flags, not appended.
10364 @end display
10366 @subsection Compile Flag Variables
10367 @cindex Flag Variables, Ordering
10368 @cindex Compile Flag Variables
10369 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
10370 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
10371 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
10372 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
10373 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
10374 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
10375 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
10376 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
10377 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
10378 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
10379 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
10380 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
10381 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
10382 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
10383 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
10384 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
10385 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
10386 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
10387 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
10388 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
10389 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
10390 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
10391 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
10392 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
10393 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
10394 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
10395 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
10396 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
10398 This section attempts to answer all the above questions.  We will
10399 mostly discuss @code{CPPFLAGS} in our examples, but actually the
10400 answer holds for all the compile flags used in Automake:
10401 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
10402 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
10403 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
10404 @code{UPCFLAGS}, and @code{YFLAGS}.
10406 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
10407 three variables that can be used to pass flags to the C preprocessor
10408 (actually these variables are also used for other languages like C++
10409 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
10410 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
10411 and @code{mumble_CPPFLAGS} is the variable specific to the
10412 @code{mumble} target (we call this a per-target variable,
10413 @pxref{Program and Library Variables}).
10415 Automake always uses two of these variables when compiling C sources
10416 files.  When compiling an object file for the @code{mumble} target,
10417 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
10418 @code{AM_CPPFLAGS} otherwise.  The second variable is always
10419 @code{CPPFLAGS}.
10421 In the following example,
10423 @example
10424 bin_PROGRAMS = foo bar
10425 foo_SOURCES = xyz.c
10426 bar_SOURCES = main.c
10427 foo_CPPFLAGS = -DFOO
10428 AM_CPPFLAGS = -DBAZ
10429 @end example
10431 @noindent
10432 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
10433 (because @file{xyz.o} is part of the @code{foo} target), while
10434 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
10435 (because there is no per-target variable for target @code{bar}).
10437 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
10438 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
10439 is a user variable, i.e., a variable that users are entitled to modify
10440 in order to compile the package.  This variable, like many others,
10441 is documented at the end of the output of @samp{configure --help}.
10443 For instance, someone who needs to add @file{/home/my/usr/include} to
10444 the C compiler's search path would configure a package with
10446 @example
10447 ./configure CPPFLAGS='-I /home/my/usr/include'
10448 @end example
10450 @noindent
10451 and this flag would be propagated to the compile rules of all
10452 @file{Makefile}s.
10454 It is also not uncommon to override a user variable at
10455 @command{make}-time.  Many installers do this with @code{prefix}, but
10456 this can be useful with compiler flags too.  For instance, if, while
10457 debugging a C++ project, you need to disable optimization in one
10458 specific object file, you can run something like
10460 @example
10461 rm file.o
10462 make CXXFLAGS=-O0 file.o
10463 make
10464 @end example
10466 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
10467 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
10468 should always have the last say.  It probably makes more sense if you
10469 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
10470 should supersede any other switch from @code{AM_CXXFLAGS} or
10471 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
10472 of @code{CXXFLAGS}).
10474 You should never redefine a user variable such as @code{CPPFLAGS} in
10475 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
10476 mistakes.  Even something like
10478 @example
10479 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
10480 @end example
10482 @noindent
10483 is erroneous.  Although this preserves @file{configure}'s value of
10484 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
10485 user attempts to override @code{CPPFLAGS} from the @command{make}
10486 command line.
10488 @example
10489 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
10490 @end example
10492 @noindent
10493 is all that is needed here if no per-target flags are used.
10495 You should not add options to these user variables within
10496 @file{configure} either, for the same reason.  Occasionally you need
10497 to modify these variables to perform a test, but you should reset
10498 their values afterwards.  In contrast, it is OK to modify the
10499 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
10500 them, but it is rather rare that you need to do this, unless you
10501 really want to change the default definitions of the @samp{AM_}
10502 variables in all @file{Makefile}s.
10504 What we recommend is that you define extra flags in separate
10505 variables.  For instance, you may write an Autoconf macro that computes
10506 a set of warning options for the C compiler, and @code{AC_SUBST} them
10507 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
10508 determines which compiler and which linker flags should be used to
10509 link with library @file{libfoo}, and @code{AC_SUBST} these in
10510 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
10511 @file{Makefile.am} could use these variables as follows:
10513 @example
10514 AM_CFLAGS = $(WARNINGCFLAGS)
10515 bin_PROGRAMS = prog1 prog2
10516 prog1_SOURCES = @dots{}
10517 prog2_SOURCES = @dots{}
10518 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
10519 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
10520 @end example
10522 In this example both programs will be compiled with the flags
10523 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
10524 additionally be compiled with the flags required to link with
10525 @file{libfoo}.
10527 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
10528 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
10529 every target in a @file{Makefile.in}.
10531 Using variables like this gives you full control over the ordering of
10532 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
10533 you want to negate for a particular target, you can use something like
10534 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
10535 been forcefully appended to @code{CFLAGS}, there would be no way to
10536 disable one flag.  Yet another reason to leave user variables to
10537 users.
10539 Finally, we have avoided naming the variable of the example
10540 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
10541 Automake to think that this is actually a per-target variable (like
10542 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
10544 @subsection Other Variables
10546 There are other variables in Automake that follow similar principles
10547 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
10548 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
10549 DejaGnu tests (@pxref{Tests}) use @code{RUNTESTDEFAULTFLAGS} and
10550 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
10551 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
10552 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
10553 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
10554 of these rules support per-target flags (yet).
10556 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
10557 obeys this naming scheme.  The slight difference is that
10558 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
10559 @command{make} itself.
10561 However you should not think that all variables ending with
10562 @code{FLAGS} follow this convention.  For instance,
10563 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Dist}) and
10564 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
10565 are two variables that are only useful to the maintainer and have no
10566 user counterpart.
10568 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
10569 has neither @code{AM_} nor per-target cousin.
10571 Finally you should not think that the existence of a per-target
10572 variable implies the existance of an @code{AM_} variable or of a user
10573 variable.  For instance, the @code{mumble_LDADD} per-target variable
10574 overrides the makefile-wide @code{LDADD} variable (which is not a user
10575 variable), and @code{mumble_LIBADD} exists only as a per-target
10576 variable.  @xref{Program and Library Variables}.
10579 @node renamed objects
10580 @section Why are object files sometimes renamed?
10582 This happens when per-target compilation flags are used.  Object
10583 files need to be renamed just in case they would clash with object
10584 files compiled from the same sources, but with different flags.
10585 Consider the following example.
10587 @example
10588 bin_PROGRAMS = true false
10589 true_SOURCES = generic.c
10590 true_CPPFLAGS = -DEXIT_CODE=0
10591 false_SOURCES = generic.c
10592 false_CPPFLAGS = -DEXIT_CODE=1
10593 @end example
10594 @noindent
10595 Obviously the two programs are built from the same source, but it
10596 would be bad if they shared the same object, because @file{generic.o}
10597 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
10598 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
10599 build two different objects: @file{true-generic.o} and
10600 @file{false-generic.o}.
10602 @command{automake} doesn't actually look whether source files are
10603 shared to decide if it must rename objects.  It will just rename all
10604 objects of a target as soon as it sees per-target compilation flags
10605 used.
10607 It's OK to share object files when per-target compilation flags are not
10608 used.  For instance, @file{true} and @file{false} will both use
10609 @file{version.o} in the following example.
10611 @example
10612 AM_CPPFLAGS = -DVERSION=1.0
10613 bin_PROGRAMS = true false
10614 true_SOURCES = true.c version.c
10615 false_SOURCES = false.c version.c
10616 @end example
10618 Note that the renaming of objects is also affected by the
10619 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
10622 @node Per-Object Flags
10623 @section Per-Object Flags Emulation
10624 @cindex Per-object flags, emulated
10626 @display
10627 One of my source files needs to be compiled with different flags.  How
10628 do I do?
10629 @end display
10631 Automake supports per-program and per-library compilation flags (see
10632 @ref{Program and Library Variables} and @ref{Flag Variables
10633 Ordering}).  With this you can define compilation flags that apply to
10634 all files compiled for a target.  For instance, in
10636 @example
10637 bin_PROGRAMS = foo
10638 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
10639 foo_CFLAGS = -some -flags
10640 @end example
10642 @noindent
10643 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
10644 compiled with @samp{-some -flags}.  (If you wonder about the names of
10645 these object files, see @ref{renamed objects}.)  Note that
10646 @code{foo_CFLAGS} gives the flags to use when compiling all the C
10647 sources of the @emph{program} @code{foo}, it has nothing to do with
10648 @file{foo.c} or @file{foo-foo.o} specifically.
10650 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
10651 specific flags, that none of the other files requires?  Obviously
10652 per-program flags are not directly applicable here.  Something like
10653 per-object flags are expected, i.e., flags that would be used only
10654 when creating @file{foo-foo.o}.  Automake does not support that,
10655 however this is easy to simulate using a library that contains only
10656 that object, and compiling this library with per-library flags.
10658 @example
10659 bin_PROGRAMS = foo
10660 foo_SOURCES = bar.c bar.h main.c
10661 foo_CFLAGS = -some -flags
10662 foo_LDADD = libfoo.a
10663 noinst_LIBRARIES = libfoo.a
10664 libfoo_a_SOURCES = foo.c foo.h
10665 libfoo_a_CFLAGS = -some -other -flags
10666 @end example
10668 Here @file{foo-bar.o} and @file{foo-main.o} will all be
10669 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
10670 be compiled using @samp{-some -other -flags}.  Eventually, all
10671 three objects will be linked to form @file{foo}.
10673 This trick can also be achieved using Libtool convenience libraries,
10674 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
10675 Convenience Libraries}).
10677 Another tempting idea to implement per-object flags is to override the
10678 compile rules @command{automake} would output for these files.
10679 Automake will not define a rule for a target you have defined, so you
10680 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
10681 We recommend against this, because this is error prone.  For instance,
10682 if you add such a rule to the first example, it will break the day you
10683 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
10684 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{renamed
10685 objects}).  Also in order to support dependency tracking, the two
10686 @file{.o}/@file{.obj} extensions, and all the other flags variables
10687 involved in a compilation, you will end up modifying a copy of the
10688 rule previously output by @command{automake} for this file.  If a new
10689 release of Automake generates a different rule, your copy will need to
10690 be updated by hand.
10692 @node Multiple Outputs
10693 @section Handling Tools that Produce Many Outputs
10694 @cindex multiple outputs, rules with
10695 @cindex many outputs, rules with
10696 @cindex rules with multiple outputs
10698 This section describes a @command{make} idiom that can be used when a
10699 tool produces multiple output files.  It is not specific to Automake
10700 and can be used in ordinary @file{Makefile}s.
10702 Suppose we have a program called @command{foo} that will read one file
10703 called @file{data.foo} and produce two files named @file{data.c} and
10704 @file{data.h}.  We want to write a @file{Makefile} rule that captures
10705 this one-to-two dependency.
10707 The naive rule is incorrect:
10709 @example
10710 # This is incorrect.
10711 data.c data.h: data.foo
10712         foo data.foo
10713 @end example
10715 @noindent
10716 What the above rule really says is that @file{data.c} and
10717 @file{data.h} each depend on @file{data.foo}, and can each be built by
10718 running @samp{foo data.foo}.  In other words it is equivalent to:
10720 @example
10721 # We do not want this.
10722 data.c: data.foo
10723         foo data.foo
10724 data.h: data.foo
10725         foo data.foo
10726 @end example
10728 @noindent
10729 which means that @command{foo} can be run twice.  Usually it will not
10730 be run twice, because @command{make} implementations are smart enough
10731 to check for the existence of the second file after the first one has
10732 been built; they will therefore detect that it already exists.
10733 However there are a few situations where it can run twice anyway:
10735 @itemize
10736 @item
10737 The most worrying case is when running a parallel @command{make}.  If
10738 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
10739 data.foo} commands will run concurrently.  This is harmful.
10740 @item
10741 Another case is when the dependency (here @file{data.foo}) is
10742 (or depends upon) a phony target.
10743 @end itemize
10745 A solution that works with parallel @command{make} but not with
10746 phony dependencies is the following:
10748 @example
10749 data.c data.h: data.foo
10750         foo data.foo
10751 data.h: data.c
10752 @end example
10754 @noindent
10755 The above rules are equivalent to
10757 @example
10758 data.c: data.foo
10759         foo data.foo
10760 data.h: data.foo data.c
10761         foo data.foo
10762 @end example
10763 @noindent
10764 therefore a parallel @command{make} will have to serialize the builds
10765 of @file{data.c} and @file{data.h}, and will detect that the second is
10766 no longer needed once the first is over.
10768 Using this pattern is probably enough for most cases.  However it does
10769 not scale easily to more output files (in this scheme all output files
10770 must be totally ordered by the dependency relation), so we will
10771 explore a more complicated solution.
10773 Another idea is to write the following:
10775 @example
10776 # There is still a problem with this one.
10777 data.c: data.foo
10778         foo data.foo
10779 data.h: data.c
10780 @end example
10782 @noindent
10783 The idea is that @samp{foo data.foo} is run only when @file{data.c}
10784 needs to be updated, but we further state that @file{data.h} depends
10785 upon @file{data.c}.  That way, if @file{data.h} is required and
10786 @file{data.foo} is out of date, the dependency on @file{data.c} will
10787 trigger the build.
10789 This is almost perfect, but suppose we have built @file{data.h} and
10790 @file{data.c}, and then we erase @file{data.h}.  Then, running
10791 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
10792 just state that @file{data.c} must be up-to-date with respect to
10793 @file{data.foo}, and this is already the case.
10795 What we need is a rule that forces a rebuild when @file{data.h} is
10796 missing.  Here it is:
10798 @example
10799 data.c: data.foo
10800         foo data.foo
10801 data.h: data.c
10802 ## Recover from the removal of $@@
10803         @@if test -f $@@; then :; else \
10804           rm -f data.c; \
10805           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10806         fi
10807 @end example
10809 The above scheme can be extended to handle more outputs and more
10810 inputs.  One of the outputs is selected to serve as a witness to the
10811 successful completion of the command, it depends upon all inputs, and
10812 all other outputs depend upon it.  For instance, if @command{foo}
10813 should additionally read @file{data.bar} and also produce
10814 @file{data.w} and @file{data.x}, we would write:
10816 @example
10817 data.c: data.foo data.bar
10818         foo data.foo data.bar
10819 data.h data.w data.x: data.c
10820 ## Recover from the removal of $@@
10821         @@if test -f $@@; then :; else \
10822           rm -f data.c; \
10823           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10824         fi
10825 @end example
10827 However there are now two minor problems in this setup.  One is related
10828 to the timestamp ordering of @file{data.h}, @file{data.w},
10829 @file{data.x}, and @file{data.c}.  The other one is a race condition
10830 if a parallel @command{make} attempts to run multiple instances of the
10831 recover block at once.
10833 Let us deal with the first problem.  @command{foo} outputs four files,
10834 but we do not know in which order these files are created.  Suppose
10835 that @file{data.h} is created before @file{data.c}.  Then we have a
10836 weird situation.  The next time @command{make} is run, @file{data.h}
10837 will appear older than @file{data.c}, the second rule will be
10838 triggered, a shell will be started to execute the @samp{if@dots{}fi}
10839 command, but actually it will just execute the @code{then} branch,
10840 that is: nothing.  In other words, because the witness we selected is
10841 not the first file created by @command{foo}, @command{make} will start
10842 a shell to do nothing each time it is run.
10844 A simple riposte is to fix the timestamps when this happens.
10846 @example
10847 data.c: data.foo data.bar
10848         foo data.foo data.bar
10849 data.h data.w data.x: data.c
10850         @@if test -f $@@; then \
10851           touch $@@; \
10852         else \
10853 ## Recover from the removal of $@@
10854           rm -f data.c; \
10855           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10856         fi
10857 @end example
10859 Another solution is to use a different and dedicated file as witness,
10860 rather than using any of @command{foo}'s outputs.
10862 @example
10863 data.stamp: data.foo data.bar
10864         @@rm -f data.tmp
10865         @@touch data.tmp
10866         foo data.foo data.bar
10867         @@mv -f data.tmp $@@
10868 data.c data.h data.w data.x: data.stamp
10869 ## Recover from the removal of $@@
10870         @@if test -f $@@; then :; else \
10871           rm -f data.stamp; \
10872           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10873         fi
10874 @end example
10876 @file{data.tmp} is created before @command{foo} is run, so it has a
10877 timestamp older than output files output by @command{foo}.  It is then
10878 renamed to @file{data.stamp} after @command{foo} has run, because we
10879 do not want to update @file{data.stamp} if @command{foo} fails.
10881 This solution still suffers from the second problem: the race
10882 condition in the recover rule.  If, after a successful build, a user
10883 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
10884 @command{make} may start both recover rules in parallel.  If the two
10885 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
10886 data.stamp} concurrently the build is likely to fail (for instance, the
10887 two rules will create @file{data.tmp}, but only one can rename it).
10889 Admittedly, such a weird situation does not arise during ordinary
10890 builds.  It occurs only when the build tree is mutilated.  Here
10891 @file{data.c} and @file{data.h} have been explicitly removed without
10892 also removing @file{data.stamp} and the other output files.
10893 @code{make clean; make} will always recover from these situations even
10894 with parallel makes, so you may decide that the recover rule is solely
10895 to help non-parallel make users and leave things as-is.  Fixing this
10896 requires some locking mechanism to ensure only one instance of the
10897 recover rule rebuilds @file{data.stamp}.  One could imagine something
10898 along the following lines.
10900 @example
10901 data.c data.h data.w data.x: data.stamp
10902 ## Recover from the removal of $@@
10903         @@if test -f $@@; then :; else \
10904           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
10905 ## mkdir is a portable test-and-set
10906           if mkdir data.lock 2>/dev/null; then \
10907 ## This code is being executed by the first process.
10908             rm -f data.stamp; \
10909             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10910             result=$$?; rm -rf data.lock; exit $$result; \
10911           else \
10912 ## This code is being executed by the follower processes.
10913 ## Wait until the first process is done.
10914             while test -d data.lock; do sleep 1; done; \
10915 ## Succeed if and only if the first process succeeded.
10916             test -f data.stamp; \
10917           fi; \
10918         fi
10919 @end example
10921 Using a dedicated witness, like @file{data.stamp}, is very handy when
10922 the list of output files is not known beforehand.  As an illustration,
10923 consider the following rules to compile many @file{*.el} files into
10924 @file{*.elc} files in a single command.  It does not matter how
10925 @code{ELFILES} is defined (as long as it is not empty: empty targets
10926 are not accepted by POSIX).
10928 @example
10929 ELFILES = one.el two.el three.el @dots{}
10930 ELCFILES = $(ELFILES:=c)
10932 elc-stamp: $(ELFILES)
10933         @@rm -f elc-temp
10934         @@touch elc-temp
10935         $(elisp_comp) $(ELFILES)
10936         @@mv -f elc-temp $@@
10938 $(ELCFILES): elc-stamp
10939 ## Recover from the removal of $@@
10940         @@if test -f $@@; then :; else \
10941           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
10942           if mkdir elc-lock 2>/dev/null; then \
10943 ## This code is being executed by the first process.
10944             rm -f elc-stamp; \
10945             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
10946             rmdir elc-lock; \
10947           else \
10948 ## This code is being executed by the follower processes.
10949 ## Wait until the first process is done.
10950             while test -d elc-lock; do sleep 1; done; \
10951 ## Succeed if and only if the first process succeeded.
10952             test -f elc-stamp; exit $$?; \
10953           fi; \
10954         fi
10955 @end example
10957 For completeness it should be noted that GNU @command{make} is able to
10958 express rules with multiple output files using pattern rules
10959 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
10960 Manual}).  We do not discuss pattern rules here because they are not
10961 portable, but they can be convenient in packages that assume GNU
10962 @command{make}.
10965 @node Hard-Coded Install Paths
10966 @section Installing to Hard-Coded Locations
10968 @display
10969 My package needs to install some configuration file.  I tried to use
10970 the following rule, but @samp{make distcheck} fails.  Why?
10972 @example
10973 # Do not do this.
10974 install-data-local:
10975         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
10976 @end example
10977 @end display
10979 @display
10980 My package needs to populate the installation directory of another
10981 package at install-time.  I can easily compute that installation
10982 directory in @file{configure}, but if I install files therein,
10983 @samp{make distcheck} fails.  How else should I do?
10984 @end display
10986 These two setups share their symptoms: @samp{make distcheck} fails
10987 because they are installing files to hard-coded paths.  In the later
10988 case the path is not really hard-coded in the package, but we can
10989 consider it to be hard-coded in the system (or in whichever tool that
10990 supplies the path).  As long as the path does not use any of the
10991 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
10992 @samp{$(datadir)}, etc.), the effect will be the same:
10993 user-installations are impossible.
10995 When a (non-root) user wants to install a package, he usually has no
10996 right to install anything in @file{/usr} or @file{/usr/local}.  So he
10997 does something like @samp{./configure --prefix ~/usr} to install
10998 package in his own @file{~/usr} tree.
11000 If a package attempts to install something to some hard-coded path
11001 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
11002 then the installation will fail.  @samp{make distcheck} performs such
11003 a @option{--prefix} installation, hence it will fail too.
11005 Now, there are some easy solutions.
11007 The above @code{install-data-local} example for installing
11008 @file{/etc/afile} would be better replaced by
11010 @example
11011 sysconf_DATA = afile
11012 @end example
11014 @noindent
11015 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
11016 this is what the GNU Standards require.  When such a package is
11017 installed on an FHS compliant system, the installer will have to set
11018 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
11019 should not be concerned by such site policies: use the appropriate
11020 standard directory variable to install your files so that the installer
11021 can easily redefine these variables to match their site conventions.
11023 Installing files that should be used by another package is slightly
11024 more involved.  Let's take an example and assume you want to install
11025 a shared library that is a Python extension module.  If you ask Python
11026 where to install the library, it will answer something like this:
11028 @example
11029 % @kbd{python -c 'from distutils import sysconfig;
11030              print sysconfig.get_python_lib(1,0)'}
11031 /usr/lib/python2.5/site-packages
11032 @end example
11034 If you indeed use this absolute path to install your shared library,
11035 non-root users will not be able to install the package, hence
11036 distcheck fails.
11038 Let's do better.  The @samp{sysconfig.get_python_lib()} function
11039 actually accepts a third argument that will replace Python's
11040 installation prefix.
11042 @example
11043 % @kbd{python -c 'from distutils import sysconfig;
11044              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
11045 $@{exec_prefix@}/lib/python2.5/site-packages
11046 @end example
11048 You can also use this new path.  If you do
11049 @itemize @bullet
11050 @item
11051 root users can install your package with the same @option{--prefix}
11052 as Python (you get the behavior of the previous attempt)
11054 @item
11055 non-root users can install your package too, they will have the
11056 extension module in a place that is not searched by Python but they
11057 can work around this using environment variables (and if you installed
11058 scripts that use this shared library, it's easy to tell Python were to
11059 look in the beginning of your script, so the script works in both
11060 cases).
11061 @end itemize
11063 The @code{AM_PATH_PYTHON} macro uses similar commands to define
11064 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
11066 Of course not all tools are as advanced as Python regarding that
11067 substitution of @var{prefix}.  So another strategy is to figure the
11068 part of the installation directory that must be preserved.  For
11069 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
11070 computes @samp{$(lispdir)}:
11072 @example
11073 $EMACS -batch -q -eval '(while load-path
11074   (princ (concat (car load-path) "\n"))
11075   (setq load-path (cdr load-path)))' >conftest.out
11076 lispdir=`sed -n
11077   -e 's,/$,,'
11078   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
11079         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
11080       @}'
11081   -e '/.*\/share\/x*emacs\/site-lisp$/@{
11082         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
11083       @}'
11084   conftest.out`
11085 @end example
11087 I.e., it just picks the first directory that looks like
11088 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
11089 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
11090 @samp{$@{datadir@}} appropriately.
11092 The emacs case looks complicated because it processes a list and
11093 expects two possible layouts, otherwise it's easy, and the benefits for
11094 non-root users are really worth the extra @command{sed} invocation.
11097 @node History
11098 @chapter History of Automake
11100 This chapter presents various aspects of the history of Automake.  The
11101 exhausted reader can safely skip it; this will be more of interest to
11102 nostalgic people, or to those curious to learn about the evolution of
11103 Automake.
11105 @menu
11106 * Timeline::                    The Automake story.
11107 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
11108 * Releases::                    Statistics about Automake Releases
11109 @end menu
11111 @node Timeline
11112 @section Timeline
11114 @table @asis
11115 @item 1994-09-19 First CVS commit.
11117 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
11118 working on Automake (or AutoMake, as it was spelt then) this Monday.
11120 The first version of the @command{automake} script looks as follows.
11122 @example
11123 #!/bin/sh
11125 status=0
11127 for makefile
11129   if test ! -f $@{makefile@}.am; then
11130     echo "automake: $@{makefile@}.am: No such honkin' file"
11131     status=1
11132     continue
11133   fi
11135   exec 4> $@{makefile@}.in
11137 done
11138 @end example
11140 From this you can already see that Automake will be about reading
11141 @file{*.am} file and producing @file{*.in} files.  You cannot see
11142 anything else, but if you also know that David is the one who created
11143 Autoconf two years before you can guess the rest.
11145 Several commits follow, and by the end of the day Automake is
11146 reported to work for GNU fileutils and GNU m4.
11148 The modus operandi is the one that is still used today: variable
11149 assignments in @file{Makefile.am} files trigger injections of
11150 precanned @file{Makefile} fragments into the generated
11151 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
11152 by the 4.4BSD @command{make} and include files, however Automake aims
11153 to be portable and to conform to the GNU standards for @file{Makefile}
11154 variables and targets.
11156 At this point, the most recent release of Autoconf is version 1.11,
11157 and David is preparing to release Autoconf 2.0 in late October.  As a
11158 matter of fact, he will barely touch Automake after September.
11160 @item 1994-11-05 David MacKenzie's last commit.
11162 At this point Automake is a 200 line portable shell script, plus 332
11163 lines of @file{Makefile} fragments.  In the @file{README}, David
11164 states his ambivalence between ``portable shell'' and ``more
11165 appropriate language'':
11167 @quotation
11168 I wrote it keeping in mind the possibility of it becoming an Autoconf
11169 macro, so it would run at configure-time.  That would slow
11170 configuration down a bit, but allow users to modify the Makefile.am
11171 without needing to fetch the AutoMake package.  And, the Makefile.in
11172 files wouldn't need to be distributed.  But all of AutoMake would.  So
11173 I might reimplement AutoMake in Perl, m4, or some other more
11174 appropriate language.
11175 @end quotation
11177 Automake is described as ``an experimental Makefile generator''.
11178 There is no documentation.  Adventurous users are referred to the
11179 examples and patches needed to use Automake with GNU m4 1.3, fileutils
11180 3.9, time 1.6, and development versions of find and indent.
11182 These examples seem to have been lost.  However at the time of writing
11183 (10 years later in September, 2004) the FSF still distributes a
11184 package that uses this version of Automake: check out GNU termutils
11185 2.0.
11187 @item 1995-11-12 Tom Tromey's first commit.
11189 After one year of inactivity, Tom Tromey takes over the package.
11190 Tom was working on GNU cpio back then, and doing this just for fun,
11191 having trouble finding a project to contribute to.  So while hacking
11192 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
11193 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
11194 grabbed it and tried it out.
11196 Tom didn't talk to djm about it until later, just to make sure he
11197 didn't mind if he made a release.  He did a bunch of early releases to
11198 the Gnits folks.
11200 Gnits was (and still is) totally informal, just a few GNU friends who
11201 Fran@,cois Pinard knew, who were all interested in making a common
11202 infrastructure for GNU projects, and shared a similar outlook on how
11203 to do it.  So they were able to make some progress.  It came along
11204 with Autoconf and extensions thereof, and then Automake from David and
11205 Tom (who were both gnitsians).  One of their ideas was to write a
11206 document paralleling the GNU standards, that was more strict in some
11207 ways and more detailed.  They never finished the GNITS standards, but
11208 the ideas mostly made their way into Automake.
11210 @item 1995-11-23 Automake 0.20
11212 Besides introducing automatic dependency tracking (@pxref{Dependency
11213 Tracking Evolution}), this version also supplies a 9-page manual.
11215 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
11216 exist, so many things had to be done by hand.  For instance, here is
11217 what a configure.in (this is the former name of the
11218 @file{configure.ac} we use today) must contain in order to use
11219 Automake 0.20:
11221 @example
11222 PACKAGE=cpio
11223 VERSION=2.3.911
11224 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
11225 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
11226 AC_SUBST(PACKAGE)
11227 AC_SUBST(VERSION)
11228 AC_ARG_PROGRAM
11229 AC_PROG_INSTALL
11230 @end example
11232 (Today all of the above is achieved by @code{AC_INIT} and
11233 @code{AM_INIT_AUTOMAKE}.)
11235 Here is how programs are specified in @file{Makefile.am}:
11237 @example
11238 PROGRAMS = hello
11239 hello_SOURCES = hello.c
11240 @end example
11242 This looks pretty much like what we do today, except the
11243 @code{PROGRAMS} variable has no directory prefix specifying where
11244 @file{hello} should be installed: all programs are installed in
11245 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
11246 that must be built but not installed (it is called
11247 @code{noinst_PROGRAMS} nowadays).
11249 Programs can be built conditionally using @code{AC_SUBST}itutions:
11251 @example
11252 PROGRAMS = @@progs@@
11253 AM_PROGRAMS = foo bar baz
11254 @end example
11256 (@code{AM_PROGRAMS} has since then been renamed to
11257 @code{EXTRA_PROGRAMS}.)
11259 Similarly scripts, static libraries, and data can be built and installed
11260 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
11261 However @code{LIBRARIES} were treated a bit specially in that Automake
11262 did automatically supply the @file{lib} and @file{.a} prefixes.
11263 Therefore to build @file{libcpio.a}, one had to write
11265 @example
11266 LIBRARIES = cpio
11267 cpio_SOURCES = ...
11268 @end example
11270 Extra files to distribute must be listed in @code{DIST_OTHER} (the
11271 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
11272 distributed should appear in @code{DIST_SUBDIRS}, but the manual
11273 describes this as a temporary ugly hack (today extra directories should
11274 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
11275 for another purpose, @pxref{Conditional Subdirectories}).
11277 @item 1995-11-26 Automake 0.21
11279 In less time than it takes to cook a frozen pizza, Tom rewrites
11280 Automake using Perl.  At this time Perl 5 is only one year old, and
11281 Perl 4.036 is in use at many sites.  Supporting several Perl versions
11282 has been a source of problems through the whole history of Automake.
11284 If you never used Perl 4, imagine Perl 5 without objects, without
11285 @samp{my} variables (only dynamically scoped @samp{local} variables),
11286 without function prototypes, with function calls that needs to be
11287 prefixed with @samp{&}, etc.  Traces of this old style can still be
11288 found in today's @command{automake}.
11290 @item 1995-11-28 Automake 0.22
11291 @itemx 1995-11-29 Automake 0.23
11293 Bug fixes.
11295 @item 1995-12-08 Automake 0.24
11296 @itemx 1995-12-10 Automake 0.25
11298 Releases are raining.  0.24 introduces the uniform naming scheme we
11299 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
11300 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
11301 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
11302 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
11303 prefixes.)  Adding support for prefixes like that was one of the major
11304 ideas in automake; it has lasted pretty well.
11306 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
11307 Pinard's doing).
11309 0.25 fixes a Perl 4 portability bug.
11311 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
11312 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
11314 @item 1996-01-03 Automake 0.26
11315 @itemx 1996-01-03 Automake 0.27
11317 Of the many changes and suggestions sent by Fran@,cois Pinard and
11318 included in 0.26, perhaps the most important is the advice that to
11319 ease customization a user rule or variable definition should always
11320 override an Automake rule or definition.
11322 Gordon Matzigkeit and Jim Meyering are two other early contributors
11323 that have been sending fixes.
11325 0.27 fixes yet another Perl 4 portability bug.
11327 @item 1996-01-13 Automake 0.28
11329 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
11330 support.  This is an important step because until this version
11331 Automake only knew about the @file{Makefile.am}s it processed.
11332 @file{configure.in} was Autoconf's world and the link between Autoconf
11333 and Automake had to be done by the @file{Makefile.am} author.  For
11334 instance, if @file{config.h} was generated by @file{configure}, it was the
11335 package maintainer's responsibility to define the @code{CONFIG_HEADER}
11336 variable in each @file{Makefile.am}.
11338 Succeeding releases will rely more and more on scanning
11339 @file{configure.in} to better automate the Autoconf integration.
11341 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
11342 @option{--gnu} and @option{--gnits} options, the latter being stricter.
11344 @item 1996-02-07 Automake 0.29
11346 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
11347 and rebuild rules for @file{configure}-generated file are
11348 automatically output.
11350 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
11351 scheme.
11353 @item 1996-02-24 Automake 0.30
11355 The test suite is born.  It contains 9 tests.  From now on test cases
11356 will be added pretty regularly (@pxref{Releases}), and this proved to
11357 be really helpful later on.
11359 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
11361 All the third-party Autoconf macros, written mostly by Fran@,cois
11362 Pinard (and later Jim Meyering), are distributed in Automake's
11363 hand-written @file{aclocal.m4} file.  Package maintainers are expected
11364 to extract the necessary macros from this file.  (In previous versions
11365 you had to copy and paste them from the manual...)
11367 @item 1996-03-11 Automake 0.31
11369 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
11370 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
11371 whenever the @code{TESTS} variable is defined.
11373 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
11374 prefix is introduced.  The syntax is now the same as today.
11376 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
11378 @item 1996-04-27 Automake 0.32
11380 @code{-hook} targets are introduced; an idea from Dieter Baron.
11382 @file{*.info} files, which were output in the build directory are
11383 now built in the source directory, because they are distributed.  It
11384 seems these files like to move back and forth as that will happen
11385 again in future versions.
11387 @item 1996-05-18 Automake 0.33
11389 Gord Matzigkeit's main two contributions:
11391 @itemize
11392 @item very preliminary libtool support
11393 @item the distcheck rule
11394 @end itemize
11396 Although they were very basic at this point, these are probably
11397 among the top features for Automake today.
11399 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
11400 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
11401 author (@pxref{maintainer-mode}).
11403 @item 1996-05-28 Automake 1.0
11405 After only six months of heavy development, the automake script is
11406 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
11407 package has 30 pages of documentation, and 38 test cases.
11408 @file{aclocal.m4} contains 4 macros.
11410 From now on and until version 1.4, new releases will occur at a rate
11411 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
11412 been the name of beta releases for 1.2.  This is the first time
11413 Automake uses suffix letters to designate beta releases, an habit that
11414 lasts.
11416 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
11418 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
11420 Between June and October, the Autoconf development is almost stalled.
11421 Roland McGrath has been working at the beginning of the year.  David
11422 comes back in November to release 2.12, but he won't touch Autoconf
11423 anymore after this year, and Autoconf then really stagnates.  The
11424 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
11426 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
11428 The mailing list is announced as follows:
11429 @smallexample
11430 I've created the "automake" mailing list.  It is
11431 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
11432 automake-request@@gnu.ai.mit.edu.
11434 The charter of this list is discussion of automake, autoconf, and
11435 other configuration/portability tools (e.g., libtool).  It is expected
11436 that discussion will range from pleas for help all the way up to
11437 patches.
11439 This list is archived on the FSF machines.  Offhand I don't know if
11440 you can get the archive without an account there.
11442 This list is open to anybody who wants to join.  Tell all your
11443 friends!
11444 -- Tom Tromey
11445 @end smallexample
11447 Before that people were discussing Automake privately, on the Gnits
11448 mailing list (which is not public either), and less frequently on
11449 @code{gnu.misc.discuss}.
11451 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
11452 noticed.  The archives of the early years of the
11453 @code{automake@@gnu.org} list have been lost, so today it is almost
11454 impossible to find traces of discussions that occurred before 1999.
11455 This has been annoying more than once, as such discussions can be
11456 useful to understand the rationale behind a piece of uncommented code
11457 that was introduced back then.
11459 @item 1997-06-22 Automake 1.2
11461 Automake developments continues, and more and more new Autoconf macros
11462 are required.  Distributing them in @file{aclocal.m4} and requiring
11463 people to browse this file to extract the relevant macros becomes
11464 uncomfortable.  Ideally, some of them should be contributed to
11465 Autoconf so that they can be used directly, however Autoconf is
11466 currently inactive.  Automake 1.2 consequently introduces
11467 @command{aclocal} (@command{aclocal} was actually started on
11468 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
11469 file from a repository of third-party macros.  Because Autoconf has
11470 stalled, Automake also becomes a kind of repository for such
11471 third-party macros, even macros completely unrelated to Automake (for
11472 instance macros that fix broken Autoconf macros).
11474 The 1.2 release contains 20 macros, including the
11475 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
11476 @file{configure.in}.
11478 Libtool is fully supported using @code{*_LTLIBRARIES}.
11480 The missing script is introduced by Fran@,cois Pinard; it is meant to be
11481 a better solution than @code{AM_MAINTAINER_MODE}
11482 (@pxref{maintainer-mode}).
11484 Conditionals support was implemented by Ian Lance Taylor.  At the
11485 time, Tom and Ian were working on an internal project at Cygnus.  They
11486 were using ILU, which is pretty similar to CORBA@.  They wanted to
11487 integrate ILU into their build, which was all @file{configure}-based,
11488 and Ian thought that adding conditionals to @command{automake} was
11489 simpler than doing all the work in @file{configure} (which was the
11490 standard at the time).  So this was actually funded by Cygnus.
11492 This very useful but tricky feature will take a lot of time to
11493 stabilize.  (At the time this text is written, there are still
11494 primaries that have not been updated to support conditional
11495 definitions in Automake 1.9.)
11497 The @command{automake} script has almost doubled: 6089 lines of Perl,
11498 plus 1294 lines of @file{Makefile} fragments.
11500 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
11502 @item 1998-04-05 Automake 1.3
11504 This is a small advance compared to 1.2.
11505 It adds support for assembly, and preliminary support for Java.
11507 Perl 5.004_04 is out, but fixes to support Perl 4 are still
11508 regularly submitted whenever Automake breaks it.
11510 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
11512 Sourceware was setup by Jason Molenda to host open source projects.
11514 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
11515 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake:
11516 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
11517 publicly accessible CVS repository.  This CVS repository is a copy of
11518 the one Tom was using on his machine, which in turn is based on
11519 a copy of the CVS repository of David MacKenzie.  This is why we still
11520 have to full source history.  (Automake was on Sourceware until 2007-10-29,
11521 when it moved to a git repository on @code{savannah.gnu.org},
11522 but the Sourceware host had been renamed to @code{sources.redhat.com}.)
11524 The oldest file in the administrative directory of the CVS repository
11525 that was created on Sourceware is dated 1998-09-19, while the
11526 announcement that @command{automake} and @command{autoconf} had joined
11527 @command{sourceware} was made on 1998-10-26.  They were among the
11528 first projects to be hosted there.
11530 The heedful reader will have noticed Automake was exactly 4 years old
11531 on 1998-09-19.
11533 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
11535 @item 1999-01-14 Automake 1.4
11537 This release adds support for Fortran 77 and for the @code{include}
11538 statement.  Also, @samp{+=} assignments are introduced, but it is
11539 still quite easy to fool Automake when mixing this with conditionals.
11541 These two releases, Automake 1.4 and Autoconf 2.13 make a duo that
11542 will be used together for years.
11544 @command{automake} is 7228 lines, plus 1591 lines of Makefile
11545 fragment, 20 macros (some 1.3 macros were finally contributed back to
11546 Autoconf), 197 test cases, and 51 pages of documentation.
11548 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
11550 This implements a new dependency tracking schemed that should be
11551 able to handle automatic dependency tracking using any compiler (not
11552 just gcc) and any make (not just GNU @command{make}).  In addition,
11553 the new scheme should be more reliable than the old one, as
11554 dependencies are generated on the end user's machine.  Alexandre Oliva
11555 creates depcomp for this purpose.
11557 @xref{Dependency Tracking Evolution}, for more details about the
11558 evolution of automatic dependency tracking in Automake.
11560 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
11562 This was a huge problem since we also had patches going in on the
11563 trunk.  The merge took a long time and was very painful.
11565 @item 2000-05-10
11567 Since September 1999 and until 2003, Akim Demaille will be zealously
11568 revamping Autoconf.
11570 @quotation
11571 I think the next release should be called "3.0".@*
11572 Let's face it: you've basically rewritten autoconf.@*
11573 Every weekend there are 30 new patches.@*
11574 I don't see how we could call this "2.15" with a straight face.@*
11575 -- Tom Tromey on @email{autoconf@@gnu.org}
11576 @end quotation
11578 Actually Akim works like a submarine: he will pile up patches while he
11579 works off-line during the weekend, and flush them in batch when he
11580 resurfaces on Monday.
11582 @item 2001-01-24
11584 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
11585 is out, and Akim has to find something to do during his week-end :)
11587 @item 2001-01-28
11589 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
11591 @quotation
11592 Aiieeee!  I was dreading the day that the Demaillator turned his
11593 sights on automake@dots{} and now it has arrived! -- Tom Tromey
11594 @end quotation
11596 It's only the beginning: in two months he will send 192 patches.  Then
11597 he would slow down so Tom can catch up and review all this.  Initially
11598 Tom actually read all these patches, then he probably trustingly
11599 answered OK to most of them, and finally gave up and let Akim apply
11600 whatever he wanted.  There was no way to keep up with that patch rate.
11602 @quotation
11603 Anyway the patch below won't apply since it predates Akim's
11604 sourcequake; I have yet to figure where the relevant passage has
11605 been moved :) -- Alexandre Duret-Lutz
11606 @end quotation
11608 All these patches were sent to and discussed on
11609 @email{automake@@gnu.org}, so subscribed users were literally drowning in
11610 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
11611 mailing list was created in May.
11613 Year after year, Automake had drifted away from its initial design:
11614 construct @file{Makefile.in} by assembling various @file{Makefile}
11615 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
11616 various places in the @command{automake} script itself; this does not
11617 help ensuring a consistent treatment of these rules (for instance
11618 making sure that user-defined rules override Automake's own rules).
11619 One of Akim's goal was moving all these hard-coded rules to separate
11620 @file{Makefile} fragments, so the logic could be centralized in a
11621 @file{Makefile} fragment processor.
11623 Another significant contribution of Akim is the interface with the
11624 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
11625 this time was to read the file and grep the various macro of interest
11626 to Automake.  Doing so could break in many unexpected ways; automake
11627 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
11628 where the arguments are known only when M4 is run), or conversely it
11629 could detect some macro that was not expanded (because it is called
11630 conditionally).  In the CVS version of Autoconf, Akim had implemented
11631 the @option{--trace} option, which provides accurate information about
11632 where macros are actually called and with what arguments.  Akim will
11633 equip Automake with a second @file{configure.in} scanner that uses
11634 this @option{--trace} interface.  Since it was not sensible to drop the
11635 Autoconf 2.13 compatibility yet, this experimental scanner was only
11636 used when an environment variable was set, the traditional
11637 grep-scanner being still the default.
11639 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
11641 It has been more than two years since Automake 1.4, CVS Automake has
11642 suffered lot's of heavy changes and still is not ready for release.
11643 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
11645 @item 2001-05-08 Automake 1.4-p1
11646 @itemx 2001-05-24 Automake 1.4-p2
11648 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
11649 release'' of Automake:
11651 @quotation
11652 The main purpose of this release is to have a stable automake
11653 which is compatible with the latest stable libtool.
11654 @end quotation
11656 The release also contains obvious fixes for bugs in Automake 1.4,
11657 some of which were reported almost monthly.
11659 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
11661 @item 2001-06-07 Automake 1.4-p3
11662 @itemx 2001-06-10 Automake 1.4-p4
11663 @itemx 2001-07-15 Automake 1.4-p5
11665 Gary continues his patch-release series.  These also add support for
11666 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
11667 @file{configure.ac} over @file{configure.in}, and it introduces a new
11668 syntax for @code{AC_OUTPUT}ing files.
11670 @item 2001-08-23 Automake 1.5
11672 A major and long-awaited release, that comes more than two years after
11673 1.4.  It brings many changes, among which:
11674 @itemize
11675 @item The new dependency tracking scheme that uses @command{depcomp}.
11676 Aside from the improvement on the dependency tracking itself
11677 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
11678 of automake generated @file{Makefile.in}s as the @file{Makefile.in}s
11679 used during development are now the same as those used in
11680 distributions.  Before that the @file{Makefile.in}s generated for
11681 maintainers required GNU @command{make} and GCC, they were different
11682 from the portable @file{Makefile} generated for distribution; this was
11683 causing some confusion.
11685 @item Support for per-target compilation flags.
11687 @item Support for reference to files in subdirectories in most
11688 @file{Makefile.am} variables.
11690 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
11691 prefixes.
11692 @item Perl 4 support is finally dropped.
11693 @end itemize
11695 1.5 did break several packages that worked with 1.4.  Enough so that
11696 Linux distributions could not easily install the new Automake version
11697 without breaking many of the packages for which they had to run
11698 @command{automake}.
11700 Some of these breakages were effectively bugs that would eventually be
11701 fixed in the next release.  However, a lot of damage was caused by
11702 some changes made deliberately to render Automake stricter on some
11703 setup we did consider bogus.  For instance, @samp{make distcheck} was
11704 improved to check that @samp{make uninstall} did remove all the files
11705 @samp{make install} installed, that @samp{make distclean} did not omit
11706 some file, and that a VPATH build would work even if the source
11707 directory was read-only.  Similarly, Automake now rejects multiple
11708 definitions of the same variable (because that would mix very badly
11709 with conditionals), and @samp{+=} assignments with no previous
11710 definition.  Because these changes all occurred suddenly after 1.4 had
11711 been established for more than two years, it hurt users.
11713 To make matter worse, meanwhile Autoconf (now at version 2.52) was
11714 facing similar troubles, for similar reasons.
11716 @item 2002-03-05 Automake 1.6
11718 This release introduced versioned installation (@pxref{API
11719 versioning}).  This was mainly pushed by Havoc Pennington, taking the
11720 GNOME source tree as motive: due to incompatibilities between the
11721 autotools it's impossible for the GNOME packages to switch to Autoconf
11722 2.53 and Automake 1.5 all at once, so they are currently stuck with
11723 Autoconf 2.13 and Automake 1.4.
11725 The idea was to call this version @file{automake-1.6}, call all its
11726 bug-fix versions identically, and switch to @file{automake-1.7} for
11727 the next release that adds new features or changes some rules.  This
11728 scheme implies maintaining a bug-fix branch in addition to the
11729 development trunk, which means more work from the maintainer, but
11730 providing regular bug-fix releases proved to be really worthwhile.
11732 Like 1.5, 1.6 also introduced a bunch of incompatibilities, intentional or
11733 not.  Perhaps the more annoying was the dependence on the newly
11734 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
11735 since its explosive 2.50 release and included changes required to fix
11736 some bugs in Automake.  In order to upgrade to Automake 1.6, people
11737 now had to upgrade Autoconf too; for some packages it was no picnic.
11739 While versioned installation helped people to upgrade, it also
11740 unfortunately allowed people not to upgrade.  At the time of writing,
11741 some Linux distributions are shipping packages for Automake 1.4, 1.5,
11742 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
11743 Some distribution also call 1.4 the ``stable'' version, and present
11744 ``1.9'' as the development version; this does not really makes sense
11745 since 1.9 is way more solid than 1.4.  All this does not help the
11746 newcomer.
11748 @item 2002-04-11 Automake 1.6.1
11750 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
11751 This one and those following will be handled by Alexandre
11752 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
11753 but his interest into Automake is drifting away towards projects like
11754 @command{gcj}.
11756 Alexandre has been using Automake since 2000, and started to
11757 contribute mostly on Akim's incitement (Akim and Alexandre have been
11758 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
11759 a lot of free time to enjoy hacking Automake.
11761 @item 2002-06-14 Automake 1.6.2
11763 @item 2002-07-28 Automake 1.6.3
11764 @itemx 2002-07-28 Automake 1.4-p6
11766 Two releases on the same day.  1.6.3 is a bug-fix release.
11768 Tom Tromey backported the versioned installation mechanism on the 1.4
11769 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
11770 side by side.  Another request from the GNOME folks.
11772 @item 2002-09-25 Automake 1.7
11774 This release switches to the new @file{configure.ac} scanner Akim
11775 was experimenting in 1.5.
11777 @item 2002-10-16 Automake 1.7.1
11778 @itemx 2002-12-06 Automake 1.7.2
11779 @itemx 2003-02-20 Automake 1.7.3
11780 @itemx 2003-04-23 Automake 1.7.4
11781 @itemx 2003-05-18 Automake 1.7.5
11782 @itemx 2003-07-10 Automake 1.7.6
11783 @itemx 2003-09-07 Automake 1.7.7
11784 @itemx 2003-10-07 Automake 1.7.8
11786 Many bug-fix releases.  1.7 lasted because the development version
11787 (upcoming 1.8) was suffering some major internal revamping.
11789 @item 2003-10-26 Automake on screen
11791 Episode 49, `Repercussions', in the third season of the `Alias' TV
11792 show is first aired.
11794 Marshall, one of the characters, is working on a computer virus that he
11795 has to modify before it gets into the wrong hands or something like
11796 that.  The screenshots you see do not show any program code, they show
11797 a @file{Makefile.in} @code{generated by automake}...
11799 @item 2003-11-09 Automake 1.7.9
11801 @item 2003-12-10 Automake 1.8
11803 The most striking update is probably that of @command{aclocal}.
11805 @command{aclocal} now uses @code{m4_include} in the produced
11806 @file{aclocal.m4} when the included macros are already distributed
11807 with the package (an idiom used in many packages), which reduces code
11808 duplication.  Many people liked that, but in fact this change was
11809 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
11810 must be rebuilt whenever a dependency of @file{configure} changes, but
11811 all the @file{m4} files included in @file{aclocal.m4} where unknown
11812 from @command{automake}.  Now @command{automake} can just trace the
11813 @code{m4_include}s to discover the dependencies.
11815 @command{aclocal} also starts using the @option{--trace} Autoconf option
11816 in order to discover used macros more accurately.  This will turn out
11817 to be very tricky (later releases will improve this) as people had
11818 devised many ways to cope with the limitation of previous
11819 @command{aclocal} versions, notably using handwritten
11820 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
11821 rule that is already included by such statement.
11823 Automake also has seen its guts rewritten.  Although this rewriting
11824 took a lot of efforts, it is only apparent to the users in that some
11825 constructions previously disallowed by the implementation now work
11826 nicely.  Conditionals, Locations, Variable and Rule definitions,
11827 Options: these items on which Automake works have been rewritten as
11828 separate Perl modules, and documented.
11830 @itemx 2004-01-11 Automake 1.8.1
11831 @itemx 2004-01-12 Automake 1.8.2
11832 @itemx 2004-03-07 Automake 1.8.3
11833 @itemx 2004-04-25 Automake 1.8.4
11834 @itemx 2004-05-16 Automake 1.8.5
11836 @item 2004-07-28 Automake 1.9
11838 This release tries to simplify the compilation rules it outputs to
11839 reduce the size of the Makefile.  The complaint initially come from
11840 the libgcj developers.  Their @file{Makefile.in} generated with
11841 Automake 1.4 and custom build rules (1.4 did not support compiled
11842 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
11843 down to 1.2MB@.
11845 Aside from this it contains mainly minor changes and bug-fixes.
11847 @itemx 2004-08-11 Automake 1.9.1
11848 @itemx 2004-09-19 Automake 1.9.2
11850 Automake has ten years.  This chapter of the manual was initially
11851 written for this occasion.
11853 @itemx 2007-10-29 Automake repository moves to @code{savannah.gnu.org} and uses
11854 git as primary repository.
11856 @end table
11858 @node Dependency Tracking Evolution
11859 @section Dependency Tracking in Automake
11861 Over the years Automake has deployed three different dependency
11862 tracking methods.  Each method, including the current one, has had
11863 flaws of various sorts.  Here we lay out the different dependency
11864 tracking methods, their flaws, and their fixes.  We conclude with
11865 recommendations for tool writers, and by indicating future directions
11866 for dependency tracking work in Automake.
11868 @subsection First Take
11869 @unnumberedsubsubsec Description
11871 Our first attempt at automatic dependency tracking was based on the
11872 method recommended by GNU @command{make}.  (@pxref{Automatic
11873 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
11874 make Manual})
11876 This version worked by precomputing dependencies ahead of time.  For
11877 each source file, it had a special @file{.P} file that held the
11878 dependencies.  There was a rule to generate a @file{.P} file by
11879 invoking the compiler appropriately.  All such @file{.P} files were
11880 included by the @file{Makefile}, thus implicitly becoming dependencies
11881 of @file{Makefile}.
11883 @unnumberedsubsubsec Bugs
11885 This approach had several critical bugs.
11887 @itemize
11888 @item
11889 The code to generate the @file{.P} file relied on @command{gcc}.
11890 (A limitation, not technically a bug.)
11891 @item
11892 The dependency tracking mechanism itself relied on GNU @command{make}.
11893 (A limitation, not technically a bug.)
11894 @item
11895 Because each @file{.P} file was a dependency of @file{Makefile}, this
11896 meant that dependency tracking was done eagerly by @command{make}.
11897 For instance, @samp{make clean} would cause all the dependency files
11898 to be updated, and then immediately removed.  This eagerness also
11899 caused problems with some configurations; if a certain source file
11900 could not be compiled on a given architecture for some reason,
11901 dependency tracking would fail, aborting the entire build.
11902 @item
11903 As dependency tracking was done as a pre-pass, compile times were
11904 doubled--the compiler had to be run twice per source file.
11905 @item
11906 @samp{make dist} re-ran @command{automake} to generate a
11907 @file{Makefile} that did not have automatic dependency tracking (and
11908 that was thus portable to any version of @command{make}).  In order to
11909 do this portably, Automake had to scan the dependency files and remove
11910 any reference that was to a source file not in the distribution.
11911 This process was error-prone.  Also, if @samp{make dist} was run in an
11912 environment where some object file had a dependency on a source file
11913 that was only conditionally created, Automake would generate a
11914 @file{Makefile} that referred to a file that might not appear in the
11915 end user's build.  A special, hacky mechanism was required to work
11916 around this.
11917 @end itemize
11919 @unnumberedsubsubsec Historical Note
11921 The code generated by Automake is often inspired by the
11922 @file{Makefile} style of a particular author.  In the case of the first
11923 implementation of dependency tracking, I believe the impetus and
11924 inspiration was Jim Meyering.  (I could be mistaken.  If you know
11925 otherwise feel free to correct me.)
11927 @subsection Dependencies As Side Effects
11928 @unnumberedsubsubsec Description
11930 The next refinement of Automake's automatic dependency tracking scheme
11931 was to implement dependencies as side effects of the compilation.
11932 This was aimed at solving the most commonly reported problems with the
11933 first approach.  In particular we were most concerned with eliminating
11934 the weird rebuilding effect associated with make clean.
11936 In this approach, the @file{.P} files were included using the
11937 @code{-include} command, which let us create these files lazily.  This
11938 avoided the @samp{make clean} problem.
11940 We only computed dependencies when a file was actually compiled.  This
11941 avoided the performance penalty associated with scanning each file
11942 twice.  It also let us avoid the other problems associated with the
11943 first, eager, implementation.  For instance, dependencies would never
11944 be generated for a source file that was not compilable on a given
11945 architecture (because it in fact would never be compiled).
11947 @unnumberedsubsubsec Bugs
11949 @itemize
11950 @item
11951 This approach also relied on the existence of @command{gcc} and GNU
11952 @command{make}.  (A limitation, not technically a bug.)
11953 @item
11954 Dependency tracking was still done by the developer, so the problems
11955 from the first implementation relating to massaging of dependencies by
11956 @samp{make dist} were still in effect.
11957 @item
11958 This implementation suffered from the ``deleted header file'' problem.
11959 Suppose a lazily-created @file{.P} file includes a dependency on a
11960 given header file, like this:
11962 @example
11963 maude.o: maude.c something.h
11964 @end example
11966 Now suppose that the developer removes @file{something.h} and updates
11967 @file{maude.c} so that this include is no longer needed.  If he runs
11968 @command{make}, he will get an error because there is no way to create
11969 @file{something.h}.
11971 We fixed this problem in a later release by further massaging the
11972 output of @command{gcc} to include a dummy dependency for each header
11973 file.
11974 @end itemize
11976 @subsection Dependencies for the User
11977 @unnumberedsubsubsec Description
11979 The bugs associated with @samp{make dist}, over time, became a real
11980 problem.  Packages using Automake were being built on a large number
11981 of platforms, and were becoming increasingly complex.  Broken
11982 dependencies were distributed in ``portable'' @file{Makefile.in}s,
11983 leading to user complaints.  Also, the requirement for @command{gcc}
11984 and GNU @command{make} was a constant source of bug reports.  The next
11985 implementation of dependency tracking aimed to remove these problems.
11987 We realized that the only truly reliable way to automatically track
11988 dependencies was to do it when the package itself was built.  This
11989 meant discovering a method portable to any version of make and any
11990 compiler.  Also, we wanted to preserve what we saw as the best point
11991 of the second implementation: dependency computation as a side effect
11992 of compilation.
11994 In the end we found that most modern make implementations support some
11995 form of include directive.  Also, we wrote a wrapper script that let
11996 us abstract away differences between dependency tracking methods for
11997 compilers.  For instance, some compilers cannot generate dependencies
11998 as a side effect of compilation.  In this case we simply have the
11999 script run the compiler twice.  Currently our wrapper script
12000 (@command{depcomp}) knows about twelve different compilers (including
12001 a "compiler" that simply invokes @command{makedepend} and then the
12002 real compiler, which is assumed to be a standard Unix-like C compiler
12003 with no way to do dependency tracking).
12005 @unnumberedsubsubsec Bugs
12007 @itemize
12008 @item
12009 Running a wrapper script for each compilation slows down the build.
12010 @item
12011 Many users don't really care about precise dependencies.
12012 @item
12013 This implementation, like every other automatic dependency tracking
12014 scheme in common use today (indeed, every one we've ever heard of),
12015 suffers from the ``duplicated new header'' bug.
12017 This bug occurs because dependency tracking tools, such as the
12018 compiler, only generate dependencies on the successful opening of a
12019 file, and not on every probe.
12021 Suppose for instance that the compiler searches three directories for
12022 a given header, and that the header is found in the third directory.
12023 If the programmer erroneously adds a header file with the same name to
12024 the first directory, then a clean rebuild from scratch could fail
12025 (suppose the new header file is buggy), whereas an incremental rebuild
12026 will succeed.
12028 What has happened here is that people have a misunderstanding of what
12029 a dependency is.  Tool writers think a dependency encodes information
12030 about which files were read by the compiler.  However, a dependency
12031 must actually encode information about what the compiler tried to do.
12033 This problem is not serious in practice.  Programmers typically do not
12034 use the same name for a header file twice in a given project.  (At
12035 least, not in C or C++.  This problem may be more troublesome in
12036 Java.)  This problem is easy to fix, by modifying dependency
12037 generators to record every probe, instead of every successful open.
12039 @item
12040 Since automake generates dependencies as a side effect of compilation,
12041 there is a bootstrapping problem when header files are generated by
12042 running a program.  The problem is that, the first time the build is
12043 done, there is no way by default to know that the headers are
12044 required, so make might try to run a compilation for which the headers
12045 have not yet been built.
12047 This was also a problem in the previous dependency tracking implementation.
12049 The current fix is to use @code{BUILT_SOURCES} to list built headers
12050 (@pxref{Sources}).  This causes them to be built before any other
12051 build rules are run.  This is unsatisfactory as a general solution,
12052 however in practice it seems sufficient for most actual programs.
12053 @end itemize
12055 This code is used since Automake 1.5.
12057 In GCC 3.0, we managed to convince the maintainers to add special
12058 command-line options to help Automake more efficiently do its job.  We
12059 hoped this would let us avoid the use of a wrapper script when
12060 Automake's automatic dependency tracking was used with @command{gcc}.
12062 Unfortunately, this code doesn't quite do what we want.  In
12063 particular, it removes the dependency file if the compilation fails;
12064 we'd prefer that it instead only touch the file in any way if the
12065 compilation succeeds.
12067 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
12068 detected at @command{configure} time, we inline the
12069 dependency-generation code and do not use the @command{depcomp}
12070 wrapper script.  This makes compilations faster for those using this
12071 compiler (probably our primary user base).  The counterpart is that
12072 because we have to encode two compilation rules in @file{Makefile}
12073 (with or without @command{depcomp}), the produced @file{Makefile}s are
12074 larger.
12076 @subsection Techniques for Computing Dependencies
12078 There are actually several ways for a build tool like Automake to
12079 cause tools to generate dependencies.
12081 @table @asis
12082 @item @command{makedepend}
12083 This was a commonly-used method in the past.  The idea is to run a
12084 special program over the source and have it generate dependency
12085 information.  Traditional implementations of @command{makedepend} are
12086 not completely precise; ordinarily they were conservative and
12087 discovered too many dependencies.
12088 @item The tool
12089 An obvious way to generate dependencies is to simply write the tool so
12090 that it can generate the information needed by the build tool.  This is
12091 also the most portable method.  Many compilers have an option to
12092 generate dependencies.  Unfortunately, not all tools provide such an
12093 option.
12094 @item The file system
12095 It is possible to write a special file system that tracks opens,
12096 reads, writes, etc, and then feed this information back to the build
12097 tool.  @command{clearmake} does this.  This is a very powerful
12098 technique, as it doesn't require cooperation from the
12099 tool.  Unfortunately it is also very difficult to implement and also
12100 not practical in the general case.
12101 @item @code{LD_PRELOAD}
12102 Rather than use the file system, one could write a special library to
12103 intercept @code{open} and other syscalls.  This technique is also quite
12104 powerful, but unfortunately it is not portable enough for use in
12105 @command{automake}.
12106 @end table
12108 @subsection Recommendations for Tool Writers
12110 We think that every compilation tool ought to be able to generate
12111 dependencies as a side effect of compilation.  Furthermore, at least
12112 while @command{make}-based tools are nearly universally in use (at
12113 least in the free software community), the tool itself should generate
12114 dummy dependencies for header files, to avoid the deleted header file
12115 bug.  Finally, the tool should generate a dependency for each probe,
12116 instead of each successful file open, in order to avoid the duplicated
12117 new header bug.
12119 @subsection Future Directions for Automake's Dependency Tracking
12121 Currently, only languages and compilers understood by Automake can
12122 have dependency tracking enabled.  We would like to see if it is
12123 practical (and worthwhile) to let this support be extended by the user
12124 to languages unknown to Automake.
12126 @node Releases
12127 @section Release Statistics
12129 The following table (inspired by @samp{perlhist(1)}) quantifies the
12130 evolution of Automake using these metrics:
12132 @table @asis
12133 @item Date, Rel
12134 The date and version of the release.
12135 @item am
12136 The number of lines of the @command{automake} script.
12137 @item acl
12138 The number of lines of the @command{aclocal} script.
12139 @item pm
12140 The number of lines of the @command{Perl} supporting modules.
12141 @item @file{*.am}
12142 The number of lines of the @file{Makefile} fragments.  The number in
12143 parentheses is the number of files.
12144 @item m4
12145 The number of lines (and files) of Autoconf macros.
12146 @item doc
12147 The number of pages of the documentation (the Postscript version).
12148 @item t
12149 The number of test cases in the test suite.  Of those, the number in
12150 parentheses is the number of generated test cases.
12151 @end table
12153 @multitable {8888-88-88} {8.8-p8} {8888} {8888} {8888} {8888 (88)} {8888 (88)} {888} {888 (88)}
12154 @headitem Date   @tab Rel    @tab   am @tab acl @tab   pm @tab @file{*.am} @tab m4 @tab doc @tab t
12155 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
12156 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
12157 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
12158 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
12159 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
12160 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
12161 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
12162 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
12163 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
12164 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
12165 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
12166 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
12167 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
12168 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
12169 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
12170 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
12171 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
12172 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (20) @tab  37 @tab 126
12173 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (23) @tab  39 @tab 156
12174 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
12175 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
12176 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
12177 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
12178 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 198
12179 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (20) @tab  51 @tab 198
12180 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (29) @tab  63 @tab 327
12181 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (27) @tab  66 @tab 365
12182 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (27) @tab  66 @tab 372
12183 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (27) @tab  67 @tab 386
12184 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (27) @tab  67 @tab 391
12185 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (20) @tab  49 @tab 197
12186 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (28) @tab  73 @tab 430
12187 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (28) @tab  73 @tab 437
12188 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (28) @tab  77 @tab 445
12189 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (29) @tab  84 @tab 448
12190 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (29) @tab  85 @tab 458
12191 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (29) @tab  85 @tab 459
12192 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (29) @tab  85 @tab 461
12193 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 467
12194 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 468
12195 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (29) @tab  90 @tab 468
12196 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (31) @tab 104 @tab 521
12197 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (31) @tab 104 @tab 525
12198 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (31) @tab 104 @tab 526
12199 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (31) @tab 111 @tab 530
12200 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (31) @tab 112 @tab 531
12201 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (31) @tab 112 @tab 533
12202 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (32) @tab 115 @tab 551
12203 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 115 @tab 552
12204 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 132 @tab 554
12205 @item 2004-11-01 @tab 1.9.3  @tab 7507 @tab 718 @tab 7804 @tab 3354 (40) @tab 1812 (32) @tab 134 @tab 556
12206 @item 2004-12-18 @tab 1.9.4  @tab 7508 @tab 718 @tab 7856 @tab 3361 (40) @tab 1811 (32) @tab 140 @tab 560
12207 @item 2005-02-13 @tab 1.9.5  @tab 7523 @tab 719 @tab 7859 @tab 3373 (40) @tab 1453 (32) @tab 142 @tab 562
12208 @item 2005-07-10 @tab 1.9.6  @tab 7539 @tab 699 @tab 7867 @tab 3400 (40) @tab 1453 (32) @tab 144 @tab 570
12209 @item 2006-10-15 @tab 1.10   @tab 7859 @tab 1072 @tab 8024 @tab 3512 (40) @tab 1496 (34) @tab 172 @tab 604
12210 @item 2008-01-19 @tab 1.10.1 @tab 7870 @tab 1089 @tab 8025 @tab 3520 (40) @tab 1499 (34) @tab 173 @tab 617
12211 @end multitable
12214 @c ========================================================== Appendices
12216 @page
12217 @node Copying This Manual
12218 @appendix Copying This Manual
12220 @menu
12221 * GNU Free Documentation License::  License for copying this manual
12222 @end menu
12224 @node GNU Free Documentation License
12225 @appendixsec GNU Free Documentation License
12226 @include fdl.texi
12228 @page
12229 @node Indices
12230 @appendix Indices
12232 @menu
12233 * Macro Index::                 Index of Autoconf macros
12234 * Variable Index::              Index of Makefile variables
12235 * General Index::               General index
12236 @end menu
12238 @node Macro Index
12239 @appendixsec Macro Index
12241 @printindex fn
12243 @node Variable Index
12244 @appendixsec Variable Index
12246 @printindex vr
12248 @node General Index
12249 @appendixsec General Index
12251 @printindex cp
12254 @page
12255 @contents
12256 @bye
12258 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
12259 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
12260 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
12261 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
12262 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
12263 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
12264 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
12265 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
12266 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
12267 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
12268 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
12269 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
12270 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
12271 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
12272 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
12273 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
12274 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
12275 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
12276 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
12277 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
12278 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
12279 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
12280 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
12281 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
12282 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
12283 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
12284 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
12285 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
12286 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
12287 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
12288 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
12289 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
12290 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
12291 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
12292 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
12293 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
12294 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
12295 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
12296 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
12297 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
12298 @c  LocalWords:  unnumberedsubsec depfile tmpdepfile depmode const interoperate
12299 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
12300 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
12301 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
12302 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
12303 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
12304 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
12305 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
12306 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
12307 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
12308 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
12309 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
12310 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
12311 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
12312 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
12313 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
12314 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
12315 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
12316 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
12317 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
12318 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
12319 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
12320 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
12321 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
12322 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
12323 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
12324 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
12325 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
12326 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
12327 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
12328 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
12329 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
12330 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
12331 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
12332 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
12333 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
12334 @c  LocalWords:  barexec Pinard's automatize initialize lzma xz