* doc/automake.texi: Fix typo.
[automake/plouj.git] / doc / automake.texi
blobda9871f93b13918ab6db5496cd7832fee7dcb065
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @setchapternewpage off
6 @c %**end of header
8 @include version.texi
10 @copying
12 This manual is for @acronym{GNU} Automake (version @value{VERSION},
13 @value{UPDATED}), a program that creates GNU standards-compliant
14 Makefiles from template files.
16 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
17 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
19 @quotation
20 Permission is granted to copy, distribute and/or modify this document
21 under the terms of the @acronym{GNU} Free Documentation License,
22 Version 1.2 or any later version published by the Free Software
23 Foundation; with no Invariant Sections, with the Front-Cover texts
24 being ``A @acronym{GNU} Manual,'' and with the Back-Cover Texts as in
25 (a) below.  A copy of the license is included in the section entitled
26 ``@acronym{GNU} Free Documentation License.''
28 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and
29 modify this @acronym{GNU} Manual, like @acronym{GNU} software.  Copies
30 published by the Free Software Foundation raise funds for
31 @acronym{GNU} development.''
32 @end quotation
33 @end copying
35 @c info Automake  points to the Automake package's documentation
36 @c info automake  points to the automake script's documentation
37 @c (Autoconf has a similar setup.)
38 @dircategory Software development
39 @direntry
40 * Automake: (automake).         Making GNU standards-compliant Makefiles.
41 @end direntry
43 @dircategory Individual utilities
44 @direntry
45 * aclocal: (automake)Invoking aclocal.          Generating aclocal.m4.
46 * automake: (automake)Invoking Automake.        Generating Makefile.in.
47 @end direntry
49 @titlepage
50 @title GNU Automake
51 @subtitle For version @value{VERSION}, @value{UPDATED}
52 @author David MacKenzie
53 @author Tom Tromey
54 @author Alexandre Duret-Lutz
55 @page
56 @vskip 0pt plus 1filll
57 @insertcopying
58 @end titlepage
61 @c We use the following macros to define indices:
62 @c   @cindex   concepts, and anything that does not fit elsewhere
63 @c   @vindex   Makefile variables
64 @c   @trindex  targets
65 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
66 @c   @opindex  tool options
68 @c Define an index of configure macros.
69 @defcodeindex ac
70 @c Define an index of options.
71 @defcodeindex op
72 @c Define an index of targets.
73 @defcodeindex tr
74 @c Define an index of commands.
75 @defcodeindex cm
77 @c Put the macros in the function index.
78 @syncodeindex ac fn
80 @c Put everything else into one index (arbitrarily chosen to be the concept index).
81 @syncodeindex op cp
82 @syncodeindex tr cp
83 @syncodeindex cm cp
85 @ifnottex
86 @node Top
87 @comment  node-name,  next,  previous,  up
88 @top GNU Automake
90 @insertcopying
92 @menu
93 * Introduction::                Automake's purpose
94 * Autotools Introduction::      An Introduction to the Autotools
95 * Generalities::                General ideas
96 * Examples::                    Some example packages
97 * Invoking Automake::           Creating a Makefile.in
98 * configure::                   Scanning configure.ac or configure.in
99 * Directories::                 Declaring subdirectories
100 * Programs::                    Building programs and libraries
101 * Other objects::               Other derived objects
102 * Other GNU Tools::             Other GNU Tools
103 * Documentation::               Building documentation
104 * Install::                     What gets installed
105 * Clean::                       What gets cleaned
106 * Dist::                        What goes in a distribution
107 * Tests::                       Support for test suites
108 * Rebuilding::                  Automatic rebuilding of Makefile
109 * Options::                     Changing Automake's behavior
110 * Miscellaneous::               Miscellaneous rules
111 * Include::                     Including extra files in an Automake template.
112 * Conditionals::                Conditionals
113 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
114 * Cygnus::                      The effect of @option{--cygnus}
115 * Not Enough::                  When Automake is not Enough
116 * Distributing::                Distributing the Makefile.in
117 * API versioning::              About compatibility between Automake versions
118 * Upgrading::                   Upgrading to a Newer Automake Version
119 * FAQ::                         Frequently Asked Questions
120 * History::                     Notes about the history of Automake
121 * Copying This Manual::         How to make copies of this manual
122 * Indices::                     Indices of variables, macros, and concepts
124 @detailmenu
125  --- The Detailed Node Listing ---
127 An Introduction to the Autotools
129 * GNU Build System::            Introducing the GNU Build System
130 * Use Cases::                   Use Cases for the GNU Build System
131 * Why Autotools::               How Autotools Help
132 * Hello World::                 A Small Hello World Package
134 Use Cases for the GNU Build System
136 * Basic Installation::          Common installation procedure
137 * Standard Targets::            A list of standard Makefile targets
138 * Standard Directory Variables::  A list of standard directory variables
139 * Standard Configuration Variables::  Using configuration variables
140 * config.site::                 Using a config.site file
141 * VPATH Builds::                Parallel build trees
142 * Two-Part Install::            Installing data and programs separately
143 * Cross-Compilation::           Building for other architectures
144 * Renaming::                    Renaming programs at install time
145 * DESTDIR::                     Building binary packages with DESTDIR
146 * Preparing Distributions::     Rolling out tarballs
147 * Dependency Tracking::         Automatic dependency tracking
148 * Nested Packages::             The GNU Build Systems can be nested
150 A Small Hello World
152 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
153 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
155 General ideas
157 * General Operation::           General operation of Automake
158 * Strictness::                  Standards conformance checking
159 * Uniform::                     The Uniform Naming Scheme
160 * Canonicalization::            How derived variables are named
161 * User Variables::              Variables reserved for the user
162 * Auxiliary Programs::          Programs automake might require
164 Some example packages
166 * Complete::                    A simple example, start to finish
167 * true::                        Building true and false
169 Scanning @file{configure.ac}
171 * Requirements::                Configuration requirements
172 * Optional::                    Other things Automake recognizes
173 * Invoking aclocal::            Auto-generating aclocal.m4
174 * Macros::                      Autoconf macros supplied with Automake
176 Auto-generating aclocal.m4
178 * aclocal options::             Options supported by aclocal
179 * Macro search path::           How aclocal finds .m4 files
180 * Extending aclocal::           Writing your own aclocal macros
181 * Local Macros::                Organizing local macros
182 * Serials::                     Serial lines in Autoconf macros
183 * Future of aclocal::           aclocal's scheduled death
185 Autoconf macros supplied with Automake
187 * Public macros::               Macros that you can use.
188 * Obsolete macros::             Macros that you should stop using.
189 * Private macros::              Macros that you should not use.
191 Directories
193 * Subdirectories::              Building subdirectories recursively
194 * Conditional Subdirectories::  Conditionally not building directories
195 * Alternative::                 Subdirectories without recursion
196 * Subpackages::                 Nesting packages
198 Building Programs and Libraries
200 * A Program::                   Building a program
201 * A Library::                   Building a library
202 * A Shared Library::            Building a Libtool library
203 * Program and Library Variables::  Variables controlling program and
204                                 library builds
205 * Default _SOURCES::            Default source files
206 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
207 * Program variables::           Variables used when building a program
208 * Yacc and Lex::                Yacc and Lex support
209 * C++ Support::                 Compiling C++ sources
210 * Objective C Support::         Compiling Objective C sources
211 * Unified Parallel C Support::  Compiling Unified Parallel C sources
212 * Assembly Support::            Compiling assembly sources
213 * Fortran 77 Support::          Compiling Fortran 77 sources
214 * Fortran 9x Support::          Compiling Fortran 9x sources
215 * Java Support::                Compiling Java sources
216 * Support for Other Languages::  Compiling other languages
217 * ANSI::                        Automatic de-ANSI-fication (obsolete)
218 * Dependencies::                Automatic dependency tracking
219 * EXEEXT::                      Support for executable extensions
221 Building a program
223 * Program Sources::             Defining program sources
224 * Linking::                     Linking with libraries or extra objects
225 * Conditional Sources::         Handling conditional sources
226 * Conditional Programs::        Building program conditionally
228 Building a Shared Library
230 * Libtool Concept::             Introducing Libtool
231 * Libtool Libraries::           Declaring Libtool Libraries
232 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
233 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
234 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
235 * Libtool Modules::             Building Libtool Modules
236 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
237 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
238 * Libtool Issues::              Common Issues Related to Libtool's Use
240 Fortran 77 Support
242 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
243 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
244 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
246 Mixing Fortran 77 With C and C++
248 * How the Linker is Chosen::    Automatic linker selection
250 Fortran 9x Support
252 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
254 Other Derived Objects
256 * Scripts::                     Executable scripts
257 * Headers::                     Header files
258 * Data::                        Architecture-independent data files
259 * Sources::                     Derived sources
261 Built sources
263 * Built sources example::       Several ways to handle built sources.
265 Other GNU Tools
267 * Emacs Lisp::                  Emacs Lisp
268 * gettext::                     Gettext
269 * Libtool::                     Libtool
270 * Java::                        Java
271 * Python::                      Python
273 Building documentation
275 * Texinfo::                     Texinfo
276 * Man pages::                   Man pages
278 Miscellaneous Rules
280 * Tags::                        Interfacing to etags and mkid
281 * Suffixes::                    Handling new file extensions
282 * Multilibs::                   Support for multilibs.
284 When Automake Isn't Enough
286 * Extending::                   Adding new rules or overriding existing ones.
287 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
289 Frequently Asked Questions about Automake
291 * CVS::                         CVS and generated files
292 * maintainer-mode::             missing and AM_MAINTAINER_MODE
293 * wildcards::                   Why doesn't Automake support wildcards?
294 * limitations on file names::   Limitations on source and installed file names
295 * distcleancheck::              Files left in build directory after distclean
296 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
297 * renamed objects::             Why are object files sometimes renamed?
298 * Per-Object Flags::            How to simulate per-object flags?
299 * Multiple Outputs::            Writing rules for tools with many output files
300 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
302 History of Automake
304 * Timeline::                    The Automake story.
305 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
306 * Releases::                    Statistics about Automake Releases
308 Copying This Manual
310 * GNU Free Documentation License::  License for copying this manual
312 Indices
314 * Macro Index::                 Index of Autoconf macros
315 * Variable Index::              Index of Makefile variables
316 * General Index::               General index
318 @end detailmenu
319 @end menu
321 @end ifnottex
324 @node Introduction
325 @chapter Introduction
327 Automake is a tool for automatically generating @file{Makefile.in}s
328 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
329 basically a series of @command{make} variable
330 definitions@footnote{These variables are also called @dfn{make macros}
331 in Make terminology, however in this manual we reserve the term
332 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
333 occasionally.  The generated @file{Makefile.in}s are compliant with
334 the GNU Makefile standards.
336 @cindex GNU Makefile standards
338 The GNU Makefile Standards Document
339 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
340 is long, complicated, and subject to change.  The goal of Automake is to
341 remove the burden of Makefile maintenance from the back of the
342 individual GNU maintainer (and put it on the back of the Automake
343 maintainers).
345 The typical Automake input file is simply a series of variable definitions.
346 Each such file is processed to create a @file{Makefile.in}.  There
347 should generally be one @file{Makefile.am} per directory of a project.
349 @cindex Constraints of Automake
350 @cindex Automake constraints
352 Automake does constrain a project in certain ways; for instance, it
353 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
354 autoconf, The Autoconf Manual}), and enforces certain restrictions on
355 the @file{configure.ac} contents@footnote{Older Autoconf versions used
356 @file{configure.in}.  Autoconf 2.50 and greater promotes
357 @file{configure.ac} over @file{configure.in}.  The rest of this
358 documentation will refer to @file{configure.ac}, but Automake also
359 supports @file{configure.in} for backward compatibility.}.
361 @cindex Automake requirements
362 @cindex Requirements, Automake
364 Automake requires @command{perl} in order to generate the
365 @file{Makefile.in}s.  However, the distributions created by Automake are
366 fully GNU standards-compliant, and do not require @command{perl} in order
367 to be built.
369 @cindex Bugs, reporting
370 @cindex Reporting bugs
371 @cindex E-mail, bug reports
373 Mail suggestions and bug reports for Automake to
374 @email{bug-automake@@gnu.org}.
376 @node Autotools Introduction
377 @chapter An Introduction to the Autotools
379 If you are new to Automake, maybe you know that it is part of a set of
380 tools called @emph{The Autotools}.  Maybe you've already delved into a
381 package full of files named @file{configure}, @file{configure.ac},
382 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
383 some of them claiming to be @emph{generated by} Autoconf or Automake.
384 But the exact purpose of these files and their relations is probably
385 fuzzy.  The goal of this chapter is to introduce you to this machinery,
386 to show you how it works and how powerful it is.  If you've never
387 installed or seen such a package, do not worry: this chapter will walk
388 you through it.
390 If you need some teaching material, more illustrations, or a less
391 @command{automake}-centered continuation, some slides for this
392 introduction are available in Alexandre Duret-Lutz's
393 @uref{http://www-src.lip6.fr/@/~Alexandre.Duret-Lutz/@/autotools.html,
394 Autotools Tutorial}.
395 This chapter is the written version of the first part of his tutorial.
397 @menu
398 * GNU Build System::            Introducing the GNU Build System
399 * Use Cases::                   Use Cases for the GNU Build System
400 * Why Autotools::               How Autotools Help
401 * Hello World::                 A Small Hello World Package
402 @end menu
404 @node GNU Build System
405 @section Introducing the GNU Build System
406 @cindex GNU Build System, introduction
408 It is a truth universally acknowledged, that a developer in
409 possession of a new package, must be in want of a build system.
411 In the Unix world, such a build system is traditionally achieved using
412 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
413 Manual}).  The developer expresses the recipe to build his package in
414 a @file{Makefile}.  This file is a set of rules to build the files in
415 the package.  For instance the program @file{prog} may be built by
416 running the linker on the files @file{main.o}, @file{foo.o}, and
417 @file{bar.o}; the file @file{main.o} may be built by running the
418 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
419 reads @file{Makefile}, checks the existence and modification time of
420 the files mentioned, decides what files need to be built (or rebuilt),
421 and runs the associated commands.
423 When a package needs to be built on a different platform than the one
424 it was developed on, its @file{Makefile} usually needs to be adjusted.
425 For instance the compiler may have another name or require more
426 options.  In 1991, David J. MacKenzie got tired of customizing
427 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
428 handcrafted a little shell script called @file{configure} to
429 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
430 autoconf, The Autoconf Manual}).  Compiling his package was now
431 as simple as running @code{./configure && make}.
433 @cindex GNU Coding Standards
435 Today this process has been standardized in the GNU project.  The GNU
436 Coding Standards (@pxref{Managing Releases, The Release Process, ,
437 standards, The GNU Coding Standards}) explains how each package of the
438 GNU project should have a @file{configure} script, and the minimal
439 interface it should have.  The @file{Makefile} too should follow some
440 established conventions.  The result?  A unified build system that
441 makes all packages almost indistinguishable by the installer.  In its
442 simplest scenario, all the installer has to do is to unpack the
443 package, run @code{./configure && make && make install}, and repeat
444 with the next package to install.
446 We call this build system the @dfn{GNU Build System}, since it was
447 grown out of the GNU project.  However it is used by a vast number of
448 other packages: following any existing convention has its advantages.
450 @cindex Autotools, introduction
452 The Autotools are tools that will create a GNU Build System for your
453 package.  Autoconf mostly focuses on @file{configure} and Automake on
454 @file{Makefile}s.  It is entirely possible to create a GNU Build
455 System without the help of these tools.  However it is rather
456 burdensome and error-prone.  We will discuss this again after some
457 illustration of the GNU Build System in action.
459 @node Use Cases
460 @section Use Cases for the GNU Build System
461 @cindex GNU Build System, use cases
462 @cindex GNU Build System, features
463 @cindex Features of the GNU Build System
464 @cindex Use Cases for the GNU Build System
465 @cindex @file{amhello-1.0.tar.gz}, location
466 @cindex @file{amhello-1.0.tar.gz}, use cases
468 In this section we explore several use cases for the GNU Build System.
469 You can replay all these examples on the @file{amhello-1.0.tar.gz}
470 package distributed with Automake.  If Automake is installed on your
471 system, you should find a copy of this file in
472 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
473 @var{prefix} is the installation prefix specified during configuration
474 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
475 installed by some GNU/Linux distribution it most likely has been set
476 to @file{/usr}).  If you do not have a copy of Automake installed,
477 you can find a copy of this file inside the @file{doc/} directory of
478 the Automake package.
480 Some of the following use cases present features that are in fact
481 extensions to the GNU Build System.  Read: they are not specified by
482 the GNU Coding Standards, but they are nonetheless part of the build
483 system created by the Autotools.  To keep things simple, we do not
484 point out the difference.  Our objective is to show you many of the
485 features that the build system created by the Autotools will offer to
486 you.
488 @menu
489 * Basic Installation::          Common installation procedure
490 * Standard Targets::            A list of standard Makefile targets
491 * Standard Directory Variables::  A list of standard directory variables
492 * Standard Configuration Variables::  Using configuration variables
493 * config.site::                 Using a config.site file
494 * VPATH Builds::                Parallel build trees
495 * Two-Part Install::            Installing data and programs separately
496 * Cross-Compilation::           Building for other architectures
497 * Renaming::                    Renaming programs at install time
498 * DESTDIR::                     Building binary packages with DESTDIR
499 * Preparing Distributions::     Rolling out tarballs
500 * Dependency Tracking::         Automatic dependency tracking
501 * Nested Packages::             The GNU Build Systems can be nested
502 @end menu
504 @node Basic Installation
505 @subsection Basic Installation
506 @cindex Configuration, basics
507 @cindex Installation, basics
508 @cindex GNU Build System, basics
510 The most common installation procedure looks as follows.
512 @example
513 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
514 ~ % @kbd{cd amhello-1.0}
515 ~/amhello-1.0 % @kbd{./configure}
516 @dots{}
517 config.status: creating Makefile
518 config.status: creating src/Makefile
519 @dots{}
520 ~/amhello-1.0 % @kbd{make}
521 @dots{}
522 ~/amhello-1.0 % @kbd{make check}
523 @dots{}
524 ~/amhello-1.0 % @kbd{su}
525 Password:
526 /home/adl/amhello-1.0 # @kbd{make install}
527 @dots{}
528 /home/adl/amhello-1.0 # @kbd{exit}
529 ~/amhello-1.0 % @kbd{make installcheck}
530 @dots{}
531 @end example
533 @cindex Unpacking
535 The user first unpacks the package.  Here, and in the following
536 examples, we will use the non-portable @code{tar zxf} command for
537 simplicity.  On a system without GNU @command{tar} installed, this
538 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
540 The user then enters the newly created directory to run the
541 @file{configure} script.  This script probes the system for various
542 features, and finally creates the @file{Makefile}s.  In this toy
543 example there are only two @file{Makefile}s, but in real-world project
544 there may be many more, usually one @file{Makefile} per directory.
546 It is now possible to run @code{make}.  This will construct all the
547 programs, libraries, and scripts that need to be constructed for the
548 package.  In our example, this compiles the @file{hello} program.
549 All files are constructed in place, in the source tree; we will see
550 later how this can be changed.
552 @code{make check} causes the package's tests to be run.  This step is
553 not mandatory, but it is often good to make sure the programs that
554 have been built behave as they should, before you decide to install
555 them.  Our example does not contain any tests, so running @code{make
556 check} is a no-op.
558 @cindex su, before @code{make install}
559 After everything has been built, and maybe tested, it is time to
560 install it on the system.  That means copying the programs,
561 libraries, header files, scripts, and other data files from the
562 source directory to their final destination on the system.  The
563 command @code{make install} will do that.  However, by default
564 everything will be installed in subdirectories of @file{/usr/local}:
565 binaries will go into @file{/usr/local/bin}, libraries will end up in
566 @file{/usr/local/lib}, etc.  This destination is usually not writable
567 by any user, so we assume that we have to become root before we can
568 run @code{make install}.  In our example, running @code{make install}
569 will copy the program @file{hello} into @file{/usr/local/bin}
570 and @file{README} into @file{/usr/local/share/doc/amhello}.
572 A last and optional step is to run @code{make installcheck}.  This
573 command may run tests on the installed files.  @code{make check} tests
574 the files in the source tree, while @code{make installcheck} tests
575 their installed copies.  The tests run by the latter can be different
576 from those run by the former.  For instance, there are tests that
577 cannot be run in the source tree.  Conversely, some packages are set
578 up so that @code{make installcheck} will run the very same tests as
579 @code{make check}, only on different files (non-installed
580 vs.@: installed).  It can make a difference, for instance when the
581 source tree's layout is different from that of the installation.
582 Furthermore it may help to diagnose an incomplete installation.
584 Presently most packages do not have any @code{installcheck} tests
585 because the existence of @code{installcheck} is little known, and its
586 usefulness is neglected.  Our little toy package is no better: @code{make
587 installcheck} does nothing.
589 @node Standard Targets
590 @subsection Standard @file{Makefile} Targets
592 So far we have come across four ways to run @command{make} in the GNU
593 Build System: @code{make}, @code{make check}, @code{make install}, and
594 @code{make installcheck}.  The words @code{check}, @code{install}, and
595 @code{installcheck}, passed as arguments to @command{make}, are called
596 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
597 @code{all} being the default target in the GNU Build System.
599 Here is a list of the most useful targets that the GNU Coding Standards
600 specify.
602 @table @code
603 @item make all
604 @trindex all
605 Build programs, libraries, documentation, etc.@: (same as @code{make}).
606 @item make install
607 @trindex install
608 Install what needs to be installed, copying the files from the
609 package's tree to system-wide directories.
610 @item make install-strip
611 @trindex install-strip
612 Same as @code{make install}, then strip debugging symbols.  Some
613 users like to trade space for useful bug reports@enddots{}
614 @item make uninstall
615 @trindex uninstall
616 The opposite of @code{make install}: erase the installed files.
617 (This needs to be run from the same build tree that was installed.)
618 @item make clean
619 @trindex clean
620 Erase from the build tree the files built by @code{make all}.
621 @item make distclean
622 @trindex distclean
623 Additionally erase anything @code{./configure} created.
624 @item make check
625 @trindex check
626 Run the test suite, if any.
627 @item make installcheck
628 @trindex installcheck
629 Check the installed programs or libraries, if supported.
630 @item make dist
631 @trindex dist
632 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
633 files.
634 @end table
636 @node Standard Directory Variables
637 @subsection Standard Directory Variables
638 @cindex directory variables
640 The GNU Coding Standards also specify a hierarchy of variables to
641 denote installation directories.  Some of these are:
643 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
644 @headitem Directory variable    @tab Default value
645 @item @code{prefix}              @tab @code{/usr/local}
646 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
647 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
648 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
649 @item @w{@ @ @ @ @dots{}}
650 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
651 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
652 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
653 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
654 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
655 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
656 @item @w{@ @ @dots{}}
657 @end multitable
659 @c We should provide a complete table somewhere, but not here.  The
660 @c complete list of directory variables it too confusing as-is.  It
661 @c requires some explanations that are too complicated for this
662 @c introduction.  Besides listing directories like localstatedir
663 @c would make the explanations in ``Two-Part Install'' harder.
665 Each of these directories has a role which is often obvious from its
666 name.  In a package, any installable file will be installed in one of
667 these directories.  For instance in @code{amhello-1.0}, the program
668 @file{hello} is to be installed in @var{bindir}, the directory for
669 binaries.  The default value for this directory is
670 @file{/usr/local/bin}, but the user can supply a different value when
671 calling @command{configure}.  Also the file @file{README} will be
672 installed into @var{docdir}, which defaults to
673 @file{/usr/local/share/doc/amhello}.
675 @opindex --prefix
677 A user who wishes to install a package on his own account could proceed
678 as follows:
680 @example
681 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
682 @dots{}
683 ~/amhello-1.0 % @kbd{make}
684 @dots{}
685 ~/amhello-1.0 % @kbd{make install}
686 @dots{}
687 @end example
689 This would install @file{~/usr/bin/hello} and
690 @file{~/usr/share/doc/amhello/README}.
692 The list of all such directory options is shown by
693 @code{./configure --help}.
695 @node Standard Configuration Variables
696 @subsection Standard Configuration Variables
697 @cindex configuration variables, overriding
699 The GNU Coding Standards also define a set of standard configuration
700 variables used during the build.  Here are some:
702 @table @asis
703 @item @code{CC}
704 C compiler command
705 @item @code{CFLAGS}
706 C compiler flags
707 @item @code{CXX}
708 C++ compiler command
709 @item @code{CXXFLAGS}
710 C++ compiler flags
711 @item @code{LDFLAGS}
712 linker flags
713 @item @code{CPPFLAGS}
714 C/C++ preprocessor flags
715 @item @dots{}
716 @end table
718 @command{configure} usually does a good job at setting appropriate
719 values for these variables, but there are cases where you may want to
720 override them.  For instance you may have several versions of a
721 compiler installed and would like to use another one, you may have
722 header files installed outside the default search path of the
723 compiler, or even libraries out of the way of the linker.
725 Here is how one would call @command{configure} to force it to use
726 @command{gcc-3} as C compiler, use header files from
727 @file{~/usr/include} when compiling, and libraries from
728 @file{~/usr/lib} when linking.
730 @example
731 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
732 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
733 @end example
735 Again, a full list of these variables appears in the output of
736 @code{./configure --help}.
738 @node config.site
739 @subsection Overriding Default Configuration Setting with @file{config.site}
740 @cindex @file{config.site} example
742 When installing several packages using the same setup, it can be
743 convenient to create a file to capture common settings.
744 If a file named @file{@var{prefix}/share/config.site} exists,
745 @command{configure} will source it at the beginning of its execution.
747 Recall the command from the previous section:
749 @example
750 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
751 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
752 @end example
754 Assuming we are installing many package in @file{~/usr}, and will
755 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
756 @code{LDFLAGS}, we can automate this by creating the following
757 @file{~/usr/share/config.site} file:
759 @example
760 test -z "$CC" && CC=gcc-3
761 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
762 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
763 @end example
765 Now, any time a @file{configure} script is using the @file{~/usr}
766 prefix, it will execute the above @file{config.site} and define
767 these three variables.
769 @example
770 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
771 configure: loading site script /home/adl/usr/share/config.site
772 @dots{}
773 @end example
775 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
776 Manual}, for more information about this feature.
779 @node VPATH Builds
780 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
781 @cindex Parallel build trees
782 @cindex VPATH builds
783 @cindex source tree and build tree
784 @cindex build tree and source tree
785 @cindex trees, source vs.@: build
787 The GNU Build System distinguishes two trees: the source tree, and
788 the build tree.
790 The source tree is rooted in the directory containing
791 @file{configure}.  It contains all the sources files (those that are
792 distributed), and may be arranged using several subdirectories.
794 The build tree is rooted in the directory in which @file{configure}
795 was run, and is populated with all object files, programs, libraries,
796 and other derived files built from the sources (and hence not
797 distributed).  The build tree usually has the same subdirectory layout
798 as the source tree; its subdirectories are created automatically by
799 the build system.
801 If @file{configure} is executed in its own directory, the source and
802 build trees are combined: derived files are constructed in the same
803 directories as their sources.  This was the case in our first
804 installation example (@pxref{Basic Installation}).
806 A common request from users is that they want to confine all derived
807 files to a single directory, to keep their source directories
808 uncluttered.  Here is how we could run @file{configure} to build
809 everything in a subdirectory called @file{build/}.
811 @example
812 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
813 ~ % @kbd{cd amhello-1.0}
814 ~/amhello-1.0 % @kbd{mkdir build && cd build}
815 ~/amhello-1.0/build % @kbd{../configure}
816 @dots{}
817 ~/amhello-1.0/build % @kbd{make}
818 @dots{}
819 @end example
821 These setups, where source and build trees are different, are often
822 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
823 @emph{parallel build} is misleading: the word @emph{parallel} is a
824 reference to the way the build tree shadows the source tree, it is not
825 about some concurrency in the way build commands are run.  For this
826 reason we refer to such setups using the name @emph{VPATH builds} in
827 the sequel.  @emph{VPATH} is the name of the @command{make} feature
828 used by the @file{Makefile}s to allow these builds (@pxref{General
829 Search, , @code{VPATH}: Search Path for All Prerequisites, make, The
830 GNU Make Manual}).
832 @cindex multiple configurations, example
833 @cindex debug build, example
834 @cindex optimized build, example
836 VPATH builds have other interesting uses.  One is to build the same
837 sources with multiple configurations.  For instance:
839 @example
840 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
841 ~ % @kbd{cd amhello-1.0}
842 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
843 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
844 @dots{}
845 ~/amhello-1.0/debug % @kbd{make}
846 @dots{}
847 ~/amhello-1.0/debug % cd ../optim
848 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
849 @dots{}
850 ~/amhello-1.0/optim % @kbd{make}
851 @dots{}
852 @end example
854 With network file systems, a similar approach can be used to build the
855 same sources on different machines.  For instance, suppose that the
856 sources are installed on a directory shared by two hosts: @code{HOST1}
857 and @code{HOST2}, which may be different platforms.
859 @example
860 ~ % @kbd{cd /nfs/src}
861 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
862 @end example
864 On the first host, you could create a local build directory:
865 @example
866 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
867 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
869 [HOST1] /tmp/amh % @kbd{make && sudo make install}
871 @end example
873 @noindent
874 (Here we assume the that installer has configured @command{sudo} so it
875 can execute @code{make install} with root privileges; it is more convenient
876 than using @command{su} like in @ref{Basic Installation}).
878 On the second host, you would do exactly the same, possibly at
879 the same time:
880 @example
881 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
882 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
884 [HOST2] /tmp/amh % @kbd{make && sudo make install}
886 @end example
888 @cindex read-only source tree
889 @cindex source tree, read-only
891 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
892 directory from being read-only.  In fact VPATH builds are also a means
893 of building packages from a read-only medium such as a CD-ROM.  (The
894 FSF used to sell CD-ROM with unpacked source code, before the GNU
895 project grew so big.)
897 @node Two-Part Install
898 @subsection Two-Part Installation
900 In our last example (@pxref{VPATH Builds}), a source tree was shared
901 by two hosts, but compilation and installation were done separately on
902 each host.
904 The GNU Build System also supports networked setups where part of the
905 installed files should be shared amongst multiple hosts.  It does so
906 by distinguishing architecture-dependent files from
907 architecture-independent files, and providing two @file{Makefile}
908 targets to install each of these classes of files.
910 @trindex install-exec
911 @trindex install-data
913 These targets are @code{install-exec} for architecture-dependent files
914 and @code{install-data} for architecture-independent files.
915 The command we used up to now, @code{make install}, can be thought of
916 as a shorthand for @code{make install-exec install-data}.
918 From the GNU Build System point of view, the distinction between
919 architecture-dependent files and architecture-independent files is
920 based exclusively on the directory variable used to specify their
921 installation destination.  In the list of directory variables we
922 provided earlier (@pxref{Standard Directory Variables}), all the
923 variables based on @var{exec-prefix} designate architecture-dependent
924 directories whose files will be installed by @code{make install-exec}.
925 The others designate architecture-independent directories and will
926 serve files installed by @code{make install-data}.  @xref{Install},
927 for more details.
929 Here is how we could revisit our two-host installation example,
930 assuming that (1) we want to install the package directly in
931 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
932 two hosts.
934 On the first host we would run
935 @example
936 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
937 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
939 [HOST1] /tmp/amh % @kbd{make && sudo make install}
941 @end example
943 On the second host, however, we need only install the
944 architecture-specific files.
945 @example
946 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
947 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
949 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
951 @end example
953 In packages that have installation checks, it would make sense to run
954 @code{make installcheck} (@pxref{Basic Installation}) to verify that
955 the package works correctly despite the apparent partial installation.
957 @node Cross-Compilation
958 @subsection Cross-Compilation
959 @cindex cross-compilation
961 To @dfn{cross-compile} is to build on one platform a binary that will
962 run on another platform.  When speaking of cross-compilation, it is
963 important to distinguish between the @dfn{build platform} on which
964 the compilation is performed, and the @dfn{host platform} on which the
965 resulting executable is expected to run.  The following
966 @command{configure} options are used to specify each of them:
968 @table @option
969 @item --build=@var{BUILD}
970 @opindex --build=@var{BUILD}
971 The system on which the package is built.
972 @item --host=@var{HOST}
973 @opindex --host=@var{HOST}
974 The system where built programs and libraries will run.
975 @end table
977 When the @option{--host} is used, @command{configure} will search for
978 the cross-compiling suite for this platform.  Cross-compilation tools
979 commonly have their target architecture as prefix of their name.  For
980 instance my cross-compiler for MinGW32 has its binaries called
981 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
982 @code{i586-mingw32msvc-as}, etc.
984 @cindex MinGW cross-compilation example
985 @cindex cross-compilation example
987 Here is how we could build @code{amhello-1.0} for
988 @code{i586-mingw32msvc} on a GNU/Linux PC.
990 @smallexample
991 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
992 checking for a BSD-compatible install... /usr/bin/install -c
993 checking whether build environment is sane... yes
994 checking for gawk... gawk
995 checking whether make sets $(MAKE)... yes
996 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
997 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
998 checking for C compiler default output file name... a.exe
999 checking whether the C compiler works... yes
1000 checking whether we are cross compiling... yes
1001 checking for suffix of executables... .exe
1002 checking for suffix of object files... o
1003 checking whether we are using the GNU C compiler... yes
1004 checking whether i586-mingw32msvc-gcc accepts -g... yes
1005 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1006 @dots{}
1007 ~/amhello-1.0 % @kbd{make}
1008 @dots{}
1009 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1010 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1011 @end smallexample
1013 The @option{--host} and @option{--build} options are usually all we
1014 need for cross-compiling.  The only exception is if the package being
1015 built is itself a cross-compiler: we need a third option to specify
1016 its target architecture.
1018 @table @option
1019 @item --target=@var{TARGET}
1020 @opindex --target=@var{TARGET}
1021 When building compiler tools: the system for which the tools will
1022 create output.
1023 @end table
1025 For instance when installing GCC, the GNU Compiler Collection, we can
1026 use @option{--target=@var{TARGET}} to specify that we want to build
1027 GCC as a cross-compiler for @var{TARGET}.  Mixing @option{--build} and
1028 @option{--target}, we can actually cross-compile a cross-compiler;
1029 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1031 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1032 Autoconf Manual}, for more information about these @command{configure}
1033 options.
1035 @node Renaming
1036 @subsection Renaming Programs at Install Time
1037 @cindex Renaming programs
1038 @cindex Transforming program names
1039 @cindex Programs, renaming during installation
1041 The GNU Build System provides means to automatically rename
1042 executables before they are installed.  This is especially convenient
1043 when installing a GNU package on a system that already has a
1044 proprietary implementation you do not want to overwrite.  For instance,
1045 you may want to install GNU @command{tar} as @command{gtar} so you can
1046 distinguish it from your vendor's @command{tar}.
1048 This can be done using one of these three @command{configure} options.
1050 @table @option
1051 @item --program-prefix=@var{PREFIX}
1052 @opindex --program-prefix=@var{PREFIX}
1053 Prepend @var{PREFIX} to installed program names.
1054 @item --program-suffix=@var{SUFFIX}
1055 @opindex --program-suffix=@var{SUFFIX}
1056 Append @var{SUFFIX} to installed program names.
1057 @item --program-transform-name=@var{PROGRAM}
1058 @opindex --program-transform-name=@var{PROGRAM}
1059 Run @code{sed @var{PROGRAM}} on installed program names.
1060 @end table
1062 The following commands would install @file{hello}
1063 as @file{/usr/local/bin/test-hello}, for instance.
1065 @example
1066 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1067 @dots{}
1068 ~/amhello-1.0 % @kbd{make}
1069 @dots{}
1070 ~/amhello-1.0 % @kbd{sudo make install}
1071 @dots{}
1072 @end example
1074 @node DESTDIR
1075 @subsection Building Binary Packages Using DESTDIR
1076 @vindex DESTDIR
1078 The GNU Build System's @code{make install} and @code{make uninstall}
1079 interface does not exactly fit the needs of a system administrator
1080 who has to deploy and upgrade packages on lots of hosts.  In other
1081 words, the GNU Build System does not replace a package manager.
1083 Such package managers usually need to know which files have been
1084 installed by a package, so a mere @code{make install} is
1085 inappropriate.
1087 @cindex Staged installation
1089 The @code{DESTDIR} variable can be used to perform a staged
1090 installation.  The package should be configured as if it was going to
1091 be installed in its final location (e.g., @code{--prefix /usr}), but
1092 when running @code{make install} the @code{DESTDIR} should be set to
1093 the absolute name of a directory in which all the installation will be
1094 diverted.  From this directory it is easy to review which files are
1095 being installed where, and finally copy them to their final location
1096 by any means.
1098 @cindex Binary package
1100 For instance here is how we could create a binary package containing a
1101 snapshot of all the files to be installed.
1103 @example
1104 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1105 @dots{}
1106 ~/amhello-1.0 % @kbd{make}
1107 @dots{}
1108 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1109 @dots{}
1110 ~/amhello-1.0 % @kbd{cd ~/inst}
1111 ~/inst % @kbd{find . -type f -print > ../files.lst}
1112 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../file.lst`}
1113 ./usr/bin/hello
1114 ./usr/share/doc/amhello/README
1115 @end example
1117 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1118 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../file.lst`}
1119 instead of @samp{.} as argument for @command{tar} avoids entries for
1120 each subdirectory in the archive: we would not like @command{tar} to
1121 restore the modification time of @file{/}, @file{/usr/}, etc.)
1123 Note that when building packages for several architectures, it might
1124 be convenient to use @code{make install-data} and @code{make
1125 install-exec} (@pxref{Two-Part Install}) to gather
1126 architecture-independent files in a single package.
1128 @xref{Install}, for more information.
1130 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1131 @c UNINSTALL counterparts.
1133 @node Preparing Distributions
1134 @subsection Preparing Distributions
1135 @cindex Preparing distributions
1136 @cindex Packages, preparation
1137 @cindex Distributions, preparation
1139 We have already mentioned @code{make dist}.  This target collects all
1140 your source files and the necessary parts of the build system to
1141 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1143 @cindex @code{distcheck} better than @code{dist}
1145 Another, more useful command is @code{make distcheck}.  The
1146 @code{distcheck} target constructs
1147 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1148 but it additionally ensures most of the use cases presented so far
1149 work:
1151 @itemize @bullet
1152 @item
1153 It attempts a full compilation of the package (@pxref{Basic
1154 Installation}), unpacking the newly constructed tarball, running
1155 @code{make}, @code{make check}, @code{make install}, as well as
1156 @code{make installcheck}, and even @code{make dist},
1157 @item
1158 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1159 @item
1160 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1161 uninstall} do not omit any file (@pxref{Standard Targets}),
1162 @item
1163 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1164 @end itemize
1166 All of these actions are performed in a temporary subdirectory, so
1167 that no root privileges are required.
1169 Releasing a package that fails @code{make distcheck} means that one of
1170 the scenarios we presented will not work and some users will be
1171 disappointed.  Therefore it is a good practice to release a package
1172 only after a successful @code{make distcheck}.  This of course does
1173 not imply that the package will be flawless, but at least it will
1174 prevent some of the embarrassing errors you may find in packages
1175 released by people who have never heard about @code{distcheck} (like
1176 @code{DESTDIR} not working because of a typo, or a distributed file
1177 being erased by @code{make clean}, or even @code{VPATH} builds not
1178 working).
1180 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1181 @code{make distcheck}.  @xref{Dist}, for more information about
1182 @code{distcheck}.
1184 @node Dependency Tracking
1185 @subsection Automatic Dependency Tracking
1186 @cindex Dependency tracking
1188 Dependency tracking is performed as a side-effect of compilation.
1189 Each time the build system compiles a source file, it computes its
1190 list of dependencies (in C these are the header files included by the
1191 source being compiled).  Later, any time @command{make} is run and a
1192 dependency appears to have changed, the dependent files will be
1193 rebuilt.
1195 When @command{configure} is executed, you can see it probing each
1196 compiler for the dependency mechanism it supports (several mechanisms
1197 can be used):
1199 @example
1200 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1201 @dots{}
1202 checking dependency style of gcc... gcc3
1203 @dots{}
1204 @end example
1206 Because dependencies are only computed as a side-effect of the
1207 compilation, no dependency information exists the first time a package
1208 is built.  This is OK because all the files need to be built anyway:
1209 @code{make} does not have to decide which files need to be rebuilt.
1210 In fact, dependency tracking is completely useless for one-time builds
1211 and there is a @command{configure} option to disable this:
1213 @table @option
1214 @item --disable-dependency-tracking
1215 @opindex --disable-dependency-tracking
1216 Speed up one-time builds.
1217 @end table
1219 Some compilers do not offer any practical way to derive the list of
1220 dependencies as a side-effect of the compilation, requiring a separate
1221 run (maybe of another tool) to compute these dependencies.  The
1222 performance penalty implied my these methods is important enough to
1223 disable them by default.  The option @option{--enable-dependency-tracking}
1224 must be passed to @command{configure} to activate them.
1226 @table @option
1227 @item --enable-dependency-tracking
1228 @opindex --enable-dependency-tracking
1229 Do not reject slow dependency extractors.
1230 @end table
1232 @xref{Dependency Tracking Evolution}, for some discussion about the
1233 different dependency tracking schemes used by Automake over the years.
1235 @node Nested Packages
1236 @subsection Nested Packages
1237 @cindex Nested packages
1238 @cindex Packages, nested
1239 @cindex Subpackages
1241 Although nesting packages isn't something we would recommend to
1242 someone who is discovering the Autotools, it is a nice feature worthy
1243 of mention in this small advertising tour.
1245 Autoconfiscated packages (that means packages whose build system have
1246 been created by Autoconf and friends) can be nested to arbitrary
1247 depth.
1249 A typical setup is that a package A will distribute one of the libraries
1250 it needs in a subdirectory.  This library B is a complete package with
1251 its own GNU Build System.  The @command{configure} script of A will
1252 run the @command{configure} script of B as part of its execution,
1253 building and installing A will also build and install B.  Generating a
1254 distribution for A will also include B.
1256 It is possible to gather several package like this.  GCC is a heavy
1257 user of this feature.  This gives installers a single package to
1258 configure, build and install, while it allows developers to work on
1259 subpackages independently.
1261 When configuring nested packages, the @command{configure} options
1262 given to the top-level @command{configure} are passed recursively to
1263 nested @command{configure}s.  A package that does not understand an
1264 option will ignore it, assuming it is meaningful to some other
1265 package.
1267 @opindex --help=recursive
1269 The command @code{configure --help=recursive} can be used to display
1270 the options supported by all the included packages.
1272 @xref{Subpackages}, for an example setup.
1274 @node Why Autotools
1275 @section How Autotools Help
1276 @cindex Autotools, purpose
1278 There are several reasons why you may not want to implement the GNU
1279 Build System yourself (read: write a @file{configure} script and
1280 @file{Makefile}s yourself).
1282 @itemize @bullet
1283 @item
1284 As we have seen, the GNU Build System has a lot of
1285 features (@pxref{Use Cases}).
1286 Some users may expect features you have not implemented because
1287 you did not need them.
1288 @item
1289 Implementing these features portably is difficult and exhausting.
1290 Think of writing portable shell scripts, and portable
1291 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1292 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1293 convince yourself.
1294 @item
1295 You will have to upgrade your setup to follow changes to the GNU
1296 Coding Standards.
1297 @end itemize
1299 The GNU Autotools take all this burden off your back and provide:
1301 @itemize @bullet
1302 @item
1303 Tools to create a portable, complete, and self-contained GNU Build
1304 System, from simple instructions.
1305 @emph{Self-contained} meaning the resulting build system does not
1306 require the GNU Autotools.
1307 @item
1308 A central place where fixes and improvements are made:
1309 a bug-fix for a portability issue will benefit every package.
1310 @end itemize
1312 Yet there also exist reasons why you may want NOT to use the
1313 Autotools@enddots{} For instance you may be already using (or used to)
1314 another incompatible build system.  Autotools will only be useful if
1315 you do accept the concepts of the GNU Build System.  People who have their
1316 own idea of how a build system should work will feel frustrated by the
1317 Autotools.
1319 @node Hello World
1320 @section A Small Hello World
1321 @cindex Example Hello World
1322 @cindex Hello World example
1323 @cindex @file{amhello-1.0.tar.gz}, creation
1325 In this section we recreate the @file{amhello-1.0} package from
1326 scratch.  The first subsection shows how to call the Autotools to
1327 instantiate the GNU Build System, while the second explains the
1328 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1329 by the Autotools.
1331 @menu
1332 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1333 * amhello Explained::           @file{configure.ac} and @file{Makefile.am} explained
1334 @end menu
1336 @node Creating amhello
1337 @subsection Creating @file{amhello-1.0.tar.gz}
1339 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1340 The package is simple enough so that we will only need to write 5
1341 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1342 that is distributed with Automake if you do not want to write them.)
1344 Create the following files in an empty directory.
1346 @itemize @bullet
1348 @item
1349 @file{src/main.c} is the source file for the @file{hello} program.  We
1350 store it in the @file{src/} subdirectory, because later, when the package
1351 evolves, it will ease the addition of a @file{man/} directory for man
1352 pages, a @file{data/} directory for data files, etc.
1353 @example
1354 ~/amhello % @kbd{cat src/main.c}
1355 #include <config.h>
1356 #include <stdio.h>
1359 main (void)
1361   puts ("Hello World!");
1362   puts ("This is " PACKAGE_STRING ".");
1363   return 0;
1365 @end example
1367 @item
1368 @file{README} contains some very limited documentation for our little
1369 package.
1370 @example
1371 ~/amhello % @kbd{cat README}
1372 This is a demonstration package for GNU Automake.
1373 Type `info Automake' to read the Automake manual.
1374 @end example
1376 @item
1377 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1378 instructions for these two directories.
1380 @example
1381 ~/amhello % @kbd{cat src/Makefile.am}
1382 bin_PROGRAMS = hello
1383 hello_SOURCES = main.c
1384 ~/amhello % @kbd{cat Makefile.am}
1385 SUBDIRS = src
1386 dist_doc_DATA = README
1387 @end example
1389 @item
1390 Finally, @file{configure.ac} contains Autoconf instructions to
1391 create the @command{configure} script.
1393 @example
1394 ~/amhello % @kbd{cat configure.ac}
1395 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1396 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1397 AC_PROG_CC
1398 AC_CONFIG_HEADERS([config.h])
1399 AC_CONFIG_FILES([
1400  Makefile
1401  src/Makefile
1403 AC_OUTPUT
1404 @end example
1405 @end itemize
1407 @cindex @command{autoreconf}, example
1409 Once you have these five files, it is time to run the Autotools to
1410 instantiate the build system.  Do this using the @command{autoreconf}
1411 command as follows:
1413 @example
1414 ~/amhello % @kbd{autoreconf --install}
1415 configure.ac: installing `./install-sh'
1416 configure.ac: installing `./missing'
1417 src/Makefile.am: installing `./depcomp'
1418 @end example
1420 At this point the build system is complete.
1422 In addition to the three scripts mentioned in its output, you can see
1423 that @command{autoreconf} created four other files: @file{configure},
1424 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1425 The latter three files are templates that will be adapted to the
1426 system by @command{configure} under the names @file{config.h},
1427 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1429 @example
1430 ~/amhello % @kbd{./configure}
1431 checking for a BSD-compatible install... /usr/bin/install -c
1432 checking whether build environment is sane... yes
1433 checking for gawk... no
1434 checking for mawk... mawk
1435 checking whether make sets $(MAKE)... yes
1436 checking for gcc... gcc
1437 checking for C compiler default output file name... a.out
1438 checking whether the C compiler works... yes
1439 checking whether we are cross compiling... no
1440 checking for suffix of executables...
1441 checking for suffix of object files... o
1442 checking whether we are using the GNU C compiler... yes
1443 checking whether gcc accepts -g... yes
1444 checking for gcc option to accept ISO C89... none needed
1445 checking for style of include used by make... GNU
1446 checking dependency style of gcc... gcc3
1447 configure: creating ./config.status
1448 config.status: creating Makefile
1449 config.status: creating src/Makefile
1450 config.status: creating config.h
1451 config.status: executing depfiles commands
1452 @end example
1454 @trindex distcheck
1455 @cindex @code{distcheck} example
1457 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1458 being created at the end after @command{configure} has probed the
1459 system.  It is now possible to run all the targets we wish
1460 (@pxref{Standard Targets}).  For instance:
1462 @example
1463 ~/amhello % @kbd{make}
1464 @dots{}
1465 ~/amhello % @kbd{src/hello}
1466 Hello World!
1467 This is amhello 1.0.
1468 ~/amhello % @kbd{make distcheck}
1469 @dots{}
1470 =============================================
1471 amhello-1.0 archives ready for distribution:
1472 amhello-1.0.tar.gz
1473 =============================================
1474 @end example
1476 Note that running @command{autoreconf} is only needed initially when
1477 the GNU Build System does not exist.  When you later change some
1478 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1479 relevant part of the build system will be regenerated automatically
1480 when you execute @command{make}.
1482 @command{autoreconf} is a script that calls @command{autoconf},
1483 @command{automake}, and a bunch of other commands in the right order.
1484 If you are beginning with these tools, it is not important to figure
1485 out in which order all these tools should be invoked and why.  However,
1486 because Autoconf and Automake have separate manuals, the important
1487 point to understand is that @command{autoconf} is in charge of
1488 creating @file{configure} from @file{configure.ac}, while
1489 @command{automake} is in charge of creating @file{Makefile.in}s from
1490 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1491 direct you to the right manual when seeking answers.
1494 @node amhello Explained
1495 @subsection @file{amhello-1.0} Explained
1497 Let us begin with the contents of @file{configure.ac}.
1499 @example
1500 AC_INIT([amhello], [1.0], [bug-automake@@gnu.org])
1501 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1502 AC_PROG_CC
1503 AC_CONFIG_HEADERS([config.h])
1504 AC_CONFIG_FILES([
1505  Makefile
1506  src/Makefile
1508 AC_OUTPUT
1509 @end example
1511 This file is read by both @command{autoconf} (to create
1512 @file{configure}) and @command{automake} (to create the various
1513 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1514 expanded as shell code to finally form the @file{configure} script.
1515 We will not elaborate on the syntax of this file, because the Autoconf
1516 manual has a whole section about it (@pxref{Writing configure.ac, ,
1517 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1519 The macros prefixed with @code{AC_} are Autoconf macros, documented
1520 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1521 Index, autoconf, The Autoconf Manual}).  The macros that start with
1522 @code{AM_} are Automake macros, documented later in this manual
1523 (@pxref{Macro Index}).
1525 The first two lines of @file{configure.ac} initialize Autoconf and
1526 Automake.  @code{AC_INIT} takes in parameters the name of the package,
1527 its version number, and a contact address for bug-reports about the
1528 package (this address is output at the end of @code{./configure
1529 --help}, for instance).  When adapting this setup to your own package,
1530 by all means please do not blindly copy Automake's address: use the
1531 mailing list of your package, or your own mail address.
1533 @opindex -Wall
1534 @opindex -Werror
1535 @opindex foreign
1537 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1538 @command{automake} (@pxref{Options}).  @option{-Wall} and
1539 @option{-Werror} ask @command{automake} to turn on all warnings and
1540 report them as errors.  We are speaking of @strong{Automake} warnings
1541 here, such as dubious instructions in @file{Makefile.am}.  This has
1542 absolutely nothing to do with how the compiler will be called, even
1543 though it may support options with similar names.  Using @option{-Wall
1544 -Werror} is a safe setting when starting to work on a package: you do
1545 not want to miss any issues.  Later you may decide to relax things a
1546 bit.  The @option{foreign} option tells Automake that this package
1547 will not follow the GNU Standards.  GNU packages should always
1548 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1549 etc.  We do not want @command{automake} to complain about these
1550 missing files in our small example.
1552 The @code{AC_PROG_CC} line causes the @command{configure} script to
1553 search for a C compiler and define the variable @code{CC} with its
1554 name.  The @file{src/Makefile.in} file generated by Automake uses the
1555 variable @code{CC} to build @file{hello}, so when @command{configure}
1556 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1557 @code{CC} with the value it has found.  If Automake is asked to create
1558 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1559 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1561 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1562 @command{configure} script to create a @file{config.h} file gathering
1563 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1564 case, the @code{AC_INIT} macro already defined a few of them.  Here
1565 is an excerpt of @file{config.h} after @command{configure} has run:
1567 @smallexample
1568 @dots{}
1569 /* Define to the address where bug reports for this package should be sent. */
1570 #define PACKAGE_BUGREPORT "bug-automake@@gnu.org"
1572 /* Define to the full name and version of this package. */
1573 #define PACKAGE_STRING "amhello 1.0"
1574 @dots{}
1575 @end smallexample
1577 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1578 it can use @code{PACKAGE_STRING}.  In a real-world project,
1579 @file{config.h} can grow really big, with one @samp{#define} per
1580 feature probed on the system.
1582 The @code{AC_CONFIG_FILES} macro declares the list of files that
1583 @command{configure} should create from their @file{*.in} templates.
1584 Automake also scans this list to find the @file{Makefile.am} files it must
1585 process.  (This is important to remember: when adding a new directory
1586 to your project, you should add its @file{Makefile} to this list,
1587 otherwise Automake will never process the new @file{Makefile.am} you
1588 wrote in that directory.)
1590 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1591 produces the part of the script in charge of creating the files
1592 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1594 @cindex @command{autoscan}
1596 When starting a new project, we suggest you start with such a simple
1597 @file{configure.ac}, and gradually add the other tests it requires.
1598 The command @command{autoscan} can also suggest a few of the tests
1599 your package may need (@pxref{autoscan Invocation, , Using
1600 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1601 Autoconf Manual}).
1603 @cindex @file{Makefile.am}, Hello World
1605 We now turn to @file{src/Makefile.am}.  This file contains
1606 Automake instructions to build and install @file{hello}.
1608 @example
1609 bin_PROGRAMS = hello
1610 hello_SOURCES = main.c
1611 @end example
1613 A @file{Makefile.am} has the same syntax as an ordinary
1614 @file{Makefile}.  When @command{automake} processes a
1615 @file{Makefile.am} it copies the entire file into the output
1616 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1617 @command{configure}) but will react to certain variable definitions
1618 by generating some build rules and other variables.
1619 Often @file{Makefile.am}s contain only a list of variable definitions as
1620 above, but they can also contain other variable and rule definitions that
1621 @command{automake} will pass along without interpretation.
1623 Variables that end with @code{_PROGRAMS} are special variables
1624 that list programs that the resulting @file{Makefile} should build.
1625 In Automake speak, this @code{_PROGRAMS} suffix is called a
1626 @dfn{primary}; Automake recognizes other primaries such as
1627 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1628 to different types of files.
1630 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1631 @command{automake} that the resulting programs should be installed in
1632 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1633 to denote destination directories and allow users to customize these
1634 locations (@pxref{Standard Directory Variables}).  Any such directory
1635 variable can be put in front of a primary (omitting the @code{dir}
1636 suffix) to tell @command{automake} where to install the listed files.
1638 Programs need to be built from source files, so for each program
1639 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1640 @command{automake} will look for another variable named
1641 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1642 than one source file: they will all be compiled and linked together.
1644 Automake also knows that source files need to be distributed when
1645 creating a tarball (unlike built programs).  So a side-effect of this
1646 @code{hello_SOURCES} declaration is that @file{main.c} will be
1647 part of the tarball created by @code{make dist}.
1649 Finally here are some explanations regarding the top-level
1650 @file{Makefile.am}.
1652 @example
1653 SUBDIRS = src
1654 dist_doc_DATA = README
1655 @end example
1657 @code{SUBDIRS} is a special variable listing all directories that
1658 @command{make} should recurse into before processing the current
1659 directory.  So this line is responsible for @command{make} building
1660 @file{src/hello} even though we run it from the top-level.  This line
1661 also causes @code{make install} to install @file{src/hello} before
1662 installing @file{README} (not that this order matters).
1664 The line @code{dist_doc_DATA = README} causes @file{README} to be
1665 distributed and installed in @var{docdir}.  Files listed with the
1666 @code{_DATA} primary are not automatically part of the tarball built
1667 with @code{make dist}, so we add the @code{dist_} prefix so they get
1668 distributed.  However, for @file{README} it would not have been
1669 necessary: @command{automake} automatically distributes any
1670 @file{README} file it encounters (the list of other files
1671 automatically distributed is presented by @code{automake --help}).
1672 The only important effect of this second line is therefore to install
1673 @file{README} during @code{make install}.
1676 @node Generalities
1677 @chapter General ideas
1679 The following sections cover a few basic ideas that will help you
1680 understand how Automake works.
1682 @menu
1683 * General Operation::           General operation of Automake
1684 * Strictness::                  Standards conformance checking
1685 * Uniform::                     The Uniform Naming Scheme
1686 * Canonicalization::            How derived variables are named
1687 * User Variables::              Variables reserved for the user
1688 * Auxiliary Programs::          Programs automake might require
1689 @end menu
1692 @node General Operation
1693 @section General Operation
1695 Automake works by reading a @file{Makefile.am} and generating a
1696 @file{Makefile.in}.  Certain variables and rules defined in the
1697 @file{Makefile.am} instruct Automake to generate more specialized code;
1698 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1699 for compiling and linking programs to be generated.
1701 @cindex Non-standard targets
1702 @cindex @code{cvs-dist}, non-standard example
1703 @trindex cvs-dist
1705 The variable definitions and rules in the @file{Makefile.am} are
1706 copied verbatim into the generated file.  This allows you to add
1707 arbitrary code into the generated @file{Makefile.in}.  For instance,
1708 the Automake distribution includes a non-standard rule for the
1709 @code{cvs-dist} target, which the Automake maintainer uses to make
1710 distributions from his source control system.
1712 @cindex GNU make extensions
1714 Note that most GNU make extensions are not recognized by Automake.  Using
1715 such extensions in a @file{Makefile.am} will lead to errors or confusing
1716 behavior.
1718 @cindex Append operator
1719 @cmindex +=
1720 A special exception is that the GNU make append operator, @samp{+=}, is
1721 supported.  This operator appends its right hand argument to the variable
1722 specified on the left.  Automake will translate the operator into
1723 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1725 Automake tries to keep comments grouped with any adjoining rules or
1726 variable definitions.
1728 @cindex Make targets, overriding
1729 @cindex Make rules, overriding
1730 @cindex Overriding make rules
1731 @cindex Overriding make targets
1733 A rule defined in @file{Makefile.am} generally overrides any such
1734 rule of a similar name that would be automatically generated by
1735 @command{automake}.  Although this is a supported feature, it is generally
1736 best to avoid making use of it, as sometimes the generated rules are
1737 very particular.
1739 @cindex Variables, overriding
1740 @cindex Overriding make variables
1742 Similarly, a variable defined in @file{Makefile.am} or
1743 @code{AC_SUBST}ed from @file{configure.ac} will override any
1744 definition of the variable that @command{automake} would ordinarily
1745 create.  This feature is more often useful than the ability to
1746 override a rule.  Be warned that many of the variables generated by
1747 @command{automake} are considered to be for internal use only, and their
1748 names might change in future releases.
1750 @cindex Recursive operation of Automake
1751 @cindex Automake, recursive operation
1752 @cindex Example of recursive operation
1754 When examining a variable definition, Automake will recursively examine
1755 variables referenced in the definition.  For example, if Automake is
1756 looking at the content of @code{foo_SOURCES} in this snippet
1758 @example
1759 xs = a.c b.c
1760 foo_SOURCES = c.c $(xs)
1761 @end example
1763 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1764 contents of @code{foo_SOURCES}.
1766 @cindex @code{##} (special Automake comment)
1767 @cindex Special Automake comment
1768 @cindex Comment, special to Automake
1770 Automake also allows a form of comment that is @emph{not} copied into
1771 the output; all lines beginning with @samp{##} (leading spaces allowed)
1772 are completely ignored by Automake.
1774 It is customary to make the first line of @file{Makefile.am} read:
1776 @cindex Makefile.am, first line
1777 @cindex First line of Makefile.am
1779 @example
1780 ## Process this file with automake to produce Makefile.in
1781 @end example
1783 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1784 @c I don't know quite what to say.
1786 @c FIXME document customary ordering of Makefile.am here!
1789 @node Strictness
1790 @section Strictness
1792 @cindex Non-GNU packages
1794 While Automake is intended to be used by maintainers of GNU packages, it
1795 does make some effort to accommodate those who wish to use it, but do
1796 not want to use all the GNU conventions.
1798 @cindex Strictness, defined
1799 @cindex Strictness, @option{foreign}
1800 @cindex @option{foreign} strictness
1801 @cindex Strictness, @option{gnu}
1802 @cindex @option{gnu} strictness
1803 @cindex Strictness, @option{gnits}
1804 @cindex @option{gnits} strictness
1806 To this end, Automake supports three levels of @dfn{strictness}---the
1807 strictness indicating how stringently Automake should check standards
1808 conformance.
1810 The valid strictness levels are:
1812 @table @option
1813 @item foreign
1814 Automake will check for only those things that are absolutely
1815 required for proper operations.  For instance, whereas GNU standards
1816 dictate the existence of a @file{NEWS} file, it will not be required in
1817 this mode.  The name comes from the fact that Automake is intended to be
1818 used for GNU programs; these relaxed rules are not the standard mode of
1819 operation.
1821 @item gnu
1822 Automake will check---as much as possible---for compliance to the GNU
1823 standards for packages.  This is the default.
1825 @item gnits
1826 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1827 standards}.  These are based on the GNU standards, but are even more
1828 detailed.  Unless you are a Gnits standards contributor, it is
1829 recommended that you avoid this option until such time as the Gnits
1830 standard is actually published (which may never happen).
1831 @end table
1833 @xref{Gnits}, for more information on the precise implications of the
1834 strictness level.
1836 Automake also has a special ``cygnus'' mode that is similar to
1837 strictness but handled differently.  This mode is useful for packages
1838 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
1839 @xref{Cygnus}, for more information on this mode.
1842 @node Uniform
1843 @section The Uniform Naming Scheme
1845 @cindex Uniform naming scheme
1847 Automake variables generally follow a @dfn{uniform naming scheme} that
1848 makes it easy to decide how programs (and other derived objects) are
1849 built, and how they are installed.  This scheme also supports
1850 @command{configure} time determination of what should be built.
1852 @cindex @code{_PROGRAMS} primary variable
1853 @cindex @code{PROGRAMS} primary variable
1854 @cindex Primary variable, @code{PROGRAMS}
1855 @cindex Primary variable, defined
1856 @vindex _PROGRAMS
1858 At @command{make} time, certain variables are used to determine which
1859 objects are to be built.  The variable names are made of several pieces
1860 that are concatenated together.
1862 The piece that tells automake what is being built is commonly called
1863 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1864 list of programs that are to be compiled and linked.
1865 @vindex PROGRAMS
1867 @cindex @code{pkgdatadir}, defined
1868 @cindex @code{pkgincludedir}, defined
1869 @cindex @code{pkglibdir}, defined
1870 @cindex @code{pkglibexecdir}, defined
1872 @vindex pkgdatadir
1873 @vindex pkgincludedir
1874 @vindex pkglibdir
1875 @vindex pkglibexecdir
1877 @cindex @code{PACKAGE}, directory
1878 A different set of names is used to decide where the built objects
1879 should be installed.  These names are prefixes to the primary, and they
1880 indicate which standard directory should be used as the installation
1881 directory.  The standard directory names are given in the GNU standards
1882 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1883 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
1884 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
1885 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
1886 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
1888 @cindex @code{EXTRA_}, prepending
1889 For each primary, there is one additional variable named by prepending
1890 @samp{EXTRA_} to the primary name.  This variable is used to list
1891 objects that may or may not be built, depending on what
1892 @command{configure} decides.  This variable is required because Automake
1893 must statically know the entire list of objects that may be built in
1894 order to generate a @file{Makefile.in} that will work in all cases.
1896 @cindex @code{EXTRA_PROGRAMS}, defined
1897 @cindex Example, @code{EXTRA_PROGRAMS}
1898 @cindex @command{cpio} example
1900 For instance, @command{cpio} decides at configure time which programs
1901 should be built.  Some of the programs are installed in @code{bindir},
1902 and some are installed in @code{sbindir}:
1904 @example
1905 EXTRA_PROGRAMS = mt rmt
1906 bin_PROGRAMS = cpio pax
1907 sbin_PROGRAMS = $(MORE_PROGRAMS)
1908 @end example
1910 Defining a primary without a prefix as a variable, e.g.,
1911 @samp{PROGRAMS}, is an error.
1913 Note that the common @samp{dir} suffix is left off when constructing the
1914 variable names; thus one writes @samp{bin_PROGRAMS} and not
1915 @samp{bindir_PROGRAMS}.
1917 Not every sort of object can be installed in every directory.  Automake
1918 will flag those attempts it finds in error.
1919 Automake will also diagnose obvious misspellings in directory names.
1921 @cindex Extending list of installation directories
1922 @cindex Installation directories, extending list
1924 Sometimes the standard directories---even as augmented by
1925 Automake---are not enough.  In particular it is sometimes useful, for
1926 clarity, to install objects in a subdirectory of some predefined
1927 directory.  To this end, Automake allows you to extend the list of
1928 possible installation directories.  A given prefix (e.g., @samp{zar})
1929 is valid if a variable of the same name with @samp{dir} appended is
1930 defined (e.g., @samp{zardir}).
1932 For instance, the following snippet will install @file{file.xml} into
1933 @samp{$(datadir)/xml}.
1935 @example
1936 xmldir = $(datadir)/xml
1937 xml_DATA = file.xml
1938 @end example
1940 @cindex @samp{noinst_} primary prefix, definition
1941 @vindex noinst_
1943 The special prefix @samp{noinst_} indicates that the objects in question
1944 should be built but not installed at all.  This is usually used for
1945 objects required to build the rest of your package, for instance static
1946 libraries (@pxref{A Library}), or helper scripts.
1948 @cindex @samp{check_} primary prefix, definition
1949 @vindex check_
1951 The special prefix @samp{check_} indicates that the objects in question
1952 should not be built until the @samp{make check} command is run.  Those
1953 objects are not installed either.
1955 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
1956 @samp{LISP}, @samp{PYTHON}, @samp{JAVA}, @samp{SCRIPTS}, @samp{DATA},
1957 @samp{HEADERS}, @samp{MANS}, and @samp{TEXINFOS}.
1958 @vindex PROGRAMS
1959 @vindex LIBRARIES
1960 @vindex LISP
1961 @vindex PYTHON
1962 @vindex JAVA
1963 @vindex SCRIPTS
1964 @vindex DATA
1965 @vindex HEADERS
1966 @vindex MANS
1967 @vindex TEXINFOS
1969 Some primaries also allow additional prefixes that control other
1970 aspects of @command{automake}'s behavior.  The currently defined prefixes
1971 are @samp{dist_}, @samp{nodist_}, and @samp{nobase_}.  These prefixes
1972 are explained later (@pxref{Program and Library Variables}).
1975 @node Canonicalization
1976 @section How derived variables are named
1978 @cindex canonicalizing Automake variables
1980 Sometimes a Makefile variable name is derived from some text the
1981 maintainer supplies.  For instance, a program name listed in
1982 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
1983 variable.  In cases like this, Automake canonicalizes the text, so that
1984 program names and the like do not have to follow Makefile variable naming
1985 rules.  All characters in the name except for letters, numbers, the
1986 strudel (@@), and the underscore are turned into underscores when making
1987 variable references.
1989 For example, if your program is named @file{sniff-glue}, the derived
1990 variable name would be @samp{sniff_glue_SOURCES}, not
1991 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
1992 @file{libmumble++.a} should be listed in the
1993 @samp{libmumble___a_SOURCES} variable.
1995 The strudel is an addition, to make the use of Autoconf substitutions in
1996 variable names less obfuscating.
1999 @node User Variables
2000 @section Variables reserved for the user
2002 @cindex variables, reserved for the user
2003 @cindex user variables
2005 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2006 for the use of the ``user''---the person building the package.  For
2007 instance, @code{CFLAGS} is one such variable.
2009 Sometimes package developers are tempted to set user variables such as
2010 @code{CFLAGS} because it appears to make their job easier.  However,
2011 the package itself should never set a user variable, particularly not
2012 to include switches that are required for proper compilation of the
2013 package.  Since these variables are documented as being for the
2014 package builder, that person rightfully expects to be able to override
2015 any of these variables at build time.
2017 To get around this problem, Automake introduces an automake-specific
2018 shadow variable for each user flag variable.  (Shadow variables are
2019 not introduced for variables like @code{CC}, where they would make no
2020 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2021 user variable's name.  For instance, the shadow variable for
2022 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2023 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2024 files---may adjust these shadow variables however necessary.
2026 @xref{Flag Variables Ordering}, for more discussion about these
2027 variables and how they interact with per-target variables.
2029 @node Auxiliary Programs
2030 @section Programs automake might require
2032 @cindex Programs, auxiliary
2033 @cindex Auxiliary programs
2035 Automake sometimes requires helper programs so that the generated
2036 @file{Makefile} can do its work properly.  There are a fairly large
2037 number of them, and we list them here.
2039 Although all of these files are distributed and installed with
2040 Automake, a couple of them are maintained separately.  The Automake
2041 copies are updated before each release, but we mention the original
2042 source in case you need more recent versions.
2044 @table @code
2045 @item ansi2knr.c
2046 @itemx ansi2knr.1
2047 These two files are used by the obsolete de-ANSI-fication support
2048 (@pxref{ANSI}).
2050 @item compile
2051 This is a wrapper for compilers that do not accept options @option{-c}
2052 and @option{-o} at the same time.  It is only used when absolutely
2053 required.  Such compilers are rare.
2055 @item config.guess
2056 @itemx config.sub
2057 These two programs compute the canonical triplets for the given build,
2058 host, or target architecture.  These programs are updated regularly to
2059 support new architectures and fix probes broken by changes in new
2060 kernel versions.  Each new release of Automake comes with up-to-date
2061 copies of these programs.  If your copy of Automake is getting old,
2062 you are encouraged to fetch the latest versions of these files from
2063 @url{http://savannah.gnu.org/cvs/?group=config} before making a
2064 release.
2066 @item config-ml.in
2067 This file is not a program, it is a @file{configure} fragment used for
2068 multilib support (@pxref{Multilibs}).  This file is maintained in the
2069 GCC tree at @url{http://gcc.gnu.org/svn.html}.
2071 @item depcomp
2072 This program understands how to run a compiler so that it will
2073 generate not only the desired output but also dependency information
2074 that is then used by the automatic dependency tracking feature
2075 (@pxref{Dependencies}).
2077 @item elisp-comp
2078 This program is used to byte-compile Emacs Lisp code.
2080 @item install-sh
2081 This is a replacement for the @command{install} program that works on
2082 platforms where @command{install} is unavailable or unusable.
2084 @item mdate-sh
2085 This script is used to generate a @file{version.texi} file.  It examines
2086 a file and prints some date information about it.
2088 @item missing
2089 This wraps a number of programs that are typically only required by
2090 maintainers.  If the program in question doesn't exist,
2091 @command{missing} prints an informative warning and attempts to fix
2092 things so that the build can continue.
2094 @item mkinstalldirs
2095 This script used to be a wrapper around @samp{mkdir -p}, which is not
2096 portable.  Now we prefer to use @samp{install-sh -d} when configure
2097 finds that @samp{mkdir -p} does not work, this makes one less script to
2098 distribute.
2100 For backward compatibility @file{mkinstalldirs} is still used and
2101 distributed when @command{automake} finds it in a package.  But it is no
2102 longer installed automatically, and it should be safe to remove it.
2104 @item py-compile
2105 This is used to byte-compile Python scripts.
2107 @item symlink-tree
2108 This program duplicates a tree of directories, using symbolic links
2109 instead of copying files.  Such operation is performed when building
2110 multilibs (@pxref{Multilibs}).  This file is maintained in the GCC
2111 tree at @url{http://gcc.gnu.org/svn.html}.
2113 @item texinfo.tex
2114 Not a program, this file is required for @samp{make dvi}, @samp{make
2115 ps} and @samp{make pdf} to work when Texinfo sources are in the
2116 package.  The latest version can be downloaded from
2117 @url{http://www.gnu.org/software/texinfo/}.
2119 @item ylwrap
2120 This program wraps @command{lex} and @command{yacc} to rename their
2121 output files.  It also ensures that, for instance, multiple
2122 @command{yacc} instances can be invoked in a single directory in
2123 parallel.
2125 @end table
2128 @node Examples
2129 @chapter Some example packages
2131 This section contains two small examples.
2133 The first example (@pxref{Complete}) assumes you have an existing
2134 project already using Autoconf, with handcrafted @file{Makefile}s, and
2135 that you want to convert it to using Automake.  If you are discovering
2136 both tools, it is probably better that you look at the Hello World
2137 example presented earlier (@pxref{Hello World}).
2139 The second example (@pxref{true}) shows how two programs can be built
2140 from the same file, using different compilation parameters.  It
2141 contains some technical digressions that are probably best skipped on
2142 first read.
2144 @menu
2145 * Complete::                    A simple example, start to finish
2146 * true::                        Building true and false
2147 @end menu
2150 @node Complete
2151 @section A simple example, start to finish
2153 @cindex Complete example
2155 Let's suppose you just finished writing @code{zardoz}, a program to make
2156 your head float from vortex to vortex.  You've been using Autoconf to
2157 provide a portability framework, but your @file{Makefile.in}s have been
2158 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2160 @cindex @code{AM_INIT_AUTOMAKE}, example use
2162 The first step is to update your @file{configure.ac} to include the
2163 commands that @command{automake} needs.  The way to do this is to add an
2164 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2166 @example
2167 AC_INIT([zardoz], [1.0])
2168 AM_INIT_AUTOMAKE
2169 @dots{}
2170 @end example
2172 Since your program doesn't have any complicating factors (e.g., it
2173 doesn't use @code{gettext}, it doesn't want to build a shared library),
2174 you're done with this part.  That was easy!
2176 @cindex @command{aclocal} program, introduction
2177 @cindex @file{aclocal.m4}, preexisting
2178 @cindex @file{acinclude.m4}, defined
2180 Now you must regenerate @file{configure}.  But to do that, you'll need
2181 to tell @command{autoconf} how to find the new macro you've used.  The
2182 easiest way to do this is to use the @command{aclocal} program to
2183 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2184 already have an @file{aclocal.m4}, because you had to write some hairy
2185 macros for your program.  The @command{aclocal} program lets you put
2186 your own macros into @file{acinclude.m4}, so simply rename and then
2187 run:
2189 @example
2190 mv aclocal.m4 acinclude.m4
2191 aclocal
2192 autoconf
2193 @end example
2195 @cindex @command{zardoz} example
2197 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2198 Since @code{zardoz} is a user program, you want to install it where the
2199 rest of the user programs go: @code{bindir}.  Additionally,
2200 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2201 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2202 @samp{$(LIBOBJS)}.  So here's what you'd write:
2204 @example
2205 bin_PROGRAMS = zardoz
2206 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2207 zardoz_LDADD = $(LIBOBJS)
2209 info_TEXINFOS = zardoz.texi
2210 @end example
2212 Now you can run @samp{automake --add-missing} to generate your
2213 @file{Makefile.in} and grab any auxiliary files you might need, and
2214 you're done!
2217 @node true
2218 @section Building true and false
2220 @cindex Example, @command{false} and @command{true}
2221 @cindex @command{false} Example
2222 @cindex @command{true} Example
2224 Here is another, trickier example.  It shows how to generate two
2225 programs (@code{true} and @code{false}) from the same source file
2226 (@file{true.c}).  The difficult part is that each compilation of
2227 @file{true.c} requires different @code{cpp} flags.
2229 @example
2230 bin_PROGRAMS = true false
2231 false_SOURCES =
2232 false_LDADD = false.o
2234 true.o: true.c
2235         $(COMPILE) -DEXIT_CODE=0 -c true.c
2237 false.o: true.c
2238         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2239 @end example
2241 Note that there is no @code{true_SOURCES} definition.  Automake will
2242 implicitly assume that there is a source file named @file{true.c}, and
2243 define rules to compile @file{true.o} and link @file{true}.  The
2244 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2245 will override the Automake generated rule to build @file{true.o}.
2247 @code{false_SOURCES} is defined to be empty---that way no implicit value
2248 is substituted.  Because we have not listed the source of
2249 @file{false}, we have to tell Automake how to link the program.  This is
2250 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2251 variable, holding the dependencies of the @file{false} target will be
2252 automatically generated by Automake from the content of
2253 @code{false_LDADD}.
2255 The above rules won't work if your compiler doesn't accept both
2256 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2257 bogus dependency (to avoid problems with a parallel @command{make}):
2259 @example
2260 true.o: true.c false.o
2261         $(COMPILE) -DEXIT_CODE=0 -c true.c
2263 false.o: true.c
2264         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2265 @end example
2267 Also, these explicit rules do not work if the obsolete de-ANSI-fication feature
2268 is used (@pxref{ANSI}).  Supporting de-ANSI-fication requires a little
2269 more work:
2271 @example
2272 true_.o: true_.c false_.o
2273         $(COMPILE) -DEXIT_CODE=0 -c true_.c
2275 false_.o: true_.c
2276         $(COMPILE) -DEXIT_CODE=1 -c true_.c && mv true_.o false_.o
2277 @end example
2279 As it turns out, there is also a much easier way to do this same task.
2280 Some of the above techniques are useful enough that we've kept the
2281 example in the manual.  However if you were to build @code{true} and
2282 @code{false} in real life, you would probably use per-program
2283 compilation flags, like so:
2285 @example
2286 bin_PROGRAMS = false true
2288 false_SOURCES = true.c
2289 false_CPPFLAGS = -DEXIT_CODE=1
2291 true_SOURCES = true.c
2292 true_CPPFLAGS = -DEXIT_CODE=0
2293 @end example
2295 In this case Automake will cause @file{true.c} to be compiled twice,
2296 with different flags.  De-ANSI-fication will work automatically.  In
2297 this instance, the names of the object files would be chosen by
2298 automake; they would be @file{false-true.o} and @file{true-true.o}.
2299 (The name of the object files rarely matters.)
2302 @node Invoking Automake
2303 @chapter Creating a @file{Makefile.in}
2305 @cindex Multiple @file{configure.ac} files
2306 @cindex Invoking @command{automake}
2307 @cindex @command{automake}, invoking
2309 To create all the @file{Makefile.in}s for a package, run the
2310 @command{automake} program in the top level directory, with no
2311 arguments.  @command{automake} will automatically find each
2312 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2313 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2314 Note that @command{automake} has a rather simplistic view of what
2315 constitutes a package; it assumes that a package has only one
2316 @file{configure.ac}, at the top.  If your package has multiple
2317 @file{configure.ac}s, then you must run @command{automake} in each
2318 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2319 on Autoconf's @command{autoreconf}, which is able to recurse your
2320 package tree and run @command{automake} where appropriate.)
2322 You can optionally give @command{automake} an argument; @file{.am} is
2323 appended to the argument and the result is used as the name of the
2324 input file.  This feature is generally only used to automatically
2325 rebuild an out-of-date @file{Makefile.in}.  Note that
2326 @command{automake} must always be run from the topmost directory of a
2327 project, even if being used to regenerate the @file{Makefile.in} in
2328 some subdirectory.  This is necessary because @command{automake} must
2329 scan @file{configure.ac}, and because @command{automake} uses the
2330 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2331 behavior in some cases.
2333 @vindex AUTOCONF
2334 Automake will run @command{autoconf} to scan @file{configure.ac} and
2335 its dependencies (i.e., @file{aclocal.m4} and any included file),
2336 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2337 an @env{AUTOCONF} variable in your environment it will be used
2338 instead of @command{autoconf}, this allows you to select a particular
2339 version of Autoconf.  By the way, don't misunderstand this paragraph:
2340 @command{automake} runs @command{autoconf} to @strong{scan} your
2341 @file{configure.ac}, this won't build @file{configure} and you still
2342 have to run @command{autoconf} yourself for this purpose.
2344 @cindex @command{automake} options
2345 @cindex Options, @command{automake}
2346 @cindex Strictness, command line
2348 @command{automake} accepts the following options:
2350 @cindex Extra files distributed with Automake
2351 @cindex Files distributed with Automake
2352 @cindex @file{config.guess}
2354 @table @code
2355 @item -a
2356 @itemx --add-missing
2357 @opindex -a
2358 @opindex --add-missing
2359 Automake requires certain common files to exist in certain situations;
2360 for instance, @file{config.guess} is required if @file{configure.ac} runs
2361 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2362 files (@pxref{Auxiliary Programs}); this option will cause the missing
2363 ones to be automatically added to the package, whenever possible.  In
2364 general if Automake tells you a file is missing, try using this option.
2365 By default Automake tries to make a symbolic link pointing to its own
2366 copy of the missing file; this can be changed with @option{--copy}.
2368 Many of the potentially-missing files are common scripts whose
2369 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2370 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2371 file is considered missing, and where the missing file is added
2372 (@pxref{Optional}).
2374 @item --libdir=@var{dir}
2375 @opindex --libdir
2376 Look for Automake data files in directory @var{dir} instead of in the
2377 installation directory.  This is typically used for debugging.
2379 @item -c
2380 @opindex -c
2381 @itemx --copy
2382 @opindex --copy
2383 When used with @option{--add-missing}, causes installed files to be
2384 copied.  The default is to make a symbolic link.
2386 @item --cygnus
2387 @opindex --cygnus
2388 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2389 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2391 @item -f
2392 @opindex -f
2393 @itemx --force-missing
2394 @opindex --force-missing
2395 When used with @option{--add-missing}, causes standard files to be reinstalled
2396 even if they already exist in the source tree.  This involves removing
2397 the file from the source tree before creating the new symlink (or, with
2398 @option{--copy}, copying the new file).
2400 @item --foreign
2401 @opindex --foreign
2402 Set the global strictness to @option{foreign}.  For more information, see
2403 @ref{Strictness}.
2405 @item --gnits
2406 @opindex --gnits
2407 Set the global strictness to @option{gnits}.  For more information, see
2408 @ref{Gnits}.
2410 @item --gnu
2411 @opindex --gnu
2412 Set the global strictness to @option{gnu}.  For more information, see
2413 @ref{Gnits}.  This is the default strictness.
2415 @item --help
2416 @opindex --help
2417 Print a summary of the command line options and exit.
2419 @item -i
2420 @itemx --ignore-deps
2421 @opindex -i
2422 This disables the dependency tracking feature in generated
2423 @file{Makefile}s; see @ref{Dependencies}.
2425 @item --include-deps
2426 @opindex --include-deps
2427 This enables the dependency tracking feature.  This feature is enabled
2428 by default.  This option is provided for historical reasons only and
2429 probably should not be used.
2431 @item --no-force
2432 @opindex --no-force
2433 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2434 @file{configure.ac}.  This option causes it to only update those
2435 @file{Makefile.in}s that are out of date with respect to one of their
2436 dependents.
2438 @item -o @var{dir}
2439 @itemx --output-dir=@var{dir}
2440 @opindex -o
2441 @opindex --output-dir
2442 Put the generated @file{Makefile.in} in the directory @var{dir}.
2443 Ordinarily each @file{Makefile.in} is created in the directory of the
2444 corresponding @file{Makefile.am}.  This option is deprecated and will be
2445 removed in a future release.
2447 @item -v
2448 @itemx --verbose
2449 @opindex -v
2450 @opindex --verbose
2451 Cause Automake to print information about which files are being read or
2452 created.
2454 @item --version
2455 @opindex --version
2456 Print the version number of Automake and exit.
2458 @item -W CATEGORY
2459 @item --warnings=@var{category}
2460 @opindex -W
2461 @opindex --warnings
2462 Output warnings falling in @var{category}.  @var{category} can be
2463 one of:
2464 @table @code
2465 @item gnu
2466 warnings related to the GNU Coding Standards
2467 (@pxref{Top, , , standards, The GNU Coding Standards}).
2468 @item obsolete
2469 obsolete features or constructions
2470 @item override
2471 user redefinitions of Automake rules or variables
2472 @item portability
2473 portability issues (e.g., use of @command{make} features that are
2474 known to be not portable)
2475 @item syntax
2476 weird syntax, unused variables, typos
2477 @item unsupported
2478 unsupported or incomplete features
2479 @item all
2480 all the warnings
2481 @item none
2482 turn off all the warnings
2483 @item error
2484 treat warnings as errors
2485 @end table
2487 A category can be turned off by prefixing its name with @samp{no-}.  For
2488 instance, @option{-Wno-syntax} will hide the warnings about unused
2489 variables.
2491 The categories output by default are @samp{syntax} and
2492 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2493 are enabled in @option{--gnu} and @option{--gnits} strictness.
2495 @vindex WARNINGS
2496 The environment variable @env{WARNINGS} can contain a comma separated
2497 list of categories to enable.  It will be taken into account before the
2498 command-line switches, this way @option{-Wnone} will also ignore any
2499 warning category enabled by @env{WARNINGS}.  This variable is also used
2500 by other tools like @command{autoconf}; unknown categories are ignored
2501 for this reason.
2503 @end table
2506 @node configure
2507 @chapter Scanning @file{configure.ac}
2509 @cindex @file{configure.ac}, scanning
2510 @cindex Scanning @file{configure.ac}
2512 Automake scans the package's @file{configure.ac} to determine certain
2513 information about the package.  Some @command{autoconf} macros are required
2514 and some variables must be defined in @file{configure.ac}.  Automake
2515 will also use information from @file{configure.ac} to further tailor its
2516 output.
2518 Automake also supplies some Autoconf macros to make the maintenance
2519 easier.  These macros can automatically be put into your
2520 @file{aclocal.m4} using the @command{aclocal} program.
2522 @menu
2523 * Requirements::                Configuration requirements
2524 * Optional::                    Other things Automake recognizes
2525 * Invoking aclocal::            Auto-generating aclocal.m4
2526 * Macros::                      Autoconf macros supplied with Automake
2527 @end menu
2530 @node Requirements
2531 @section Configuration requirements
2533 @cindex Automake requirements
2534 @cindex Requirements of Automake
2536 @acindex AM_INIT_AUTOMAKE
2537 The one real requirement of Automake is that your @file{configure.ac}
2538 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2539 required for proper Automake operation (@pxref{Macros}).
2541 Here are the other macros that Automake requires but which are not run
2542 by @code{AM_INIT_AUTOMAKE}:
2544 @table @code
2545 @item AC_CONFIG_FILES
2546 @itemx AC_OUTPUT
2547 @acindex AC_CONFIG_FILES
2548 @acindex AC_OUTPUT
2549 These two macros are usually invoked as follows near the end of
2550 @file{configure.ac}.
2552 @example
2553 @dots{}
2554 AC_CONFIG_FILES([
2555   Makefile
2556   doc/Makefile
2557   src/Makefile
2558   src/lib/Makefile
2559   @dots{}
2561 AC_OUTPUT
2562 @end example
2564 Automake uses these to determine which files to create (@pxref{Output, ,
2565 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2566 is considered to be an Automake generated @file{Makefile} if there
2567 exists a file with the same name and the @file{.am} extension appended.
2568 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2569 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2571 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2573 @example
2574 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2575 @end example
2577 @noindent
2578 @command{automake} will generate the first @file{.in} input file for
2579 which a @file{.am} file exists.  If no such file exists the output
2580 file is not considered to be Automake generated.
2582 Files created by @code{AC_CONFIG_FILES}, be they Automake
2583 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2584 Their inputs are automatically distributed, except for inputs that
2585 turn out the be outputs of prior @code{AC_CONFIG_FILES} commands.
2586 Finally, rebuild rules are generated in the Automake @file{Makefile}
2587 existing in the subdirectory of the output file, if there is one, or
2588 in the top-level @file{Makefile} otherwise.
2590 The above machinery (cleaning, distributing, and rebuilding) works
2591 fine if the @code{AC_CONFIG_FILES} specifications contain only
2592 literals.  If part of the specification uses shell variables,
2593 @command{automake} will not be able to fulfill this setup, and you will
2594 have to complete the missing bits by hand.  For instance, on
2596 @example
2597 file=input
2598 @dots{}
2599 AC_CONFIG_FILES([output:$file],, [file=$file])
2600 @end example
2602 @noindent
2603 @command{automake} will output rules to clean @file{output}, and
2604 rebuild it.  However the rebuild rule will not depend on @file{input},
2605 and this file will not be distributed either.  (You must add
2606 @samp{EXTRA_DIST = input} to your @file{Makefile} if @file{input} is a
2607 source file.)
2609 Similarly
2611 @example
2612 file=output
2613 file2=out:in
2614 @dots{}
2615 AC_CONFIG_FILES([$file:input],, [file=$file])
2616 AC_CONFIG_FILES([$file2],, [file2=$file2])
2617 @end example
2619 @noindent
2620 will only cause @file{input} to be distributed.  No file will be
2621 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2622 yourself), and no rebuild rule will be output.
2624 Obviously @command{automake} cannot guess what value @samp{$file} is
2625 going to hold later when @file{configure} is run, and it cannot use
2626 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2627 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2628 that is compatible with @command{make}'s syntax) and furthermore use
2629 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2630 @file{Makefile}, then @command{automake} will be able to use
2631 @samp{$@{file@}} to generate all these rules.  For instance, here is
2632 how the Automake package itself generates versioned scripts for its
2633 test suite:
2635 @example
2636 AC_SUBST([APIVERSION], @dots{})
2637 @dots{}
2638 AC_CONFIG_FILES(
2639   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2640   [chmod +x tests/aclocal-$@{APIVERSION@}],
2641   [APIVERSION=$APIVERSION])
2642 AC_CONFIG_FILES(
2643   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2644   [chmod +x tests/automake-$@{APIVERSION@}])
2645 @end example
2647 @noindent
2648 Here cleaning, distributing, and rebuilding are done automatically,
2649 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2651 Note that you should not use shell variables to declare
2652 @file{Makefile} files for which @command{automake} must create
2653 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2654 @command{automake} needs to know the file name when it runs in order
2655 to check whether @file{Makefile.am} exists.  (In the very hairy case
2656 that your setup requires such use of variables, you will have to tell
2657 Automake which @file{Makefile.in}s to generate on the command-line.)
2659 To summarize:
2660 @itemize @bullet
2661 @item
2662 Use literals for @file{Makefile}s, and for other files whenever possible.
2663 @item
2664 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2665 for files that @command{automake} should ignore.
2666 @item
2667 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2668 that @command{automake} should not ignore.
2669 @end itemize
2671 @end table
2674 @node Optional
2675 @section Other things Automake recognizes
2677 @cindex Macros Automake recognizes
2678 @cindex Recognized macros by Automake
2680 Every time Automake is run it calls Autoconf to trace
2681 @file{configure.ac}.  This way it can recognize the use of certain
2682 macros and tailor the generated @file{Makefile.in} appropriately.
2683 Currently recognized macros and their effects are:
2685 @ftable @code
2686 @item AC_CANONICAL_BUILD
2687 @itemx AC_CANONICAL_HOST
2688 @itemx AC_CANONICAL_TARGET
2689 @vindex build_triplet
2690 @vindex host_triplet
2691 @vindex target_triplet
2692 Automake will ensure that @file{config.guess} and @file{config.sub}
2693 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2694 @code{host_triplet} and @code{target_triplet} are introduced.  See
2695 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2696 The Autoconf Manual}.
2698 @item AC_CONFIG_AUX_DIR
2699 Automake will look for various helper scripts, such as
2700 @file{install-sh}, in the directory named in this macro invocation.
2701 @c This list is accurate relative to version 1.8
2702 (The full list of scripts is: @file{config.guess}, @file{config.sub},
2703 @file{depcomp}, @file{elisp-comp}, @file{compile}, @file{install-sh},
2704 @file{ltmain.sh}, @file{mdate-sh}, @file{missing}, @file{mkinstalldirs},
2705 @file{py-compile}, @file{texinfo.tex}, and @file{ylwrap}.)  Not all
2706 scripts are always searched for; some scripts will only be sought if the
2707 generated @file{Makefile.in} requires them.
2709 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2710 their standard locations.  For @file{mdate-sh},
2711 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2712 source directory corresponding to the current @file{Makefile.am}.  For
2713 the rest, the standard location is the first one of @file{.}, @file{..},
2714 or @file{../..} (relative to the top source directory) that provides any
2715 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2716 autoconf, The Autoconf Manual}.
2718 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2719 distributed, even if there is no @file{Makefile.am} in this directory.
2721 @item AC_CONFIG_LIBOBJ_DIR
2722 Automake will require the sources file declared with
2723 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2724 macro.
2726 @item AC_CONFIG_HEADERS
2727 Automake will generate rules to rebuild these headers.  Older versions
2728 of Automake required the use of @code{AM_CONFIG_HEADER}
2729 (@pxref{Macros}); this is no longer the case today.
2731 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2732 specification using shell variables will be ignored as far as
2733 cleaning, distributing, and rebuilding is concerned.
2735 @item AC_CONFIG_LINKS
2736 Automake will generate rules to remove @file{configure} generated
2737 links on @samp{make distclean} and to distribute named source files as
2738 part of @samp{make dist}.
2740 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2741 specification using shell variables will be ignored as far as cleaning
2742 and distributing is concerned.  (There is no rebuild rules for links.)
2744 @item AC_LIBOBJ
2745 @itemx AC_LIBSOURCE
2746 @itemx AC_LIBSOURCES
2747 @vindex LIBOBJS
2748 Automake will automatically distribute any file listed in
2749 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2751 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2752 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2753 @file{file.c} will be distributed automatically by Automake.  This
2754 encompasses many macros like @code{AC_FUNC_ALLOCA},
2755 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2757 By the way, direct assignments to @code{LIBOBJS} are no longer
2758 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2759 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2760 autoconf, The Autoconf Manual}.
2762 @item AC_PROG_RANLIB
2763 This is required if any libraries are built in the package.
2764 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2765 Autoconf Manual}.
2767 @item AC_PROG_CXX
2768 This is required if any C++ source is included.  @xref{Particular
2769 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2771 @item AC_PROG_OBJC
2772 This is required if any Objective C source is included.  @xref{Particular
2773 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2775 @item AC_PROG_F77
2776 This is required if any Fortran 77 source is included.  This macro is
2777 distributed with Autoconf version 2.13 and later.  @xref{Particular
2778 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2780 @item AC_F77_LIBRARY_LDFLAGS
2781 This is required for programs and shared libraries that are a mixture of
2782 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
2783 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
2785 @item AC_FC_SRCEXT
2786 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
2787 of files with the respective source extension (@pxref{Fortran Compiler, ,
2788 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
2790 @item AC_PROG_FC
2791 This is required if any Fortran 90/95 source is included.  This macro is
2792 distributed with Autoconf version 2.58 and later.  @xref{Particular
2793 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
2795 @item AC_PROG_LIBTOOL
2796 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
2797 Introduction, libtool, The Libtool Manual}).
2799 @item AC_PROG_YACC
2800 @vindex YACC
2801 If a Yacc source file is seen, then you must either use this macro or
2802 define the variable @code{YACC} in @file{configure.ac}.  The former is
2803 preferred (@pxref{Particular Programs, , Particular Program Checks,
2804 autoconf, The Autoconf Manual}).
2806 @item AC_PROG_LEX
2807 If a Lex source file is seen, then this macro must be used.
2808 @xref{Particular Programs, , Particular Program Checks, autoconf, The
2809 Autoconf Manual}.
2811 @item AC_REQUIRE_AUX_FILE
2812 @command{automake} will ensure each file for which this macro is
2813 called exists in the aux directory, and will complain otherwise.  It
2814 will also automatically distribute the file.  This macro should be
2815 used by third-party Autoconf macros that requires some supporting
2816 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
2817 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
2818 The Autoconf Manual}.
2820 @item AC_SUBST
2821 The first argument is automatically defined as a variable in each
2822 generated @file{Makefile.in}.  @xref{Setting Output Variables, , Setting
2823 Output Variables, autoconf, The Autoconf Manual}.
2825 If the Autoconf manual says that a macro calls @code{AC_SUBST} for
2826 @var{var}, or defines the output variable @var{var} then @var{var} will
2827 be defined in each @file{Makefile.in} generated by Automake.
2828 E.g.@: @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and @code{X_LIBS}, so
2829 you can use these variables in any @file{Makefile.am} if
2830 @code{AC_PATH_XTRA} is called.
2832 @item AM_C_PROTOTYPES
2833 This is required when using the obsolete de-ANSI-fication feature; see
2834 @ref{ANSI}.
2836 @item AM_GNU_GETTEXT
2837 This macro is required for packages that use GNU gettext
2838 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
2839 this macro it ensures that the package meets some of gettext's
2840 requirements.
2842 @item AM_GNU_GETTEXT_INTL_SUBDIR
2843 This macro specifies that the @file{intl/} subdirectory is to be built,
2844 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
2845 of @samp{external}.
2847 @item AM_MAINTAINER_MODE
2848 @opindex --enable-maintainer-mode
2849 This macro adds a @option{--enable-maintainer-mode} option to
2850 @command{configure}.  If this is used, @command{automake} will cause
2851 ``maintainer-only'' rules to be turned off by default in the
2852 generated @file{Makefile.in}s.  This macro defines the
2853 @code{MAINTAINER_MODE} conditional, which you can use in your own
2854 @file{Makefile.am}.  @xref{maintainer-mode}.
2856 @item m4_include
2857 Files included by @file{configure.ac} using this macro will be
2858 detected by Automake and automatically distributed.  They will also
2859 appear as dependencies in @file{Makefile} rules.
2861 @code{m4_include} is seldom used by @file{configure.ac} authors, but
2862 can appear in @file{aclocal.m4} when @command{aclocal} detects that
2863 some required macros come from files local to your package (as opposed
2864 to macros installed in a system-wide directory, @pxref{Invoking
2865 aclocal}).
2867 @end ftable
2870 @node Invoking aclocal
2871 @section Auto-generating aclocal.m4
2873 @cindex Invoking @command{aclocal}
2874 @cindex @command{aclocal}, Invoking
2876 Automake includes a number of Autoconf macros that can be used in
2877 your package (@pxref{Macros}); some of them are actually required by
2878 Automake in certain situations.  These macros must be defined in your
2879 @file{aclocal.m4}; otherwise they will not be seen by
2880 @command{autoconf}.
2882 The @command{aclocal} program will automatically generate
2883 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
2884 This provides a convenient way to get Automake-provided macros,
2885 without having to search around.  The @command{aclocal} mechanism
2886 allows other packages to supply their own macros (@pxref{Extending
2887 aclocal}).  You can also use it to maintain your own set of custom
2888 macros (@pxref{Local Macros}).
2890 At startup, @command{aclocal} scans all the @file{.m4} files it can
2891 find, looking for macro definitions (@pxref{Macro search path}).  Then
2892 it scans @file{configure.ac}.  Any mention of one of the macros found
2893 in the first step causes that macro, and any macros it in turn
2894 requires, to be put into @file{aclocal.m4}.
2896 @emph{Putting} the file that contains the macro definition into
2897 @file{aclocal.m4} is usually done by copying the entire text of this
2898 file, including unused macro definitions as well as both @samp{#} and
2899 @samp{dnl} comments.  If you want to make a comment that will be
2900 completely ignored by @command{aclocal}, use @samp{##} as the comment
2901 leader.
2903 When a file selected by @command{aclocal} is located in a subdirectory
2904 specified as a relative search path with @command{aclocal}'s @option{-I}
2905 argument, @command{aclocal} assumes the file belongs to the package
2906 and uses @code{m4_include} instead of copying it into
2907 @file{aclocal.m4}.  This makes the package smaller, eases dependency
2908 tracking, and cause the file to be distributed automatically.
2909 (@xref{Local Macros}, for an example.)  Any macro that is found in a
2910 system-wide directory, or via an absolute search path will be copied.
2911 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
2912 some relative directory need to be considered outside the package.
2914 The contents of @file{acinclude.m4}, if this file exists, are also
2915 automatically included in @file{aclocal.m4}.  We recommend against
2916 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
2918 @vindex AUTOM4TE
2919 @cindex autom4te
2920 While computing @file{aclocal.m4}, @command{aclocal} runs
2921 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
2922 autoconf, The Autoconf Manual}) in order to trace the macros that are
2923 really used, and omit from @file{aclocal.m4} all macros that are
2924 mentioned but otherwise unexpanded (this can happen when a macro is
2925 called conditionally).  @command{autom4te} is expected to be in the
2926 @env{PATH}, just as @command{autoconf}.  Its location can be
2927 overridden using the @env{AUTOM4TE} environment variable.
2929 @menu
2930 * aclocal options::             Options supported by aclocal
2931 * Macro search path::           How aclocal finds .m4 files
2932 * Extending aclocal::           Writing your own aclocal macros
2933 * Local Macros::                Organizing local macros
2934 * Serials::                     Serial lines in Autoconf macros
2935 * Future of aclocal::           aclocal's scheduled death
2936 @end menu
2938 @node aclocal options
2939 @subsection aclocal options
2941 @cindex @command{aclocal}, Options
2942 @cindex Options, @command{aclocal}
2944 @command{aclocal} accepts the following options:
2946 @table @code
2947 @item --acdir=@var{dir}
2948 @opindex --acdir
2949 Look for the macro files in @var{dir} instead of the installation
2950 directory.  This is typically used for debugging.
2952 @item --diff[=@var{command}]
2953 @opindex --diff
2954 Run @var{command} on M4 file that would be installed or overwritten
2955 by @option{--install}.  The default @var{command} is @samp{diff -u}.
2956 This option implies @option{--install} and @option{--dry-run}.
2958 @item --dry-run
2959 @opindex --dry-run
2960 Do not actually overwrite (or create) @file{aclocal.m4} and M4
2961 files installed by @option{--install}.
2963 @item --help
2964 @opindex --help
2965 Print a summary of the command line options and exit.
2967 @item -I @var{dir}
2968 @opindex -I
2969 Add the directory @var{dir} to the list of directories searched for
2970 @file{.m4} files.
2972 @item --install
2973 @opindex --install
2974 Install system-wide third-party macros into the first directory
2975 specified with @samp{-I @var{dir}} instead of copying them in the
2976 output file.
2978 @cindex serial number and @option{--install}
2979 When this option is used, and only when this option is used,
2980 @command{aclocal} will also honor @samp{#serial @var{NUMBER}} lines
2981 that appear in macros: an M4 file is ignored if there exists another
2982 M4 file with the same basename and a greater serial number in the
2983 search path (@pxref{Serials}).
2985 @item --force
2986 @opindex --force
2987 Always overwrite the output file.  The default is to overwrite the output
2988 file only when really needed, i.e., when its contents changes or if one
2989 of its dependencies is younger.
2991 This option forces the update of @file{aclocal.m4} (or the file
2992 specified with @file{--output} below) and only this file, it has
2993 absolutely no influence on files that may need to be installed by
2994 @option{--install}.
2996 @item --output=@var{file}
2997 @opindex --output
2998 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3000 @item --print-ac-dir
3001 @opindex --print-ac-dir
3002 Prints the name of the directory that @command{aclocal} will search to
3003 find third-party @file{.m4} files.  When this option is given, normal
3004 processing is suppressed.  This option can be used by a package to
3005 determine where to install a macro file.
3007 @item --verbose
3008 @opindex --verbose
3009 Print the names of the files it examines.
3011 @item --version
3012 @opindex --version
3013 Print the version number of Automake and exit.
3015 @item -W CATEGORY
3016 @item --warnings=@var{category}
3017 @opindex -W
3018 @opindex --warnings
3019 Output warnings falling in @var{category}.  @var{category} can be
3020 one of:
3021 @table @code
3022 @item syntax
3023 dubious syntactic constructs, underquoted macros, unused macros, etc.
3024 @item unsupported
3025 unknown macros
3026 @item all
3027 all the warnings, this is the default
3028 @item none
3029 turn off all the warnings
3030 @item error
3031 treat warnings as errors
3032 @end table
3034 All warnings are output by default.
3036 @vindex WARNINGS
3037 The environment variable @env{WARNINGS} is honored in the same
3038 way as it is for @command{automake} (@pxref{Invoking Automake}).
3040 @end table
3042 @node Macro search path
3043 @subsection Macro search path
3045 @cindex Macro search path
3046 @cindex @command{aclocal} search path
3048 By default, @command{aclocal} searches for @file{.m4} files in the following
3049 directories, in this order:
3051 @table @code
3052 @item @var{acdir-APIVERSION}
3053 This is where the @file{.m4} macros distributed with automake itself
3054 are stored.  @var{APIVERSION} depends on the automake release used;
3055 for automake 1.6.x, @var{APIVERSION} = @code{1.6}.
3057 @item @var{acdir}
3058 This directory is intended for third party @file{.m4} files, and is
3059 configured when @command{automake} itself is built.  This is
3060 @file{@@datadir@@/aclocal/}, which typically
3061 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3062 value of @var{acdir}, use the @option{--print-ac-dir} option
3063 (@pxref{aclocal options}).
3064 @end table
3066 As an example, suppose that @command{automake-1.6.2} was configured with
3067 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3069 @enumerate
3070 @item @file{/usr/local/share/aclocal-1.6/}
3071 @item @file{/usr/local/share/aclocal/}
3072 @end enumerate
3074 As explained in (@pxref{aclocal options}), there are several options that
3075 can be used to change or extend this search path.
3077 @subsubsection Modifying the macro search path: @option{--acdir}
3079 The most erroneous option to modify the search path is
3080 @option{--acdir=@var{dir}}, which changes default directory and
3081 drops the @var{APIVERSION} directory.  For example, if one specifies
3082 @samp{--acdir=/opt/private/}, then the search path becomes:
3084 @enumerate
3085 @item @file{/opt/private/}
3086 @end enumerate
3088 This option, @option{--acdir}, is intended for use by the internal
3089 automake test suite only; it is not ordinarily needed by end-users.
3091 @subsubsection Modifying the macro search path: @samp{-I @var{dir}}
3093 Any extra directories specified using @option{-I} options
3094 (@pxref{aclocal options}) are @emph{prepended} to this search list.  Thus,
3095 @samp{aclocal -I /foo -I /bar} results in the following search path:
3097 @enumerate
3098 @item @file{/foo}
3099 @item @file{/bar}
3100 @item @var{acdir}-@var{APIVERSION}
3101 @item @var{acdir}
3102 @end enumerate
3104 @subsubsection Modifying the macro search path: @file{dirlist}
3105 @cindex @file{dirlist}
3107 There is a third mechanism for customizing the search path.  If a
3108 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3109 contain a list of directory patterns, one per line.  @command{aclocal}
3110 expands these patterns to directory names, and adds them to the search
3111 list @emph{after} all other directories.  @file{dirlist} entries may
3112 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3114 For example, suppose
3115 @file{@var{acdir}/dirlist} contains the following:
3117 @example
3118 /test1
3119 /test2
3120 /test3*
3121 @end example
3123 @noindent
3124 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3125 Then, the search path would be
3127 @c @code looks better than @file here
3128 @enumerate
3129 @item @code{/foo}
3130 @item @code{/bar}
3131 @item @var{acdir}-@var{APIVERSION}
3132 @item @var{acdir}
3133 @item @code{/test1}
3134 @item @code{/test2}
3135 @end enumerate
3137 @noindent
3138 and all directories with path names starting with @code{/test3}.
3140 If the @option{--acdir=@var{dir}} option is used, then @command{aclocal}
3141 will search for the @file{dirlist} file in @var{dir}.  In the
3142 @samp{--acdir=/opt/private/} example above, @command{aclocal} would look
3143 for @file{/opt/private/dirlist}.  Again, however, the @option{--acdir}
3144 option is intended for use by the internal automake test suite only;
3145 @option{--acdir} is not ordinarily needed by end-users.
3147 @file{dirlist} is useful in the following situation: suppose that
3148 @command{automake} version @code{1.6.2} is installed with
3149 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3150 directories are
3152 @c @code looks better than @file here
3153 @enumerate
3154 @item @code{/usr/share/aclocal-1.6/}
3155 @item @code{/usr/share/aclocal/}
3156 @end enumerate
3158 However, suppose further that many packages have been manually
3159 installed on the system, with $prefix=/usr/local, as is typical.  In
3160 that case, many of these ``extra'' @file{.m4} files are in
3161 @file{/usr/local/share/aclocal}.  The only way to force
3162 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3163 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3164 inconvenient.  With @file{dirlist}, one may create a file
3165 @file{/usr/share/aclocal/dirlist} containing only the single line
3167 @example
3168 /usr/local/share/aclocal
3169 @end example
3171 Now, the ``default'' search path on the affected system is
3173 @c @code looks better than @file here
3174 @enumerate
3175 @item @code{/usr/share/aclocal-1.6/}
3176 @item @code{/usr/share/aclocal/}
3177 @item @code{/usr/local/share/aclocal/}
3178 @end enumerate
3180 without the need for @option{-I} options; @option{-I} options can be reserved
3181 for project-specific needs (@file{my-source-dir/m4/}), rather than
3182 using it to work around local system-dependent tool installation
3183 directories.
3185 Similarly, @file{dirlist} can be handy if you have installed a local
3186 copy Automake on your account and want @command{aclocal} to look for
3187 macros installed at other places on the system.
3190 @node Extending aclocal
3191 @subsection Writing your own aclocal macros
3193 @cindex @command{aclocal}, extending
3194 @cindex Extending @command{aclocal}
3196 The @command{aclocal} program doesn't have any built-in knowledge of any
3197 macros, so it is easy to extend it with your own macros.
3199 This can be used by libraries that want to supply their own Autoconf
3200 macros for use by other programs.  For instance, the @command{gettext}
3201 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3202 any package using @command{gettext}.  When the library is installed, it
3203 installs this macro so that @command{aclocal} will find it.
3205 A macro file's name should end in @file{.m4}.  Such files should be
3206 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3208 @example
3209 aclocaldir = $(datadir)/aclocal
3210 aclocal_DATA = mymacro.m4 myothermacro.m4
3211 @end example
3213 @noindent
3214 Please do use @file{$(datadir)/aclocal}, and not something based on
3215 the result of @samp{aclocal --print-ac-dir}.  @xref{Hard-Coded Install
3216 Paths}, for arguments.
3218 A file of macros should be a series of properly quoted
3219 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3220 Autoconf Manual}).  The @command{aclocal} programs also understands
3221 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3222 Autoconf Manual}), so it is safe to put each macro in a separate file.
3223 Each file should have no side effects but macro definitions.
3224 Especially, any call to @code{AC_PREREQ} should be done inside the
3225 defined macro, not at the beginning of the file.
3227 @cindex underquoted @code{AC_DEFUN}
3228 @acindex AC_DEFUN
3229 @acindex AC_PREREQ
3231 Starting with Automake 1.8, @command{aclocal} will warn about all
3232 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3233 lot of people, because @command{aclocal} was not so strict in the past
3234 and many third party macros are underquoted; and we have to apologize
3235 for this temporary inconvenience.  The reason we have to be stricter
3236 is that a future implementation of @command{aclocal} (@pxref{Future of
3237 aclocal}) will have to temporarily include all these third party
3238 @file{.m4} files, maybe several times, including even files that are
3239 not actually needed.  Doing so should alleviate many problems of the
3240 current implementation, however it requires a stricter style from the
3241 macro authors.  Hopefully it is easy to revise the existing macros.
3242 For instance,
3243 @example
3244 # bad style
3245 AC_PREREQ(2.57)
3246 AC_DEFUN(AX_FOOBAR,
3247 [AC_REQUIRE([AX_SOMETHING])dnl
3248 AX_FOO
3249 AX_BAR
3251 @end example
3252 @noindent
3253 should be rewritten as
3254 @example
3255 AC_DEFUN([AX_FOOBAR],
3256 [AC_PREREQ([2.57])dnl
3257 AC_REQUIRE([AX_SOMETHING])dnl
3258 AX_FOO
3259 AX_BAR
3261 @end example
3263 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3264 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
3265 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3266 allows the macro to be redefined or included twice (otherwise this
3267 first argument would be expanded during the second definition).  For
3268 consistency we like to quote even arguments such as @code{2.57} that
3269 do not require it.
3271 If you have been directed here by the @command{aclocal} diagnostic but
3272 are not the maintainer of the implicated macro, you will want to
3273 contact the maintainer of that macro.  Please make sure you have the
3274 last version of the macro and that the problem already hasn't been
3275 reported before doing so: people tend to work faster when they aren't
3276 flooded by mails.
3278 Another situation where @command{aclocal} is commonly used is to
3279 manage macros that are used locally by the package, @ref{Local
3280 Macros}.
3282 @node Local Macros
3283 @subsection Handling Local Macros
3285 Feature tests offered by Autoconf do not cover all needs.  People
3286 often have to supplement existing tests with their own macros, or
3287 with third-party macros.
3289 There are two ways to organize custom macros in a package.
3291 The first possibility (the historical practice) is to list all your
3292 macros in @file{acinclude.m4}.  This file will be included in
3293 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3294 henceforth be visible to @command{autoconf}.  However if it contains
3295 numerous macros, it will rapidly become difficult to maintain, and it
3296 will be almost impossible to share macros between packages.
3298 @vindex ACLOCAL_AMFLAGS
3299 The second possibility, which we do recommend, is to write each macro
3300 in its own file and gather all these files in a directory.  This
3301 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3302 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3303 From the command line, this is done with @samp{aclocal -I m4}.  The
3304 top-level @file{Makefile.am} should also be updated to define
3306 @example
3307 ACLOCAL_AMFLAGS = -I m4
3308 @end example
3310 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3311 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3312 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3313 Using @command{autoreconf} to Update @file{configure} Scripts,
3314 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3315 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3316 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3317 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3318 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3319 the place where Gettext's macros should be installed.  So even if you
3320 do not really care about the rebuild rules, you should define
3321 @code{ACLOCAL_AMFLAGS}.
3323 When @samp{aclocal -I m4} is run, it will build a @file{aclocal.m4}
3324 that @code{m4_include}s any file from @file{m4/} that defines a
3325 required macro.  Macros not found locally will still be searched in
3326 system-wide directories, as explained in @ref{Macro search path}.
3328 Custom macros should be distributed for the same reason that
3329 @file{configure.ac} is: so that other people have all the sources of
3330 your package if they want to work on it.  Actually, this distribution
3331 happens automatically because all @code{m4_include}d files are
3332 distributed.
3334 However there is no consensus on the distribution of third-party
3335 macros that your package may use.  Many libraries install their own
3336 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3337 aclocal}).  For instance, Guile ships with a file called
3338 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3339 be used to define setup compiler and linker flags appropriate for
3340 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3341 cause @command{aclocal} to copy @file{guile.m4} into
3342 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3343 it will not be distributed.  Technically, that means a user who
3344 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3345 This is probably OK, if Guile already is a requirement to build the
3346 package.  However, if Guile is only an optional feature, or if your
3347 package might run on architectures where Guile cannot be installed,
3348 this requirement will hinder development.  An easy solution is to copy
3349 such third-party macros in your local @file{m4/} directory so they get
3350 distributed.
3352 Since Automake 1.10, @command{aclocal} offers an option to copy these
3353 system-wide third-party macros in your local macro directory, solving
3354 the above problem.  Simply use:
3356 @example
3357 ACLOCAL_AMFLAGS = -I m4 --install
3358 @end example
3360 @noindent
3361 With this setup, system-wide macros will be copied to @file{m4/}
3362 the first time you run @command{autoreconf}.  Then the locally
3363 installed macros will have precedence over the system-wide installed
3364 macros each time @command{aclocal} is run again.
3366 One reason why you should keep @option{--install} in the flags even
3367 after the first run is that when you later edit @file{configure.ac}
3368 and depend on a new macro, this macro will be installed in your
3369 @file{m4/} automatically.  Another one is that serial numbers
3370 (@pxref{Serials}) can be used to update the macros in your source tree
3371 automatically when new system-wide versions are installed.  A serial
3372 number should be a single line of the form
3374 @example
3375 #serial @var{NNN}
3376 @end example
3378 @noindent
3379 where @var{NNN} contains only digits and dots.  It should appear in
3380 the M4 file before any macro definition.  It is a good practice to
3381 maintain a serial number for each macro you distribute, even if you do
3382 not use the @option{--install} option of @command{aclocal}: this allows
3383 other people to use it.
3386 @node Serials
3387 @subsection Serial Numbers
3388 @cindex serial numbers in macros
3389 @cindex macro serial numbers
3390 @cindex @code{#serial} syntax
3391 @cindex @command{aclocal} and serial numbers
3393 Because third-party macros defined in @file{*.m4} files are naturally
3394 shared between multiple projects, some people like to version them.
3395 This makes it easier to tell which of two M4 files is newer.  Since at
3396 least 1996, the tradition is to use a @samp{#serial} line for this.
3398 A serial number should be a single line of the form
3400 @example
3401 # serial @var{version}
3402 @end example
3404 @noindent
3405 where @var{version} is a version number containing only digits and
3406 dots.  Usually people use a single integer, and they increment it each
3407 time they change the macro (hence the name of ``serial'').  Such a
3408 line should appear in the M4 file before any macro definition.
3410 The @samp{#} must be the first character on the line,
3411 and it is OK to have extra words after the version, as in
3413 @example
3414 #serial @var{version} @var{garbage}
3415 @end example
3417 Normally these serial numbers are completely ignored by
3418 @command{aclocal} and @command{autoconf}, like any genuine comment.
3419 However when using @command{aclocal}'s @option{--install} feature, these
3420 serial numbers will modify the way @command{aclocal} selects the
3421 macros to install in the package: if two files with the same basename
3422 exists in your search path, and if at least one of them use a
3423 @samp{#serial} line, @command{aclocal} will ignore the file that has
3424 the older @samp{#serial} line (or the file that has none).
3426 Note that a serial number applies to a whole M4 file, not to any macro
3427 it contains.  A file can contains multiple macros, but only one
3428 serial.
3430 Here is a use case that illustrate the use of @option{--install} and
3431 its interaction with serial numbers.  Let's assume we maintain a
3432 package called MyPackage, the @file{configure.ac} of which requires a
3433 third-party macro @code{AX_THIRD_PARTY} defined in
3434 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3436 @example
3437 # serial 1
3438 AC_DEFUN([AX_THIRD_PARTY], [...])
3439 @end example
3441 MyPackage uses an @file{m4/} directory to store local macros as
3442 explained in @ref{Local Macros}, and has
3444 @example
3445 ACLOCAL_AMFLAGS = -I m4 --install
3446 @end example
3448 @noindent
3449 in its top-level @file{Makefile.am}.
3451 Initially the @file{m4/} directory is empty.  The first time we run
3452 @command{autoreconf}, it will fetch the options to pass to
3453 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3454 --install}.  @command{aclocal} will notice that
3456 @itemize @bullet
3457 @item
3458 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3459 @item
3460 No local macros define @code{AX_THIRD_PARTY}
3461 @item
3462 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3463 with serial 1.
3464 @end itemize
3466 @noindent
3467 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3468 and @command{aclocal} was given the @option{--install} option, it will
3469 copy this file in @file{m4/thirdparty.m4}, and output an
3470 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3472 The next time @samp{aclocal -I m4 --install} is run (either via
3473 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3474 rules) something different happens.  @command{aclocal} notices that
3476 @itemize @bullet
3477 @item
3478 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3479 @item
3480 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3481 with serial 1.
3482 @item
3483 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3484 with serial 1.
3485 @end itemize
3487 @noindent
3488 Because both files have the same serial number, @command{aclocal} uses
3489 the first it found in its search path order (@pxref{Macro search
3490 path}).  @command{aclocal} therefore ignores
3491 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3492 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3494 Local directories specified with @option{-I} are always searched before
3495 system-wide directories, so a local file will always be preferred to
3496 the system-wide file in case of equal serial numbers.
3498 Now suppose the system-wide third-party macro is changed.  This can
3499 happen if the package installing this macro is updated.  Let's suppose
3500 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3501 --install} is run the situation is the following:
3503 @itemize @bullet
3504 @item
3505 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3506 @item
3507 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3508 with serial 1.
3509 @item
3510 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3511 with serial 2.
3512 @end itemize
3514 @noindent
3515 When @command{aclocal} sees a greater serial number, it immediately
3516 forgets anything it knows from files that have the same basename and a
3517 smaller serial number.  So after it has found
3518 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3519 @command{aclocal} will proceed as if it had never seen
3520 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3521 to that at the beginning of our example, where no local file defined
3522 the macro.  @command{aclocal} will install the new version of the
3523 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3524 version.  MyPackage just had its macro updated as a side effect of
3525 running @command{aclocal}.
3527 If you are leery of letting @command{aclocal} update your local macro,
3528 you can run @samp{aclocal -I m4 --diff} to review the changes
3529 @samp{aclocal -I m4 --install} would perform on these macros.
3531 Finally, note that the @option{--force} option of @command{aclocal} has
3532 absolutely no effect on the files installed by @option{--install}.  For
3533 instance, if you have modified your local macros, do not expect
3534 @option{--install --force} to replace the local macros by their
3535 system-wide versions.  If you want to do so, simply erase the local
3536 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3539 @node Future of aclocal
3540 @subsection The Future of @command{aclocal}
3541 @cindex @command{aclocal}'s scheduled death
3543 @command{aclocal} is expected to disappear.  This feature really
3544 should not be offered by Automake.  Automake should focus on
3545 generating @file{Makefile}s; dealing with M4 macros really is
3546 Autoconf's job.  That some people install Automake just to use
3547 @command{aclocal}, but do not use @command{automake} otherwise is an
3548 indication of how that feature is misplaced.
3550 The new implementation will probably be done slightly differently.
3551 For instance, it could enforce the @file{m4/}-style layout discussed in
3552 @ref{Local Macros}.
3554 We have no idea when and how this will happen.  This has been
3555 discussed several times in the past, but someone still has to commit
3556 itself to that non-trivial task.
3558 From the user point of view, @command{aclocal}'s removal might turn
3559 out to be painful.  There is a simple precaution that you may take to
3560 make that switch more seamless: never call @command{aclocal} yourself.
3561 Keep this guy under the exclusive control of @command{autoreconf} and
3562 Automake's rebuild rules.  Hopefully you won't need to worry about
3563 things breaking, when @command{aclocal} disappears, because everything
3564 will have been taken care of.  If otherwise you used to call
3565 @command{aclocal} directly yourself or from some script, you will
3566 quickly notice the change.
3568 Many packages come with a script called @file{bootstrap.sh} or
3569 @file{autogen.sh}, that will just call @command{aclocal},
3570 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3571 @command{autoconf}, @command{autoheader}, and @command{automake} in
3572 the right order.  Actually this is precisely what @command{autoreconf}
3573 can do for you.  If your package has such a @file{bootstrap.sh} or
3574 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3575 should simplify its logic a lot (less things to maintain, yum!), it's
3576 even likely you will not need the script anymore, and more to the point
3577 you will not call @command{aclocal} directly anymore.
3579 For the time being, third-party packages should continue to install
3580 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3581 is replaced by another tool it might make sense to rename the
3582 directory, but supporting @file{/usr/share/aclocal/} for backward
3583 compatibility should be really easy provided all macros are properly
3584 written (@pxref{Extending aclocal}).
3588 @node Macros
3589 @section Autoconf macros supplied with Automake
3591 Automake ships with several Autoconf macros that you can use from your
3592 @file{configure.ac}.  When you use one of them it will be included by
3593 @command{aclocal} in @file{aclocal.m4}.
3595 @menu
3596 * Public macros::               Macros that you can use.
3597 * Obsolete macros::             Macros that you should stop using.
3598 * Private macros::              Macros that you should not use.
3599 @end menu
3601 @c consider generating the following subsections automatically from m4 files.
3603 @node Public macros
3604 @subsection Public macros
3606 @table @code
3608 @item AM_ENABLE_MULTILIB
3609 @acindex AM_ENABLE_MULTILIB
3610 This is used when a ``multilib'' library is being built.  The first
3611 optional argument is the name of the @file{Makefile} being generated; it
3612 defaults to @samp{Makefile}.  The second option argument is used to find
3613 the top source directory; it defaults to the empty string (generally
3614 this should not be used unless you are familiar with the internals).
3615 @xref{Multilibs}.
3617 @item AM_INIT_AUTOMAKE([OPTIONS])
3618 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
3619 @acindex AM_INIT_AUTOMAKE
3620 Runs many macros required for proper operation of the generated Makefiles.
3622 @vindex AUTOMAKE_OPTIONS
3623 This macro has two forms, the first of which is preferred.
3624 In this form, @code{AM_INIT_AUTOMAKE} is called with a
3625 single argument: a space-separated list of Automake options that should
3626 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3627 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3629 @acindex AC_INIT
3630 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
3631 arguments: the package and the version number.  This form is
3632 obsolete because the @var{package} and @var{version} can be obtained
3633 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
3634 form).
3636 If your @file{configure.ac} has:
3638 @example
3639 AC_INIT([src/foo.c])
3640 AM_INIT_AUTOMAKE([mumble], [1.5])
3641 @end example
3643 @noindent
3644 you can modernize it as follows:
3646 @example
3647 AC_INIT([mumble], [1.5])
3648 AC_CONFIG_SRCDIR([src/foo.c])
3649 AM_INIT_AUTOMAKE
3650 @end example
3652 Note that if you're upgrading your @file{configure.ac} from an earlier
3653 version of Automake, it is not always correct to simply move the
3654 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3655 @code{AC_INIT}, as in the example above.  The first argument to
3656 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3657 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3658 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3659 tarball name from the package name, which should work for most but not
3660 all package names.  (If it doesn't work for yours, you can use the
3661 four-argument form of @code{AC_INIT} to provide the tarball name
3662 explicitly).
3664 @cindex @code{PACKAGE}, prevent definition
3665 @cindex @code{VERSION}, prevent definition
3666 @opindex no-define
3667 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3668 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3669 option, as in:
3670 @example
3671 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3672 @end example
3673 or by passing a third non-empty argument to the obsolete form.
3675 @item AM_PATH_LISPDIR
3676 @acindex AM_PATH_LISPDIR
3677 @vindex EMACS
3678 @vindex lispdir
3679 Searches for the program @command{emacs}, and, if found, sets the
3680 output variable @code{lispdir} to the full path to Emacs' site-lisp
3681 directory.
3683 Note that this test assumes the @command{emacs} found to be a version
3684 that supports Emacs Lisp (such as @sc{gnu} Emacs or XEmacs).  Other
3685 emacsen can cause this test to hang (some, like old versions of
3686 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3687 exit, which is hardly obvious for a non-emacs user).  In most cases,
3688 however, you should be able to use @kbd{C-c} to kill the test.  In
3689 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3690 environment, or use the @option{--with-lispdir} option to
3691 @command{configure} to explicitly set the correct path (if you're sure
3692 you have an @command{emacs} that supports Emacs Lisp.
3694 @item AM_PROG_AS
3695 @acindex AM_PROG_AS
3696 @vindex CCAS
3697 @vindex CCASFLAGS
3698 Use this macro when you have assembly code in your project.  This will
3699 choose the assembler for you (by default the C compiler) and set
3700 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
3702 @item AM_PROG_CC_C_O
3703 @acindex AM_PROG_CC_C_O
3704 @acindex AC_PROG_CC_C_O
3705 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
3706 the manner required by automake.  You must use this instead of
3707 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
3708 using per-target flags or subdir-objects with C sources.
3710 @item AM_PROG_LEX
3711 @acindex AM_PROG_LEX
3712 @acindex AC_PROG_LEX
3713 @cindex HP-UX 10, @command{lex} problems
3714 @cindex @command{lex} problems with HP-UX 10
3715 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
3716 Program Checks, autoconf, The Autoconf Manual}), but uses the
3717 @command{missing} script on systems that do not have @command{lex}.
3718 HP-UX 10 is one such system.
3720 @item AM_PROG_GCJ
3721 @acindex AM_PROG_GCJ
3722 @vindex GCJ
3723 @vindex GCJFLAGS
3724 This macro finds the @command{gcj} program or causes an error.  It sets
3725 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
3726 GNU Compiler Collection.
3728 @item AM_PROG_UPC([@var{compiler-search-list}])
3729 @acindex AM_PROG_UPC
3730 @vindex UPC
3731 Find a compiler for Unified Parallel C and define the @code{UPC}
3732 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
3733 This macro will abort @command{configure} if no Unified Parallel C
3734 compiler is found.
3736 @item AM_WITH_DMALLOC
3737 @acindex AM_WITH_DMALLOC
3738 @cindex @command{dmalloc}, support for
3739 @vindex WITH_DMALLOC
3740 @opindex --with-dmalloc
3741 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
3742 the user runs @command{configure} with @option{--with-dmalloc}, then
3743 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
3745 @item AM_WITH_REGEX
3746 @acindex AM_WITH_REGEX
3747 @vindex WITH_REGEX
3748 @opindex --with-regex
3749 @cindex regex package
3750 @cindex rx package
3751 Adds @option{--with-regex} to the @command{configure} command line.  If
3752 specified (the default), then the @samp{regex} regular expression
3753 library is used, @file{regex.o} is put into @code{LIBOBJS}, and
3754 @code{WITH_REGEX} is defined.  If @option{--without-regex} is given, then
3755 the @code{rx} regular expression library is used, and @file{rx.o} is put
3756 into @code{LIBOBJS}.
3758 @end table
3761 @node Obsolete macros
3762 @subsection Obsolete macros
3763 @cindex obsolete macros
3764 @cindex autoupdate
3766 Although using some of the following macros was required in past
3767 releases, you should not used any of them in new code.  Running
3768 @command{autoupdate} should adjust your @file{configure.ac}
3769 automatically (@pxref{autoupdate Invocation, , Using
3770 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
3771 Autoconf Manual}).
3773 @table @code
3774 @item AM_C_PROTOTYPES
3775 @acindex AM_C_PROTOTYPES
3776 @vindex ANSI2KNR
3777 @vindex U
3778 Check to see if function prototypes are understood by the compiler.  If
3779 so, define @samp{PROTOTYPES} and set the output variables @code{U} and
3780 @code{ANSI2KNR} to the empty string.  Otherwise, set @code{U} to
3781 @samp{_} and @code{ANSI2KNR} to @samp{./ansi2knr}.  Automake uses these
3782 values to implement the obsolete de-ANSI-fication feature.
3784 @item AM_CONFIG_HEADER
3785 @acindex AM_CONFIG_HEADER
3786 Automake will generate rules to automatically regenerate the config
3787 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
3788 today (@pxref{Optional}).
3790 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3791 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
3792 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
3793 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
3794 found in @file{<termios.h>}.  This macro is obsolete, you should
3795 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
3797 @item AM_PROG_MKDIR_P
3798 @acindex AM_PROG_MKDIR_P
3799 @cindex @code{mkdir -p}, macro check
3800 @vindex MKDIR_P
3801 @vindex mkdir_p
3803 From Automake 1.8 to 1.9.6 this macro used to define the output
3804 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
3805 -d}, or @code{mkinstalldirs}.
3807 Nowadays Autoconf provides a similar functionality with
3808 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
3809 Program Checks, autoconf, The Autoconf Manual}), however this defines
3810 the output variable @code{MKDIR_P} instead.  Therefore
3811 @code{AM_PROG_MKDIR_P} has been rewritten as a thin wrapper around
3812 @code{AC_PROG_MKDIR_P} to define @code{mkdir_p} to the same value as
3813 @code{MKDIR_P} for backward compatibility.
3815 If you are using Automake, there is normally no reason to call this
3816 macro, because @code{AM_INIT_AUTOMAKE} already does so.  However, make
3817 sure that the custom rules in your @file{Makefile}s use
3818 @code{$(MKDIR_P)} and not @code{$(mkdir_p)}.  Even if both variables
3819 still work, the latter should be considered obsolete.
3821 If you are not using Automake, please call @code{AC_PROG_MKDIR_P}
3822 instead of @code{AM_PROG_MKDIR_P}.
3824 @item AM_SYS_POSIX_TERMIOS
3825 @acindex AM_SYS_POSIX_TERMIOS
3826 @cindex POSIX termios headers
3827 @cindex termios POSIX headers
3828 Check to see if POSIX termios headers and functions are available on the
3829 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
3830 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
3831 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
3833 @end table
3836 @node Private macros
3837 @subsection Private macros
3839 The following macros are private macros you should not call directly.
3840 They are called by the other public macros when appropriate.  Do not
3841 rely on them, as they might be changed in a future version.  Consider
3842 them as implementation details; or better, do not consider them at all:
3843 skip this section!
3845 @ftable @code
3846 @item _AM_DEPENDENCIES
3847 @itemx AM_SET_DEPDIR
3848 @itemx AM_DEP_TRACK
3849 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
3850 These macros are used to implement Automake's automatic dependency
3851 tracking scheme.  They are called automatically by automake when
3852 required, and there should be no need to invoke them manually.
3854 @item AM_MAKE_INCLUDE
3855 This macro is used to discover how the user's @command{make} handles
3856 @code{include} statements.  This macro is automatically invoked when
3857 needed; there should be no need to invoke it manually.
3859 @item AM_PROG_INSTALL_STRIP
3860 This is used to find a version of @code{install} that can be used to
3861 strip a program at installation time.  This macro is automatically
3862 included when required.
3864 @item AM_SANITY_CHECK
3865 This checks to make sure that a file created in the build directory is
3866 newer than a file in the source directory.  This can fail on systems
3867 where the clock is set incorrectly.  This macro is automatically run
3868 from @code{AM_INIT_AUTOMAKE}.
3870 @end ftable
3873 @node Directories
3874 @chapter Directories
3876 For simple projects that distributes all files in the same directory
3877 it is enough to have a single @file{Makefile.am} that builds
3878 everything in place.
3880 In larger projects it is common to organize files in different
3881 directories, in a tree.  For instance one directory per program, per
3882 library or per module.  The traditional approach is to build these
3883 subdirectory recursively: each directory contains its @file{Makefile}
3884 (generated from @file{Makefile.am}), and when @command{make} is run
3885 from the top level directory it enters each subdirectory in turn to
3886 build its contents.
3888 @menu
3889 * Subdirectories::              Building subdirectories recursively
3890 * Conditional Subdirectories::  Conditionally not building directories
3891 * Alternative::                 Subdirectories without recursion
3892 * Subpackages::                 Nesting packages
3893 @end menu
3895 @node Subdirectories
3896 @section Recursing subdirectories
3898 @cindex @code{SUBDIRS}, explained
3900 In packages with subdirectories, the top level @file{Makefile.am} must
3901 tell Automake which subdirectories are to be built.  This is done via
3902 the @code{SUBDIRS} variable.
3903 @vindex SUBDIRS
3905 The @code{SUBDIRS} variable holds a list of subdirectories in which
3906 building of various sorts can occur.  The rules for many targets
3907 (e.g., @code{all}) in the generated @file{Makefile} will run commands
3908 both locally and in all specified subdirectories.  Note that the
3909 directories listed in @code{SUBDIRS} are not required to contain
3910 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
3911 This allows inclusion of libraries from packages that do not use
3912 Automake (such as @code{gettext}; see also @ref{Third-Party
3913 Makefiles}).
3915 In packages that use subdirectories, the top-level @file{Makefile.am} is
3916 often very short.  For instance, here is the @file{Makefile.am} from the
3917 GNU Hello distribution:
3919 @example
3920 EXTRA_DIST = BUGS ChangeLog.O README-alpha
3921 SUBDIRS = doc intl po src tests
3922 @end example
3924 When Automake invokes @command{make} in a subdirectory, it uses the value
3925 of the @code{MAKE} variable.  It passes the value of the variable
3926 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
3927 @file{Makefile.am} if there are flags you must always pass to
3928 @command{make}.
3929 @vindex MAKE
3930 @vindex AM_MAKEFLAGS
3932 The directories mentioned in @code{SUBDIRS} are usually direct
3933 children of the current directory, each subdirectory containing its
3934 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
3935 subdirectories.  Automake can be used to construct packages of
3936 arbitrary depth this way.
3938 By default, Automake generates @file{Makefiles} that work depth-first
3939 in postfix order: the subdirectories are built before the current
3940 directory.  However, it is possible to change this ordering.  You can
3941 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
3942 putting @samp{.} first will cause a prefix ordering of
3943 directories.
3945 Using
3947 @example
3948 SUBDIRS = lib src . test
3949 @end example
3951 @noindent
3952 will cause @file{lib/} to be built before @file{src/}, then the
3953 current directory will be built, finally the @file{test/} directory
3954 will be built.  It is customary to arrange test directories to be
3955 built after everything else since they are meant to test what has
3956 been constructed.
3958 All @code{clean} rules are run in reverse order of build rules.
3960 @node Conditional Subdirectories
3961 @section Conditional Subdirectories
3962 @cindex Subdirectories, building conditionally
3963 @cindex Conditional subdirectories
3964 @cindex @code{SUBDIRS}, conditional
3965 @cindex Conditional @code{SUBDIRS}
3967 It is possible to define the @code{SUBDIRS} variable conditionally if,
3968 like in the case of GNU Inetutils, you want to only build a subset of
3969 the entire package.
3971 To illustrate how this works, let's assume we have two directories
3972 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
3973 want to decide in @command{configure} whether @file{opt/} will be built
3974 or not.  (For this example we will assume that @file{opt/} should be
3975 built when the variable @samp{$want_opt} was set to @samp{yes}.)
3977 Running @command{make} should thus recurse into @file{src/} always, and
3978 then maybe in @file{opt/}.
3980 However @samp{make dist} should always recurse into both @file{src/}
3981 and @file{opt/}.  Because @file{opt/} should be distributed even if it
3982 is not needed in the current configuration.  This means
3983 @file{opt/Makefile} should be created @emph{unconditionally}.
3985 There are two ways to setup a project like this.  You can use Automake
3986 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
3987 variables (@pxref{Setting Output Variables, , Setting Output
3988 Variables, autoconf, The Autoconf Manual}).  Using Automake
3989 conditionals is the preferred solution.  Before we illustrate these
3990 two possibilities, let's introduce @code{DIST_SUBDIRS}.
3992 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
3993 @cindex @code{DIST_SUBDIRS}, explained
3995 Automake considers two sets of directories, defined by the variables
3996 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
3998 @code{SUBDIRS} contains the subdirectories of the current directory
3999 that must be built (@pxref{Subdirectories}).  It must be defined
4000 manually; Automake will never guess a directory is to be built.  As we
4001 will see in the next two sections, it is possible to define it
4002 conditionally so that some directory will be omitted from the build.
4004 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4005 directories, even those that have been conditionally left out of the
4006 build.  Recall our example where we may not want to build subdirectory
4007 @file{opt/}, but yet we want to distribute it?  This is where
4008 @code{DIST_SUBDIRS} come into play: @samp{opt} may not appear in
4009 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4011 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4012 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4013 other recursive rules use @code{SUBDIRS}.
4015 If @code{SUBDIRS} is defined conditionally using Automake
4016 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4017 from the possibles values of @code{SUBDIRS} in all conditions.
4019 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4020 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4021 does not know the possible values of these variables.  In this case
4022 @code{DIST_SUBDIRS} needs to be defined manually.
4024 @subsection Conditional subdirectories with @code{AM_CONDITIONAL}
4025 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4026 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4028 @c The test case for the setup described here is
4029 @c     test/subdircond2.test
4030 @c Try to keep it in sync.
4032 @file{configure} should output the @file{Makefile} for each directory
4033 and define a condition into which @file{opt/} should be built.
4035 @example
4036 @dots{}
4037 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4038 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4039 @dots{}
4040 @end example
4042 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4043 as follows.
4045 @example
4046 if COND_OPT
4047   MAYBE_OPT = opt
4048 endif
4049 SUBDIRS = src $(MAYBE_OPT)
4050 @end example
4052 As you can see, running @command{make} will rightly recurse into
4053 @file{src/} and maybe @file{opt/}.
4055 @vindex DIST_SUBDIRS
4056 As you can't see, running @samp{make dist} will recurse into both
4057 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4058 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4059 @code{DIST_SUBDIRS} variable.
4061 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4062 automatically because it knows that @code{MAYBE_OPT} can contain
4063 @samp{opt} in some condition.
4065 @subsection Conditional Subdirectories with @code{AC_SUBST}
4066 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4067 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4069 @c The test case for the setup described here is
4070 @c     test/subdircond3.test
4071 @c Try to keep it in sync.
4073 Another possibility is to define @code{MAYBE_OPT} from
4074 @file{./configure} using @code{AC_SUBST}:
4076 @example
4077 @dots{}
4078 if test "$want_opt" = yes; then
4079   MAYBE_OPT=opt
4080 else
4081   MAYBE_OPT=
4083 AC_SUBST([MAYBE_OPT])
4084 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4085 @dots{}
4086 @end example
4088 In this case the top-level @file{Makefile.am} should look as follows.
4090 @example
4091 SUBDIRS = src $(MAYBE_OPT)
4092 DIST_SUBDIRS = src opt
4093 @end example
4095 The drawback is that since Automake cannot guess what the possible
4096 values of @code{MAYBE_OPT} are, it is necessary to define
4097 @code{DIST_SUBDIRS}.
4099 @subsection Non-configured Subdirectories
4100 @cindex Subdirectories, configured conditionally
4102 The semantic of @code{DIST_SUBDIRS} is often misunderstood by some
4103 users that try to @emph{configure and build} subdirectories
4104 conditionally.  Here by configuring we mean creating the
4105 @file{Makefile} (it might also involve running a nested
4106 @command{configure} script: this is a costly operation that explains
4107 why people want to do it conditionally, but only the @file{Makefile}
4108 is relevant to the discussion).
4110 The above examples all assume that every @file{Makefile} is created,
4111 even in directories that are not going to be built.  The simple reason
4112 is that we want @samp{make dist} to distribute even the directories
4113 that are not being built (e.g., platform-dependent code), hence
4114 @file{make dist} must recurse into the subdirectory, hence this
4115 directory must be configured and appear in @code{DIST_SUBDIRS}.
4117 Building packages that do not configure every subdirectory is a tricky
4118 business, and we do not recommend it to the novice as it is easy to
4119 produce an incomplete tarball by mistake.  We will not discuss this
4120 topic in depth here, yet for the adventurous here are a few rules to
4121 remember.
4123 @cartouche
4124 @itemize
4125 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4127 It makes little sense to have a directory in @code{SUBDIRS} that
4128 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4129 which directories listed in the latter should be built.
4130 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4131 must be configured.
4133 I.e., the @file{Makefile} must exists or the recursive @command{make}
4134 rules will not be able to process the directory.
4135 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4137 So that the cleaning rule remove the generated @file{Makefile}s.
4138 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4139 lists all the directories that have been configured.
4140 @end itemize
4141 @end cartouche
4143 In order to prevent recursion in some non-configured directory you
4144 must therefore ensure that this directory does not appear in
4145 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4146 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4147 @code{DIST_SUBDIRS} explicitly, it will be default to
4148 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4149 = $(SUBDIRS)}.
4151 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4152 not be distributed unless you make other arrangements for this to
4153 happen (for instance, always running @samp{make dist} in a
4154 configuration where all directories are known to appear in
4155 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4156 distribute these directories).
4158 @cindex Subdirectories, not distributed
4159 In few packages, non-configured directories are not even expected to
4160 be distributed.  Although these packages do not require the
4161 aforementioned extra arrangements, there is another pitfall.  If the
4162 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4163 @command{automake} will make sure the directory exists.  Consequently
4164 @command{automake} cannot be run on such a distribution when one
4165 directory has been omitted.  One way to avoid this check is to use the
4166 @code{AC_SUBST} method to declare conditional directories; since
4167 @command{automake} does not know the values of @code{AC_SUBST}
4168 variables it cannot ensure the corresponding directory exist.
4170 @node Alternative
4171 @section An Alternative Approach to Subdirectories
4173 If you've ever read Peter Miller's excellent paper,
4174 @uref{http://www.pcug.org.au/~millerp/rmch/recu-make-cons-harm.html,
4175 Recursive Make Considered Harmful}, the preceding sections on the use of
4176 subdirectories will probably come as unwelcome advice.  For those who
4177 haven't read the paper, Miller's main thesis is that recursive
4178 @command{make} invocations are both slow and error-prone.
4180 Automake provides sufficient cross-directory support @footnote{We
4181 believe.  This work is new and there are probably warts.
4182 @xref{Introduction}, for information on reporting bugs.} to enable you
4183 to write a single @file{Makefile.am} for a complex multi-directory
4184 package.
4187 By default an installable file specified in a subdirectory will have its
4188 directory name stripped before installation.  For instance, in this
4189 example, the header file will be installed as
4190 @file{$(includedir)/stdio.h}:
4192 @example
4193 include_HEADERS = inc/stdio.h
4194 @end example
4196 @vindex nobase_
4197 @cindex @code{nobase_} prefix
4198 @cindex Path stripping, avoiding
4199 @cindex Avoiding path stripping
4201 However, the @samp{nobase_} prefix can be used to circumvent this path
4202 stripping.  In this example, the header file will be installed as
4203 @file{$(includedir)/sys/types.h}:
4205 @example
4206 nobase_include_HEADERS = sys/types.h
4207 @end example
4209 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4210 @cindex @code{dist_} and @code{nobase_}
4211 @cindex @code{nodist_} and @code{nobase_}
4212 @vindex dist_
4213 @vindex nodist_
4215 @samp{nobase_} should be specified first when used in conjunction with
4216 either @samp{dist_} or @samp{nodist_} (@pxref{Dist}).  For instance:
4218 @example
4219 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4220 @end example
4222 Finally, note that a variable using the @samp{nobase_} prefix can
4223 always be replaced by several variables, one for each destination
4224 directory (@pxref{Uniform}).  For instance, the last example could be
4225 rewritten as follows:
4227 @example
4228 imagesdir = $(pkgdatadir)/images
4229 soundsdir = $(pkgdatadir)/sounds
4230 dist_images_DATA = images/vortex.pgm
4231 dist_sounds_DATA = sounds/whirl.ogg
4232 @end example
4234 @noindent
4235 This latter syntax makes it possible to change one destination
4236 directory without changing the layout of the source tree.
4238 @node Subpackages
4239 @section Nesting Packages
4240 @cindex Nesting packages
4241 @cindex Subpackages
4242 @acindex AC_CONFIG_SUBDIRS
4243 @acindex AC_CONFIG_AUX_DIR
4246 In the GNU Build System, packages can be nested to arbitrary depth.
4247 This means that a package can embedded other packages with their own
4248 @file{configure}, @file{Makefile}s, etc.
4250 These other packages should just appear as subdirectories of their
4251 parent package.  They must be listed in @code{SUBDIRS} like other
4252 ordinary directories.  However the subpackage's @file{Makefile}s
4253 should be output by its own @file{configure} script, not by the
4254 parent's @file{configure}.  This is achieved using the
4255 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4256 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4257 autoconf, The Autoconf Manual}).
4259 Here is an example package for an @code{arm} program that links with
4260 an @code{hand} library that is a nested package in subdirectory
4261 @file{hand/}.
4263 @code{arm}'s @file{configure.ac}:
4265 @example
4266 AC_INIT([arm], [1.0])
4267 AC_CONFIG_AUX_DIR([.])
4268 AM_INIT_AUTOMAKE
4269 AC_PROG_CC
4270 AC_CONFIG_FILES([Makefile])
4271 # Call hand's ./configure script recursively.
4272 AC_CONFIG_SUBDIRS([hand])
4273 AC_OUTPUT
4274 @end example
4276 @code{arm}'s @file{Makefile.am}:
4278 @example
4279 # Build the library in the hand subdirectory first.
4280 SUBDIRS = hand
4282 # Include hand's header when compiling this directory.
4283 AM_CPPFLAGS = -I$(srcdir)/hand
4285 bin_PROGRAMS = arm
4286 arm_SOURCES = arm.c
4287 # link with the hand library.
4288 arm_LDADD = hand/libhand.a
4289 @end example
4291 Now here is @code{hand}'s @file{hand/configure.ac}:
4293 @example
4294 AC_INIT([hand], [1.2])
4295 AC_CONFIG_AUX_DIR([.])
4296 AM_INIT_AUTOMAKE
4297 AC_PROG_CC
4298 AC_PROG_RANLIB
4299 AC_CONFIG_FILES([Makefile])
4300 AC_OUTPUT
4301 @end example
4303 @noindent
4304 and its @file{hand/Makefile.am}:
4306 @example
4307 lib_LIBRARIES = libhand.a
4308 libhand_a_SOURCES = hand.c
4309 @end example
4311 When @samp{make dist} is run from the top-level directory it will
4312 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4313 code as well as the @file{hand} subdirectory.  This package can be
4314 built and installed like any ordinary package, with the usual
4315 @samp{./configure && make && make install} sequence (the @code{hand}
4316 subpackage will be built and installed by the process).
4318 When @samp{make dist} is run from the hand directory, it will create a
4319 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4320 to be embedded in another package, it can still be used separately.
4322 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4323 force Automake and Autoconf into search auxiliary script in the
4324 current directory.  For instance, this means that there will be two
4325 copies of @file{install-sh}: one in the top-level of the @code{arm}
4326 package, and another one in the @file{hand/} subdirectory for the
4327 @code{hand} package.
4329 The historical default is to search these auxiliary scripts in the
4330 immediate parent and grand-parent directories.  So if the
4331 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4332 @file{hand/configure.ac}, that subpackage would share the auxiliary
4333 script of the @code{arm} package.  This may looks like a gain in size
4334 (a few kilobytes), but it is actually a loss of modularity as the
4335 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4336 in the subdirectory will not work anymore).
4338 Packages that do not use Automake need more work to be integrated this
4339 way.  @xref{Third-Party Makefiles}.
4341 @node Programs
4342 @chapter Building Programs and Libraries
4344 A large part of Automake's functionality is dedicated to making it easy
4345 to build programs and libraries.
4347 @menu
4348 * A Program::                   Building a program
4349 * A Library::                   Building a library
4350 * A Shared Library::            Building a Libtool library
4351 * Program and Library Variables::  Variables controlling program and
4352                                 library builds
4353 * Default _SOURCES::            Default source files
4354 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4355 * Program variables::           Variables used when building a program
4356 * Yacc and Lex::                Yacc and Lex support
4357 * C++ Support::                 Compiling C++ sources
4358 * Objective C Support::         Compiling Objective C sources
4359 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4360 * Assembly Support::            Compiling assembly sources
4361 * Fortran 77 Support::          Compiling Fortran 77 sources
4362 * Fortran 9x Support::          Compiling Fortran 9x sources
4363 * Java Support::                Compiling Java sources
4364 * Support for Other Languages::  Compiling other languages
4365 * ANSI::                        Automatic de-ANSI-fication (obsolete)
4366 * Dependencies::                Automatic dependency tracking
4367 * EXEEXT::                      Support for executable extensions
4368 @end menu
4371 @node A Program
4372 @section Building a program
4374 In order to build a program, you need to tell Automake which sources
4375 are part of it, and which libraries it should be linked with.
4377 This section also covers conditional compilation of sources or
4378 programs.  Most of the comments about these also apply to libraries
4379 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4381 @menu
4382 * Program Sources::             Defining program sources
4383 * Linking::                     Linking with libraries or extra objects
4384 * Conditional Sources::         Handling conditional sources
4385 * Conditional Programs::        Building program conditionally
4386 @end menu
4388 @node Program Sources
4389 @subsection Defining program sources
4391 @cindex @code{PROGRAMS}, @code{bindir}
4392 @vindex _PROGRAMS
4393 @vindex bin_PROGRAMS
4394 @vindex sbin_PROGRAMS
4395 @vindex libexec_PROGRAMS
4396 @vindex pkglib_PROGRAMS
4397 @vindex noinst_PROGRAMS
4398 @vindex check_PROGRAMS
4400 In a directory containing source that gets built into a program (as
4401 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4402 Programs can be installed in @code{bindir}, @code{sbindir},
4403 @code{libexecdir}, @code{pkglibdir}, @code{pkglibexecdir}, or not at all
4404 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4405 which case the prefix is @samp{check_}.
4407 For instance:
4409 @example
4410 bin_PROGRAMS = hello
4411 @end example
4413 In this simple case, the resulting @file{Makefile.in} will contain code
4414 to generate a program named @code{hello}.
4416 Associated with each program are several assisting variables that are
4417 named after the program.  These variables are all optional, and have
4418 reasonable defaults.  Each variable, its use, and default is spelled out
4419 below; we use the ``hello'' example throughout.
4421 The variable @code{hello_SOURCES} is used to specify which source files
4422 get built into an executable:
4424 @example
4425 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4426 @end example
4428 This causes each mentioned @file{.c} file to be compiled into the
4429 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4431 @cindex @code{_SOURCES} primary, defined
4432 @cindex @code{SOURCES} primary, defined
4433 @cindex Primary variable, @code{SOURCES}
4434 @vindex _SOURCES
4436 If @code{hello_SOURCES} is not specified, then it defaults to the single
4437 file @file{hello.c} (@pxref{Default _SOURCES}).
4438 @vindex _SOURCES
4439 @vindex SOURCES
4441 Multiple programs can be built in a single directory.  Multiple programs
4442 can share a single source file, which must be listed in each
4443 @code{_SOURCES} definition.
4445 @cindex Header files in @code{_SOURCES}
4446 @cindex @code{_SOURCES} and header files
4448 Header files listed in a @code{_SOURCES} definition will be included in
4449 the distribution but otherwise ignored.  In case it isn't obvious, you
4450 should not include the header file generated by @file{configure} in a
4451 @code{_SOURCES} variable; this file should not be distributed.  Lex
4452 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4453 and Lex}.
4456 @node Linking
4457 @subsection Linking the program
4459 If you need to link against libraries that are not found by
4460 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4461 used to specify additional objects or libraries to link with; it is
4462 inappropriate for specifying specific linker flags, you should use
4463 @code{AM_LDFLAGS} for this purpose.
4464 @vindex LDADD
4465 @vindex AM_LDFLAGS
4467 @cindex @code{prog_LDADD}, defined
4469 Sometimes, multiple programs are built in one directory but do not share
4470 the same link-time requirements.  In this case, you can use the
4471 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4472 program as it appears in some @code{_PROGRAMS} variable, and usually
4473 written in lowercase) to override the global @code{LDADD}.  If this
4474 variable exists for a given program, then that program is not linked
4475 using @code{LDADD}.
4476 @vindex maude_LDADD
4478 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4479 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4480 built in the same directory, and has no such link requirement.  Also,
4481 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4482 is what cpio's @file{src/Makefile.am} looks like (abridged):
4484 @example
4485 bin_PROGRAMS = cpio pax $(MT)
4486 libexec_PROGRAMS = $(RMT)
4487 EXTRA_PROGRAMS = mt rmt
4489 LDADD = ../lib/libcpio.a $(INTLLIBS)
4490 rmt_LDADD =
4492 cpio_SOURCES = @dots{}
4493 pax_SOURCES = @dots{}
4494 mt_SOURCES = @dots{}
4495 rmt_SOURCES = @dots{}
4496 @end example
4498 @cindex @code{_LDFLAGS}, defined
4499 @vindex maude_LDFLAGS
4500 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4501 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4502 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4503 this purpose.
4505 @cindex @code{_DEPENDENCIES}, defined
4506 @vindex maude_DEPENDENCIES
4507 It is also occasionally useful to have a program depend on some other
4508 target that is not actually part of that program.  This can be done
4509 using the @code{@var{prog}_DEPENDENCIES} variable.  Each program
4510 depends on the contents of such a variable, but no further
4511 interpretation is done.
4513 Since these dependencies are associated to the link rule used to
4514 create the programs they should normally list files used by the link
4515 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4516 files.  In rare cases you may need to add other kinds of files such as
4517 linker scripts, but @emph{listing a source file in
4518 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4519 before all the components of a program are built, consider using the
4520 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4522 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4523 Automake.  The automatically-assigned value is the contents of
4524 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4525 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4526 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4527 @samp{$(ALLOCA)}; these are left because it is known that they will not
4528 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4529 generated.
4531 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4532 is useful.
4534 @cindex @code{LDADD} and @option{-l}
4535 @cindex @option{-l} and @code{LDADD}
4536 We recommend that you avoid using @option{-l} options in @code{LDADD}
4537 or @code{@var{prog}_LDADD} when referring to libraries built by your
4538 package.  Instead, write the file name of the library explicitly as in
4539 the above @code{cpio} example.  Use @option{-l} only to list
4540 third-party libraries.  If you follow this rule, the default value of
4541 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4542 omit the other ones.
4545 @node Conditional Sources
4546 @subsection Conditional compilation of sources
4548 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4549 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4550 @code{_SOURCES} variable.  The reason for this is a bit hard to
4551 explain, but suffice to say that it simply won't work.  Automake will
4552 give an error if you try to do this.
4554 Fortunately there are two other ways to achieve the same result.  One is
4555 to use configure substitutions in @code{_LDADD} variables, the other is
4556 to use an Automake conditional.
4558 @subsubsection Conditional compilation using @code{_LDADD} substitutions
4560 @cindex @code{EXTRA_prog_SOURCES}, defined
4562 Automake must know all the source files that could possibly go into a
4563 program, even if not all the files are built in every circumstance.  Any
4564 files that are only conditionally built should be listed in the
4565 appropriate @code{EXTRA_} variable.  For instance, if
4566 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4567 in @code{hello}, the @file{Makefile.am} would contain:
4569 @example
4570 bin_PROGRAMS = hello
4571 hello_SOURCES = hello-common.c
4572 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4573 hello_LDADD = $(HELLO_SYSTEM)
4574 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4575 @end example
4577 @noindent
4578 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4579 @file{configure.ac}:
4581 @example
4582 @dots{}
4583 case $host in
4584   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4585   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4586 esac
4587 AC_SUBST([HELLO_SYSTEM])
4588 @dots{}
4589 @end example
4591 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4592 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4593 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4594 built and linked in.
4596 @subsubsection Conditional compilation using Automake conditionals
4598 An often simpler way to compile source files conditionally is to use
4599 Automake conditionals.  For instance, you could use this
4600 @file{Makefile.am} construct to build the same @file{hello} example:
4602 @example
4603 bin_PROGRAMS = hello
4604 if LINUX
4605 hello_SOURCES = hello-linux.c hello-common.c
4606 else
4607 hello_SOURCES = hello-generic.c hello-common.c
4608 endif
4609 @end example
4611 In this case, @file{configure.ac} should setup the @code{LINUX}
4612 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4614 When using conditionals like this you don't need to use the
4615 @code{EXTRA_} variable, because Automake will examine the contents of
4616 each variable to construct the complete list of source files.
4618 If your program uses a lot of files, you will probably prefer a
4619 conditional @samp{+=}.
4621 @example
4622 bin_PROGRAMS = hello
4623 hello_SOURCES = hello-common.c
4624 if LINUX
4625 hello_SOURCES += hello-linux.c
4626 else
4627 hello_SOURCES += hello-generic.c
4628 endif
4629 @end example
4631 @node Conditional Programs
4632 @subsection Conditional compilation of programs
4633 @cindex Conditional programs
4634 @cindex Programs, conditional
4636 Sometimes it is useful to determine the programs that are to be built
4637 at configure time.  For instance, GNU @code{cpio} only builds
4638 @code{mt} and @code{rmt} under special circumstances.  The means to
4639 achieve conditional compilation of programs are the same you can use
4640 to compile source files conditionally: substitutions or conditionals.
4642 @subsubsection Conditional programs using @command{configure} substitutions
4644 @vindex EXTRA_PROGRAMS
4645 @cindex @code{EXTRA_PROGRAMS}, defined
4646 In this case, you must notify Automake of all the programs that can
4647 possibly be built, but at the same time cause the generated
4648 @file{Makefile.in} to use the programs specified by @command{configure}.
4649 This is done by having @command{configure} substitute values into each
4650 @code{_PROGRAMS} definition, while listing all optionally built programs
4651 in @code{EXTRA_PROGRAMS}.
4653 @example
4654 bin_PROGRAMS = cpio pax $(MT)
4655 libexec_PROGRAMS = $(RMT)
4656 EXTRA_PROGRAMS = mt rmt
4657 @end example
4659 As explained in @ref{EXEEXT}, Automake will rewrite
4660 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4661 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4662 Obviously it cannot rewrite values obtained at run-time through
4663 @command{configure} substitutions, therefore you should take care of
4664 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4665 ['mt$@{EXEEXT@}'])}.
4667 @subsubsection Conditional programs using Automake conditionals
4669 You can also use Automake conditionals (@pxref{Conditionals}) to
4670 select programs to be built.  In this case you don't have to worry
4671 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4673 @example
4674 bin_PROGRAMS = cpio pax
4675 if WANT_MT
4676   bin_PROGRAMS += mt
4677 endif
4678 if WANT_RMT
4679   libexec_PROGRAMS = rmt
4680 endif
4681 @end example
4684 @node A Library
4685 @section Building a library
4687 @cindex @code{_LIBRARIES} primary, defined
4688 @cindex @code{LIBRARIES} primary, defined
4689 @cindex Primary variable, @code{LIBRARIES}
4690 @vindex _LIBRARIES
4692 @vindex lib_LIBRARIES
4693 @vindex pkglib_LIBRARIES
4694 @vindex noinst_LIBRARIES
4696 Building a library is much like building a program.  In this case, the
4697 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
4698 @code{libdir} or @code{pkglibdir}.
4700 @xref{A Shared Library}, for information on how to build shared
4701 libraries using libtool and the @code{LTLIBRARIES} primary.
4703 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
4704 For instance, to create a library named @file{libcpio.a}, but not install
4705 it, you would write:
4707 @example
4708 noinst_LIBRARIES = libcpio.a
4709 libcpio_a_SOURCES = @dots{}
4710 @end example
4712 The sources that go into a library are determined exactly as they are
4713 for programs, via the @code{_SOURCES} variables.  Note that the library
4714 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
4715 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
4716 not @samp{libcpio.a_SOURCES}.
4718 @vindex maude_LIBADD
4719 Extra objects can be added to a library using the
4720 @code{@var{library}_LIBADD} variable.  This should be used for objects
4721 determined by @command{configure}.  Again from @code{cpio}:
4723 @example
4724 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4725 @end example
4727 In addition, sources for extra objects that will not exist until
4728 configure-time must be added to the @code{BUILT_SOURCES} variable
4729 (@pxref{Sources}).
4731 Building a static library is done by compiling all object files, then
4732 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
4733 library and the list of objects, and finally by calling
4734 @samp{$(RANLIB)} on that library.  You should call
4735 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
4736 @code{RANLIB} (Automake will complain otherwise).  @code{AR} and
4737 @code{ARFLAGS} default to @code{ar} and @code{cru} respectively; you
4738 can override these two variables my setting them in your
4739 @file{Makefile.am}, by @code{AC_SUBST}ing them from your
4740 @file{configure.ac}, or by defining a per-library @code{maude_AR}
4741 variable (@pxref{Program and Library Variables}).
4743 @cindex Empty libraries
4744 Be careful when selecting library components conditionally.  Because
4745 building an empty library is not portable, you should ensure that any
4746 library contains always at least one object.
4748 To use a static library when building a program, add it to
4749 @code{LDADD} for this program.  In the following example, the program
4750 @file{cpio} is statically linked with the library @file{libcpio.a}.
4752 @example
4753 noinst_LIBRARIES = libcpio.a
4754 libcpio_a_SOURCES = @dots{}
4756 bin_PROGRAMS = cpio
4757 cpio_SOURCES = cpio.c @dots{}
4758 cpio_LDADD = libcpio.a
4759 @end example
4762 @node A Shared Library
4763 @section Building a Shared Library
4765 @cindex Shared libraries, support for
4767 Building shared libraries portably is a relatively complex matter.
4768 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
4769 Libtool Manual}) was created to help build shared libraries in a
4770 platform-independent way.
4772 @menu
4773 * Libtool Concept::             Introducing Libtool
4774 * Libtool Libraries::           Declaring Libtool Libraries
4775 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
4776 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
4777 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
4778 * Libtool Modules::             Building Libtool Modules
4779 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
4780 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
4781 * Libtool Issues::              Common Issues Related to Libtool's Use
4782 @end menu
4784 @node Libtool Concept
4785 @subsection The Libtool Concept
4787 @cindex @command{libtool}, introduction
4788 @cindex libtool library, definition
4789 @cindex suffix @file{.la}, defined
4790 @cindex @file{.la} suffix, defined
4792 Libtool abstracts shared and static libraries into a unified concept
4793 henceforth called @dfn{libtool libraries}.  Libtool libraries are
4794 files using the @file{.la} suffix, and can designate a static library,
4795 a shared library, or maybe both.  Their exact nature cannot be
4796 determined until @file{./configure} is run: not all platforms support
4797 all kinds of libraries, and users can explicitly select which
4798 libraries should be built.  (However the package's maintainers can
4799 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
4800 macro, libtool, The Libtool Manual}.)
4802 @cindex suffix @file{.lo}, defined
4803 Because object files for shared and static libraries must be compiled
4804 differently, libtool is also used during compilation.  Object files
4805 built by libtool are called @dfn{libtool objects}: these are files
4806 using the @file{.lo} suffix.  Libtool libraries are built from these
4807 libtool objects.
4809 You should not assume anything about the structure of @file{.la} or
4810 @file{.lo} files and how libtool constructs them: this is libtool's
4811 concern, and the last thing one wants is to learn about libtool's
4812 guts.  However the existence of these files matters, because they are
4813 used as targets and dependencies in @file{Makefile}s rules when
4814 building libtool libraries.  There are situations where you may have
4815 to refer to these, for instance when expressing dependencies for
4816 building source files conditionally (@pxref{Conditional Libtool
4817 Sources}).
4819 @cindex @file{libltdl}, introduction
4821 People considering writing a plug-in system, with dynamically loaded
4822 modules, should look into @file{libltdl}: libtool's dlopening library
4823 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
4824 This offers a portable dlopening facility to load libtool libraries
4825 dynamically, and can also achieve static linking where unavoidable.
4827 Before we discuss how to use libtool with Automake in details, it
4828 should be noted that the libtool manual also has a section about how
4829 to use Automake with libtool (@pxref{Using Automake, , Using Automake
4830 with Libtool, libtool, The Libtool Manual}).
4832 @node Libtool Libraries
4833 @subsection Building Libtool Libraries
4835 @cindex @code{_LTLIBRARIES} primary, defined
4836 @cindex @code{LTLIBRARIES} primary, defined
4837 @cindex Primary variable, @code{LTLIBRARIES}
4838 @cindex Example of shared libraries
4839 @vindex lib_LTLIBRARIES
4840 @vindex pkglib_LTLIBRARIES
4841 @vindex _LTLIBRARIES
4843 Automake uses libtool to build libraries declared with the
4844 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
4845 list of libtool libraries to build.  For instance, to create a libtool
4846 library named @file{libgettext.la}, and install it in @code{libdir},
4847 write:
4849 @example
4850 lib_LTLIBRARIES = libgettext.la
4851 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
4852 @end example
4854 Automake predefines the variable @code{pkglibdir}, so you can use
4855 @code{pkglib_LTLIBRARIES} to install libraries in
4856 @samp{$(libdir)/@@PACKAGE@@/}.
4858 If @file{gettext.h} is a public header file that needs to be installed
4859 in order for people to use the library, it should be declared using a
4860 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
4861 Headers listed in the latter should be internal headers that are not
4862 part of the public interface.
4864 @example
4865 lib_LTLIBRARIES = libgettext.la
4866 libgettext_la_SOURCES = gettext.c @dots{}
4867 include_HEADERS = gettext.h @dots{}
4868 @end example
4870 A package can build and install such a library along with other
4871 programs that use it.  This dependency should be specified using
4872 @code{LDADD}.  The following example builds a program named
4873 @file{hello} that is linked with @file{libgettext.la}.
4875 @example
4876 lib_LTLIBRARIES = libgettext.la
4877 libgettext_la_SOURCES = gettext.c @dots{}
4879 bin_PROGRAMS = hello
4880 hello_SOURCES = hello.c @dots{}
4881 hello_LDADD = libgettext.la
4882 @end example
4884 @noindent
4885 Whether @file{hello} is statically or dynamically linked with
4886 @file{libgettext.la} is not yet known: this will depend on the
4887 configuration of libtool and the capabilities of the host.
4890 @node Conditional Libtool Libraries
4891 @subsection Building Libtool Libraries Conditionally
4892 @cindex libtool libraries, conditional
4893 @cindex conditional libtool libraries
4895 Like conditional programs (@pxref{Conditional Programs}), there are
4896 two main ways to build conditional libraries: using Automake
4897 conditionals or using Autoconf @code{AC_SUBST}itutions.
4899 The important implementation detail you have to be aware of is that
4900 the place where a library will be installed matters to libtool: it
4901 needs to be indicated @emph{at link-time} using the @option{-rpath}
4902 option.
4904 For libraries whose destination directory is known when Automake runs,
4905 Automake will automatically supply the appropriate @option{-rpath}
4906 option to libtool.  This is the case for libraries listed explicitly in
4907 some installable @code{_LTLIBRARIES} variables such as
4908 @code{lib_LTLIBRARIES}.
4910 However, for libraries determined at configure time (and thus
4911 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
4912 final installation directory.  For such libraries you must add the
4913 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
4914 hand.
4916 The examples below illustrate the differences between these two methods.
4918 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
4919 variable set at @file{./configure}-time to either @file{libfoo.la},
4920 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
4921 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
4922 relates to @file{libfoo.la} or @file{libbar.la} by the time it creates
4923 the link rule for these two libraries.  Therefore the @option{-rpath}
4924 argument must be explicitly supplied.
4926 @example
4927 EXTRA_LTLIBRARIES = libfoo.la libbar.la
4928 lib_LTLIBRARIES = $(WANTEDLIBS)
4929 libfoo_la_SOURCES = foo.c @dots{}
4930 libfoo_la_LDFLAGS = -rpath '$(libdir)'
4931 libbar_la_SOURCES = bar.c @dots{}
4932 libbar_la_LDFLAGS = -rpath '$(libdir)'
4933 @end example
4935 Here is how the same @file{Makefile.am} would look using Automake
4936 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
4937 Automake is able to compute the @option{-rpath} setting itself, because
4938 it's clear that both libraries will end up in @samp{$(libdir)} if they
4939 are installed.
4941 @example
4942 lib_LTLIBRARIES =
4943 if WANT_LIBFOO
4944 lib_LTLIBRARIES += libfoo.la
4945 endif
4946 if WANT_LIBBAR
4947 lib_LTLIBRARIES += libbar.la
4948 endif
4949 libfoo_la_SOURCES = foo.c @dots{}
4950 libbar_la_SOURCES = bar.c @dots{}
4951 @end example
4953 @node Conditional Libtool Sources
4954 @subsection Libtool Libraries with Conditional Sources
4956 Conditional compilation of sources in a library can be achieved in the
4957 same way as conditional compilation of sources in a program
4958 (@pxref{Conditional Sources}).  The only difference is that
4959 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
4960 should mention libtool objects (@file{.lo} files).
4962 So, to mimic the @file{hello} example from @ref{Conditional Sources},
4963 we could build a @file{libhello.la} library using either
4964 @file{hello-linux.c} or @file{hello-generic.c} with the following
4965 @file{Makefile.am}.
4967 @example
4968 lib_LTLIBRARIES = libhello.la
4969 libhello_la_SOURCES = hello-common.c
4970 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
4971 libhello_la_LIBADD = $(HELLO_SYSTEM)
4972 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
4973 @end example
4975 @noindent
4976 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
4977 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
4979 Or we could simply use an Automake conditional as follows.
4981 @example
4982 lib_LTLIBRARIES = libhello.la
4983 libhello_la_SOURCES = hello-common.c
4984 if LINUX
4985 libhello_la_SOURCES += hello-linux.c
4986 else
4987 libhello_la_SOURCES += hello-generic.c
4988 endif
4989 @end example
4991 @node Libtool Convenience Libraries
4992 @subsection Libtool Convenience Libraries
4993 @cindex convenience libraries, libtool
4994 @cindex libtool convenience libraries
4995 @vindex noinst_LTLIBRARIES
4996 @vindex check_LTLIBRARIES
4998 Sometimes you want to build libtool libraries that should not be
4999 installed.  These are called @dfn{libtool convenience libraries} and
5000 are typically used to encapsulate many sublibraries, later gathered
5001 into one big installed library.
5003 Libtool convenience libraries are declared by directory-less variables
5004 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5005 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5006 not need an @option{-rpath} flag at link time (actually this is the only
5007 difference).
5009 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5010 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5011 @samp{make check}.  Finally, libraries listed in
5012 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5013 rules to build them, but if the library does not appear as a Makefile
5014 dependency anywhere it won't be built (this is why
5015 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5017 Here is a sample setup merging libtool convenience libraries from
5018 subdirectories into one main @file{libtop.la} library.
5020 @example
5021 # -- Top-level Makefile.am --
5022 SUBDIRS = sub1 sub2 @dots{}
5023 lib_LTLIBRARIES = libtop.la
5024 libtop_la_SOURCES =
5025 libtop_la_LIBADD = \
5026   sub1/libsub1.la \
5027   sub2/libsub2.la \
5028   @dots{}
5030 # -- sub1/Makefile.am --
5031 noinst_LTLIBRARIES = libsub1.la
5032 libsub1_la_SOURCES = @dots{}
5034 # -- sub2/Makefile.am --
5035 # showing nested convenience libraries
5036 SUBDIRS = sub2.1 sub2.2 @dots{}
5037 noinst_LTLIBRARIES = libsub2.la
5038 libsub2_la_SOURCES =
5039 libsub2_la_LIBADD = \
5040   sub21/libsub21.la \
5041   sub22/libsub22.la \
5042   @dots{}
5043 @end example
5045 When using such setup, beware that @command{automake} will assume
5046 @file{libtop.la} is to be linked with the C linker.  This is because
5047 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5048 default language.  If @code{libtop_la_SOURCES} was not empty,
5049 @command{automake} would select the linker as explained in @ref{How
5050 the Linker is Chosen}.
5052 If one of the sublibraries contains non-C source, it is important that
5053 the appropriate linker be chosen.  One way to achieve this is to
5054 pretend that there is such a non-C file among the sources of the
5055 library, thus forcing @command{automake} to select the appropriate
5056 linker.  Here is the top-level @file{Makefile} of our example updated
5057 to force C++ linking.
5059 @example
5060 SUBDIRS = sub1 sub2 @dots{}
5061 lib_LTLIBRARIES = libtop.la
5062 libtop_la_SOURCES =
5063 # Dummy C++ source to cause C++ linking.
5064 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5065 libtop_la_LIBADD = \
5066   sub1/libsub1.la \
5067   sub2/libsub2.la \
5068   @dots{}
5069 @end example
5071 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5072 files that might be compiled (this is mostly useful when doing
5073 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5074 Libtool Sources}), and the @code{nodist_} prefix means the listed
5075 sources are not to be distributed (@pxref{Program and Library
5076 Variables}).  In effect the file @file{dummy.cxx} does not need to
5077 exist in the source tree.  Of course if you have some real source file
5078 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5079 @code{nodist_EXTRA_libtop_la_SOURCES}.
5082 @node Libtool Modules
5083 @subsection Libtool Modules
5084 @cindex modules, libtool
5085 @cindex libtool modules
5086 @cindex @option{-module}, libtool
5088 These are libtool libraries meant to be dlopened.  They are
5089 indicated to libtool by passing @option{-module} at link-time.
5091 @example
5092 pkglib_LTLIBRARIES = mymodule.la
5093 mymodule_la_SOURCES = doit.c
5094 mymodule_la_LDFLAGS = -module
5095 @end example
5097 Ordinarily, Automake requires that a library's name starts with
5098 @code{lib}.  However, when building a dynamically loadable module you
5099 might wish to use a "nonstandard" name.  Automake will not complain
5100 about such nonstandard name if it knows the library being built is a
5101 libtool module, i.e., if @option{-module} explicitly appears in the
5102 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5103 variable when no per-library @code{_LDFLAGS} variable is defined).
5105 As always, @code{AC_SUBST} variables are black boxes to Automake since
5106 their values are not yet known when @command{automake} is run.
5107 Therefore if @option{-module} is set via such a variable, Automake
5108 cannot notice it and will proceed as if the library was an ordinary
5109 libtool library, with strict naming.
5111 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5112 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5114 @node Libtool Flags
5115 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5116 @cindex @code{_LIBADD}, libtool
5117 @cindex @code{_LDFLAGS}, libtool
5118 @cindex @code{_LIBTOOLFLAGS}, libtool
5119 @vindex AM_LIBTOOLFLAGS
5120 @vindex LIBTOOLFLAGS
5121 @vindex maude_LIBTOOLFLAGS
5123 As shown in previous sections, the @samp{@var{library}_LIBADD}
5124 variable should be used to list extra libtool objects (@file{.lo}
5125 files) or libtool libraries (@file{.la}) to add to @var{library}.
5127 The @samp{@var{library}_LDFLAGS} variable is the place to list
5128 additional libtool linking flags, such as @option{-version-info},
5129 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5130 libtool, The Libtool Manual}.
5132 The @command{libtool} command has two kinds of options: mode-specific
5133 options and generic options.  Mode-specific options such as the
5134 aforementioned linking flags should be lumped with the other flags
5135 passed to the tool invoked by @command{libtool} (hence the use of
5136 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5137 options include @option{--tag=@var{TAG}} and @option{--silent}
5138 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5139 Libtool Manual} for more options) should appear before the mode
5140 selection on the command line; in @file{Makefile.am}s they should
5141 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5143 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, the global
5144 @code{AM_LIBTOOLFLAGS} variable is used instead.
5146 These flags are passed to libtool after the @option{--tag=@var{TAG}}
5147 option computed by Automake (if any), so
5148 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is the
5149 good place to override or supplement the @option{--tag=@var{TAG}}
5150 setting.
5152 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5153 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5154 Variables Ordering}.  It allows users to run @samp{make
5155 LIBTOOLFLAGS=--silent}, for instance.
5158 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5159 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5160 @cindex @code{LTLIBOBJS}, special handling
5161 @cindex @code{LIBOBJS}, and Libtool
5162 @cindex @code{LTALLOCA}, special handling
5163 @cindex @code{ALLOCA}, and Libtool
5164 @vindex LTLIBOBJS
5165 @vindex LIBOBJS
5166 @vindex LTALLOCA
5167 @vindex ALLOCA
5168 @acindex AC_LIBOBJ
5170 Where an ordinary library might include @samp{$(LIBOBJS)} or
5171 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5172 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5173 the object files that libtool operates on do not necessarily end in
5174 @file{.o}.
5176 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5177 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5178 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5180 @node Libtool Issues
5181 @subsection Common Issues Related to Libtool's Use
5183 @subsubsection @samp{required file `./ltmain.sh' not found}
5184 @cindex @file{ltmain.sh} not found
5185 @cindex @command{libtoolize}, no longer run by @command{automake}
5186 @cindex @command{libtoolize} and @command{autoreconf}
5187 @cindex @command{autoreconf} and @command{libtoolize}
5188 @cindex @file{bootstrap.sh} and @command{autoreconf}
5189 @cindex @file{autogen.sh} and @command{autoreconf}
5191 Libtool comes with a tool called @command{libtoolize} that will
5192 install libtool's supporting files into a package.  Running this
5193 command will install @file{ltmain.sh}.  You should execute it before
5194 @command{aclocal} and @command{automake}.
5196 People upgrading old packages to newer autotools are likely to face
5197 this issue because older Automake versions used to call
5198 @command{libtoolize}.  Therefore old build scripts do not call
5199 @command{libtoolize}.
5201 Since Automake 1.6, it has been decided that running
5202 @command{libtoolize} was none of Automake's business.  Instead, that
5203 functionality has been moved into the @command{autoreconf} command
5204 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5205 The Autoconf Manual}).  If you do not want to remember what to run and
5206 when, just learn the @command{autoreconf} command.  Hopefully,
5207 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5208 a call to @command{autoreconf} should also free you from any similar
5209 incompatible change in the future.
5211 @subsubsection Objects @samp{created with both libtool and without}
5213 Sometimes, the same source file is used both to build a libtool
5214 library and to build another non-libtool target (be it a program or
5215 another library).
5217 Let's consider the following @file{Makefile.am}.
5219 @example
5220 bin_PROGRAMS = prog
5221 prog_SOURCES = prog.c foo.c @dots{}
5223 lib_LTLIBRARIES = libfoo.la
5224 libfoo_la_SOURCES = foo.c @dots{}
5225 @end example
5227 @noindent
5228 (In this trivial case the issue could be avoided by linking
5229 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5230 @code{prog_SOURCES}.  But let's assume we really want to keep
5231 @file{prog} and @file{libfoo.la} separate.)
5233 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5234 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5235 that in the course of creating @file{foo.lo}, libtool may erase (or
5236 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5238 Therefore, when Automake detects this situation it will complain
5239 with a message such as
5240 @example
5241 object `foo.$(OBJEXT)' created both with libtool and without
5242 @end example
5244 A workaround for this issue is to ensure that these two objects get
5245 different basenames.  As explained in @ref{renamed objects}, this
5246 happens automatically when per-targets flags are used.
5248 @example
5249 bin_PROGRAMS = prog
5250 prog_SOURCES = prog.c foo.c @dots{}
5251 prog_CFLAGS = $(AM_CFLAGS)
5253 lib_LTLIBRARIES = libfoo.la
5254 libfoo_la_SOURCES = foo.c @dots{}
5255 @end example
5257 @noindent
5258 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5259 when the @code{prog_CFLAGS} is defined, it is used instead of
5260 @code{AM_CFLAGS}.  However as a side effect it will cause
5261 @file{prog.c} and @file{foo.c} to be compiled as
5262 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5263 the issue.
5265 @node Program and Library Variables
5266 @section Program and Library Variables
5268 Associated with each program are a collection of variables that can be
5269 used to modify how that program is built.  There is a similar list of
5270 such variables for each library.  The canonical name of the program (or
5271 library) is used as a base for naming these variables.
5273 In the list below, we use the name ``maude'' to refer to the program or
5274 library.  In your @file{Makefile.am} you would replace this with the
5275 canonical name of your program.  This list also refers to ``maude'' as a
5276 program, but in general the same rules apply for both static and dynamic
5277 libraries; the documentation below notes situations where programs and
5278 libraries differ.
5280 @vtable @code
5281 @item maude_SOURCES
5282 This variable, if it exists, lists all the source files that are
5283 compiled to build the program.  These files are added to the
5284 distribution by default.  When building the program, Automake will cause
5285 each source file to be compiled to a single @file{.o} file (or
5286 @file{.lo} when using libtool).  Normally these object files are named
5287 after the source file, but other factors can change this.  If a file in
5288 the @code{_SOURCES} variable has an unrecognized extension, Automake
5289 will do one of two things with it.  If a suffix rule exists for turning
5290 files with the unrecognized extension into @file{.o} files, then
5291 automake will treat this file as it will any other source file
5292 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5293 ignored as though it were a header file.
5295 The prefixes @code{dist_} and @code{nodist_} can be used to control
5296 whether files listed in a @code{_SOURCES} variable are distributed.
5297 @code{dist_} is redundant, as sources are distributed by default, but it
5298 can be specified for clarity if desired.
5300 It is possible to have both @code{dist_} and @code{nodist_} variants of
5301 a given @code{_SOURCES} variable at once; this lets you easily
5302 distribute some files and not others, for instance:
5304 @example
5305 nodist_maude_SOURCES = nodist.c
5306 dist_maude_SOURCES = dist-me.c
5307 @end example
5309 By default the output file (on Unix systems, the @file{.o} file) will
5310 be put into the current build directory.  However, if the option
5311 @option{subdir-objects} is in effect in the current directory then the
5312 @file{.o} file will be put into the subdirectory named after the
5313 source file.  For instance, with @option{subdir-objects} enabled,
5314 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5315 people prefer this mode of operation.  You can specify
5316 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5317 @cindex Subdirectory, objects in
5318 @cindex Objects in subdirectory
5321 @item EXTRA_maude_SOURCES
5322 Automake needs to know the list of files you intend to compile
5323 @emph{statically}.  For one thing, this is the only way Automake has of
5324 knowing what sort of language support a given @file{Makefile.in}
5325 requires.  @footnote{There are other, more obscure reasons for
5326 this limitation as well.}  This means that, for example, you can't put a
5327 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5328 variable.  If you intend to conditionally compile source files and use
5329 @file{configure} to substitute the appropriate object names into, e.g.,
5330 @code{_LDADD} (see below), then you should list the corresponding source
5331 files in the @code{EXTRA_} variable.
5333 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5334 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5335 sources that may need to be built, but should not be distributed.
5337 @item maude_AR
5338 A static library is created by default by invoking @samp{$(AR)
5339 $(ARFLAGS)} followed by the name of the library and then the objects
5340 being put into the library.  You can override this by setting the
5341 @code{_AR} variable.  This is usually used with C++; some C++
5342 compilers require a special invocation in order to instantiate all the
5343 templates that should go into a library.  For instance, the SGI C++
5344 compiler likes this variable set like so:
5345 @example
5346 libmaude_a_AR = $(CXX) -ar -o
5347 @end example
5349 @item maude_LIBADD
5350 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5351 variable.  For instance, this should be used for objects determined by
5352 @command{configure} (@pxref{A Library}).
5354 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5355 to other libtool libraries.
5357 @item maude_LDADD
5358 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5359 @file{*.la}) can be added to a @emph{program} by listing them in the
5360 @code{_LDADD} variable.  For instance, this should be used for objects
5361 determined by @command{configure} (@pxref{Linking}).
5363 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5364 program-specific linker flags (except for @option{-l}, @option{-L},
5365 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5366 for this purpose.
5368 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5369 could link your program against the X libraries like so:
5371 @example
5372 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5373 @end example
5375 We recommend that you use @option{-l} and @option{-L} only when
5376 referring to third-party libraries, and give the explicit file names
5377 of any library built by your package.  Doing so will ensure that
5378 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5380 @item maude_LDFLAGS
5381 This variable is used to pass extra flags to the link step of a program
5382 or a shared library.  It overrides the global @code{AM_LDFLAGS} variable.
5384 @item maude_LIBTOOLFLAGS
5385 This variable is used to pass extra options to @command{libtool}.
5386 It overrides the global @code{AM_LIBTOOLFLAGS} variable.
5387 These options are output before @command{libtool}'s @option{--mode=@var{MODE}}
5388 option, so they should not be mode-specific options (those belong to
5389 the compiler or linker flags).  @xref{Libtool Flags}.
5391 @item maude_DEPENDENCIES
5392 It is also occasionally useful to have a target (program or library)
5393 depend on some other file that is not actually part of that target.
5394 This can be done using the @code{_DEPENDENCIES} variable.  Each
5395 targets depends on the contents of such a variable, but no further
5396 interpretation is done.
5398 Since these dependencies are associated to the link rule used to
5399 create the programs they should normally list files used by the link
5400 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5401 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5402 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5403 may need to add other kinds of files such as linker scripts, but
5404 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5405 some source file needs to be built before all the components of a
5406 program are built, consider using the @code{BUILT_SOURCES} variable
5407 (@pxref{Sources}).
5409 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5410 The automatically-assigned value is the contents of @code{_LDADD} or
5411 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5412 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5413 substitutions that are left in are only @samp{$(LIBOBJS)} and
5414 @samp{$(ALLOCA)}; these are left because it is known that they will not
5415 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5417 @code{_DEPENDENCIES} is more likely used to perform conditional
5418 compilation using an @code{AC_SUBST} variable that contains a list of
5419 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5420 Sources}.
5422 @item maude_LINK
5423 You can override the linker on a per-program basis.  By default the
5424 linker is chosen according to the languages used by the program.  For
5425 instance, a program that includes C++ source code would use the C++
5426 compiler to link.  The @code{_LINK} variable must hold the name of a
5427 command that can be passed all the @file{.o} file names as arguments.
5428 Note that the name of the underlying program is @emph{not} passed to
5429 @code{_LINK}; typically one uses @samp{$@@}:
5431 @example
5432 maude_LINK = $(CCLD) -magic -o $@@
5433 @end example
5435 @item maude_CCASFLAGS
5436 @itemx maude_CFLAGS
5437 @itemx maude_CPPFLAGS
5438 @itemx maude_CXXFLAGS
5439 @itemx maude_FFLAGS
5440 @itemx maude_GCJFLAGS
5441 @itemx maude_LFLAGS
5442 @itemx maude_OBJCFLAGS
5443 @itemx maude_RFLAGS
5444 @itemx maude_UPCFLAGS
5445 @itemx maude_YFLAGS
5446 @cindex per-target compilation flags, defined
5447 Automake allows you to set compilation flags on a per-program (or
5448 per-library) basis.  A single source file can be included in several
5449 programs, and it will potentially be compiled with different flags for
5450 each program.  This works for any language directly supported by
5451 Automake.  These @dfn{per-target compilation flags} are
5452 @samp{_CCASFLAGS},
5453 @samp{_CFLAGS},
5454 @samp{_CPPFLAGS},
5455 @samp{_CXXFLAGS},
5456 @samp{_FFLAGS},
5457 @samp{_GCJFLAGS},
5458 @samp{_LFLAGS},
5459 @samp{_OBJCFLAGS},
5460 @samp{_RFLAGS},
5461 @samp{_UPCFLAGS}, and
5462 @samp{_YFLAGS}.
5464 When using a per-target compilation flag, Automake will choose a
5465 different name for the intermediate object files.  Ordinarily a file
5466 like @file{sample.c} will be compiled to produce @file{sample.o}.
5467 However, if the program's @code{_CFLAGS} variable is set, then the
5468 object file will be named, for instance, @file{maude-sample.o}.  (See
5469 also @ref{renamed objects}.)  The use of per-target compilation flags
5470 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5471 from @file{configure.ac}.
5473 In compilations with per-target flags, the ordinary @samp{AM_} form of
5474 the flags variable is @emph{not} automatically included in the
5475 compilation (however, the user form of the variable @emph{is} included).
5476 So for instance, if you want the hypothetical @file{maude} compilations
5477 to also use the value of @code{AM_CFLAGS}, you would need to write:
5479 @example
5480 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5481 @end example
5483 @xref{Flag Variables Ordering}, for more discussion about the
5484 interaction between user variables, @samp{AM_} shadow variables, and
5485 per-target variables.
5487 @item maude_SHORTNAME
5488 On some platforms the allowable file names are very short.  In order to
5489 support these systems and per-target compilation flags at the same
5490 time, Automake allows you to set a ``short name'' that will influence
5491 how intermediate object files are named.  For instance, in the following
5492 example,
5494 @example
5495 bin_PROGRAMS = maude
5496 maude_CPPFLAGS = -DSOMEFLAG
5497 maude_SHORTNAME = m
5498 maude_SOURCES = sample.c @dots{}
5499 @end example
5501 @noindent
5502 the object file would be named @file{m-sample.o} rather than
5503 @file{maude-sample.o}.
5505 This facility is rarely needed in practice,
5506 and we recommend avoiding it until you find it is required.
5507 @end vtable
5509 @node Default _SOURCES
5510 @section Default @code{_SOURCES}
5512 @vindex _SOURCES
5513 @vindex SOURCES
5514 @cindex @code{_SOURCES}, default
5515 @cindex default @code{_SOURCES}
5517 @code{_SOURCES} variables are used to specify source files of programs
5518 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5519 libraries (@pxref{A Shared Library}).
5521 When no such variable is specified for a target, Automake will define
5522 one itself.  The default is to compile a single C file whose base name
5523 is the name of the target itself, with any extension replaced by
5524 @file{.c}.  (Defaulting to C is terrible but we are stuck with it for
5525 historical reasons.)
5527 For example if you have the following somewhere in your
5528 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5530 @example
5531 lib_LIBRARIES = libfoo.a sub/libc++.a
5532 @end example
5534 @noindent
5535 @file{libfoo.a} will be built using a default source file named
5536 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5537 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5538 would be built from @file{sub_libc___a.c}, i.e., the default source
5539 was the canonized name of the target, with @file{.c} appended.
5540 We believe the new behavior is more sensible, but for backward
5541 compatibility automake will use the old name if a file or a rule
5542 with that name exist.)
5544 @cindex @code{check_PROGRAMS} example
5545 @vindex check_PROGRAMS
5546 Default sources are mainly useful in test suites, when building many
5547 tests programs each from a single source.  For instance, in
5549 @example
5550 check_PROGRAMS = test1 test2 test3
5551 @end example
5553 @noindent
5554 @file{test1}, @file{test2}, and @file{test3} will be built
5555 from @file{test1.c}, @file{test2.c}, and @file{test3.c}.
5557 @cindex Libtool modules, default source example
5558 @cindex default source, Libtool modules example
5559 Another case where is this convenient is building many Libtool modules
5560 (@file{moduleN.la}), each defined in its own file (@file{moduleN.c}).
5562 @example
5563 AM_LDFLAGS = -module
5564 lib_LTLIBRARIES = module1.la module2.la module3.la
5565 @end example
5567 @cindex empty @code{_SOURCES}
5568 @cindex @code{_SOURCES}, empty
5569 Finally, there is one situation where this default source computation
5570 needs to be avoided: when a target should not be built from sources.
5571 We already saw such an example in @ref{true}; this happens when all
5572 the constituents of a target have already been compiled and need just
5573 to be combined using a @code{_LDADD} variable.  Then it is necessary
5574 to define an empty @code{_SOURCES} variable, so that automake does not
5575 compute a default.
5577 @example
5578 bin_PROGRAMS = target
5579 target_SOURCES =
5580 target_LDADD = libmain.a libmisc.a
5581 @end example
5583 @node LIBOBJS
5584 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5586 @cindex @code{LIBOBJS}, example
5587 @cindex @code{ALLOCA}, example
5588 @cindex @code{LIBOBJS}, special handling
5589 @cindex @code{ALLOCA}, special handling
5590 @vindex LTLIBOBJS
5591 @vindex LIBOBJS
5592 @vindex LTALLOCA
5593 @vindex ALLOCA
5595 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5596 files that should be compiled into the project to provide an
5597 implementation for functions that are missing or broken on the host
5598 system.  They are substituted by @file{configure}.
5600 @acindex AC_LIBOBJ
5602 These variables are defined by Autoconf macros such as
5603 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5604 Generic Function Checks, autoconf, The Autoconf Manual}), or
5605 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5606 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5607 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5608 populate @samp{$(LIBOBJS)}.
5610 @acindex AC_LIBSOURCE
5612 Using these variables is very similar to doing conditional compilation
5613 using @code{AC_SUBST} variables, as described in @ref{Conditional
5614 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5615 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5616 variable, or to the @samp{*_LIBADD} variable when building a library.
5617 However there is no need to list the corresponding sources in
5618 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5619 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5620 dependencies, and it will discover the list of corresponding source
5621 files automatically (by tracing the invocations of the
5622 @code{AC_LIBSOURCE} Autoconf macros).
5624 These variables are usually used to build a portability library that
5625 is linked with all the programs of the project.  We now review a
5626 sample setup.  First, @file{configure.ac} contains some checks that
5627 affect either @code{LIBOBJS} or @code{ALLOCA}.
5629 @example
5630 # configure.ac
5631 @dots{}
5632 AC_CONFIG_LIBOBJ_DIR([lib])
5633 @dots{}
5634 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5635 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5636 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5637 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5638 @dots{}
5639 AC_CONFIG_FILES([
5640   lib/Makefile
5641   src/Makefile
5643 AC_OUTPUT
5644 @end example
5646 @acindex AC_CONFIG_LIBOBJ_DIR
5648 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
5649 of these object files are to be found in the @file{lib/} directory.
5650 Automake can also use this information, otherwise it expects the
5651 source files are to be in the directory where the @samp{$(LIBOBJS)}
5652 and @samp{$(ALLOCA)} variables are used.
5654 The @file{lib/} directory should therefore contain @file{malloc.c},
5655 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
5656 @file{Makefile.am}:
5658 @example
5659 # lib/Makefile.am
5661 noinst_LIBRARIES = libcompat.a
5662 libcompat_a_SOURCES =
5663 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5664 @end example
5666 The library can have any name, of course, and anyway it is not going
5667 to be installed: it just holds the replacement versions of the missing
5668 or broken functions so we can later link them in.  In many projects
5669 also include extra functions, specific to the project, in that
5670 library: they are simply added on the @code{_SOURCES} line.
5672 @cindex Empty libraries and @samp{$(LIBOBJS)}
5673 @cindex @samp{$(LIBOBJS)} and empty libraries
5674 There is a small trap here, though: @samp{$(LIBOBJS)} and
5675 @samp{$(ALLOCA)} might be empty, and building an empty library is not
5676 portable.  You should ensure that there is always something to put in
5677 @file{libcompat.a}.  Most projects will also add some utility
5678 functions in that directory, and list them in
5679 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
5680 be empty.
5682 Finally here is how this library could be used from the @file{src/}
5683 directory.
5685 @example
5686 # src/Makefile.am
5688 # Link all programs in this directory with libcompat.a
5689 LDADD = ../lib/libcompat.a
5691 bin_PROGRAMS = tool1 tool2 @dots{}
5692 tool1_SOURCES = @dots{}
5693 tool2_SOURCES = @dots{}
5694 @end example
5696 When option @option{subdir-objects} is not used, as in the above
5697 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
5698 be used in the directory where their sources lie.  E.g., here it would
5699 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
5700 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
5701 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
5702 in other directories.  For instance @file{src/Makefile.am} could be
5703 changed as follows.
5705 @example
5706 # src/Makefile.am
5708 AUTOMAKE_OPTIONS = subdir-objects
5709 LDADD = $(LIBOBJS) $(ALLOCA)
5711 bin_PROGRAMS = tool1 tool2 @dots{}
5712 tool1_SOURCES = @dots{}
5713 tool2_SOURCES = @dots{}
5714 @end example
5716 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
5717 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
5718 Libtool libraries (where the expected object extension is @file{.lo}):
5719 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
5721 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
5722 be defined by hand (as in the past), however at the time of writing
5723 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
5724 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
5725 autoconf, The Autoconf Manual}.
5728 @node Program variables
5729 @section Variables used when building a program
5731 Occasionally it is useful to know which @file{Makefile} variables
5732 Automake uses for compilations; for instance, you might need to do your
5733 own compilation in some special cases.
5735 Some variables are inherited from Autoconf; these are @code{CC},
5736 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
5737 @code{LIBS}.
5738 @vindex CC
5739 @vindex CFLAGS
5740 @vindex CPPFLAGS
5741 @vindex DEFS
5742 @vindex LDFLAGS
5743 @vindex LIBS
5745 There are some additional variables that Automake defines on its own:
5747 @vtable @code
5748 @item AM_CPPFLAGS
5749 The contents of this variable are passed to every compilation that invokes
5750 the C preprocessor; it is a list of arguments to the preprocessor.  For
5751 instance, @option{-I} and @option{-D} options should be listed here.
5753 Automake already provides some @option{-I} options automatically.  In
5754 particular it generates @samp{-I$(srcdir)}, @samp{-I.}, and a
5755 @option{-I} pointing to the directory holding @file{config.h} (if
5756 you've used @code{AC_CONFIG_HEADERS} or @code{AM_CONFIG_HEADER}).  You
5757 can disable the default @option{-I} options using the
5758 @option{nostdinc} option.
5760 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
5761 per-library) @code{_CPPFLAGS} variable if it is defined.
5763 @item INCLUDES
5764 This does the same job as @code{AM_CPPFLAGS} (or any per-target
5765 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
5766 same functionality.  This variable is deprecated; we suggest using
5767 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
5769 @item AM_CFLAGS
5770 This is the variable the @file{Makefile.am} author can use to pass
5771 in additional C compiler flags.  It is more fully documented elsewhere.
5772 In some situations, this is not used, in preference to the
5773 per-executable (or per-library) @code{_CFLAGS}.
5775 @item COMPILE
5776 This is the command used to actually compile a C source file.  The
5777 file name is appended to form the complete command line.
5779 @item AM_LDFLAGS
5780 This is the variable the @file{Makefile.am} author can use to pass
5781 in additional linker flags.  In some situations, this is not used, in
5782 preference to the per-executable (or per-library) @code{_LDFLAGS}.
5784 @item LINK
5785 This is the command used to actually link a C program.  It already
5786 includes @samp{-o $@@} and the usual variable references (for instance,
5787 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
5788 and libraries to link in.
5789 @end vtable
5792 @node Yacc and Lex
5793 @section Yacc and Lex support
5795 Automake has somewhat idiosyncratic support for Yacc and Lex.
5797 Automake assumes that the @file{.c} file generated by @command{yacc}
5798 (or @command{lex}) should be named using the basename of the input
5799 file.  That is, for a yacc source file @file{foo.y}, Automake will
5800 cause the intermediate file to be named @file{foo.c} (as opposed to
5801 @file{y.tab.c}, which is more traditional).
5803 The extension of a yacc source file is used to determine the extension
5804 of the resulting C or C++ file.  Files with the extension @file{.y}
5805 will be turned into @file{.c} files; likewise, @file{.yy} will become
5806 @file{.cc}; @file{.y++}, @file{c++}; @file{.yxx}, @file{.cxx}; and
5807 @file{.ypp}, @file{.cpp}.
5809 Likewise, lex source files can be used to generate C or C++; the
5810 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
5811 @file{.lpp} are recognized.
5813 You should never explicitly mention the intermediate (C or C++) file
5814 in any @code{SOURCES} variable; only list the source file.
5816 The intermediate files generated by @command{yacc} (or @command{lex})
5817 will be included in any distribution that is made.  That way the user
5818 doesn't need to have @command{yacc} or @command{lex}.
5820 If a @command{yacc} source file is seen, then your @file{configure.ac} must
5821 define the variable @code{YACC}.  This is most easily done by invoking
5822 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
5823 Program Checks, autoconf, The Autoconf Manual}).
5825 @vindex YFLAGS
5826 @vindex AM_YFLAGS
5827 When @code{yacc} is invoked, it is passed @code{YFLAGS} and
5828 @code{AM_YFLAGS}.  The former is a user variable and the latter is
5829 intended for the @file{Makefile.am} author.
5831 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
5832 @command{yacc}.  Automake knows what this means and will automatically
5833 adjust its rules to update and distribute the header file built by
5834 @samp{yacc -d}.  What Automake cannot guess, though, is where this
5835 header will be used: it is up to you to ensure the header gets built
5836 before it is first used.  Typically this is necessary in order for
5837 dependency tracking to work when the header is included by another
5838 file.  The common solution is listing the header file in
5839 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
5841 @example
5842 BUILT_SOURCES = parser.h
5843 AM_YFLAGS = -d
5844 bin_PROGRAMS = foo
5845 foo_SOURCES = @dots{} parser.y @dots{}
5846 @end example
5848 If a @command{lex} source file is seen, then your @file{configure.ac}
5849 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
5850 to do this (@pxref{Particular Programs, , Particular Program Checks,
5851 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
5852 (@pxref{Macros}) is recommended.
5854 @vindex LFLAGS
5855 @vindex AM_LFLAGS
5856 When @command{lex} is invoked, it is passed @code{LFLAGS} and
5857 @code{AM_LFLAGS}.  The former is a user variable and the latter is
5858 intended for the @file{Makefile.am} author.
5860 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
5861 rebuild rule for distributed Yacc and Lex sources are only used when
5862 @code{maintainer-mode} is enabled, or when the files have been erased.
5864 @cindex @command{ylwrap}
5865 @cindex @command{yacc}, multiple parsers
5866 @cindex Multiple @command{yacc} parsers
5867 @cindex Multiple @command{lex} lexers
5868 @cindex @command{lex}, multiple lexers
5870 When @command{lex} or @command{yacc} sources are used, @code{automake
5871 -i} automatically installs an auxiliary program called
5872 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
5873 program is used by the build rules to rename the output of these
5874 tools, and makes it possible to include multiple @command{yacc} (or
5875 @command{lex}) source files in a single directory.  (This is necessary
5876 because yacc's output file name is fixed, and a parallel make could
5877 conceivably invoke more than one instance of @command{yacc}
5878 simultaneously.)
5880 For @command{yacc}, simply managing locking is insufficient.  The output of
5881 @command{yacc} always uses the same symbol names internally, so it isn't
5882 possible to link two @command{yacc} parsers into the same executable.
5884 We recommend using the following renaming hack used in @command{gdb}:
5885 @example
5886 #define yymaxdepth c_maxdepth
5887 #define yyparse c_parse
5888 #define yylex   c_lex
5889 #define yyerror c_error
5890 #define yylval  c_lval
5891 #define yychar  c_char
5892 #define yydebug c_debug
5893 #define yypact  c_pact
5894 #define yyr1    c_r1
5895 #define yyr2    c_r2
5896 #define yydef   c_def
5897 #define yychk   c_chk
5898 #define yypgo   c_pgo
5899 #define yyact   c_act
5900 #define yyexca  c_exca
5901 #define yyerrflag c_errflag
5902 #define yynerrs c_nerrs
5903 #define yyps    c_ps
5904 #define yypv    c_pv
5905 #define yys     c_s
5906 #define yy_yys  c_yys
5907 #define yystate c_state
5908 #define yytmp   c_tmp
5909 #define yyv     c_v
5910 #define yy_yyv  c_yyv
5911 #define yyval   c_val
5912 #define yylloc  c_lloc
5913 #define yyreds  c_reds
5914 #define yytoks  c_toks
5915 #define yylhs   c_yylhs
5916 #define yylen   c_yylen
5917 #define yydefred c_yydefred
5918 #define yydgoto c_yydgoto
5919 #define yysindex c_yysindex
5920 #define yyrindex c_yyrindex
5921 #define yygindex c_yygindex
5922 #define yytable  c_yytable
5923 #define yycheck  c_yycheck
5924 #define yyname   c_yyname
5925 #define yyrule   c_yyrule
5926 @end example
5928 For each define, replace the @samp{c_} prefix with whatever you like.
5929 These defines work for @command{bison}, @command{byacc}, and
5930 traditional @code{yacc}s.  If you find a parser generator that uses a
5931 symbol not covered here, please report the new name so it can be added
5932 to the list.
5935 @node C++ Support
5936 @section C++ Support
5938 @cindex C++ support
5939 @cindex Support for C++
5941 Automake includes full support for C++.
5943 Any package including C++ code must define the output variable
5944 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
5945 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
5946 Program Checks, autoconf, The Autoconf Manual}).
5948 A few additional variables are defined when a C++ source file is seen:
5950 @vtable @code
5951 @item CXX
5952 The name of the C++ compiler.
5954 @item CXXFLAGS
5955 Any flags to pass to the C++ compiler.
5957 @item AM_CXXFLAGS
5958 The maintainer's variant of @code{CXXFLAGS}.
5960 @item CXXCOMPILE
5961 The command used to actually compile a C++ source file.  The file name
5962 is appended to form the complete command line.
5964 @item CXXLINK
5965 The command used to actually link a C++ program.
5966 @end vtable
5969 @node Objective C Support
5970 @section Objective C Support
5972 @cindex Objective C support
5973 @cindex Support for Objective C
5975 Automake includes some support for Objective C.
5977 Any package including Objective C code must define the output variable
5978 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
5979 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
5980 Program Checks, autoconf, The Autoconf Manual}).
5982 A few additional variables are defined when an Objective C source file
5983 is seen:
5985 @vtable @code
5986 @item OBJC
5987 The name of the Objective C compiler.
5989 @item OBJCFLAGS
5990 Any flags to pass to the Objective C compiler.
5992 @item AM_OBJCFLAGS
5993 The maintainer's variant of @code{OBJCFLAGS}.
5995 @item OBJCCOMPILE
5996 The command used to actually compile a Objective C source file.  The
5997 file name is appended to form the complete command line.
5999 @item OBJCLINK
6000 The command used to actually link a Objective C program.
6001 @end vtable
6004 @node Unified Parallel C Support
6005 @section Unified Parallel C Support
6007 @cindex Unified Parallel C support
6008 @cindex Support for Unified Parallel C
6010 Automake includes some support for Unified Parallel C.
6012 Any package including Unified Parallel C code must define the output
6013 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6014 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public macros}).
6016 A few additional variables are defined when an Unified Parallel C
6017 source file is seen:
6019 @vtable @code
6020 @item UPC
6021 The name of the Unified Parallel C compiler.
6023 @item UPCFLAGS
6024 Any flags to pass to the Unified Parallel C compiler.
6026 @item AM_UPCFLAGS
6027 The maintainer's variant of @code{UPCFLAGS}.
6029 @item UPCCOMPILE
6030 The command used to actually compile a Unified Parallel C source file.
6031 The file name is appended to form the complete command line.
6033 @item UPCLINK
6034 The command used to actually link a Unified Parallel C program.
6035 @end vtable
6038 @node Assembly Support
6039 @section Assembly Support
6041 Automake includes some support for assembly code.  There are two forms
6042 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6043 (@file{*.S}).
6045 @vindex CCAS
6046 @vindex CCASFLAGS
6047 @vindex CPPFLAGS
6048 @vindex AM_CCASFLAGS
6049 @vindex AM_CPPFLAGS
6050 The variable @code{CCAS} holds the name of the compiler used to build
6051 assembly code.  This compiler must work a bit like a C compiler; in
6052 particular it must accept @option{-c} and @option{-o}.  The values of
6053 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6054 definition) is passed to the compilation.  For preprocessed files,
6055 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6056 and @code{AM_CPPFLAGS} are also used.
6058 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6059 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6060 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6061 flags), but you are free to define these variables by other means.
6063 Only the suffixes @file{.s} and @file{.S} are recognized by
6064 @command{automake} as being files containing assembly code.
6067 @node Fortran 77 Support
6068 @comment  node-name,  next,  previous,  up
6069 @section Fortran 77 Support
6071 @cindex Fortran 77 support
6072 @cindex Support for Fortran 77
6074 Automake includes full support for Fortran 77.
6076 Any package including Fortran 77 code must define the output variable
6077 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6078 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6079 Program Checks, autoconf, The Autoconf Manual}).
6081 A few additional variables are defined when a Fortran 77 source file is
6082 seen:
6084 @vtable @code
6086 @item F77
6087 The name of the Fortran 77 compiler.
6089 @item FFLAGS
6090 Any flags to pass to the Fortran 77 compiler.
6092 @item AM_FFLAGS
6093 The maintainer's variant of @code{FFLAGS}.
6095 @item RFLAGS
6096 Any flags to pass to the Ratfor compiler.
6098 @item AM_RFLAGS
6099 The maintainer's variant of @code{RFLAGS}.
6101 @item F77COMPILE
6102 The command used to actually compile a Fortran 77 source file.  The file
6103 name is appended to form the complete command line.
6105 @item FLINK
6106 The command used to actually link a pure Fortran 77 program or shared
6107 library.
6109 @end vtable
6111 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6112 addition to compiling them@footnote{Much, if not most, of the
6113 information in the following sections pertaining to preprocessing
6114 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6115 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6116 also contains some support for creating programs and shared libraries
6117 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6118 Fortran 77 With C and C++}).
6120 These issues are covered in the following sections.
6122 @menu
6123 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6124 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6125 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6126 @end menu
6129 @node Preprocessing Fortran 77
6130 @comment  node-name,  next,  previous,  up
6131 @subsection Preprocessing Fortran 77
6133 @cindex Preprocessing Fortran 77
6134 @cindex Fortran 77, Preprocessing
6135 @cindex Ratfor programs
6137 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6138 rule runs just the preprocessor to convert a preprocessable Fortran 77
6139 or Ratfor source file into a strict Fortran 77 source file.  The precise
6140 command used is as follows:
6142 @table @file
6144 @item .F
6145 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6146 $(AM_FFLAGS) $(FFLAGS)}
6148 @item .r
6149 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6151 @end table
6154 @node Compiling Fortran 77 Files
6155 @comment  node-name,  next,  previous,  up
6156 @subsection Compiling Fortran 77 Files
6158 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6159 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6160 is as follows:
6162 @table @file
6164 @item .f
6165 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6167 @item .F
6168 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6169 $(AM_FFLAGS) $(FFLAGS)}
6171 @item .r
6172 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6174 @end table
6177 @node Mixing Fortran 77 With C and C++
6178 @comment  node-name,  next,  previous,  up
6179 @subsection Mixing Fortran 77 With C and C++
6181 @cindex Fortran 77, mixing with C and C++
6182 @cindex Mixing Fortran 77 with C and C++
6183 @cindex Linking Fortran 77 with C and C++
6184 @cindex cfortran
6185 @cindex Mixing Fortran 77 with C and/or C++
6187 Automake currently provides @emph{limited} support for creating programs
6188 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6189 However, there are many other issues related to mixing Fortran 77 with
6190 other languages that are @emph{not} (currently) handled by Automake, but
6191 that are handled by other packages@footnote{For example,
6192 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6193 addresses all of these inter-language issues, and runs under nearly all
6194 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6195 @command{cfortran} is not yet Free Software, but it will be in the next
6196 major release.}.
6198 @page
6199 Automake can help in two ways:
6201 @enumerate
6202 @item
6203 Automatic selection of the linker depending on which combinations of
6204 source code.
6206 @item
6207 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6208 @option{-l}) to pass to the automatically selected linker in order to link
6209 in the appropriate Fortran 77 intrinsic and run-time libraries.
6211 @cindex @code{FLIBS}, defined
6212 @vindex FLIBS
6213 These extra Fortran 77 linker flags are supplied in the output variable
6214 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
6215 supplied with newer versions of Autoconf (Autoconf version 2.13 and
6216 later).  @xref{Fortran 77 Compiler Characteristics, , , autoconf, The
6217 Autoconf}.
6218 @end enumerate
6220 If Automake detects that a program or shared library (as mentioned in
6221 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6222 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6223 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6224 @file{configure.ac}, and that either @code{$(FLIBS)}
6225 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6226 (for shared libraries) variables.  It is the responsibility of the
6227 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6228 appears in the appropriate @code{_LDADD} or
6229 @code{_LIBADD} variable.
6231 @cindex Mixed language example
6232 @cindex Example, mixed language
6234 For example, consider the following @file{Makefile.am}:
6236 @example
6237 bin_PROGRAMS = foo
6238 foo_SOURCES  = main.cc foo.f
6239 foo_LDADD    = libfoo.la $(FLIBS)
6241 pkglib_LTLIBRARIES = libfoo.la
6242 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6243 libfoo_la_LIBADD   = $(FLIBS)
6244 @end example
6246 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6247 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6248 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6249 Automake would have issued a warning.
6252 @page
6253 @menu
6254 * How the Linker is Chosen::    Automatic linker selection
6255 @end menu
6257 @node How the Linker is Chosen
6258 @comment  node-name,  next,  previous,  up
6259 @subsubsection How the Linker is Chosen
6261 @cindex Automatic linker selection
6262 @cindex Selecting the linker automatically
6264 When a program or library mixes several languages, Automake choose the
6265 linker according to the following priorities.  (The names in
6266 parentheses are the variables containing the link command.)
6268 @enumerate
6269 @item
6270 @vindex GCJLINK
6271 Native Java (@code{GCJLINK})
6272 @item
6273 @vindex CXXLINK
6274 C++ (@code{CXXLINK})
6275 @item
6276 @vindex F77LINK
6277 Fortran 77 (@code{F77LINK})
6278 @item
6279 @vindex FCLINK
6280 Fortran (@code{FCLINK})
6281 @item
6282 @vindex OBJCLINK
6283 Objective C (@code{OBJCLINK})
6284 @item
6285 @vindex UPCLINK
6286 Unified Parallel C (@code{UPCLINK})
6287 @item
6288 @vindex LINK
6289 C (@code{LINK})
6290 @end enumerate
6292 For example, if Fortran 77, C and C++ source code is compiled
6293 into a program, then the C++ linker will be used.  In this case, if the
6294 C or Fortran 77 linkers required any special libraries that weren't
6295 included by the C++ linker, then they must be manually added to an
6296 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6297 @file{Makefile.am}.
6299 Automake only looks at the file names listed in @file{_SOURCES}
6300 variables to choose the linker, and defaults to the C linker.
6301 Sometimes this is inconvenient because you are linking against a
6302 library written in another language and would like to set the linker
6303 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6304 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6307 @node Fortran 9x Support
6308 @comment  node-name,  next,  previous,  up
6309 @section Fortran 9x Support
6311 @cindex Fortran 9x support
6312 @cindex Support for Fortran 9x
6314 Automake includes support for Fortran 9x.
6316 Any package including Fortran 9x code must define the output variable
6317 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6318 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6319 Program Checks, autoconf, The Autoconf Manual}).
6321 A few additional variables are defined when a Fortran 9x source file is
6322 seen:
6324 @vtable @code
6326 @item FC
6327 The name of the Fortran 9x compiler.
6329 @item FCFLAGS
6330 Any flags to pass to the Fortran 9x compiler.
6332 @item AM_FCFLAGS
6333 The maintainer's variant of @code{FCFLAGS}.
6335 @item FCCOMPILE
6336 The command used to actually compile a Fortran 9x source file.  The file
6337 name is appended to form the complete command line.
6339 @item FCLINK
6340 The command used to actually link a pure Fortran 9x program or shared
6341 library.
6343 @end vtable
6345 @menu
6346 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6347 @end menu
6349 @node Compiling Fortran 9x Files
6350 @comment  node-name,  next,  previous,  up
6351 @subsection Compiling Fortran 9x Files
6353 @file{N.o} is made automatically from @file{N.f90} or @file{N.f95}
6354 by running the Fortran 9x compiler.  The precise command used
6355 is as follows:
6357 @table @file
6359 @item .f90
6360 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6362 @item .f95
6363 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6365 @end table
6367 @node Java Support
6368 @comment  node-name,  next,  previous,  up
6369 @section Java Support
6371 @cindex Java support
6372 @cindex Support for Java
6374 Automake includes support for compiled Java, using @command{gcj}, the Java
6375 front end to the GNU Compiler Collection.
6377 Any package including Java code to be compiled must define the output
6378 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6379 must also be defined somehow (either in @file{configure.ac} or
6380 @file{Makefile.am}).  The simplest way to do this is to use the
6381 @code{AM_PROG_GCJ} macro.
6383 @vindex GCJFLAGS
6385 By default, programs including Java source files are linked with
6386 @command{gcj}.
6388 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6389 compilation invoking @command{gcj} (in its role as an ahead-of-time
6390 compiler, when invoking it to create @file{.class} files,
6391 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6392 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6393 the user variable @code{GCJFLAGS}, should be used.
6395 @vindex AM_GCJFLAGS
6397 @command{gcj} can be used to compile @file{.java}, @file{.class},
6398 @file{.zip}, or @file{.jar} files.
6400 When linking, @command{gcj} requires that the main class be specified
6401 using the @option{--main=} option.  The easiest way to do this is to use
6402 the @code{_LDFLAGS} variable for the program.
6405 @node Support for Other Languages
6406 @comment  node-name,  next,  previous,  up
6407 @section Support for Other Languages
6409 Automake currently only includes full support for C, C++ (@pxref{C++
6410 Support}), Objective C (@pxref{Objective C Support}), Fortran 77
6411 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6412 and Java (@pxref{Java Support}).  There is only rudimentary support for other
6413 languages, support for which will be improved based on user demand.
6415 Some limited support for adding your own languages is available via the
6416 suffix rule handling (@pxref{Suffixes}).
6419 @node ANSI
6420 @section Automatic de-ANSI-fication
6422 @cindex de-ANSI-fication, defined
6424 The features described in this section are obsolete; you should not
6425 used any of them in new code, and they may be withdrawn in future
6426 Automake releases.
6428 When the C language was standardized in 1989, there was a long
6429 transition period where package developers needed to worry about
6430 porting to older systems that did not support ANSI C by default.
6431 These older systems are no longer in practical use and are no longer
6432 supported by their original suppliers, so developers need not worry
6433 about this problem any more.
6435 Automake allows you to write packages that are portable to K&R C by
6436 @dfn{de-ANSI-fying} each source file before the actual compilation takes
6437 place.
6439 @vindex AUTOMAKE_OPTIONS
6440 @opindex ansi2knr
6442 If the @file{Makefile.am} variable @code{AUTOMAKE_OPTIONS}
6443 (@pxref{Options}) contains the option @option{ansi2knr} then code to
6444 handle de-ANSI-fication is inserted into the generated
6445 @file{Makefile.in}.
6447 This causes each C source file in the directory to be treated as ANSI C@.
6448 If an ANSI C compiler is available, it is used.  If no ANSI C compiler
6449 is available, the @command{ansi2knr} program is used to convert the source
6450 files into K&R C, which is then compiled.
6452 The @command{ansi2knr} program is simple-minded.  It assumes the source
6453 code will be formatted in a particular way; see the @command{ansi2knr} man
6454 page for details.
6456 @acindex AM_C_PROTOTYPES
6457 Support for the obsolete de-ANSI-fication feature
6458 requires the source files @file{ansi2knr.c}
6459 and @file{ansi2knr.1} to be in the same package as the ANSI C source;
6460 these files are distributed with Automake.  Also, the package
6461 @file{configure.ac} must call the macro @code{AM_C_PROTOTYPES}
6462 (@pxref{Macros}).
6464 Automake also handles finding the @command{ansi2knr} support files in some
6465 other directory in the current package.  This is done by prepending the
6466 relative path to the appropriate directory to the @command{ansi2knr}
6467 option.  For instance, suppose the package has ANSI C code in the
6468 @file{src} and @file{lib} subdirectories.  The files @file{ansi2knr.c} and
6469 @file{ansi2knr.1} appear in @file{lib}.  Then this could appear in
6470 @file{src/Makefile.am}:
6472 @example
6473 AUTOMAKE_OPTIONS = ../lib/ansi2knr
6474 @end example
6476 If no directory prefix is given, the files are assumed to be in the
6477 current directory.
6479 Note that automatic de-ANSI-fication will not work when the package is
6480 being built for a different host architecture.  That is because automake
6481 currently has no way to build @command{ansi2knr} for the build machine.
6483 @c FIXME: this paragraph might be better moved to an `upgrading' section.
6484 @cindex @code{LTLIBOBJS} and @code{ansi2knr}
6485 @cindex @code{LIBOBJS} and @code{ansi2knr}
6486 @cindex @code{ansi2knr} and @code{LTLIBOBJS}
6487 @cindex @code{ansi2knr} and @code{LIBOBJS}
6488 Using @code{LIBOBJS} with source de-ANSI-fication used to require
6489 hand-crafted code in @file{configure} to append @samp{$U} to basenames
6490 in @code{LIBOBJS}.  This is no longer true today.  Starting with version
6491 2.54, Autoconf takes care of rewriting @code{LIBOBJS} and
6492 @code{LTLIBOBJS}.  (@pxref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ}
6493 vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual})
6495 @node Dependencies
6496 @section Automatic dependency tracking
6498 As a developer it is often painful to continually update the
6499 @file{Makefile.in} whenever the include-file dependencies change in a
6500 project.  Automake supplies a way to automatically track dependency
6501 changes (@pxref{Dependency Tracking}).
6503 @cindex Dependency tracking
6504 @cindex Automatic dependency tracking
6506 Automake always uses complete dependencies for a compilation,
6507 including system headers.  Automake's model is that dependency
6508 computation should be a side effect of the build.  To this end,
6509 dependencies are computed by running all compilations through a
6510 special wrapper program called @command{depcomp}.  @command{depcomp}
6511 understands how to coax many different C and C++ compilers into
6512 generating dependency information in the format it requires.
6513 @samp{automake -a} will install @command{depcomp} into your source
6514 tree for you.  If @command{depcomp} can't figure out how to properly
6515 invoke your compiler, dependency tracking will simply be disabled for
6516 your build.
6518 @cindex @command{depcomp}
6520 Experience with earlier versions of Automake (@pxref{Dependency
6521 Tracking Evolution}) taught us that it is not reliable to generate
6522 dependencies only on the maintainer's system, as configurations vary
6523 too much.  So instead Automake implements dependency tracking at build
6524 time.
6526 Automatic dependency tracking can be suppressed by putting
6527 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6528 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6529 (this should be the preferred way).  Or, you can invoke @command{automake}
6530 with the @option{-i} option.  Dependency tracking is enabled by default.
6532 @vindex AUTOMAKE_OPTIONS
6533 @opindex no-dependencies
6535 The person building your package also can choose to disable dependency
6536 tracking by configuring with @option{--disable-dependency-tracking}.
6538 @cindex Disabling dependency tracking
6539 @cindex Dependency tracking, disabling
6542 @node EXEEXT
6543 @section Support for executable extensions
6545 @cindex Executable extension
6546 @cindex Extension, executable
6547 @cindex Windows
6549 On some platforms, such as Windows, executables are expected to have an
6550 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6551 among them) will automatically generate @file{foo.exe} when asked to
6552 generate @file{foo}.
6554 Automake provides mostly-transparent support for this.  Unfortunately
6555 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6556 dictionary is revised, you will have to assist Automake if your package
6557 must support those platforms.
6559 One thing you must be aware of is that, internally, Automake rewrites
6560 something like this:
6562 @example
6563 bin_PROGRAMS = liver
6564 @end example
6566 to this:
6568 @example
6569 bin_PROGRAMS = liver$(EXEEXT)
6570 @end example
6572 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6573 extension.
6575 The variable @code{TESTS} (@pxref{Tests}) is also rewritten if it
6576 contains filenames that have been declared as programs in the same
6577 @file{Makefile}.  (This is mostly useful when some programs from
6578 @code{check_PROGRAMS} are listed in @code{TESTS}.)
6580 However, Automake cannot apply this rewriting to @command{configure}
6581 substitutions.  This means that if you are conditionally building a
6582 program using such a substitution, then your @file{configure.ac} must
6583 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6585 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
6586 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
6587 automatically if you configure a compiler (say, through
6588 @code{AC_PROG_CC}).
6590 Sometimes maintainers like to write an explicit link rule for their
6591 program.  Without executable extension support, this is easy---you
6592 simply write a rule whose target is the name of the program.  However,
6593 when executable extension support is enabled, you must instead add the
6594 @samp{$(EXEEXT)} suffix.
6596 Unfortunately, due to the change in Autoconf 2.50, this means you must
6597 always add this extension.  However, this is a problem for maintainers
6598 who know their package will never run on a platform that has
6599 executable extensions.  For those maintainers, the @option{no-exeext}
6600 option (@pxref{Options}) will disable this feature.  This works in a
6601 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6602 rule for a target named @code{foo} in @file{Makefile.am} will override
6603 an automake-generated rule for @samp{foo$(EXEEXT)}.  Without
6604 the @option{no-exeext} option, this use will give a diagnostic.
6607 @node Other objects
6608 @chapter Other Derived Objects
6610 Automake can handle derived objects that are not C programs.  Sometimes
6611 the support for actually building such objects must be explicitly
6612 supplied, but Automake will still automatically handle installation and
6613 distribution.
6615 @menu
6616 * Scripts::                     Executable scripts
6617 * Headers::                     Header files
6618 * Data::                        Architecture-independent data files
6619 * Sources::                     Derived sources
6620 @end menu
6623 @node Scripts
6624 @section Executable Scripts
6626 @cindex @code{_SCRIPTS} primary, defined
6627 @cindex @code{SCRIPTS} primary, defined
6628 @cindex Primary variable, @code{SCRIPTS}
6629 @vindex _SCRIPTS
6630 @cindex Installing scripts
6632 It is possible to define and install programs that are scripts.  Such
6633 programs are listed using the @code{SCRIPTS} primary name.  When the
6634 script is distributed in its final, installable form, the
6635 @file{Makefile} usually looks as follows:
6636 @vindex SCRIPTS
6638 @example
6639 # Install my_script in $(bindir) and distribute it.
6640 dist_bin_SCRIPTS = my_script
6641 @end example
6643 Script are not distributed by default; as we have just seen, those
6644 that should be distributed can be specified using a @code{dist_}
6645 prefix as with other primaries.
6647 @cindex @code{SCRIPTS}, installation directories
6648 @vindex bin_SCRIPTS
6649 @vindex sbin_SCRIPTS
6650 @vindex libexec_SCRIPTS
6651 @vindex pkgdata_SCRIPTS
6652 @vindex noinst_SCRIPTS
6653 @vindex check_SCRIPTS
6655 Scripts can be installed in @code{bindir}, @code{sbindir},
6656 @code{libexecdir}, or @code{pkgdatadir}.
6658 Scripts that need not being installed can be listed in
6659 @code{noinst_SCRIPTS}, and among them, those which are needed only by
6660 @samp{make check} should go in @code{check_SCRIPTS}.
6662 When a script needs to be built, the @file{Makefile.am} should include
6663 the appropriate rules.  For instance the @command{automake} program
6664 itself is a Perl script that is generated from @file{automake.in}.
6665 Here is how this is handled:
6667 @example
6668 bin_SCRIPTS = automake
6669 CLEANFILES = $(bin_SCRIPTS)
6670 EXTRA_DIST = automake.in
6672 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
6673             -e 's,[@@]PERL[@@],$(PERL),g' \
6674             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
6675             -e 's,[@@]VERSION[@@],$(VERSION),g' \
6676             @dots{}
6678 automake: automake.in Makefile
6679         $(do_subst) < $(srcdir)/automake.in > automake
6680         chmod +x automake
6681 @end example
6683 Such scripts for which a build rule has been supplied need to be
6684 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
6685 sources have to be distributed, usually with @code{EXTRA_DIST}
6686 (@pxref{Dist}).
6688 Another common way to build scripts is to process them from
6689 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
6690 Automake knows which files should be cleaned and distributed, and what
6691 the rebuild rules should look like.
6693 For instance if @file{configure.ac} contains
6695 @example
6696 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
6697 @end example
6699 @noindent
6700 to build @file{src/my_script} from @file{src/my_script.in}, then an
6701 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
6702 be as simple as
6704 @example
6705 bin_SCRIPTS = my_script
6706 CLEANFILES = $(bin_SCRIPTS)
6707 @end example
6709 @noindent
6710 There is no need for @code{EXTRA_DIST} or any build rule: Automake
6711 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
6712 @code{CLEANFILES} is still useful, because by default Automake will
6713 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
6714 @code{clean}.
6716 Although this looks simpler, building scripts this way has one
6717 drawback: directory variables such as @code{$(datadir)} are not fully
6718 expanded and may refer to other directory variables.
6720 @node Headers
6721 @section Header files
6723 @cindex @code{_HEADERS} primary, defined
6724 @cindex @code{HEADERS} primary, defined
6725 @cindex Primary variable, @code{HEADERS}
6726 @vindex _HEADERS
6727 @vindex noinst_HEADERS
6728 @cindex @code{HEADERS}, installation directories
6729 @cindex Installing headers
6730 @vindex include_HEADERS
6731 @vindex oldinclude_HEADERS
6732 @vindex pkginclude_HEADERS
6735 Header files that must be installed are specified by the
6736 @code{HEADERS} family of variables.  Headers can be installed in
6737 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
6738 other directory you may have defined (@pxref{Uniform}).  For instance,
6740 @example
6741 include_HEADERS = foo.h bar/bar.h
6742 @end example
6744 @noindent
6745 will install the two files as @file{$(includedir)/foo.h} and
6746 @file{$(includedir)/bar.h}.
6748 The @code{nobase_} prefix is also supported,
6750 @example
6751 nobase_include_HEADERS = foo.h bar/bar.h
6752 @end example
6754 @noindent
6755 will install the two files as @file{$(includedir)/foo.h} and
6756 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
6758 @vindex noinst_HEADERS
6759 Usually, only header files that accompany installed libraries need to
6760 be installed.  Headers used by programs or convenience libraries are
6761 not installed.  The @code{noinst_HEADERS} variable can be used for
6762 such headers.  However when the header actually belongs to one
6763 convenient library or program, we recommend listing it in the
6764 program's or library's @code{_SOURCES} variable (@pxref{Program
6765 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
6766 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
6767 right variable to use in a directory containing only headers and no
6768 associated library or program.
6770 All header files must be listed somewhere; in a @code{_SOURCES}
6771 variable or in a @code{_HEADERS} variable.  Missing ones will not
6772 appear in the distribution.
6774 For header files that are built and must not be distributed, use the
6775 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
6776 @code{nodist_prog_SOURCES}.  If these generated headers are needed
6777 during the build, you must also ensure they exist before they are
6778 used (@pxref{Sources}).
6781 @node Data
6782 @section Architecture-independent data files
6784 @cindex @code{_DATA} primary, defined
6785 @cindex @code{DATA} primary, defined
6786 @cindex Primary variable, @code{DATA}
6787 @vindex _DATA
6789 Automake supports the installation of miscellaneous data files using the
6790 @code{DATA} family of variables.
6791 @vindex DATA
6793 @vindex data_DATA
6794 @vindex sysconf_DATA
6795 @vindex sharedstate_DATA
6796 @vindex localstate_DATA
6797 @vindex pkgdata_DATA
6799 Such data can be installed in the directories @code{datadir},
6800 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
6801 @code{pkgdatadir}.
6803 By default, data files are @emph{not} included in a distribution.  Of
6804 course, you can use the @code{dist_} prefix to change this on a
6805 per-variable basis.
6807 Here is how Automake declares its auxiliary data files:
6809 @example
6810 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
6811 @end example
6814 @node Sources
6815 @section Built sources
6817 Because Automake's automatic dependency tracking works as a side-effect
6818 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
6819 target should not be compiled before its dependencies are made, but
6820 these dependencies are unknown until the target is first compiled.
6822 Ordinarily this is not a problem, because dependencies are distributed
6823 sources: they preexist and do not need to be built.  Suppose that
6824 @file{foo.c} includes @file{foo.h}.  When it first compiles
6825 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
6826 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
6827 records the @file{foo.h} dependency so that following invocations of
6828 @command{make} will honor it.  In these conditions, it's clear there is
6829 no problem: either @file{foo.o} doesn't exist and has to be built
6830 (regardless of the dependencies), or accurate dependencies exist and
6831 they can be used to decide whether @file{foo.o} should be rebuilt.
6833 It's a different story if @file{foo.h} doesn't exist by the first
6834 @command{make} run.  For instance, there might be a rule to build
6835 @file{foo.h}.  This time @file{file.o}'s build will fail because the
6836 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
6837 rule to build @file{foo.h} first by lack of dependency information.
6839 @vindex BUILT_SOURCES
6840 @cindex @code{BUILT_SOURCES}, defined
6842 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
6843 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
6844 or @samp{make check} (or even @samp{make install}) before other
6845 targets are processed.  However, such a source file is not
6846 @emph{compiled} unless explicitly requested by mentioning it in some
6847 other @code{_SOURCES} variable.
6849 So, to conclude our introductory example, we could use
6850 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
6851 any other target (including @file{foo.o}) during @samp{make all} or
6852 @samp{make check}.
6854 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
6855 must be created early in the build process can be listed in this
6856 variable.  Moreover, all built sources do not necessarily have to be
6857 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
6858 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
6859 another source), because it's a known dependency of the associated
6860 object.
6862 It might be important to emphasize that @code{BUILT_SOURCES} is
6863 honored only by @samp{make all}, @samp{make check} and @samp{make
6864 install}.  This means you cannot build a specific target (e.g.,
6865 @samp{make foo}) in a clean tree if it depends on a built source.
6866 However it will succeed if you have run @samp{make all} earlier,
6867 because accurate dependencies are already available.
6869 The next section illustrates and discusses the handling of built sources
6870 on a toy example.
6872 @menu
6873 * Built sources example::       Several ways to handle built sources.
6874 @end menu
6876 @node Built sources example
6877 @subsection Built sources example
6879 Suppose that @file{foo.c} includes @file{bindir.h}, which is
6880 installation-dependent and not distributed: it needs to be built.  Here
6881 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
6882 value of the @command{make} variable @code{bindir} (inherited from
6883 @file{configure}).
6885 We suggest several implementations below.  It's not meant to be an
6886 exhaustive listing of all ways to handle built sources, but it will give
6887 you a few ideas if you encounter this issue.
6889 @unnumberedsubsec First try
6891 This first implementation will illustrate the bootstrap issue mentioned
6892 in the previous section (@pxref{Sources}).
6894 Here is a tentative @file{Makefile.am}.
6896 @example
6897 # This won't work.
6898 bin_PROGRAMS = foo
6899 foo_SOURCES = foo.c
6900 nodist_foo_SOURCES = bindir.h
6901 CLEANFILES = bindir.h
6902 bindir.h: Makefile
6903         echo '#define bindir "$(bindir)"' >$@@
6904 @end example
6906 This setup doesn't work, because Automake doesn't know that @file{foo.c}
6907 includes @file{bindir.h}.  Remember, automatic dependency tracking works
6908 as a side-effect of compilation, so the dependencies of @file{foo.o} will
6909 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
6910 The symptom is as follows.
6912 @example
6913 % make
6914 source='foo.c' object='foo.o' libtool=no \
6915 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
6916 depmode=gcc /bin/sh ./depcomp \
6917 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
6918 foo.c:2: bindir.h: No such file or directory
6919 make: *** [foo.o] Error 1
6920 @end example
6922 In this example @file{bindir.h} is not distributed, not installed, and
6923 it is not even being built on-time.  One may wonder what the
6924 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
6925 line simply states that @file{bindir.h} is a source of @code{foo}, so
6926 for instance, it should be inspected while generating tags
6927 (@pxref{Tags}).  In other words, it does not help our present problem,
6928 and the build would fail identically without it.
6930 @unnumberedsubsec Using @code{BUILT_SOURCES}
6932 A solution is to require @file{bindir.h} to be built before anything
6933 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
6935 @example
6936 bin_PROGRAMS = foo
6937 foo_SOURCES = foo.c
6938 nodist_foo_SOURCES = bindir.h
6939 BUILT_SOURCES = bindir.h
6940 CLEANFILES = bindir.h
6941 bindir.h: Makefile
6942         echo '#define bindir "$(bindir)"' >$@@
6943 @end example
6945 See how @file{bindir.h} get built first:
6947 @example
6948 % make
6949 echo '#define bindir "/usr/local/bin"' >bindir.h
6950 make  all-am
6951 make[1]: Entering directory `/home/adl/tmp'
6952 source='foo.c' object='foo.o' libtool=no \
6953 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
6954 depmode=gcc /bin/sh ./depcomp \
6955 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
6956 gcc  -g -O2   -o foo  foo.o
6957 make[1]: Leaving directory `/home/adl/tmp'
6958 @end example
6960 However, as said earlier, @code{BUILT_SOURCES} applies only to the
6961 @code{all}, @code{check}, and @code{install} targets.  It still fails
6962 if you try to run @samp{make foo} explicitly:
6964 @example
6965 % make clean
6966 test -z "bindir.h" || rm -f bindir.h
6967 test -z "foo" || rm -f foo
6968 rm -f *.o
6969 % : > .deps/foo.Po # Suppress previously recorded dependencies
6970 % make foo
6971 source='foo.c' object='foo.o' libtool=no \
6972 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
6973 depmode=gcc /bin/sh ./depcomp \
6974 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
6975 foo.c:2: bindir.h: No such file or directory
6976 make: *** [foo.o] Error 1
6977 @end example
6979 @unnumberedsubsec Recording dependencies manually
6981 Usually people are happy enough with @code{BUILT_SOURCES} because they
6982 never build targets such as @samp{make foo} before @samp{make all}, as
6983 in the previous example.  However if this matters to you, you can
6984 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
6985 the @file{Makefile.am}.
6987 @example
6988 bin_PROGRAMS = foo
6989 foo_SOURCES = foo.c
6990 nodist_foo_SOURCES = bindir.h
6991 foo.$(OBJEXT): bindir.h
6992 CLEANFILES = bindir.h
6993 bindir.h: Makefile
6994         echo '#define bindir "$(bindir)"' >$@@
6995 @end example
6997 You don't have to list @emph{all} the dependencies of @file{foo.o}
6998 explicitly, only those that might need to be built.  If a dependency
6999 already exists, it will not hinder the first compilation and will be
7000 recorded by the normal dependency tracking code.  (Note that after
7001 this first compilation the dependency tracking code will also have
7002 recorded the dependency between @file{foo.o} and
7003 @file{bindir.h}; so our explicit dependency is really useful to
7004 the first build only.)
7006 Adding explicit dependencies like this can be a bit dangerous if you are
7007 not careful enough.  This is due to the way Automake tries not to
7008 overwrite your rules (it assumes you know better than it).
7009 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7010 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7011 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7012 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7013 Always check the generated @file{Makefile.in} if you do this.
7015 @unnumberedsubsec Build @file{bindir.h} from @file{configure}
7017 It's possible to define this preprocessor macro from @file{configure},
7018 either in @file{config.h} (@pxref{Defining Directories, , Defining
7019 Directories, autoconf, The Autoconf Manual}), or by processing a
7020 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7021 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7022 Autoconf Manual}).
7024 At this point it should be clear that building @file{bindir.h} from
7025 @file{configure} work well for this example.  @file{bindir.h} will exist
7026 before you build any target, hence will not cause any dependency issue.
7028 The Makefile can be shrunk as follows.  We do not even have to mention
7029 @file{bindir.h}.
7031 @example
7032 bin_PROGRAMS = foo
7033 foo_SOURCES = foo.c
7034 @end example
7036 However, it's not always possible to build sources from
7037 @file{configure}, especially when these sources are generated by a tool
7038 that needs to be built first...
7040 @unnumberedsubsec Build @file{bindir.c}, not @file{bindir.h}.
7042 Another attractive idea is to define @code{bindir} as a variable or
7043 function exported from @file{bindir.o}, and build @file{bindir.c}
7044 instead of @file{bindir.h}.
7046 @example
7047 noinst_PROGRAMS = foo
7048 foo_SOURCES = foo.c bindir.h
7049 nodist_foo_SOURCES = bindir.c
7050 CLEANFILES = bindir.c
7051 bindir.c: Makefile
7052         echo 'const char bindir[] = "$(bindir)";' >$@@
7053 @end example
7055 @file{bindir.h} contains just the variable's declaration and doesn't
7056 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7057 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7058 first.
7060 @unnumberedsubsec Which is best?
7062 There is no panacea, of course.  Each solution has its merits and
7063 drawbacks.
7065 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7066 foo} on a clean tree is important to you.
7068 You won't add explicit dependencies if you are leery of overriding
7069 an Automake rule by mistake.
7071 Building files from @file{./configure} is not always possible, neither
7072 is converting @file{.h} files into @file{.c} files.
7075 @node Other GNU Tools
7076 @chapter Other GNU Tools
7078 Since Automake is primarily intended to generate @file{Makefile.in}s for
7079 use in GNU programs, it tries hard to interoperate with other GNU tools.
7081 @menu
7082 * Emacs Lisp::                  Emacs Lisp
7083 * gettext::                     Gettext
7084 * Libtool::                     Libtool
7085 * Java::                        Java
7086 * Python::                      Python
7087 @end menu
7090 @node Emacs Lisp
7091 @section Emacs Lisp
7093 @cindex @code{_LISP} primary, defined
7094 @cindex @code{LISP} primary, defined
7095 @cindex Primary variable, @code{LISP}
7097 @vindex _LISP
7098 @vindex lisp_LISP
7099 @vindex noinst_LISP
7101 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7102 is used to hold a list of @file{.el} files.  Possible prefixes for this
7103 primary are @code{lisp_} and @code{noinst_}.  Note that if
7104 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7105 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7107 @vindex dist_lisp_LISP
7108 @vindex dist_noinst_LISP
7109 Lisp sources are not distributed by default.  You can prefix the
7110 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7111 @code{dist_noinst_LISP}, to indicate that these files should be
7112 distributed.
7114 Automake will byte-compile all Emacs Lisp source files using the Emacs
7115 found by @code{AM_PATH_LISPDIR}, if any was found.
7117 Byte-compiled Emacs Lisp files are not portable among all versions of
7118 Emacs, so it makes sense to turn this off if you expect sites to have
7119 more than one version of Emacs installed.  Furthermore, many packages
7120 don't actually benefit from byte-compilation.  Still, we recommend
7121 that you byte-compile your Emacs Lisp sources.  It is probably better
7122 for sites with strange setups to cope for themselves than to make the
7123 installation less nice for everybody else.
7125 There are two ways to avoid byte-compiling.  Historically, we have
7126 recommended the following construct.
7127 @example
7128 lisp_LISP = file1.el file2.el
7129 ELCFILES =
7130 @end example
7131 @noindent
7132 @code{ELCFILES} is an internal Automake variable that normally lists
7133 all @file{.elc} files that must be byte-compiled.  Automake defines
7134 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7135 variable explicitly prevents byte-compilation to occur.
7137 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead.  As
7139 @example
7140 lisp_DATA = file1.el file2.el
7141 @end example
7143 Note that these two constructs are not equivalent.  @code{_LISP} will
7144 not install a file if Emacs is not installed, while @code{_DATA} will
7145 always install its files.
7147 @node gettext
7148 @section Gettext
7150 @cindex GNU Gettext support
7151 @cindex Gettext support
7152 @cindex Support for GNU Gettext
7154 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7155 turns on support for GNU gettext, a message catalog system for
7156 internationalization
7157 (@pxref{GNU Gettext, , , gettext, GNU gettext utilities}).
7159 The @code{gettext} support in Automake requires the addition of one or
7160 two subdirectories to the package, @file{po} and possibly also @file{intl}.
7161 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7162 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7163 Automake ensures that these directories exist and are mentioned in
7164 @code{SUBDIRS}.
7166 @node Libtool
7167 @section Libtool
7169 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7170 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7171 @xref{A Shared Library}.
7174 @node Java
7175 @section Java
7177 @cindex @code{_JAVA} primary, defined
7178 @cindex @code{JAVA} primary, defined
7179 @cindex Primary variable, @code{JAVA}
7181 Automake provides some minimal support for Java compilation with the
7182 @code{JAVA} primary.
7184 Any @file{.java} files listed in a @code{_JAVA} variable will be
7185 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7186 files are not included in the distribution, you should use the
7187 @code{dist_} prefix to distribute them.
7189 Here is a typical setup for distributing @file{.java} files and
7190 installing the @file{.class} files resulting from their compilation.
7192 @example
7193 javadir = $(datadir)/java
7194 dist_java_JAVA = a.java b.java @dots{}
7195 @end example
7197 @cindex @code{JAVA} restrictions
7198 @cindex Restrictions for @code{JAVA}
7200 Currently Automake enforces the restriction that only one @code{_JAVA}
7201 primary can be used in a given @file{Makefile.am}.  The reason for this
7202 restriction is that, in general, it isn't possible to know which
7203 @file{.class} files were generated from which @file{.java} files, so
7204 it would be impossible to know which files to install where.  For
7205 instance, a @file{.java} file can define multiple classes; the resulting
7206 @file{.class} file names cannot be predicted without parsing the
7207 @file{.java} file.
7209 There are a few variables that are used when compiling Java sources:
7211 @vtable @code
7212 @item JAVAC
7213 The name of the Java compiler.  This defaults to @samp{javac}.
7215 @item JAVACFLAGS
7216 The flags to pass to the compiler.  This is considered to be a user
7217 variable (@pxref{User Variables}).
7219 @item AM_JAVACFLAGS
7220 More flags to pass to the Java compiler.  This, and not
7221 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7222 compiler flags into @file{Makefile.am}.
7224 @item JAVAROOT
7225 The value of this variable is passed to the @option{-d} option to
7226 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7228 @item CLASSPATH_ENV
7229 This variable is an @code{sh} expression that is used to set the
7230 @env{CLASSPATH} environment variable on the @code{javac} command line.
7231 (In the future we will probably handle class path setting differently.)
7232 @end vtable
7235 @node Python
7236 @section Python
7238 @cindex @code{_PYTHON} primary, defined
7239 @cindex @code{PYTHON} primary, defined
7240 @cindex Primary variable, @code{PYTHON}
7241 @vindex _PYTHON
7243 Automake provides support for Python compilation with the
7244 @code{PYTHON} primary.  A typical setup is to call
7245 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7246 following in @file{Makefile.am}:
7248 @example
7249 python_PYTHON = tree.py leave.py
7250 @end example
7252 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7253 with @command{py-compile} at install time.  @command{py-compile}
7254 actually creates both standard (@file{.pyc}) and optimized
7255 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7256 because byte-compilation occurs at install time, any files listed in
7257 @code{noinst_PYTHON} will not be compiled.  Python source files are
7258 included in the distribution by default, prepend @code{nodist_} (as in
7259 @code{nodist_python_PYTHON}) to omit them.
7261 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7262 that will determine some Python-related directory variables (see
7263 below).  If you have called @code{AM_PATH_PYTHON} from
7264 @file{configure.ac}, then you may use the variables
7265 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7266 files in your @file{Makefile.am}, depending where you want your files
7267 installed (see the definitions of @code{pythondir} and
7268 @code{pkgpythondir} below).
7270 @defmac AM_PATH_PYTHON ([@var{VERSION}], [@var{ACTION-IF-FOUND}], [@var{ACTION-IF-NOT-FOUND}])
7272 Search a Python interpreter on the system.  This macro takes three
7273 optional arguments.  The first argument, if present, is the minimum
7274 version of Python required for this package: @code{AM_PATH_PYTHON}
7275 will skip any Python interpreter that is older than @var{VERSION}.
7276 If an interpreter is found and satisfies @var{VERSION}, then
7277 @var{ACTION-IF-FOUND} is run.  Otherwise, @var{ACTION-IF-NOT-FOUND} is
7278 run.
7280 If @var{ACTION-IF-NOT-FOUND} is not specified, as in the following
7281 example, the default is to abort @command{configure}.
7283 @example
7284 AM_PATH_PYTHON([2.2])
7285 @end example
7287 @noindent
7288 This is fine when Python is an absolute requirement for the package.
7289 If Python >= 2.2 was only @emph{optional} to the package,
7290 @code{AM_PATH_PYTHON} could be called as follows.
7292 @example
7293 AM_PATH_PYTHON([2.2],, [:])
7294 @end example
7296 @code{AM_PATH_PYTHON} creates the following output variables based on
7297 the Python installation found during configuration.
7298 @end defmac
7300 @vtable @code
7301 @item PYTHON
7302 The name of the Python executable, or @samp{:} if no suitable
7303 interpreter could be found.
7305 Assuming @var{ACTION-IF-NOT-FOUND} is used (otherwise @file{./configure}
7306 will abort if Python is absent), the value of @code{PYTHON} can be used
7307 to setup a conditional in order to disable the relevant part of a build
7308 as follows.
7310 @example
7311   AM_PATH_PYTHON(,, [:])
7312   AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7313 @end example
7315 @item PYTHON_VERSION
7316 The Python version number, in the form @var{major}.@var{minor}
7317 (e.g., @samp{1.5}).  This is currently the value of
7318 @samp{sys.version[:3]}.
7320 @item PYTHON_PREFIX
7321 The string @samp{$@{prefix@}}.  This term may be used in future work
7322 that needs the contents of Python's @samp{sys.prefix}, but general
7323 consensus is to always use the value from configure.
7325 @item PYTHON_EXEC_PREFIX
7326 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7327 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7328 consensus is to always use the value from configure.
7330 @item PYTHON_PLATFORM
7331 The canonical name used by Python to describe the operating system, as
7332 given by @samp{sys.platform}.  This value is sometimes needed when
7333 building Python extensions.
7335 @item pythondir
7336 The directory name for the @file{site-packages} subdirectory of the
7337 standard Python install tree.
7339 @item pkgpythondir
7340 This is the directory under @code{pythondir} that is named after the
7341 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7342 as a convenience.
7344 @item pyexecdir
7345 This is the directory where Python extension modules (shared libraries)
7346 should be installed.  An extension module written in C could be declared
7347 as follows to Automake:
7349 @example
7350 pyexec_LTLIBRARIES = quaternion.la
7351 quaternion_SOURCES = quaternion.c support.c support.h
7352 quaternion_la_LDFLAGS = -avoid-version -module
7353 @end example
7355 @item pkgpyexecdir
7356 This is a convenience variable that is defined as
7357 @samp{$(pyexecdir)/$(PACKAGE)}.
7358 @end vtable
7360 All these directory variables have values that start with either
7361 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7362 fine in @file{Makefiles}, but it makes these variables hard to use in
7363 @file{configure}.  This is mandated by the GNU coding standards, so
7364 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7365 manual has a section with more details on this topic
7366 (@pxref{Installation Directory Variables, , Installation Directory
7367 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7368 Install Paths}.
7371 @node Documentation
7372 @chapter Building documentation
7374 Currently Automake provides support for Texinfo and man pages.
7376 @menu
7377 * Texinfo::                     Texinfo
7378 * Man pages::                   Man pages
7379 @end menu
7382 @node Texinfo
7383 @section Texinfo
7385 @cindex @code{_TEXINFOS} primary, defined
7386 @cindex @code{TEXINFOS} primary, defined
7387 @cindex Primary variable, @code{TEXINFOS}
7388 @cindex HTML output using Texinfo
7389 @cindex PDF output using Texinfo
7390 @cindex PS output using Texinfo
7391 @cindex DVI output using Texinfo
7392 @vindex _TEXINFOS
7393 @vindex info_TEXINFOS
7395 If the current directory contains Texinfo source, you must declare it
7396 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7397 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7398 here.  Any Texinfo source file must end in the @file{.texi},
7399 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7400 for new manuals.
7402 Automake generates rules to build @file{.info}, @file{.dvi},
7403 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7404 sources.  Following the GNU Coding Standards, only the @file{.info}
7405 files are built by @samp{make all} and installed by @samp{make
7406 install} (unless you use @option{no-installinfo}, see below).
7407 Furthermore, @file{.info} files are automatically distributed so that
7408 Texinfo is not a prerequisite for installing your package.
7410 @trindex dvi
7411 @trindex html
7412 @trindex pdf
7413 @trindex ps
7414 @trindex install-dvi
7415 @trindex install-html
7416 @trindex install-pdf
7417 @trindex install-ps
7418 Other documentation formats can be built on request by @samp{make
7419 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7420 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7421 @samp{make install-pdf} and @samp{make install-html} explicitly.
7422 @samp{make uninstall} will remove everything: the Texinfo
7423 documentation installed by default as well as all the above optional
7424 formats.
7426 All these targets can be extended using @samp{-local} rules
7427 (@pxref{Extending}).
7429 @cindex Texinfo flag, @code{VERSION}
7430 @cindex Texinfo flag, @code{UPDATED}
7431 @cindex Texinfo flag, @code{EDITION}
7432 @cindex Texinfo flag, @code{UPDATED-MONTH}
7434 @cindex @code{VERSION} Texinfo flag
7435 @cindex @code{UPDATED} Texinfo flag
7436 @cindex @code{EDITION} Texinfo flag
7437 @cindex @code{UPDATED-MONTH} Texinfo flag
7439 @cindex @file{mdate-sh}
7441 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7442 that file will be automatically generated.  The file @file{version.texi}
7443 defines four Texinfo flag you can reference using
7444 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7445 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7447 @table @code
7448 @item EDITION
7449 @itemx VERSION
7450 Both of these flags hold the version number of your program.  They are
7451 kept separate for clarity.
7453 @item UPDATED
7454 This holds the date the primary @file{.texi} file was last modified.
7456 @item UPDATED-MONTH
7457 This holds the name of the month in which the primary @file{.texi} file
7458 was last modified.
7459 @end table
7461 The @file{version.texi} support requires the @command{mdate-sh}
7462 script; this script is supplied with Automake and automatically
7463 included when @command{automake} is invoked with the
7464 @option{--add-missing} option.
7466 If you have multiple Texinfo files, and you want to use the
7467 @file{version.texi} feature, then you have to have a separate version
7468 file for each Texinfo file.  Automake will treat any include in a
7469 Texinfo file that matches @file{vers*.texi} just as an automatically
7470 generated version file.
7472 Sometimes an info file actually depends on more than one @file{.texi}
7473 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7474 @file{gpl.texi}.  You can tell Automake about these dependencies using
7475 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7476 @vindex TEXINFOS
7477 @vindex _TEXINFOS
7479 @example
7480 info_TEXINFOS = hello.texi
7481 hello_TEXINFOS = gpl.texi
7482 @end example
7484 @cindex @file{texinfo.tex}
7486 By default, Automake requires the file @file{texinfo.tex} to appear in
7487 the same directory as the Texinfo source (this can be changed using the
7488 @code{TEXINFO_TEX} variable, see below).  However, if you used
7489 @code{AC_CONFIG_AUX_DIR} in @file{configure.ac} (@pxref{Input, , Finding
7490 `configure' Input, autoconf, The Autoconf Manual}), then
7491 @file{texinfo.tex} is looked for there.  Automake supplies
7492 @file{texinfo.tex} if @option{--add-missing} is given.
7494 @opindex no-texinfo.tex
7496 The option @option{no-texinfo.tex} can be used to eliminate the
7497 requirement for the file @file{texinfo.tex}.  Use of the variable
7498 @code{TEXINFO_TEX} is preferable, however, because that allows the
7499 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7501 @cindex Option, @code{no-installinfo}
7502 @cindex Target, @code{install-info}
7503 @cindex @code{install-info} target
7504 @cindex @code{no-installinfo} option
7506 @opindex no-installinfo
7507 @trindex install-info
7509 Automake generates an @code{install-info} rule; some people apparently
7510 use this.  By default, info pages are installed by @samp{make
7511 install}, so running @code{make install-info} is pointless.  This can
7512 be prevented via the @code{no-installinfo} option.  In this case,
7513 @file{.info} files are not installed by default, and user must
7514 request this explicitly using @samp{make install-info}
7516 The following variables are used by the Texinfo build rules.
7518 @vtable @code
7519 @item MAKEINFO
7520 The name of the program invoked to build @file{.info} files.  This
7521 variable is defined by Automake.  If the @command{makeinfo} program is
7522 found on the system then it will be used by default; otherwise
7523 @command{missing} will be used instead.
7525 @item MAKEINFOHTML
7526 The command invoked to build @file{.html} files.  Automake
7527 defines this to @samp{$(MAKEINFO) --html}.
7529 @item MAKEINFOFLAGS
7530 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7531 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7532 not expected to be defined in any @file{Makefile}; it can be used by
7533 users to pass extra flags to suit their needs.
7535 @item AM_MAKEINFOFLAGS
7536 @itemx AM_MAKEINFOHTMLFLAGS
7537 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7538 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7539 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7540 passed to @code{makeinfo} when building @file{.info} files; and
7541 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7542 files.
7544 For instance, the following setting can be used to obtain one single
7545 @file{.html} file per manual, without node separators.
7546 @example
7547 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7548 @end example
7550 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7551 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7552 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7553 and @file{.html} files.
7555 @item TEXI2DVI
7556 The name of the command that converts a @file{.texi} file into a
7557 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7558 with the Texinfo package.
7560 @item TEXI2PDF
7561 The name of the command that translates a @file{.texi} file into a
7562 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7564 @item DVIPS
7565 The name of the command that build a @file{.ps} file out of a
7566 @file{.dvi} file.  This defaults to @samp{dvips}.
7568 @item TEXINFO_TEX
7570 If your package has Texinfo files in many directories, you can use the
7571 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7572 @file{texinfo.tex} for your package.  The value of this variable should
7573 be the relative path from the current @file{Makefile.am} to
7574 @file{texinfo.tex}:
7576 @example
7577 TEXINFO_TEX = ../doc/texinfo.tex
7578 @end example
7579 @end vtable
7582 @node Man pages
7583 @section Man pages
7585 @cindex @code{_MANS} primary, defined
7586 @cindex @code{MANS} primary, defined
7587 @cindex Primary variable, @code{MANS}
7589 @vindex _MANS
7590 @vindex man_MANS
7591 A package can also include man pages (but see the GNU standards on this
7592 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7593 pages are declared using the @code{MANS} primary.  Generally the
7594 @code{man_MANS} variable is used.  Man pages are automatically installed in
7595 the correct subdirectory of @code{mandir}, based on the file extension.
7597 File extensions such as @file{.1c} are handled by looking for the valid
7598 part of the extension and using that to determine the correct
7599 subdirectory of @code{mandir}.  Valid section names are the digits
7600 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7602 Sometimes developers prefer to name a man page something like
7603 @file{foo.man} in the source, and then rename it to have the correct
7604 suffix, for example @file{foo.1}, when installing the file.  Automake
7605 also supports this mode.  For a valid section named @var{SECTION},
7606 there is a corresponding directory named @samp{man@var{SECTION}dir},
7607 and a corresponding @code{_MANS} variable.  Files listed in such a
7608 variable are installed in the indicated section.  If the file already
7609 has a valid suffix, then it is installed as-is; otherwise the file
7610 suffix is changed to match the section.
7612 For instance, consider this example:
7613 @example
7614 man1_MANS = rename.man thesame.1 alsothesame.1c
7615 @end example
7617 In this case, @file{rename.man} will be renamed to @file{rename.1} when
7618 installed, but the other files will keep their names.
7620 @cindex Target, @code{install-man}
7621 @cindex Option, @option{no-installman}
7622 @cindex @code{install-man} target
7623 @cindex @option{no-installman} option
7624 @opindex no-installman
7625 @trindex install-man
7627 By default, man pages are installed by @samp{make install}.  However,
7628 since the GNU project does not require man pages, many maintainers do
7629 not expend effort to keep the man pages up to date.  In these cases, the
7630 @option{no-installman} option will prevent the man pages from being
7631 installed by default.  The user can still explicitly install them via
7632 @samp{make install-man}.
7634 Man pages are not currently considered to be source, because it is not
7635 uncommon for man pages to be automatically generated.  Therefore they
7636 are not automatically included in the distribution.  However, this can
7637 be changed by use of the @code{dist_} prefix.  For instance here is
7638 how to distribute and install the two man pages of GNU @command{cpio}
7639 (which includes both Texinfo documentation and man pages):
7641 @example
7642 dist_man_MANS = cpio.1 mt.1
7643 @end example
7645 The @code{nobase_} prefix is meaningless for man pages and is
7646 disallowed.
7649 @node Install
7650 @chapter What Gets Installed
7652 @cindex Installation support
7653 @cindex @samp{make install} support
7655 @section Basics of installation
7657 Naturally, Automake handles the details of actually installing your
7658 program once it has been built.  All files named by the various
7659 primaries are automatically installed in the appropriate places when the
7660 user runs @samp{make install}.
7662 A file named in a primary is installed by copying the built file into
7663 the appropriate directory.  The base name of the file is used when
7664 installing.
7666 @example
7667 bin_PROGRAMS = hello subdir/goodbye
7668 @end example
7670 In this example, both @samp{hello} and @samp{goodbye} will be installed
7671 in @samp{$(bindir)}.
7673 Sometimes it is useful to avoid the basename step at install time.  For
7674 instance, you might have a number of header files in subdirectories of
7675 the source tree that are laid out precisely how you want to install
7676 them.  In this situation you can use the @code{nobase_} prefix to
7677 suppress the base name step.  For example:
7679 @example
7680 nobase_include_HEADERS = stdio.h sys/types.h
7681 @end example
7683 Will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
7684 in @samp{$(includedir)/sys}.
7686 @section The two parts of install
7688 Automake generates separate @code{install-data} and @code{install-exec}
7689 rules, in case the installer is installing on multiple machines that
7690 share directory structure---these targets allow the machine-independent
7691 parts to be installed only once.  @code{install-exec} installs
7692 platform-dependent files, and @code{install-data} installs
7693 platform-independent files.  The @code{install} target depends on both
7694 of these targets.  While Automake tries to automatically segregate
7695 objects into the correct category, the @file{Makefile.am} author is, in
7696 the end, responsible for making sure this is done correctly.
7697 @trindex install-data
7698 @trindex install-exec
7699 @trindex install
7700 @cindex Install, two parts of
7702 Variables using the standard directory prefixes @samp{data},
7703 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
7704 @samp{pkgdata}, or @samp{pkginclude} are installed by
7705 @code{install-data}.
7707 Variables using the standard directory prefixes @samp{bin},
7708 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
7709 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
7711 For instance, @code{data_DATA} files are installed by @code{install-data},
7712 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
7714 Any variable using a user-defined directory prefix with @samp{exec} in
7715 the name (e.g., @code{myexecbin_PROGRAMS}) is installed by
7716 @code{install-exec}.  All other user-defined prefixes are installed by
7717 @code{install-data}.
7719 @section Extending installation
7721 It is possible to extend this mechanism by defining an
7722 @code{install-exec-local} or @code{install-data-local} rule.  If these
7723 rules exist, they will be run at @samp{make install} time.  These
7724 rules can do almost anything; care is required.
7725 @trindex install-exec-local
7726 @trindex install-data-local
7728 Automake also supports two install hooks, @code{install-exec-hook} and
7729 @code{install-data-hook}.  These hooks are run after all other install
7730 rules of the appropriate type, exec or data, have completed.  So, for
7731 instance, it is possible to perform post-installation modifications
7732 using an install hook.  @ref{Extending} gives some examples.
7733 @cindex Install hook
7735 @section Staged installs
7737 @vindex DESTDIR
7738 Automake generates support for the @code{DESTDIR} variable in all
7739 install rules.  @code{DESTDIR} is used during the @samp{make install}
7740 step to relocate install objects into a staging area.  Each object and
7741 path is prefixed with the value of @code{DESTDIR} before being copied
7742 into the install area.  Here is an example of typical DESTDIR usage:
7744 @example
7745 mkdir /tmp/staging &&
7746 make DESTDIR=/tmp/staging install
7747 @end example
7749 The @command{mkdir} command avoids a security problem if the attacker
7750 creates a symbolic link from @file{/tmp/staging} to a victim area;
7751 then @command{make} places install objects in a directory tree built under
7752 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
7753 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
7754 would install @file{/tmp/staging/gnu/bin/foo} and
7755 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
7757 This feature is commonly used to build install images and packages
7758 (@pxref{DESTDIR}).
7760 Support for @code{DESTDIR} is implemented by coding it directly into
7761 the install rules.  If your @file{Makefile.am} uses a local install
7762 rule (e.g., @code{install-exec-local}) or an install hook, then you
7763 must write that code to respect @code{DESTDIR}.
7765 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
7766 for another usage example.
7768 @section Rules for the user
7770 Automake also generates rules for targets @code{uninstall},
7771 @code{installdirs}, and @code{install-strip}.
7772 @trindex uninstall
7773 @trindex installdirs
7774 @trindex install-strip
7776 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
7777 There is no notion of separate uninstalls for ``exec'' and ``data'', as
7778 these features would not provide additional functionality.
7780 Note that @code{uninstall} is not meant as a replacement for a real
7781 packaging tool.
7784 @node Clean
7785 @chapter What Gets Cleaned
7787 @cindex @samp{make clean} support
7789 The GNU Makefile Standards specify a number of different clean rules.
7790 @xref{Standard Targets, , Standard Targets for Users, standards,
7791 The GNU Coding Standards}.
7793 Generally the files that can be cleaned are determined automatically by
7794 Automake.  Of course, Automake also recognizes some variables that can
7795 be defined to specify additional files to clean.  These variables are
7796 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
7797 @code{MAINTAINERCLEANFILES}.
7798 @vindex MOSTLYCLEANFILES
7799 @vindex CLEANFILES
7800 @vindex DISTCLEANFILES
7801 @vindex MAINTAINERCLEANFILES
7803 @trindex mostlyclean-local
7804 @trindex clean-local
7805 @trindex distclean-local
7806 @trindex maintainer-clean-local
7807 When cleaning involves more than deleting some hard-coded list of
7808 files, it is also possible to supplement the cleaning rules with your
7809 own commands.  Simply define a rule for any of the
7810 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
7811 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
7812 case is deleting a directory, for instance, a directory created by the
7813 test suite:
7815 @example
7816 clean-local:
7817         -rm -rf testSubDir
7818 @end example
7820 As the GNU Standards aren't always explicit as to which files should
7821 be removed by which rule, we've adopted a heuristic that we believe
7822 was first formulated by Fran@,{c}ois Pinard:
7824 @itemize @bullet
7825 @item
7826 If @command{make} built it, and it is commonly something that one would
7827 want to rebuild (for instance, a @file{.o} file), then
7828 @code{mostlyclean} should delete it.
7830 @item
7831 Otherwise, if @command{make} built it, then @code{clean} should delete it.
7833 @item
7834 If @command{configure} built it, then @code{distclean} should delete it.
7836 @item
7837 If the maintainer built it (for instance, a @file{.info} file), then
7838 @code{maintainer-clean} should delete it.  However
7839 @code{maintainer-clean} should not delete anything that needs to exist
7840 in order to run @samp{./configure && make}.
7841 @end itemize
7843 We recommend that you follow this same set of heuristics in your
7844 @file{Makefile.am}.
7847 @node Dist
7848 @chapter What Goes in a Distribution
7850 @section Basics of distribution
7852 @cindex @samp{make dist}
7854 @vindex PACKAGE
7855 @vindex VERSION
7856 @trindex dist
7857 The @code{dist} rule in the generated @file{Makefile.in} can be used
7858 to generate a gzipped @code{tar} file and other flavors of archive for
7859 distribution.  The files is named based on the @code{PACKAGE} and
7860 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
7861 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
7862 @samp{@var{package}-@var{version}.tar.gz}.
7863 @vindex GZIP_ENV
7864 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
7865 is run.  The default setting is @option{--best}.
7867 @cindex @code{m4_include}, distribution
7868 @cindex @code{include}, distribution
7869 @acindex m4_include
7870 @cmindex include
7871 For the most part, the files to distribute are automatically found by
7872 Automake: all source files are automatically included in a distribution,
7873 as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
7874 has a built-in list of commonly used files that are automatically
7875 included if they are found in the current directory (either physically,
7876 or as the target of a @file{Makefile.am} rule).  This list is printed by
7877 @samp{automake --help}.  Also, files that are read by @command{configure}
7878 (i.e.@: the source files corresponding to the files specified in various
7879 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
7880 automatically distributed.  Files included in @file{Makefile.am}s (using
7881 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
7882 helper scripts installed with @samp{automake --add-missing} are also
7883 distributed.
7885 @vindex EXTRA_DIST
7886 Still, sometimes there are files that must be distributed, but which
7887 are not covered in the automatic rules.  These files should be listed in
7888 the @code{EXTRA_DIST} variable.  You can mention files from
7889 subdirectories in @code{EXTRA_DIST}.
7891 You can also mention a directory in @code{EXTRA_DIST}; in this case the
7892 entire directory will be recursively copied into the distribution.
7893 Please note that this will also copy @emph{everything} in the directory,
7894 including CVS/RCS version control files.  We recommend against using
7895 this feature.
7897 @vindex SUBDIRS
7898 @vindex DIST_SUBDIRS
7899 If you define @code{SUBDIRS}, Automake will recursively include the
7900 subdirectories in the distribution.  If @code{SUBDIRS} is defined
7901 conditionally (@pxref{Conditionals}), Automake will normally include
7902 all directories that could possibly appear in @code{SUBDIRS} in the
7903 distribution.  If you need to specify the set of directories
7904 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
7905 exact list of subdirectories to include in the distribution
7906 (@pxref{Conditional Subdirectories}).
7909 @section Fine-grained distribution control
7911 @vindex dist_
7912 @vindex nodist_
7913 Sometimes you need tighter control over what does @emph{not} go into the
7914 distribution; for instance, you might have source files that are
7915 generated and that you do not want to distribute.  In this case
7916 Automake gives fine-grained control using the @code{dist} and
7917 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
7918 prefixed with @code{dist_} to add the listed files to the distribution.
7919 Similarly, @code{nodist_} can be used to omit the files from the
7920 distribution.
7922 As an example, here is how you would cause some data to be distributed
7923 while leaving some source code out of the distribution:
7925 @example
7926 dist_data_DATA = distribute-this
7927 bin_PROGRAMS = foo
7928 nodist_foo_SOURCES = do-not-distribute.c
7929 @end example
7931 @section The dist hook
7933 @trindex dist-hook
7935 Occasionally it is useful to be able to change the distribution before
7936 it is packaged up.  If the @code{dist-hook} rule exists, it is run
7937 after the distribution directory is filled, but before the actual tar
7938 (or shar) file is created.  One way to use this is for distributing
7939 files in subdirectories for which a new @file{Makefile.am} is overkill:
7941 @example
7942 dist-hook:
7943         mkdir $(distdir)/random
7944         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
7945 @end example
7947 Another way to use this is for removing unnecessary files that get
7948 recursively included by specifying a directory in EXTRA_DIST:
7950 @example
7951 EXTRA_DIST = doc
7953 dist-hook:
7954         rm -rf `find $(distdir)/doc -name CVS`
7955 @end example
7957 @vindex distdir
7958 @vindex top_distdir
7959 Two variables that come handy when writing @code{dist-hook} rules are
7960 @samp{$(distdir)} and @samp{$(top_distdir)}.
7962 @samp{$(distdir)} points to the directory where the @code{dist} rule
7963 will copy files from the current directory before creating the
7964 tarball.  If you are at the top-level directory, then @samp{distdir =
7965 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
7966 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
7967 @samp{$(distdir)} can be a relative or absolute path, do not assume
7968 any form.
7970 @samp{$(top_distdir)} always points to the root directory of the
7971 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
7972 In the @file{foo/} subdirectory
7973 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
7974 @samp{$(top_distdir)} too can be a relative or absolute path.
7976 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
7977 (@pxref{Subpackages}), then @samp{$(distdir)} and
7978 @samp{$(top_distdir)} are relative to the package where @samp{make
7979 dist} was run, not to any sub-packages involved.
7981 @section Checking the distribution
7983 @cindex @samp{make distcheck}
7984 @cindex @samp{make distcleancheck}
7985 @vindex distcleancheck_listfiles
7986 @cindex @samp{make distuninstallcheck}
7987 @vindex distuninstallcheck_listfiles
7989 @trindex distcheck
7990 Automake also generates a @code{distcheck} rule that can be of help to
7991 ensure that a given distribution will actually work.  @code{distcheck}
7992 makes a distribution, then tries to do a @code{VPATH} build
7993 (@pxref{VPATH Builds}), run the test suite, and finally make another
7994 tarball to ensure the distribution is self-contained.
7996 @vindex DISTCHECK_CONFIGURE_FLAGS
7997 Building the package involves running @samp{./configure}.  If you need
7998 to supply additional flags to @command{configure}, define them in the
7999 @code{DISTCHECK_CONFIGURE_FLAGS} variable, either in your top-level
8000 @file{Makefile.am}, or on the command line when invoking @command{make}.
8002 @trindex distcheck-hook
8003 If the @code{distcheck-hook} rule is defined in your top-level
8004 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8005 the new distribution has been unpacked, but before the unpacked copy
8006 is configured and built.  Your @code{distcheck-hook} can do almost
8007 anything, though as always caution is advised.  Generally this hook is
8008 used to check for potential distribution errors not caught by the
8009 standard mechanism.  Note that @code{distcheck-hook} as well as
8010 @code{DISTCHECK_CONFIGURE_FLAGS} are not honored in a subpackage
8011 @file{Makefile.am}, but the @code{DISTCHECK_CONFIGURE_FLAGS} are
8012 passed down to the @command{configure} script of the subpackage.
8014 @trindex distcleancheck
8015 @vindex DISTCLEANFILES
8016 @vindex distcleancheck_listfiles
8017 Speaking of potential distribution errors, @code{distcheck} also
8018 ensures that the @code{distclean} rule actually removes all built
8019 files.  This is done by running @samp{make distcleancheck} at the end of
8020 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8021 @code{distclean} and then make sure the build tree has been emptied by
8022 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8023 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8024 variable (@pxref{Clean}).
8026 The @code{distcleancheck} behavior should be OK for most packages,
8027 otherwise you have the possibility to override the definition of
8028 either the @code{distcleancheck} rule, or the
8029 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8030 @code{distcleancheck} completely, add the following rule to your
8031 top-level @file{Makefile.am}:
8033 @example
8034 distcleancheck:
8035         @@:
8036 @end example
8038 If you want @code{distcleancheck} to ignore built files that have not
8039 been cleaned because they are also part of the distribution, add the
8040 following definition instead:
8042 @example
8043 distcleancheck_listfiles = \
8044   find -type f -exec sh -c 'test -f $(srcdir)/@{@} || echo @{@}' ';'
8045 @end example
8047 The above definition is not the default because it's usually an error if
8048 your Makefiles cause some distributed files to be rebuilt when the user
8049 build the package.  (Think about the user missing the tool required to
8050 build the file; or if the required tool is built by your package,
8051 consider the cross-compilation case where it can't be run.)  There is
8052 a FAQ entry about this (@pxref{distcleancheck}), make sure you read it
8053 before playing with @code{distcleancheck_listfiles}.
8055 @code{distcheck} also checks that the @code{uninstall} rule works
8056 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8057 by invoking @samp{make uninstall}, and then it checks the install tree
8058 to see if any files are left over.  This check will make sure that you
8059 correctly coded your @code{uninstall}-related rules.
8061 By default, the checking is done by the @code{distuninstallcheck} rule,
8062 and the list of files in the install tree is generated by
8063 @samp{$(distuninstallcheck_listfiles}) (this is a variable whose value is
8064 a shell command to run that prints the list of files to stdout).
8066 Either of these can be overridden to modify the behavior of
8067 @code{distcheck}.  For instance, to disable this check completely, you
8068 would write:
8070 @example
8071 distuninstallcheck:
8072         @@:
8073 @end example
8075 @section The types of distributions
8077 Automake generates rules to provide archives of the project for
8078 distributions in various formats.  Their targets are:
8080 @table @asis
8081 @item @code{dist-bzip2}
8082 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8083 frequently smaller than gzipped archives.
8084 @trindex dist-bzip2
8086 @item @code{dist-gzip}
8087 Generate a gzip tar archive of the distribution.
8088 @trindex dist-gzip
8090 @item @code{dist-shar}
8091 Generate a shar archive of the distribution.
8092 @trindex dist-shar
8094 @item @code{dist-zip}
8095 Generate a zip archive of the distribution.
8096 @trindex dist-zip
8098 @item @code{dist-tarZ}
8099 Generate a compressed tar archive of
8100 the distribution.
8101 @trindex dist-tarZ
8102 @end table
8104 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8105 create archives in all the enabled formats, @ref{Options}.  By
8106 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8109 @node Tests
8110 @chapter Support for test suites
8112 @cindex Test suites
8113 @cindex @code{make check}
8114 @trindex check
8116 Automake supports two forms of test suites.
8118 @section Simple Tests
8120 If the variable @code{TESTS} is defined, its value is taken to be a
8121 list of programs or scripts to run in order to do the testing.
8122 Programs needing data files should look for them in @code{srcdir}
8123 (which is both an environment variable and a make variable) so they
8124 work when building in a separate directory (@pxref{Build Directories,
8125 , Build Directories , autoconf, The Autoconf Manual}), and in
8126 particular for the @code{distcheck} rule (@pxref{Dist}).
8128 @cindex Exit status 77, special interpretation
8130 The number of failures will be printed at the end of the run.  If a
8131 given test program exits with a status of 77, then its result is ignored
8132 in the final count.  This feature allows non-portable tests to be
8133 ignored in environments where they don't make sense.
8135 @vindex TESTS
8136 @vindex TESTS_ENVIRONMENT
8137 The variable @code{TESTS_ENVIRONMENT} can be used to set environment
8138 variables for the test run; the environment variable @code{srcdir} is
8139 set in the rule.  If all your test programs are scripts, you can also
8140 set @code{TESTS_ENVIRONMENT} to an invocation of the shell (e.g.
8141 @samp{$(SHELL) -x} can be useful for debugging the tests), or any other
8142 interpreter.  For instance the following setup is used by the Automake
8143 package to run four tests in Perl.
8144 @example
8145 TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
8146 TESTS = Condition.pl DisjConditions.pl Version.pl Wrap.pl
8147 @end example
8150 @cindex Tests, expected failure
8151 @cindex Expected test failure
8153 You may define the variable @code{XFAIL_TESTS} to a list of tests
8154 (usually a subset of @code{TESTS}) that are expected to fail.  This will
8155 reverse the result of those tests.
8156 @vindex XFAIL_TESTS
8158 Automake ensures that each file listed in @code{TESTS} is built before
8159 any tests are run; you can list both source and derived programs (or
8160 scripts) in @code{TESTS}; the generated rule will look both in
8161 @code{srcdir} and @file{.}.  For instance, you might want to run a C
8162 program as a test.  To do this you would list its name in @code{TESTS}
8163 and also in @code{check_PROGRAMS}, and then specify it as you would
8164 any other program.
8166 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8167 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8168 not during @code{make all}.  You should list there any program needed
8169 by your tests that does not need to be built by @code{make all}.  Note
8170 that @code{check_PROGRAMS} are @emph{not} automatically added to
8171 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8172 by the tests, not the tests themselves.  Of course you can set
8173 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8175 @section DejaGnu Tests
8177 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
8178 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
8179 assumed.  The variable @code{DEJATOOL} is a list of names that are
8180 passed, one at a time, as the @option{--tool} argument to
8181 @command{runtest} invocations; it defaults to the name of the package.
8183 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
8184 @option{--srcdir} flags that are passed to dejagnu by default; this can be
8185 overridden if necessary.
8186 @vindex RUNTESTDEFAULTFLAGS
8188 The variables @code{EXPECT} and @code{RUNTEST} can
8189 also be overridden to provide project-specific values.  For instance,
8190 you will need to do this if you are testing a compiler toolchain,
8191 because the default values do not take into account host and target
8192 names.
8193 @opindex dejagnu
8194 @vindex DEJATOOL
8195 @vindex EXPECT
8196 @vindex RUNTEST
8198 The contents of the variable @code{RUNTESTFLAGS} are passed to the
8199 @code{runtest} invocation.  This is considered a ``user variable''
8200 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
8201 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
8202 @vindex RUNTESTFLAGS
8203 @vindex AM_RUNTESTFLAGS
8205 @cindex @file{site.exp}
8206 Automake will generate rules to create a local @file{site.exp} file,
8207 defining various variables detected by @command{configure}.  This file
8208 is automatically read by DejaGnu.  It is OK for the user of a package
8209 to edit this file in order to tune the test suite.  However this is
8210 not the place where the test suite author should define new variables:
8211 this should be done elsewhere in the real test suite code.
8212 Especially, @file{site.exp} should not be distributed.
8214 For more information regarding DejaGnu test suites, see @ref{Top, , ,
8215 dejagnu, The DejaGnu Manual}.
8217 In either case, the testing is done via @samp{make check}.
8219 @section Install Tests
8221 The @code{installcheck} target is available to the user as a way to
8222 run any tests after the package has been installed.  You can add tests
8223 to this by writing an @code{installcheck-local} rule.
8226 @node Rebuilding
8227 @chapter Rebuilding Makefiles
8228 @cindex rebuild rules
8230 Automake generates rules to automatically rebuild @file{Makefile}s,
8231 @file{configure}, and other derived files like @file{Makefile.in}.
8233 @acindex AM_MAINTAINER_MODE
8234 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
8235 these automatic rebuilding rules are only enabled in maintainer mode.
8237 @vindex ACLOCAL_AMFLAGS
8238 Sometimes you need to run @command{aclocal} with an argument like
8239 @option{-I} to tell it where to find @file{.m4} files.  Since
8240 sometimes @command{make} will automatically run @command{aclocal}, you
8241 need a way to specify these arguments.  You can do this by defining
8242 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
8243 to @command{aclocal}.  This variable is only useful in the top-level
8244 @file{Makefile.am}.
8246 @vindex CONFIG_STATUS_DEPENDENCIES
8247 @vindex CONFIGURE_DEPENDENCIES
8248 @cindex @file{version.sh}, example
8249 @cindex @file{version.m4}, example
8251 Sometimes it is convenient to supplement the rebuild rules for
8252 @file{configure} or @file{config.status} with additional dependencies.
8253 The variables @code{CONFIGURE_DEPENDENCIES} and
8254 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
8255 dependencies.  These variable should be defined in all
8256 @file{Makefile}s of the tree (because these two rebuild rules are
8257 output in all them), so it is safer and easier to @code{AC_SUBST} them
8258 from @file{configure.ac}.  For instance, the following statement will
8259 cause @file{configure} to be rerun each time @file{version.sh} is
8260 changed.
8261 @example
8262 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
8263 @end example
8264 @noindent
8265 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
8266 is to be used in all @file{Makefile}s, its value must be sensible at
8267 any level in the build hierarchy.
8269 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
8270 @code{CONFIG_STATUS_DEPENDENCIES}.
8272 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
8273 @file{configure} rule, whose effect is to run @command{autoconf}.  This
8274 variable should be seldom used, because @command{automake} already tracks
8275 @code{m4_include}d files.  However it can be useful when playing
8276 tricky games with @code{m4_esyscmd} or similar non-recommendable
8277 macros with side effects.
8279 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
8280 @file{config.status} rule, whose effect is to run @file{configure}.
8281 This variable should therefore carry any non-standard source that may
8282 be read as a side effect of running configure, like @file{version.sh}
8283 in the example above.
8285 Speaking of @file{version.sh} scripts, we recommend against them
8286 today.  They are mainly used when the version of a package is updated
8287 automatically by a script (e.g., in daily builds).  Here is what some
8288 old-style @file{configure.ac}s may look like:
8289 @example
8290 AC_INIT
8291 . $srcdir/version.sh
8292 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
8293 @dots{}
8294 @end example
8295 @noindent
8296 Here, @file{version.sh} is a shell fragment that sets
8297 @code{VERSION_NUMBER}.  The problem with this example is that
8298 @command{automake} cannot track dependencies (listing @file{version.sh}
8299 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
8300 to the user), and that it uses the obsolete form of @code{AC_INIT} and
8301 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
8302 straightforward, because shell variables are not allowed in
8303 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
8304 replaced by an M4 file that is included by @file{configure.ac}:
8305 @example
8306 m4_include([version.m4])
8307 AC_INIT([name], VERSION_NUMBER)
8308 AM_INIT_AUTOMAKE
8309 @dots{}
8310 @end example
8311 @noindent
8312 Here @file{version.m4} could contain something like
8313 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
8314 second form is that @command{automake} will take care of the
8315 dependencies when defining the rebuild rule, and will also distribute
8316 the file automatically.  An inconvenience is that @command{autoconf}
8317 will now be rerun each time the version number is bumped, when only
8318 @file{configure} had to be rerun in the previous setup.
8321 @node Options
8322 @chapter Changing Automake's Behavior
8324 Various features of Automake can be controlled by options in the
8325 @file{Makefile.am}.  Such options are applied on a per-@file{Makefile}
8326 basis when listed in a special @file{Makefile} variable named
8327 @code{AUTOMAKE_OPTIONS}.  They are applied globally to all processed
8328 @file{Makefiles} when listed in the first argument of
8329 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}.  Currently understood
8330 options are:
8331 @vindex AUTOMAKE_OPTIONS
8333 @table @asis
8334 @item @option{gnits}
8335 @itemx @option{gnu}
8336 @itemx @option{foreign}
8337 @itemx @option{cygnus}
8338 @cindex Option, @option{gnits}
8339 @cindex Option, @option{gnu}
8340 @cindex Option, @option{foreign}
8341 @cindex Option, @option{cygnus}
8342 @opindex gnits
8343 @opindex gnu
8344 @opindex foreign
8345 @opindex cygnus
8347 Set the strictness as appropriate.  The @option{gnits} option also
8348 implies options @option{readme-alpha} and @option{check-news}.
8350 @item @option{ansi2knr}
8351 @itemx @option{@var{path}/ansi2knr}
8352 @cindex Option, @option{ansi2knr}
8353 @opindex ansi2knr
8354 Turn on the obsolete de-ANSI-fication feature.  @xref{ANSI}.  If preceded by a
8355 path, the generated @file{Makefile.in} will look in the specified
8356 directory to find the @file{ansi2knr} program.  The path should be a
8357 relative path to another directory in the same distribution (Automake
8358 currently does not check this).
8360 @item @option{check-news}
8361 @cindex Option, @option{check-news}
8362 @opindex check-news
8363 Cause @samp{make dist} to fail unless the current version number appears
8364 in the first few lines of the @file{NEWS} file.
8366 @item @option{dejagnu}
8367 @cindex Option, @option{dejagnu}
8368 @opindex dejagnu
8369 Cause @command{dejagnu}-specific rules to be generated.  @xref{Tests}.
8371 @item @option{dist-bzip2}
8372 @cindex Option, @option{dist-bzip2}
8373 @opindex dist-bzip2
8374 Hook @code{dist-bzip2} to @code{dist}.
8375 @trindex dist-bzip2
8377 @item @option{dist-shar}
8378 @cindex Option, @option{dist-shar}
8379 @opindex dist-shar
8380 Hook @code{dist-shar} to @code{dist}.
8381 @trindex dist-shar
8383 @item @option{dist-zip}
8384 @cindex Option, @option{dist-zip}
8385 @opindex dist-zip
8386 Hook @code{dist-zip} to @code{dist}.
8387 @trindex dist-zip
8389 @item @option{dist-tarZ}
8390 @cindex Option, @option{dist-tarZ}
8391 @opindex dist-tarZ
8392 Hook @code{dist-tarZ} to @code{dist}.
8393 @trindex dist-tarZ
8395 @item @option{filename-length-max=99}
8396 @cindex Option, @option{filename-length-max=99}
8397 @opindex filename-length-max=99
8398 Abort if file names longer than 99 characters are found during
8399 @samp{make dist}.  Such long file names are generally considered not to
8400 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
8401 options below.  This option should be used in the top-level
8402 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
8403 @file{configure.ac}, it will be ignored otherwise.  It will also be
8404 ignored in sub-packages of nested packages (@pxref{Subpackages}).
8406 @item @option{no-define}
8407 @cindex Option, @option{no-define}
8408 @opindex no-define
8409 This options is meaningful only when passed as an argument to
8410 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
8411 @code{VERSION} variables to be @code{AC_DEFINE}d.
8413 @item @option{no-dependencies}
8414 @cindex Option, @option{no-dependencies}
8415 @opindex no-dependencies
8416 This is similar to using @option{--ignore-deps} on the command line,
8417 but is useful for those situations where you don't have the necessary
8418 bits to make automatic dependency tracking work
8419 (@pxref{Dependencies}).  In this case the effect is to effectively
8420 disable automatic dependency tracking.
8422 @item @option{no-dist}
8423 @cindex Option, @option{no-dist}
8424 @opindex no-dist
8425 Don't emit any code related to @code{dist} target.  This is useful
8426 when a package has its own method for making distributions.
8428 @item @option{no-dist-gzip}
8429 @cindex Option, @option{no-dist-gzip}
8430 @opindex no-dist-gzip
8431 Do not hook @code{dist-gzip} to @code{dist}.
8432 @trindex no-dist-gzip
8434 @item @option{no-exeext}
8435 @cindex Option, @option{no-exeext}
8436 @opindex no-exeext
8437 If your @file{Makefile.am} defines a rule for target @code{foo}, it
8438 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
8439 necessary when @code{EXEEXT} is found to be empty.  However, by
8440 default automake will generate an error for this use.  The
8441 @option{no-exeext} option will disable this error.  This is intended for
8442 use only where it is known in advance that the package will not be
8443 ported to Windows, or any other operating system using extensions on
8444 executables.
8446 @item @option{no-installinfo}
8447 @cindex Option, @option{no-installinfo}
8448 @opindex no-installinfo
8449 The generated @file{Makefile.in} will not cause info pages to be built
8450 or installed by default.  However, @code{info} and @code{install-info}
8451 targets will still be available.  This option is disallowed at
8452 @option{gnu} strictness and above.
8453 @trindex info
8454 @trindex install-info
8456 @item @option{no-installman}
8457 @cindex Option, @option{no-installman}
8458 @opindex no-installman
8459 The generated @file{Makefile.in} will not cause man pages to be
8460 installed by default.  However, an @code{install-man} target will still
8461 be available for optional installation.  This option is disallowed at
8462 @option{gnu} strictness and above.
8463 @trindex install-man
8465 @item @option{nostdinc}
8466 @cindex Option, @option{nostdinc}
8467 @opindex nostdinc
8468 This option can be used to disable the standard @option{-I} options that
8469 are ordinarily automatically provided by Automake.
8471 @item @option{no-texinfo.tex}
8472 @cindex Option, @option{no-texinfo.tex}
8473 @opindex no-texinfo.tex
8474 Don't require @file{texinfo.tex}, even if there are texinfo files in
8475 this directory.
8477 @item @option{readme-alpha}
8478 @cindex Option, @option{readme-alpha}
8479 @opindex readme-alpha
8480 If this release is an alpha release, and the file @file{README-alpha}
8481 exists, then it will be added to the distribution.  If this option is
8482 given, version numbers are expected to follow one of two forms.  The
8483 first form is @samp{@var{MAJOR}.@var{MINOR}.@var{ALPHA}}, where each
8484 element is a number; the final period and number should be left off for
8485 non-alpha releases.  The second form is
8486 @samp{@var{MAJOR}.@var{MINOR}@var{ALPHA}}, where @var{ALPHA} is a
8487 letter; it should be omitted for non-alpha releases.
8489 @item @option{std-options}
8490 @cindex Options, @option{std-options}
8491 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
8492 @cindex @option{--help} check
8493 @cindex @option{--version} check
8494 @opindex std-options
8496 Make the @code{installcheck} rule check that installed scripts and
8497 programs support the @option{--help} and @option{--version} options.
8498 This also provides a basic check that the program's
8499 run-time dependencies are satisfied after installation.
8501 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
8502 In a few situations, programs (or scripts) have to be exempted from this
8503 test.  For instance, @command{false} (from GNU sh-utils) is never
8504 successful, even for @option{--help} or @option{--version}.  You can list
8505 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
8506 Programs (not scripts) listed in this variable should be suffixed by
8507 @samp{$(EXEEXT)} for the sake of Win32 or OS/2.  For instance, suppose we
8508 build @file{false} as a program but @file{true.sh} as a script, and that
8509 neither of them support @option{--help} or @option{--version}:
8511 @example
8512 AUTOMAKE_OPTIONS = std-options
8513 bin_PROGRAMS = false ...
8514 bin_SCRIPTS = true.sh ...
8515 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
8516 @end example
8518 @item @option{subdir-objects}
8519 @cindex Options, @option{subdir-objects}
8520 @opindex subdir-objects
8521 If this option is specified, then objects are placed into the
8522 subdirectory of the build directory corresponding to the subdirectory of
8523 the source file.  For instance, if the source file is
8524 @file{subdir/file.cxx}, then the output file would be
8525 @file{subdir/file.o}.
8527 In order to use this option with C sources, you should add
8528 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
8530 @anchor{tar-formats}
8531 @item @option{tar-v7}
8532 @itemx @option{tar-ustar}
8533 @itemx @option{tar-pax}
8534 @cindex Option, @option{tar-v7}
8535 @cindex Option, @option{tar-ustar}
8536 @cindex Option, @option{tar-pax}
8537 @cindex @command{tar} formats
8538 @cindex v7 @command{tar} format
8539 @cindex ustar format
8540 @cindex pax format
8541 @opindex tar-v7
8542 @opindex tar-ustar
8543 @opindex tar-pax
8545 These three mutually exclusive options select the tar format to use
8546 when generating tarballs with @samp{make dist}.  (The tar file created
8547 is then compressed according to the set of @option{no-dist-gzip},
8548 @option{dist-bzip2} and @option{dist-tarZ} options in use.)
8550 These options must be passed as argument to @code{AM_INIT_AUTOMAKE}
8551 (@pxref{Macros}) because they can require additional configure checks.
8552 Automake will complain if it sees such options in an
8553 @code{AUTOMAKE_OPTIONS} variable.
8555 @option{tar-v7} selects the old V7 tar format.  This is the historical
8556 default.  This antiquated format is understood by all tar
8557 implementations and supports file names with up to 99 characters.  When
8558 given longer file names some tar implementations will diagnose the
8559 problem while other will generate broken tarballs or use non-portable
8560 extensions.  Furthermore, the V7 format cannot store empty
8561 directories.  When using this format, consider using the
8562 @option{filename-length-max=99} option to catch file names too long.
8564 @option{tar-ustar} selects the ustar format defined by POSIX
8565 1003.1-1988.  This format is believed to be old enough to be portable.
8566 It fully supports empty directories.  It can store file names with up
8567 to 256 characters, provided that the file name can be split at
8568 directory separator in two parts, first of them being at most 155
8569 bytes long.  So, in most cases the maximum file name length will be
8570 shorter than 256 characters.  However you may run against broken tar
8571 implementations that incorrectly handle file names longer than 99
8572 characters (please report them to @email{bug-automake@@gnu.org} so we
8573 can document this accurately).
8575 @option{tar-pax} selects the new pax interchange format defined by POSIX
8576 1003.1-2001.  It does not limit the length of file names.  However,
8577 this format is very young and should probably be restricted to
8578 packages that target only very modern platforms.  There are moves to
8579 change the pax format in an upward-compatible way, so this option may
8580 refer to a more recent version in the future.
8582 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
8583 further discussion about tar formats.
8585 @command{configure} knows several ways to construct these formats.  It
8586 will not abort if it cannot find a tool up to the task (so that the
8587 package can still be built), but @samp{make dist} will fail.
8589 @item @var{version}
8590 @cindex Option, @var{version}
8591 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
8592 newer than the version specified, creation of the @file{Makefile.in}
8593 will be suppressed.
8595 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
8596 @cindex Option, warnings
8597 @cindex Option, @option{-W@var{category}}
8598 @cindex Option, @option{--warnings=@var{category}}
8599 These options behave exactly like their command-line counterpart
8600 (@pxref{Invoking Automake}).  This allows you to enable or disable some
8601 warning categories on a per-file basis.  You can also setup some warnings
8602 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
8603 in your @file{configure.ac}.
8605 @end table
8607 Unrecognized options are diagnosed by @command{automake}.
8609 If you want an option to apply to all the files in the tree, you can use
8610 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
8611 @xref{Macros}.
8614 @node Miscellaneous
8615 @chapter Miscellaneous Rules
8617 There are a few rules and variables that didn't fit anywhere else.
8619 @menu
8620 * Tags::                        Interfacing to etags and mkid
8621 * Suffixes::                    Handling new file extensions
8622 * Multilibs::                   Support for multilibs.
8623 @end menu
8626 @node Tags
8627 @section Interfacing to @command{etags}
8629 @cindex @file{TAGS} support
8631 Automake will generate rules to generate @file{TAGS} files for use with
8632 GNU Emacs under some circumstances.
8634 @trindex tags
8635 If any C, C++ or Fortran 77 source code or headers are present, then
8636 @code{tags} and @code{TAGS} rules will be generated for the directory.
8637 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
8638 @code{_LISP} primaries will be used to generate tags.  Note that
8639 generated source files that are not distributed must be declared in
8640 variables like @code{nodist_noinst_HEADERS} or
8641 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
8643 A @code{tags} rule will be output at the topmost directory of a
8644 multi-directory package.  When run from this topmost directory,
8645 @samp{make tags} will generate a @file{TAGS} file that includes by
8646 reference all @file{TAGS} files from subdirectories.
8648 The @code{tags} rule will also be generated if the variable
8649 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
8650 directories that contain taggable source that @command{etags} does
8651 not understand.  The user can use the @code{ETAGSFLAGS} to pass
8652 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
8653 available for use in @file{Makefile.am}.
8654 @vindex ETAGS_ARGS
8655 @vindex ETAGSFLAGS
8656 @vindex AM_ETAGSFLAGS
8658 Here is how Automake generates tags for its source, and for nodes in its
8659 Texinfo file:
8661 @example
8662 ETAGS_ARGS = automake.in --lang=none \
8663  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
8664 @end example
8666 If you add file names to @code{ETAGS_ARGS}, you will probably also
8667 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
8668 are added directly to the dependencies for the @code{tags} rule.
8669 @vindex TAGS_DEPENDENCIES
8671 Automake also generates a @code{ctags} rule that can be used to
8672 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
8673 is the name of the program to invoke (by default @command{ctags});
8674 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
8675 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
8677 Automake will also generate an @code{ID} rule that will run
8678 @command{mkid} on the source.  This is only supported on a
8679 directory-by-directory basis.
8680 @trindex id
8682 Finally, Automake also emit rules to support the
8683 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
8684 The @code{GTAGS} rule runs Global Tags and puts the
8685 result in the top build directory.  The variable @code{GTAGS_ARGS}
8686 holds arguments that are passed to @command{gtags}.
8687 @vindex GTAGS_ARGS
8690 @node Suffixes
8691 @section Handling new file extensions
8693 @cindex Adding new @code{SUFFIXES}
8694 @cindex @code{SUFFIXES}, adding
8695 @vindex SUFFIXES
8697 It is sometimes useful to introduce a new implicit rule to handle a file
8698 type that Automake does not know about.
8700 For instance, suppose you had a compiler that could compile @file{.foo}
8701 files to @file{.o} files.  You would simply define an suffix rule for
8702 your language:
8704 @example
8705 .foo.o:
8706         foocc -c -o $@@ $<
8707 @end example
8709 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
8710 variable and expect the correct results:
8712 @example
8713 bin_PROGRAMS = doit
8714 doit_SOURCES = doit.foo
8715 @end example
8717 This was the simpler and more common case.  In other cases, you will
8718 have to help Automake to figure which extensions you are defining your
8719 suffix rule for.  This usually happens when your extensions does not
8720 start with a dot.  Then, all you have to do is to put a list of new
8721 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
8722 implicit rule.
8724 For instance, the following definition prevents Automake to misinterpret
8725 @samp{.idlC.cpp:} as an attempt to transform @file{.idlC} files into
8726 @file{.cpp} files.
8728 @example
8729 SUFFIXES = .idl C.cpp
8730 .idlC.cpp:
8731         # whatever
8732 @end example
8734 As you may have noted, the @code{SUFFIXES} variable behaves like the
8735 @code{.SUFFIXES} special target of @command{make}.  You should not touch
8736 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
8737 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
8738 @code{SUFFIXES} go at the start of the generated suffixes list, followed
8739 by Automake generated suffixes not already in the list.
8741 @node Multilibs
8742 @section Support for Multilibs
8744 Automake has support for an obscure feature called multilibs.  A
8745 @dfn{multilib} is a library that is built for multiple different ABIs
8746 at a single time; each time the library is built with a different target
8747 flag combination.  This is only useful when the library is intended to
8748 be cross-compiled, and it is almost exclusively used for compiler
8749 support libraries.
8751 The multilib support is still experimental.  Only use it if you are
8752 familiar with multilibs and can debug problems you might encounter.
8755 @node Include
8756 @chapter Include
8758 @cmindex include
8759 @cindex Including @file{Makefile} fragment
8760 @cindex @file{Makefile} fragment, including
8762 Automake supports an @code{include} directive that  can be used to
8763 include other @file{Makefile} fragments when @command{automake} is run.
8764 Note that these fragments are read and interpreted by @command{automake},
8765 not by @command{make}.  As with conditionals, @command{make} has no idea that
8766 @code{include} is in use.
8768 There are two forms of @code{include}:
8770 @table @code
8771 @item include $(srcdir)/file
8772 Include a fragment that is found relative to the current source
8773 directory.
8775 @item include $(top_srcdir)/file
8776 Include a fragment that is found relative to the top source directory.
8777 @end table
8779 Note that if a fragment is included inside a conditional, then the
8780 condition applies to the entire contents of that fragment.
8782 Makefile fragments included this way are always distributed because
8783 they are needed to rebuild @file{Makefile.in}.
8785 @node Conditionals
8786 @chapter Conditionals
8788 @cindex Conditionals
8790 Automake supports a simple type of conditionals.
8792 @unnumberedsec Usage
8794 @acindex AM_CONDITIONAL
8795 Before using a conditional, you must define it by using
8796 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
8798 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
8799 The conditional name, @var{conditional}, should be a simple string
8800 starting with a letter and containing only letters, digits, and
8801 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
8802 that are reserved by Automake.
8804 The shell @var{condition} (suitable for use in a shell @code{if}
8805 statement) is evaluated when @command{configure} is run.  Note that you
8806 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
8807 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
8808 conditionally (e.g., in a shell @code{if} statement), then the result
8809 will confuse automake.
8810 @end defmac
8812 @cindex @option{--enable-debug}, example
8813 @cindex Example conditional @option{--enable-debug}
8814 @cindex Conditional example, @option{--enable-debug}
8816 Conditionals typically depend upon options that the user provides to
8817 the @command{configure} script.  Here is an example of how to write a
8818 conditional that is true if the user uses the @option{--enable-debug}
8819 option.
8821 @example
8822 AC_ARG_ENABLE([debug],
8823 [  --enable-debug    Turn on debugging],
8824 [case "$@{enableval@}" in
8825   yes) debug=true ;;
8826   no)  debug=false ;;
8827   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
8828 esac],[debug=false])
8829 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
8830 @end example
8832 Here is an example of how to use that conditional in @file{Makefile.am}:
8834 @cmindex if
8835 @cmindex endif
8836 @cmindex else
8838 @example
8839 if DEBUG
8840 DBG = debug
8841 else
8842 DBG =
8843 endif
8844 noinst_PROGRAMS = $(DBG)
8845 @end example
8847 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
8848 (@pxref{Conditional Programs}).
8850 You may only test a single variable in an @code{if} statement, possibly
8851 negated using @samp{!}.  The @code{else} statement may be omitted.
8852 Conditionals may be nested to any depth.  You may specify an argument to
8853 @code{else} in which case it must be the negation of the condition used
8854 for the current @code{if}.  Similarly you may specify the condition
8855 that is closed by an @code{end}:
8857 @example
8858 if DEBUG
8859 DBG = debug
8860 else !DEBUG
8861 DBG =
8862 endif !DEBUG
8863 @end example
8865 @noindent
8866 Unbalanced conditions are errors.
8868 The @code{else} branch of the above two examples could be omitted,
8869 since assigning the empty string to an otherwise undefined variable
8870 makes no difference.
8872 @unnumberedsec Portability
8874 Note that conditionals in Automake are not the same as conditionals in
8875 GNU Make.  Automake conditionals are checked at configure time by the
8876 @file{configure} script, and affect the translation from
8877 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
8878 to @file{configure} and on results that @file{configure} has discovered
8879 about the host system.  GNU Make conditionals are checked at @command{make}
8880 time, and are based on variables passed to the make program or defined
8881 in the @file{Makefile}.
8883 Automake conditionals will work with any make program.
8885 @unnumberedsec Limits
8887 Conditionals should enclose complete statements like variables or
8888 rules definitions.  Automake cannot deal with conditionals used inside
8889 a variable definition, for instance, and is not even able to diagnose
8890 this situation.  The following example would not work:
8892 @example
8893 # This syntax is not understood by Automake
8894 AM_CPPFLAGS = \
8895   -DFEATURE_A \
8896 if WANT_DEBUG
8897   -DDEBUG \
8898 endif
8899   -DFEATURE_B
8900 @end example
8902 However the intended definition of @code{AM_CPPFLAGS} can be achieved
8903 with
8905 @example
8906 if WANT_DEBUG
8907   DEBUGFLAGS = -DDEBUG
8908 endif
8909 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
8910 @end example
8912 @noindent or
8914 @example
8915 AM_CPPFLAGS = -DFEATURE_A
8916 if WANT_DEBUG
8917 AM_CPPFLAGS += -DDEBUG
8918 endif
8919 AM_CPPFLAGS += -DFEATURE_B
8920 @end example
8922 @node Gnits
8923 @chapter The effect of @option{--gnu} and @option{--gnits}
8925 @cindex @option{--gnu}, required files
8926 @cindex @option{--gnu}, complete description
8928 The @option{--gnu} option (or @option{gnu} in the
8929 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
8930 the following:
8932 @itemize @bullet
8933 @item
8934 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
8935 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
8936 or @file{COPYING}, are required at the topmost directory of the package.
8938 @item
8939 The options @option{no-installman} and @option{no-installinfo} are
8940 prohibited.
8941 @end itemize
8943 Note that this option will be extended in the future to do even more
8944 checking; it is advisable to be familiar with the precise requirements
8945 of the GNU standards.  Also, @option{--gnu} can require certain
8946 non-standard GNU programs to exist for use by various maintainer-only
8947 rules; for instance, in the future @command{pathchk} might be required for
8948 @samp{make dist}.
8950 @cindex @option{--gnits}, complete description
8952 The @option{--gnits} option does everything that @option{--gnu} does, and
8953 checks the following as well:
8955 @itemize @bullet
8956 @item
8957 @samp{make installcheck} will check to make sure that the @option{--help}
8958 and @option{--version} really print a usage message and a version string,
8959 respectively.  This is the @option{std-options} option (@pxref{Options}).
8961 @item
8962 @samp{make dist} will check to make sure the @file{NEWS} file has been
8963 updated to the current version.
8965 @item
8966 @code{VERSION} is checked to make sure its format complies with Gnits
8967 standards.
8968 @c FIXME xref when standards are finished
8970 @item
8971 @cindex @file{README-alpha}
8972 If @code{VERSION} indicates that this is an alpha release, and the file
8973 @file{README-alpha} appears in the topmost directory of a package, then
8974 it is included in the distribution.  This is done in @option{--gnits}
8975 mode, and no other, because this mode is the only one where version
8976 number formats are constrained, and hence the only mode where Automake
8977 can automatically determine whether @file{README-alpha} should be
8978 included.
8980 @item
8981 The file @file{THANKS} is required.
8982 @end itemize
8985 @node Cygnus
8986 @chapter The effect of @option{--cygnus}
8988 @cindex @option{cygnus} strictness
8990 Some packages, notably GNU GCC and GNU gdb, have a build environment
8991 originally written at Cygnus Support (subsequently renamed Cygnus
8992 Solutions, and then later purchased by Red Hat).  Packages with this
8993 ancestry are sometimes referred to as ``Cygnus'' trees.
8995 A Cygnus tree has slightly different rules for how a
8996 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
8997 @command{automake} will cause any generated @file{Makefile.in} to
8998 comply with Cygnus rules.
9000 Here are the precise effects of @option{--cygnus}:
9002 @itemize @bullet
9003 @item
9004 Info files are always created in the build directory, and not in the
9005 source directory.
9007 @item
9008 @file{texinfo.tex} is not required if a Texinfo source file is
9009 specified.  The assumption is that the file will be supplied, but in a
9010 place that Automake cannot find.  This assumption is an artifact of how
9011 Cygnus packages are typically bundled.
9013 @item
9014 @samp{make dist} is not supported, and the rules for it are not
9015 generated.  Cygnus-style trees use their own distribution mechanism.
9017 @item
9018 Certain tools will be searched for in the build tree as well as in the
9019 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
9020 @command{makeinfo} and @command{texi2dvi}.
9022 @item
9023 @option{--foreign} is implied.
9025 @item
9026 The options @option{no-installinfo} and @option{no-dependencies} are
9027 implied.
9029 @item
9030 The macros @code{AM_MAINTAINER_MODE} and @code{AM_CYGWIN32} are
9031 required.
9033 @item
9034 The @code{check} target doesn't depend on @code{all}.
9035 @end itemize
9037 GNU maintainers are advised to use @option{gnu} strictness in preference
9038 to the special Cygnus mode.  Some day, perhaps, the differences between
9039 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
9040 more standards compliant).  At that time the special Cygnus mode will be
9041 removed.
9044 @node Not Enough
9045 @chapter When Automake Isn't Enough
9047 In some situations, where Automake is not up to one task, one has to
9048 resort to handwritten rules or even handwritten @file{Makefile}s.
9050 @menu
9051 * Extending::                   Adding new rules or overriding existing ones.
9052 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
9053 @end menu
9055 @node Extending
9056 @section Extending Automake Rules
9058 With some minor exceptions (like @code{_PROGRAMS} variables being
9059 rewritten to append @samp{$(EXEEXT)}), the contents of a
9060 @file{Makefile.am} is copied to @file{Makefile.in} verbatim.
9062 @cindex copying semantics
9064 These copying semantics means that many problems can be worked around
9065 by simply adding some @command{make} variables and rules to
9066 @file{Makefile.am}.  Automake will ignore these additions.
9068 @cindex conflicting definitions
9069 @cindex rules, conflicting
9070 @cindex variables, conflicting
9071 @cindex definitions, conflicts
9073 Since a @file{Makefile.in} is built from data gathered from three
9074 different places (@file{Makefile.am}, @file{configure.ac}, and
9075 @command{automake} itself), it is possible to have conflicting
9076 definitions of rules or variables.  When building @file{Makefile.in}
9077 the following priorities are respected by @command{automake} to ensure
9078 the user always have the last word.  User defined variables in
9079 @file{Makefile.am} have priority over variables @code{AC_SUBST}ed from
9080 @file{configure.ac}, and @code{AC_SUBST}ed variables have priority
9081 over @command{automake}-defined variables.  As far rules are
9082 concerned, a user-defined rule overrides any
9083 @command{automake}-defined rule for the same target.
9085 @cindex overriding rules
9086 @cindex overriding semantics
9087 @cindex rules, overriding
9089 These overriding semantics make it possible to fine tune some default
9090 settings of Automake, or replace some of its rules.  Overriding
9091 Automake rules is often inadvisable, particularly in the topmost
9092 directory of a package with subdirectories.  The @option{-Woverride}
9093 option (@pxref{Invoking Automake}) comes handy to catch overridden
9094 definitions.
9096 Note that Automake does not make any difference between rules with
9097 commands and rules that only specify dependencies.  So it is not
9098 possible to append new dependencies to an @command{automake}-defined
9099 target without redefining the entire rule.
9101 @cindex @option{-local} targets
9102 @cindex local targets
9104 However, various useful targets have a @samp{-local} version you can
9105 specify in your @file{Makefile.am}.  Automake will supplement the
9106 standard target with these user-supplied targets.
9108 @trindex  all
9109 @trindex  all-local
9110 @trindex  info
9111 @trindex  info-local
9112 @trindex  dvi
9113 @trindex  dvi-local
9114 @trindex  ps
9115 @trindex  ps-local
9116 @trindex  pdf
9117 @trindex  pdf-local
9118 @trindex  html
9119 @trindex  html-local
9120 @trindex  check
9121 @trindex  check-local
9122 @trindex  install
9123 @trindex  install-data
9124 @trindex  install-data-local
9125 @trindex  install-dvi
9126 @trindex  install-dvi-local
9127 @trindex  install-exec
9128 @trindex  install-exec-local
9129 @trindex  install-html
9130 @trindex  install-html-local
9131 @trindex  install-info
9132 @trindex  install-info-local
9133 @trindex  install-pdf
9134 @trindex  install-pdf-local
9135 @trindex  install-ps
9136 @trindex  install-ps-local
9137 @trindex  uninstall
9138 @trindex  uninstall-local
9139 @trindex  mostlyclean
9140 @trindex  mostlyclean-local
9141 @trindex  clean
9142 @trindex  clean-local
9143 @trindex  distclean
9144 @trindex  distclean-local
9145 @trindex  installdirs
9146 @trindex  installdirs-local
9147 @trindex  installcheck
9148 @trindex  installcheck-local
9150 The targets that support a local version are @code{all}, @code{info},
9151 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
9152 @code{install-data}, @code{install-dvi}, @code{install-exec},
9153 @code{install-html}, @code{install-info}, @code{install-pdf},
9154 @code{install-ps}, @code{uninstall}, @code{installdirs},
9155 @code{installcheck} and the various @code{clean} targets
9156 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
9157 @code{maintainer-clean}).
9159 Note that there are no @code{uninstall-exec-local} or
9160 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
9161 It doesn't make sense to uninstall just data or just executables.
9163 For instance, here is one way to erase a subdirectory during
9164 @samp{make clean} (@pxref{Clean}).
9166 @example
9167 clean-local:
9168         -rm -rf testSubDir
9169 @end example
9171 Older version of this manual used to show how to use
9172 @code{install-data-local} to install a file to some hard-coded
9173 location, but you should avoid this.  (@pxref{Hard-Coded Install Paths})
9175 @cindex @option{-hook} targets
9176 @cindex hook targets
9178 Some rule also have a way to run another rule, called a @dfn{hook},
9179 after their work is done.  The hook is named after the principal target,
9180 with @samp{-hook} appended.  The targets allowing hooks are
9181 @code{install-data}, @code{install-exec}, @code{uninstall}, @code{dist},
9182 and @code{distcheck}.
9183 @trindex install-data-hook
9184 @trindex install-exec-hook
9185 @trindex uninstall-hook
9186 @trindex dist-hook
9188 For instance, here is how to create a hard link to an installed program:
9190 @example
9191 install-exec-hook:
9192         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
9193            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
9194 @end example
9196 Although cheaper and more portable than symbolic links, hard links
9197 will not work everywhere (for instance, OS/2 does not have
9198 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
9199 @command{ln} does not work.  An easy way, if symbolic links are
9200 acceptable to you, is to add @code{AC_PROG_LN_S} to
9201 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
9202 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
9203 @file{Makefile.am}.
9205 @cindex versioned binaries, installing
9206 @cindex installing versioned binaries
9207 @cindex @code{LN_S} example
9208 For instance, here is how you could install a versioned copy of a
9209 program using @samp{$(LN_S)}:
9211 @example
9212 install-exec-hook:
9213         cd $(DESTDIR)$(bindir) && \
9214           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
9215           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
9216 @end example
9218 Note that we rename the program so that a new version will erase the
9219 symbolic link, not the real binary.  Also we @command{cd} into the
9220 destination directory in order to create relative links.
9222 When writing @code{install-exec-hook} or @code{install-data-hook},
9223 please bear in mind that the exec/data distinction is based on the
9224 installation directory, not on the primary used (@pxref{Install}).  So
9225 a @code{foo_SCRIPTS} will be installed by @code{install-data}, and a
9226 @code{barexec_SCRIPTS} will be installed by @code{install-exec}.  You
9227 should define your hooks consequently.
9229 @c FIXME should include discussion of variables you can use in these
9230 @c rules
9232 @node Third-Party Makefiles
9233 @section Third-Party @file{Makefile}s
9235 @cindex Third-party packages, interfacing with
9236 @cindex Interfacing with third-party packages
9238 In most projects all @file{Makefile}s are generated by Automake.  In
9239 some cases, however, projects need to embed subdirectories with
9240 handwritten @file{Makefile}s.  For instance, one subdirectory could be
9241 a third-party project with its own build system, not using Automake.
9243 It is possible to list arbitrary directories in @code{SUBDIRS} or
9244 @code{DIST_SUBDIRS} provided each of these directories has a
9245 @file{Makefile} that recognizes all the following recursive targets.
9247 @cindex recursive targets and third-party @file{Makefile}s
9248 When a user runs one of these targets, that target is run recursively
9249 in all subdirectories.  This is why it is important that even
9250 third-party @file{Makefile}s support them.
9252 @table @code
9253 @item all
9254 Compile the entire package.  This is the default target in
9255 Automake-generated @file{Makefile}s, but it does not need to be the
9256 default in third-party @file{Makefile}s.
9258 @item distdir
9259 @trindex distdir
9260 @vindex distdir
9261 @vindex top_distdir
9262 Copy files to distribute into @samp{$(distdir)}, before a tarball is
9263 constructed.  Of course this target is not required if the
9264 @option{no-dist} option (@pxref{Options}) is used.
9266 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
9267 (@pxref{Dist}) will be passed from the outer package to the subpackage
9268 when the @code{distdir} target is invoked.  These two variables have
9269 been adjusted for the directory that is being recursed into, so they
9270 are ready to use.
9272 @item install
9273 @itemx install-data
9274 @itemx install-exec
9275 @itemx uninstall
9276 Install or uninstall files (@pxref{Install}).
9278 @item install-dvi
9279 @itemx install-html
9280 @itemx install-info
9281 @itemx install-ps
9282 @itemx install-pdf
9283 Install only some specific documentation format (@pxref{Texinfo}).
9285 @item installdirs
9286 Create install directories, but do not install any files.
9288 @item check
9289 @itemx installcheck
9290 Check the package (@pxref{Tests}).
9292 @item mostlyclean
9293 @itemx clean
9294 @itemx distclean
9295 @itemx maintainer-clean
9296 Cleaning rules (@pxref{Clean}).
9298 @item dvi
9299 @itemx pdf
9300 @itemx ps
9301 @itemx info
9302 @itemx html
9303 Build the documentation in various formats (@pxref{Texinfo}).
9305 @item tags
9306 @itemx ctags
9307 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
9308 @end table
9310 If you have ever used Gettext in a project, this is a good example of
9311 how third-party @file{Makefile}s can be used with Automake.  The
9312 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
9313 @file{intl/} directories are handwritten @file{Makefile}s that
9314 implement all these targets.  That way they can be added to
9315 @code{SUBDIRS} in Automake packages.
9317 Directories that are only listed in @code{DIST_SUBDIRS} but not in
9318 @code{SUBDIRS} need only the @code{distclean},
9319 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
9320 Subdirectories}).
9322 Usually, many of these rules are irrelevant to the third-party
9323 subproject, but they are required for the whole package to work.  It's
9324 OK to have a rule that does nothing, so if you are integrating a
9325 third-party project with no documentation or tag support, you could
9326 simply augment its @file{Makefile} as follows:
9328 @example
9329 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
9330 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
9331 $(EMPTY_AUTOMAKE_TARGETS):
9332 @end example
9334 Another aspect of integrating third-party build systems is whether
9335 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
9336 subpackage does not support VPATH builds the whole package will not
9337 support VPATH builds.  This in turns means that @samp{make distcheck}
9338 will not work, because it relies on VPATH builds.  Some people can
9339 live without this (actually, many Automake users have never heard of
9340 @samp{make distcheck}).  Other people may prefer to revamp the
9341 existing @file{Makefile}s to support VPATH@.  Doing so does not
9342 necessarily require Automake, only Autoconf is needed (@pxref{Build
9343 Directories, , Build Directories, autoconf, The Autoconf Manual}).
9344 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
9345 and @samp{@@top_builddir@@} are defined by @file{configure} when it
9346 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
9347 Output Variables, autoconf, The Autoconf Manual}), they are not
9348 computed by the Makefile like the aforementioned @samp{$(distdir)} and
9349 @samp{$(top_distdir)} variables..
9351 It is sometimes inconvenient to modify a third-party @file{Makefile}
9352 to introduce the above required targets.  For instance, one may want to
9353 keep the third-party sources untouched to ease upgrades to new
9354 versions.
9356 @cindex @file{GNUmakefile} including @file{Makefile}
9357 Here are two other ideas.  If GNU make is assumed, one possibility is
9358 to add to that subdirectory a @file{GNUmakefile} that defines the
9359 required targets and include the third-party @file{Makefile}.  For
9360 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
9361 directory; the easiest way to do this is to write a
9362 @file{GNUmakefile.in} instead, and have it processed with
9363 @code{AC_CONFIG_FILES} from the outer package.  For example if we
9364 assume @file{Makefile} defines all targets except the documentation
9365 targets, and that the @code{check} target is actually called
9366 @code{test}, we could write @file{GNUmakefile} (or
9367 @file{GNUmakefile.in}) like this:
9369 @example
9370 # First, include the real Makefile
9371 include Makefile
9372 # Then, define the other targets needed by Automake Makefiles.
9373 .PHONY: dvi pdf ps info html check
9374 dvi pdf ps info html:
9375 check: test
9376 @end example
9378 @cindex Proxy @file{Makefile} for third-party packages
9379 A similar idea that does not use @code{include} is to write a proxy
9380 @file{Makefile} that dispatches rules to the real @file{Makefile},
9381 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
9382 it's OK to rename the original @file{Makefile}) or with @samp{cd
9383 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
9384 subdirectory project one directory deeper).  The good news is that
9385 this proxy @file{Makefile} can be generated with Automake.  All we
9386 need are @option{-local} targets (@pxref{Extending}) that perform the
9387 dispatch.  Of course the other Automake features are available, so you
9388 could decide to let Automake perform distribution or installation.
9389 Here is a possible @file{Makefile.am}:
9391 @example
9392 all-local:
9393         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
9394 check-local:
9395         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
9396 clean-local:
9397         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
9399 # Assuming the package knows how to install itself
9400 install-data-local:
9401         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
9402 install-exec-local:
9403         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
9404 uninstall-local:
9405         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
9407 # Distribute files from here.
9408 EXTRA_DIST = subdir/Makefile subdir/program.c ...
9409 @end example
9411 Pushing this idea to the extreme, it is also possible to ignore the
9412 subproject build system and build everything from this proxy
9413 @file{Makefile.am}.  This might sounds very sensible if you need VPATH
9414 builds but the subproject does not support them.
9416 @node Distributing
9417 @chapter Distributing @file{Makefile.in}s
9419 Automake places no restrictions on the distribution of the resulting
9420 @file{Makefile.in}s.  We still encourage software authors to
9421 distribute their work under terms like those of the GPL, but doing so
9422 is not required to use Automake.
9424 Some of the files that can be automatically installed via the
9425 @option{--add-missing} switch do fall under the GPL@.  However, these also
9426 have a special exception allowing you to distribute them with your
9427 package, regardless of the licensing you choose.
9430 @node API versioning
9431 @chapter Automake API versioning
9433 New Automake releases usually include bug fixes and new features.
9434 Unfortunately they may also introduce new bugs and incompatibilities.
9435 This makes four reasons why a package may require a particular Automake
9436 version.
9438 Things get worse when maintaining a large tree of packages, each one
9439 requiring a different version of Automake.  In the past, this meant that
9440 any developer (and sometime users) had to install several versions of
9441 Automake in different places, and switch @samp{$PATH} appropriately for
9442 each package.
9444 Starting with version 1.6, Automake installs versioned binaries.  This
9445 means you can install several versions of Automake in the same
9446 @samp{$prefix}, and can select an arbitrary Automake version by running
9447 @command{automake-1.6} or @command{automake-1.7} without juggling with
9448 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
9449 will use @command{automake-1.6} explicitly in their rebuild rules.
9451 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
9452 not Automake's version.  If a bug fix release is made, for instance
9453 Automake 1.6.1, the API version will remain 1.6.  This means that a
9454 package that works with Automake 1.6 should also work with 1.6.1; after
9455 all, this is what people expect from bug fix releases.
9457 If your package relies on a feature or a bug fix introduced in
9458 a release, you can pass this version as an option to Automake to ensure
9459 older releases will not be used.  For instance, use this in your
9460 @file{configure.ac}:
9462 @example
9463   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
9464 @end example
9465 @noindent
9466 or, in a particular @file{Makefile.am}:
9468 @example
9469   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
9470 @end example
9471 @noindent
9472 Automake will print an error message if its version is
9473 older than the requested version.
9476 @heading What is in the API
9478 Automake's programming interface is not easy to define.  Basically it
9479 should include at least all @strong{documented} variables and targets
9480 that a @file{Makefile.am} author can use, any behavior associated with
9481 them (e.g., the places where @samp{-hook}'s are run), the command line
9482 interface of @command{automake} and @command{aclocal}, @dots{}
9484 @heading What is not in the API
9486 Every undocumented variable, target, or command line option, is not part
9487 of the API@.  You should avoid using them, as they could change from one
9488 version to the other (even in bug fix releases, if this helps to fix a
9489 bug).
9491 If it turns out you need to use such a undocumented feature, contact
9492 @email{automake@@gnu.org} and try to get it documented and exercised by
9493 the test-suite.
9495 @node Upgrading
9496 @chapter Upgrading a Package to a Newer Automake Version
9498 Automake maintains three kind of files in a package.
9500 @itemize
9501 @item @file{aclocal.m4}
9502 @item @file{Makefile.in}s
9503 @item auxiliary tools like @file{install-sh} or @file{py-compile}
9504 @end itemize
9506 @file{aclocal.m4} is generated by @command{aclocal} and contains some
9507 Automake-supplied M4 macros.  Auxiliary tools are installed by
9508 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
9509 built from @file{Makefile.am} by @command{automake}, and rely on the
9510 definitions of the M4 macros put in @file{aclocal.m4} as well as the
9511 behavior of the auxiliary tools installed.
9513 Because all these files are closely related, it is important to
9514 regenerate all of them when upgrading to a newer Automake release.
9515 The usual way to do that is
9517 @example
9518 aclocal # with any option needed (such a -I m4)
9519 autoconf
9520 automake --add-missing --force-missing
9521 @end example
9523 @noindent
9524 or more conveniently:
9526 @example
9527 autoreconf -vfi
9528 @end example
9530 The use of @option{--force-missing} ensures that auxiliary tools will be
9531 overridden by new versions (@pxref{Invoking Automake}).
9533 It is important to regenerate all these files each time Automake is
9534 upgraded, even between bug fixes releases.  For instance, it is not
9535 unusual for a bug fix to involve changes to both the rules generated
9536 in @file{Makefile.in} and the supporting M4 macros copied to
9537 @file{aclocal.m4}.
9539 Presently @command{automake} is able to diagnose situations where
9540 @file{aclocal.m4} has been generated with another version of
9541 @command{aclocal}.  However it never checks whether auxiliary scripts
9542 are up-to-date.  In other words, @command{automake} will tell you when
9543 @command{aclocal} needs to be rerun, but it will never diagnose a
9544 missing @option{--force-missing}.
9546 Before upgrading to a new major release, it is a good idea to read the
9547 file @file{NEWS}.  This file lists all changes between releases: new
9548 features, obsolete constructs, known incompatibilities, and
9549 workarounds.
9551 @node FAQ
9552 @chapter Frequently Asked Questions about Automake
9554 This chapter covers some questions that often come up on the mailing
9555 lists.
9557 @menu
9558 * CVS::                         CVS and generated files
9559 * maintainer-mode::             missing and AM_MAINTAINER_MODE
9560 * wildcards::                   Why doesn't Automake support wildcards?
9561 * limitations on file names::   Limitations on source and installed file names
9562 * distcleancheck::              Files left in build directory after distclean
9563 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
9564 * renamed objects::             Why are object files sometimes renamed?
9565 * Per-Object Flags::            How to simulate per-object flags?
9566 * Multiple Outputs::            Writing rules for tools with many output files
9567 * Hard-Coded Install Paths::    Installing to Hard-Coded Locations
9568 @end menu
9570 @node CVS
9571 @section CVS and generated files
9573 @subsection Background: distributed generated files
9574 @cindex generated files, distributed
9575 @cindex rebuild rules
9577 Packages made with Autoconf and Automake ship with some generated
9578 files like @file{configure} or @file{Makefile.in}.  These files were
9579 generated on the developer's host and are distributed so that
9580 end-users do not have to install the maintainer tools required to
9581 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
9582 or Info documentation, are usually distributed on similar grounds.
9584 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
9585 instance, @command{make} will run @command{autoconf} to rebuild
9586 @file{configure} whenever @file{configure.ac} is changed.  This makes
9587 development safer by ensuring a @file{configure} is never out-of-date
9588 with respect to @file{configure.ac}.
9590 As generated files shipped in packages are up-to-date, and because
9591 @command{tar} preserves times-tamps, these rebuild rules are not
9592 triggered when a user unpacks and builds a package.
9594 @subsection Background: CVS and timestamps
9595 @cindex timestamps and CVS
9596 @cindex CVS and timestamps
9598 Unless you use CVS keywords (in which case files must be updated at
9599 commit time), CVS preserves timestamp during @samp{cvs commit} and
9600 @samp{cvs import -d} operations.
9602 When you check out a file using @samp{cvs checkout} its timestamp is
9603 set to that of the revision that is being checked out.
9605 However, during @command{cvs update}, files will have the date of the
9606 update, not the original timestamp of this revision.  This is meant to
9607 make sure that @command{make} notices sources files have been updated.
9609 This timestamp shift is troublesome when both sources and generated
9610 files are kept under CVS@.  Because CVS processes files in alphabetical
9611 order, @file{configure.ac} will appear older than @file{configure}
9612 after a @command{cvs update} that updates both files, even if
9613 @file{configure} was newer than @file{configure.ac} when it was
9614 checked in.  Calling @command{make} will then trigger a spurious rebuild
9615 of @file{configure}.
9617 @subsection Living with CVS in Autoconfiscated projects
9618 @cindex CVS and generated files
9619 @cindex generated files and CVS
9621 There are basically two clans amongst maintainers: those who keep all
9622 distributed files under CVS, including generated files, and those who
9623 keep generated files @emph{out} of CVS.
9625 @subsubheading All files in CVS
9627 @itemize @bullet
9628 @item
9629 The CVS repository contains all distributed files so you know exactly
9630 what is distributed, and you can checkout any prior version entirely.
9632 @item
9633 Maintainers can see how generated files evolve (for instance, you can
9634 see what happens to your @file{Makefile.in}s when you upgrade Automake
9635 and make sure they look OK).
9637 @item
9638 Users do not need the autotools to build a checkout of the project, it
9639 works just like a released tarball.
9641 @item
9642 If users use @command{cvs update} to update their copy, instead of
9643 @command{cvs checkout} to fetch a fresh one, timestamps will be
9644 inaccurate.  Some rebuild rules will be triggered and attempt to
9645 run developer tools such as @command{autoconf} or @command{automake}.
9647 Actually, calls to such tools are all wrapped into a call to the
9648 @command{missing} script discussed later (@pxref{maintainer-mode}).
9649 @command{missing} will take care of fixing the timestamps when these
9650 tools are not installed, so that the build can continue.
9652 @item
9653 In distributed development, developers are likely to have different
9654 version of the maintainer tools installed.  In this case rebuilds
9655 triggered by timestamp lossage will lead to spurious changes
9656 to generated files.  There are several solutions to this:
9658 @itemize
9659 @item
9660 All developers should use the same versions, so that the rebuilt files
9661 are identical to files in CVS@.  (This starts to be difficult when each
9662 project you work on uses different versions.)
9663 @item
9664 Or people use a script to fix the timestamp after a checkout (the GCC
9665 folks have such a script).
9666 @item
9667 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
9668 disable all these rebuild rules by default.  This is further discussed
9669 in @ref{maintainer-mode}.
9670 @end itemize
9672 @item
9673 Although we focused on spurious rebuilds, the converse can also
9674 happen.  CVS's timestamp handling can also let you think an
9675 out-of-date file is up-to-date.
9677 For instance, suppose a developer has modified @file{Makefile.am} and
9678 has rebuilt @file{Makefile.in}.  He then decide to do a last-minute
9679 change to @file{Makefile.am} right before checking in both files
9680 (without rebuilding @file{Makefile.in} to account for the change).
9682 This last change to @file{Makefile.am} make the copy of
9683 @file{Makefile.in} out-of-date.  Since CVS processes files
9684 alphabetically, when another developer @samp{cvs update} his or her
9685 tree, @file{Makefile.in} will happen to be newer than
9686 @file{Makefile.am}.  This other developer will not see
9687 @file{Makefile.in} is out-of-date.
9689 @end itemize
9691 @subsubheading Generated files out of CVS
9693 One way to get CVS and @command{make} working peacefully is to never
9694 store generated files in CVS, i.e., do not CVS-control files that
9695 are @file{Makefile} targets (also called @emph{derived} files).
9697 This way developers are not annoyed by changes to generated files.  It
9698 does not matter if they all have different versions (assuming they are
9699 compatible, of course).  And finally, timestamps are not lost, changes
9700 to sources files can't be missed as in the
9701 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
9703 The drawback is that the CVS repository is not an exact copy of what
9704 is distributed and that users now need to install various development
9705 tools (maybe even specific versions) before they can build a checkout.
9706 But, after all, CVS's job is versioning, not distribution.
9708 Allowing developers to use different versions of their tools can also
9709 hide bugs during distributed development.  Indeed, developers will be
9710 using (hence testing) their own generated files, instead of the
9711 generated files that will be released actually.  The developer who
9712 prepares the tarball might be using a version of the tool that
9713 produces bogus output (for instance a non-portable C file), something
9714 other developers could have noticed if they weren't using their own
9715 versions of this tool.
9717 @subsection Third-party files
9718 @cindex CVS and third-party files
9719 @cindex third-party files and CVS
9721 Another class of files not discussed here (because they do not cause
9722 timestamp issues) are files that are shipped with a package, but
9723 maintained elsewhere.  For instance, tools like @command{gettextize}
9724 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
9725 Libtool), will install or update files in your package.
9727 These files, whether they are kept under CVS or not, raise similar
9728 concerns about version mismatch between developers' tools.  The
9729 Gettext manual has a section about this, see @ref{CVS Issues, CVS
9730 Issues, Integrating with CVS, gettext, GNU gettext tools}.
9732 @node maintainer-mode
9733 @section @command{missing} and @code{AM_MAINTAINER_MODE}
9735 @subsection @command{missing}
9736 @cindex @command{missing}, purpose
9738 The @command{missing} script is a wrapper around several maintainer
9739 tools, designed to warn users if a maintainer tool is required but
9740 missing.  Typical maintainer tools are @command{autoconf},
9741 @command{automake}, @command{bison}, etc.  Because file generated by
9742 these tools are shipped with the other sources of a package, these
9743 tools shouldn't be required during a user build and they are not
9744 checked for in @file{configure}.
9746 However, if for some reason a rebuild rule is triggered and involves a
9747 missing tool, @command{missing} will notice it and warn the user.
9748 Besides the warning, when a tool is missing, @command{missing} will
9749 attempt to fix timestamps in a way that allows the build to continue.
9750 For instance, @command{missing} will touch @file{configure} if
9751 @command{autoconf} is not installed.  When all distributed files are
9752 kept under CVS, this feature of @command{missing} allows user
9753 @emph{with no maintainer tools} to build a package off CVS, bypassing
9754 any timestamp inconsistency implied by @samp{cvs update}.
9756 If the required tool is installed, @command{missing} will run it and
9757 won't attempt to continue after failures.  This is correct during
9758 development: developers love fixing failures.  However, users with
9759 wrong versions of maintainer tools may get an error when the rebuild
9760 rule is spuriously triggered, halting the build.  This failure to let
9761 the build continue is one of the arguments of the
9762 @code{AM_MAINTAINER_MODE} advocates.
9764 @subsection @code{AM_MAINTAINER_MODE}
9765 @cindex @code{AM_MAINTAINER_MODE}, purpose
9766 @acindex AM_MAINTAINER_MODE
9768 @code{AM_MAINTAINER_MODE} disables the so called "rebuild rules" by
9769 default.  If you have @code{AM_MAINTAINER_MODE} in
9770 @file{configure.ac}, and run @samp{./configure && make}, then
9771 @command{make} will *never* attempt to rebuilt @file{configure},
9772 @file{Makefile.in}s, Lex or Yacc outputs, etc.  I.e., this disables
9773 build rules for files that are usually distributed and that users
9774 should normally not have to update.
9776 If you run @samp{./configure --enable-maintainer-mode}, then these
9777 rebuild rules will be active.
9779 People use @code{AM_MAINTAINER_MODE} either because they do want their
9780 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
9781 because they simply can't stand the rebuild rules and prefer running
9782 maintainer tools explicitly.
9784 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
9785 rules conditionally.  Some developers use this feature to disable
9786 rules that need exotic tools that users may not have available.
9788 Several years ago Fran@,{c}ois Pinard pointed out several arguments
9789 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
9790 insecurity.  By removing dependencies you get non-dependable builds:
9791 change to sources files can have no effect on generated files and this
9792 can be very confusing when unnoticed.  He adds that security shouldn't
9793 be reserved to maintainers (what @option{--enable-maintainer-mode}
9794 suggests), on the contrary.  If one user has to modify a
9795 @file{Makefile.am}, then either @file{Makefile.in} should be updated
9796 or a warning should be output (this is what Automake uses
9797 @command{missing} for) but the last thing you want is that nothing
9798 happens and the user doesn't notice it (this is what happens when
9799 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
9801 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
9802 swayed by Fran@,{c}ois's arguments, and got rid of
9803 @code{AM_MAINTAINER_MODE} in all of his packages.
9805 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
9806 it helps them working on projects where all files are kept under CVS,
9807 and because @command{missing} isn't enough if you have the wrong
9808 version of the tools.
9811 @node wildcards
9812 @section Why doesn't Automake support wildcards?
9813 @cindex wildcards
9815 Developers are lazy.  They often would like to use wildcards in
9816 @file{Makefile.am}s, so they don't need to remember they have to
9817 update @file{Makefile.am}s every time they add, delete, or rename a
9818 file.
9820 There are several objections to this:
9821 @itemize
9822 @item
9823 When using CVS (or similar) developers need to remember they have to
9824 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
9825 @file{Makefile.am} accordingly quickly becomes a reflex.
9827 Conversely, if your application doesn't compile
9828 because you forgot to add a file in @file{Makefile.am}, it will help
9829 you remember to @samp{cvs add} it.
9831 @item
9832 Using wildcards makes easy to distribute files by mistake.  For
9833 instance, some code a developer is experimenting with (a test case,
9834 say) but that should not be part of the distribution.
9836 @item
9837 Using wildcards it's easy to omit some files by mistake.  For
9838 instance, one developer creates a new file, uses it at many places,
9839 but forget to commit it.  Another developer then checkout the
9840 incomplete project and is able to run `make dist' successfully,
9841 even though a file is missing.
9843 @item
9844 Listing files, you control *exactly* what you distribute.
9845 If some file that should be distributed is missing from your
9846 tree, @samp{make dist} will complain.  Besides, you don't distribute
9847 more than what you listed.
9849 @item
9850 Finally it's really hard to @file{forget} adding a file to
9851 @file{Makefile.am}, because if you don't add it, it doesn't get
9852 compiled nor installed, so you can't even test it.
9853 @end itemize
9855 Still, these are philosophical objections, and as such you may disagree,
9856 or find enough value in wildcards to dismiss all of them.  Before you
9857 start writing a patch against Automake to teach it about wildcards,
9858 let's see the main technical issue: portability.
9860 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
9861 not portable to other @command{make} implementations.
9863 The only way Automake could support @command{$(wildcard ...)} is by
9864 expending @command{$(wildcard ...)} when @command{automake} is run.
9865 Resulting @file{Makefile.in}s would be portable since they would
9866 list all files and not use @samp{$(wildcard ...)}.  However that
9867 means developers need to remember they must run @command{automake} each
9868 time they add, delete, or rename files.
9870 Compared to editing @file{Makefile.am}, this is really little win.  Sure,
9871 it's easier and faster to type @samp{automake; make} than to type
9872 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
9873 patch add support for this syntax.  Some people use scripts to
9874 generated file lists in @file{Makefile.am} or in separate
9875 @file{Makefile} fragments.
9877 Even if you don't care about portability, and are tempted to use
9878 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
9879 should know there are many places where Automake need to know exactly
9880 which files should be processed.  As Automake doesn't know how to
9881 expand @samp{$(wildcard ...)}, you cannot use it in these places.
9882 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
9883 variables as far Automake is concerned.
9885 You can get warnings about @samp{$(wildcard ...}) constructs using the
9886 @option{-Wportability} flag.
9888 @node limitations on file names
9889 @section Limitations on file names
9890 @cindex file names, limitations on
9892 Automake attempts to support all kinds of file names, even those that
9893 contain unusual characters or are unusually long.  However, some
9894 limitations are imposed by the underlying operating system and tools.
9896 Most operating systems prohibit the use of the null byte in file
9897 names, and reserve @samp{/} as a directory separator.  Also, they
9898 require that file names are properly encoded for the user's locale.
9899 Automake is subject to these limits.
9901 Portable packages should limit themselves to @acronym{POSIX} file
9902 names.  These can contain @acronym{ASCII} letters and digits,
9903 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
9904 separated by @samp{/}.  File name components cannot begin with
9905 @samp{-}.
9907 Portable POSIX file names cannot contain components that exceed a
9908 14-byte limit, but nowadays it's normally safe to assume the
9909 more-generous @acronym{XOPEN} limit of 255 bytes.  @acronym{POSIX}
9910 limits file names to 255 bytes (@acronym{XOPEN} allows 1023 bytes),
9911 but you may want to limit a source tarball to file names to 99 bytes
9912 to avoid interoperability problems with old versions of @command{tar}.
9914 If you depart from these rules (e.g., by using non-@acronym{ASCII}
9915 characters in file names, or by using lengthy file names), your
9916 installers may have problems for reasons unrelated to Automake.
9917 However, if this does not concern you, you should know about the
9918 limitations imposed by Automake itself.  These limitations are
9919 undesirable, but some of them seem to be inherent to underlying tools
9920 like Autoconf, Make, M4, and the shell.  They fall into three
9921 categories: install directories, build directories, and file names.
9923 The following characters:
9925 @example
9926 @r{newline} " # $ ' `
9927 @end example
9929 should not appear in the names of install directories.  For example,
9930 the operand of @command{configure}'s @option{--prefix} option should
9931 not contain these characters.
9933 Build directories suffer the same limitations as install directories,
9934 and in addition should not contain the following characters:
9936 @example
9937 & @@ \
9938 @end example
9940 For example, the full name of the directory containing the source
9941 files should not contain these characters.
9943 Source and installation file names like @file{main.c} are limited even
9944 further: they should conform to the @acronym{POSIX}/@acronym{XOPEN}
9945 rules described above.  In addition, if you plan to port to
9946 non-@acronym{POSIX} environments, you should avoid file names that
9947 differ only in case (e.g., @file{makefile} and @file{Makefile}).
9948 Nowadays it is no longer worth worrying about the 8.3 limits of
9949 @acronym{DOS} file systems.
9951 @node distcleancheck
9952 @section Files left in build directory after distclean
9953 @cindex @code{distclean}, diagnostic
9954 @cindex @samp{make distclean}, diagnostic
9955 @cindex dependencies and distributed files
9956 @trindex distclean
9957 @trindex distcleancheck
9959 This is a diagnostic you might encounter while running @samp{make
9960 distcheck}.
9962 As explained in @ref{Dist}, @samp{make distcheck} attempts to build
9963 and check your package for errors like this one.
9965 @samp{make distcheck} will perform a @code{VPATH} build of your
9966 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
9967 Files left in the build directory after @samp{make distclean} has run
9968 are listed after this error.
9970 This diagnostic really covers two kinds of errors:
9972 @itemize @bullet
9973 @item
9974 files that are forgotten by distclean;
9975 @item
9976 distributed files that are erroneously rebuilt.
9977 @end itemize
9979 The former left-over files are not distributed, so the fix is to mark
9980 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
9981 more explanations.
9983 The latter bug is not always easy to understand and fix, so let's
9984 proceed with an example.  Suppose our package contains a program for
9985 which we want to build a man page using @command{help2man}.  GNU
9986 @command{help2man} produces simple manual pages from the @option{--help}
9987 and @option{--version} output of other commands (@pxref{Top, , Overview,
9988 help2man, The Help2man Manual}).  Because we don't to force want our
9989 users to install @command{help2man}, we decide to distribute the
9990 generated man page using the following setup.
9992 @example
9993 # This Makefile.am is bogus.
9994 bin_PROGRAMS = foo
9995 foo_SOURCES = foo.c
9996 dist_man_MANS = foo.1
9998 foo.1: foo$(EXEEXT)
9999         help2man --output=foo.1 ./foo$(EXEEXT)
10000 @end example
10002 This will effectively distribute the man page.  However,
10003 @samp{make distcheck} will fail with:
10005 @example
10006 ERROR: files left in build directory after distclean:
10007 ./foo.1
10008 @end example
10010 Why was @file{foo.1} rebuilt?  Because although distributed,
10011 @file{foo.1} depends on a non-distributed built file:
10012 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
10013 will always appear to be newer than the distributed @file{foo.1}.
10015 @samp{make distcheck} caught an inconsistency in our package.  Our
10016 intent was to distribute @file{foo.1} so users do not need installing
10017 @command{help2man}, however since this our rule causes this file to be
10018 always rebuilt, users @emph{do} need @command{help2man}.  Either we
10019 should ensure that @file{foo.1} is not rebuilt by users, or there is
10020 no point in distributing @file{foo.1}.
10022 More generally, the rule is that distributed files should never depend
10023 on non-distributed built files.  If you distribute something
10024 generated, distribute its sources.
10026 One way to fix the above example, while still distributing
10027 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
10028 assuming @command{foo --version} and @command{foo --help} do not
10029 change unless @file{foo.c} or @file{configure.ac} change, we could
10030 write the following @file{Makefile.am}:
10032 @example
10033 bin_PROGRAMS = foo
10034 foo_SOURCES = foo.c
10035 dist_man_MANS = foo.1
10037 foo.1: foo.c $(top_srcdir)/configure.ac
10038         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
10039         help2man --output=foo.1 ./foo$(EXEEXT)
10040 @end example
10042 This way, @file{foo.1} will not get rebuilt every time
10043 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
10044 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
10045 way to ensure this would be to use separate directories for binaries
10046 and man pages, and set @code{SUBDIRS} so that binaries are built
10047 before man pages.
10049 We could also decide not to distribute @file{foo.1}.  In
10050 this case it's fine to have @file{foo.1} dependent upon
10051 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
10052 However it would be impossible to build the package in a
10053 cross-compilation, because building @file{foo.1} involves
10054 an @emph{execution} of @file{foo$(EXEEXT)}.
10056 Another context where such errors are common is when distributed files
10057 are built by tools that are built by the package.  The pattern is
10058 similar:
10060 @example
10061 distributed-file: built-tools distributed-sources
10062         build-command
10063 @end example
10065 @noindent
10066 should be changed to
10068 @example
10069 distributed-file: distributed-sources
10070         $(MAKE) $(AM_MAKEFLAGS) built-tools
10071         build-command
10072 @end example
10074 @noindent
10075 or you could choose not to distribute @file{distributed-file}, if
10076 cross-compilation does not matter.
10078 The points made through these examples are worth a summary:
10080 @cartouche
10081 @itemize
10082 @item
10083 Distributed files should never depend upon non-distributed built
10084 files.
10085 @item
10086 Distributed files should be distributed with all their dependencies.
10087 @item
10088 If a file is @emph{intended} to be rebuilt by users, then there is no point
10089 in distributing it.
10090 @end itemize
10091 @end cartouche
10093 @vrindex distcleancheck_listfiles
10094 For desperate cases, it's always possible to disable this check by
10095 setting @code{distcleancheck_listfiles} as documented in @ref{Dist}.
10096 Make sure you do understand the reason why @samp{make distcheck}
10097 complains before you do this.  @code{distcleancheck_listfiles} is a
10098 way to @emph{hide} errors, not to fix them.  You can always do better.
10100 @node Flag Variables Ordering
10101 @section Flag Variables Ordering
10102 @cindex Ordering flag variables
10103 @cindex Flag variables, ordering
10105 @display
10106 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
10107 @code{mumble_CFLAGS}?
10108 @end display
10110 @display
10111 Why does @command{automake} output @code{CPPFLAGS} after
10112 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
10113 @end display
10115 @display
10116 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
10117 one @file{Makefile.am} I would like to append a new flag, however if I
10118 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
10119 flags, not appended.
10120 @end display
10122 @subsection Compile Flag Variables
10123 @cindex Flag Variables, Ordering
10124 @cindex Compile Flag Variables
10125 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
10126 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
10127 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
10128 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
10129 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
10130 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
10131 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
10132 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
10133 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
10134 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
10135 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
10136 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
10137 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
10138 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
10139 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
10140 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
10141 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
10142 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
10143 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
10144 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
10145 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
10146 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
10147 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
10148 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
10149 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
10150 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
10151 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
10152 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
10154 This section attempts to answer all the above questions.  We will
10155 mostly discuss @code{CPPFLAGS} in our examples, but actually the
10156 answer holds for all the compile flags used in Automake:
10157 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
10158 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
10159 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
10160 @code{UPCFLAGS}, and @code{YFLAGS}.
10162 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
10163 three variables that can be used to pass flags to the C preprocessor
10164 (actually these variables are also used for other languages like C++
10165 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
10166 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
10167 and @code{mumble_CPPFLAGS} is the variable specific to the
10168 @code{mumble} target (we call this a per-target variable,
10169 @pxref{Program and Library Variables}).
10171 Automake always uses two of these variables when compiling C sources
10172 files.  When compiling an object file for the @code{mumble} target,
10173 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
10174 @code{AM_CPPFLAGS} otherwise.  The second variable is always
10175 @code{CPPFLAGS}.
10177 In the following example,
10179 @example
10180 bin_PROGRAMS = foo bar
10181 foo_SOURCES = xyz.c
10182 bar_SOURCES = main.c
10183 foo_CPPFLAGS = -DFOO
10184 AM_CPPFLAGS = -DBAZ
10185 @end example
10187 @noindent
10188 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
10189 (because @file{xyz.o} is part of the @code{foo} target), while
10190 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
10191 (because there is no per-target variable for target @code{bar}).
10193 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
10194 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
10195 is a user variable, i.e., a variable that users are entitled to modify
10196 in order to compile the package.  This variable, like many others,
10197 is documented at the end of the output of @samp{configure --help}.
10199 For instance, someone who needs to add @file{/home/my/usr/include} to
10200 the C compiler's search path would configure a package with
10202 @example
10203 ./configure CPPFLAGS='-I /home/my/usr/include'
10204 @end example
10206 @noindent
10207 and this flag would be propagated to the compile rules of all
10208 @file{Makefile}s.
10210 It is also not uncommon to override a user variable at
10211 @command{make}-time.  Many installers do this with @code{prefix}, but
10212 this can be useful with compiler flags too.  For instance, if, while
10213 debugging a C++ project, you need to disable optimization in one
10214 specific object file, you can run something like
10216 @example
10217 rm file.o
10218 make CXXFLAGS=-O0 file.o
10219 make
10220 @end example
10222 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
10223 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
10224 should always have the last say.  It probably makes more sense if you
10225 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
10226 should supersede any other switch from @code{AM_CXXFLAGS} or
10227 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
10228 of @code{CXXFLAGS}).
10230 You should never redefine a user variable such as @code{CPPFLAGS} in
10231 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
10232 mistakes.  Even something like
10234 @example
10235 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
10236 @end example
10238 @noindent
10239 is erroneous.  Although this preserves @file{configure}'s value of
10240 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
10241 user attempts to override @code{CPPFLAGS} from the @command{make}
10242 command line.
10244 @example
10245 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
10246 @end example
10248 @noindent
10249 is all what is needed here if no per-target flags are used.
10251 You should not add options to these user variables within
10252 @file{configure} either, for the same reason.  Occasionally you need
10253 to modify these variables to perform a test, but you should reset
10254 their values afterwards.  In contrast, it is OK to modify the
10255 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
10256 them, but it is rather rare that you need to do this, unless you
10257 really want to change the default definitions of the @samp{AM_}
10258 variables in all @file{Makefile}s.
10260 What we recommend is that you define extra flags in separate
10261 variables.  For instance, you may write an Autoconf macro that computes
10262 a set of warning options for the C compiler, and @code{AC_SUBST} them
10263 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
10264 determines which compiler and which linker flags should be used to
10265 link with library @file{libfoo}, and @code{AC_SUBST} these in
10266 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
10267 @file{Makefile.am} could use these variables as follows:
10269 @example
10270 AM_CFLAGS = $(WARNINGCFLAGS)
10271 bin_PROGRAMS = prog1 prog2
10272 prog1_SOURCES = @dots{}
10273 prog2_SOURCES = @dots{}
10274 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
10275 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
10276 @end example
10278 In this example both programs will be compiled with the flags
10279 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
10280 additionally be compiled with the flags required to link with
10281 @file{libfoo}.
10283 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
10284 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
10285 every target in a @file{Makefile.in}.
10287 Using variables like this gives you full control over the ordering of
10288 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
10289 you want to negate for a particular target, you can use something like
10290 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
10291 been forcefully appended to @code{CFLAGS}, there would be no way to
10292 disable one flag.  Yet another reason to leave user variables to
10293 users.
10295 Finally, we have avoided naming the variable of the example
10296 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
10297 Automake to think that this is actually a per-target variable (like
10298 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
10300 @subsection Other Variables
10302 There are other variables in Automake that follow similar principles
10303 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
10304 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
10305 DejaGnu tests (@pxref{Tests}) use @code{RUNTESTDEFAULTFLAGS} and
10306 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
10307 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
10308 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
10309 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
10310 of these rules do support per-target flags (yet).
10312 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
10313 obeys this naming scheme.  The slight difference is that
10314 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
10315 @command{make} itself.
10317 However you should not think that all variables ending with
10318 @code{FLAGS} follow this convention.  For instance,
10319 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Dist}),
10320 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
10321 are two variables that are only useful to the maintainer and have no
10322 user counterpart.
10324 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
10325 has neither @code{AM_} nor per-target cousin.
10327 Finally you should not think either that the existence of a per-target
10328 variable implies that of an @code{AM_} variable or that of a user
10329 variable.  For instance, the @code{mumble_LDADD} per-target variable
10330 overrides the global @code{LDADD} variable (which is not a user
10331 variable), and @code{mumble_LIBADD} exists only as a per-target
10332 variable.  @xref{Program and Library Variables}.
10335 @node renamed objects
10336 @section Why are object files sometimes renamed?
10338 This happens when per-target compilation flags are used.  Object
10339 files need to be renamed just in case they would clash with object
10340 files compiled from the same sources, but with different flags.
10341 Consider the following example.
10343 @example
10344 bin_PROGRAMS = true false
10345 true_SOURCES = generic.c
10346 true_CPPFLAGS = -DEXIT_CODE=0
10347 false_SOURCES = generic.c
10348 false_CPPFLAGS = -DEXIT_CODE=1
10349 @end example
10350 @noindent
10351 Obviously the two programs are built from the same source, but it
10352 would be bad if they shared the same object, because @file{generic.o}
10353 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
10354 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
10355 build two different objects: @file{true-generic.o} and
10356 @file{false-generic.o}.
10358 @command{automake} doesn't actually look whether source files are
10359 shared to decide if it must rename objects.  It will just rename all
10360 objects of a target as soon as it sees per-target compilation flags
10361 are used.
10363 It's OK to share object files when per-target compilation flags are not
10364 used.  For instance, @file{true} and @file{false} will both use
10365 @file{version.o} in the following example.
10367 @example
10368 AM_CPPFLAGS = -DVERSION=1.0
10369 bin_PROGRAMS = true false
10370 true_SOURCES = true.c version.c
10371 false_SOURCES = false.c version.c
10372 @end example
10374 Note that the renaming of objects is also affected by the
10375 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
10378 @node Per-Object Flags
10379 @section Per-Object Flags Emulation
10380 @cindex Per-object flags, emulated
10382 @display
10383 One of my source files needs to be compiled with different flags.  How
10384 do I do?
10385 @end display
10387 Automake supports per-program and per-library compilation flags (see
10388 @ref{Program and Library Variables} and @ref{Flag Variables
10389 Ordering}).  With this you can define compilation flags that apply to
10390 all files compiled for a target.  For instance, in
10392 @example
10393 bin_PROGRAMS = foo
10394 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
10395 foo_CFLAGS = -some -flags
10396 @end example
10398 @noindent
10399 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
10400 compiled with @samp{-some -flags}.  (If you wonder about the names of
10401 these object files, see @ref{renamed objects}.)  Note that
10402 @code{foo_CFLAGS} gives the flags to use when compiling all the C
10403 sources of the @emph{program} @code{foo}, it has nothing to do with
10404 @file{foo.c} or @file{foo-foo.o} specifically.
10406 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
10407 specific flags, that none of the other files require?  Obviously
10408 per-program flags are not directly applicable here.  Something like
10409 per-object flags are expected, i.e., flags that would be used only
10410 when creating @file{foo-foo.o}.  Automake does not support that,
10411 however this is easy to simulate using a library that contains only
10412 that object, and compiling this library with per-library flags.
10414 @example
10415 bin_PROGRAMS = foo
10416 foo_SOURCES = bar.c bar.h main.c
10417 foo_CFLAGS = -some -flags
10418 foo_LDADD = libfoo.a
10419 noinst_LIBRARIES = libfoo.a
10420 libfoo_a_SOURCES = foo.c foo.h
10421 libfoo_a_CFLAGS = -some -other -flags
10422 @end example
10424 Here @file{foo-bar.o} and @file{foo-main.o} will all be
10425 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
10426 be compiled using @samp{-some -other -flags}.  Eventually, all
10427 three objects will be linked to form @file{foo}.
10429 This trick can also be achieved using Libtool convenience libraries,
10430 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
10431 Convenience Libraries}).
10433 Another tempting idea to implement per-object flags is to override the
10434 compile rules @command{automake} would output for these files.
10435 Automake will not define a rule for a target you have defined, so you
10436 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
10437 We recommend against this, because this is error prone.  For instance,
10438 if you add such a rule to the first example, it will break the day you
10439 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
10440 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{renamed
10441 objects}).  Also in order to support dependency tracking, the two
10442 @file{.o}/@file{.obj} extensions, and all the other flags variables
10443 involved in a compilation, you will end up modifying a copy of the
10444 rule previously output by @command{automake} for this file.  If a new
10445 release of Automake generates a different rule, your copy will need to
10446 be updated by hand.
10448 @node Multiple Outputs
10449 @section Handling Tools that Produce Many Outputs
10450 @cindex multiple outputs, rules with
10451 @cindex many outputs, rules with
10452 @cindex rules with multiple outputs
10454 This section describes a @command{make} idiom that can be used when a
10455 tool produces multiple output files.  It is not specific to Automake
10456 and can be used in ordinary @file{Makefile}s.
10458 Suppose we have a program called @command{foo} that will read one file
10459 called @file{data.foo} and produce two files named @file{data.c} and
10460 @file{data.h}.  We want to write a @file{Makefile} rule that captures
10461 this one-to-two dependency.
10463 The naive rule is incorrect:
10465 @example
10466 # This is incorrect.
10467 data.c data.h: data.foo
10468         foo data.foo
10469 @end example
10471 @noindent
10472 What the above rule really says is that @file{data.c} and
10473 @file{data.h} each depend on @file{data.foo}, and can each be built by
10474 running @samp{foo data.foo}.  In other words it is equivalent to:
10476 @example
10477 # We do not want this.
10478 data.c: data.foo
10479         foo data.foo
10480 data.h: data.foo
10481         foo data.foo
10482 @end example
10484 @noindent
10485 which means that @command{foo} can be run twice.  Usually it will not
10486 be run twice, because @command{make} implementations are smart enough
10487 to check for the existence of the second file after the first one has
10488 been built; they will therefore detect that it already exists.
10489 However there are a few situations where it can run twice anyway:
10491 @itemize
10492 @item
10493 The most worrying case is when running a parallel @command{make}.  If
10494 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
10495 data.foo} commands will run concurrently.  This is harmful.
10496 @item
10497 Another case is when the dependency (here @file{data.foo}) is
10498 (or depends upon) a phony target.
10499 @end itemize
10501 A solution that works with parallel @command{make} but not with
10502 phony dependencies is the following:
10504 @example
10505 data.c data.h: data.foo
10506         foo data.foo
10507 data.h: data.c
10508 @end example
10510 @noindent
10511 The above rules are equivalent to
10513 @example
10514 data.c: data.foo
10515         foo data.foo
10516 data.h: data.foo data.c
10517         foo data.foo
10518 @end example
10519 @noindent
10520 therefore a parallel @command{make} will have to serialize the builds
10521 of @file{data.c} and @file{data.h}, and will detect that the second is
10522 no longer needed once the first is over.
10524 Using this pattern is probably enough for most cases.  However it does
10525 not scale easily to more output files (in this scheme all output files
10526 must be totally ordered by the dependency relation), so we will
10527 explore a more complicated solution.
10529 Another idea is to write the following:
10531 @example
10532 # There is still a problem with this one.
10533 data.c: data.foo
10534         foo data.foo
10535 data.h: data.c
10536 @end example
10538 @noindent
10539 The idea is that @samp{foo data.foo} is run only when @file{data.c}
10540 needs to be updated, but we further state that @file{data.h} depends
10541 upon @file{data.c}.  That way, if @file{data.h} is required and
10542 @file{data.foo} is out of date, the dependency on @file{data.c} will
10543 trigger the build.
10545 This is almost perfect, but suppose we have built @file{data.h} and
10546 @file{data.c}, and then we erase @file{data.h}.  Then, running
10547 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
10548 just state that @file{data.c} must be up-to-date with respect to
10549 @file{data.foo}, and this is already the case.
10551 What we need is a rule that forces a rebuild when @file{data.h} is
10552 missing.  Here it is:
10554 @example
10555 data.c: data.foo
10556         foo data.foo
10557 data.h: data.c
10558 ## Recover from the removal of $@@
10559         @@if test -f $@@; then :; else \
10560           rm -f data.c; \
10561           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10562         fi
10563 @end example
10565 The above scheme can be extended to handle more outputs and more
10566 inputs.  One of the outputs is selected to serve as a witness to the
10567 successful completion of the command, it depends upon all inputs, and
10568 all other outputs depend upon it.  For instance, if @command{foo}
10569 should additionally read @file{data.bar} and also produce
10570 @file{data.w} and @file{data.x}, we would write:
10572 @example
10573 data.c: data.foo data.bar
10574         foo data.foo data.bar
10575 data.h data.w data.x: data.c
10576 ## Recover from the removal of $@@
10577         @@if test -f $@@; then :; else \
10578           rm -f data.c; \
10579           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10580         fi
10581 @end example
10583 However there are now two minor problems in this setup.  One is related
10584 to the timestamp ordering of @file{data.h}, @file{data.w},
10585 @file{data.x}, and @file{data.c}.  The other one is a race condition
10586 if a parallel @command{make} attempts to run multiple instances of the
10587 recover block at once.
10589 Let us deal with the first problem.  @command{foo} outputs four files,
10590 but we do not know in which order these files are created.  Suppose
10591 that @file{data.h} is created before @file{data.c}.  Then we have a
10592 weird situation.  The next time @command{make} is run, @file{data.h}
10593 will appear older than @file{data.c}, the second rule will be
10594 triggered, a shell will be started to execute the @samp{if@dots{}fi}
10595 command, but actually it will just execute the @code{then} branch,
10596 that is: nothing.  In other words, because the witness we selected is
10597 not the first file created by @command{foo}, @command{make} will start
10598 a shell to do nothing each time it is run.
10600 A simple riposte is to fix the timestamps when this happens.
10602 @example
10603 data.c: data.foo data.bar
10604         foo data.foo data.bar
10605 data.h data.w data.x: data.c
10606         @@if test -f $@@; then \
10607           touch $@@; \
10608         else \
10609 ## Recover from the removal of $@@
10610           rm -f data.c; \
10611           $(MAKE) $(AM_MAKEFLAGS) data.c; \
10612         fi
10613 @end example
10615 Another solution is to use a different and dedicated file as witness,
10616 rather than using any of @command{foo}'s outputs.
10618 @example
10619 data.stamp: data.foo data.bar
10620         @@rm -f data.tmp
10621         @@touch data.tmp
10622         foo data.foo data.bar
10623         @@mv -f data.tmp $@@
10624 data.c data.h data.w data.x: data.stamp
10625 ## Recover from the removal of $@@
10626         @@if test -f $@@; then :; else \
10627           rm -f data.stamp; \
10628           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10629         fi
10630 @end example
10632 @file{data.tmp} is created before @command{foo} is run, so it has a
10633 timestamp older than output files output by @command{foo}.  It is then
10634 renamed to @file{data.stamp} after @command{foo} has run, because we
10635 do not want to update @file{data.stamp} if @command{foo} fails.
10637 This solution still suffers from the second problem: the race
10638 condition in the recover rule.  If, after a successful build, a user
10639 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
10640 @command{make} may start both recover rules in parallel.  If the two
10641 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
10642 data.stamp} concurrently the build is likely to fail (for instance, the
10643 two rules will create @file{data.tmp}, but only one can rename it).
10645 Admittedly, such a weird situation does not arise during ordinary
10646 builds.  It occurs only when the build tree is mutilated.  Here
10647 @file{data.c} and @file{data.h} have been explicitly removed without
10648 also removing @file{data.stamp} and the other output files.
10649 @code{make clean; make} will always recover from these situations even
10650 with parallel makes, so you may decide that the recover rule is solely
10651 to help non-parallel make users and leave things as-is.  Fixing this
10652 requires some locking mechanism to ensure only one instance of the
10653 recover rule rebuilds @file{data.stamp}.  One could imagine something
10654 along the following lines.
10656 @example
10657 data.c data.h data.w data.x: data.stamp
10658 ## Recover from the removal of $@@
10659         @@if test -f $@@; then :; else \
10660           trap 'rm -rf data.lock data.stamp 1 2 13 15; \
10661 ## mkdir is a portable test-and-set
10662           if mkdir data.lock 2>/dev/null; then \
10663 ## This code is being executed by the first process.
10664             rm -f data.stamp; \
10665             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
10666           else \
10667 ## This code is being executed by the follower processes.
10668 ## Wait until the first process is done.
10669             while test -d data.lock; do sleep 1; done; \
10670 ## Succeed if and only if the first process succeeded.
10671             test -f data.stamp; exit $$?; \
10672           fi; \
10673         fi
10674 @end example
10676 Using a dedicated witness, like @file{data.stamp}, is very handy when
10677 the list of output files is not known beforehand.  As an illustration,
10678 consider the following rules to compile many @file{*.el} files into
10679 @file{*.elc} files in a single command.  It does not matter how
10680 @code{ELFILES} is defined (as long as it is not empty: empty targets
10681 are not accepted by POSIX).
10683 @example
10684 ELFILES = one.el two.el three.el @dots{}
10685 ELCFILES = $(ELFILES:=c)
10687 elc-stamp: $(ELFILES)
10688         @@rm -f elc-temp
10689         @@touch elc-temp
10690         $(elisp_comp) $(ELFILES)
10691         @@mv -f elc-temp $@@
10693 $(ELCFILES): elc-stamp
10694 ## Recover from the removal of $@@
10695         @@if test -f $@@; then :; else \
10696           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
10697           if mkdir elc-lock 2>/dev/null; then \
10698 ## This code is being executed by the first process.
10699             rm -f elc-stamp; \
10700             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
10701             rmdir elc-lock; \
10702           else \
10703 ## This code is being executed by the follower processes.
10704 ## Wait until the first process is done.
10705             while test -d elc-lock; do sleep 1; done; \
10706 ## Succeed if and only if the first process succeeded.
10707             test -f elc-stamp; exit $$?; \
10708           fi; \
10709         fi
10710 @end example
10712 For completeness it should be noted that GNU @command{make} is able to
10713 express rules with multiple output files using pattern rules
10714 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
10715 Manual}).  We do not discuss pattern rules here because they are not
10716 portable, but they can be convenient in packages that assume GNU
10717 @command{make}.
10720 @node Hard-Coded Install Paths
10721 @section Installing to Hard-Coded Locations
10723 @display
10724 My package needs to install some configuration file.  I tried to use
10725 the following rule, but @samp{make distcheck} fails.  Why?
10727 @example
10728 # Do not do this.
10729 install-data-local:
10730         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
10731 @end example
10732 @end display
10734 @display
10735 My package needs to populate the installation directory of another
10736 package at install-time.  I can easily compute that installation
10737 directory in @file{configure}, but if I install files therein,
10738 @samp{make distcheck} fails.  How else should I do?
10739 @end display
10741 These two setups share their symptoms: @samp{make distcheck} fails
10742 because they are installing files to hard-coded paths.  In the later
10743 case the path is not really hard-coded in the package, but we can
10744 consider it to be hard-coded in the system (or in whichever tool that
10745 supplies the path).  As long as the path does not use any of the
10746 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
10747 @samp{$(datadir)}, etc.), the effect will be the same:
10748 user-installations are impossible.
10750 When a (non-root) user wants to install a package, he usually has no
10751 right to install anything in @file{/usr} or @file{/usr/local}.  So he
10752 does something like @samp{./configure --prefix ~/usr} to install
10753 package in his own @file{~/usr} tree.
10755 If a package attempts to install something to some hard-coded path
10756 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
10757 then the installation will fail.  @samp{make distcheck} performs such
10758 a @option{--prefix} installation, hence it will fail too.
10760 Now, there are some easy solutions.
10762 The above @code{install-data-local} example for installing
10763 @file{/etc/afile} would be better replaced by
10765 @example
10766 sysconf_DATA = afile
10767 @end example
10769 @noindent
10770 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
10771 this is what the GNU Standards require.  When such a package is
10772 installed on a FHS compliant system, the installer will have to set
10773 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
10774 should not be concerned by such site policies: use the appropriate
10775 standard directory variable to install your files so that installer
10776 can easily redefine these variables to match their site conventions.
10778 Installing files that should be used by another package, is slightly
10779 more involved.  Let's take an example and assume you want to install
10780 shared library that is a Python extension module.  If you ask Python
10781 where to install the library, it will answer something like this:
10783 @example
10784 % @kbd{python -c 'from distutils import sysconfig;
10785              print sysconfig.get_python_lib(1,0)'}
10786 /usr/lib/python2.3/site-packages
10787 @end example
10789 If you indeed use this absolute path to install your shared library,
10790 non-root users will not be able to install the package, hence
10791 distcheck fails.
10793 Let's do better.  The @samp{sysconfig.get_python_lib()} function
10794 actually accepts a third argument that will replace Python's
10795 installation prefix.
10797 @example
10798 % @kbd{python -c 'from distutils import sysconfig;
10799              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
10800 $@{exec_prefix@}/lib/python2.3/site-packages
10801 @end example
10803 You can also use this new path.  If you do
10804 @itemize @bullet
10805 @item
10806 root users can install your package with the same @option{--prefix}
10807 as Python (you get the behavior of the previous attempt)
10809 @item
10810 non-root users can install your package too, they will have the
10811 extension module in a place that is not searched by Python but they
10812 can work around this using environment variables (and if you installed
10813 scripts that use this shared library, it's easy to tell Python were to
10814 look in the beginning of your script, so the script works in both
10815 cases).
10816 @end itemize
10818 The @code{AM_PATH_PYTHON} macro uses similar commands to define
10819 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
10821 Of course not all tools are as advanced as Python regarding that
10822 substitution of @var{prefix}.  So another strategy is to figure the
10823 part of the of the installation directory that must be preserved.  For
10824 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
10825 computes @samp{$(lispdir)}:
10827 @example
10828 $EMACS -batch -q -eval '(while load-path
10829   (princ (concat (car load-path) "\n"))
10830   (setq load-path (cdr load-path)))' >conftest.out
10831 lispdir=`sed -n
10832   -e 's,/$,,'
10833   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
10834         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
10835       @}'
10836   -e '/.*\/share\/x*emacs\/site-lisp$/@{
10837         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
10838       @}'
10839   conftest.out`
10840 @end example
10842 I.e., it just picks the first directory that looks like
10843 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
10844 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
10845 @samp{$@{datadir@}} appropriately.
10847 The emacs case looks complicated because it processes a list and
10848 expect two possible layouts, otherwise it's easy, and the benefit for
10849 non-root users are really worth the extra @command{sed} invocation.
10852 @node History
10853 @chapter History of Automake
10855 This chapter presents various aspects of the history of Automake.  The
10856 exhausted reader can safely skip it; this will be more of interest to
10857 nostalgic people, or to those curious to learn about the evolution of
10858 Automake.
10860 @menu
10861 * Timeline::                    The Automake story.
10862 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
10863 * Releases::                    Statistics about Automake Releases
10864 @end menu
10866 @node Timeline
10867 @section Timeline
10869 @table @asis
10870 @item 1994-09-19 First CVS commit.
10872 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
10873 working on Automake (or AutoMake, as it was spelt then) this Monday.
10875 The first version of the @command{automake} script looks as follows.
10877 @example
10878 #!/bin/sh
10880 status=0
10882 for makefile
10884   if test ! -f $@{makefile@}.am; then
10885     echo "automake: $@{makefile@}.am: No such honkin' file"
10886     status=1
10887     continue
10888   fi
10890   exec 4> $@{makefile@}.in
10892 done
10893 @end example
10895 From this you can already see that Automake will be about reading
10896 @file{*.am} file and producing @file{*.in} files.  You cannot see
10897 anything else, but if you also know that David is the one who created
10898 Autoconf two years before you can guess the rest.
10900 Several commits follow, and by the end of the day Automake is
10901 reported to work for GNU fileutils and GNU m4.
10903 The modus operandi is the one that is still used today: variables
10904 assignments in @file{Makefile.am} files trigger injections of
10905 precanned @file{Makefile} fragments into the generated
10906 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
10907 by the 4.4BSD @command{make} and include files, however Automake aims
10908 to be portable and to conform to the GNU standards for @file{Makefile}
10909 variables and targets.
10911 At this point, the most recent release of Autoconf is version 1.11,
10912 and David is preparing to release Autoconf 2.0 in late October.  As a
10913 matter of fact, he will barely touch Automake after September.
10915 @item 1994-11-05 David MacKenzie's last commit.
10917 At this point Automake is a 200 line portable shell script, plus 332
10918 lines of @file{Makefile} fragments.  In the @file{README}, David
10919 states his ambivalence between ``portable shell'' and ``more
10920 appropriate language'':
10922 @quotation
10923 I wrote it keeping in mind the possibility of it becoming an Autoconf
10924 macro, so it would run at configure-time.  That would slow
10925 configuration down a bit, but allow users to modify the Makefile.am
10926 without needing to fetch the AutoMake package.  And, the Makefile.in
10927 files wouldn't need to be distributed.  But all of AutoMake would.  So
10928 I might reimplement AutoMake in Perl, m4, or some other more
10929 appropriate language.
10930 @end quotation
10932 Automake is described as ``an experimental Makefile generator''.
10933 There is no documentation.  Adventurous users are referred to the
10934 examples and patches needed to use Automake with GNU m4 1.3, fileutils
10935 3.9, time 1.6, and development versions of find and indent.
10937 These examples seem to have been lost.  However at the time of writing
10938 (10 years later in September, 2004) the FSF still distributes a
10939 package that uses this version of Automake: check out GNU termutils
10940 2.0.
10942 @item 1995-11-12 Tom Tromey's first commit.
10944 After one year of inactivity, Tom Tromey takes over the package.
10945 Tom was working on GNU cpio back then, and doing this just for fun,
10946 having trouble finding a project to contribute to.  So while hacking
10947 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
10948 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
10949 grabbed it and tried it out.
10951 Tom didn't talk to djm about it until later, just to make sure he
10952 didn't mind if he made a release.  He did a bunch of early releases to
10953 the Gnits folks.
10955 Gnits was (and still is) totally informal, just a few GNU friends who
10956 Fran@,cois Pinard knew, who were all interested in making a common
10957 infrastructure for GNU projects, and shared a similar outlook on how
10958 to do it.  So they were able to make some progress.  It came along
10959 with Autoconf and extensions thereof, and then Automake from David and
10960 Tom (who were both gnitsians).  One of their ideas was to write a
10961 document paralleling the GNU standards, that was more strict in some
10962 ways and more detailed.  They never finished the GNITS standards, but
10963 the ideas mostly made their way into Automake.
10965 @item 1995-11-23 Automake 0.20
10967 Besides introducing automatic dependency tracking (@pxref{Dependency
10968 Tracking Evolution}), this version also supplies a 9-page manual.
10970 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
10971 exist, so many things had to be done by hand.  For instance, here is
10972 what a configure.in (this is the former name of the
10973 @file{configure.ac} we use today) must contain in order to use
10974 Automake 0.20:
10976 @example
10977 PACKAGE=cpio
10978 VERSION=2.3.911
10979 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
10980 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
10981 AC_SUBST(PACKAGE)
10982 AC_SUBST(VERSION)
10983 AC_ARG_PROGRAM
10984 AC_PROG_INSTALL
10985 @end example
10987 (Today all of the above is achieved by @code{AC_INIT} and
10988 @code{AM_INIT_AUTOMAKE}.)
10990 Here is how programs are specified in @file{Makefile.am}:
10992 @example
10993 PROGRAMS = hello
10994 hello_SOURCES = hello.c
10995 @end example
10997 This looks pretty much like what we do today, except the
10998 @code{PROGRAMS} variable has no directory prefix specifying where
10999 @file{hello} should be installed: all programs are installed in
11000 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
11001 that must be built but not installed (it is called
11002 @code{noinst_PROGRAMS} nowadays).
11004 Programs can be built conditionally using @code{AC_SUBST}itutions:
11006 @example
11007 PROGRAMS = @@progs@@
11008 AM_PROGRAMS = foo bar baz
11009 @end example
11011 (@code{AM_PROGRAMS} has since then been renamed to
11012 @code{EXTRA_PROGRAMS}.)
11014 Similarly scripts, static libraries, and data can built and installed
11015 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
11016 However @code{LIBRARIES} were treated a bit specially in that Automake
11017 did automatically supply the @file{lib} and @file{.a} prefixes.
11018 Therefore to build @file{libcpio.a}, one had to write
11020 @example
11021 LIBRARIES = cpio
11022 cpio_SOURCES = ...
11023 @end example
11025 Extra files to distribute must be listed in @code{DIST_OTHER} (the
11026 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
11027 distributed should appear in @code{DIST_SUBDIRS}, but the manual
11028 describes this as a temporary ugly hack (today extra directories should
11029 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
11030 for another purpose, @pxref{Conditional Subdirectories}).
11032 @item 1995-11-26 Automake 0.21
11034 In less time that it takes to cook a frozen pizza, Tom rewrites
11035 Automake using Perl.  At this time Perl 5 is only one year old, and
11036 Perl 4.036 is in use at many sites.  Supporting several Perl versions
11037 has been a source of problems through the whole history of Automake.
11039 If you never used Perl 4, imagine Perl 5 without objects, without
11040 @samp{my} variables (only dynamically scoped @samp{local} variables),
11041 without function prototypes, with function calls that needs to be
11042 prefixed with @samp{&}, etc.  Traces of this old style can still be
11043 found in today's @command{automake}.
11045 @item 1995-11-28 Automake 0.22
11046 @itemx 1995-11-29 Automake 0.23
11048 Bug fixes.
11050 @item 1995-12-08 Automake 0.24
11051 @itemx 1995-12-10 Automake 0.25
11053 Releases are raining.  0.24 introduces the uniform naming scheme we
11054 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
11055 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
11056 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
11057 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
11058 prefixes.)  Adding support for prefixes like that was one of the major
11059 ideas in automake; it has lasted pretty well.
11061 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
11062 Pinard's doing).
11064 0.25 fixes a Perl 4 portability bug.
11066 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
11067 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
11069 @item 1996-01-03 Automake 0.26
11070 @itemx 1996-01-03 Automake 0.27
11072 Of the many change and suggestions sent by Fran@,cois Pinard and
11073 included in 0.26, the most important is perhaps the advise that to
11074 ease customization a user rule or variable definition should always
11075 override an Automake rule or definition.
11077 Gordon Matzigkeit and Jim Meyering are two other early contributors
11078 that have been sending fixes.
11080 0.27 fixes yet another Perl 4 portability bug.
11082 @item 1996-01-13 Automake 0.28
11084 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
11085 support.  This is an important step because until this version
11086 Automake did only know about the @file{Makefile.am}s it processed.
11087 @file{configure.in} was Autoconf's world and the link between Autoconf
11088 and Automake had to be done by the @file{Makefile.am} author.  For
11089 instance, if @file{config.h} was generated by @file{configure}, it was the
11090 package maintainer's responsibility to define the @code{CONFIG_HEADER}
11091 variable in each @file{Makefile.am}.
11093 Succeeding releases will rely more and more on scanning
11094 @file{configure.in} to better automate the Autoconf integration.
11096 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
11097 @option{--gnu} and @option{--gnits} options, the latter being stricter.
11099 @item 1996-02-07 Automake 0.29
11101 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
11102 and rebuild rules for @file{configure}-generated file are
11103 automatically output.
11105 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
11106 scheme.
11108 @item 1996-02-24 Automake 0.30
11110 The test suite is born.  It contains 9 tests.  From now on test cases
11111 will be added pretty regularly (@pxref{Releases}), and this proved to
11112 be really helpful later on.
11114 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
11116 All the third-party Autoconf macros, written mostly by Fran@,cois
11117 Pinard (and later Jim Meyering), are distributed in Automake's
11118 hand-written @file{aclocal.m4} file.  Package maintainers are expected
11119 to extract the necessary macros from this file.  (In previous version
11120 you had to copy and paste them from the manual...)
11122 @item 1996-03-11 Automake 0.31
11124 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
11125 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
11126 whenever the @code{TESTS} variable is defined.
11128 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
11129 prefix is introduced.  The syntax is now the same as today.
11131 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
11133 @item 1996-04-27 Automake 0.32
11135 @code{-hook} targets are introduced; an idea from Dieter Baron.
11137 @file{*.info} files, which were output in the build directory are
11138 now built in the source directory, because they are distributed.  It
11139 seems these files like to move back and forth as that will happen
11140 again in future versions.
11142 @item 1996-05-18 Automake 0.33
11144 Gord Matzigkeit's main two contributions:
11146 @itemize
11147 @item very preliminary libtool support
11148 @item the distcheck rule
11149 @end itemize
11151 Although they were very basic at this point, these are probably
11152 among the top features for Automake today.
11154 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
11155 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
11156 author (@pxref{maintainer-mode}).
11158 @item 1996-05-28 Automake 1.0
11160 After only six months of heavy development, the automake script is
11161 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
11162 package has 30 pages of documentation, and 38 test cases.
11163 @file{aclocal.m4} contains 4 macros.
11165 From now on and until version 1.4, new releases will occur at a rate
11166 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
11167 been the name of beta releases for 1.2.  This is the first time
11168 Automake uses suffix letters to designate beta releases, an habit that
11169 lasts.
11171 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
11173 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
11175 Between June and October, the Autoconf development is almost staled.
11176 Roland McGrath has been working at the beginning of the year.  David
11177 comes back in November to release 2.12, but he won't touch Autoconf
11178 anymore after this year, and Autoconf then really stagnates.  The
11179 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
11181 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
11183 The mailing list is announced as follows:
11184 @smallexample
11185 I've created the "automake" mailing list.  It is
11186 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
11187 automake-request@@gnu.ai.mit.edu.
11189 The charter of this list is discussion of automake, autoconf, and
11190 other configuration/portability tools (e.g., libtool).  It is expected
11191 that discussion will range from pleas for help all the way up to
11192 patches.
11194 This list is archived on the FSF machines.  Offhand I don't know if
11195 you can get the archive without an account there.
11197 This list is open to anybody who wants to join.  Tell all your
11198 friends!
11199 -- Tom Tromey
11200 @end smallexample
11202 Before that people were discussing Automake privately, on the Gnits
11203 mailing list (which is not public either), and less frequently on
11204 @code{gnu.misc.discuss}.
11206 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
11207 noticed.  The archives of the early years of the
11208 @code{automake@@gnu.org} list have been lost, so today it is almost
11209 impossible to find traces of discussions that occurred before 1999.
11210 This has been annoying more than once, as such discussions can be
11211 useful to understand the rationale behind a piece of uncommented code
11212 that was introduced back then.
11214 @item 1997-06-22 Automake 1.2
11216 Automake developments continues, and more and more new Autoconf macros
11217 are required.  Distributing them in @file{aclocal.m4} and requiring
11218 people to browse this file to extract the relevant macros becomes
11219 uncomfortable.  Ideally, some of them should be contributed to
11220 Autoconf so that they can be used directly, however Autoconf is
11221 currently inactive.  Automake 1.2 consequently introduces
11222 @command{aclocal} (@command{aclocal} was actually started on
11223 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
11224 file from a repository of third-party macros.  Because Autoconf has
11225 stalled, Automake also becomes a kind of repository for such
11226 third-party macros, even macros completely unrelated to Automake (for
11227 instance macros that fix broken Autoconf macros).
11229 The 1.2 release contains 20 macros, among which the
11230 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
11231 @file{configure.in}.
11233 Libtool is fully supported using @code{*_LTLIBRARIES}.
11235 The missing script is introduced by Fran@,cois Pinard; it is meant to be
11236 a better solution than @code{AM_MAINTAINER_MODE}
11237 (@pxref{maintainer-mode}).
11239 Conditionals support was implemented by Ian Lance Taylor.  At the
11240 time, Tom and Ian were working on an internal project at Cygnus.  They
11241 were using ILU, which is pretty similar to CORBA@.  They wanted to
11242 integrate ILU into their build, which was all @file{configure}-based,
11243 and Ian thought that adding conditionals to @command{automake} was
11244 simpler than doing all the work in @file{configure} (which was the
11245 standard at the time).  So this was actually funded by Cygnus.
11247 This very useful but tricky feature will take a lot of time to
11248 stabilize.  (At the time this text is written, there are still
11249 primaries that have not been updated to support conditional
11250 definitions in Automake 1.9.)
11252 The @command{automake} script has almost doubled: 6089 lines of Perl,
11253 plus 1294 lines of @file{Makefile} fragments.
11255 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
11257 @item 1998-04-05 Automake 1.3
11259 This is a small advance compared to 1.2.
11260 It add support for assembly, and preliminary support for Java.
11262 Perl 5.004_04 is out, but fixes to support Perl 4 are still
11263 regularly submitted whenever Automake breaks it.
11265 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
11267 Sourceware was setup by Jason Molenda to host open source projects.
11269 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
11270 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake
11271 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
11272 publicly accessible CVS repository.  This CVS repository is a copy of
11273 the one Tom was using on his machine, which in turn is based on
11274 a copy of the CVS repository of David MacKenzie.  This is why we still
11275 have to full source history.  (Automake is still on Sourceware today,
11276 but the host has been renamed to @code{sources.redhat.com}.)
11278 The oldest file in the administrative directory of the CVS repository
11279 that was created on Sourceware is dated 1998-09-19, while the
11280 announcement that @command{automake} and @command{autoconf} had joined
11281 @command{sourceware} was made on 1998-10-26.  They were among the
11282 first projects to be hosted there.
11284 The heedful reader will have noticed Automake was exactly 4-year-old
11285 on 1998-09-19.
11287 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
11289 @item 1999-01-14 Automake 1.4
11291 This release adds support for Fortran 77 and for the @code{include}
11292 statement.  Also, @samp{+=} assignments are introduced, but it is
11293 still quite easy to fool Automake when mixing this with conditionals.
11295 These two releases, Automake 1.4 and Autoconf 2.13 makes a duo that
11296 will be used together for years.
11298 @command{automake} is 7228 lines, plus 1591 lines of Makefile
11299 fragment, 20 macros (some 1.3 macros were finally contributed back to
11300 Autoconf), 197 test cases, and 51 pages of documentation.
11302 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
11304 This implements a new dependency tracking schemed that should be
11305 able to handle automatic dependency tracking using any compiler (not
11306 just gcc) and any make (not just GNU @command{make}).  In addition,
11307 the new scheme should be more reliable than the old one, as
11308 dependencies are generated on the end user's machine.  Alexandre Oliva
11309 creates depcomp for this purpose.
11311 @xref{Dependency Tracking Evolution}, for more details about the
11312 evolution of automatic dependency tracking in Automake.
11314 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
11316 This was a huge problem since we also had patches going in on the
11317 trunk.  The merge took a long time and was very painful.
11319 @item 2000-05-10
11321 Since September 1999 and until 2003, Akim Demaille will be zealously
11322 revamping Autoconf.
11324 @quotation
11325 I think the next release should be called "3.0".@*
11326 Let's face it: you've basically rewritten autoconf.@*
11327 Every weekend there are 30 new patches.@*
11328 I don't see how we could call this "2.15" with a straight face.@*
11329 -- Tom Tromey on @email{autoconf@@gnu.org}
11330 @end quotation
11332 Actually Akim works like a submarine: he will pile up patches while he
11333 works off-line during the weekend, and flush them in batch when he
11334 resurfaces on Monday.
11336 @item 2001-01-24
11338 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
11339 is out, and Akim has to find something to do during his week-end :)
11341 @item 2001-01-28
11343 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
11345 @quotation
11346 Aiieeee!  I was dreading the day that the Demaillator turned his
11347 sights on automake@dots{} and now it has arrived! -- Tom Tromey
11348 @end quotation
11350 It's only the beginning: in two months he will send 192 patches.  Then
11351 he would slow down so Tom can catch up and review all this.  Initially
11352 Tom actually read all these patches, then he probably trustingly
11353 answered OK to most of them, and finally gave up and let Akim apply
11354 whatever he wanted.  There was no way to keep up with that patch rate.
11356 @quotation
11357 Anyway the patch below won't apply since it predates Akim's
11358 sourcequake; I have yet to figure where the relevant passage has
11359 been moved :) -- Alexandre Duret-Lutz
11360 @end quotation
11362 All these patches were sent to and discussed on
11363 @email{automake@@gnu.org}, so subscribed users were literally drown in
11364 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
11365 mailing list was created in May.
11367 Year after year, Automake had drifted away from its initial design:
11368 construct @file{Makefile.in} by assembling various @file{Makefile}
11369 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
11370 various places in the @command{automake} script itself; this does not
11371 help ensuring a consistent treatment of these rules (for instance
11372 making sure that user-defined rules override Automake's own rules).
11373 One of Akim's goal was moving all these hard-coded rules to separate
11374 @file{Makefile} fragments, so the logic could be centralized in a
11375 @file{Makefile} fragment processor.
11377 Another significant contribution of Akim is the interface with the
11378 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
11379 this time was to read the file and grep the various macro of interest
11380 to Automake.  Doing so could break in many unexpected ways; automake
11381 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
11382 where the arguments are known only when M4 is run), or conversely it
11383 could detect some macro that was not expanded (because it is called
11384 conditionally).  In the CVS version of Autoconf, Akim had implemented
11385 the @option{--trace} option, which provides accurate information about
11386 where macros are actually called and with what arguments.  Akim will
11387 equip Automake with a second @file{configure.in} scanner that uses
11388 this @option{--trace} interface.  Since it was not sensible to drop the
11389 Autoconf 2.13 compatibility yet, this experimental scanner was only
11390 used when an environment variable was set, the traditional
11391 grep-scanner being still the default.
11393 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
11395 It has been more than two years since Automake 1.4, CVS Automake has
11396 suffered lot's of heavy changes and still is not ready for release.
11397 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
11399 @item 2001-05-08 Automake 1.4-p1
11400 @itemx 2001-05-24 Automake 1.4-p2
11402 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
11403 release'' of Automake:
11405 @quotation
11406 The main purpose of this release is to have a stable automake
11407 which is compatible with the latest stable libtool.
11408 @end quotation
11410 The release also contains obvious fixes for bugs in Automake 1.4,
11411 some of which were reported almost monthly.
11413 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
11415 @item 2001-06-07 Automake 1.4-p3
11416 @itemx 2001-06-10 Automake 1.4-p4
11417 @itemx 2001-07-15 Automake 1.4-p5
11419 Gary continues his patch-release series.  These also add support for
11420 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
11421 @file{configure.ac} over @file{configure.in}, and it introduces a new
11422 syntax for @code{AC_OUTPUT}ing files.
11424 @item 2001-08-23 Automake 1.5
11426 A major and long-awaited release, that comes more than two years after
11427 1.4.  It brings many changes, among which:
11428 @itemize
11429 @item The new dependency tracking scheme that uses @command{depcomp}.
11430 Aside from the improvement on the dependency tracking itself
11431 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
11432 of automake generated @file{Makefile.in}s as the @file{Makefile.in}s
11433 used during development are now the same as those used in
11434 distributions.  Before that the @file{Makefile.in}s generated for
11435 maintainers required GNU @command{make} and GCC, they were different
11436 from the portable @file{Makefile} generated for distribution; this was
11437 causing some confusion.
11439 @item Support for per-target compilation flags.
11441 @item Support for reference to files in subdirectories in most
11442 @file{Makefile.am} variables.
11444 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
11445 prefixes.
11446 @item Perl 4 support is finally dropped.
11447 @end itemize
11449 1.5 did broke several packages that worked with 1.4.  Enough so that
11450 Linux distributions could not easily install the new Automake version
11451 without breaking many of the packages for which they had to run
11452 @command{automake}.
11454 Some of these breakages were effectively bugs that would eventually be
11455 fixed in the next release.  However, a lot of damage was caused by
11456 some changes made deliberately to render Automake stricter on some
11457 setup we did consider bogus.  For instance, @samp{make distcheck} was
11458 improved to check that @samp{make uninstall} did remove all the files
11459 @samp{make install} installed, that @samp{make distclean} did not omit
11460 some file, and that a VPATH build would work even if the source
11461 directory was read-only.  Similarly, Automake now rejects multiple
11462 definitions of the same variable (because that would mix very badly
11463 with conditionals), and @samp{+=} assignments with no previous
11464 definition.  Because these changes all occurred suddenly after 1.4 had
11465 been established for more than two years, it hurt users.
11467 To make matter worse, meanwhile Autoconf (now at version 2.52) was
11468 facing similar troubles, for similar reasons.
11470 @item 2002-03-05 Automake 1.6
11472 This release introduced versioned installation (@pxref{API
11473 versioning}).  This was mainly pushed by Havoc Pennington, taking the
11474 GNOME source tree as motive: due to incompatibilities between the
11475 autotools it's impossible for the GNOME packages to switch to Autoconf
11476 2.53 and Automake 1.5 all at once, so they are currently stuck with
11477 Autoconf 2.13 and Automake 1.4.
11479 The idea was to call this version @file{automake-1.6}, call all its
11480 bug-fix versions identically, and switch to @file{automake-1.7} for
11481 the next release that adds new features or changes some rules.  This
11482 scheme implies maintaining a bug-fix branch in addition to the
11483 development trunk, which means more work from the maintainer, but
11484 providing regular bug-fix releases proved to be really worthwhile.
11486 Like 1.5, 1.6 also introduced a bunch of incompatibilities, meant or
11487 not.  Perhaps the more annoying was the dependence on the newly
11488 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
11489 since its explosive 2.50 release, and included changes required to fix
11490 some bugs in Automake.  In order to upgrade to Automake 1.6, people
11491 now had to upgrade Autoconf too; for some packages it was no picnic.
11493 While versioned installation helped people to upgrade, it also
11494 unfortunately allowed people not to upgrade.  At the time of writing,
11495 some Linux distributions are shipping packages for Automake 1.4, 1.5,
11496 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
11497 Some distribution also call 1.4 the ``stable'' version, and present
11498 ``1.9'' as the development version; this does not really makes sense
11499 since 1.9 is way more solid than 1.4.  All this does not help the
11500 newcomer.
11502 @item 2002-04-11 Automake 1.6.1
11504 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
11505 This one and those following will be handled by Alexandre
11506 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
11507 but his interest into Automake is drifting away towards projects like
11508 @command{gcj}.
11510 Alexandre has been using Automake since 2000, and started to
11511 contribute mostly on Akim's incitement (Akim and Alexandre have been
11512 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
11513 a lot of free time to enjoy hacking Automake.
11515 @item 2002-06-14 Automake 1.6.2
11517 @item 2002-07-28 Automake 1.6.3
11518 @itemx 2002-07-28 Automake 1.4-p6
11520 Two releases on the same day.  1.6.3 is a bug-fix release.
11522 Tom Tromey backported the versioned installation mechanism on the 1.4
11523 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
11524 side by side.  Another request from the GNOME folks.
11526 @item 2002-09-25 Automake 1.7
11528 This release switches to the new @file{configure.ac} scanner Akim
11529 was experimenting in 1.5.
11531 @item 2002-10-16 Automake 1.7.1
11532 @itemx 2002-12-06 Automake 1.7.2
11533 @itemx 2003-02-20 Automake 1.7.3
11534 @itemx 2003-04-23 Automake 1.7.4
11535 @itemx 2003-05-18 Automake 1.7.5
11536 @itemx 2003-07-10 Automake 1.7.6
11537 @itemx 2003-09-07 Automake 1.7.7
11538 @itemx 2003-10-07 Automake 1.7.8
11540 Many bug-fix releases.  1.7 lasted because the development version
11541 (upcoming 1.8) was suffering some major internal revamping.
11543 @item 2003-10-26 Automake on screen
11545 Episode 49, `Repercussions', in the third season of the `Alias' TV
11546 show is first aired.
11548 Marshall, one of the character, is working on a computer virus that he
11549 has to modify before it gets into the wrong hands or something like
11550 that.  The screenshots you see do not show any program code, they show
11551 a @file{Makefile.in} @code{generated by automake}...
11553 @item 2003-11-09 Automake 1.7.9
11555 @item 2003-12-10 Automake 1.8
11557 The most striking update is probably that of @command{aclocal}.
11559 @command{aclocal} now uses @code{m4_include} in the produced
11560 @file{aclocal.m4} when the included macros are already distributed
11561 with the package (an idiom used in many packages), which reduces code
11562 duplication.  Many people liked that, but in fact this change was
11563 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
11564 must be rebuilt whenever a dependency of @file{configure} changes, but
11565 all the @file{m4} files included in @file{aclocal.m4} where unknown
11566 from @command{automake}.  Now @command{automake} can just trace the
11567 @code{m4_include}s to discover the dependencies.
11569 @command{aclocal} also starts using the @option{--trace} Autoconf option
11570 in order to discover used macros more accurately.  This will turn out
11571 to be very tricky (later releases will improve this) as people had
11572 devised many ways to cope with the limitation of previous
11573 @command{aclocal} versions, notably using handwritten
11574 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
11575 rule that is already included by such statement.
11577 Automake also has seen its guts rewritten.  Although this rewriting
11578 took a lot of efforts, it is only apparent to the users in that some
11579 constructions previously disallowed by the implementation now work
11580 nicely.  Conditionals, Locations, Variable and Rule definitions,
11581 Options: these items on which Automake works have been rewritten as
11582 separate Perl modules, and documented.
11584 @itemx 2004-01-11 Automake 1.8.1
11585 @itemx 2004-01-12 Automake 1.8.2
11586 @itemx 2004-03-07 Automake 1.8.3
11587 @itemx 2004-04-25 Automake 1.8.4
11588 @itemx 2004-05-16 Automake 1.8.5
11590 @item 2004-07-28 Automake 1.9
11592 This release tries to simplify the compilation rules it outputs to
11593 reduce the size of the Makefile.  The complaint initially come from
11594 the libgcj developers.  Their @file{Makefile.in} generated with
11595 Automake 1.4 and custom build rules (1.4 did not support compiled
11596 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
11597 down to 1.2MB@.
11599 Aside from this it contains mainly minor changes and bug-fixes.
11601 @itemx 2004-08-11 Automake 1.9.1
11602 @itemx 2004-09-19 Automake 1.9.2
11604 Automake has ten years.  This chapter of the manual was initially
11605 written for this occasion.
11607 @end table
11609 @node Dependency Tracking Evolution
11610 @section Dependency Tracking in Automake
11612 Over the years Automake has deployed three different dependency
11613 tracking methods.  Each method, including the current one, has had
11614 flaws of various sorts.  Here we lay out the different dependency
11615 tracking methods, their flaws, and their fixes.  We conclude with
11616 recommendations for tool writers, and by indicating future directions
11617 for dependency tracking work in Automake.
11619 @subsection First Take
11620 @unnumberedsubsubsec Description
11622 Our first attempt at automatic dependency tracking was based on the
11623 method recommended by GNU @command{make}.  (@pxref{Automatic
11624 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
11625 make Manual})
11627 This version worked by precomputing dependencies ahead of time.  For
11628 each source file, it had a special @file{.P} file that held the
11629 dependencies.  There was a rule to generate a @file{.P} file by
11630 invoking the compiler appropriately.  All such @file{.P} files were
11631 included by the @file{Makefile}, thus implicitly becoming dependencies
11632 of @file{Makefile}.
11634 @unnumberedsubsubsec Bugs
11636 This approach had several critical bugs.
11638 @itemize
11639 @item
11640 The code to generate the @file{.P} file relied on @command{gcc}.
11641 (A limitation, not technically a bug.)
11642 @item
11643 The dependency tracking mechanism itself relied on GNU @command{make}.
11644 (A limitation, not technically a bug.)
11645 @item
11646 Because each @file{.P} file was a dependency of @file{Makefile}, this
11647 meant that dependency tracking was done eagerly by @command{make}.
11648 For instance, @samp{make clean} would cause all the dependency files
11649 to be updated, and then immediately removed.  This eagerness also
11650 caused problems with some configurations; if a certain source file
11651 could not be compiled on a given architecture for some reason,
11652 dependency tracking would fail, aborting the entire build.
11653 @item
11654 As dependency tracking was done as a pre-pass, compile times were
11655 doubled--the compiler had to be run twice per source file.
11656 @item
11657 @samp{make dist} re-ran @command{automake} to generate a
11658 @file{Makefile} that did not have automatic dependency tracking (and
11659 that was thus portable to any version of @command{make}).  In order to
11660 do this portably, Automake had to scan the dependency files and remove
11661 any reference that was to a source file not in the distribution.
11662 This process was error-prone.  Also, if @samp{make dist} was run in an
11663 environment where some object file had a dependency on a source file
11664 that was only conditionally created, Automake would generate a
11665 @file{Makefile} that referred to a file that might not appear in the
11666 end user's build.  A special, hacky mechanism was required to work
11667 around this.
11668 @end itemize
11670 @unnumberedsubsubsec Historical Note
11672 The code generated by Automake is often inspired by the
11673 @file{Makefile} style of a particular author.  In the case of the first
11674 implementation of dependency tracking, I believe the impetus and
11675 inspiration was Jim Meyering.  (I could be mistaken.  If you know
11676 otherwise feel free to correct me.)
11678 @subsection Dependencies As Side Effects
11679 @unnumberedsubsubsec Description
11681 The next refinement of Automake's automatic dependency tracking scheme
11682 was to implement dependencies as side effects of the compilation.
11683 This was aimed at solving the most commonly reported problems with the
11684 first approach.  In particular we were most concerned with eliminating
11685 the weird rebuilding effect associated with make clean.
11687 In this approach, the @file{.P} files were included using the
11688 @code{-include} command, which let us create these files lazily.  This
11689 avoided the @samp{make clean} problem.
11691 We only computed dependencies when a file was actually compiled.  This
11692 avoided the performance penalty associated with scanning each file
11693 twice.  It also let us avoid the other problems associated with the
11694 first, eager, implementation.  For instance, dependencies would never
11695 be generated for a source file that was not compilable on a given
11696 architecture (because it in fact would never be compiled).
11698 @unnumberedsubsubsec Bugs
11700 @itemize
11701 @item
11702 This approach also relied on the existence of @command{gcc} and GNU
11703 @command{make}.  (A limitation, not technically a bug.)
11704 @item
11705 Dependency tracking was still done by the developer, so the problems
11706 from the first implementation relating to massaging of dependencies by
11707 @samp{make dist} were still in effect.
11708 @item
11709 This implementation suffered from the ``deleted header file'' problem.
11710 Suppose a lazily-created @file{.P} file includes a dependency on a
11711 given header file, like this:
11713 @example
11714 maude.o: maude.c something.h
11715 @end example
11717 Now suppose that the developer removes @file{something.h} and updates
11718 @file{maude.c} so that this include is no longer needed.  If he runs
11719 @command{make}, he will get an error because there is no way to create
11720 @file{something.h}.
11722 We fixed this problem in a later release by further massaging the
11723 output of @command{gcc} to include a dummy dependency for each header
11724 file.
11725 @end itemize
11727 @subsection Dependencies for the User
11728 @unnumberedsubsubsec Description
11730 The bugs associated with @samp{make dist}, over time, became a real
11731 problem.  Packages using Automake were being built on a large number
11732 of platforms, and were becoming increasingly complex.  Broken
11733 dependencies were distributed in ``portable'' @file{Makefile.in}s,
11734 leading to user complaints.  Also, the requirement for @command{gcc}
11735 and GNU @command{make} was a constant source of bug reports.  The next
11736 implementation of dependency tracking aimed to remove these problems.
11738 We realized that the only truly reliable way to automatically track
11739 dependencies was to do it when the package itself was built.  This
11740 meant discovering a method portable to any version of make and any
11741 compiler.  Also, we wanted to preserve what we saw as the best point
11742 of the second implementation: dependency computation as a side effect
11743 of compilation.
11745 In the end we found that most modern make implementations support some
11746 form of include directive.  Also, we wrote a wrapper script that let
11747 us abstract away differences between dependency tracking methods for
11748 compilers.  For instance, some compilers cannot generate dependencies
11749 as a side effect of compilation.  In this case we simply have the
11750 script run the compiler twice.  Currently our wrapper script
11751 (@command{depcomp}) knows about twelve different compilers (including
11752 a "compiler" that simply invokes @command{makedepend} and then the
11753 real compiler, which is assumed to be a standard Unix-like C compiler
11754 with no way to do dependency tracking).
11756 @unnumberedsubsubsec Bugs
11758 @itemize
11759 @item
11760 Running a wrapper script for each compilation slows down the build.
11761 @item
11762 Many users don't really care about precise dependencies.
11763 @item
11764 This implementation, like every other automatic dependency tracking
11765 scheme in common use today (indeed, every one we've ever heard of),
11766 suffers from the ``duplicated new header'' bug.
11768 This bug occurs because dependency tracking tools, such as the
11769 compiler, only generate dependencies on the successful opening of a
11770 file, and not on every probe.
11772 Suppose for instance that the compiler searches three directories for
11773 a given header, and that the header is found in the third directory.
11774 If the programmer erroneously adds a header file with the same name to
11775 the first directory, then a clean rebuild from scratch could fail
11776 (suppose the new header file is buggy), whereas an incremental rebuild
11777 will succeed.
11779 What has happened here is that people have a misunderstanding of what
11780 a dependency is.  Tool writers think a dependency encodes information
11781 about which files were read by the compiler.  However, a dependency
11782 must actually encode information about what the compiler tried to do.
11784 This problem is not serious in practice.  Programmers typically do not
11785 use the same name for a header file twice in a given project.  (At
11786 least, not in C or C++.  This problem may be more troublesome in
11787 Java.)  This problem is easy to fix, by modifying dependency
11788 generators to record every probe, instead of every successful open.
11790 @item
11791 Since automake generates dependencies as a side effect of compilation,
11792 there is a bootstrapping problem when header files are generated by
11793 running a program.  The problem is that, the first time the build is
11794 done, there is no way by default to know that the headers are
11795 required, so make might try to run a compilation for which the headers
11796 have not yet been built.
11798 This was also a problem in the previous dependency tracking implementation.
11800 The current fix is to use @code{BUILT_SOURCES} to list built headers
11801 (@pxref{Sources}).  This causes them to be built before any other
11802 build rules are run.  This is unsatisfactory as a general solution,
11803 however in practice it seems sufficient for most actual programs.
11804 @end itemize
11806 This code is used since Automake 1.5.
11808 In GCC 3.0, we managed to convince the maintainers to add special
11809 command-line options to help Automake more efficiently do its job.  We
11810 hoped this would let us avoid the use of a wrapper script when
11811 Automake's automatic dependency tracking was used with @command{gcc}.
11813 Unfortunately, this code doesn't quite do what we want.  In
11814 particular, it removes the dependency file if the compilation fails;
11815 we'd prefer that it instead only touch the file in any way if the
11816 compilation succeeds.
11818 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
11819 detected at @command{configure} time, we inline the
11820 dependency-generation code and do not use the @command{depcomp}
11821 wrapper script.  This makes compilations faster for those using this
11822 compiler (probably our primary user base).  The counterpart is that
11823 because we have to encode two compilation rules in @file{Makefile}
11824 (with or without @command{depcomp}), the produced @file{Makefile}s are
11825 larger.
11827 @subsection Techniques for Computing Dependencies
11829 There are actually several ways for a build tool like Automake to
11830 cause tools to generate dependencies.
11832 @table @asis
11833 @item @command{makedepend}
11834 This was a commonly-used method in the past.  The idea is to run a
11835 special program over the source and have it generate dependency
11836 information.  Traditional implementations of @command{makedepend} are
11837 not completely precise; ordinarily they were conservative and
11838 discovered too many dependencies.
11839 @item The tool
11840 An obvious way to generate dependencies is to simply write the tool so
11841 that it can generate the information needed by the build tool.  This is
11842 also the most portable method.  Many compilers have an option to
11843 generate dependencies.  Unfortunately, not all tools provide such an
11844 option.
11845 @item The file system
11846 It is possible to write a special file system that tracks opens,
11847 reads, writes, etc, and then feed this information back to the build
11848 tool.  @command{clearmake} does this.  This is a very powerful
11849 technique, as it doesn't require cooperation from the
11850 tool.  Unfortunately it is also very difficult to implement and also
11851 not practical in the general case.
11852 @item @code{LD_PRELOAD}
11853 Rather than use the file system, one could write a special library to
11854 intercept @code{open} and other syscalls.  This technique is also quite
11855 powerful, but unfortunately it is not portable enough for use in
11856 @command{automake}.
11857 @end table
11859 @subsection Recommendations for Tool Writers
11861 We think that every compilation tool ought to be able to generate
11862 dependencies as a side effect of compilation.  Furthermore, at least
11863 while @command{make}-based tools are nearly universally in use (at
11864 least in the free software community), the tool itself should generate
11865 dummy dependencies for header files, to avoid the deleted header file
11866 bug.  Finally, the tool should generate a dependency for each probe,
11867 instead of each successful file open, in order to avoid the duplicated
11868 new header bug.
11870 @subsection Future Directions for Automake's Dependency Tracking
11872 Currently, only languages and compilers understood by Automake can
11873 have dependency tracking enabled.  We would like to see if it is
11874 practical (and worthwhile) to let this support be extended by the user
11875 to languages unknown to Automake.
11877 @node Releases
11878 @section Release Statistics
11880 The following table (inspired by @samp{perlhist(1)}) quantifies the
11881 evolution of Automake using these metrics:
11883 @table @asis
11884 @item Date, Rel
11885 The date and version of the release.
11886 @item am
11887 The number of lines of the @command{automake} script.
11888 @item acl
11889 The number of lines of the @command{aclocal} script.
11890 @item pm
11891 The number of lines of the @command{Perl} supporting modules.
11892 @item @file{*.am}
11893 The number of lines of the @file{Makefile} fragments.  The number in parenthesis
11894 is the number of files.
11895 @item m4
11896 The number of lines (and files) of Autoconf macros.
11897 @item doc
11898 The number of pages of the documentation (the Postscript version).
11899 @item t
11900 The number of test cases in the test suite.
11901 @end table
11903 @multitable {8888-88-88} {8.8-p8} {8888} {8888} {8888} {8888 (88)} {8888 (88)} {888} {888}
11904 @headitem Date   @tab Rel @tab am @tab acl @tab pm @tab @file{*.am} @tab m4 @tab doc @tab t
11905 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
11906 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
11907 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
11908 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
11909 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
11910 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
11911 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
11912 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
11913 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
11914 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
11915 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
11916 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
11917 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
11918 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
11919 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
11920 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
11921 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
11922 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (20) @tab  37 @tab 126
11923 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (23) @tab  39 @tab 156
11924 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
11925 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
11926 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
11927 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
11928 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 198
11929 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (20) @tab  51 @tab 198
11930 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (29) @tab  63 @tab 327
11931 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (27) @tab  66 @tab 365
11932 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (27) @tab  66 @tab 372
11933 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (27) @tab  67 @tab 386
11934 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (27) @tab  67 @tab 391
11935 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (20) @tab  49 @tab 197
11936 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (28) @tab  73 @tab 430
11937 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (28) @tab  73 @tab 437
11938 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (28) @tab  77 @tab 445
11939 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (29) @tab  84 @tab 448
11940 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (29) @tab  85 @tab 458
11941 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (29) @tab  85 @tab 459
11942 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (29) @tab  85 @tab 461
11943 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 467
11944 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 468
11945 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (29) @tab  90 @tab 468
11946 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (31) @tab 104 @tab 521
11947 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (31) @tab 104 @tab 525
11948 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (31) @tab 104 @tab 526
11949 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (31) @tab 111 @tab 530
11950 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (31) @tab 112 @tab 531
11951 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (31) @tab 112 @tab 533
11952 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (32) @tab 115 @tab 551
11953 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 115 @tab 552
11954 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 132 @tab 554
11955 @item 2004-11-01 @tab 1.9.3  @tab 7507 @tab 718 @tab 7804 @tab 3354 (40) @tab 1812 (32) @tab 134 @tab 556
11956 @item 2004-12-18 @tab 1.9.4  @tab 7508 @tab 718 @tab 7856 @tab 3361 (40) @tab 1811 (32) @tab 140 @tab 560
11957 @item 2005-02-13 @tab 1.9.5  @tab 7523 @tab 719 @tab 7859 @tab 3373 (40) @tab 1453 (32) @tab 142 @tab 562
11958 @item 2005-07-10 @tab 1.9.6  @tab 7539 @tab 699 @tab 7867 @tab 3400 (40) @tab 1453 (32) @tab 144 @tab 570
11959 @item 2006-10-15 @tab 1.10   @tab 7859 @tab 1072 @tab 8024 @tab 3512 (40) @tab 1496 (34) @tab 172 @tab 604
11960 @end multitable
11963 @c ========================================================== Appendices
11965 @page
11966 @node Copying This Manual
11967 @appendix Copying This Manual
11969 @menu
11970 * GNU Free Documentation License::  License for copying this manual
11971 @end menu
11973 @include fdl.texi
11975 @page
11976 @node Indices
11977 @appendix Indices
11979 @menu
11980 * Macro Index::                 Index of Autoconf macros
11981 * Variable Index::              Index of Makefile variables
11982 * General Index::               General index
11983 @end menu
11985 @node Macro Index
11986 @appendixsec Macro Index
11988 @printindex fn
11990 @node Variable Index
11991 @appendixsec Variable Index
11993 @printindex vr
11995 @node General Index
11996 @appendixsec General Index
11998 @printindex cp
12001 @page
12002 @contents
12003 @bye
12005 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
12006 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
12007 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
12008 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
12009 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
12010 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
12011 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
12012 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
12013 @c  LocalWords:  libmumble CC YFLAGS ansi knr itemx de fication config url comp
12014 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
12015 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
12016 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
12017 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
12018 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
12019 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
12020 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
12021 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
12022 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
12023 @c  LocalWords:  dirlist noindent usr MULTILIB multilib Multilibs TIOCGWINSZ sc
12024 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
12025 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
12026 @c  LocalWords:  dmalloc ldmalloc REGEX regex rx DEPDIR DEP DEFUN aclocaldir fi
12027 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
12028 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
12029 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
12030 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
12031 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
12032 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
12033 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
12034 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
12035 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
12036 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
12037 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
12038 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
12039 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
12040 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
12041 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
12042 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
12043 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
12044 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
12045 @c  LocalWords:  unnumberedsubsec depfile tmpdepfile depmode const interoperate
12046 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
12047 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
12048 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
12049 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
12050 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
12051 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
12052 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
12053 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
12054 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
12055 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid multilibbing cd
12056 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
12057 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
12058 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
12059 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
12060 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
12061 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
12062 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
12063 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
12064 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
12065 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
12066 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
12067 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
12068 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
12069 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
12070 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
12071 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
12072 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
12073 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
12074 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
12075 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
12076 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
12077 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
12078 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
12079 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
12080 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
12081 @c  LocalWords:  barexec Pinard's automatize initialize