build: Inline perl prototypes in sources
[automake.git] / doc / automake.texi
blobdbe222d205405f8b5b7fc7afbf84f2e721c999c2
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @documentencoding UTF-8
6 @documentlanguage en
7 @setchapternewpage off
8 @c %**end of header
10 @include version.texi
12 @c @ovar(ARG, DEFAULT)
13 @c -------------------
14 @c The ARG is an optional argument.  To be used for macro arguments in
15 @c their documentation (@defmac).
16 @macro ovar{varname}
17 @r{[}@var{\varname\}@r{]}
18 @end macro
20 @set PACKAGE_BUGREPORT bug-automake@@gnu.org
22 @copying
24 This manual is for GNU Automake (version @value{VERSION},
25 @value{UPDATED}), a program that creates GNU standards-compliant
26 Makefiles from template files.
28 Copyright @copyright{} 1995-2017 Free Software Foundation, Inc.
30 @quotation
31 Permission is granted to copy, distribute and/or modify this document
32 under the terms of the GNU Free Documentation License,
33 Version 1.3 or any later version published by the Free Software
34 Foundation; with no Invariant Sections, with no Front-Cover texts,
35 and with no Back-Cover Texts.  A copy of the license is included in the
36 section entitled ``GNU Free Documentation License.''
38 @end quotation
39 @end copying
41 @dircategory Software development
42 @direntry
43 * Automake: (automake).         Making GNU standards-compliant Makefiles.
44 @end direntry
46 @dircategory Individual utilities
47 @direntry
48 * aclocal-invocation: (automake)aclocal Invocation.   Generating aclocal.m4.
49 * automake-invocation: (automake)automake Invocation. Generating Makefile.in.
50 @end direntry
52 @titlepage
53 @title GNU Automake
54 @subtitle For version @value{VERSION}, @value{UPDATED}
55 @author David MacKenzie
56 @author Tom Tromey
57 @author Alexandre Duret-Lutz
58 @author Ralf Wildenhues
59 @author Stefano Lattarini
60 @page
61 @vskip 0pt plus 1filll
62 @insertcopying
63 @end titlepage
65 @contents
67 @c We use the following macros to define indices:
68 @c   @cindex   concepts, and anything that does not fit elsewhere
69 @c   @vindex   Makefile variables
70 @c   @trindex  targets
71 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
72 @c   @opindex  tool options
74 @c Define an index of configure macros.
75 @defcodeindex ac
76 @c Define an index of options.
77 @defcodeindex op
78 @c Define an index of targets.
79 @defcodeindex tr
80 @c Define an index of commands.
81 @defcodeindex cm
83 @c Put the macros in the function index.
84 @syncodeindex ac fn
86 @c Put everything else into one index (arbitrarily chosen to be the
87 @c concept index).
88 @syncodeindex op cp
89 @syncodeindex tr cp
90 @syncodeindex cm cp
92 @ifnottex
93 @node Top
94 @comment  node-name,  next,  previous,  up
95 @top GNU Automake
97 @insertcopying
99 @menu
100 * Introduction::                Automake's purpose
101 * Autotools Introduction::      An Introduction to the Autotools
102 * Generalities::                General ideas
103 * Examples::                    Some example packages
104 * automake Invocation::         Creating a Makefile.in
105 * configure::                   Scanning configure.ac, using aclocal
106 * Directories::                 Declaring subdirectories
107 * Programs::                    Building programs and libraries
108 * Other Objects::               Other derived objects
109 * Other GNU Tools::             Other GNU Tools
110 * Documentation::               Building documentation
111 * Install::                     What gets installed
112 * Clean::                       What gets cleaned
113 * Dist::                        What goes in a distribution
114 * Tests::                       Support for test suites
115 * Rebuilding::                  Automatic rebuilding of Makefile
116 * Options::                     Changing Automake's behavior
117 * Miscellaneous::               Miscellaneous rules
118 * Include::                     Including extra files in an Automake template
119 * Conditionals::                Conditionals
120 * Silencing Make::              Obtain less verbose output from @command{make}
121 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
122 * Not Enough::                  When Automake is not Enough
123 * Distributing::                Distributing the Makefile.in
124 * API Versioning::              About compatibility between Automake versions
125 * Upgrading::                   Upgrading to a Newer Automake Version
126 * FAQ::                         Frequently Asked Questions
127 * Copying This Manual::         How to make copies of this manual
128 * Indices::                     Indices of variables, macros, and concepts
130 @detailmenu
131  --- The Detailed Node Listing ---
133 An Introduction to the Autotools
135 * GNU Build System::            Introducing the GNU Build System
136 * Use Cases::                   Use Cases for the GNU Build System
137 * Why Autotools::               How Autotools Help
138 * Hello World::                 A Small Hello World Package
140 Use Cases for the GNU Build System
142 * Basic Installation::          Common installation procedure
143 * Standard Targets::            A list of standard Makefile targets
144 * Standard Directory Variables::  A list of standard directory variables
145 * Standard Configuration Variables::  Using configuration variables
146 * config.site::                 Using a config.site file
147 * VPATH Builds::                Parallel build trees
148 * Two-Part Install::            Installing data and programs separately
149 * Cross-Compilation::           Building for other architectures
150 * Renaming::                    Renaming programs at install time
151 * DESTDIR::                     Building binary packages with DESTDIR
152 * Preparing Distributions::     Rolling out tarballs
153 * Dependency Tracking::         Automatic dependency tracking
154 * Nested Packages::             The GNU Build Systems can be nested
156 A Small Hello World
158 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
159 * amhello's configure.ac Setup Explained::
160 * amhello's Makefile.am Setup Explained::
162 General ideas
164 * General Operation::           General operation of Automake
165 * Strictness::                  Standards conformance checking
166 * Uniform::                     The Uniform Naming Scheme
167 * Length Limitations::          Staying below the command line length limit
168 * Canonicalization::            How derived variables are named
169 * User Variables::              Variables reserved for the user
170 * Auxiliary Programs::          Programs automake might require
172 Some example packages
174 * Complete::                    A simple example, start to finish
175 * true::                        Building true and false
177 Scanning @file{configure.ac}, using @command{aclocal}
179 * Requirements::                Configuration requirements
180 * Optional::                    Other things Automake recognizes
181 * aclocal Invocation::          Auto-generating aclocal.m4
182 * Macros::                      Autoconf macros supplied with Automake
184 Auto-generating aclocal.m4
186 * aclocal Options::             Options supported by aclocal
187 * Macro Search Path::           How aclocal finds .m4 files
188 * Extending aclocal::           Writing your own aclocal macros
189 * Local Macros::                Organizing local macros
190 * Serials::                     Serial lines in Autoconf macros
191 * Future of aclocal::           aclocal's scheduled death
193 Autoconf macros supplied with Automake
195 * Public Macros::               Macros that you can use.
196 * Private Macros::              Macros that you should not use.
198 Directories
200 * Subdirectories::              Building subdirectories recursively
201 * Conditional Subdirectories::  Conditionally not building directories
202 * Alternative::                 Subdirectories without recursion
203 * Subpackages::                 Nesting packages
205 Conditional Subdirectories
207 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
208 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
209 * Subdirectories with AC_SUBST::  Another way for conditional recursion
210 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
212 Building Programs and Libraries
214 * A Program::                   Building a program
215 * A Library::                   Building a library
216 * A Shared Library::            Building a Libtool library
217 * Program and Library Variables::  Variables controlling program and
218                                 library builds
219 * Default _SOURCES::            Default source files
220 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
221 * Program Variables::           Variables used when building a program
222 * Yacc and Lex::                Yacc and Lex support
223 * C++ Support::                 Compiling C++ sources
224 * Objective C Support::         Compiling Objective C sources
225 * Objective C++ Support::       Compiling Objective C++ sources
226 * Unified Parallel C Support::  Compiling Unified Parallel C sources
227 * Assembly Support::            Compiling assembly sources
228 * Fortran 77 Support::          Compiling Fortran 77 sources
229 * Fortran 9x Support::          Compiling Fortran 9x sources
230 * Java Support with gcj::       Compiling Java sources using gcj
231 * Vala Support::                Compiling Vala sources
232 * Support for Other Languages::  Compiling other languages
233 * Dependencies::                Automatic dependency tracking
234 * EXEEXT::                      Support for executable extensions
236 Building a program
238 * Program Sources::             Defining program sources
239 * Linking::                     Linking with libraries or extra objects
240 * Conditional Sources::         Handling conditional sources
241 * Conditional Programs::        Building a program conditionally
243 Building a Shared Library
245 * Libtool Concept::             Introducing Libtool
246 * Libtool Libraries::           Declaring Libtool Libraries
247 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
248 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
249 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
250 * Libtool Modules::             Building Libtool Modules
251 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
252 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
253 * Libtool Issues::              Common Issues Related to Libtool's Use
255 Common Issues Related to Libtool's Use
257 * Error required file ltmain.sh not found::  The need to run libtoolize
258 * Objects created both with libtool and without::  Avoid a specific build race
260 Fortran 77 Support
262 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
263 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
264 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
266 Mixing Fortran 77 With C and C++
268 * How the Linker is Chosen::    Automatic linker selection
270 Fortran 9x Support
272 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
274 Other Derived Objects
276 * Scripts::                     Executable scripts
277 * Headers::                     Header files
278 * Data::                        Architecture-independent data files
279 * Sources::                     Derived sources
281 Built Sources
283 * Built Sources Example::       Several ways to handle built sources.
285 Other GNU Tools
287 * Emacs Lisp::                  Emacs Lisp
288 * gettext::                     Gettext
289 * Libtool::                     Libtool
290 * Java::                        Java bytecode compilation (deprecated)
291 * Python::                      Python
293 Building documentation
295 * Texinfo::                     Texinfo
296 * Man Pages::                   Man pages
298 What Gets Installed
300 * Basics of Installation::      What gets installed where
301 * The Two Parts of Install::    Installing data and programs separately
302 * Extending Installation::      Adding your own rules for installation
303 * Staged Installs::             Installation in a temporary location
304 * Install Rules for the User::  Useful additional rules
306 What Goes in a Distribution
308 * Basics of Distribution::      Files distributed by default
309 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
310 * The dist Hook::               A target for last-minute distribution changes
311 * Checking the Distribution::   @samp{make distcheck} explained
312 * The Types of Distributions::  A variety of formats and compression methods
314 Support for test suites
316 * Generalities about Testing::  Generic concepts and terminology about testing
317 * Simple Tests::                Listing test scripts in @code{TESTS}
318 * Custom Test Drivers::         Writing and using custom test drivers
319 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
320 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
321 * Install Tests::               Running tests on installed packages
323 Simple Tests
325 * Scripts-based Testsuites::    Automake-specific concepts and terminology
326 * Serial Test Harness::         Older (and discouraged) serial test harness
327 * Parallel Test Harness::       Generic concurrent test harness
329 Using the TAP test protocol
331 * Introduction to TAP::
332 * Use TAP with the Automake test harness::
333 * Incompatibilities with other TAP parsers and drivers::
334 * Links and external resources on TAP::
336 Custom Test Drivers
338 * Overview of Custom Test Drivers Support::
339 * Declaring Custom Test Drivers::
340 * API for Custom Test Drivers::
342 API for Custom Test Drivers
344 * Command-line arguments for test drivers::
345 * Log files generation and test results recording::
346 * Testsuite progress output::
348 Changing Automake's Behavior
350 * Options generalities::        Semantics of Automake option
351 * List of Automake options::    A comprehensive list of Automake options
353 Miscellaneous Rules
355 * Tags::                        Interfacing to cscope, etags and mkid
356 * Suffixes::                    Handling new file extensions
358 Conditionals
360 * Usage of Conditionals::       Declaring conditional content
361 * Limits of Conditionals::      Enclosing complete statements
363 Silencing Make
365 * Make verbosity::              Make is verbose by default
366 * Tricks For Silencing Make::   Standard and generic ways to silence make
367 * Automake Silent Rules::       How Automake can help in silencing make
369 When Automake Isn't Enough
371 * Extending::                   Adding new rules or overriding existing ones.
372 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
374 Frequently Asked Questions about Automake
376 * CVS::                         CVS and generated files
377 * maintainer-mode::             missing and AM_MAINTAINER_MODE
378 * Wildcards::                   Why doesn't Automake support wildcards?
379 * Limitations on File Names::   Limitations on source and installed file names
380 * Errors with distclean::       Files left in build directory after distclean
381 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
382 * Renamed Objects::             Why are object files sometimes renamed?
383 * Per-Object Flags::            How to simulate per-object flags?
384 * Multiple Outputs::            Writing rules for tools with many output files
385 * Hard-Coded Install Paths::    Installing to hard-coded locations
386 * Debugging Make Rules::        Strategies when things don't work as expected
387 * Reporting Bugs::              Feedback on bugs and feature requests
389 Copying This Manual
391 * GNU Free Documentation License::  License for copying this manual
393 Indices
395 * Macro Index::                 Index of Autoconf macros
396 * Variable Index::              Index of Makefile variables
397 * General Index::               General index
399 @end detailmenu
400 @end menu
402 @end ifnottex
405 @node Introduction
406 @chapter Introduction
408 Automake is a tool for automatically generating @file{Makefile.in}s
409 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
410 basically a series of @command{make} variable
411 definitions@footnote{These variables are also called @dfn{make macros}
412 in Make terminology, however in this manual we reserve the term
413 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
414 occasionally.  The generated @file{Makefile.in}s are compliant with
415 the GNU Makefile standards.
417 @cindex GNU Makefile standards
419 The GNU Makefile Standards Document
420 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
421 is long, complicated, and subject to change.  The goal of Automake is to
422 remove the burden of Makefile maintenance from the back of the
423 individual GNU maintainer (and put it on the back of the Automake
424 maintainers).
426 The typical Automake input file is simply a series of variable definitions.
427 Each such file is processed to create a @file{Makefile.in}.
429 @cindex Constraints of Automake
430 @cindex Automake constraints
432 Automake does constrain a project in certain ways; for instance, it
433 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
434 autoconf, The Autoconf Manual}), and enforces certain restrictions on
435 the @file{configure.ac} contents.
437 @cindex Automake requirements
438 @cindex Requirements, Automake
440 Automake requires @command{perl} in order to generate the
441 @file{Makefile.in}s.  However, the distributions created by Automake are
442 fully GNU standards-compliant, and do not require @command{perl} in order
443 to be built.
445 @cindex Bugs, reporting
446 @cindex Reporting bugs
447 @cindex E-mail, bug reports
449 For more information on bug reports, @xref{Reporting Bugs}.
451 @node Autotools Introduction
452 @chapter An Introduction to the Autotools
454 If you are new to Automake, maybe you know that it is part of a set of
455 tools called @emph{The Autotools}.  Maybe you've already delved into a
456 package full of files named @file{configure}, @file{configure.ac},
457 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
458 some of them claiming to be @emph{generated by} Autoconf or Automake.
459 But the exact purpose of these files and their relations is probably
460 fuzzy.  The goal of this chapter is to introduce you to this machinery,
461 to show you how it works and how powerful it is.  If you've never
462 installed or seen such a package, do not worry: this chapter will walk
463 you through it.
465 If you need some teaching material, more illustrations, or a less
466 @command{automake}-centered continuation, some slides for this
467 introduction are available in Alexandre Duret-Lutz's
468 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
469 Autotools Tutorial}.
470 This chapter is the written version of the first part of his tutorial.
472 @menu
473 * GNU Build System::            Introducing the GNU Build System
474 * Use Cases::                   Use Cases for the GNU Build System
475 * Why Autotools::               How Autotools Help
476 * Hello World::                 A Small Hello World Package
477 @end menu
479 @node GNU Build System
480 @section Introducing the GNU Build System
481 @cindex GNU Build System, introduction
483 It is a truth universally acknowledged, that as a developer in
484 possession of a new package, you must be in want of a build system.
486 In the Unix world, such a build system is traditionally achieved using
487 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
488 Manual}).  You express the recipe to build your package in a
489 @file{Makefile}.  This file is a set of rules to build the files in
490 the package.  For instance the program @file{prog} may be built by
491 running the linker on the files @file{main.o}, @file{foo.o}, and
492 @file{bar.o}; the file @file{main.o} may be built by running the
493 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
494 reads @file{Makefile}, checks the existence and modification time of
495 the files mentioned, decides what files need to be built (or rebuilt),
496 and runs the associated commands.
498 When a package needs to be built on a different platform than the one
499 it was developed on, its @file{Makefile} usually needs to be adjusted.
500 For instance the compiler may have another name or require more
501 options.  In 1991, David J. MacKenzie got tired of customizing
502 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
503 handcrafted a little shell script called @file{configure} to
504 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
505 autoconf, The Autoconf Manual}).  Compiling his package was now
506 as simple as running @code{./configure && make}.
508 @cindex GNU Coding Standards
510 Today this process has been standardized in the GNU project.  The GNU
511 Coding Standards (@pxref{Managing Releases, The Release Process, ,
512 standards, The GNU Coding Standards}) explains how each package of the
513 GNU project should have a @file{configure} script, and the minimal
514 interface it should have.  The @file{Makefile} too should follow some
515 established conventions.  The result?  A unified build system that
516 makes all packages almost indistinguishable by the installer.  In its
517 simplest scenario, all the installer has to do is to unpack the
518 package, run @code{./configure && make && make install}, and repeat
519 with the next package to install.
521 We call this build system the @dfn{GNU Build System}, since it was
522 grown out of the GNU project.  However it is used by a vast number of
523 other packages: following any existing convention has its advantages.
525 @cindex Autotools, introduction
527 The Autotools are tools that will create a GNU Build System for your
528 package.  Autoconf mostly focuses on @file{configure} and Automake on
529 @file{Makefile}s.  It is entirely possible to create a GNU Build
530 System without the help of these tools.  However it is rather
531 burdensome and error-prone.  We will discuss this again after some
532 illustration of the GNU Build System in action.
534 @node Use Cases
535 @section Use Cases for the GNU Build System
536 @cindex GNU Build System, use cases
537 @cindex GNU Build System, features
538 @cindex Features of the GNU Build System
539 @cindex Use Cases for the GNU Build System
540 @cindex @file{amhello-1.0.tar.gz}, location
541 @cindex @file{amhello-1.0.tar.gz}, use cases
543 In this section we explore several use cases for the GNU Build System.
544 You can replay all of these examples on the @file{amhello-1.0.tar.gz}
545 package distributed with Automake.  If Automake is installed on your
546 system, you should find a copy of this file in
547 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
548 @var{prefix} is the installation prefix specified during configuration
549 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
550 installed by some GNU/Linux distribution it most likely has been set
551 to @file{/usr}).  If you do not have a copy of Automake installed,
552 you can find a copy of this file inside the @file{doc/} directory of
553 the Automake package.
555 Some of the following use cases present features that are in fact
556 extensions to the GNU Build System.  Read: they are not specified by
557 the GNU Coding Standards, but they are nonetheless part of the build
558 system created by the Autotools.  To keep things simple, we do not
559 point out the difference.  Our objective is to show you many of the
560 features that the build system created by the Autotools will offer to
561 you.
563 @menu
564 * Basic Installation::          Common installation procedure
565 * Standard Targets::            A list of standard Makefile targets
566 * Standard Directory Variables::  A list of standard directory variables
567 * Standard Configuration Variables::  Using configuration variables
568 * config.site::                 Using a config.site file
569 * VPATH Builds::                Parallel build trees
570 * Two-Part Install::            Installing data and programs separately
571 * Cross-Compilation::           Building for other architectures
572 * Renaming::                    Renaming programs at install time
573 * DESTDIR::                     Building binary packages with DESTDIR
574 * Preparing Distributions::     Rolling out tarballs
575 * Dependency Tracking::         Automatic dependency tracking
576 * Nested Packages::             The GNU Build Systems can be nested
577 @end menu
579 @node Basic Installation
580 @subsection Basic Installation
581 @cindex Configuration, basics
582 @cindex Installation, basics
583 @cindex GNU Build System, basics
585 The most common installation procedure looks as follows.
587 @example
588 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
589 ~ % @kbd{cd amhello-1.0}
590 ~/amhello-1.0 % @kbd{./configure}
591 @dots{}
592 config.status: creating Makefile
593 config.status: creating src/Makefile
594 @dots{}
595 ~/amhello-1.0 % @kbd{make}
596 @dots{}
597 ~/amhello-1.0 % @kbd{make check}
598 @dots{}
599 ~/amhello-1.0 % @kbd{su}
600 Password:
601 /home/adl/amhello-1.0 # @kbd{make install}
602 @dots{}
603 /home/adl/amhello-1.0 # @kbd{exit}
604 ~/amhello-1.0 % @kbd{make installcheck}
605 @dots{}
606 @end example
608 @cindex Unpacking
610 The user first unpacks the package.  Here, and in the following
611 examples, we will use the non-portable @code{tar zxf} command for
612 simplicity.  On a system without GNU @command{tar} installed, this
613 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
615 The user then enters the newly created directory to run the
616 @file{configure} script.  This script probes the system for various
617 features, and finally creates the @file{Makefile}s.  In this toy
618 example there are only two @file{Makefile}s, but in real-world projects,
619 there may be many more, usually one @file{Makefile} per directory.
621 It is now possible to run @code{make}.  This will construct all the
622 programs, libraries, and scripts that need to be constructed for the
623 package.  In our example, this compiles the @file{hello} program.
624 All files are constructed in place, in the source tree; we will see
625 later how this can be changed.
627 @code{make check} causes the package's tests to be run.  This step is
628 not mandatory, but it is often good to make sure the programs that
629 have been built behave as they should, before you decide to install
630 them.  Our example does not contain any tests, so running @code{make
631 check} is a no-op.
633 @cindex su, before @code{make install}
634 After everything has been built, and maybe tested, it is time to
635 install it on the system.  That means copying the programs,
636 libraries, header files, scripts, and other data files from the
637 source directory to their final destination on the system.  The
638 command @code{make install} will do that.  However, by default
639 everything will be installed in subdirectories of @file{/usr/local}:
640 binaries will go into @file{/usr/local/bin}, libraries will end up in
641 @file{/usr/local/lib}, etc.  This destination is usually not writable
642 by any user, so we assume that we have to become root before we can
643 run @code{make install}.  In our example, running @code{make install}
644 will copy the program @file{hello} into @file{/usr/local/bin}
645 and @file{README} into @file{/usr/local/share/doc/amhello}.
647 A last and optional step is to run @code{make installcheck}.  This
648 command may run tests on the installed files.  @code{make check} tests
649 the files in the source tree, while @code{make installcheck} tests
650 their installed copies.  The tests run by the latter can be different
651 from those run by the former.  For instance, there are tests that
652 cannot be run in the source tree.  Conversely, some packages are set
653 up so that @code{make installcheck} will run the very same tests as
654 @code{make check}, only on different files (non-installed
655 vs.@: installed).  It can make a difference, for instance when the
656 source tree's layout is different from that of the installation.
657 Furthermore it may help to diagnose an incomplete installation.
659 Presently most packages do not have any @code{installcheck} tests
660 because the existence of @code{installcheck} is little known, and its
661 usefulness is neglected.  Our little toy package is no better: @code{make
662 installcheck} does nothing.
664 @node Standard Targets
665 @subsection Standard @file{Makefile} Targets
667 So far we have come across four ways to run @command{make} in the GNU
668 Build System: @code{make}, @code{make check}, @code{make install}, and
669 @code{make installcheck}.  The words @code{check}, @code{install}, and
670 @code{installcheck}, passed as arguments to @command{make}, are called
671 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
672 @code{all} being the default target in the GNU Build System.
674 Here is a list of the most useful targets that the GNU Coding Standards
675 specify.
677 @table @code
678 @item make all
679 @trindex all
680 Build programs, libraries, documentation, etc.@: (same as @code{make}).
681 @item make install
682 @trindex install
683 Install what needs to be installed, copying the files from the
684 package's tree to system-wide directories.
685 @item make install-strip
686 @trindex install-strip
687 Same as @code{make install}, then strip debugging symbols.  Some
688 users like to trade space for useful bug reports@enddots{}
689 @item make uninstall
690 @trindex uninstall
691 The opposite of @code{make install}: erase the installed files.
692 (This needs to be run from the same build tree that was installed.)
693 @item make clean
694 @trindex clean
695 Erase from the build tree the files built by @code{make all}.
696 @item make distclean
697 @trindex distclean
698 Additionally erase anything @code{./configure} created.
699 @item make check
700 @trindex check
701 Run the test suite, if any.
702 @item make installcheck
703 @trindex installcheck
704 Check the installed programs or libraries, if supported.
705 @item make dist
706 @trindex dist
707 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
708 files.
709 @end table
711 @node Standard Directory Variables
712 @subsection Standard Directory Variables
713 @cindex directory variables
715 The GNU Coding Standards also specify a hierarchy of variables to
716 denote installation directories.  Some of these are:
718 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
719 @headitem Directory variable    @tab Default value
720 @item @code{prefix}              @tab @code{/usr/local}
721 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
722 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
723 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
724 @item @w{@ @ @ @ @dots{}}
725 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
726 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
727 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
728 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
729 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
730 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
731 @item @w{@ @ @dots{}}
732 @end multitable
734 @c We should provide a complete table somewhere, but not here.  The
735 @c complete list of directory variables it too confusing as-is.  It
736 @c requires some explanations that are too complicated for this
737 @c introduction.  Besides listing directories like localstatedir
738 @c would make the explanations in ``Two-Part Install'' harder.
740 Each of these directories has a role which is often obvious from its
741 name.  In a package, any installable file will be installed in one of
742 these directories.  For instance in @code{amhello-1.0}, the program
743 @file{hello} is to be installed in @var{bindir}, the directory for
744 binaries.  The default value for this directory is
745 @file{/usr/local/bin}, but the user can supply a different value when
746 calling @command{configure}.  Also the file @file{README} will be
747 installed into @var{docdir}, which defaults to
748 @file{/usr/local/share/doc/amhello}.
750 @opindex --prefix
752 As a user, if you wish to install a package on your own account, you
753 could proceed as follows:
755 @example
756 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
757 @dots{}
758 ~/amhello-1.0 % @kbd{make}
759 @dots{}
760 ~/amhello-1.0 % @kbd{make install}
761 @dots{}
762 @end example
764 This would install @file{~/usr/bin/hello} and
765 @file{~/usr/share/doc/amhello/README}.
767 The list of all such directory options is shown by
768 @code{./configure --help}.
770 @node Standard Configuration Variables
771 @subsection Standard Configuration Variables
772 @cindex configuration variables, overriding
774 The GNU Coding Standards also define a set of standard configuration
775 variables used during the build.  Here are some:
777 @table @asis
778 @item @code{CC}
779 C compiler command
780 @item @code{CFLAGS}
781 C compiler flags
782 @item @code{CXX}
783 C++ compiler command
784 @item @code{CXXFLAGS}
785 C++ compiler flags
786 @item @code{LDFLAGS}
787 linker flags
788 @item @code{CPPFLAGS}
789 C/C++ preprocessor flags
790 @item @dots{}
791 @end table
793 @command{configure} usually does a good job at setting appropriate
794 values for these variables, but there are cases where you may want to
795 override them.  For instance you may have several versions of a
796 compiler installed and would like to use another one, you may have
797 header files installed outside the default search path of the
798 compiler, or even libraries out of the way of the linker.
800 Here is how one would call @command{configure} to force it to use
801 @command{gcc-3} as C compiler, use header files from
802 @file{~/usr/include} when compiling, and libraries from
803 @file{~/usr/lib} when linking.
805 @example
806 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
807 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
808 @end example
810 Again, a full list of these variables appears in the output of
811 @code{./configure --help}.
813 @node config.site
814 @subsection Overriding Default Configuration Setting with @file{config.site}
815 @cindex @file{config.site} example
817 When installing several packages using the same setup, it can be
818 convenient to create a file to capture common settings.
819 If a file named @file{@var{prefix}/share/config.site} exists,
820 @command{configure} will source it at the beginning of its execution.
822 Recall the command from the previous section:
824 @example
825 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
826 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
827 @end example
829 Assuming we are installing many package in @file{~/usr}, and will
830 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
831 @code{LDFLAGS}, we can automate this by creating the following
832 @file{~/usr/share/config.site} file:
834 @example
835 test -z "$CC" && CC=gcc-3
836 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
837 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
838 @end example
840 Now, any time a @file{configure} script is using the @file{~/usr}
841 prefix, it will execute the above @file{config.site} and define
842 these three variables.
844 @example
845 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
846 configure: loading site script /home/adl/usr/share/config.site
847 @dots{}
848 @end example
850 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
851 Manual}, for more information about this feature.
854 @node VPATH Builds
855 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
856 @cindex Parallel build trees
857 @cindex VPATH builds
858 @cindex source tree and build tree
859 @cindex build tree and source tree
860 @cindex trees, source vs.@: build
862 The GNU Build System distinguishes two trees: the source tree, and
863 the build tree.
865 The source tree is rooted in the directory containing
866 @file{configure}.  It contains all the sources files (those that are
867 distributed), and may be arranged using several subdirectories.
869 The build tree is rooted in the directory in which @file{configure}
870 was run, and is populated with all object files, programs, libraries,
871 and other derived files built from the sources (and hence not
872 distributed).  The build tree usually has the same subdirectory layout
873 as the source tree; its subdirectories are created automatically by
874 the build system.
876 If @file{configure} is executed in its own directory, the source and
877 build trees are combined: derived files are constructed in the same
878 directories as their sources.  This was the case in our first
879 installation example (@pxref{Basic Installation}).
881 A common request from users is that they want to confine all derived
882 files to a single directory, to keep their source directories
883 uncluttered.  Here is how we could run @file{configure} to build
884 everything in a subdirectory called @file{build/}.
886 @example
887 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
888 ~ % @kbd{cd amhello-1.0}
889 ~/amhello-1.0 % @kbd{mkdir build && cd build}
890 ~/amhello-1.0/build % @kbd{../configure}
891 @dots{}
892 ~/amhello-1.0/build % @kbd{make}
893 @dots{}
894 @end example
896 These setups, where source and build trees are different, are often
897 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
898 @emph{parallel build} is misleading: the word @emph{parallel} is a
899 reference to the way the build tree shadows the source tree, it is not
900 about some concurrency in the way build commands are run.  For this
901 reason we refer to such setups using the name @emph{VPATH builds} in
902 the following.  @emph{VPATH} is the name of the @command{make} feature
903 used by the @file{Makefile}s to allow these builds (@pxref{General
904 Search, , @code{VPATH} Search Path for All Prerequisites, make, The
905 GNU Make Manual}).
907 @cindex multiple configurations, example
908 @cindex debug build, example
909 @cindex optimized build, example
911 VPATH builds have other interesting uses.  One is to build the same
912 sources with multiple configurations.  For instance:
914 @c Keep in sync with amhello-cflags.sh
915 @example
916 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
917 ~ % @kbd{cd amhello-1.0}
918 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
919 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
920 @dots{}
921 ~/amhello-1.0/debug % @kbd{make}
922 @dots{}
923 ~/amhello-1.0/debug % cd ../optim
924 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
925 @dots{}
926 ~/amhello-1.0/optim % @kbd{make}
927 @dots{}
928 @end example
930 With network file systems, a similar approach can be used to build the
931 same sources on different machines.  For instance, suppose that the
932 sources are installed on a directory shared by two hosts: @code{HOST1}
933 and @code{HOST2}, which may be different platforms.
935 @example
936 ~ % @kbd{cd /nfs/src}
937 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
938 @end example
940 On the first host, you could create a local build directory:
941 @example
942 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
943 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
945 [HOST1] /tmp/amh % @kbd{make && sudo make install}
947 @end example
949 @noindent
950 (Here we assume that the installer has configured @command{sudo} so it
951 can execute @code{make install} with root privileges; it is more convenient
952 than using @command{su} like in @ref{Basic Installation}).
954 On the second host, you would do exactly the same, possibly at
955 the same time:
956 @example
957 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
958 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
960 [HOST2] /tmp/amh % @kbd{make && sudo make install}
962 @end example
964 @cindex read-only source tree
965 @cindex source tree, read-only
967 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
968 directory from being read-only.  In fact VPATH builds are also a means
969 of building packages from a read-only medium such as a CD-ROM.  (The
970 FSF used to sell CD-ROM with unpacked source code, before the GNU
971 project grew so big.)
973 @node Two-Part Install
974 @subsection Two-Part Installation
976 In our last example (@pxref{VPATH Builds}), a source tree was shared
977 by two hosts, but compilation and installation were done separately on
978 each host.
980 The GNU Build System also supports networked setups where part of the
981 installed files should be shared amongst multiple hosts.  It does so
982 by distinguishing architecture-dependent files from
983 architecture-independent files, and providing two @file{Makefile}
984 targets to install each of these classes of files.
986 @trindex install-exec
987 @trindex install-data
989 These targets are @code{install-exec} for architecture-dependent files
990 and @code{install-data} for architecture-independent files.
991 The command we used up to now, @code{make install}, can be thought of
992 as a shorthand for @code{make install-exec install-data}.
994 From the GNU Build System point of view, the distinction between
995 architecture-dependent files and architecture-independent files is
996 based exclusively on the directory variable used to specify their
997 installation destination.  In the list of directory variables we
998 provided earlier (@pxref{Standard Directory Variables}), all the
999 variables based on @var{exec-prefix} designate architecture-dependent
1000 directories whose files will be installed by @code{make install-exec}.
1001 The others designate architecture-independent directories and will
1002 serve files installed by @code{make install-data}.  @xref{The Two Parts
1003 of Install}, for more details.
1005 Here is how we could revisit our two-host installation example,
1006 assuming that (1) we want to install the package directly in
1007 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
1008 two hosts.
1010 On the first host we would run
1011 @example
1012 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1013 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1015 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1017 @end example
1019 On the second host, however, we need only install the
1020 architecture-specific files.
1021 @example
1022 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1023 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1025 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1027 @end example
1029 In packages that have installation checks, it would make sense to run
1030 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1031 the package works correctly despite the apparent partial installation.
1033 @node Cross-Compilation
1034 @subsection Cross-Compilation
1035 @cindex cross-compilation
1037 To @dfn{cross-compile} is to build on one platform a binary that will
1038 run on another platform.  When speaking of cross-compilation, it is
1039 important to distinguish between the @dfn{build platform} on which
1040 the compilation is performed, and the @dfn{host platform} on which the
1041 resulting executable is expected to run.  The following
1042 @command{configure} options are used to specify each of them:
1044 @table @option
1045 @item --build=@var{build}
1046 @opindex --build=@var{build}
1047 The system on which the package is built.
1048 @item --host=@var{host}
1049 @opindex --host=@var{host}
1050 The system where built programs and libraries will run.
1051 @end table
1053 When the @option{--host} is used, @command{configure} will search for
1054 the cross-compiling suite for this platform.  Cross-compilation tools
1055 commonly have their target architecture as prefix of their name.  For
1056 instance my cross-compiler for MinGW32 has its binaries called
1057 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1058 @code{i586-mingw32msvc-as}, etc.
1060 @cindex MinGW cross-compilation example
1061 @cindex cross-compilation example
1063 Here is how we could build @code{amhello-1.0} for
1064 @code{i586-mingw32msvc} on a GNU/Linux PC.
1066 @c Keep in sync with amhello-cross-compile.sh
1067 @smallexample
1068 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1069 checking for a BSD-compatible install... /usr/bin/install -c
1070 checking whether build environment is sane... yes
1071 checking for gawk... gawk
1072 checking whether make sets $(MAKE)... yes
1073 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1074 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1075 checking for C compiler default output file name... a.exe
1076 checking whether the C compiler works... yes
1077 checking whether we are cross compiling... yes
1078 checking for suffix of executables... .exe
1079 checking for suffix of object files... o
1080 checking whether we are using the GNU C compiler... yes
1081 checking whether i586-mingw32msvc-gcc accepts -g... yes
1082 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1083 @dots{}
1084 ~/amhello-1.0 % @kbd{make}
1085 @dots{}
1086 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1087 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1088 @end smallexample
1090 The @option{--host} and @option{--build} options are usually all we
1091 need for cross-compiling.  The only exception is if the package being
1092 built is itself a cross-compiler: we need a third option to specify
1093 its target architecture.
1095 @table @option
1096 @item --target=@var{target}
1097 @opindex --target=@var{target}
1098 When building compiler tools: the system for which the tools will
1099 create output.
1100 @end table
1102 For instance when installing GCC, the GNU Compiler Collection, we can
1103 use @option{--target=@/@var{target}} to specify that we want to build
1104 GCC as a cross-compiler for @var{target}.  Mixing @option{--build} and
1105 @option{--target}, we can actually cross-compile a cross-compiler;
1106 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1108 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1109 Autoconf Manual}, for more information about these @command{configure}
1110 options.
1112 @node Renaming
1113 @subsection Renaming Programs at Install Time
1114 @cindex Renaming programs
1115 @cindex Transforming program names
1116 @cindex Programs, renaming during installation
1118 The GNU Build System provides means to automatically rename
1119 executables and manpages before they are installed (@pxref{Man Pages}).
1120 This is especially convenient
1121 when installing a GNU package on a system that already has a
1122 proprietary implementation you do not want to overwrite.  For instance,
1123 you may want to install GNU @command{tar} as @command{gtar} so you can
1124 distinguish it from your vendor's @command{tar}.
1126 This can be done using one of these three @command{configure} options.
1128 @table @option
1129 @item --program-prefix=@var{prefix}
1130 @opindex --program-prefix=@var{prefix}
1131 Prepend @var{prefix} to installed program names.
1132 @item --program-suffix=@var{suffix}
1133 @opindex --program-suffix=@var{suffix}
1134 Append @var{suffix} to installed program names.
1135 @item --program-transform-name=@var{program}
1136 @opindex --program-transform-name=@var{program}
1137 Run @code{sed @var{program}} on installed program names.
1138 @end table
1140 The following commands would install @file{hello}
1141 as @file{/usr/local/bin/test-hello}, for instance.
1143 @example
1144 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1145 @dots{}
1146 ~/amhello-1.0 % @kbd{make}
1147 @dots{}
1148 ~/amhello-1.0 % @kbd{sudo make install}
1149 @dots{}
1150 @end example
1152 @node DESTDIR
1153 @subsection Building Binary Packages Using DESTDIR
1154 @vindex DESTDIR
1156 The GNU Build System's @code{make install} and @code{make uninstall}
1157 interface does not exactly fit the needs of a system administrator
1158 who has to deploy and upgrade packages on lots of hosts.  In other
1159 words, the GNU Build System does not replace a package manager.
1161 Such package managers usually need to know which files have been
1162 installed by a package, so a mere @code{make install} is
1163 inappropriate.
1165 @cindex Staged installation
1167 The @code{DESTDIR} variable can be used to perform a staged
1168 installation.  The package should be configured as if it was going to
1169 be installed in its final location (e.g., @code{--prefix /usr}), but
1170 when running @code{make install}, the @code{DESTDIR} should be set to
1171 the absolute name of a directory into which the installation will be
1172 diverted.  From this directory it is easy to review which files are
1173 being installed where, and finally copy them to their final location
1174 by some means.
1176 @cindex Binary package
1178 For instance here is how we could create a binary package containing a
1179 snapshot of all the files to be installed.
1181 @c Keep in sync with amhello-binpkg.sh
1182 @example
1183 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1184 @dots{}
1185 ~/amhello-1.0 % @kbd{make}
1186 @dots{}
1187 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1188 @dots{}
1189 ~/amhello-1.0 % @kbd{cd ~/inst}
1190 ~/inst % @kbd{find . -type f -print > ../files.lst}
1191 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1192 ./usr/bin/hello
1193 ./usr/share/doc/amhello/README
1194 @end example
1196 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1197 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1198 instead of @samp{.} as argument for @command{tar} avoids entries for
1199 each subdirectory in the archive: we would not like @command{tar} to
1200 restore the modification time of @file{/}, @file{/usr/}, etc.)
1202 Note that when building packages for several architectures, it might
1203 be convenient to use @code{make install-data} and @code{make
1204 install-exec} (@pxref{Two-Part Install}) to gather
1205 architecture-independent files in a single package.
1207 @xref{Install}, for more information.
1209 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1210 @c UNINSTALL counterparts.
1212 @node Preparing Distributions
1213 @subsection Preparing Distributions
1214 @cindex Preparing distributions
1215 @cindex Packages, preparation
1216 @cindex Distributions, preparation
1218 We have already mentioned @code{make dist}.  This target collects all
1219 your source files and the necessary parts of the build system to
1220 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1222 @cindex @code{distcheck} better than @code{dist}
1224 Another, more useful command is @code{make distcheck}.  The
1225 @code{distcheck} target constructs
1226 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1227 but it additionally ensures most of the use cases presented so far
1228 work:
1230 @itemize @bullet
1231 @item
1232 It attempts a full compilation of the package (@pxref{Basic
1233 Installation}), unpacking the newly constructed tarball, running
1234 @code{make}, @code{make check}, @code{make install}, as well as
1235 @code{make installcheck}, and even @code{make dist},
1236 @item
1237 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1238 @item
1239 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1240 uninstall} do not omit any file (@pxref{Standard Targets}),
1241 @item
1242 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1243 @end itemize
1245 All of these actions are performed in a temporary directory, so that no
1246 root privileges are required.  Please note that the exact location and the
1247 exact structure of such a subdirectory (where the extracted sources are
1248 placed, how the temporary build and install directories are named and how
1249 deeply they are nested, etc.) is to be considered an implementation detail,
1250 which can change at any time; so do not rely on it.
1252 Releasing a package that fails @code{make distcheck} means that one of
1253 the scenarios we presented will not work and some users will be
1254 disappointed.  Therefore it is a good practice to release a package
1255 only after a successful @code{make distcheck}.  This of course does
1256 not imply that the package will be flawless, but at least it will
1257 prevent some of the embarrassing errors you may find in packages
1258 released by people who have never heard about @code{distcheck} (like
1259 @code{DESTDIR} not working because of a typo, or a distributed file
1260 being erased by @code{make clean}, or even @code{VPATH} builds not
1261 working).
1263 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1264 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1265 information about @code{distcheck}.
1267 @node Dependency Tracking
1268 @subsection Automatic Dependency Tracking
1269 @cindex Dependency tracking
1271 Dependency tracking is performed as a side-effect of compilation.
1272 Each time the build system compiles a source file, it computes its
1273 list of dependencies (in C these are the header files included by the
1274 source being compiled).  Later, any time @command{make} is run and a
1275 dependency appears to have changed, the dependent files will be
1276 rebuilt.
1278 Automake generates code for automatic dependency tracking by default,
1279 unless the developer chooses to override it; for more information,
1280 @pxref{Dependencies}.
1282 When @command{configure} is executed, you can see it probing each
1283 compiler for the dependency mechanism it supports (several mechanisms
1284 can be used):
1286 @example
1287 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1288 @dots{}
1289 checking dependency style of gcc... gcc3
1290 @dots{}
1291 @end example
1293 Because dependencies are only computed as a side-effect of the
1294 compilation, no dependency information exists the first time a package
1295 is built.  This is OK because all the files need to be built anyway:
1296 @code{make} does not have to decide which files need to be rebuilt.
1297 In fact, dependency tracking is completely useless for one-time builds
1298 and there is a @command{configure} option to disable this:
1300 @table @option
1301 @item --disable-dependency-tracking
1302 @opindex --disable-dependency-tracking
1303 Speed up one-time builds.
1304 @end table
1306 Some compilers do not offer any practical way to derive the list of
1307 dependencies as a side-effect of the compilation, requiring a separate
1308 run (maybe of another tool) to compute these dependencies.  The
1309 performance penalty implied by these methods is important enough to
1310 disable them by default.  The option @option{--enable-dependency-tracking}
1311 must be passed to @command{configure} to activate them.
1313 @table @option
1314 @item --enable-dependency-tracking
1315 @opindex --enable-dependency-tracking
1316 Do not reject slow dependency extractors.
1317 @end table
1319 @xref{Dependency Tracking Evolution, , Dependency Tracking Evolution,
1320 automake-history, Brief History of Automake}, for some discussion about
1321 the different dependency tracking schemes used by Automake over the years.
1323 @node Nested Packages
1324 @subsection Nested Packages
1325 @cindex Nested packages
1326 @cindex Packages, nested
1327 @cindex Subpackages
1329 Although nesting packages isn't something we would recommend to
1330 someone who is discovering the Autotools, it is a nice feature worthy
1331 of mention in this small advertising tour.
1333 Autoconfiscated packages (that means packages whose build system have
1334 been created by Autoconf and friends) can be nested to arbitrary
1335 depth.
1337 A typical setup is that package A will distribute one of the libraries
1338 it needs in a subdirectory.  This library B is a complete package with
1339 its own GNU Build System.  The @command{configure} script of A will
1340 run the @command{configure} script of B as part of its execution,
1341 building and installing A will also build and install B.  Generating a
1342 distribution for A will also include B.
1344 It is possible to gather several packages like this.  GCC is a heavy
1345 user of this feature.  This gives installers a single package to
1346 configure, build and install, while it allows developers to work on
1347 subpackages independently.
1349 When configuring nested packages, the @command{configure} options
1350 given to the top-level @command{configure} are passed recursively to
1351 nested @command{configure}s.  A package that does not understand an
1352 option will ignore it, assuming it is meaningful to some other
1353 package.
1355 @opindex --help=recursive
1357 The command @code{configure --help=recursive} can be used to display
1358 the options supported by all the included packages.
1360 @xref{Subpackages}, for an example setup.
1362 @node Why Autotools
1363 @section How Autotools Help
1364 @cindex Autotools, purpose
1366 There are several reasons why you may not want to implement the GNU
1367 Build System yourself (read: write a @file{configure} script and
1368 @file{Makefile}s yourself).
1370 @itemize @bullet
1371 @item
1372 As we have seen, the GNU Build System has a lot of
1373 features (@pxref{Use Cases}).
1374 Some users may expect features you have not implemented because
1375 you did not need them.
1376 @item
1377 Implementing these features portably is difficult and exhausting.
1378 Think of writing portable shell scripts, and portable
1379 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1380 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1381 convince yourself.
1382 @item
1383 You will have to upgrade your setup to follow changes to the GNU
1384 Coding Standards.
1385 @end itemize
1387 The GNU Autotools take all this burden off your back and provide:
1389 @itemize @bullet
1390 @item
1391 Tools to create a portable, complete, and self-contained GNU Build
1392 System, from simple instructions.
1393 @emph{Self-contained} meaning the resulting build system does not
1394 require the GNU Autotools.
1395 @item
1396 A central place where fixes and improvements are made:
1397 a bug-fix for a portability issue will benefit every package.
1398 @end itemize
1400 Yet there also exist reasons why you may want NOT to use the
1401 Autotools@enddots{} For instance you may be already using (or used to)
1402 another incompatible build system.  Autotools will only be useful if
1403 you do accept the concepts of the GNU Build System.  People who have their
1404 own idea of how a build system should work will feel frustrated by the
1405 Autotools.
1407 @node Hello World
1408 @section A Small Hello World
1409 @cindex Example Hello World
1410 @cindex Hello World example
1411 @cindex @file{amhello-1.0.tar.gz}, creation
1413 In this section we recreate the @file{amhello-1.0} package from
1414 scratch.  The first subsection shows how to call the Autotools to
1415 instantiate the GNU Build System, while the second explains the
1416 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1417 by the Autotools.
1419 @anchor{amhello Explained}
1420 @menu
1421 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1422 * amhello's configure.ac Setup Explained::
1423 * amhello's Makefile.am Setup Explained::
1424 @end menu
1426 @node Creating amhello
1427 @subsection Creating @file{amhello-1.0.tar.gz}
1429 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1430 The package is simple enough so that we will only need to write 5
1431 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1432 that is distributed with Automake if you do not want to write them.)
1434 Create the following files in an empty directory.
1436 @itemize @bullet
1438 @item
1439 @file{src/main.c} is the source file for the @file{hello} program.  We
1440 store it in the @file{src/} subdirectory, because later, when the package
1441 evolves, it will ease the addition of a @file{man/} directory for man
1442 pages, a @file{data/} directory for data files, etc.
1443 @example
1444 ~/amhello % @kbd{cat src/main.c}
1445 #include <config.h>
1446 #include <stdio.h>
1449 main (void)
1451   puts ("Hello World!");
1452   puts ("This is " PACKAGE_STRING ".");
1453   return 0;
1455 @end example
1457 @item
1458 @file{README} contains some very limited documentation for our little
1459 package.
1460 @example
1461 ~/amhello % @kbd{cat README}
1462 This is a demonstration package for GNU Automake.
1463 Type 'info Automake' to read the Automake manual.
1464 @end example
1466 @item
1467 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1468 instructions for these two directories.
1470 @example
1471 ~/amhello % @kbd{cat src/Makefile.am}
1472 bin_PROGRAMS = hello
1473 hello_SOURCES = main.c
1474 ~/amhello % @kbd{cat Makefile.am}
1475 SUBDIRS = src
1476 dist_doc_DATA = README
1477 @end example
1479 @item
1480 Finally, @file{configure.ac} contains Autoconf instructions to
1481 create the @command{configure} script.
1483 @example
1484 ~/amhello % @kbd{cat configure.ac}
1485 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1486 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1487 AC_PROG_CC
1488 AC_CONFIG_HEADERS([config.h])
1489 AC_CONFIG_FILES([
1490  Makefile
1491  src/Makefile
1493 AC_OUTPUT
1494 @end example
1495 @end itemize
1497 @cindex @command{autoreconf}, example
1499 Once you have these five files, it is time to run the Autotools to
1500 instantiate the build system.  Do this using the @command{autoreconf}
1501 command as follows:
1503 @example
1504 ~/amhello % @kbd{autoreconf --install}
1505 configure.ac: installing './install-sh'
1506 configure.ac: installing './missing'
1507 configure.ac: installing './compile'
1508 src/Makefile.am: installing './depcomp'
1509 @end example
1511 At this point the build system is complete.
1513 In addition to the three scripts mentioned in its output, you can see
1514 that @command{autoreconf} created four other files: @file{configure},
1515 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1516 The latter three files are templates that will be adapted to the
1517 system by @command{configure} under the names @file{config.h},
1518 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1520 @example
1521 ~/amhello % @kbd{./configure}
1522 checking for a BSD-compatible install... /usr/bin/install -c
1523 checking whether build environment is sane... yes
1524 checking for gawk... no
1525 checking for mawk... mawk
1526 checking whether make sets $(MAKE)... yes
1527 checking for gcc... gcc
1528 checking for C compiler default output file name... a.out
1529 checking whether the C compiler works... yes
1530 checking whether we are cross compiling... no
1531 checking for suffix of executables...
1532 checking for suffix of object files... o
1533 checking whether we are using the GNU C compiler... yes
1534 checking whether gcc accepts -g... yes
1535 checking for gcc option to accept ISO C89... none needed
1536 checking for style of include used by make... GNU
1537 checking dependency style of gcc... gcc3
1538 configure: creating ./config.status
1539 config.status: creating Makefile
1540 config.status: creating src/Makefile
1541 config.status: creating config.h
1542 config.status: executing depfiles commands
1543 @end example
1545 @trindex distcheck
1546 @cindex @code{distcheck} example
1548 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1549 being created at the end after @command{configure} has probed the
1550 system.  It is now possible to run all the targets we wish
1551 (@pxref{Standard Targets}).  For instance:
1553 @example
1554 ~/amhello % @kbd{make}
1555 @dots{}
1556 ~/amhello % @kbd{src/hello}
1557 Hello World!
1558 This is amhello 1.0.
1559 ~/amhello % @kbd{make distcheck}
1560 @dots{}
1561 =============================================
1562 amhello-1.0 archives ready for distribution:
1563 amhello-1.0.tar.gz
1564 =============================================
1565 @end example
1567 Note that running @command{autoreconf} is only needed initially when
1568 the GNU Build System does not exist.  When you later change some
1569 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1570 relevant part of the build system will be regenerated automatically
1571 when you execute @command{make}.
1573 @command{autoreconf} is a script that calls @command{autoconf},
1574 @command{automake}, and a bunch of other commands in the right order.
1575 If you are beginning with these tools, it is not important to figure
1576 out in which order all of these tools should be invoked and why.  However,
1577 because Autoconf and Automake have separate manuals, the important
1578 point to understand is that @command{autoconf} is in charge of
1579 creating @file{configure} from @file{configure.ac}, while
1580 @command{automake} is in charge of creating @file{Makefile.in}s from
1581 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1582 direct you to the right manual when seeking answers.
1585 @node amhello's configure.ac Setup Explained
1586 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1588 @cindex @file{configure.ac}, Hello World
1590 Let us begin with the contents of @file{configure.ac}.
1592 @example
1593 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1594 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1595 AC_PROG_CC
1596 AC_CONFIG_HEADERS([config.h])
1597 AC_CONFIG_FILES([
1598  Makefile
1599  src/Makefile
1601 AC_OUTPUT
1602 @end example
1604 This file is read by both @command{autoconf} (to create
1605 @file{configure}) and @command{automake} (to create the various
1606 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1607 expanded as shell code to finally form the @file{configure} script.
1608 We will not elaborate on the syntax of this file, because the Autoconf
1609 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1610 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1612 The macros prefixed with @code{AC_} are Autoconf macros, documented
1613 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1614 Index, autoconf, The Autoconf Manual}).  The macros that start with
1615 @code{AM_} are Automake macros, documented later in this manual
1616 (@pxref{Macro Index}).
1618 The first two lines of @file{configure.ac} initialize Autoconf and
1619 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1620 its version number, and a contact address for bug-reports about the
1621 package (this address is output at the end of @code{./configure
1622 --help}, for instance).  When adapting this setup to your own package,
1623 by all means please do not blindly copy Automake's address: use the
1624 mailing list of your package, or your own mail address.
1626 @opindex -Wall
1627 @opindex -Werror
1628 @opindex foreign
1630 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1631 @command{automake} (@pxref{Options}).  @option{-Wall} and
1632 @option{-Werror} ask @command{automake} to turn on all warnings and
1633 report them as errors.  We are speaking of @strong{Automake} warnings
1634 here, such as dubious instructions in @file{Makefile.am}.  This has
1635 absolutely nothing to do with how the compiler will be called, even
1636 though it may support options with similar names.  Using @option{-Wall
1637 -Werror} is a safe setting when starting to work on a package: you do
1638 not want to miss any issues.  Later you may decide to relax things a
1639 bit.  The @option{foreign} option tells Automake that this package
1640 will not follow the GNU Standards.  GNU packages should always
1641 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1642 etc.  We do not want @command{automake} to complain about these
1643 missing files in our small example.
1645 The @code{AC_PROG_CC} line causes the @command{configure} script to
1646 search for a C compiler and define the variable @code{CC} with its
1647 name.  The @file{src/Makefile.in} file generated by Automake uses the
1648 variable @code{CC} to build @file{hello}, so when @command{configure}
1649 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1650 @code{CC} with the value it has found.  If Automake is asked to create
1651 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1652 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1654 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1655 @command{configure} script to create a @file{config.h} file gathering
1656 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1657 case, the @code{AC_INIT} macro already defined a few of them.  Here
1658 is an excerpt of @file{config.h} after @command{configure} has run:
1660 @smallexample
1661 @dots{}
1662 /* Define to the address where bug reports for this package should be sent. */
1663 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1665 /* Define to the full name and version of this package. */
1666 #define PACKAGE_STRING "amhello 1.0"
1667 @dots{}
1668 @end smallexample
1670 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1671 it can use @code{PACKAGE_STRING}.  In a real-world project,
1672 @file{config.h} can grow really big, with one @samp{#define} per
1673 feature probed on the system.
1675 The @code{AC_CONFIG_FILES} macro declares the list of files that
1676 @command{configure} should create from their @file{*.in} templates.
1677 Automake also scans this list to find the @file{Makefile.am} files it must
1678 process.  (This is important to remember: when adding a new directory
1679 to your project, you should add its @file{Makefile} to this list,
1680 otherwise Automake will never process the new @file{Makefile.am} you
1681 wrote in that directory.)
1683 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1684 produces the part of the script in charge of creating the files
1685 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1687 @cindex @command{autoscan}
1689 When starting a new project, we suggest you start with such a simple
1690 @file{configure.ac}, and gradually add the other tests it requires.
1691 The command @command{autoscan} can also suggest a few of the tests
1692 your package may need (@pxref{autoscan Invocation, , Using
1693 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1694 Autoconf Manual}).
1697 @node amhello's Makefile.am Setup Explained
1698 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1700 @cindex @file{Makefile.am}, Hello World
1702 We now turn to @file{src/Makefile.am}.  This file contains
1703 Automake instructions to build and install @file{hello}.
1705 @example
1706 bin_PROGRAMS = hello
1707 hello_SOURCES = main.c
1708 @end example
1710 A @file{Makefile.am} has the same syntax as an ordinary
1711 @file{Makefile}.  When @command{automake} processes a
1712 @file{Makefile.am} it copies the entire file into the output
1713 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1714 @command{configure}) but will react to certain variable definitions
1715 by generating some build rules and other variables.
1716 Often @file{Makefile.am}s contain only a list of variable definitions as
1717 above, but they can also contain other variable and rule definitions that
1718 @command{automake} will pass along without interpretation.
1720 Variables that end with @code{_PROGRAMS} are special variables
1721 that list programs that the resulting @file{Makefile} should build.
1722 In Automake speak, this @code{_PROGRAMS} suffix is called a
1723 @dfn{primary}; Automake recognizes other primaries such as
1724 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1725 to different types of files.
1727 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1728 @command{automake} that the resulting programs should be installed in
1729 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1730 to denote destination directories and allow users to customize these
1731 locations (@pxref{Standard Directory Variables}).  Any such directory
1732 variable can be put in front of a primary (omitting the @code{dir}
1733 suffix) to tell @command{automake} where to install the listed files.
1735 Programs need to be built from source files, so for each program
1736 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1737 @command{automake} will look for another variable named
1738 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1739 than one source file: they will all be compiled and linked together.
1741 Automake also knows that source files need to be distributed when
1742 creating a tarball (unlike built programs).  So a side-effect of this
1743 @code{hello_SOURCES} declaration is that @file{main.c} will be
1744 part of the tarball created by @code{make dist}.
1746 Finally here are some explanations regarding the top-level
1747 @file{Makefile.am}.
1749 @example
1750 SUBDIRS = src
1751 dist_doc_DATA = README
1752 @end example
1754 @code{SUBDIRS} is a special variable listing all directories that
1755 @command{make} should recurse into before processing the current
1756 directory.  So this line is responsible for @command{make} building
1757 @file{src/hello} even though we run it from the top-level.  This line
1758 also causes @code{make install} to install @file{src/hello} before
1759 installing @file{README} (not that this order matters).
1761 The line @code{dist_doc_DATA = README} causes @file{README} to be
1762 distributed and installed in @var{docdir}.  Files listed with the
1763 @code{_DATA} primary are not automatically part of the tarball built
1764 with @code{make dist}, so we add the @code{dist_} prefix so they get
1765 distributed.  However, for @file{README} it would not have been
1766 necessary: @command{automake} automatically distributes any
1767 @file{README} file it encounters (the list of other files
1768 automatically distributed is presented by @code{automake --help}).
1769 The only important effect of this second line is therefore to install
1770 @file{README} during @code{make install}.
1772 One thing not covered in this example is accessing the installation
1773 directory values (@pxref{Standard Directory Variables}) from your
1774 program code, that is, converting them into defined macros.  For this,
1775 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1778 @node Generalities
1779 @chapter General ideas
1781 The following sections cover a few basic ideas that will help you
1782 understand how Automake works.
1784 @menu
1785 * General Operation::           General operation of Automake
1786 * Strictness::                  Standards conformance checking
1787 * Uniform::                     The Uniform Naming Scheme
1788 * Length Limitations::          Staying below the command line length limit
1789 * Canonicalization::            How derived variables are named
1790 * User Variables::              Variables reserved for the user
1791 * Auxiliary Programs::          Programs automake might require
1792 @end menu
1795 @node General Operation
1796 @section General Operation
1798 Automake works by reading a @file{Makefile.am} and generating a
1799 @file{Makefile.in}.  Certain variables and rules defined in the
1800 @file{Makefile.am} instruct Automake to generate more specialized code;
1801 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1802 for compiling and linking programs to be generated.
1804 @cindex Non-standard targets
1805 @cindex @code{git-dist}, non-standard example
1806 @trindex git-dist
1808 The variable definitions and rules in the @file{Makefile.am} are
1809 copied mostly verbatim into the generated file, with all variable
1810 definitions preceding all rules.  This allows you to add almost
1811 arbitrary code into the generated @file{Makefile.in}.  For instance,
1812 the Automake distribution includes a non-standard rule for the
1813 @code{git-dist} target, which the Automake maintainer uses to make
1814 distributions from the source control system.
1816 @cindex GNU make extensions
1818 Note that most GNU make extensions are not recognized by Automake.  Using
1819 such extensions in a @file{Makefile.am} will lead to errors or confusing
1820 behavior.
1822 @cindex Append operator
1823 @cmindex +=
1824 A special exception is that the GNU make append operator, @samp{+=}, is
1825 supported.  This operator appends its right hand argument to the variable
1826 specified on the left.  Automake will translate the operator into
1827 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1829 Automake tries to keep comments grouped with any adjoining rules or
1830 variable definitions.
1832 @cindex Limitations of automake parser
1833 @cindex Automake parser, limitations of
1834 @cindex indentation in Makefile.am
1835 Generally, Automake is not particularly smart in the parsing of unusual
1836 Makefile constructs, so you're advised to avoid fancy constructs or
1837 ``creative'' use of whitespace.
1838 @c Keep this in sync with doc-parsing-buglets-tabs.sh
1839 For example, @key{TAB} characters cannot be used between a target name
1840 and the following ``@code{:}'' character, and variable assignments
1841 shouldn't be indented with @key{TAB} characters.
1842 @c Keep this in sync with doc-parsing-buglets-colneq-subst.sh
1843 Also, using more complex macro in target names can cause trouble:
1845 @example
1846 % @kbd{cat Makefile.am}
1847 $(FOO:=x): bar
1848 % @kbd{automake}
1849 Makefile.am:1: bad characters in variable name '$(FOO'
1850 Makefile.am:1: ':='-style assignments are not portable
1851 @end example
1853 @cindex Make targets, overriding
1854 @cindex Make rules, overriding
1855 @cindex Overriding make rules
1856 @cindex Overriding make targets
1858 A rule defined in @file{Makefile.am} generally overrides any such
1859 rule of a similar name that would be automatically generated by
1860 @command{automake}.  Although this is a supported feature, it is generally
1861 best to avoid making use of it, as sometimes the generated rules are
1862 very particular.
1864 @cindex Variables, overriding
1865 @cindex Overriding make variables
1867 Similarly, a variable defined in @file{Makefile.am} or
1868 @code{AC_SUBST}ed from @file{configure.ac} will override any
1869 definition of the variable that @command{automake} would ordinarily
1870 create.  This feature is more often useful than the ability to
1871 override a rule.  Be warned that many of the variables generated by
1872 @command{automake} are considered to be for internal use only, and their
1873 names might change in future releases.
1875 @cindex Recursive operation of Automake
1876 @cindex Automake, recursive operation
1877 @cindex Example of recursive operation
1879 When examining a variable definition, Automake will recursively examine
1880 variables referenced in the definition.  For example, if Automake is
1881 looking at the content of @code{foo_SOURCES} in this snippet
1883 @c Keep in sync with interp.sh
1884 @example
1885 xs = a.c b.c
1886 foo_SOURCES = c.c $(xs)
1887 @end example
1889 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1890 contents of @code{foo_SOURCES}.
1892 @cindex @code{##} (special Automake comment)
1893 @cindex Special Automake comment
1894 @cindex Comment, special to Automake
1896 Automake also allows a form of comment that is @emph{not} copied into
1897 the output; all lines beginning with @samp{##} (leading spaces allowed)
1898 are completely ignored by Automake.
1900 It is customary to make the first line of @file{Makefile.am} read:
1902 @cindex Makefile.am, first line
1903 @cindex First line of Makefile.am
1905 @example
1906 ## Process this file with automake to produce Makefile.in
1907 @end example
1909 @c FIXME document customary ordering of Makefile.am here!
1912 @node Strictness
1913 @section Strictness
1915 @cindex Non-GNU packages
1917 While Automake is intended to be used by maintainers of GNU packages, it
1918 does make some effort to accommodate those who wish to use it, but do
1919 not want to use all the GNU conventions.
1921 @cindex Strictness, defined
1922 @cindex Strictness, @option{foreign}
1923 @cindex @option{foreign} strictness
1924 @cindex Strictness, @option{gnu}
1925 @cindex @option{gnu} strictness
1926 @cindex Strictness, @option{gnits}
1927 @cindex @option{gnits} strictness
1929 To this end, Automake supports three levels of @dfn{strictness}---the
1930 strictness indicating how stringently Automake should check standards
1931 conformance.
1933 The valid strictness levels are:
1935 @table @option
1936 @item foreign
1937 Automake will check for only those things that are absolutely
1938 required for proper operations.  For instance, whereas GNU standards
1939 dictate the existence of a @file{NEWS} file, it will not be required in
1940 this mode.  This strictness will also turn off some warnings by default
1941 (among them, portability warnings).
1942 The name comes from the fact that Automake is intended to be
1943 used for GNU programs; these relaxed rules are not the standard mode of
1944 operation.
1946 @item gnu
1947 Automake will check---as much as possible---for compliance to the GNU
1948 standards for packages.  This is the default.
1950 @item gnits
1951 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1952 standards}.  These are based on the GNU standards, but are even more
1953 detailed.  Unless you are a Gnits standards contributor, it is
1954 recommended that you avoid this option until such time as the Gnits
1955 standard is actually published (which may never happen).
1956 @end table
1958 @xref{Gnits}, for more information on the precise implications of the
1959 strictness level.
1962 @node Uniform
1963 @section The Uniform Naming Scheme
1965 @cindex Uniform naming scheme
1967 Automake variables generally follow a @dfn{uniform naming scheme} that
1968 makes it easy to decide how programs (and other derived objects) are
1969 built, and how they are installed.  This scheme also supports
1970 @command{configure} time determination of what should be built.
1972 @cindex @code{_PROGRAMS} primary variable
1973 @cindex @code{PROGRAMS} primary variable
1974 @cindex Primary variable, @code{PROGRAMS}
1975 @cindex Primary variable, defined
1976 @vindex _PROGRAMS
1978 At @command{make} time, certain variables are used to determine which
1979 objects are to be built.  The variable names are made of several pieces
1980 that are concatenated together.
1982 The piece that tells @command{automake} what is being built is commonly called
1983 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1984 list of programs that are to be compiled and linked.
1985 @vindex PROGRAMS
1987 @cindex @code{pkgdatadir}, defined
1988 @cindex @code{pkgincludedir}, defined
1989 @cindex @code{pkglibdir}, defined
1990 @cindex @code{pkglibexecdir}, defined
1992 @vindex pkgdatadir
1993 @vindex pkgincludedir
1994 @vindex pkglibdir
1995 @vindex pkglibexecdir
1997 @cindex @code{PACKAGE}, directory
1998 A different set of names is used to decide where the built objects
1999 should be installed.  These names are prefixes to the primary, and they
2000 indicate which standard directory should be used as the installation
2001 directory.  The standard directory names are given in the GNU standards
2002 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
2003 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
2004 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
2005 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
2006 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
2008 @cindex @code{EXTRA_}, prepending
2009 For each primary, there is one additional variable named by prepending
2010 @samp{EXTRA_} to the primary name.  This variable is used to list
2011 objects that may or may not be built, depending on what
2012 @command{configure} decides.  This variable is required because Automake
2013 must statically know the entire list of objects that may be built in
2014 order to generate a @file{Makefile.in} that will work in all cases.
2016 @cindex @code{EXTRA_PROGRAMS}, defined
2017 @cindex Example, @code{EXTRA_PROGRAMS}
2018 @cindex @command{cpio} example
2020 For instance, @command{cpio} decides at configure time which programs
2021 should be built.  Some of the programs are installed in @code{bindir},
2022 and some are installed in @code{sbindir}:
2024 @example
2025 EXTRA_PROGRAMS = mt rmt
2026 bin_PROGRAMS = cpio pax
2027 sbin_PROGRAMS = $(MORE_PROGRAMS)
2028 @end example
2030 Defining a primary without a prefix as a variable, e.g.,
2031 @samp{PROGRAMS}, is an error.
2033 Note that the common @samp{dir} suffix is left off when constructing the
2034 variable names; thus one writes @samp{bin_PROGRAMS} and not
2035 @samp{bindir_PROGRAMS}.
2037 Not every sort of object can be installed in every directory.  Automake
2038 will flag those attempts it finds in error (but see below how to override
2039 the check if you really need to).
2040 Automake will also diagnose obvious misspellings in directory names.
2042 @cindex Extending list of installation directories
2043 @cindex Installation directories, extending list
2045 Sometimes the standard directories---even as augmented by
2046 Automake---are not enough.  In particular it is sometimes useful, for
2047 clarity, to install objects in a subdirectory of some predefined
2048 directory.  To this end, Automake allows you to extend the list of
2049 possible installation directories.  A given prefix (e.g., @samp{zar})
2050 is valid if a variable of the same name with @samp{dir} appended is
2051 defined (e.g., @samp{zardir}).
2053 For instance, the following snippet will install @file{file.xml} into
2054 @samp{$(datadir)/xml}.
2056 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2057 @example
2058 xmldir = $(datadir)/xml
2059 xml_DATA = file.xml
2060 @end example
2062 This feature can also be used to override the sanity checks Automake
2063 performs to diagnose suspicious directory/primary couples (in the
2064 unlikely case these checks are undesirable, and you really know what
2065 you're doing).  For example, Automake would error out on this input:
2067 @c Should be tested in primary-prefix-invalid-couples.sh
2068 @example
2069 # Forbidden directory combinations, automake will error out on this.
2070 pkglib_PROGRAMS = foo
2071 doc_LIBRARIES = libquux.a
2072 @end example
2074 @noindent
2075 but it will succeed with this:
2077 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2078 @example
2079 # Work around forbidden directory combinations.  Do not use this
2080 # without a very good reason!
2081 my_execbindir = $(pkglibdir)
2082 my_doclibdir = $(docdir)
2083 my_execbin_PROGRAMS = foo
2084 my_doclib_LIBRARIES = libquux.a
2085 @end example
2087 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2088 the files be installed at the right time (@pxref{The Two Parts of
2089 Install}).
2091 @cindex @samp{noinst_} primary prefix, definition
2092 @vindex noinst_
2094 The special prefix @samp{noinst_} indicates that the objects in question
2095 should be built but not installed at all.  This is usually used for
2096 objects required to build the rest of your package, for instance static
2097 libraries (@pxref{A Library}), or helper scripts.
2099 @cindex @samp{check_} primary prefix, definition
2100 @vindex check_
2102 The special prefix @samp{check_} indicates that the objects in question
2103 should not be built until the @samp{make check} command is run.  Those
2104 objects are not installed either.
2106 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2107 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2108 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2109 @samp{TEXINFOS}.
2110 @vindex PROGRAMS
2111 @vindex LIBRARIES
2112 @vindex LTLIBRARIES
2113 @vindex LISP
2114 @vindex PYTHON
2115 @vindex JAVA
2116 @vindex SCRIPTS
2117 @vindex DATA
2118 @vindex HEADERS
2119 @vindex MANS
2120 @vindex TEXINFOS
2122 Some primaries also allow additional prefixes that control other
2123 aspects of @command{automake}'s behavior.  The currently defined prefixes
2124 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2125 These prefixes are explained later (@pxref{Program and Library Variables})
2126 (@pxref{Man Pages}).
2129 @node Length Limitations
2130 @section Staying below the command line length limit
2132 @cindex command line length limit
2133 @cindex ARG_MAX
2135 Traditionally, most unix-like systems have a length limitation for the
2136 command line arguments and environment contents when creating new
2137 processes (see for example
2138 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2139 overview on this issue),
2140 which of course also applies to commands spawned by @command{make}.
2141 POSIX requires this limit to be at least 4096 bytes, and most modern
2142 systems have quite high limits (or are unlimited).
2144 In order to create portable Makefiles that do not trip over these
2145 limits, it is necessary to keep the length of file lists bounded.
2146 Unfortunately, it is not possible to do so fully transparently within
2147 Automake, so your help may be needed.  Typically, you can split long
2148 file lists manually and use different installation directory names for
2149 each list.  For example,
2151 @example
2152 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2153 @end example
2155 @noindent
2156 may also be written as
2158 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2159 @example
2160 data_DATA = file1 @dots{} file@var{N}
2161 data2dir = $(datadir)
2162 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2163 @end example
2165 @noindent
2166 and will cause Automake to treat the two lists separately during
2167 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2168 directory names that will keep the ordering of the two parts of
2169 installation Note that @code{make dist} may still only work on a host
2170 with a higher length limit in this example.
2172 Automake itself employs a couple of strategies to avoid long command
2173 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2174 names, as can happen with above @code{$(data_DATA)} lists, it limits
2175 the amount of arguments passed to external commands.
2177 Unfortunately, some system's @command{make} commands may prepend
2178 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2179 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2180 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2181 may have to switch to use GNU Make, or refrain from using VPATH builds,
2182 in order to stay below the length limit.
2184 For libraries and programs built from many sources, convenience archives
2185 may be used as intermediates in order to limit the object list length
2186 (@pxref{Libtool Convenience Libraries}).
2189 @node Canonicalization
2190 @section How derived variables are named
2192 @cindex canonicalizing Automake variables
2194 Sometimes a Makefile variable name is derived from some text the
2195 maintainer supplies.  For instance, a program name listed in
2196 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2197 variable.  In cases like this, Automake canonicalizes the text, so that
2198 program names and the like do not have to follow Makefile variable naming
2199 rules.  All characters in the name except for letters, numbers, the
2200 strudel (@@), and the underscore are turned into underscores when making
2201 variable references.
2203 For example, if your program is named @file{sniff-glue}, the derived
2204 variable name would be @samp{sniff_glue_SOURCES}, not
2205 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2206 @file{libmumble++.a} should be listed in the
2207 @samp{libmumble___a_SOURCES} variable.
2209 The strudel is an addition, to make the use of Autoconf substitutions in
2210 variable names less obfuscating.
2213 @node User Variables
2214 @section Variables reserved for the user
2216 @cindex variables, reserved for the user
2217 @cindex user variables
2219 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2220 for the use of the ``user''---the person building the package.  For
2221 instance, @code{CFLAGS} is one such variable.
2223 Sometimes package developers are tempted to set user variables such as
2224 @code{CFLAGS} because it appears to make their job easier.  However,
2225 the package itself should never set a user variable, particularly not
2226 to include switches that are required for proper compilation of the
2227 package.  Since these variables are documented as being for the
2228 package builder, that person rightfully expects to be able to override
2229 any of these variables at build time.
2231 To get around this problem, Automake introduces an automake-specific
2232 shadow variable for each user flag variable.  (Shadow variables are
2233 not introduced for variables like @code{CC}, where they would make no
2234 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2235 user variable's name.  For instance, the shadow variable for
2236 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2237 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2238 files---may adjust these shadow variables however necessary.
2240 @xref{Flag Variables Ordering}, for more discussion about these
2241 variables and how they interact with per-target variables.
2243 @node Auxiliary Programs
2244 @section Programs automake might require
2246 @cindex Programs, auxiliary
2247 @cindex Auxiliary programs
2249 Automake sometimes requires helper programs so that the generated
2250 @file{Makefile} can do its work properly.  There are a fairly large
2251 number of them, and we list them here.
2253 Although all of these files are distributed and installed with
2254 Automake, a couple of them are maintained separately.  The Automake
2255 copies are updated before each release, but we mention the original
2256 source in case you need more recent versions.
2258 @table @code
2259 @item ar-lib
2260 This is a wrapper primarily for the Microsoft lib archiver, to make
2261 it more POSIX-like.
2263 @item compile
2264 This is a wrapper for compilers that do not accept options @option{-c}
2265 and @option{-o} at the same time.  It is only used when absolutely
2266 required.  Such compilers are rare, with the Microsoft C/C++ Compiler
2267 as the most notable exception. This wrapper also makes the following
2268 common options available for that compiler, while performing file name
2269 translation where needed: @option{-I}, @option{-L}, @option{-l},
2270 @option{-Wl,} and @option{-Xlinker}.
2272 @item config.guess
2273 @itemx config.sub
2274 These two programs compute the canonical triplets for the given build,
2275 host, or target architecture.  These programs are updated regularly to
2276 support new architectures and fix probes broken by changes in new
2277 kernel versions.  Each new release of Automake comes with up-to-date
2278 copies of these programs.  If your copy of Automake is getting old,
2279 you are encouraged to fetch the latest versions of these files from
2280 @url{http://savannah.gnu.org/git/?group=config} before making a
2281 release.
2283 @item depcomp
2284 This program understands how to run a compiler so that it will
2285 generate not only the desired output but also dependency information
2286 that is then used by the automatic dependency tracking feature
2287 (@pxref{Dependencies}).
2289 @item install-sh
2290 This is a replacement for the @command{install} program that works on
2291 platforms where @command{install} is unavailable or unusable.
2293 @item mdate-sh
2294 This script is used to generate a @file{version.texi} file.  It examines
2295 a file and prints some date information about it.
2297 @item missing
2298 This wraps a number of programs that are typically only required by
2299 maintainers.  If the program in question doesn't exist, or seems to old,
2300 @command{missing} will print an informative warning before failing out,
2301 to provide the user with more context and information.
2303 @item mkinstalldirs
2304 This script used to be a wrapper around @samp{mkdir -p}, which is not
2305 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2306 finds that @samp{mkdir -p} does not work, this makes one less script to
2307 distribute.
2309 For backward compatibility @file{mkinstalldirs} is still used and
2310 distributed when @command{automake} finds it in a package.  But it is no
2311 longer installed automatically, and it should be safe to remove it.
2313 @item py-compile
2314 This is used to byte-compile Python scripts.
2316 @item test-driver
2317 This implements the default test driver offered by the parallel
2318 testsuite harness.
2320 @item texinfo.tex
2321 Not a program, this file is required for @samp{make dvi}, @samp{make
2322 ps} and @samp{make pdf} to work when Texinfo sources are in the
2323 package.  The latest version can be downloaded from
2324 @url{http://www.gnu.org/software/texinfo/}.
2326 @item ylwrap
2327 This program wraps @command{lex} and @command{yacc} to rename their
2328 output files.  It also ensures that, for instance, multiple
2329 @command{yacc} instances can be invoked in a single directory in
2330 parallel.
2332 @end table
2335 @node Examples
2336 @chapter Some example packages
2338 This section contains two small examples.
2340 The first example (@pxref{Complete}) assumes you have an existing
2341 project already using Autoconf, with handcrafted @file{Makefile}s, and
2342 that you want to convert it to using Automake.  If you are discovering
2343 both tools, it is probably better that you look at the Hello World
2344 example presented earlier (@pxref{Hello World}).
2346 The second example (@pxref{true}) shows how two programs can be built
2347 from the same file, using different compilation parameters.  It
2348 contains some technical digressions that are probably best skipped on
2349 first read.
2351 @menu
2352 * Complete::                    A simple example, start to finish
2353 * true::                        Building true and false
2354 @end menu
2357 @node Complete
2358 @section A simple example, start to finish
2360 @cindex Complete example
2362 Let's suppose you just finished writing @code{zardoz}, a program to make
2363 your head float from vortex to vortex.  You've been using Autoconf to
2364 provide a portability framework, but your @file{Makefile.in}s have been
2365 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2367 @cindex @code{AM_INIT_AUTOMAKE}, example use
2369 The first step is to update your @file{configure.ac} to include the
2370 commands that @command{automake} needs.  The way to do this is to add an
2371 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2373 @example
2374 AC_INIT([zardoz], [1.0])
2375 AM_INIT_AUTOMAKE
2376 @dots{}
2377 @end example
2379 Since your program doesn't have any complicating factors (e.g., it
2380 doesn't use @code{gettext}, it doesn't want to build a shared library),
2381 you're done with this part.  That was easy!
2383 @cindex @command{aclocal} program, introduction
2384 @cindex @file{aclocal.m4}, preexisting
2385 @cindex @file{acinclude.m4}, defined
2387 Now you must regenerate @file{configure}.  But to do that, you'll need
2388 to tell @command{autoconf} how to find the new macro you've used.  The
2389 easiest way to do this is to use the @command{aclocal} program to
2390 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2391 already have an @file{aclocal.m4}, because you had to write some hairy
2392 macros for your program.  The @command{aclocal} program lets you put
2393 your own macros into @file{acinclude.m4}, so simply rename and then
2394 run:
2396 @example
2397 mv aclocal.m4 acinclude.m4
2398 aclocal
2399 autoconf
2400 @end example
2402 @cindex @command{zardoz} example
2404 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2405 Since @code{zardoz} is a user program, you want to install it where the
2406 rest of the user programs go: @code{bindir}.  Additionally,
2407 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2408 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2409 @samp{$(LIBOBJS)}.  So here's what you'd write:
2411 @example
2412 bin_PROGRAMS = zardoz
2413 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2414 zardoz_LDADD = $(LIBOBJS)
2416 info_TEXINFOS = zardoz.texi
2417 @end example
2419 Now you can run @samp{automake --add-missing} to generate your
2420 @file{Makefile.in} and grab any auxiliary files you might need, and
2421 you're done!
2424 @node true
2425 @section Building true and false
2427 @cindex Example, @command{false} and @command{true}
2428 @cindex @command{false} Example
2429 @cindex @command{true} Example
2431 Here is another, trickier example.  It shows how to generate two
2432 programs (@code{true} and @code{false}) from the same source file
2433 (@file{true.c}).  The difficult part is that each compilation of
2434 @file{true.c} requires different @code{cpp} flags.
2436 @example
2437 bin_PROGRAMS = true false
2438 false_SOURCES =
2439 false_LDADD = false.o
2441 true.o: true.c
2442         $(COMPILE) -DEXIT_CODE=0 -c true.c
2444 false.o: true.c
2445         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2446 @end example
2448 Note that there is no @code{true_SOURCES} definition.  Automake will
2449 implicitly assume that there is a source file named @file{true.c}
2450 (@pxref{Default _SOURCES}), and
2451 define rules to compile @file{true.o} and link @file{true}.  The
2452 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2453 will override the Automake generated rule to build @file{true.o}.
2455 @code{false_SOURCES} is defined to be empty---that way no implicit value
2456 is substituted.  Because we have not listed the source of
2457 @file{false}, we have to tell Automake how to link the program.  This is
2458 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2459 variable, holding the dependencies of the @file{false} target will be
2460 automatically generated by Automake from the content of
2461 @code{false_LDADD}.
2463 The above rules won't work if your compiler doesn't accept both
2464 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2465 bogus dependency (to avoid problems with a parallel @command{make}):
2467 @example
2468 true.o: true.c false.o
2469         $(COMPILE) -DEXIT_CODE=0 -c true.c
2471 false.o: true.c
2472         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2473 @end example
2475 As it turns out, there is also a much easier way to do this same task.
2476 Some of the above technique is useful enough that we've kept the
2477 example in the manual.  However if you were to build @code{true} and
2478 @code{false} in real life, you would probably use per-program
2479 compilation flags, like so:
2481 @c Keep in sync with specflg7.sh and specflg8.sh
2482 @example
2483 bin_PROGRAMS = false true
2485 false_SOURCES = true.c
2486 false_CPPFLAGS = -DEXIT_CODE=1
2488 true_SOURCES = true.c
2489 true_CPPFLAGS = -DEXIT_CODE=0
2490 @end example
2492 In this case Automake will cause @file{true.c} to be compiled twice,
2493 with different flags.  In this instance, the names of the object files
2494 would be chosen by automake; they would be @file{false-true.o} and
2495 @file{true-true.o}. (The name of the object files rarely matters.)
2497 @node automake Invocation
2498 @chapter Creating a @file{Makefile.in}
2499 @c This node used to be named "Invoking automake".  This @anchor
2500 @c allows old links to still work.
2501 @anchor{Invoking automake}
2503 @cindex Multiple @file{configure.ac} files
2504 @cindex Invoking @command{automake}
2505 @cindex @command{automake}, invoking
2506 @cindex Invocation of @command{automake}
2507 @cindex @command{automake}, invocation
2509 To create all the @file{Makefile.in}s for a package, run the
2510 @command{automake} program in the top level directory, with no
2511 arguments.  @command{automake} will automatically find each
2512 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2513 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2514 Note that @command{automake} has a rather simplistic view of what
2515 constitutes a package; it assumes that a package has only one
2516 @file{configure.ac}, at the top.  If your package has multiple
2517 @file{configure.ac}s, then you must run @command{automake} in each
2518 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2519 on Autoconf's @command{autoreconf}, which is able to recurse your
2520 package tree and run @command{automake} where appropriate.)
2522 You can optionally give @command{automake} an argument; @file{.am} is
2523 appended to the argument and the result is used as the name of the
2524 input file.  This feature is generally only used to automatically
2525 rebuild an out-of-date @file{Makefile.in}.  Note that
2526 @command{automake} must always be run from the topmost directory of a
2527 project, even if being used to regenerate the @file{Makefile.in} in
2528 some subdirectory.  This is necessary because @command{automake} must
2529 scan @file{configure.ac}, and because @command{automake} uses the
2530 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2531 behavior in some cases.
2533 @vindex AUTOCONF
2534 Automake will run @command{autoconf} to scan @file{configure.ac} and
2535 its dependencies (i.e., @file{aclocal.m4} and any included file),
2536 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2537 an @env{AUTOCONF} variable in your environment it will be used
2538 instead of @command{autoconf}, this allows you to select a particular
2539 version of Autoconf.  By the way, don't misunderstand this paragraph:
2540 @command{automake} runs @command{autoconf} to @strong{scan} your
2541 @file{configure.ac}, this won't build @file{configure} and you still
2542 have to run @command{autoconf} yourself for this purpose.
2544 @cindex @command{automake} options
2545 @cindex Options, @command{automake}
2546 @cindex Strictness, command line
2548 @command{automake} accepts the following options:
2550 @cindex Extra files distributed with Automake
2551 @cindex Files distributed with Automake
2552 @cindex @file{config.guess}
2554 @table @code
2555 @item -a
2556 @itemx --add-missing
2557 @opindex -a
2558 @opindex --add-missing
2559 Automake requires certain common files to exist in certain situations;
2560 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2561 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2562 files (@pxref{Auxiliary Programs}); this option will cause the missing
2563 ones to be automatically added to the package, whenever possible.  In
2564 general if Automake tells you a file is missing, try using this option.
2565 By default Automake tries to make a symbolic link pointing to its own
2566 copy of the missing file; this can be changed with @option{--copy}.
2568 Many of the potentially-missing files are common scripts whose
2569 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2570 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2571 file is considered missing, and where the missing file is added
2572 (@pxref{Optional}).
2574 In some strictness modes, additional files are installed, see @ref{Gnits}
2575 for more information.
2577 @item --libdir=@var{dir}
2578 @opindex --libdir
2579 Look for Automake data files in directory @var{dir} instead of in the
2580 installation directory.  This is typically used for debugging.
2582 @vindex AUTOMAKE_LIBDIR
2583 The environment variable @env{AUTOMAKE_LIBDIR} provides another way to
2584 set the directory containing Automake data files.  However
2585 @option{--libdir} takes precedence over it.
2587 @item --print-libdir
2588 @opindex --print-libdir
2589 Print the path of the installation directory containing Automake-provided
2590 scripts and data files (like e.g., @file{texinfo.texi} and
2591 @file{install-sh}).
2593 @item -c
2594 @opindex -c
2595 @itemx --copy
2596 @opindex --copy
2597 When used with @option{--add-missing}, causes installed files to be
2598 copied.  The default is to make a symbolic link.
2600 @item -f
2601 @opindex -f
2602 @itemx --force-missing
2603 @opindex --force-missing
2604 When used with @option{--add-missing}, causes standard files to be reinstalled
2605 even if they already exist in the source tree.  This involves removing
2606 the file from the source tree before creating the new symlink (or, with
2607 @option{--copy}, copying the new file).
2609 @item --foreign
2610 @opindex --foreign
2611 Set the global strictness to @option{foreign}.  For more information, see
2612 @ref{Strictness}.
2614 @item --gnits
2615 @opindex --gnits
2616 Set the global strictness to @option{gnits}.  For more information, see
2617 @ref{Gnits}.
2619 @item --gnu
2620 @opindex --gnu
2621 Set the global strictness to @option{gnu}.  For more information, see
2622 @ref{Gnits}.  This is the default strictness.
2624 @item --help
2625 @opindex --help
2626 Print a summary of the command line options and exit.
2628 @item -i
2629 @itemx --ignore-deps
2630 @opindex -i
2631 This disables the dependency tracking feature in generated
2632 @file{Makefile}s; see @ref{Dependencies}.
2634 @item --include-deps
2635 @opindex --include-deps
2636 This enables the dependency tracking feature.  This feature is enabled
2637 by default.  This option is provided for historical reasons only and
2638 probably should not be used.
2640 @item --no-force
2641 @opindex --no-force
2642 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2643 @file{configure.ac}.  This option causes it to only update those
2644 @file{Makefile.in}s that are out of date with respect to one of their
2645 dependents.
2647 @item -o @var{dir}
2648 @itemx --output-dir=@var{dir}
2649 @opindex -o
2650 @opindex --output-dir
2651 Put the generated @file{Makefile.in} in the directory @var{dir}.
2652 Ordinarily each @file{Makefile.in} is created in the directory of the
2653 corresponding @file{Makefile.am}.  This option is deprecated and will be
2654 removed in a future release.
2656 @item -v
2657 @itemx --verbose
2658 @opindex -v
2659 @opindex --verbose
2660 Cause Automake to print information about which files are being read or
2661 created.
2663 @item --version
2664 @opindex --version
2665 Print the version number of Automake and exit.
2667 @item -W CATEGORY
2668 @itemx --warnings=@var{category}
2669 @opindex -W
2670 @opindex --warnings
2671 Output warnings falling in @var{category}.  @var{category} can be
2672 one of:
2673 @table @code
2674 @item gnu
2675 warnings related to the GNU Coding Standards
2676 (@pxref{Top, , , standards, The GNU Coding Standards}).
2677 @item obsolete
2678 obsolete features or constructions
2679 @item override
2680 user redefinitions of Automake rules or variables
2681 @item portability
2682 portability issues (e.g., use of @command{make} features that are
2683 known to be not portable)
2684 @item extra-portability
2685 extra portability issues related to obscure tools.  One example of such
2686 a tool is the Microsoft @command{lib} archiver.
2687 @item syntax
2688 weird syntax, unused variables, typos
2689 @item unsupported
2690 unsupported or incomplete features
2691 @item all
2692 all the warnings
2693 @item none
2694 turn off all the warnings
2695 @item error
2696 treat warnings as errors
2697 @end table
2699 A category can be turned off by prefixing its name with @samp{no-}.  For
2700 instance, @option{-Wno-syntax} will hide the warnings about unused
2701 variables.
2703 The categories output by default are @samp{obsolete}, @samp{syntax} and
2704 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2705 are enabled in @option{--gnu} and @option{--gnits} strictness.
2707 @c Checked by extra-portability.sh
2708 Turning off @samp{portability} will also turn off @samp{extra-portability},
2709 and similarly turning on @samp{extra-portability} will also turn on
2710 @samp{portability}.  However, turning on @samp{portability} or turning
2711 off @samp{extra-portability} will not affect the other category.
2713 @vindex WARNINGS
2714 The environment variable @env{WARNINGS} can contain a comma separated
2715 list of categories to enable.  It will be taken into account before the
2716 command-line switches, this way @option{-Wnone} will also ignore any
2717 warning category enabled by @env{WARNINGS}.  This variable is also used
2718 by other tools like @command{autoconf}; unknown categories are ignored
2719 for this reason.
2721 @end table
2723 @vindex AUTOMAKE_JOBS
2724 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2725 number, it is taken as the maximum number of Perl threads to use in
2726 @command{automake} for generating multiple @file{Makefile.in} files
2727 concurrently.  This is an experimental feature.
2730 @node configure
2731 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2733 @cindex @file{configure.ac}, scanning
2734 @cindex Scanning @file{configure.ac}
2735 @cindex Using @command{aclocal}
2736 @cindex @command{aclocal}, using
2738 Automake scans the package's @file{configure.ac} to determine certain
2739 information about the package.  Some @command{autoconf} macros are required
2740 and some variables must be defined in @file{configure.ac}.  Automake
2741 will also use information from @file{configure.ac} to further tailor its
2742 output.
2744 Automake also supplies some Autoconf macros to make the maintenance
2745 easier.  These macros can automatically be put into your
2746 @file{aclocal.m4} using the @command{aclocal} program.
2748 @menu
2749 * Requirements::                Configuration requirements
2750 * Optional::                    Other things Automake recognizes
2751 * aclocal Invocation::          Auto-generating aclocal.m4
2752 * Macros::                      Autoconf macros supplied with Automake
2753 @end menu
2756 @node Requirements
2757 @section Configuration requirements
2759 @cindex Automake requirements
2760 @cindex Requirements of Automake
2762 @acindex AM_INIT_AUTOMAKE
2763 The one real requirement of Automake is that your @file{configure.ac}
2764 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2765 required for proper Automake operation (@pxref{Macros}).
2767 Here are the other macros that Automake requires but which are not run
2768 by @code{AM_INIT_AUTOMAKE}:
2770 @table @code
2771 @item AC_CONFIG_FILES
2772 @itemx AC_OUTPUT
2773 @acindex AC_CONFIG_FILES
2774 @acindex AC_OUTPUT
2775 These two macros are usually invoked as follows near the end of
2776 @file{configure.ac}.
2778 @example
2779 @dots{}
2780 AC_CONFIG_FILES([
2781   Makefile
2782   doc/Makefile
2783   src/Makefile
2784   src/lib/Makefile
2785   @dots{}
2787 AC_OUTPUT
2788 @end example
2790 Automake uses these to determine which files to create (@pxref{Output, ,
2791 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2792 is considered to be an Automake generated @file{Makefile} if there
2793 exists a file with the same name and the @file{.am} extension appended.
2794 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2795 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2797 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2799 @example
2800 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2801 @end example
2803 @noindent
2804 @command{automake} will generate the first @file{.in} input file for
2805 which a @file{.am} file exists.  If no such file exists the output
2806 file is not considered to be generated by Automake.
2808 Files created by @code{AC_CONFIG_FILES}, be they Automake
2809 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2810 Their inputs are automatically distributed, unless they
2811 are the output of prior @code{AC_CONFIG_FILES} commands.
2812 Finally, rebuild rules are generated in the Automake @file{Makefile}
2813 existing in the subdirectory of the output file, if there is one, or
2814 in the top-level @file{Makefile} otherwise.
2816 The above machinery (cleaning, distributing, and rebuilding) works
2817 fine if the @code{AC_CONFIG_FILES} specifications contain only
2818 literals.  If part of the specification uses shell variables,
2819 @command{automake} will not be able to fulfill this setup, and you will
2820 have to complete the missing bits by hand.  For instance, on
2822 @c Keep in sync with output11.sh
2823 @example
2824 file=input
2825 @dots{}
2826 AC_CONFIG_FILES([output:$file],, [file=$file])
2827 @end example
2829 @noindent
2830 @command{automake} will output rules to clean @file{output}, and
2831 rebuild it.  However the rebuild rule will not depend on @file{input},
2832 and this file will not be distributed either.  (You must add
2833 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2834 source file.)
2836 Similarly
2838 @c Keep in sync with output11.sh
2839 @example
2840 file=output
2841 file2=out:in
2842 @dots{}
2843 AC_CONFIG_FILES([$file:input],, [file=$file])
2844 AC_CONFIG_FILES([$file2],, [file2=$file2])
2845 @end example
2847 @noindent
2848 will only cause @file{input} to be distributed.  No file will be
2849 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2850 yourself), and no rebuild rule will be output.
2852 Obviously @command{automake} cannot guess what value @samp{$file} is
2853 going to hold later when @file{configure} is run, and it cannot use
2854 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2855 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2856 that is compatible with @command{make}'s syntax) and furthermore use
2857 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2858 @file{Makefile}, then @command{automake} will be able to use
2859 @samp{$@{file@}} to generate all of these rules.  For instance, here is
2860 how the Automake package itself generates versioned scripts for its
2861 test suite:
2863 @example
2864 AC_SUBST([APIVERSION], @dots{})
2865 @dots{}
2866 AC_CONFIG_FILES(
2867   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2868   [chmod +x tests/aclocal-$@{APIVERSION@}],
2869   [APIVERSION=$APIVERSION])
2870 AC_CONFIG_FILES(
2871   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2872   [chmod +x tests/automake-$@{APIVERSION@}])
2873 @end example
2875 @noindent
2876 Here cleaning, distributing, and rebuilding are done automatically,
2877 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2879 Note that you should not use shell variables to declare
2880 @file{Makefile} files for which @command{automake} must create
2881 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2882 @command{automake} needs to know the file name when it runs in order
2883 to check whether @file{Makefile.am} exists.  (In the very hairy case
2884 that your setup requires such use of variables, you will have to tell
2885 Automake which @file{Makefile.in}s to generate on the command-line.)
2887 It is possible to let @command{automake} emit conditional rules for
2888 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2889 (@pxref{Optional}).
2891 To summarize:
2892 @itemize @bullet
2893 @item
2894 Use literals for @file{Makefile}s, and for other files whenever possible.
2895 @item
2896 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2897 for files that @command{automake} should ignore.
2898 @item
2899 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2900 that @command{automake} should not ignore.
2901 @end itemize
2903 @end table
2906 @node Optional
2907 @section Other things Automake recognizes
2909 @cindex Macros Automake recognizes
2910 @cindex Recognized macros by Automake
2912 Every time Automake is run it calls Autoconf to trace
2913 @file{configure.ac}.  This way it can recognize the use of certain
2914 macros and tailor the generated @file{Makefile.in} appropriately.
2915 Currently recognized macros and their effects are:
2917 @ftable @code
2918 @item AC_CANONICAL_BUILD
2919 @itemx AC_CANONICAL_HOST
2920 @itemx AC_CANONICAL_TARGET
2921 @vindex build_triplet
2922 @vindex host_triplet
2923 @vindex target_triplet
2924 Automake will ensure that @file{config.guess} and @file{config.sub}
2925 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2926 @code{host_triplet} and @code{target_triplet} are introduced.  See
2927 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2928 The Autoconf Manual}.
2930 @item AC_CONFIG_AUX_DIR
2931 Automake will look for various helper scripts, such as
2932 @file{install-sh}, in the directory named in this macro invocation.
2933 @c This list is accurate relative to version 1.11
2934 (The full list of scripts is:
2935 @file{ar-lib},
2936 @file{config.guess},
2937 @file{config.sub},
2938 @file{depcomp},
2939 @file{compile},
2940 @file{install-sh},
2941 @file{ltmain.sh},
2942 @file{mdate-sh},
2943 @file{missing},
2944 @file{mkinstalldirs},
2945 @file{py-compile},
2946 @file{test-driver},
2947 @file{texinfo.tex},
2948 @file{ylwrap}.)
2949 Not all scripts are always searched for; some scripts
2950 will only be sought if the generated @file{Makefile.in} requires them.
2952 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2953 their standard locations.  For @file{mdate-sh},
2954 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2955 source directory corresponding to the current @file{Makefile.am}.  For
2956 the rest, the standard location is the first one of @file{.}, @file{..},
2957 or @file{../..} (relative to the top source directory) that provides any
2958 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2959 autoconf, The Autoconf Manual}.
2961 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2962 distributed, even if there is no @file{Makefile.am} in this directory.
2964 @item AC_CONFIG_LIBOBJ_DIR
2965 Automake will require the sources file declared with
2966 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2967 macro.
2969 @item AC_CONFIG_HEADERS
2970 Automake will generate rules to rebuild these headers from the
2971 corresponding templates (usually, the template for a @file{foo.h}
2972 header being @file{foo.h.in}).  Older versions of Automake
2973 required the use of @code{AM_CONFIG_HEADER}; this is no longer
2974 the case, and that macro has indeed been removed.
2976 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2977 specification using shell variables will be ignored as far as
2978 cleaning, distributing, and rebuilding is concerned.
2980 @item AC_CONFIG_LINKS
2981 Automake will generate rules to remove @file{configure} generated
2982 links on @samp{make distclean} and to distribute named source files as
2983 part of @samp{make dist}.
2985 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2986 specification using shell variables will be ignored as far as cleaning
2987 and distributing is concerned.  (There are no rebuild rules for links.)
2989 @item AC_LIBOBJ
2990 @itemx AC_LIBSOURCE
2991 @itemx AC_LIBSOURCES
2992 @vindex LIBOBJS
2993 Automake will automatically distribute any file listed in
2994 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2996 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2997 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2998 @file{file.c} will be distributed automatically by Automake.  This
2999 encompasses many macros like @code{AC_FUNC_ALLOCA},
3000 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
3002 By the way, direct assignments to @code{LIBOBJS} are no longer
3003 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
3004 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
3005 autoconf, The Autoconf Manual}.
3007 @item AC_PROG_RANLIB
3008 This is required if any libraries are built in the package.
3009 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3010 Autoconf Manual}.
3012 @item AC_PROG_CXX
3013 This is required if any C++ source is included.  @xref{Particular
3014 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3016 @item AC_PROG_OBJC
3017 This is required if any Objective C source is included.  @xref{Particular
3018 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3020 @item AC_PROG_OBJCXX
3021 This is required if any Objective C++ source is included.  @xref{Particular
3022 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3024 @item AC_PROG_F77
3025 This is required if any Fortran 77 source is included.  @xref{Particular
3026 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3028 @item AC_F77_LIBRARY_LDFLAGS
3029 This is required for programs and shared libraries that are a mixture of
3030 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
3031 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
3033 @item AC_FC_SRCEXT
3034 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
3035 of files with the respective source extension (@pxref{Fortran Compiler, ,
3036 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
3038 @item AC_PROG_FC
3039 This is required if any Fortran 90/95 source is included.  This macro is
3040 distributed with Autoconf version 2.58 and later.  @xref{Particular
3041 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3043 @item AC_PROG_LIBTOOL
3044 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
3045 Introduction, libtool, The Libtool Manual}).
3047 @item AC_PROG_YACC
3048 @vindex YACC
3049 If a Yacc source file is seen, then you must either use this macro or
3050 define the variable @code{YACC} in @file{configure.ac}.  The former is
3051 preferred (@pxref{Particular Programs, , Particular Program Checks,
3052 autoconf, The Autoconf Manual}).
3054 @item AC_PROG_LEX
3055 If a Lex source file is seen, then this macro must be used.
3056 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3057 Autoconf Manual}.
3059 @item AC_REQUIRE_AUX_FILE
3060 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3061 @command{automake} will ensure that @file{@var{file}} exists in the
3062 aux directory, and will complain otherwise.  It
3063 will also automatically distribute the file.  This macro should be
3064 used by third-party Autoconf macros that require some supporting
3065 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3066 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
3067 The Autoconf Manual}.
3069 @item AC_SUBST
3070 The first argument is automatically defined as a variable in each
3071 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3072 used for this variable.  @xref{Setting Output Variables, , Setting
3073 Output Variables, autoconf, The Autoconf Manual}.
3075 For every substituted variable @var{var}, @command{automake} will add
3076 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3077 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3078 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3079 @code{X_LIBS}.  Thus, you can access these variables as
3080 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3081 if @code{AC_PATH_XTRA} is called.
3083 @item AM_CONDITIONAL
3084 This introduces an Automake conditional (@pxref{Conditionals}).
3086 @item AM_COND_IF
3087 This macro allows @code{automake} to detect subsequent access within
3088 @file{configure.ac} to a conditional previously introduced with
3089 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3090 (@pxref{Usage of Conditionals}).
3092 @item AM_GNU_GETTEXT
3093 This macro is required for packages that use GNU gettext
3094 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
3095 this macro it ensures that the package meets some of gettext's
3096 requirements.
3098 @item AM_GNU_GETTEXT_INTL_SUBDIR
3099 This macro specifies that the @file{intl/} subdirectory is to be built,
3100 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3101 of @samp{external}.
3103 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3104 @opindex --enable-maintainer-mode
3105 @opindex --disable-maintainer-mode
3106 This macro adds an @option{--enable-maintainer-mode} option to
3107 @command{configure}.  If this is used, @command{automake} will cause
3108 ``maintainer-only'' rules to be turned off by default in the
3109 generated @file{Makefile.in}s, unless @var{default-mode} is
3110 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3111 conditional, which you can use in your own @file{Makefile.am}.
3112 @xref{maintainer-mode}.
3114 @item AM_SUBST_NOTMAKE(@var{var})
3115 Prevent Automake from defining a variable @var{var}, even if it is
3116 substituted by @command{config.status}.  Normally, Automake defines a
3117 @command{make} variable for each @command{configure} substitution,
3118 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3119 definition from Automake.  If @code{AC_SUBST} has not been called
3120 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3121 Preventing variable definitions may be useful for substitution of
3122 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3123 unintended results.
3125 @item m4_include
3126 Files included by @file{configure.ac} using this macro will be
3127 detected by Automake and automatically distributed.  They will also
3128 appear as dependencies in @file{Makefile} rules.
3130 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3131 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3132 some required macros come from files local to your package (as opposed to
3133 macros installed in a system-wide directory, @pxref{aclocal Invocation}).
3135 @end ftable
3137 @node aclocal Invocation
3138 @section Auto-generating aclocal.m4
3139 @c This node used to be named "Invoking automake".  This @anchor
3140 @c allows old links to still work.
3141 @anchor{Invoking aclocal}
3143 @cindex Invocation of @command{aclocal}
3144 @cindex @command{aclocal}, Invocation
3145 @cindex Invoking @command{aclocal}
3146 @cindex @command{aclocal}, Invoking
3148 Automake includes a number of Autoconf macros that can be used in
3149 your package (@pxref{Macros}); some of them are actually required by
3150 Automake in certain situations.  These macros must be defined in your
3151 @file{aclocal.m4}; otherwise they will not be seen by
3152 @command{autoconf}.
3154 The @command{aclocal} program will automatically generate
3155 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3156 This provides a convenient way to get Automake-provided macros,
3157 without having to search around.  The @command{aclocal} mechanism
3158 allows other packages to supply their own macros (@pxref{Extending
3159 aclocal}).  You can also use it to maintain your own set of custom
3160 macros (@pxref{Local Macros}).
3162 At startup, @command{aclocal} scans all the @file{.m4} files it can
3163 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3164 it scans @file{configure.ac}.  Any mention of one of the macros found
3165 in the first step causes that macro, and any macros it in turn
3166 requires, to be put into @file{aclocal.m4}.
3168 @emph{Putting} the file that contains the macro definition into
3169 @file{aclocal.m4} is usually done by copying the entire text of this
3170 file, including unused macro definitions as well as both @samp{#} and
3171 @samp{dnl} comments.  If you want to make a comment that will be
3172 completely ignored by @command{aclocal}, use @samp{##} as the comment
3173 leader.
3175 When a file selected by @command{aclocal} is located in a subdirectory
3176 specified as a relative search path with @command{aclocal}'s @option{-I}
3177 argument, @command{aclocal} assumes the file belongs to the package
3178 and uses @code{m4_include} instead of copying it into
3179 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3180 tracking, and cause the file to be distributed automatically.
3181 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3182 system-wide directory, or via an absolute search path will be copied.
3183 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3184 some relative directory should be considered outside the package.
3186 The contents of @file{acinclude.m4}, if this file exists, are also
3187 automatically included in @file{aclocal.m4}.  We recommend against
3188 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3190 @vindex AUTOM4TE
3191 @cindex autom4te
3192 While computing @file{aclocal.m4}, @command{aclocal} runs
3193 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3194 autoconf, The Autoconf Manual}) in order to trace the macros that are
3195 really used, and omit from @file{aclocal.m4} all macros that are
3196 mentioned but otherwise unexpanded (this can happen when a macro is
3197 called conditionally).  @command{autom4te} is expected to be in the
3198 @env{PATH}, just as @command{autoconf}.  Its location can be
3199 overridden using the @env{AUTOM4TE} environment variable.
3201 @menu
3202 * aclocal Options::             Options supported by aclocal
3203 * Macro Search Path::           How aclocal finds .m4 files
3204 * Extending aclocal::           Writing your own aclocal macros
3205 * Local Macros::                Organizing local macros
3206 * Serials::                     Serial lines in Autoconf macros
3207 * Future of aclocal::           aclocal's scheduled death
3208 @end menu
3210 @node aclocal Options
3211 @subsection aclocal Options
3213 @cindex @command{aclocal}, Options
3214 @cindex Options, @command{aclocal}
3216 @command{aclocal} accepts the following options:
3218 @table @code
3219 @item --automake-acdir=@var{dir}
3220 @opindex --automake-acdir
3221 Look for the automake-provided macro files in @var{dir} instead of
3222 in the installation directory.  This is typically used for debugging.
3224 @vindex ACLOCAL_AUTOMAKE_DIR
3225 The environment variable @env{ACLOCAL_AUTOMAKE_DIR} provides another
3226 way to set the directory containing automake-provided macro files.
3227 However @option{--automake-acdir} takes precedence over it.
3229 @item --system-acdir=@var{dir}
3230 @opindex --system-acdir
3231 Look for the system-wide third-party macro files (and the special
3232 @file{dirlist} file) in @var{dir} instead of in the installation
3233 directory.  This is typically used for debugging.
3235 @item --diff[=@var{command}]
3236 @opindex --diff
3237 Run @var{command} on M4 file that would be installed or overwritten
3238 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3239 This option implies @option{--install} and @option{--dry-run}.
3241 @item --dry-run
3242 @opindex --dry-run
3243 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3244 files installed by @option{--install}.
3246 @item --help
3247 @opindex --help
3248 Print a summary of the command line options and exit.
3250 @item -I @var{dir}
3251 @opindex -I
3252 Add the directory @var{dir} to the list of directories searched for
3253 @file{.m4} files.
3255 @item --install
3256 @opindex --install
3257 Install system-wide third-party macros into the first directory
3258 specified with @samp{-I @var{dir}} instead of copying them in the
3259 output file.
3260 @c Keep in sync with aclocal-install-absdir.sh
3261 Note that this will happen also if @var{dir} is an absolute path.
3263 @cindex serial number and @option{--install}
3264 When this option is used, and only when this option is used,
3265 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3266 that appear in macros: an M4 file is ignored if there exists another
3267 M4 file with the same basename and a greater serial number in the
3268 search path (@pxref{Serials}).
3270 @item --force
3271 @opindex --force
3272 Always overwrite the output file.  The default is to overwrite the output
3273 file only when really needed, i.e., when its contents changes or if one
3274 of its dependencies is younger.
3276 This option forces the update of @file{aclocal.m4} (or the file
3277 specified with @file{--output} below) and only this file, it has
3278 absolutely no influence on files that may need to be installed by
3279 @option{--install}.
3281 @item --output=@var{file}
3282 @opindex --output
3283 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3285 @item --print-ac-dir
3286 @opindex --print-ac-dir
3287 Prints the name of the directory that @command{aclocal} will search to
3288 find third-party @file{.m4} files.  When this option is given, normal
3289 processing is suppressed.  This option was used @emph{in the past} by
3290 third-party packages to determine where to install @file{.m4} macro
3291 files, but @emph{this usage is today discouraged}, since it causes
3292 @samp{$(prefix)} not to be thoroughly honored (which violates the
3293 GNU Coding Standards), and a similar semantics can be better obtained
3294 with the @env{ACLOCAL_PATH} environment variable; @pxref{Extending aclocal}.
3296 @item --verbose
3297 @opindex --verbose
3298 Print the names of the files it examines.
3300 @item --version
3301 @opindex --version
3302 Print the version number of Automake and exit.
3304 @item -W CATEGORY
3305 @item --warnings=@var{category}
3306 @opindex -W
3307 @opindex --warnings
3308 Output warnings falling in @var{category}.  @var{category} can be
3309 one of:
3310 @table @code
3311 @item syntax
3312 dubious syntactic constructs, underquoted macros, unused macros, etc.
3313 @item unsupported
3314 unknown macros
3315 @item all
3316 all the warnings, this is the default
3317 @item none
3318 turn off all the warnings
3319 @item error
3320 treat warnings as errors
3321 @end table
3323 All warnings are output by default.
3325 @vindex WARNINGS
3326 The environment variable @env{WARNINGS} is honored in the same
3327 way as it is for @command{automake} (@pxref{automake Invocation}).
3329 @end table
3331 @node Macro Search Path
3332 @subsection Macro Search Path
3334 @cindex Macro search path
3335 @cindex @command{aclocal} search path
3337 By default, @command{aclocal} searches for @file{.m4} files in the following
3338 directories, in this order:
3340 @table @code
3341 @item @var{acdir-APIVERSION}
3342 This is where the @file{.m4} macros distributed with Automake itself
3343 are stored.  @var{APIVERSION} depends on the Automake release used;
3344 for example, for Automake 1.11.x, @var{APIVERSION} = @code{1.11}.
3346 @item @var{acdir}
3347 This directory is intended for third party @file{.m4} files, and is
3348 configured when @command{automake} itself is built.  This is
3349 @file{@@datadir@@/aclocal/}, which typically
3350 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3351 value of @var{acdir}, use the @option{--print-ac-dir} option
3352 (@pxref{aclocal Options}).
3353 @end table
3355 As an example, suppose that @command{automake-1.11.2} was configured with
3356 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3358 @enumerate
3359 @item @file{/usr/local/share/aclocal-1.11.2/}
3360 @item @file{/usr/local/share/aclocal/}
3361 @end enumerate
3363 The paths for the @var{acdir} and @var{acdir-APIVERSION} directories can
3364 be changed respectively through aclocal options @option{--system-acdir}
3365 and @option{--automake-acdir} (@pxref{aclocal Options}).  Note however
3366 that these options are only intended for use by the internal Automake
3367 test suite, or for debugging under highly unusual situations; they are
3368 not ordinarily needed by end-users.
3370 As explained in (@pxref{aclocal Options}), there are several options that
3371 can be used to change or extend this search path.
3373 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3375 Any extra directories specified using @option{-I} options
3376 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3377 @samp{aclocal -I /foo -I /bar} results in the following search path:
3379 @enumerate
3380 @item @file{/foo}
3381 @item @file{/bar}
3382 @item @var{acdir}-@var{APIVERSION}
3383 @item @var{acdir}
3384 @end enumerate
3386 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3387 @cindex @file{dirlist}
3389 There is a third mechanism for customizing the search path.  If a
3390 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3391 contain a list of directory patterns, one per line.  @command{aclocal}
3392 expands these patterns to directory names, and adds them to the search
3393 list @emph{after} all other directories.  @file{dirlist} entries may
3394 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3396 For example, suppose
3397 @file{@var{acdir}/dirlist} contains the following:
3399 @example
3400 /test1
3401 /test2
3402 /test3*
3403 @end example
3405 @noindent
3406 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3407 Then, the search path would be
3409 @c @code looks better than @file here
3410 @enumerate
3411 @item @code{/foo}
3412 @item @code{/bar}
3413 @item @var{acdir}-@var{APIVERSION}
3414 @item @var{acdir}
3415 @item @code{/test1}
3416 @item @code{/test2}
3417 @end enumerate
3419 @noindent
3420 and all directories with path names starting with @code{/test3}.
3422 If the @option{--system-acdir=@var{dir}} option is used, then
3423 @command{aclocal} will search for the @file{dirlist} file in
3424 @var{dir}; but remember the warnings  above against the use of
3425 @option{--system-acdir}.
3427 @file{dirlist} is useful in the following situation: suppose that
3428 @command{automake} version @code{1.11.2} is installed with
3429 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3430 directories are
3432 @c @code looks better than @file here
3433 @enumerate
3434 @item @code{/usr/share/aclocal-1.11/}
3435 @item @code{/usr/share/aclocal/}
3436 @end enumerate
3438 However, suppose further that many packages have been manually
3439 installed on the system, with $prefix=/usr/local, as is typical.  In
3440 that case, many of these ``extra'' @file{.m4} files are in
3441 @file{/usr/local/share/aclocal}.  The only way to force
3442 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3443 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3444 inconvenient.  With @file{dirlist}, one may create a file
3445 @file{/usr/share/aclocal/dirlist} containing only the single line
3447 @example
3448 /usr/local/share/aclocal
3449 @end example
3451 Now, the ``default'' search path on the affected system is
3453 @c @code looks better than @file here
3454 @enumerate
3455 @item @code{/usr/share/aclocal-1.11/}
3456 @item @code{/usr/share/aclocal/}
3457 @item @code{/usr/local/share/aclocal/}
3458 @end enumerate
3460 without the need for @option{-I} options; @option{-I} options can be reserved
3461 for project-specific needs (@file{my-source-dir/m4/}), rather than
3462 using it to work around local system-dependent tool installation
3463 directories.
3465 Similarly, @file{dirlist} can be handy if you have installed a local
3466 copy of Automake in your account and want @command{aclocal} to look for
3467 macros installed at other places on the system.
3469 @anchor{ACLOCAL_PATH}
3470 @subsubheading Modifying the Macro Search Path: @file{ACLOCAL_PATH}
3471 @cindex @env{ACLOCAL_PATH}
3473 The fourth and last mechanism to customize the macro search path is
3474 also the simplest.  Any directory included in the colon-separated
3475 environment variable @env{ACLOCAL_PATH} is added to the search path
3476 @c Keep in sync with aclocal-path-precedence.sh
3477 and takes precedence over system directories (including those found via
3478 @file{dirlist}), with the exception of the versioned directory
3479 @var{acdir-APIVERSION} (@pxref{Macro Search Path}).  However, directories
3480 passed via @option{-I} will take precedence over directories in
3481 @env{ACLOCAL_PATH}.
3483 @c Keep in sync with aclocal-path-installed.sh
3484 Also note that, if the @option{--install} option is used, any @file{.m4}
3485 file containing a required macro that is found in a directory listed in
3486 @env{ACLOCAL_PATH} will be installed locally.
3487 @c Keep in sync with aclocal-path-installed-serial.sh
3488 In this case, serial numbers in @file{.m4} are honored too,
3489 @pxref{Serials}.
3491 Conversely to @file{dirlist}, @env{ACLOCAL_PATH} is useful if you are
3492 using a global copy of Automake and want @command{aclocal} to look for
3493 macros somewhere under your home directory.
3495 @subsubheading Planned future incompatibilities
3497 The order in which the directories in the macro search path are currently
3498 looked up is confusing and/or suboptimal in various aspects, and is
3499 probably going to be changed in the future Automake release.  In
3500 particular, directories in @env{ACLOCAL_PATH} and @file{@var{acdir}}
3501 might end up taking precedence over @file{@var{acdir-APIVERSION}}, and
3502 directories in @file{@var{acdir}/dirlist} might end up taking precedence
3503 over @file{@var{acdir}}.  @emph{This is a possible future incompatibility!}
3505 @node Extending aclocal
3506 @subsection Writing your own aclocal macros
3508 @cindex @command{aclocal}, extending
3509 @cindex Extending @command{aclocal}
3511 The @command{aclocal} program doesn't have any built-in knowledge of any
3512 macros, so it is easy to extend it with your own macros.
3514 This can be used by libraries that want to supply their own Autoconf
3515 macros for use by other programs.  For instance, the @command{gettext}
3516 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3517 any package using @command{gettext}.  When the library is installed, it
3518 installs this macro so that @command{aclocal} will find it.
3520 A macro file's name should end in @file{.m4}.  Such files should be
3521 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3523 @c Keep in sync with primary-prefix-couples-documented-valid.sh
3524 @example
3525 aclocaldir = $(datadir)/aclocal
3526 aclocal_DATA = mymacro.m4 myothermacro.m4
3527 @end example
3529 @noindent
3530 Please do use @file{$(datadir)/aclocal}, and not something based on
3531 the result of @samp{aclocal --print-ac-dir} (@pxref{Hard-Coded Install
3532 Paths}, for arguments).  It might also be helpful to suggest to
3533 the user to add the @file{$(datadir)/aclocal} directory to his
3534 @env{ACLOCAL_PATH} variable (@pxref{ACLOCAL_PATH}) so that
3535 @command{aclocal} will find the @file{.m4} files installed by your
3536 package automatically.
3538 A file of macros should be a series of properly quoted
3539 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3540 Autoconf Manual}).  The @command{aclocal} programs also understands
3541 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3542 Autoconf Manual}), so it is safe to put each macro in a separate file.
3543 Each file should have no side effects but macro definitions.
3544 Especially, any call to @code{AC_PREREQ} should be done inside the
3545 defined macro, not at the beginning of the file.
3547 @cindex underquoted @code{AC_DEFUN}
3548 @acindex AC_DEFUN
3549 @acindex AC_PREREQ
3551 Starting with Automake 1.8, @command{aclocal} will warn about all
3552 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3553 lot of people, because @command{aclocal} was not so strict in the past
3554 and many third party macros are underquoted; and we have to apologize
3555 for this temporary inconvenience.  The reason we have to be stricter
3556 is that a future implementation of @command{aclocal} (@pxref{Future of
3557 aclocal}) will have to temporarily include all of these third party
3558 @file{.m4} files, maybe several times, including even files that are
3559 not actually needed.  Doing so should alleviate many problems of the
3560 current implementation, however it requires a stricter style from the
3561 macro authors.  Hopefully it is easy to revise the existing macros.
3562 For instance,
3564 @example
3565 # bad style
3566 AC_PREREQ(2.68)
3567 AC_DEFUN(AX_FOOBAR,
3568 [AC_REQUIRE([AX_SOMETHING])dnl
3569 AX_FOO
3570 AX_BAR
3572 @end example
3574 @noindent
3575 should be rewritten as
3577 @example
3578 AC_DEFUN([AX_FOOBAR],
3579 [AC_PREREQ([2.68])dnl
3580 AC_REQUIRE([AX_SOMETHING])dnl
3581 AX_FOO
3582 AX_BAR
3584 @end example
3586 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3587 Autoconf 2.68 will not be required if @code{AX_FOOBAR} is not actually
3588 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3589 allows the macro to be redefined or included twice (otherwise this
3590 first argument would be expanded during the second definition).  For
3591 consistency we like to quote even arguments such as @code{2.68} that
3592 do not require it.
3594 If you have been directed here by the @command{aclocal} diagnostic but
3595 are not the maintainer of the implicated macro, you will want to
3596 contact the maintainer of that macro.  Please make sure you have the
3597 latest version of the macro and that the problem hasn't already been
3598 reported before doing so: people tend to work faster when they aren't
3599 flooded by mails.
3601 Another situation where @command{aclocal} is commonly used is to
3602 manage macros that are used locally by the package, @ref{Local
3603 Macros}.
3605 @node Local Macros
3606 @subsection Handling Local Macros
3608 Feature tests offered by Autoconf do not cover all needs.  People
3609 often have to supplement existing tests with their own macros, or
3610 with third-party macros.
3612 There are two ways to organize custom macros in a package.
3614 The first possibility (the historical practice) is to list all your
3615 macros in @file{acinclude.m4}.  This file will be included in
3616 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3617 henceforth be visible to @command{autoconf}.  However if it contains
3618 numerous macros, it will rapidly become difficult to maintain, and it
3619 will be almost impossible to share macros between packages.
3621 The second possibility, which we do recommend, is to write each macro
3622 in its own file and gather all these files in a directory.  This
3623 directory is usually called @file{m4/}.  Then it's enough to update
3624 @file{configure.ac} by adding a proper call to @code{AC_CONFIG_MACRO_DIRS}:
3626 @example
3627 AC_CONFIG_MACRO_DIRS([m4])
3628 @end example
3630 @command{aclocal} will then take care of automatically adding @file{m4/}
3631 to its search path for m4 files.
3633 When @samp{aclocal} is run, it will build an @file{aclocal.m4}
3634 that @code{m4_include}s any file from @file{m4/} that defines a
3635 required macro.  Macros not found locally will still be searched in
3636 system-wide directories, as explained in @ref{Macro Search Path}.
3638 Custom macros should be distributed for the same reason that
3639 @file{configure.ac} is: so that other people have all the sources of
3640 your package if they want to work on it.  Actually, this distribution
3641 happens automatically because all @code{m4_include}d files are
3642 distributed.
3644 However there is no consensus on the distribution of third-party
3645 macros that your package may use.  Many libraries install their own
3646 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3647 aclocal}).  For instance, Guile ships with a file called
3648 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3649 be used to define setup compiler and linker flags appropriate for
3650 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3651 cause @command{aclocal} to copy @file{guile.m4} into
3652 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3653 it will not be distributed.  Technically, that means a user who
3654 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3655 This is probably OK, if Guile already is a requirement to build the
3656 package.  However, if Guile is only an optional feature, or if your
3657 package might run on architectures where Guile cannot be installed,
3658 this requirement will hinder development.  An easy solution is to copy
3659 such third-party macros in your local @file{m4/} directory so they get
3660 distributed.
3662 Since Automake 1.10, @command{aclocal} offers the option @code{--install}
3663 to copy these system-wide third-party macros in your local macro directory,
3664 helping to solve the above problem.
3666 With this setup, system-wide macros will be copied to @file{m4/}
3667 the first time you run @command{aclocal}.  Then the locally installed
3668 macros will have precedence over the system-wide installed macros
3669 each time @command{aclocal} is run again.
3671 One reason why you should keep @option{--install} in the flags even
3672 after the first run is that when you later edit @file{configure.ac}
3673 and depend on a new macro, this macro will be installed in your
3674 @file{m4/} automatically.  Another one is that serial numbers
3675 (@pxref{Serials}) can be used to update the macros in your source tree
3676 automatically when new system-wide versions are installed.  A serial
3677 number should be a single line of the form
3679 @example
3680 #serial @var{nnn}
3681 @end example
3683 @noindent
3684 where @var{nnn} contains only digits and dots.  It should appear in
3685 the M4 file before any macro definition.  It is a good practice to
3686 maintain a serial number for each macro you distribute, even if you do
3687 not use the @option{--install} option of @command{aclocal}: this allows
3688 other people to use it.
3691 @node Serials
3692 @subsection Serial Numbers
3693 @cindex serial numbers in macros
3694 @cindex macro serial numbers
3695 @cindex @code{#serial} syntax
3696 @cindex @command{aclocal} and serial numbers
3698 Because third-party macros defined in @file{*.m4} files are naturally
3699 shared between multiple projects, some people like to version them.
3700 This makes it easier to tell which of two M4 files is newer.  Since at
3701 least 1996, the tradition is to use a @samp{#serial} line for this.
3703 A serial number should be a single line of the form
3705 @example
3706 # serial @var{version}
3707 @end example
3709 @noindent
3710 where @var{version} is a version number containing only digits and
3711 dots.  Usually people use a single integer, and they increment it each
3712 time they change the macro (hence the name of ``serial'').  Such a
3713 line should appear in the M4 file before any macro definition.
3715 The @samp{#} must be the first character on the line,
3716 and it is OK to have extra words after the version, as in
3718 @example
3719 #serial @var{version} @var{garbage}
3720 @end example
3722 Normally these serial numbers are completely ignored by
3723 @command{aclocal} and @command{autoconf}, like any genuine comment.
3724 However when using @command{aclocal}'s @option{--install} feature, these
3725 serial numbers will modify the way @command{aclocal} selects the
3726 macros to install in the package: if two files with the same basename
3727 exist in your search path, and if at least one of them uses a
3728 @samp{#serial} line, @command{aclocal} will ignore the file that has
3729 the older @samp{#serial} line (or the file that has none).
3731 Note that a serial number applies to a whole M4 file, not to any macro
3732 it contains.  A file can contains multiple macros, but only one
3733 serial.
3735 Here is a use case that illustrates the use of @option{--install} and
3736 its interaction with serial numbers.  Let's assume we maintain a
3737 package called MyPackage, the @file{configure.ac} of which requires a
3738 third-party macro @code{AX_THIRD_PARTY} defined in
3739 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3741 @example
3742 # serial 1
3743 AC_DEFUN([AX_THIRD_PARTY], [...])
3744 @end example
3746 MyPackage uses an @file{m4/} directory to store local macros as
3747 explained in @ref{Local Macros}, and has
3749 @example
3750 AC_CONFIG_MACRO_DIRS([m4])
3751 @end example
3753 @noindent
3754 in its @file{configure.ac}.
3756 Initially the @file{m4/} directory is empty.  The first time we run
3757 @command{aclocal --install}, it will notice that
3759 @itemize @bullet
3760 @item
3761 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3762 @item
3763 No local macros define @code{AX_THIRD_PARTY}
3764 @item
3765 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3766 with serial 1.
3767 @end itemize
3769 @noindent
3770 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3771 and @command{aclocal} was given the @option{--install} option, it will
3772 copy this file in @file{m4/thirdparty.m4}, and output an
3773 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3775 The next time @samp{aclocal --install} is run, something different
3776 happens.  @command{aclocal} notices that
3778 @itemize @bullet
3779 @item
3780 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3781 @item
3782 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3783 with serial 1.
3784 @item
3785 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3786 with serial 1.
3787 @end itemize
3789 @noindent
3790 Because both files have the same serial number, @command{aclocal} uses
3791 the first it found in its search path order (@pxref{Macro Search
3792 Path}).  @command{aclocal} therefore ignores
3793 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3794 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3796 Local directories specified with @option{-I} are always searched before
3797 system-wide directories, so a local file will always be preferred to
3798 the system-wide file in case of equal serial numbers.
3800 Now suppose the system-wide third-party macro is changed.  This can
3801 happen if the package installing this macro is updated.  Let's suppose
3802 the new macro has serial number 2.  The next time @samp{aclocal --install}
3803 is run the situation is the following:
3805 @itemize @bullet
3806 @item
3807 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3808 @item
3809 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3810 with serial 1.
3811 @item
3812 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3813 with serial 2.
3814 @end itemize
3816 @noindent
3817 When @command{aclocal} sees a greater serial number, it immediately
3818 forgets anything it knows from files that have the same basename and a
3819 smaller serial number.  So after it has found
3820 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3821 @command{aclocal} will proceed as if it had never seen
3822 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3823 to that at the beginning of our example, where no local file defined
3824 the macro.  @command{aclocal} will install the new version of the
3825 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3826 version.  MyPackage just had its macro updated as a side effect of
3827 running @command{aclocal}.
3829 If you are leery of letting @command{aclocal} update your local
3830 macro, you can run @samp{aclocal --diff} to review the changes
3831 @samp{aclocal --install} would perform on these macros.
3833 Finally, note that the @option{--force} option of @command{aclocal} has
3834 absolutely no effect on the files installed by @option{--install}.  For
3835 instance, if you have modified your local macros, do not expect
3836 @option{--install --force} to replace the local macros by their
3837 system-wide versions.  If you want to do so, simply erase the local
3838 macros you want to revert, and run @samp{aclocal --install}.
3841 @node Future of aclocal
3842 @subsection The Future of @command{aclocal}
3843 @cindex @command{aclocal}'s scheduled death
3845 @command{aclocal} is expected to disappear.  This feature really
3846 should not be offered by Automake.  Automake should focus on
3847 generating @file{Makefile}s; dealing with M4 macros really is
3848 Autoconf's job.  The fact that some people install Automake just to use
3849 @command{aclocal}, but do not use @command{automake} otherwise is an
3850 indication of how that feature is misplaced.
3852 The new implementation will probably be done slightly differently.
3853 For instance, it could enforce the @file{m4/}-style layout discussed in
3854 @ref{Local Macros}.
3856 We have no idea when and how this will happen.  This has been
3857 discussed several times in the past, but someone still has to commit
3858 to that non-trivial task.
3860 From the user point of view, @command{aclocal}'s removal might turn
3861 out to be painful.  There is a simple precaution that you may take to
3862 make that switch more seamless: never call @command{aclocal} yourself.
3863 Keep this guy under the exclusive control of @command{autoreconf} and
3864 Automake's rebuild rules.  Hopefully you won't need to worry about
3865 things breaking, when @command{aclocal} disappears, because everything
3866 will have been taken care of.  If otherwise you used to call
3867 @command{aclocal} directly yourself or from some script, you will
3868 quickly notice the change.
3870 Many packages come with a script called @file{bootstrap} or
3871 @file{autogen.sh}, that will just call @command{aclocal},
3872 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3873 @command{autoconf}, @command{autoheader}, and @command{automake} in
3874 the right order.  Actually this is precisely what @command{autoreconf}
3875 can do for you.  If your package has such a @file{bootstrap} or
3876 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3877 should simplify its logic a lot (less things to maintain, yum!), it's
3878 even likely you will not need the script anymore, and more to the point
3879 you will not call @command{aclocal} directly anymore.
3881 For the time being, third-party packages should continue to install
3882 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3883 is replaced by another tool it might make sense to rename the
3884 directory, but supporting @file{/usr/share/aclocal/} for backward
3885 compatibility should be really easy provided all macros are properly
3886 written (@pxref{Extending aclocal}).
3890 @node Macros
3891 @section Autoconf macros supplied with Automake
3893 Automake ships with several Autoconf macros that you can use from your
3894 @file{configure.ac}.  When you use one of them it will be included by
3895 @command{aclocal} in @file{aclocal.m4}.
3897 @menu
3898 * Public Macros::               Macros that you can use.
3899 * Obsolete Macros::             Macros that will soon be removed.
3900 * Private Macros::              Macros that you should not use.
3901 @end menu
3903 @c consider generating the following subsections automatically from m4 files.
3905 @node Public Macros
3906 @subsection Public Macros
3908 @table @code
3910 @item AM_INIT_AUTOMAKE([OPTIONS])
3911 @acindex AM_INIT_AUTOMAKE
3912 Runs many macros required for proper operation of the generated Makefiles.
3914 @vindex AUTOMAKE_OPTIONS
3915 Today, @code{AM_INIT_AUTOMAKE} is called with a single argument: a
3916 space-separated list of Automake options that should be applied to
3917 every @file{Makefile.am} in the tree.  The effect is as if
3918 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3920 @acindex AC_INIT
3921 This macro can also be called in another, @emph{deprecated} form:
3922 @code{AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])}.  In this form,
3923 there are two required arguments: the package and the version number.
3924 This usage is mostly obsolete because the @var{package} and @var{version}
3925 can be obtained from Autoconf's @code{AC_INIT} macro.  However,
3926 differently from what happens for @code{AC_INIT} invocations, this
3927 @code{AM_INIT_AUTOMAKE} invocation supports shell variables' expansions
3928 in the @code{PACKAGE} and @code{VERSION} arguments (which otherwise
3929 defaults, respectively, to the @code{PACKAGE_TARNAME} and
3930 @code{PACKAGE_VERSION} defined via the @code{AC_INIT} invocation;
3931 @pxref{AC_INIT, , The @code{AC_INIT} macro, autoconf, The Autoconf Manual});
3932 and this can be still be useful in some selected situations.
3933 Our hope is that future Autoconf versions will improve their support
3934 for package versions defined dynamically at configure runtime; when
3935 (and if) this happens, support for the two-args @code{AM_INIT_AUTOMAKE}
3936 invocation will likely be removed from Automake.
3938 @anchor{Modernize AM_INIT_AUTOMAKE invocation}
3939 If your @file{configure.ac} has:
3941 @example
3942 AC_INIT([src/foo.c])
3943 AM_INIT_AUTOMAKE([mumble], [1.5])
3944 @end example
3946 @noindent
3947 you should modernize it as follows:
3949 @example
3950 AC_INIT([mumble], [1.5])
3951 AC_CONFIG_SRCDIR([src/foo.c])
3952 AM_INIT_AUTOMAKE
3953 @end example
3955 Note that if you're upgrading your @file{configure.ac} from an earlier
3956 version of Automake, it is not always correct to simply move the
3957 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3958 @code{AC_INIT}, as in the example above.  The first argument to
3959 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3960 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3961 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3962 tarball name from the package name, which should work for most but not
3963 all package names.  (If it doesn't work for yours, you can use the
3964 four-argument form of @code{AC_INIT} to provide the tarball name
3965 explicitly).
3967 @cindex @code{PACKAGE}, prevent definition
3968 @cindex @code{VERSION}, prevent definition
3969 @opindex no-define
3970 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3971 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3972 option (@pxref{List of Automake options}):
3973 @example
3974 AM_INIT_AUTOMAKE([no-define ...])
3975 @end example
3977 @item AM_PATH_LISPDIR
3978 @acindex AM_PATH_LISPDIR
3979 @vindex EMACS
3980 @vindex lispdir
3981 Searches for the program @command{emacs}, and, if found, sets the
3982 output variable @code{lispdir} to the full path to Emacs' site-lisp
3983 directory.
3985 Note that this test assumes the @command{emacs} found to be a version
3986 that supports Emacs Lisp (such as GNU Emacs or XEmacs).  Other
3987 emacsen can cause this test to hang (some, like old versions of
3988 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3989 exit, which is hardly obvious for a non-emacs user).  In most cases,
3990 however, you should be able to use @kbd{C-c} to kill the test.  In
3991 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3992 environment, or use the @option{--with-lispdir} option to
3993 @command{configure} to explicitly set the correct path (if you're sure
3994 you have an @command{emacs} that supports Emacs Lisp).
3996 @item AM_PROG_AR(@ovar{act-if-fail})
3997 @acindex AM_PROG_AR
3998 @vindex AR
3999 You must use this macro when you use the archiver in your project, if
4000 you want support for unusual archivers such as Microsoft @command{lib}.
4001 The content of the optional argument is executed if the archiver
4002 interface is not recognized; the default action is to abort configure
4003 with an error message.
4005 @item AM_PROG_AS
4006 @acindex AM_PROG_AS
4007 @vindex CCAS
4008 @vindex CCASFLAGS
4009 Use this macro when you have assembly code in your project.  This will
4010 choose the assembler for you (by default the C compiler) and set
4011 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
4013 @item AM_PROG_CC_C_O
4014 @acindex AM_PROG_CC_C_O
4015 This is an obsolescent macro that checks that the C compiler supports
4016 the @option{-c} and @option{-o} options together.  Note that, since
4017 Automake 1.14, the @code{AC_PROG_CC} is rewritten to implement such
4018 checks itself, and thus the explicit use of @code{AM_PROG_CC_C_O}
4019 should no longer be required.
4021 @item AM_PROG_LEX
4022 @acindex AM_PROG_LEX
4023 @acindex AC_PROG_LEX
4024 @cindex HP-UX 10, @command{lex} problems
4025 @cindex @command{lex} problems with HP-UX 10
4026 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
4027 Program Checks, autoconf, The Autoconf Manual}), but uses the
4028 @command{missing} script on systems that do not have @command{lex}.
4029 HP-UX 10 is one such system.
4031 @item AM_PROG_GCJ
4032 @acindex AM_PROG_GCJ
4033 @vindex GCJ
4034 @vindex GCJFLAGS
4035 This macro finds the @command{gcj} program or causes an error.  It sets
4036 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
4037 GNU Compiler Collection.
4039 @item AM_PROG_UPC([@var{compiler-search-list}])
4040 @acindex AM_PROG_UPC
4041 @vindex UPC
4042 Find a compiler for Unified Parallel C and define the @code{UPC}
4043 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
4044 This macro will abort @command{configure} if no Unified Parallel C
4045 compiler is found.
4047 @item AM_MISSING_PROG(@var{name}, @var{program})
4048 @acindex AM_MISSING_PROG
4049 @vindex MISSING
4050 Find a maintainer tool @var{program} and define the @var{name}
4051 environment variable with its location.  If @var{program} is not
4052 detected, then @var{name} will instead invoke the @command{missing}
4053 script, in order to give useful advice to the user about the missing
4054 maintainer tool.  @xref{maintainer-mode}, for more information on when
4055 the @command{missing} script is appropriate.
4057 @item AM_SILENT_RULES
4058 @acindex AM_SILENT_RULES
4059 Control the machinery for less verbose build output
4060 (@pxref{Automake Silent Rules}).
4062 @item AM_WITH_DMALLOC
4063 @acindex AM_WITH_DMALLOC
4064 @cindex @command{dmalloc}, support for
4065 @vindex WITH_DMALLOC
4066 @opindex --with-dmalloc
4067 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
4068 the user runs @command{configure} with @option{--with-dmalloc}, then
4069 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
4071 @end table
4074 @node Obsolete Macros
4075 @subsection Obsolete Macros
4076 @cindex obsolete macros
4077 @cindex autoupdate
4079 Although using some of the following macros was required in past
4080 releases, you should not use any of them in new code.  @emph{All
4081 these macros will be removed in the next major Automake version};
4082 if you are still using them, running @command{autoupdate} should
4083 adjust your @file{configure.ac} automatically (@pxref{autoupdate
4084 Invocation, , Using @command{autoupdate} to Modernize
4085 @file{configure.ac}, autoconf, The Autoconf Manual}).
4086 @emph{Do it NOW!}
4088 @table @code
4090 @item AM_PROG_MKDIR_P
4091 @acindex AM_PROG_MKDIR_P
4092 @cindex @code{mkdir -p}, macro check
4093 @vindex MKDIR_P
4094 @vindex mkdir_p
4096 From Automake 1.8 to 1.9.6 this macro used to define the output
4097 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
4098 -d}, or @code{mkinstalldirs}.
4100 Nowadays Autoconf provides a similar functionality with
4101 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
4102 Program Checks, autoconf, The Autoconf Manual}), however this defines
4103 the output variable @code{MKDIR_P} instead.  In case you are still
4104 using the @code{AM_PROG_MKDIR_P} macro in your @file{configure.ac},
4105 or its provided variable @code{$(mkdir_p)} in your @file{Makefile.am},
4106 you are advised to switch ASAP to the more modern Autoconf-provided
4107 interface instead; both the macro and the variable might be removed
4108 in a future major Automake release.
4110 @end table
4113 @node Private Macros
4114 @subsection Private Macros
4116 The following macros are private macros you should not call directly.
4117 They are called by the other public macros when appropriate.  Do not
4118 rely on them, as they might be changed in a future version.  Consider
4119 them as implementation details; or better, do not consider them at all:
4120 skip this section!
4122 @ftable @code
4123 @item _AM_DEPENDENCIES
4124 @itemx AM_SET_DEPDIR
4125 @itemx AM_DEP_TRACK
4126 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4127 These macros are used to implement Automake's automatic dependency
4128 tracking scheme.  They are called automatically by Automake when
4129 required, and there should be no need to invoke them manually.
4131 @item AM_MAKE_INCLUDE
4132 This macro is used to discover how the user's @command{make} handles
4133 @code{include} statements.  This macro is automatically invoked when
4134 needed; there should be no need to invoke it manually.
4136 @item AM_PROG_INSTALL_STRIP
4137 This is used to find a version of @code{install} that can be used to
4138 strip a program at installation time.  This macro is automatically
4139 included when required.
4141 @item AM_SANITY_CHECK
4142 This checks to make sure that a file created in the build directory is
4143 newer than a file in the source directory.  This can fail on systems
4144 where the clock is set incorrectly.  This macro is automatically run
4145 from @code{AM_INIT_AUTOMAKE}.
4147 @end ftable
4150 @node Directories
4151 @chapter Directories
4153 For simple projects that distribute all files in the same directory
4154 it is enough to have a single @file{Makefile.am} that builds
4155 everything in place.
4157 In larger projects, it is common to organize files in different
4158 directories, in a tree.  For example, there could be a directory
4159 for the program's source, one for the testsuite, and one for the
4160 documentation; or, for very large projects, there could be one
4161 directory per program, per library or per module.
4163 The traditional approach is to build these subdirectories recursively,
4164 employing @emph{make recursion}: each directory contains its
4165 own @file{Makefile}, and when @command{make} is run from the top-level
4166 directory, it enters each subdirectory in turn, and invokes there a
4167 new @command{make} instance to build the directory's contents.
4169 Because this approach is very widespread, Automake offers built-in
4170 support for it.  However, it is worth nothing that the use of make
4171 recursion has its own serious issues and drawbacks, and that it's
4172 well possible to have packages with a multi directory layout that
4173 make little or no use of such recursion (examples of such packages
4174 are GNU Bison and GNU Automake itself); see also the @ref{Alternative}
4175 section below.
4177 @menu
4178 * Subdirectories::              Building subdirectories recursively
4179 * Conditional Subdirectories::  Conditionally not building directories
4180 * Alternative::                 Subdirectories without recursion
4181 * Subpackages::                 Nesting packages
4182 @end menu
4184 @node Subdirectories
4185 @section Recursing subdirectories
4187 @cindex @code{SUBDIRS}, explained
4189 In packages using make recursion, the top level @file{Makefile.am} must
4190 tell Automake which subdirectories are to be built.  This is done via
4191 the @code{SUBDIRS} variable.
4192 @vindex SUBDIRS
4194 The @code{SUBDIRS} variable holds a list of subdirectories in which
4195 building of various sorts can occur.  The rules for many targets
4196 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4197 both locally and in all specified subdirectories.  Note that the
4198 directories listed in @code{SUBDIRS} are not required to contain
4199 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4200 This allows inclusion of libraries from packages that do not use
4201 Automake (such as @code{gettext}; see also @ref{Third-Party
4202 Makefiles}).
4204 In packages that use subdirectories, the top-level @file{Makefile.am} is
4205 often very short.  For instance, here is the @file{Makefile.am} from the
4206 GNU Hello distribution:
4208 @example
4209 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4210 SUBDIRS = doc intl po src tests
4211 @end example
4213 When Automake invokes @command{make} in a subdirectory, it uses the value
4214 of the @code{MAKE} variable.  It passes the value of the variable
4215 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4216 @file{Makefile.am} if there are flags you must always pass to
4217 @command{make}.
4218 @vindex MAKE
4219 @vindex AM_MAKEFLAGS
4221 The directories mentioned in @code{SUBDIRS} are usually direct
4222 children of the current directory, each subdirectory containing its
4223 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4224 subdirectories.  Automake can be used to construct packages of
4225 arbitrary depth this way.
4227 By default, Automake generates @file{Makefiles} that work depth-first
4228 in postfix order: the subdirectories are built before the current
4229 directory.  However, it is possible to change this ordering.  You can
4230 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4231 putting @samp{.} first will cause a prefix ordering of
4232 directories.
4234 Using
4236 @example
4237 SUBDIRS = lib src . test
4238 @end example
4240 @noindent
4241 will cause @file{lib/} to be built before @file{src/}, then the
4242 current directory will be built, finally the @file{test/} directory
4243 will be built.  It is customary to arrange test directories to be
4244 built after everything else since they are meant to test what has
4245 been constructed.
4247 In addition to the built-in recursive targets defined by Automake
4248 (@code{all}, @code{check}, etc.), the developer can also define his
4249 own recursive targets.  That is done by passing the names of such
4250 targets as arguments to the m4 macro @code{AM_EXTRA_RECURSIVE_TARGETS}
4251 in @file{configure.ac}.  Automake generates rules to handle the
4252 recursion for such targets; and the developer can define real actions
4253 for them by defining corresponding @code{-local} targets.
4255 @example
4256 % @kbd{cat configure.ac}
4257 AC_INIT([pkg-name], [1.0]
4258 AM_INIT_AUTOMAKE
4259 AM_EXTRA_RECURSIVE_TARGETS([foo])
4260 AC_CONFIG_FILES([Makefile sub/Makefile sub/src/Makefile])
4261 AC_OUTPUT
4262 % @kbd{cat Makefile.am}
4263 SUBDIRS = sub
4264 foo-local:
4265         @@echo This will be run by "make foo".
4266 % @kbd{cat sub/Makefile.am}
4267 SUBDIRS = src
4268 % @kbd{cat sub/src/Makefile.am}
4269 foo-local:
4270         @@echo This too will be run by a "make foo" issued either in
4271         @@echo the 'sub/src/' directory, the 'sub/' directory, or the
4272         @@echo top-level directory.
4273 @end example
4275 @node Conditional Subdirectories
4276 @section Conditional Subdirectories
4277 @cindex Subdirectories, building conditionally
4278 @cindex Conditional subdirectories
4279 @cindex @code{SUBDIRS}, conditional
4280 @cindex Conditional @code{SUBDIRS}
4282 It is possible to define the @code{SUBDIRS} variable conditionally if,
4283 like in the case of GNU Inetutils, you want to only build a subset of
4284 the entire package.
4286 To illustrate how this works, let's assume we have two directories
4287 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4288 want to decide in @command{configure} whether @file{opt/} will be built
4289 or not.  (For this example we will assume that @file{opt/} should be
4290 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4292 Running @command{make} should thus recurse into @file{src/} always, and
4293 then maybe in @file{opt/}.
4295 However @samp{make dist} should always recurse into both @file{src/}
4296 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4297 is not needed in the current configuration.  This means
4298 @file{opt/Makefile} should be created @emph{unconditionally}.
4300 There are two ways to setup a project like this.  You can use Automake
4301 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4302 variables (@pxref{Setting Output Variables, , Setting Output
4303 Variables, autoconf, The Autoconf Manual}).  Using Automake
4304 conditionals is the preferred solution.  Before we illustrate these
4305 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4307 @menu
4308 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4309 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4310 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4311 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4312 @end menu
4314 @node SUBDIRS vs DIST_SUBDIRS
4315 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4316 @cindex @code{DIST_SUBDIRS}, explained
4318 Automake considers two sets of directories, defined by the variables
4319 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4321 @code{SUBDIRS} contains the subdirectories of the current directory
4322 that must be built (@pxref{Subdirectories}).  It must be defined
4323 manually; Automake will never guess a directory is to be built.  As we
4324 will see in the next two sections, it is possible to define it
4325 conditionally so that some directory will be omitted from the build.
4327 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4328 directories, even those that have been conditionally left out of the
4329 build.  Recall our example where we may not want to build subdirectory
4330 @file{opt/}, but yet we want to distribute it?  This is where
4331 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4332 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4334 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4335 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4336 other recursive rules use @code{SUBDIRS}.
4338 If @code{SUBDIRS} is defined conditionally using Automake
4339 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4340 from the possible values of @code{SUBDIRS} in all conditions.
4342 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4343 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4344 does not know the possible values of these variables.  In this case
4345 @code{DIST_SUBDIRS} needs to be defined manually.
4347 @node Subdirectories with AM_CONDITIONAL
4348 @subsection Subdirectories with @code{AM_CONDITIONAL}
4349 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4350 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4352 @c Keep in sync with subdir-am-cond.sh
4354 @file{configure} should output the @file{Makefile} for each directory
4355 and define a condition into which @file{opt/} should be built.
4357 @example
4358 @dots{}
4359 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4360 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4361 @dots{}
4362 @end example
4364 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4365 as follows.
4367 @example
4368 if COND_OPT
4369   MAYBE_OPT = opt
4370 endif
4371 SUBDIRS = src $(MAYBE_OPT)
4372 @end example
4374 As you can see, running @command{make} will rightly recurse into
4375 @file{src/} and maybe @file{opt/}.
4377 @vindex DIST_SUBDIRS
4378 As you can't see, running @samp{make dist} will recurse into both
4379 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4380 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4381 @code{DIST_SUBDIRS} variable.
4383 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4384 automatically because it knows that @code{MAYBE_OPT} can contain
4385 @samp{opt} in some condition.
4387 @node Subdirectories with AC_SUBST
4388 @subsection Subdirectories with @code{AC_SUBST}
4389 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4390 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4392 @c Keep in sync with subdir-ac-subst.sh
4394 Another possibility is to define @code{MAYBE_OPT} from
4395 @file{./configure} using @code{AC_SUBST}:
4397 @example
4398 @dots{}
4399 if test "$want_opt" = yes; then
4400   MAYBE_OPT=opt
4401 else
4402   MAYBE_OPT=
4404 AC_SUBST([MAYBE_OPT])
4405 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4406 @dots{}
4407 @end example
4409 In this case the top-level @file{Makefile.am} should look as follows.
4411 @example
4412 SUBDIRS = src $(MAYBE_OPT)
4413 DIST_SUBDIRS = src opt
4414 @end example
4416 The drawback is that since Automake cannot guess what the possible
4417 values of @code{MAYBE_OPT} are, it is necessary to define
4418 @code{DIST_SUBDIRS}.
4420 @node Unconfigured Subdirectories
4421 @subsection Unconfigured Subdirectories
4422 @cindex Subdirectories, configured conditionally
4424 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4425 users that try to @emph{configure and build} subdirectories
4426 conditionally.  Here by configuring we mean creating the
4427 @file{Makefile} (it might also involve running a nested
4428 @command{configure} script: this is a costly operation that explains
4429 why people want to do it conditionally, but only the @file{Makefile}
4430 is relevant to the discussion).
4432 The above examples all assume that every @file{Makefile} is created,
4433 even in directories that are not going to be built.  The simple reason
4434 is that we want @samp{make dist} to distribute even the directories
4435 that are not being built (e.g., platform-dependent code), hence
4436 @file{make dist} must recurse into the subdirectory, hence this
4437 directory must be configured and appear in @code{DIST_SUBDIRS}.
4439 Building packages that do not configure every subdirectory is a tricky
4440 business, and we do not recommend it to the novice as it is easy to
4441 produce an incomplete tarball by mistake.  We will not discuss this
4442 topic in depth here, yet for the adventurous here are a few rules to
4443 remember.
4445 @cartouche
4446 @itemize
4447 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4449 It makes little sense to have a directory in @code{SUBDIRS} that
4450 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4451 which directories listed in the latter should be built.
4452 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4453 must be configured.
4455 I.e., the @file{Makefile} must exists or the recursive @command{make}
4456 rules will not be able to process the directory.
4457 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4459 So that the cleaning rules remove the generated @file{Makefile}s.
4460 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4461 lists all the directories that have been configured.
4462 @end itemize
4463 @end cartouche
4465 In order to prevent recursion in some unconfigured directory you
4466 must therefore ensure that this directory does not appear in
4467 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4468 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4469 @code{DIST_SUBDIRS} explicitly, it will be default to
4470 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4471 = $(SUBDIRS)}.
4473 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4474 not be distributed unless you make other arrangements for this to
4475 happen (for instance, always running @samp{make dist} in a
4476 configuration where all directories are known to appear in
4477 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4478 distribute these directories).
4480 @cindex Subdirectories, not distributed
4481 In few packages, unconfigured directories are not even expected to
4482 be distributed.  Although these packages do not require the
4483 aforementioned extra arrangements, there is another pitfall.  If the
4484 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4485 @command{automake} will make sure the directory exists.  Consequently
4486 @command{automake} cannot be run on such a distribution when one
4487 directory has been omitted.  One way to avoid this check is to use the
4488 @code{AC_SUBST} method to declare conditional directories; since
4489 @command{automake} does not know the values of @code{AC_SUBST}
4490 variables it cannot ensure the corresponding directory exists.
4492 @node Alternative
4493 @section An Alternative Approach to Subdirectories
4495 If you've ever read Peter Miller's excellent paper,
4496 @uref{http://miller.emu.id.au/pmiller/books/rmch/,
4497 Recursive Make Considered Harmful}, the preceding sections on the use of
4498 make recursion will probably come as unwelcome advice.  For those who
4499 haven't read the paper, Miller's main thesis is that recursive
4500 @command{make} invocations are both slow and error-prone.
4502 Automake provides sufficient cross-directory support @footnote{We
4503 believe.  This work is new and there are probably warts.
4504 @xref{Introduction}, for information on reporting bugs.} to enable you
4505 to write a single @file{Makefile.am} for a complex multi-directory
4506 package.
4508 By default an installable file specified in a subdirectory will have its
4509 directory name stripped before installation.  For instance, in this
4510 example, the header file will be installed as
4511 @file{$(includedir)/stdio.h}:
4513 @example
4514 include_HEADERS = inc/stdio.h
4515 @end example
4517 @vindex nobase_
4518 @cindex @code{nobase_} prefix
4519 @cindex Path stripping, avoiding
4520 @cindex Avoiding path stripping
4522 However, the @samp{nobase_} prefix can be used to circumvent this path
4523 stripping.  In this example, the header file will be installed as
4524 @file{$(includedir)/sys/types.h}:
4526 @example
4527 nobase_include_HEADERS = sys/types.h
4528 @end example
4530 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4531 @cindex @code{dist_} and @code{nobase_}
4532 @cindex @code{nodist_} and @code{nobase_}
4533 @vindex dist_
4534 @vindex nodist_
4536 @samp{nobase_} should be specified first when used in conjunction with
4537 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4538 Control}).  For instance:
4540 @example
4541 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4542 @end example
4544 Finally, note that a variable using the @samp{nobase_} prefix can
4545 often be replaced by several variables, one for each destination
4546 directory (@pxref{Uniform}).  For instance, the last example could be
4547 rewritten as follows:
4549 @c Keep in sync with primary-prefix-couples-documented-valid.sh
4550 @example
4551 imagesdir = $(pkgdatadir)/images
4552 soundsdir = $(pkgdatadir)/sounds
4553 dist_images_DATA = images/vortex.pgm
4554 dist_sounds_DATA = sounds/whirl.ogg
4555 @end example
4557 @noindent
4558 This latter syntax makes it possible to change one destination
4559 directory without changing the layout of the source tree.
4561 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4562 rule, in that there is no particular installation order guarantee for
4563 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4565 @node Subpackages
4566 @section Nesting Packages
4567 @cindex Nesting packages
4568 @cindex Subpackages
4569 @acindex AC_CONFIG_SUBDIRS
4570 @acindex AC_CONFIG_AUX_DIR
4573 In the GNU Build System, packages can be nested to arbitrary depth.
4574 This means that a package can embed other packages with their own
4575 @file{configure}, @file{Makefile}s, etc.
4577 These other packages should just appear as subdirectories of their
4578 parent package.  They must be listed in @code{SUBDIRS} like other
4579 ordinary directories.  However the subpackage's @file{Makefile}s
4580 should be output by its own @file{configure} script, not by the
4581 parent's @file{configure}.  This is achieved using the
4582 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4583 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4584 autoconf, The Autoconf Manual}).
4586 Here is an example package for an @code{arm} program that links with
4587 a @code{hand} library that is a nested package in subdirectory
4588 @file{hand/}.
4590 @code{arm}'s @file{configure.ac}:
4592 @example
4593 AC_INIT([arm], [1.0])
4594 AC_CONFIG_AUX_DIR([.])
4595 AM_INIT_AUTOMAKE
4596 AC_PROG_CC
4597 AC_CONFIG_FILES([Makefile])
4598 # Call hand's ./configure script recursively.
4599 AC_CONFIG_SUBDIRS([hand])
4600 AC_OUTPUT
4601 @end example
4603 @code{arm}'s @file{Makefile.am}:
4605 @example
4606 # Build the library in the hand subdirectory first.
4607 SUBDIRS = hand
4609 # Include hand's header when compiling this directory.
4610 AM_CPPFLAGS = -I$(srcdir)/hand
4612 bin_PROGRAMS = arm
4613 arm_SOURCES = arm.c
4614 # link with the hand library.
4615 arm_LDADD = hand/libhand.a
4616 @end example
4618 Now here is @code{hand}'s @file{hand/configure.ac}:
4620 @example
4621 AC_INIT([hand], [1.2])
4622 AC_CONFIG_AUX_DIR([.])
4623 AM_INIT_AUTOMAKE
4624 AC_PROG_CC
4625 AM_PROG_AR
4626 AC_PROG_RANLIB
4627 AC_CONFIG_FILES([Makefile])
4628 AC_OUTPUT
4629 @end example
4631 @noindent
4632 and its @file{hand/Makefile.am}:
4634 @example
4635 lib_LIBRARIES = libhand.a
4636 libhand_a_SOURCES = hand.c
4637 @end example
4639 When @samp{make dist} is run from the top-level directory it will
4640 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4641 code as well as the @file{hand} subdirectory.  This package can be
4642 built and installed like any ordinary package, with the usual
4643 @samp{./configure && make && make install} sequence (the @code{hand}
4644 subpackage will be built and installed by the process).
4646 When @samp{make dist} is run from the hand directory, it will create a
4647 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4648 to be embedded in another package, it can still be used separately.
4650 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4651 force Automake and Autoconf to search for auxiliary scripts in the
4652 current directory.  For instance, this means that there will be two
4653 copies of @file{install-sh}: one in the top-level of the @code{arm}
4654 package, and another one in the @file{hand/} subdirectory for the
4655 @code{hand} package.
4657 The historical default is to search for these auxiliary scripts in
4658 the parent directory and the grandparent directory.  So if the
4659 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4660 @file{hand/configure.ac}, that subpackage would share the auxiliary
4661 script of the @code{arm} package.  This may looks like a gain in size
4662 (a few kilobytes), but it is actually a loss of modularity as the
4663 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4664 in the subdirectory will not work anymore).
4666 Packages that do not use Automake need more work to be integrated this
4667 way.  @xref{Third-Party Makefiles}.
4669 @node Programs
4670 @chapter Building Programs and Libraries
4672 A large part of Automake's functionality is dedicated to making it easy
4673 to build programs and libraries.
4675 @menu
4676 * A Program::                   Building a program
4677 * A Library::                   Building a library
4678 * A Shared Library::            Building a Libtool library
4679 * Program and Library Variables::  Variables controlling program and
4680                                 library builds
4681 * Default _SOURCES::            Default source files
4682 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4683 * Program Variables::           Variables used when building a program
4684 * Yacc and Lex::                Yacc and Lex support
4685 * C++ Support::                 Compiling C++ sources
4686 * Objective C Support::         Compiling Objective C sources
4687 * Objective C++ Support::       Compiling Objective C++ sources
4688 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4689 * Assembly Support::            Compiling assembly sources
4690 * Fortran 77 Support::          Compiling Fortran 77 sources
4691 * Fortran 9x Support::          Compiling Fortran 9x sources
4692 * Java Support with gcj::       Compiling Java sources using gcj
4693 * Vala Support::                Compiling Vala sources
4694 * Support for Other Languages::  Compiling other languages
4695 * Dependencies::                Automatic dependency tracking
4696 * EXEEXT::                      Support for executable extensions
4697 @end menu
4700 @node A Program
4701 @section Building a program
4703 In order to build a program, you need to tell Automake which sources
4704 are part of it, and which libraries it should be linked with.
4706 This section also covers conditional compilation of sources or
4707 programs.  Most of the comments about these also apply to libraries
4708 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4710 @menu
4711 * Program Sources::             Defining program sources
4712 * Linking::                     Linking with libraries or extra objects
4713 * Conditional Sources::         Handling conditional sources
4714 * Conditional Programs::        Building a program conditionally
4715 @end menu
4717 @node Program Sources
4718 @subsection Defining program sources
4720 @cindex @code{PROGRAMS}, @code{bindir}
4721 @vindex _PROGRAMS
4722 @vindex bin_PROGRAMS
4723 @vindex sbin_PROGRAMS
4724 @vindex libexec_PROGRAMS
4725 @vindex pkglibexec_PROGRAMS
4726 @vindex noinst_PROGRAMS
4727 @vindex check_PROGRAMS
4729 In a directory containing source that gets built into a program (as
4730 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4731 Programs can be installed in @code{bindir}, @code{sbindir},
4732 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4733 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4734 which case the prefix is @samp{check_}.
4736 For instance:
4738 @example
4739 bin_PROGRAMS = hello
4740 @end example
4742 In this simple case, the resulting @file{Makefile.in} will contain code
4743 to generate a program named @code{hello}.
4745 Associated with each program are several assisting variables that are
4746 named after the program.  These variables are all optional, and have
4747 reasonable defaults.  Each variable, its use, and default is spelled out
4748 below; we use the ``hello'' example throughout.
4750 The variable @code{hello_SOURCES} is used to specify which source files
4751 get built into an executable:
4753 @example
4754 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4755 @end example
4757 This causes each mentioned @file{.c} file to be compiled into the
4758 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4760 @cindex @code{_SOURCES} primary, defined
4761 @cindex @code{SOURCES} primary, defined
4762 @cindex Primary variable, @code{SOURCES}
4763 @vindex _SOURCES
4765 If @code{hello_SOURCES} is not specified, then it defaults to the single
4766 file @file{hello.c} (@pxref{Default _SOURCES}).
4767 @vindex _SOURCES
4768 @vindex SOURCES
4770 Multiple programs can be built in a single directory.  Multiple programs
4771 can share a single source file, which must be listed in each
4772 @code{_SOURCES} definition.
4774 @cindex Header files in @code{_SOURCES}
4775 @cindex @code{_SOURCES} and header files
4777 Header files listed in a @code{_SOURCES} definition will be included in
4778 the distribution but otherwise ignored.  In case it isn't obvious, you
4779 should not include the header file generated by @file{configure} in a
4780 @code{_SOURCES} variable; this file should not be distributed.  Lex
4781 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4782 and Lex}.
4785 @node Linking
4786 @subsection Linking the program
4788 If you need to link against libraries that are not found by
4789 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4790 used to specify additional objects or libraries to link with; it is
4791 inappropriate for specifying specific linker flags, you should use
4792 @code{AM_LDFLAGS} for this purpose.
4793 @vindex LDADD
4794 @vindex AM_LDFLAGS
4796 @cindex @code{prog_LDADD}, defined
4798 Sometimes, multiple programs are built in one directory but do not share
4799 the same link-time requirements.  In this case, you can use the
4800 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4801 program as it appears in some @code{_PROGRAMS} variable, and usually
4802 written in lowercase) to override @code{LDADD}.  If this variable exists
4803 for a given program, then that program is not linked using @code{LDADD}.
4804 @vindex maude_LDADD
4806 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4807 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4808 built in the same directory, and has no such link requirement.  Also,
4809 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4810 is what cpio's @file{src/Makefile.am} looks like (abridged):
4812 @example
4813 bin_PROGRAMS = cpio pax $(MT)
4814 libexec_PROGRAMS = $(RMT)
4815 EXTRA_PROGRAMS = mt rmt
4817 LDADD = ../lib/libcpio.a $(INTLLIBS)
4818 rmt_LDADD =
4820 cpio_SOURCES = @dots{}
4821 pax_SOURCES = @dots{}
4822 mt_SOURCES = @dots{}
4823 rmt_SOURCES = @dots{}
4824 @end example
4826 @cindex @code{_LDFLAGS}, defined
4827 @vindex maude_LDFLAGS
4828 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4829 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4830 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4831 this purpose.
4833 @cindex @code{_DEPENDENCIES}, defined
4834 @vindex maude_DEPENDENCIES
4835 @vindex EXTRA_maude_DEPENDENCIES
4836 It is also occasionally useful to have a program depend on some other
4837 target that is not actually part of that program.  This can be done
4838 using either the @code{@var{prog}_DEPENDENCIES} or the
4839 @code{EXTRA_@var{prog}_DEPENDENCIES} variable.  Each program depends on
4840 the contents both variables, but no further interpretation is done.
4842 Since these dependencies are associated to the link rule used to
4843 create the programs they should normally list files used by the link
4844 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4845 files.  In rare cases you may need to add other kinds of files such as
4846 linker scripts, but @emph{listing a source file in
4847 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4848 before all the components of a program are built, consider using the
4849 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4851 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4852 Automake.  The automatically-assigned value is the contents of
4853 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4854 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4855 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4856 @samp{$(ALLOCA)}; these are left because it is known that they will not
4857 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4858 generated.
4860 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4861 may be used.
4863 The @code{EXTRA_@var{prog}_DEPENDENCIES} may be useful for cases where
4864 you merely want to augment the @command{automake}-generated
4865 @code{@var{prog}_DEPENDENCIES} rather than replacing it.
4867 @cindex @code{LDADD} and @option{-l}
4868 @cindex @option{-l} and @code{LDADD}
4869 We recommend that you avoid using @option{-l} options in @code{LDADD}
4870 or @code{@var{prog}_LDADD} when referring to libraries built by your
4871 package.  Instead, write the file name of the library explicitly as in
4872 the above @code{cpio} example.  Use @option{-l} only to list
4873 third-party libraries.  If you follow this rule, the default value of
4874 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4875 omit the other ones.
4878 @node Conditional Sources
4879 @subsection Conditional compilation of sources
4881 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4882 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4883 @code{_SOURCES} variable.  The reason for this is a bit hard to
4884 explain, but suffice to say that it simply won't work.  Automake will
4885 give an error if you try to do this.
4887 Fortunately there are two other ways to achieve the same result.  One is
4888 to use configure substitutions in @code{_LDADD} variables, the other is
4889 to use an Automake conditional.
4891 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4893 @cindex @code{EXTRA_prog_SOURCES}, defined
4895 Automake must know all the source files that could possibly go into a
4896 program, even if not all the files are built in every circumstance.  Any
4897 files that are only conditionally built should be listed in the
4898 appropriate @code{EXTRA_} variable.  For instance, if
4899 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4900 in @code{hello}, the @file{Makefile.am} would contain:
4902 @example
4903 bin_PROGRAMS = hello
4904 hello_SOURCES = hello-common.c
4905 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4906 hello_LDADD = $(HELLO_SYSTEM)
4907 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4908 @end example
4910 @noindent
4911 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4912 @file{configure.ac}:
4914 @example
4915 @dots{}
4916 case $host in
4917   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4918   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4919 esac
4920 AC_SUBST([HELLO_SYSTEM])
4921 @dots{}
4922 @end example
4924 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4925 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4926 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4927 built and linked in.
4929 @subsubheading Conditional Compilation using Automake Conditionals
4931 An often simpler way to compile source files conditionally is to use
4932 Automake conditionals.  For instance, you could use this
4933 @file{Makefile.am} construct to build the same @file{hello} example:
4935 @example
4936 bin_PROGRAMS = hello
4937 if LINUX
4938 hello_SOURCES = hello-linux.c hello-common.c
4939 else
4940 hello_SOURCES = hello-generic.c hello-common.c
4941 endif
4942 @end example
4944 In this case, @file{configure.ac} should setup the @code{LINUX}
4945 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4947 When using conditionals like this you don't need to use the
4948 @code{EXTRA_} variable, because Automake will examine the contents of
4949 each variable to construct the complete list of source files.
4951 If your program uses a lot of files, you will probably prefer a
4952 conditional @samp{+=}.
4954 @example
4955 bin_PROGRAMS = hello
4956 hello_SOURCES = hello-common.c
4957 if LINUX
4958 hello_SOURCES += hello-linux.c
4959 else
4960 hello_SOURCES += hello-generic.c
4961 endif
4962 @end example
4964 @node Conditional Programs
4965 @subsection Conditional compilation of programs
4966 @cindex Conditional programs
4967 @cindex Programs, conditional
4969 Sometimes it is useful to determine the programs that are to be built
4970 at configure time.  For instance, GNU @code{cpio} only builds
4971 @code{mt} and @code{rmt} under special circumstances.  The means to
4972 achieve conditional compilation of programs are the same you can use
4973 to compile source files conditionally: substitutions or conditionals.
4975 @subsubheading Conditional Programs using @command{configure} Substitutions
4977 @vindex EXTRA_PROGRAMS
4978 @cindex @code{EXTRA_PROGRAMS}, defined
4979 In this case, you must notify Automake of all the programs that can
4980 possibly be built, but at the same time cause the generated
4981 @file{Makefile.in} to use the programs specified by @command{configure}.
4982 This is done by having @command{configure} substitute values into each
4983 @code{_PROGRAMS} definition, while listing all optionally built programs
4984 in @code{EXTRA_PROGRAMS}.
4986 @example
4987 bin_PROGRAMS = cpio pax $(MT)
4988 libexec_PROGRAMS = $(RMT)
4989 EXTRA_PROGRAMS = mt rmt
4990 @end example
4992 As explained in @ref{EXEEXT}, Automake will rewrite
4993 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4994 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4995 Obviously it cannot rewrite values obtained at run-time through
4996 @command{configure} substitutions, therefore you should take care of
4997 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4998 ['mt$@{EXEEXT@}'])}.
5000 @subsubheading Conditional Programs using Automake Conditionals
5002 You can also use Automake conditionals (@pxref{Conditionals}) to
5003 select programs to be built.  In this case you don't have to worry
5004 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
5006 @c Keep in sync with exeext.sh
5007 @example
5008 bin_PROGRAMS = cpio pax
5009 if WANT_MT
5010   bin_PROGRAMS += mt
5011 endif
5012 if WANT_RMT
5013   libexec_PROGRAMS = rmt
5014 endif
5015 @end example
5018 @node A Library
5019 @section Building a library
5021 @cindex @code{_LIBRARIES} primary, defined
5022 @cindex @code{LIBRARIES} primary, defined
5023 @cindex Primary variable, @code{LIBRARIES}
5024 @vindex _LIBRARIES
5026 @vindex lib_LIBRARIES
5027 @vindex pkglib_LIBRARIES
5028 @vindex noinst_LIBRARIES
5030 Building a library is much like building a program.  In this case, the
5031 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
5032 @code{libdir} or @code{pkglibdir}.
5034 @xref{A Shared Library}, for information on how to build shared
5035 libraries using libtool and the @code{LTLIBRARIES} primary.
5037 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
5038 For instance, to create a library named @file{libcpio.a}, but not install
5039 it, you would write:
5041 @example
5042 noinst_LIBRARIES = libcpio.a
5043 libcpio_a_SOURCES = @dots{}
5044 @end example
5046 The sources that go into a library are determined exactly as they are
5047 for programs, via the @code{_SOURCES} variables.  Note that the library
5048 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
5049 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
5050 not @samp{libcpio.a_SOURCES}.
5052 @vindex maude_LIBADD
5053 Extra objects can be added to a library using the
5054 @code{@var{library}_LIBADD} variable.  This should be used for objects
5055 determined by @command{configure}.  Again from @code{cpio}:
5057 @c Keep in sync with pr401c.sh
5058 @example
5059 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5060 @end example
5062 In addition, sources for extra objects that will not exist until
5063 configure-time must be added to the @code{BUILT_SOURCES} variable
5064 (@pxref{Sources}).
5066 Building a static library is done by compiling all object files, then
5067 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
5068 library and the list of objects, and finally by calling
5069 @samp{$(RANLIB)} on that library.  You should call
5070 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
5071 @code{RANLIB} (Automake will complain otherwise).  You should also
5072 call @code{AM_PROG_AR} to define @code{AR}, in order to support unusual
5073 archivers such as Microsoft lib.  @code{ARFLAGS} will default to
5074 @code{cru}; you can override this variable by setting it in your
5075 @file{Makefile.am} or by @code{AC_SUBST}ing it from your
5076 @file{configure.ac}.  You can override the @code{AR} variable by
5077 defining a per-library @code{maude_AR} variable (@pxref{Program and
5078 Library Variables}).
5080 @cindex Empty libraries
5081 Be careful when selecting library components conditionally.  Because
5082 building an empty library is not portable, you should ensure that any
5083 library always contains at least one object.
5085 To use a static library when building a program, add it to
5086 @code{LDADD} for this program.  In the following example, the program
5087 @file{cpio} is statically linked with the library @file{libcpio.a}.
5089 @example
5090 noinst_LIBRARIES = libcpio.a
5091 libcpio_a_SOURCES = @dots{}
5093 bin_PROGRAMS = cpio
5094 cpio_SOURCES = cpio.c @dots{}
5095 cpio_LDADD = libcpio.a
5096 @end example
5099 @node A Shared Library
5100 @section Building a Shared Library
5102 @cindex Shared libraries, support for
5104 Building shared libraries portably is a relatively complex matter.
5105 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5106 Libtool Manual}) was created to help build shared libraries in a
5107 platform-independent way.
5109 @menu
5110 * Libtool Concept::             Introducing Libtool
5111 * Libtool Libraries::           Declaring Libtool Libraries
5112 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
5113 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
5114 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
5115 * Libtool Modules::             Building Libtool Modules
5116 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5117 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
5118 * Libtool Issues::              Common Issues Related to Libtool's Use
5119 @end menu
5121 @node Libtool Concept
5122 @subsection The Libtool Concept
5124 @cindex @command{libtool}, introduction
5125 @cindex libtool library, definition
5126 @cindex suffix @file{.la}, defined
5127 @cindex @file{.la} suffix, defined
5129 Libtool abstracts shared and static libraries into a unified concept
5130 henceforth called @dfn{libtool libraries}.  Libtool libraries are
5131 files using the @file{.la} suffix, and can designate a static library,
5132 a shared library, or maybe both.  Their exact nature cannot be
5133 determined until @file{./configure} is run: not all platforms support
5134 all kinds of libraries, and users can explicitly select which
5135 libraries should be built.  (However the package's maintainers can
5136 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
5137 macro, libtool, The Libtool Manual}.)
5139 @cindex suffix @file{.lo}, defined
5140 Because object files for shared and static libraries must be compiled
5141 differently, libtool is also used during compilation.  Object files
5142 built by libtool are called @dfn{libtool objects}: these are files
5143 using the @file{.lo} suffix.  Libtool libraries are built from these
5144 libtool objects.
5146 You should not assume anything about the structure of @file{.la} or
5147 @file{.lo} files and how libtool constructs them: this is libtool's
5148 concern, and the last thing one wants is to learn about libtool's
5149 guts.  However the existence of these files matters, because they are
5150 used as targets and dependencies in @file{Makefile}s rules when
5151 building libtool libraries.  There are situations where you may have
5152 to refer to these, for instance when expressing dependencies for
5153 building source files conditionally (@pxref{Conditional Libtool
5154 Sources}).
5156 @cindex @file{libltdl}, introduction
5158 People considering writing a plug-in system, with dynamically loaded
5159 modules, should look into @file{libltdl}: libtool's dlopening library
5160 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5161 This offers a portable dlopening facility to load libtool libraries
5162 dynamically, and can also achieve static linking where unavoidable.
5164 Before we discuss how to use libtool with Automake in details, it
5165 should be noted that the libtool manual also has a section about how
5166 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5167 with Libtool, libtool, The Libtool Manual}).
5169 @node Libtool Libraries
5170 @subsection Building Libtool Libraries
5172 @cindex @code{_LTLIBRARIES} primary, defined
5173 @cindex @code{LTLIBRARIES} primary, defined
5174 @cindex Primary variable, @code{LTLIBRARIES}
5175 @cindex Example of shared libraries
5176 @vindex lib_LTLIBRARIES
5177 @vindex pkglib_LTLIBRARIES
5178 @vindex _LTLIBRARIES
5180 Automake uses libtool to build libraries declared with the
5181 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5182 list of libtool libraries to build.  For instance, to create a libtool
5183 library named @file{libgettext.la}, and install it in @code{libdir},
5184 write:
5186 @example
5187 lib_LTLIBRARIES = libgettext.la
5188 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5189 @end example
5191 Automake predefines the variable @code{pkglibdir}, so you can use
5192 @code{pkglib_LTLIBRARIES} to install libraries in
5193 @samp{$(libdir)/@@PACKAGE@@/}.
5195 If @file{gettext.h} is a public header file that needs to be installed
5196 in order for people to use the library, it should be declared using a
5197 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5198 Headers listed in the latter should be internal headers that are not
5199 part of the public interface.
5201 @example
5202 lib_LTLIBRARIES = libgettext.la
5203 libgettext_la_SOURCES = gettext.c @dots{}
5204 include_HEADERS = gettext.h @dots{}
5205 @end example
5207 A package can build and install such a library along with other
5208 programs that use it.  This dependency should be specified using
5209 @code{LDADD}.  The following example builds a program named
5210 @file{hello} that is linked with @file{libgettext.la}.
5212 @example
5213 lib_LTLIBRARIES = libgettext.la
5214 libgettext_la_SOURCES = gettext.c @dots{}
5216 bin_PROGRAMS = hello
5217 hello_SOURCES = hello.c @dots{}
5218 hello_LDADD = libgettext.la
5219 @end example
5221 @noindent
5222 Whether @file{hello} is statically or dynamically linked with
5223 @file{libgettext.la} is not yet known: this will depend on the
5224 configuration of libtool and the capabilities of the host.
5227 @node Conditional Libtool Libraries
5228 @subsection Building Libtool Libraries Conditionally
5229 @cindex libtool libraries, conditional
5230 @cindex conditional libtool libraries
5232 Like conditional programs (@pxref{Conditional Programs}), there are
5233 two main ways to build conditional libraries: using Automake
5234 conditionals or using Autoconf @code{AC_SUBST}itutions.
5236 The important implementation detail you have to be aware of is that
5237 the place where a library will be installed matters to libtool: it
5238 needs to be indicated @emph{at link-time} using the @option{-rpath}
5239 option.
5241 For libraries whose destination directory is known when Automake runs,
5242 Automake will automatically supply the appropriate @option{-rpath}
5243 option to libtool.  This is the case for libraries listed explicitly in
5244 some installable @code{_LTLIBRARIES} variables such as
5245 @code{lib_LTLIBRARIES}.
5247 However, for libraries determined at configure time (and thus
5248 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5249 final installation directory.  For such libraries you must add the
5250 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5251 hand.
5253 The examples below illustrate the differences between these two methods.
5255 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5256 variable set at @file{./configure}-time to either @file{libfoo.la},
5257 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5258 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5259 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5260 the link rule for these two libraries.  Therefore the @option{-rpath}
5261 argument must be explicitly supplied.
5263 @c Keep in sync with ltcond.sh
5264 @example
5265 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5266 lib_LTLIBRARIES = $(WANTEDLIBS)
5267 libfoo_la_SOURCES = foo.c @dots{}
5268 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5269 libbar_la_SOURCES = bar.c @dots{}
5270 libbar_la_LDFLAGS = -rpath '$(libdir)'
5271 @end example
5273 Here is how the same @file{Makefile.am} would look using Automake
5274 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5275 Automake is able to compute the @option{-rpath} setting itself, because
5276 it's clear that both libraries will end up in @samp{$(libdir)} if they
5277 are installed.
5279 @c Keep in sync with ltcond.sh
5280 @example
5281 lib_LTLIBRARIES =
5282 if WANT_LIBFOO
5283 lib_LTLIBRARIES += libfoo.la
5284 endif
5285 if WANT_LIBBAR
5286 lib_LTLIBRARIES += libbar.la
5287 endif
5288 libfoo_la_SOURCES = foo.c @dots{}
5289 libbar_la_SOURCES = bar.c @dots{}
5290 @end example
5292 @node Conditional Libtool Sources
5293 @subsection Libtool Libraries with Conditional Sources
5295 Conditional compilation of sources in a library can be achieved in the
5296 same way as conditional compilation of sources in a program
5297 (@pxref{Conditional Sources}).  The only difference is that
5298 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5299 should mention libtool objects (@file{.lo} files).
5301 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5302 we could build a @file{libhello.la} library using either
5303 @file{hello-linux.c} or @file{hello-generic.c} with the following
5304 @file{Makefile.am}.
5306 @c Keep in sync with ltcond2.sh
5307 @example
5308 lib_LTLIBRARIES = libhello.la
5309 libhello_la_SOURCES = hello-common.c
5310 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5311 libhello_la_LIBADD = $(HELLO_SYSTEM)
5312 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5313 @end example
5315 @noindent
5316 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5317 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5319 Or we could simply use an Automake conditional as follows.
5321 @c Keep in sync with ltcond2.sh
5322 @example
5323 lib_LTLIBRARIES = libhello.la
5324 libhello_la_SOURCES = hello-common.c
5325 if LINUX
5326 libhello_la_SOURCES += hello-linux.c
5327 else
5328 libhello_la_SOURCES += hello-generic.c
5329 endif
5330 @end example
5332 @node Libtool Convenience Libraries
5333 @subsection Libtool Convenience Libraries
5334 @cindex convenience libraries, libtool
5335 @cindex libtool convenience libraries
5336 @vindex noinst_LTLIBRARIES
5337 @vindex check_LTLIBRARIES
5339 Sometimes you want to build libtool libraries that should not be
5340 installed.  These are called @dfn{libtool convenience libraries} and
5341 are typically used to encapsulate many sublibraries, later gathered
5342 into one big installed library.
5344 Libtool convenience libraries are declared by directory-less variables
5345 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5346 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5347 not need an @option{-rpath} flag at link time (actually this is the only
5348 difference).
5350 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5351 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5352 @samp{make check}.  Finally, libraries listed in
5353 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5354 rules to build them, but if the library does not appear as a Makefile
5355 dependency anywhere it won't be built (this is why
5356 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5358 Here is a sample setup merging libtool convenience libraries from
5359 subdirectories into one main @file{libtop.la} library.
5361 @c Keep in sync with ltconv.sh
5362 @example
5363 # -- Top-level Makefile.am --
5364 SUBDIRS = sub1 sub2 @dots{}
5365 lib_LTLIBRARIES = libtop.la
5366 libtop_la_SOURCES =
5367 libtop_la_LIBADD = \
5368   sub1/libsub1.la \
5369   sub2/libsub2.la \
5370   @dots{}
5372 # -- sub1/Makefile.am --
5373 noinst_LTLIBRARIES = libsub1.la
5374 libsub1_la_SOURCES = @dots{}
5376 # -- sub2/Makefile.am --
5377 # showing nested convenience libraries
5378 SUBDIRS = sub2.1 sub2.2 @dots{}
5379 noinst_LTLIBRARIES = libsub2.la
5380 libsub2_la_SOURCES =
5381 libsub2_la_LIBADD = \
5382   sub21/libsub21.la \
5383   sub22/libsub22.la \
5384   @dots{}
5385 @end example
5387 When using such setup, beware that @command{automake} will assume
5388 @file{libtop.la} is to be linked with the C linker.  This is because
5389 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5390 default language.  If @code{libtop_la_SOURCES} was not empty,
5391 @command{automake} would select the linker as explained in @ref{How
5392 the Linker is Chosen}.
5394 If one of the sublibraries contains non-C source, it is important that
5395 the appropriate linker be chosen.  One way to achieve this is to
5396 pretend that there is such a non-C file among the sources of the
5397 library, thus forcing @command{automake} to select the appropriate
5398 linker.  Here is the top-level @file{Makefile} of our example updated
5399 to force C++ linking.
5401 @example
5402 SUBDIRS = sub1 sub2 @dots{}
5403 lib_LTLIBRARIES = libtop.la
5404 libtop_la_SOURCES =
5405 # Dummy C++ source to cause C++ linking.
5406 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5407 libtop_la_LIBADD = \
5408   sub1/libsub1.la \
5409   sub2/libsub2.la \
5410   @dots{}
5411 @end example
5413 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5414 files that might be compiled (this is mostly useful when doing
5415 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5416 Libtool Sources}), and the @code{nodist_} prefix means the listed
5417 sources are not to be distributed (@pxref{Program and Library
5418 Variables}).  In effect the file @file{dummy.cxx} does not need to
5419 exist in the source tree.  Of course if you have some real source file
5420 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5421 @code{nodist_EXTRA_libtop_la_SOURCES}.
5424 @node Libtool Modules
5425 @subsection Libtool Modules
5426 @cindex modules, libtool
5427 @cindex libtool modules
5428 @cindex @option{-module}, libtool
5430 These are libtool libraries meant to be dlopened.  They are
5431 indicated to libtool by passing @option{-module} at link-time.
5433 @example
5434 pkglib_LTLIBRARIES = mymodule.la
5435 mymodule_la_SOURCES = doit.c
5436 mymodule_la_LDFLAGS = -module
5437 @end example
5439 Ordinarily, Automake requires that a library's name start with
5440 @code{lib}.  However, when building a dynamically loadable module you
5441 might wish to use a "nonstandard" name.  Automake will not complain
5442 about such nonstandard names if it knows the library being built is a
5443 libtool module, i.e., if @option{-module} explicitly appears in the
5444 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5445 variable when no per-library @code{_LDFLAGS} variable is defined).
5447 As always, @code{AC_SUBST} variables are black boxes to Automake since
5448 their values are not yet known when @command{automake} is run.
5449 Therefore if @option{-module} is set via such a variable, Automake
5450 cannot notice it and will proceed as if the library was an ordinary
5451 libtool library, with strict naming.
5453 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5454 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5456 @node Libtool Flags
5457 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5458 @cindex @code{_LIBADD}, libtool
5459 @cindex @code{_LDFLAGS}, libtool
5460 @cindex @code{_LIBTOOLFLAGS}, libtool
5461 @vindex AM_LIBTOOLFLAGS
5462 @vindex LIBTOOLFLAGS
5463 @vindex maude_LIBTOOLFLAGS
5465 As shown in previous sections, the @samp{@var{library}_LIBADD}
5466 variable should be used to list extra libtool objects (@file{.lo}
5467 files) or libtool libraries (@file{.la}) to add to @var{library}.
5469 The @samp{@var{library}_LDFLAGS} variable is the place to list
5470 additional libtool linking flags, such as @option{-version-info},
5471 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5472 libtool, The Libtool Manual}.
5474 The @command{libtool} command has two kinds of options: mode-specific
5475 options and generic options.  Mode-specific options such as the
5476 aforementioned linking flags should be lumped with the other flags
5477 passed to the tool invoked by @command{libtool} (hence the use of
5478 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5479 options include @option{--tag=@var{tag}} and @option{--silent}
5480 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5481 Libtool Manual} for more options) should appear before the mode
5482 selection on the command line; in @file{Makefile.am}s they should
5483 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5485 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5486 @code{AM_LIBTOOLFLAGS} is used instead.
5488 These flags are passed to libtool after the @option{--tag=@var{tag}}
5489 option computed by Automake (if any), so
5490 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5491 good place to override or supplement the @option{--tag=@var{tag}}
5492 setting.
5494 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5495 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5496 Variables Ordering}.  It allows users to run @samp{make
5497 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5498 @command{libtool} can also be influenced by the Automake support
5499 for silent rules (@pxref{Automake Silent Rules}).
5501 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5502 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5503 @cindex @code{LTLIBOBJS}, special handling
5504 @cindex @code{LIBOBJS}, and Libtool
5505 @cindex @code{LTALLOCA}, special handling
5506 @cindex @code{ALLOCA}, and Libtool
5507 @vindex LTLIBOBJS
5508 @vindex LIBOBJS
5509 @vindex LTALLOCA
5510 @vindex ALLOCA
5511 @acindex AC_LIBOBJ
5513 Where an ordinary library might include @samp{$(LIBOBJS)} or
5514 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5515 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5516 the object files that libtool operates on do not necessarily end in
5517 @file{.o}.
5519 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5520 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5521 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5523 @node Libtool Issues
5524 @subsection Common Issues Related to Libtool's Use
5526 @menu
5527 * Error required file ltmain.sh not found::  The need to run libtoolize
5528 * Objects created both with libtool and without::  Avoid a specific build race
5529 @end menu
5531 @node Error required file ltmain.sh not found
5532 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5533 @cindex @file{ltmain.sh} not found
5534 @cindex @command{libtoolize}, no longer run by @command{automake}
5535 @cindex @command{libtoolize} and @command{autoreconf}
5536 @cindex @command{autoreconf} and @command{libtoolize}
5537 @cindex @file{bootstrap} and @command{autoreconf}
5538 @cindex @file{autogen.sh} and @command{autoreconf}
5540 Libtool comes with a tool called @command{libtoolize} that will
5541 install libtool's supporting files into a package.  Running this
5542 command will install @file{ltmain.sh}.  You should execute it before
5543 @command{aclocal} and @command{automake}.
5545 People upgrading old packages to newer autotools are likely to face
5546 this issue because older Automake versions used to call
5547 @command{libtoolize}.  Therefore old build scripts do not call
5548 @command{libtoolize}.
5550 Since Automake 1.6, it has been decided that running
5551 @command{libtoolize} was none of Automake's business.  Instead, that
5552 functionality has been moved into the @command{autoreconf} command
5553 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5554 The Autoconf Manual}).  If you do not want to remember what to run and
5555 when, just learn the @command{autoreconf} command.  Hopefully,
5556 replacing existing @file{bootstrap} or @file{autogen.sh} scripts by
5557 a call to @command{autoreconf} should also free you from any similar
5558 incompatible change in the future.
5560 @node Objects created both with libtool and without
5561 @subsubsection Objects @samp{created with both libtool and without}
5563 Sometimes, the same source file is used both to build a libtool
5564 library and to build another non-libtool target (be it a program or
5565 another library).
5567 Let's consider the following @file{Makefile.am}.
5569 @example
5570 bin_PROGRAMS = prog
5571 prog_SOURCES = prog.c foo.c @dots{}
5573 lib_LTLIBRARIES = libfoo.la
5574 libfoo_la_SOURCES = foo.c @dots{}
5575 @end example
5577 @noindent
5578 (In this trivial case the issue could be avoided by linking
5579 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5580 @code{prog_SOURCES}.  But let's assume we really want to keep
5581 @file{prog} and @file{libfoo.la} separate.)
5583 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5584 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5585 that in the course of creating @file{foo.lo}, libtool may erase (or
5586 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5588 Therefore, when Automake detects this situation it will complain
5589 with a message such as
5590 @example
5591 object 'foo.$(OBJEXT)' created both with libtool and without
5592 @end example
5594 A workaround for this issue is to ensure that these two objects get
5595 different basenames.  As explained in @ref{Renamed Objects}, this
5596 happens automatically when per-targets flags are used.
5598 @example
5599 bin_PROGRAMS = prog
5600 prog_SOURCES = prog.c foo.c @dots{}
5601 prog_CFLAGS = $(AM_CFLAGS)
5603 lib_LTLIBRARIES = libfoo.la
5604 libfoo_la_SOURCES = foo.c @dots{}
5605 @end example
5607 @noindent
5608 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5609 when the @code{prog_CFLAGS} is defined, it is used instead of
5610 @code{AM_CFLAGS}.  However as a side effect it will cause
5611 @file{prog.c} and @file{foo.c} to be compiled as
5612 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5613 the issue.
5615 @node Program and Library Variables
5616 @section Program and Library Variables
5618 Associated with each program is a collection of variables that can be
5619 used to modify how that program is built.  There is a similar list of
5620 such variables for each library.  The canonical name of the program (or
5621 library) is used as a base for naming these variables.
5623 In the list below, we use the name ``maude'' to refer to the program or
5624 library.  In your @file{Makefile.am} you would replace this with the
5625 canonical name of your program.  This list also refers to ``maude'' as a
5626 program, but in general the same rules apply for both static and dynamic
5627 libraries; the documentation below notes situations where programs and
5628 libraries differ.
5630 @vtable @code
5631 @item maude_SOURCES
5632 This variable, if it exists, lists all the source files that are
5633 compiled to build the program.  These files are added to the
5634 distribution by default.  When building the program, Automake will cause
5635 each source file to be compiled to a single @file{.o} file (or
5636 @file{.lo} when using libtool).  Normally these object files are named
5637 after the source file, but other factors can change this.  If a file in
5638 the @code{_SOURCES} variable has an unrecognized extension, Automake
5639 will do one of two things with it.  If a suffix rule exists for turning
5640 files with the unrecognized extension into @file{.o} files, then
5641 @command{automake} will treat this file as it will any other source file
5642 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5643 ignored as though it were a header file.
5645 The prefixes @code{dist_} and @code{nodist_} can be used to control
5646 whether files listed in a @code{_SOURCES} variable are distributed.
5647 @code{dist_} is redundant, as sources are distributed by default, but it
5648 can be specified for clarity if desired.
5650 It is possible to have both @code{dist_} and @code{nodist_} variants of
5651 a given @code{_SOURCES} variable at once; this lets you easily
5652 distribute some files and not others, for instance:
5654 @example
5655 nodist_maude_SOURCES = nodist.c
5656 dist_maude_SOURCES = dist-me.c
5657 @end example
5659 By default the output file (on Unix systems, the @file{.o} file) will
5660 be put into the current build directory.  However, if the option
5661 @option{subdir-objects} is in effect in the current directory then the
5662 @file{.o} file will be put into the subdirectory named after the
5663 source file.  For instance, with @option{subdir-objects} enabled,
5664 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5665 people prefer this mode of operation.  You can specify
5666 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5667 @cindex Subdirectory, objects in
5668 @cindex Objects in subdirectory
5671 @item EXTRA_maude_SOURCES
5672 Automake needs to know the list of files you intend to compile
5673 @emph{statically}.  For one thing, this is the only way Automake has of
5674 knowing what sort of language support a given @file{Makefile.in}
5675 requires.  @footnote{There are other, more obscure reasons for
5676 this limitation as well.}  This means that, for example, you can't put a
5677 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5678 variable.  If you intend to conditionally compile source files and use
5679 @file{configure} to substitute the appropriate object names into, e.g.,
5680 @code{_LDADD} (see below), then you should list the corresponding source
5681 files in the @code{EXTRA_} variable.
5683 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5684 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5685 sources that may need to be built, but should not be distributed.
5687 @item maude_AR
5688 A static library is created by default by invoking @samp{$(AR)
5689 $(ARFLAGS)} followed by the name of the library and then the objects
5690 being put into the library.  You can override this by setting the
5691 @code{_AR} variable.  This is usually used with C++; some C++
5692 compilers require a special invocation in order to instantiate all the
5693 templates that should go into a library.  For instance, the SGI C++
5694 compiler likes this variable set like so:
5695 @example
5696 libmaude_a_AR = $(CXX) -ar -o
5697 @end example
5699 @item maude_LIBADD
5700 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5701 variable.  For instance, this should be used for objects determined by
5702 @command{configure} (@pxref{A Library}).
5704 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5705 to other libtool libraries.
5707 @item maude_LDADD
5708 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5709 @file{*.la}) can be added to a @emph{program} by listing them in the
5710 @code{_LDADD} variable.  For instance, this should be used for objects
5711 determined by @command{configure} (@pxref{Linking}).
5713 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5714 program-specific linker flags (except for @option{-l}, @option{-L},
5715 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5716 for this purpose.
5718 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5719 could link your program against the X libraries like so:
5721 @example
5722 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5723 @end example
5725 We recommend that you use @option{-l} and @option{-L} only when
5726 referring to third-party libraries, and give the explicit file names
5727 of any library built by your package.  Doing so will ensure that
5728 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5730 @item maude_LDFLAGS
5731 This variable is used to pass extra flags to the link step of a program
5732 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5734 @item maude_LIBTOOLFLAGS
5735 This variable is used to pass extra options to @command{libtool}.
5736 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5737 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5738 option, so they should not be mode-specific options (those belong to
5739 the compiler or linker flags).  @xref{Libtool Flags}.
5741 @item maude_DEPENDENCIES
5742 @itemx EXTRA_maude_DEPENDENCIES
5743 It is also occasionally useful to have a target (program or library)
5744 depend on some other file that is not actually part of that target.
5745 This can be done using the @code{_DEPENDENCIES} variable.  Each
5746 target depends on the contents of such a variable, but no further
5747 interpretation is done.
5749 Since these dependencies are associated to the link rule used to
5750 create the programs they should normally list files used by the link
5751 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5752 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5753 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5754 may need to add other kinds of files such as linker scripts, but
5755 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5756 some source file needs to be built before all the components of a
5757 program are built, consider using the @code{BUILT_SOURCES} variable
5758 (@pxref{Sources}).
5760 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5761 The automatically-assigned value is the contents of @code{_LDADD} or
5762 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5763 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5764 substitutions that are left in are only @samp{$(LIBOBJS)} and
5765 @samp{$(ALLOCA)}; these are left because it is known that they will not
5766 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5768 @code{_DEPENDENCIES} is more likely used to perform conditional
5769 compilation using an @code{AC_SUBST} variable that contains a list of
5770 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5771 Sources}.
5773 The @code{EXTRA_*_DEPENDENCIES} variable may be useful for cases where
5774 you merely want to augment the @command{automake}-generated
5775 @code{_DEPENDENCIES} variable rather than replacing it.
5777 @item maude_LINK
5778 You can override the linker on a per-program basis.  By default the
5779 linker is chosen according to the languages used by the program.  For
5780 instance, a program that includes C++ source code would use the C++
5781 compiler to link.  The @code{_LINK} variable must hold the name of a
5782 command that can be passed all the @file{.o} file names and libraries
5783 to link against as arguments.  Note that the name of the underlying
5784 program is @emph{not} passed to @code{_LINK}; typically one uses
5785 @samp{$@@}:
5787 @example
5788 maude_LINK = $(CCLD) -magic -o $@@
5789 @end example
5791 If a @code{_LINK} variable is not supplied, it may still be generated
5792 and used by Automake due to the use of per-target link flags such as
5793 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5794 they apply.
5796 @item maude_CCASFLAGS
5797 @itemx maude_CFLAGS
5798 @itemx maude_CPPFLAGS
5799 @itemx maude_CXXFLAGS
5800 @itemx maude_FFLAGS
5801 @itemx maude_GCJFLAGS
5802 @itemx maude_LFLAGS
5803 @itemx maude_OBJCFLAGS
5804 @itemx maude_OBJCXXFLAGS
5805 @itemx maude_RFLAGS
5806 @itemx maude_UPCFLAGS
5807 @itemx maude_YFLAGS
5808 @cindex per-target compilation flags, defined
5809 Automake allows you to set compilation flags on a per-program (or
5810 per-library) basis.  A single source file can be included in several
5811 programs, and it will potentially be compiled with different flags for
5812 each program.  This works for any language directly supported by
5813 Automake.  These @dfn{per-target compilation flags} are
5814 @samp{_CCASFLAGS},
5815 @samp{_CFLAGS},
5816 @samp{_CPPFLAGS},
5817 @samp{_CXXFLAGS},
5818 @samp{_FFLAGS},
5819 @samp{_GCJFLAGS},
5820 @samp{_LFLAGS},
5821 @samp{_OBJCFLAGS},
5822 @samp{_OBJCXXFLAGS},
5823 @samp{_RFLAGS},
5824 @samp{_UPCFLAGS}, and
5825 @samp{_YFLAGS}.
5827 When using a per-target compilation flag, Automake will choose a
5828 different name for the intermediate object files.  Ordinarily a file
5829 like @file{sample.c} will be compiled to produce @file{sample.o}.
5830 However, if the program's @code{_CFLAGS} variable is set, then the
5831 object file will be named, for instance, @file{maude-sample.o}.  (See
5832 also @ref{Renamed Objects}).
5834 In compilations with per-target flags, the ordinary @samp{AM_} form of
5835 the flags variable is @emph{not} automatically included in the
5836 compilation (however, the user form of the variable @emph{is} included).
5837 So for instance, if you want the hypothetical @file{maude} compilations
5838 to also use the value of @code{AM_CFLAGS}, you would need to write:
5840 @example
5841 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5842 @end example
5844 @xref{Flag Variables Ordering}, for more discussion about the
5845 interaction between user variables, @samp{AM_} shadow variables, and
5846 per-target variables.
5848 @item maude_SHORTNAME
5849 On some platforms the allowable file names are very short.  In order to
5850 support these systems and per-target compilation flags at the same
5851 time, Automake allows you to set a ``short name'' that will influence
5852 how intermediate object files are named.  For instance, in the following
5853 example,
5855 @example
5856 bin_PROGRAMS = maude
5857 maude_CPPFLAGS = -DSOMEFLAG
5858 maude_SHORTNAME = m
5859 maude_SOURCES = sample.c @dots{}
5860 @end example
5862 @noindent
5863 the object file would be named @file{m-sample.o} rather than
5864 @file{maude-sample.o}.
5866 This facility is rarely needed in practice,
5867 and we recommend avoiding it until you find it is required.
5868 @end vtable
5870 @node Default _SOURCES
5871 @section Default @code{_SOURCES}
5873 @vindex _SOURCES
5874 @vindex SOURCES
5875 @cindex @code{_SOURCES}, default
5876 @cindex default @code{_SOURCES}
5877 @vindex AM_DEFAULT_SOURCE_EXT
5879 @code{_SOURCES} variables are used to specify source files of programs
5880 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5881 libraries (@pxref{A Shared Library}).
5883 When no such variable is specified for a target, Automake will define
5884 one itself.  The default is to compile a single C file whose base name
5885 is the name of the target itself, with any extension replaced by
5886 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5888 For example if you have the following somewhere in your
5889 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5891 @example
5892 lib_LIBRARIES = libfoo.a sub/libc++.a
5893 @end example
5895 @noindent
5896 @file{libfoo.a} will be built using a default source file named
5897 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5898 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5899 would be built from @file{sub_libc___a.c}, i.e., the default source
5900 was the canonized name of the target, with @file{.c} appended.
5901 We believe the new behavior is more sensible, but for backward
5902 compatibility @command{automake} will use the old name if a file or a rule
5903 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5905 @cindex @code{check_PROGRAMS} example
5906 @vindex check_PROGRAMS
5907 Default sources are mainly useful in test suites, when building many
5908 test programs each from a single source.  For instance, in
5910 @example
5911 check_PROGRAMS = test1 test2 test3
5912 AM_DEFAULT_SOURCE_EXT = .cpp
5913 @end example
5915 @noindent
5916 @file{test1}, @file{test2}, and @file{test3} will be built
5917 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5918 Without the last line, they will be built from @file{test1.c},
5919 @file{test2.c}, and @file{test3.c}.
5921 @cindex Libtool modules, default source example
5922 @cindex default source, Libtool modules example
5923 Another case where this is convenient is building many Libtool modules
5924 (@file{module@var{n}.la}), each defined in its own file
5925 (@file{module@var{n}.c}).
5927 @example
5928 AM_LDFLAGS = -module
5929 lib_LTLIBRARIES = module1.la module2.la module3.la
5930 @end example
5932 @cindex empty @code{_SOURCES}
5933 @cindex @code{_SOURCES}, empty
5934 Finally, there is one situation where this default source computation
5935 needs to be avoided: when a target should not be built from sources.
5936 We already saw such an example in @ref{true}; this happens when all
5937 the constituents of a target have already been compiled and just need
5938 to be combined using a @code{_LDADD} variable.  Then it is necessary
5939 to define an empty @code{_SOURCES} variable, so that @command{automake}
5940 does not compute a default.
5942 @example
5943 bin_PROGRAMS = target
5944 target_SOURCES =
5945 target_LDADD = libmain.a libmisc.a
5946 @end example
5948 @node LIBOBJS
5949 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5951 @cindex @code{LIBOBJS}, example
5952 @cindex @code{ALLOCA}, example
5953 @cindex @code{LIBOBJS}, special handling
5954 @cindex @code{ALLOCA}, special handling
5955 @vindex LTLIBOBJS
5956 @vindex LIBOBJS
5957 @vindex LTALLOCA
5958 @vindex ALLOCA
5960 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5961 files that should be compiled into the project to provide an
5962 implementation for functions that are missing or broken on the host
5963 system.  They are substituted by @file{configure}.
5965 @acindex AC_LIBOBJ
5967 These variables are defined by Autoconf macros such as
5968 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5969 Generic Function Checks, autoconf, The Autoconf Manual}), or
5970 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5971 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5972 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5973 populate @samp{$(LIBOBJS)}.
5975 @acindex AC_LIBSOURCE
5977 Using these variables is very similar to doing conditional compilation
5978 using @code{AC_SUBST} variables, as described in @ref{Conditional
5979 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5980 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5981 variable, or to the @samp{*_LIBADD} variable when building a library.
5982 However there is no need to list the corresponding sources in
5983 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5984 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5985 dependencies, and it will discover the list of corresponding source
5986 files automatically (by tracing the invocations of the
5987 @code{AC_LIBSOURCE} Autoconf macros).  If you have already defined
5988 @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then you
5989 either need to add these variables manually, or use
5990 @samp{EXTRA_*_DEPENDENCIES} instead of @samp{*_DEPENDENCIES}.
5992 These variables are usually used to build a portability library that
5993 is linked with all the programs of the project.  We now review a
5994 sample setup.  First, @file{configure.ac} contains some checks that
5995 affect either @code{LIBOBJS} or @code{ALLOCA}.
5997 @example
5998 # configure.ac
5999 @dots{}
6000 AC_CONFIG_LIBOBJ_DIR([lib])
6001 @dots{}
6002 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
6003 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
6004 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
6005 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
6006 @dots{}
6007 AC_CONFIG_FILES([
6008   lib/Makefile
6009   src/Makefile
6011 AC_OUTPUT
6012 @end example
6014 @acindex AC_CONFIG_LIBOBJ_DIR
6016 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
6017 of these object files are to be found in the @file{lib/} directory.
6018 Automake can also use this information, otherwise it expects the
6019 source files are to be in the directory where the @samp{$(LIBOBJS)}
6020 and @samp{$(ALLOCA)} variables are used.
6022 The @file{lib/} directory should therefore contain @file{malloc.c},
6023 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
6024 @file{Makefile.am}:
6026 @example
6027 # lib/Makefile.am
6029 noinst_LIBRARIES = libcompat.a
6030 libcompat_a_SOURCES =
6031 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
6032 @end example
6034 The library can have any name, of course, and anyway it is not going
6035 to be installed: it just holds the replacement versions of the missing
6036 or broken functions so we can later link them in.  Many projects
6037 also include extra functions, specific to the project, in that
6038 library: they are simply added on the @code{_SOURCES} line.
6040 @cindex Empty libraries and @samp{$(LIBOBJS)}
6041 @cindex @samp{$(LIBOBJS)} and empty libraries
6042 There is a small trap here, though: @samp{$(LIBOBJS)} and
6043 @samp{$(ALLOCA)} might be empty, and building an empty library is not
6044 portable.  You should ensure that there is always something to put in
6045 @file{libcompat.a}.  Most projects will also add some utility
6046 functions in that directory, and list them in
6047 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
6048 be empty.
6050 Finally here is how this library could be used from the @file{src/}
6051 directory.
6053 @example
6054 # src/Makefile.am
6056 # Link all programs in this directory with libcompat.a
6057 LDADD = ../lib/libcompat.a
6059 bin_PROGRAMS = tool1 tool2 @dots{}
6060 tool1_SOURCES = @dots{}
6061 tool2_SOURCES = @dots{}
6062 @end example
6064 When option @option{subdir-objects} is not used, as in the above
6065 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
6066 be used in the directory where their sources lie.  E.g., here it would
6067 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
6068 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
6069 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
6070 in other directories.  For instance @file{src/Makefile.am} could be
6071 changed as follows.
6073 @example
6074 # src/Makefile.am
6076 AUTOMAKE_OPTIONS = subdir-objects
6077 LDADD = $(LIBOBJS) $(ALLOCA)
6079 bin_PROGRAMS = tool1 tool2 @dots{}
6080 tool1_SOURCES = @dots{}
6081 tool2_SOURCES = @dots{}
6082 @end example
6084 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
6085 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
6086 Libtool libraries (where the expected object extension is @file{.lo}):
6087 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
6089 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
6090 be defined by hand (as in the past), however at the time of writing
6091 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6092 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6093 autoconf, The Autoconf Manual}.
6096 @node Program Variables
6097 @section Variables used when building a program
6099 Occasionally it is useful to know which @file{Makefile} variables
6100 Automake uses for compilations, and in which order (@pxref{Flag
6101 Variables Ordering}); for instance, you might need to do your own
6102 compilation in some special cases.
6104 Some variables are inherited from Autoconf; these are @code{CC},
6105 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6106 @code{LIBS}.
6107 @vindex CC
6108 @vindex CFLAGS
6109 @vindex CPPFLAGS
6110 @vindex DEFS
6111 @vindex LDFLAGS
6112 @vindex LIBS
6114 There are some additional variables that Automake defines on its own:
6116 @vtable @code
6117 @item AM_CPPFLAGS
6118 The contents of this variable are passed to every compilation that invokes
6119 the C preprocessor; it is a list of arguments to the preprocessor.  For
6120 instance, @option{-I} and @option{-D} options should be listed here.
6122 Automake already provides some @option{-I} options automatically, in a
6123 separate variable that is also passed to every compilation that invokes
6124 the C preprocessor.  In particular it generates @samp{-I.},
6125 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6126 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS}).  You can
6127 disable the default @option{-I} options using the @option{nostdinc}
6128 option.
6130 When a file to be included is generated during the build and not part
6131 of a distribution tarball, its location is under @code{$(builddir)},
6132 not under @code{$(srcdir)}.  This matters especially for packages that
6133 use header files placed in sub-directories and want to allow builds
6134 outside the source tree (@pxref{VPATH Builds}). In that case we
6135 recommend to use a pair of @option{-I} options, such as, e.g.,
6136 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6137 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6138 Note that the reference to the build tree should come before the
6139 reference to the source tree, so that accidentally leftover generated
6140 files in the source directory are ignored.
6142 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6143 per-library) @code{_CPPFLAGS} variable if it is defined.
6145 @item INCLUDES
6146 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6147 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
6148 same functionality.  This variable is deprecated; we suggest using
6149 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6151 @item AM_CFLAGS
6152 This is the variable the @file{Makefile.am} author can use to pass
6153 in additional C compiler flags.  In some situations, this is
6154 not used, in preference to the per-executable (or per-library)
6155 @code{_CFLAGS}.
6157 @item COMPILE
6158 This is the command used to actually compile a C source file.  The
6159 file name is appended to form the complete command line.
6161 @item AM_LDFLAGS
6162 This is the variable the @file{Makefile.am} author can use to pass
6163 in additional linker flags.  In some situations, this is not used, in
6164 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6166 @item LINK
6167 This is the command used to actually link a C program.  It already
6168 includes @samp{-o $@@} and the usual variable references (for instance,
6169 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
6170 and libraries to link in.  This variable is not used when the linker is
6171 overridden with a per-target @code{_LINK} variable or per-target flags
6172 cause Automake to define such a @code{_LINK} variable.
6173 @end vtable
6176 @node Yacc and Lex
6177 @section Yacc and Lex support
6179 Automake has somewhat idiosyncratic support for Yacc and Lex.
6181 Automake assumes that the @file{.c} file generated by @command{yacc}
6182 (or @command{lex}) should be named using the basename of the input
6183 file.  That is, for a yacc source file @file{foo.y}, Automake will
6184 cause the intermediate file to be named @file{foo.c} (as opposed to
6185 @file{y.tab.c}, which is more traditional).
6187 The extension of a yacc source file is used to determine the extension
6188 of the resulting C or C++ source and header files.  Note that header
6189 files are generated only when the @option{-d} Yacc option is used; see
6190 below for more information about this flag, and how to specify it.
6191 Files with the extension @file{.y} will thus be turned into @file{.c}
6192 sources and @file{.h} headers; likewise, @file{.yy} will become
6193 @file{.cc} and @file{.hh}, @file{.y++} will become @file{c++} and
6194 @file{h++}, @file{.yxx} will become @file{.cxx} and @file{.hxx},
6195 and @file{.ypp} will become @file{.cpp} and @file{.hpp}.
6197 Similarly, lex source files can be used to generate C or C++; the
6198 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6199 @file{.lpp} are recognized.
6201 You should never explicitly mention the intermediate (C or C++) file
6202 in any @code{SOURCES} variable; only list the source file.
6204 The intermediate files generated by @command{yacc} (or @command{lex})
6205 will be included in any distribution that is made.  That way the user
6206 doesn't need to have @command{yacc} or @command{lex}.
6208 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6209 define the variable @code{YACC}.  This is most easily done by invoking
6210 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6211 Program Checks, autoconf, The Autoconf Manual}).
6213 @vindex YFLAGS
6214 @vindex AM_YFLAGS
6215 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6216 @code{YFLAGS}.  The latter is a user variable and the former is
6217 intended for the @file{Makefile.am} author.
6219 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6220 @command{yacc}.  Automake knows what this means and will automatically
6221 adjust its rules to update and distribute the header file built by
6222 @samp{yacc -d}@footnote{Please note that @command{automake} recognizes
6223 @option{-d} in @code{AM_YFLAGS} only if it is not clustered with other
6224 options; for example, it won't be recognized if @code{AM_YFLAGS} is
6225 @option{-dt}, but it will be if @code{AM_YFLAGS} is @option{-d -t} or
6226 @option{-t -d}.}.
6227 What Automake cannot guess, though, is where this
6228 header will be used: it is up to you to ensure the header gets built
6229 before it is first used.  Typically this is necessary in order for
6230 dependency tracking to work when the header is included by another
6231 file.  The common solution is listing the header file in
6232 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6234 @example
6235 BUILT_SOURCES = parser.h
6236 AM_YFLAGS = -d
6237 bin_PROGRAMS = foo
6238 foo_SOURCES = @dots{} parser.y @dots{}
6239 @end example
6241 If a @command{lex} source file is seen, then your @file{configure.ac}
6242 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6243 to do this (@pxref{Particular Programs, , Particular Program Checks,
6244 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6245 (@pxref{Macros}) is recommended.
6247 @vindex LFLAGS
6248 @vindex AM_LFLAGS
6249 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6250 @code{LFLAGS}.  The latter is a user variable and the former is
6251 intended for the @file{Makefile.am} author.
6253 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6254 rebuild rule for distributed Yacc and Lex sources are only used when
6255 @code{maintainer-mode} is enabled, or when the files have been erased.
6257 @cindex @command{ylwrap}
6258 @cindex @command{yacc}, multiple parsers
6259 @cindex Multiple @command{yacc} parsers
6260 @cindex Multiple @command{lex} lexers
6261 @cindex @command{lex}, multiple lexers
6263 When @command{lex} or @command{yacc} sources are used, @code{automake -a}
6264 automatically installs an auxiliary program called @command{ylwrap} in
6265 your package (@pxref{Auxiliary Programs}).
6266 This program is used by the build rules to rename the output of these
6267 tools, and makes it possible to include multiple @command{yacc} (or
6268 @command{lex}) source files in a single directory.  (This is necessary
6269 because yacc's output file name is fixed, and a parallel make could
6270 conceivably invoke more than one instance of @command{yacc}
6271 simultaneously.)
6273 For @command{yacc}, simply managing locking is insufficient.  The output of
6274 @command{yacc} always uses the same symbol names internally, so it isn't
6275 possible to link two @command{yacc} parsers into the same executable.
6277 We recommend using the following renaming hack used in @command{gdb}:
6278 @example
6279 #define yymaxdepth c_maxdepth
6280 #define yyparse c_parse
6281 #define yylex   c_lex
6282 #define yyerror c_error
6283 #define yylval  c_lval
6284 #define yychar  c_char
6285 #define yydebug c_debug
6286 #define yypact  c_pact
6287 #define yyr1    c_r1
6288 #define yyr2    c_r2
6289 #define yydef   c_def
6290 #define yychk   c_chk
6291 #define yypgo   c_pgo
6292 #define yyact   c_act
6293 #define yyexca  c_exca
6294 #define yyerrflag c_errflag
6295 #define yynerrs c_nerrs
6296 #define yyps    c_ps
6297 #define yypv    c_pv
6298 #define yys     c_s
6299 #define yy_yys  c_yys
6300 #define yystate c_state
6301 #define yytmp   c_tmp
6302 #define yyv     c_v
6303 #define yy_yyv  c_yyv
6304 #define yyval   c_val
6305 #define yylloc  c_lloc
6306 #define yyreds  c_reds
6307 #define yytoks  c_toks
6308 #define yylhs   c_yylhs
6309 #define yylen   c_yylen
6310 #define yydefred c_yydefred
6311 #define yydgoto  c_yydgoto
6312 #define yysindex c_yysindex
6313 #define yyrindex c_yyrindex
6314 #define yygindex c_yygindex
6315 #define yytable  c_yytable
6316 #define yycheck  c_yycheck
6317 #define yyname   c_yyname
6318 #define yyrule   c_yyrule
6319 @end example
6321 For each define, replace the @samp{c_} prefix with whatever you like.
6322 These defines work for @command{bison}, @command{byacc}, and
6323 traditional @code{yacc}s.  If you find a parser generator that uses a
6324 symbol not covered here, please report the new name so it can be added
6325 to the list.
6328 @node C++ Support
6329 @section C++ Support
6331 @cindex C++ support
6332 @cindex Support for C++
6334 Automake includes full support for C++.
6336 Any package including C++ code must define the output variable
6337 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6338 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6339 Program Checks, autoconf, The Autoconf Manual}).
6341 A few additional variables are defined when a C++ source file is seen:
6343 @vtable @code
6344 @item CXX
6345 The name of the C++ compiler.
6347 @item CXXFLAGS
6348 Any flags to pass to the C++ compiler.
6350 @item AM_CXXFLAGS
6351 The maintainer's variant of @code{CXXFLAGS}.
6353 @item CXXCOMPILE
6354 The command used to actually compile a C++ source file.  The file name
6355 is appended to form the complete command line.
6357 @item CXXLINK
6358 The command used to actually link a C++ program.
6359 @end vtable
6362 @node Objective C Support
6363 @section Objective C Support
6365 @cindex Objective C support
6366 @cindex Support for Objective C
6368 Automake includes some support for Objective C.
6370 Any package including Objective C code must define the output variable
6371 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6372 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6373 Program Checks, autoconf, The Autoconf Manual}).
6375 A few additional variables are defined when an Objective C source file
6376 is seen:
6378 @vtable @code
6379 @item OBJC
6380 The name of the Objective C compiler.
6382 @item OBJCFLAGS
6383 Any flags to pass to the Objective C compiler.
6385 @item AM_OBJCFLAGS
6386 The maintainer's variant of @code{OBJCFLAGS}.
6388 @item OBJCCOMPILE
6389 The command used to actually compile an Objective C source file.  The
6390 file name is appended to form the complete command line.
6392 @item OBJCLINK
6393 The command used to actually link an Objective C program.
6394 @end vtable
6397 @node Objective C++ Support
6398 @section Objective C++ Support
6400 @cindex Objective C++ support
6401 @cindex Support for Objective C++
6403 Automake includes some support for Objective C++.
6405 Any package including Objective C++ code must define the output variable
6406 @code{OBJCXX} in @file{configure.ac}; the simplest way to do this is to use
6407 the @code{AC_PROG_OBJCXX} macro (@pxref{Particular Programs, , Particular
6408 Program Checks, autoconf, The Autoconf Manual}).
6410 A few additional variables are defined when an Objective C++ source file
6411 is seen:
6413 @vtable @code
6414 @item OBJCXX
6415 The name of the Objective C++ compiler.
6417 @item OBJCXXFLAGS
6418 Any flags to pass to the Objective C++ compiler.
6420 @item AM_OBJCXXFLAGS
6421 The maintainer's variant of @code{OBJCXXFLAGS}.
6423 @item OBJCXXCOMPILE
6424 The command used to actually compile an Objective C++ source file.  The
6425 file name is appended to form the complete command line.
6427 @item OBJCXXLINK
6428 The command used to actually link an Objective C++ program.
6429 @end vtable
6432 @node Unified Parallel C Support
6433 @section Unified Parallel C Support
6435 @cindex Unified Parallel C support
6436 @cindex Support for Unified Parallel C
6438 Automake includes some support for Unified Parallel C.
6440 Any package including Unified Parallel C code must define the output
6441 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6442 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6444 A few additional variables are defined when a Unified Parallel C
6445 source file is seen:
6447 @vtable @code
6448 @item UPC
6449 The name of the Unified Parallel C compiler.
6451 @item UPCFLAGS
6452 Any flags to pass to the Unified Parallel C compiler.
6454 @item AM_UPCFLAGS
6455 The maintainer's variant of @code{UPCFLAGS}.
6457 @item UPCCOMPILE
6458 The command used to actually compile a Unified Parallel C source file.
6459 The file name is appended to form the complete command line.
6461 @item UPCLINK
6462 The command used to actually link a Unified Parallel C program.
6463 @end vtable
6466 @node Assembly Support
6467 @section Assembly Support
6469 Automake includes some support for assembly code.  There are two forms
6470 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6471 (@file{*.S} or @file{*.sx}).
6473 @vindex CCAS
6474 @vindex CCASFLAGS
6475 @vindex CPPFLAGS
6476 @vindex AM_CCASFLAGS
6477 @vindex AM_CPPFLAGS
6478 The variable @code{CCAS} holds the name of the compiler used to build
6479 assembly code.  This compiler must work a bit like a C compiler; in
6480 particular it must accept @option{-c} and @option{-o}.  The values of
6481 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6482 definition) is passed to the compilation.  For preprocessed files,
6483 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6484 and @code{AM_CPPFLAGS} are also used.
6486 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6487 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6488 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6489 flags), but you are free to define these variables by other means.
6491 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6492 @command{automake} as being files containing assembly code.
6495 @node Fortran 77 Support
6496 @comment  node-name,  next,  previous,  up
6497 @section Fortran 77 Support
6499 @cindex Fortran 77 support
6500 @cindex Support for Fortran 77
6502 Automake includes full support for Fortran 77.
6504 Any package including Fortran 77 code must define the output variable
6505 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6506 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6507 Program Checks, autoconf, The Autoconf Manual}).
6509 A few additional variables are defined when a Fortran 77 source file is
6510 seen:
6512 @vtable @code
6514 @item F77
6515 The name of the Fortran 77 compiler.
6517 @item FFLAGS
6518 Any flags to pass to the Fortran 77 compiler.
6520 @item AM_FFLAGS
6521 The maintainer's variant of @code{FFLAGS}.
6523 @item RFLAGS
6524 Any flags to pass to the Ratfor compiler.
6526 @item AM_RFLAGS
6527 The maintainer's variant of @code{RFLAGS}.
6529 @item F77COMPILE
6530 The command used to actually compile a Fortran 77 source file.  The file
6531 name is appended to form the complete command line.
6533 @item FLINK
6534 The command used to actually link a pure Fortran 77 program or shared
6535 library.
6537 @end vtable
6539 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6540 addition to compiling them@footnote{Much, if not most, of the
6541 information in the following sections pertaining to preprocessing
6542 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6543 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6544 also contains some support for creating programs and shared libraries
6545 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6546 Fortran 77 With C and C++}).
6548 These issues are covered in the following sections.
6550 @menu
6551 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6552 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6553 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6554 @end menu
6557 @node Preprocessing Fortran 77
6558 @comment  node-name,  next,  previous,  up
6559 @subsection Preprocessing Fortran 77
6561 @cindex Preprocessing Fortran 77
6562 @cindex Fortran 77, Preprocessing
6563 @cindex Ratfor programs
6565 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6566 rule runs just the preprocessor to convert a preprocessable Fortran 77
6567 or Ratfor source file into a strict Fortran 77 source file.  The precise
6568 command used is as follows:
6570 @table @file
6572 @item .F
6573 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6574 $(AM_FFLAGS) $(FFLAGS)}
6576 @item .r
6577 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6579 @end table
6582 @node Compiling Fortran 77 Files
6583 @comment  node-name,  next,  previous,  up
6584 @subsection Compiling Fortran 77 Files
6586 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6587 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6588 is as follows:
6590 @table @file
6592 @item .f
6593 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6595 @item .F
6596 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6597 $(AM_FFLAGS) $(FFLAGS)}
6599 @item .r
6600 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6602 @end table
6605 @node Mixing Fortran 77 With C and C++
6606 @comment  node-name,  next,  previous,  up
6607 @subsection Mixing Fortran 77 With C and C++
6609 @cindex Fortran 77, mixing with C and C++
6610 @cindex Mixing Fortran 77 with C and C++
6611 @cindex Linking Fortran 77 with C and C++
6612 @cindex cfortran
6613 @cindex Mixing Fortran 77 with C and/or C++
6615 Automake currently provides @emph{limited} support for creating programs
6616 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6617 However, there are many other issues related to mixing Fortran 77 with
6618 other languages that are @emph{not} (currently) handled by Automake, but
6619 that are handled by other packages@footnote{For example,
6620 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6621 addresses all of these inter-language issues, and runs under nearly all
6622 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6623 @command{cfortran} is not yet Free Software, but it will be in the next
6624 major release.}.
6626 Automake can help in two ways:
6628 @enumerate
6629 @item
6630 Automatic selection of the linker depending on which combinations of
6631 source code.
6633 @item
6634 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6635 @option{-l}) to pass to the automatically selected linker in order to link
6636 in the appropriate Fortran 77 intrinsic and run-time libraries.
6638 @cindex @code{FLIBS}, defined
6639 @vindex FLIBS
6640 These extra Fortran 77 linker flags are supplied in the output variable
6641 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro.
6642 @xref{Fortran Compiler, , Fortran Compiler Characteristics, autoconf,
6643 The Autoconf Manual}.
6644 @end enumerate
6646 If Automake detects that a program or shared library (as mentioned in
6647 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6648 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6649 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6650 @file{configure.ac}, and that either @code{$(FLIBS)}
6651 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6652 (for shared libraries) variables.  It is the responsibility of the
6653 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6654 appears in the appropriate @code{_LDADD} or
6655 @code{_LIBADD} variable.
6657 @cindex Mixed language example
6658 @cindex Example, mixed language
6660 For example, consider the following @file{Makefile.am}:
6662 @example
6663 bin_PROGRAMS = foo
6664 foo_SOURCES  = main.cc foo.f
6665 foo_LDADD    = libfoo.la $(FLIBS)
6667 pkglib_LTLIBRARIES = libfoo.la
6668 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6669 libfoo_la_LIBADD   = $(FLIBS)
6670 @end example
6672 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6673 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6674 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6675 Automake would have issued a warning.
6677 @menu
6678 * How the Linker is Chosen::    Automatic linker selection
6679 @end menu
6681 @node How the Linker is Chosen
6682 @comment  node-name,  next,  previous,  up
6683 @subsubsection How the Linker is Chosen
6685 @cindex Automatic linker selection
6686 @cindex Selecting the linker automatically
6688 When a program or library mixes several languages, Automake choose the
6689 linker according to the following priorities.  (The names in
6690 parentheses are the variables containing the link command.)
6692 @enumerate
6693 @item
6694 @vindex GCJLINK
6695 Native Java (@code{GCJLINK})
6696 @item
6697 @vindex OBJCXXLINK
6698 Objective C++ (@code{OBJCXXLINK})
6699 @item
6700 @vindex CXXLINK
6701 C++ (@code{CXXLINK})
6702 @item
6703 @vindex F77LINK
6704 Fortran 77 (@code{F77LINK})
6705 @item
6706 @vindex FCLINK
6707 Fortran (@code{FCLINK})
6708 @item
6709 @vindex OBJCLINK
6710 Objective C (@code{OBJCLINK})
6711 @item
6712 @vindex UPCLINK
6713 Unified Parallel C (@code{UPCLINK})
6714 @item
6715 @vindex LINK
6716 C (@code{LINK})
6717 @end enumerate
6719 For example, if Fortran 77, C and C++ source code is compiled
6720 into a program, then the C++ linker will be used.  In this case, if the
6721 C or Fortran 77 linkers required any special libraries that weren't
6722 included by the C++ linker, then they must be manually added to an
6723 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6724 @file{Makefile.am}.
6726 Automake only looks at the file names listed in @file{_SOURCES}
6727 variables to choose the linker, and defaults to the C linker.
6728 Sometimes this is inconvenient because you are linking against a
6729 library written in another language and would like to set the linker
6730 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6731 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6733 A per-target @code{_LINK} variable will override the above selection.
6734 Per-target link flags will cause Automake to write a per-target
6735 @code{_LINK} variable according to the language chosen as above.
6738 @node Fortran 9x Support
6739 @comment  node-name,  next,  previous,  up
6740 @section Fortran 9x Support
6742 @cindex Fortran 9x support
6743 @cindex Support for Fortran 9x
6745 Automake includes support for Fortran 9x.
6747 Any package including Fortran 9x code must define the output variable
6748 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6749 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6750 Program Checks, autoconf, The Autoconf Manual}).
6752 A few additional variables are defined when a Fortran 9x source file is
6753 seen:
6755 @vtable @code
6757 @item FC
6758 The name of the Fortran 9x compiler.
6760 @item FCFLAGS
6761 Any flags to pass to the Fortran 9x compiler.
6763 @item AM_FCFLAGS
6764 The maintainer's variant of @code{FCFLAGS}.
6766 @item FCCOMPILE
6767 The command used to actually compile a Fortran 9x source file.  The file
6768 name is appended to form the complete command line.
6770 @item FCLINK
6771 The command used to actually link a pure Fortran 9x program or shared
6772 library.
6774 @end vtable
6776 @menu
6777 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6778 @end menu
6780 @node Compiling Fortran 9x Files
6781 @comment  node-name,  next,  previous,  up
6782 @subsection Compiling Fortran 9x Files
6784 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6785 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6786 by running the Fortran 9x compiler.  The precise command used
6787 is as follows:
6789 @table @file
6791 @item .f90
6792 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6794 @item .f95
6795 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6797 @item .f03
6798 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6800 @item .f08
6801 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6803 @end table
6805 @node Java Support with gcj
6806 @comment  node-name,  next,  previous,  up
6807 @section Compiling Java sources using gcj
6809 @cindex Java support with gcj
6810 @cindex Support for Java with gcj
6811 @cindex Java to native code, compilation
6812 @cindex Compilation of Java to native code
6814 Automake includes support for natively compiled Java, using @command{gcj},
6815 the Java front end to the GNU Compiler Collection (rudimentary support
6816 for compiling Java to bytecode using the @command{javac} compiler is
6817 also present, @emph{albeit deprecated}; @pxref{Java}).
6819 Any package including Java code to be compiled must define the output
6820 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6821 must also be defined somehow (either in @file{configure.ac} or
6822 @file{Makefile.am}).  The simplest way to do this is to use the
6823 @code{AM_PROG_GCJ} macro.
6825 @vindex GCJFLAGS
6827 By default, programs including Java source files are linked with
6828 @command{gcj}.
6830 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6831 compilation invoking @command{gcj} (in its role as an ahead-of-time
6832 compiler, when invoking it to create @file{.class} files,
6833 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6834 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6835 the user variable @code{GCJFLAGS}, should be used.
6837 @vindex AM_GCJFLAGS
6839 @command{gcj} can be used to compile @file{.java}, @file{.class},
6840 @file{.zip}, or @file{.jar} files.
6842 When linking, @command{gcj} requires that the main class be specified
6843 using the @option{--main=} option.  The easiest way to do this is to use
6844 the @code{_LDFLAGS} variable for the program.
6847 @node Vala Support
6848 @comment  node-name,  next,  previous,  up
6849 @section Vala Support
6851 @cindex Vala Support
6852 @cindex Support for Vala
6854 Automake provides initial support for Vala
6855 (@uref{http://www.vala-project.org/}).
6856 This requires valac version 0.7.0 or later, and currently requires
6857 the user to use GNU @command{make}.
6859 @example
6860 foo_SOURCES = foo.vala bar.vala zardoc.c
6861 @end example
6863 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6864 compiled into C code by the Vala compiler. The generated @file{.c} files
6865 are distributed. The end user does not need to have a Vala compiler installed.
6867 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6868 that will locate the Vala compiler and optionally check its version
6869 number.
6871 @defmac AM_PROG_VALAC (@ovar{minimum-version}, @ovar{action-if-found},
6872   @ovar{action-if-not-found})
6873 Search for a Vala compiler in @env{PATH}.  If it is found, the variable
6874 @code{VALAC} is set to point to it (see below for more details).  This
6875 macro takes three optional arguments.  The first argument, if present,
6876 is the minimum version of the Vala compiler required to compile this
6877 package.  If a compiler is found and satisfies @var{minimum-version},
6878 then @var{action-if-found} is run (this defaults to do nothing).
6879 Otherwise, @var{action-if-not-found} is run.  If @var{action-if-not-found}
6880 is not specified, the default value is to print a warning in case no
6881 compiler is found, or if a too-old version of the compiler is found.
6882 @end defmac
6884 There are a few variables that are used when compiling Vala sources:
6886 @vtable @code
6887 @item VALAC
6888 Absolute path to the Vala compiler, or simply @samp{valac} if no
6889 suitable compiler Vala could be found at configure runtime.
6891 @item VALAFLAGS
6892 Additional arguments for the Vala compiler.
6894 @item AM_VALAFLAGS
6895 The maintainer's variant of @code{VALAFLAGS}.
6897 @example
6898 lib_LTLIBRARIES = libfoo.la
6899 libfoo_la_SOURCES = foo.vala
6900 @end example
6901 @end vtable
6903 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
6904 (@pxref{Renamed Objects}) to produce different C files from one Vala
6905 source file.
6908 @node Support for Other Languages
6909 @comment  node-name,  next,  previous,  up
6910 @section Support for Other Languages
6912 Automake currently only includes full support for C, C++ (@pxref{C++
6913 Support}), Objective C (@pxref{Objective C Support}),
6914 Objective C++ (@pxref{Objective C++ Support}),
6915 Fortran 77
6916 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6917 and Java (@pxref{Java Support with gcj}).  There is only rudimentary
6918 support for other languages, support for which will be improved based
6919 on user demand.
6921 Some limited support for adding your own languages is available via the
6922 suffix rule handling (@pxref{Suffixes}).
6924 @node Dependencies
6925 @section Automatic dependency tracking
6927 As a developer it is often painful to continually update the
6928 @file{Makefile.am} whenever the include-file dependencies change in a
6929 project.  Automake supplies a way to automatically track dependency
6930 changes (@pxref{Dependency Tracking}).
6932 @cindex Dependency tracking
6933 @cindex Automatic dependency tracking
6935 Automake always uses complete dependencies for a compilation,
6936 including system headers.  Automake's model is that dependency
6937 computation should be a side effect of the build.  To this end,
6938 dependencies are computed by running all compilations through a
6939 special wrapper program called @command{depcomp}.  @command{depcomp}
6940 understands how to coax many different C and C++ compilers into
6941 generating dependency information in the format it requires.
6942 @samp{automake -a} will install @command{depcomp} into your source
6943 tree for you.  If @command{depcomp} can't figure out how to properly
6944 invoke your compiler, dependency tracking will simply be disabled for
6945 your build.
6947 @cindex @command{depcomp}
6949 Experience with earlier versions of Automake (@pxref{Dependency Tracking
6950 Evolution, , Dependency Tracking Evolution, automake-history, Brief History
6951 of Automake}) taught us that it is not reliable to generate dependencies
6952 only on the maintainer's system, as configurations vary too much.  So
6953 instead Automake implements dependency tracking at build time.
6955 Automatic dependency tracking can be suppressed by putting
6956 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6957 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6958 (this should be the preferred way).  Or, you can invoke @command{automake}
6959 with the @option{-i} option.  Dependency tracking is enabled by default.
6961 @vindex AUTOMAKE_OPTIONS
6962 @opindex no-dependencies
6964 The person building your package also can choose to disable dependency
6965 tracking by configuring with @option{--disable-dependency-tracking}.
6967 @cindex Disabling dependency tracking
6968 @cindex Dependency tracking, disabling
6971 @node EXEEXT
6972 @section Support for executable extensions
6974 @cindex Executable extension
6975 @cindex Extension, executable
6976 @cindex Windows
6978 On some platforms, such as Windows, executables are expected to have an
6979 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6980 among them) will automatically generate @file{foo.exe} when asked to
6981 generate @file{foo}.
6983 Automake provides mostly-transparent support for this.  Unfortunately
6984 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6985 dictionary is revised, you will have to assist Automake if your package
6986 must support those platforms.
6988 One thing you must be aware of is that, internally, Automake rewrites
6989 something like this:
6991 @example
6992 bin_PROGRAMS = liver
6993 @end example
6995 to this:
6997 @example
6998 bin_PROGRAMS = liver$(EXEEXT)
6999 @end example
7001 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
7002 extension.
7004 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests})
7005 are also rewritten if they contain filenames that have been declared as
7006 programs in the same @file{Makefile}.  (This is mostly useful when some
7007 programs from @code{check_PROGRAMS} are listed in @code{TESTS}.)
7009 However, Automake cannot apply this rewriting to @command{configure}
7010 substitutions.  This means that if you are conditionally building a
7011 program using such a substitution, then your @file{configure.ac} must
7012 take care to add @samp{$(EXEEXT)} when constructing the output variable.
7014 Sometimes maintainers like to write an explicit link rule for their
7015 program.  Without executable extension support, this is easy---you
7016 simply write a rule whose target is the name of the program.  However,
7017 when executable extension support is enabled, you must instead add the
7018 @samp{$(EXEEXT)} suffix.
7020 This might be a nuisance for maintainers who know their package will
7021 never run on a platform that has
7022 executable extensions.  For those maintainers, the @option{no-exeext}
7023 option (@pxref{Options}) will disable this feature.  This works in a
7024 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
7025 rule for a target named @code{foo} in @file{Makefile.am} will override
7026 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
7027 the @option{no-exeext} option, this use will give a diagnostic.
7030 @node Other Objects
7031 @chapter Other Derived Objects
7033 Automake can handle derived objects that are not C programs.  Sometimes
7034 the support for actually building such objects must be explicitly
7035 supplied, but Automake will still automatically handle installation and
7036 distribution.
7038 @menu
7039 * Scripts::                     Executable scripts
7040 * Headers::                     Header files
7041 * Data::                        Architecture-independent data files
7042 * Sources::                     Derived sources
7043 @end menu
7046 @node Scripts
7047 @section Executable Scripts
7049 @cindex @code{_SCRIPTS} primary, defined
7050 @cindex @code{SCRIPTS} primary, defined
7051 @cindex Primary variable, @code{SCRIPTS}
7052 @vindex _SCRIPTS
7053 @cindex Installing scripts
7055 It is possible to define and install programs that are scripts.  Such
7056 programs are listed using the @code{SCRIPTS} primary name.  When the
7057 script is distributed in its final, installable form, the
7058 @file{Makefile} usually looks as follows:
7059 @vindex SCRIPTS
7061 @example
7062 # Install my_script in $(bindir) and distribute it.
7063 dist_bin_SCRIPTS = my_script
7064 @end example
7066 Scripts are not distributed by default; as we have just seen, those
7067 that should be distributed can be specified using a @code{dist_}
7068 prefix as with other primaries.
7070 @cindex @code{SCRIPTS}, installation directories
7071 @vindex bin_SCRIPTS
7072 @vindex sbin_SCRIPTS
7073 @vindex libexec_SCRIPTS
7074 @vindex pkgdata_SCRIPTS
7075 @vindex pkglibexec_SCRIPTS
7076 @vindex noinst_SCRIPTS
7077 @vindex check_SCRIPTS
7079 Scripts can be installed in @code{bindir}, @code{sbindir},
7080 @code{libexecdir}, @code{pkglibexecdir}, or @code{pkgdatadir}.
7082 Scripts that need not be installed can be listed in
7083 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7084 @samp{make check} should go in @code{check_SCRIPTS}.
7086 When a script needs to be built, the @file{Makefile.am} should include
7087 the appropriate rules.  For instance the @command{automake} program
7088 itself is a Perl script that is generated from @file{automake.in}.
7089 Here is how this is handled:
7091 @example
7092 bin_SCRIPTS = automake
7093 CLEANFILES = $(bin_SCRIPTS)
7094 EXTRA_DIST = automake.in
7096 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7097             -e 's,[@@]PERL[@@],$(PERL),g' \
7098             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7099             -e 's,[@@]VERSION[@@],$(VERSION),g' \
7100             @dots{}
7102 automake: automake.in Makefile
7103         $(do_subst) < $(srcdir)/automake.in > automake
7104         chmod +x automake
7105 @end example
7107 Such scripts for which a build rule has been supplied need to be
7108 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7109 sources have to be distributed, usually with @code{EXTRA_DIST}
7110 (@pxref{Basics of Distribution}).
7112 Another common way to build scripts is to process them from
7113 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
7114 Automake knows which files should be cleaned and distributed, and what
7115 the rebuild rules should look like.
7117 For instance if @file{configure.ac} contains
7119 @example
7120 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7121 @end example
7123 @noindent
7124 to build @file{src/my_script} from @file{src/my_script.in}, then a
7125 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7126 be as simple as
7128 @example
7129 bin_SCRIPTS = my_script
7130 CLEANFILES = $(bin_SCRIPTS)
7131 @end example
7133 @noindent
7134 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7135 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7136 @code{CLEANFILES} is still useful, because by default Automake will
7137 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7138 @code{clean}.
7140 Although this looks simpler, building scripts this way has one
7141 drawback: directory variables such as @code{$(datadir)} are not fully
7142 expanded and may refer to other directory variables.
7144 @node Headers
7145 @section Header files
7147 @cindex @code{_HEADERS} primary, defined
7148 @cindex @code{HEADERS} primary, defined
7149 @cindex Primary variable, @code{HEADERS}
7150 @vindex _HEADERS
7151 @vindex noinst_HEADERS
7152 @cindex @code{HEADERS}, installation directories
7153 @cindex Installing headers
7154 @vindex include_HEADERS
7155 @vindex oldinclude_HEADERS
7156 @vindex pkginclude_HEADERS
7159 Header files that must be installed are specified by the
7160 @code{HEADERS} family of variables.  Headers can be installed in
7161 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7162 other directory you may have defined (@pxref{Uniform}).  For instance,
7164 @example
7165 include_HEADERS = foo.h bar/bar.h
7166 @end example
7168 @noindent
7169 will install the two files as @file{$(includedir)/foo.h} and
7170 @file{$(includedir)/bar.h}.
7172 The @code{nobase_} prefix is also supported,
7174 @example
7175 nobase_include_HEADERS = foo.h bar/bar.h
7176 @end example
7178 @noindent
7179 will install the two files as @file{$(includedir)/foo.h} and
7180 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7182 @vindex noinst_HEADERS
7183 Usually, only header files that accompany installed libraries need to
7184 be installed.  Headers used by programs or convenience libraries are
7185 not installed.  The @code{noinst_HEADERS} variable can be used for
7186 such headers.  However when the header actually belongs to a single
7187 convenience library or program, we recommend listing it in the
7188 program's or library's @code{_SOURCES} variable (@pxref{Program
7189 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7190 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7191 right variable to use in a directory containing only headers and no
7192 associated library or program.
7194 All header files must be listed somewhere; in a @code{_SOURCES}
7195 variable or in a @code{_HEADERS} variable.  Missing ones will not
7196 appear in the distribution.
7198 For header files that are built and must not be distributed, use the
7199 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7200 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7201 during the build, you must also ensure they exist before they are
7202 used (@pxref{Sources}).
7205 @node Data
7206 @section Architecture-independent data files
7208 @cindex @code{_DATA} primary, defined
7209 @cindex @code{DATA} primary, defined
7210 @cindex Primary variable, @code{DATA}
7211 @vindex _DATA
7213 Automake supports the installation of miscellaneous data files using the
7214 @code{DATA} family of variables.
7215 @vindex DATA
7217 @vindex data_DATA
7218 @vindex sysconf_DATA
7219 @vindex sharedstate_DATA
7220 @vindex localstate_DATA
7221 @vindex pkgdata_DATA
7223 Such data can be installed in the directories @code{datadir},
7224 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7225 @code{pkgdatadir}.
7227 By default, data files are @emph{not} included in a distribution.  Of
7228 course, you can use the @code{dist_} prefix to change this on a
7229 per-variable basis.
7231 Here is how Automake declares its auxiliary data files:
7233 @example
7234 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7235 @end example
7238 @node Sources
7239 @section Built Sources
7241 Because Automake's automatic dependency tracking works as a side-effect
7242 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7243 target should not be compiled before its dependencies are made, but
7244 these dependencies are unknown until the target is first compiled.
7246 Ordinarily this is not a problem, because dependencies are distributed
7247 sources: they preexist and do not need to be built.  Suppose that
7248 @file{foo.c} includes @file{foo.h}.  When it first compiles
7249 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7250 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7251 records the @file{foo.h} dependency so that following invocations of
7252 @command{make} will honor it.  In these conditions, it's clear there is
7253 no problem: either @file{foo.o} doesn't exist and has to be built
7254 (regardless of the dependencies), or accurate dependencies exist and
7255 they can be used to decide whether @file{foo.o} should be rebuilt.
7257 It's a different story if @file{foo.h} doesn't exist by the first
7258 @command{make} run.  For instance, there might be a rule to build
7259 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7260 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7261 rule to build @file{foo.h} first by lack of dependency information.
7263 @vindex BUILT_SOURCES
7264 @cindex @code{BUILT_SOURCES}, defined
7266 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7267 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7268 or @samp{make check} (or even @samp{make install}) before other
7269 targets are processed.  However, such a source file is not
7270 @emph{compiled} unless explicitly requested by mentioning it in some
7271 other @code{_SOURCES} variable.
7273 So, to conclude our introductory example, we could use
7274 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7275 any other target (including @file{foo.o}) during @samp{make all} or
7276 @samp{make check}.
7278 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7279 must be created early in the build process can be listed in this
7280 variable.  Moreover, all built sources do not necessarily have to be
7281 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7282 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7283 another source), because it's a known dependency of the associated
7284 object.
7286 It might be important to emphasize that @code{BUILT_SOURCES} is
7287 honored only by @samp{make all}, @samp{make check} and @samp{make
7288 install}.  This means you cannot build a specific target (e.g.,
7289 @samp{make foo}) in a clean tree if it depends on a built source.
7290 However it will succeed if you have run @samp{make all} earlier,
7291 because accurate dependencies are already available.
7293 The next section illustrates and discusses the handling of built sources
7294 on a toy example.
7296 @menu
7297 * Built Sources Example::       Several ways to handle built sources.
7298 @end menu
7300 @node Built Sources Example
7301 @subsection Built Sources Example
7303 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7304 installation-dependent and not distributed: it needs to be built.  Here
7305 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7306 value of the @command{make} variable @code{bindir} (inherited from
7307 @file{configure}).
7309 We suggest several implementations below.  It's not meant to be an
7310 exhaustive listing of all ways to handle built sources, but it will give
7311 you a few ideas if you encounter this issue.
7313 @subsubheading First Try
7315 This first implementation will illustrate the bootstrap issue mentioned
7316 in the previous section (@pxref{Sources}).
7318 Here is a tentative @file{Makefile.am}.
7320 @example
7321 # This won't work.
7322 bin_PROGRAMS = foo
7323 foo_SOURCES = foo.c
7324 nodist_foo_SOURCES = bindir.h
7325 CLEANFILES = bindir.h
7326 bindir.h: Makefile
7327         echo '#define bindir "$(bindir)"' >$@@
7328 @end example
7330 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7331 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7332 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7333 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7334 The symptom is as follows.
7336 @example
7337 % make
7338 source='foo.c' object='foo.o' libtool=no \
7339 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7340 depmode=gcc /bin/sh ./depcomp \
7341 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7342 foo.c:2: bindir.h: No such file or directory
7343 make: *** [foo.o] Error 1
7344 @end example
7346 In this example @file{bindir.h} is not distributed nor installed, and
7347 it is not even being built on-time.  One may wonder if the
7348 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7349 line simply states that @file{bindir.h} is a source of @code{foo}, so
7350 for instance, it should be inspected while generating tags
7351 (@pxref{Tags}).  In other words, it does not help our present problem,
7352 and the build would fail identically without it.
7354 @subsubheading Using @code{BUILT_SOURCES}
7356 A solution is to require @file{bindir.h} to be built before anything
7357 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7359 @example
7360 bin_PROGRAMS = foo
7361 foo_SOURCES = foo.c
7362 nodist_foo_SOURCES = bindir.h
7363 BUILT_SOURCES = bindir.h
7364 CLEANFILES = bindir.h
7365 bindir.h: Makefile
7366         echo '#define bindir "$(bindir)"' >$@@
7367 @end example
7369 See how @file{bindir.h} gets built first:
7371 @example
7372 % make
7373 echo '#define bindir "/usr/local/bin"' >bindir.h
7374 make  all-am
7375 make[1]: Entering directory `/home/adl/tmp'
7376 source='foo.c' object='foo.o' libtool=no \
7377 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7378 depmode=gcc /bin/sh ./depcomp \
7379 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7380 gcc  -g -O2   -o foo  foo.o
7381 make[1]: Leaving directory `/home/adl/tmp'
7382 @end example
7384 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7385 @code{all}, @code{check}, and @code{install} targets.  It still fails
7386 if you try to run @samp{make foo} explicitly:
7388 @example
7389 % make clean
7390 test -z "bindir.h" || rm -f bindir.h
7391 test -z "foo" || rm -f foo
7392 rm -f *.o
7393 % : > .deps/foo.Po # Suppress previously recorded dependencies
7394 % make foo
7395 source='foo.c' object='foo.o' libtool=no \
7396 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7397 depmode=gcc /bin/sh ./depcomp \
7398 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7399 foo.c:2: bindir.h: No such file or directory
7400 make: *** [foo.o] Error 1
7401 @end example
7403 @subsubheading Recording Dependencies manually
7405 Usually people are happy enough with @code{BUILT_SOURCES} because they
7406 never build targets such as @samp{make foo} before @samp{make all}, as
7407 in the previous example.  However if this matters to you, you can
7408 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7409 the @file{Makefile.am}.
7411 @example
7412 bin_PROGRAMS = foo
7413 foo_SOURCES = foo.c
7414 nodist_foo_SOURCES = bindir.h
7415 foo.$(OBJEXT): bindir.h
7416 CLEANFILES = bindir.h
7417 bindir.h: Makefile
7418         echo '#define bindir "$(bindir)"' >$@@
7419 @end example
7421 You don't have to list @emph{all} the dependencies of @file{foo.o}
7422 explicitly, only those that might need to be built.  If a dependency
7423 already exists, it will not hinder the first compilation and will be
7424 recorded by the normal dependency tracking code.  (Note that after
7425 this first compilation the dependency tracking code will also have
7426 recorded the dependency between @file{foo.o} and
7427 @file{bindir.h}; so our explicit dependency is really useful to
7428 the first build only.)
7430 Adding explicit dependencies like this can be a bit dangerous if you are
7431 not careful enough.  This is due to the way Automake tries not to
7432 overwrite your rules (it assumes you know better than it).
7433 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7434 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7435 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7436 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7437 Always check the generated @file{Makefile.in} if you do this.
7439 @subsubheading Build @file{bindir.h} from @file{configure}
7441 It's possible to define this preprocessor macro from @file{configure},
7442 either in @file{config.h} (@pxref{Defining Directories, , Defining
7443 Directories, autoconf, The Autoconf Manual}), or by processing a
7444 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7445 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7446 Autoconf Manual}).
7448 At this point it should be clear that building @file{bindir.h} from
7449 @file{configure} works well for this example.  @file{bindir.h} will exist
7450 before you build any target, hence will not cause any dependency issue.
7452 The Makefile can be shrunk as follows.  We do not even have to mention
7453 @file{bindir.h}.
7455 @example
7456 bin_PROGRAMS = foo
7457 foo_SOURCES = foo.c
7458 @end example
7460 However, it's not always possible to build sources from
7461 @file{configure}, especially when these sources are generated by a tool
7462 that needs to be built first.
7464 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7466 Another attractive idea is to define @code{bindir} as a variable or
7467 function exported from @file{bindir.o}, and build @file{bindir.c}
7468 instead of @file{bindir.h}.
7470 @example
7471 noinst_PROGRAMS = foo
7472 foo_SOURCES = foo.c bindir.h
7473 nodist_foo_SOURCES = bindir.c
7474 CLEANFILES = bindir.c
7475 bindir.c: Makefile
7476         echo 'const char bindir[] = "$(bindir)";' >$@@
7477 @end example
7479 @file{bindir.h} contains just the variable's declaration and doesn't
7480 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7481 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7482 first.
7484 @subsubheading Which is best?
7486 There is no panacea, of course.  Each solution has its merits and
7487 drawbacks.
7489 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7490 foo} on a clean tree is important to you.
7492 You won't add explicit dependencies if you are leery of overriding
7493 an Automake rule by mistake.
7495 Building files from @file{./configure} is not always possible, neither
7496 is converting @file{.h} files into @file{.c} files.
7499 @node Other GNU Tools
7500 @chapter Other GNU Tools
7502 Since Automake is primarily intended to generate @file{Makefile.in}s for
7503 use in GNU programs, it tries hard to interoperate with other GNU tools.
7505 @menu
7506 * Emacs Lisp::                  Emacs Lisp
7507 * gettext::                     Gettext
7508 * Libtool::                     Libtool
7509 * Java::                        Java bytecode compilation (deprecated)
7510 * Python::                      Python
7511 @end menu
7514 @node Emacs Lisp
7515 @section Emacs Lisp
7517 @cindex @code{_LISP} primary, defined
7518 @cindex @code{LISP} primary, defined
7519 @cindex Primary variable, @code{LISP}
7521 @vindex _LISP
7522 @vindex lisp_LISP
7523 @vindex noinst_LISP
7525 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7526 is used to hold a list of @file{.el} files.  Possible prefixes for this
7527 primary are @code{lisp_} and @code{noinst_}.  Note that if
7528 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7529 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7531 @vindex dist_lisp_LISP
7532 @vindex dist_noinst_LISP
7533 Lisp sources are not distributed by default.  You can prefix the
7534 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7535 @code{dist_noinst_LISP}, to indicate that these files should be
7536 distributed.
7538 Automake will byte-compile all Emacs Lisp source files using the Emacs
7539 found by @code{AM_PATH_LISPDIR}, if any was found.  When performing such
7540 byte-compilation, the flags specified in the (developer-reserved)
7541 @code{AM_ELCFLAGS} and (user-reserved) @code{ELCFLAGS} make variables
7542 will be passed to the Emacs invocation.
7544 Byte-compiled Emacs Lisp files are not portable among all versions of
7545 Emacs, so it makes sense to turn this off if you expect sites to have
7546 more than one version of Emacs installed.  Furthermore, many packages
7547 don't actually benefit from byte-compilation.  Still, we recommend
7548 that you byte-compile your Emacs Lisp sources.  It is probably better
7549 for sites with strange setups to cope for themselves than to make the
7550 installation less nice for everybody else.
7552 There are two ways to avoid byte-compiling.  Historically, we have
7553 recommended the following construct.
7555 @example
7556 lisp_LISP = file1.el file2.el
7557 ELCFILES =
7558 @end example
7560 @noindent
7561 @code{ELCFILES} is an internal Automake variable that normally lists
7562 all @file{.elc} files that must be byte-compiled.  Automake defines
7563 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7564 variable explicitly prevents byte-compilation.
7566 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7568 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7569 @example
7570 lisp_DATA = file1.el file2.el
7571 @end example
7573 Note that these two constructs are not equivalent.  @code{_LISP} will
7574 not install a file if Emacs is not installed, while @code{_DATA} will
7575 always install its files.
7577 @node gettext
7578 @section Gettext
7580 @cindex GNU Gettext support
7581 @cindex Gettext support
7582 @cindex Support for GNU Gettext
7584 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7585 turns on support for GNU gettext, a message catalog system for
7586 internationalization
7587 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7589 The @code{gettext} support in Automake requires the addition of one or
7590 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7591 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7592 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7593 Automake ensures that these directories exist and are mentioned in
7594 @code{SUBDIRS}.
7596 @node Libtool
7597 @section Libtool
7599 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7600 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7601 @xref{A Shared Library}.
7604 @node Java
7605 @section Java bytecode compilation (deprecated)
7607 @cindex @code{_JAVA} primary, defined
7608 @cindex @code{JAVA} primary, defined
7609 @cindex Primary variable, @code{JAVA}
7610 @cindex Java to bytecode, compilation
7611 @cindex Compilation of Java to bytecode
7613 Automake provides some minimal support for Java bytecode compilation with
7614 the @code{JAVA} primary (in addition to the support for compiling Java to
7615 native machine code; @pxref{Java Support with gcj}).  Note however that
7616 @emph{the interface and most features described here are deprecated}.
7617 Future Automake releases will strive to provide a better and cleaner
7618 interface, which however @emph{won't be backward-compatible}; the present
7619 interface will probably be removed altogether some time after the
7620 introduction of the new interface (if that ever materializes).  In any
7621 case, the current @code{JAVA} primary features are frozen and will no
7622 longer be developed, not even to take bug fixes.
7624 Any @file{.java} files listed in a @code{_JAVA} variable will be
7625 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7626 files are not included in the distribution, you should use the
7627 @code{dist_} prefix to distribute them.
7629 Here is a typical setup for distributing @file{.java} files and
7630 installing the @file{.class} files resulting from their compilation.
7632 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7633 @example
7634 javadir = $(datadir)/java
7635 dist_java_JAVA = a.java b.java @dots{}
7636 @end example
7638 @cindex @code{JAVA} restrictions
7639 @cindex Restrictions for @code{JAVA}
7641 Currently Automake enforces the restriction that only one @code{_JAVA}
7642 primary can be used in a given @file{Makefile.am}.  The reason for this
7643 restriction is that, in general, it isn't possible to know which
7644 @file{.class} files were generated from which @file{.java} files, so
7645 it would be impossible to know which files to install where.  For
7646 instance, a @file{.java} file can define multiple classes; the resulting
7647 @file{.class} file names cannot be predicted without parsing the
7648 @file{.java} file.
7650 There are a few variables that are used when compiling Java sources:
7652 @vtable @code
7653 @item JAVAC
7654 The name of the Java compiler.  This defaults to @samp{javac}.
7656 @item JAVACFLAGS
7657 The flags to pass to the compiler.  This is considered to be a user
7658 variable (@pxref{User Variables}).
7660 @item AM_JAVACFLAGS
7661 More flags to pass to the Java compiler.  This, and not
7662 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7663 compiler flags into @file{Makefile.am}.
7665 @item JAVAROOT
7666 The value of this variable is passed to the @option{-d} option to
7667 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7669 @item CLASSPATH_ENV
7670 This variable is a shell expression that is used to set the
7671 @env{CLASSPATH} environment variable on the @code{javac} command line.
7672 (In the future we will probably handle class path setting differently.)
7673 @end vtable
7676 @node Python
7677 @section Python
7679 @cindex @code{_PYTHON} primary, defined
7680 @cindex @code{PYTHON} primary, defined
7681 @cindex Primary variable, @code{PYTHON}
7682 @vindex _PYTHON
7684 Automake provides support for Python compilation with the
7685 @code{PYTHON} primary.  A typical setup is to call
7686 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7687 following in @file{Makefile.am}:
7689 @example
7690 python_PYTHON = tree.py leave.py
7691 @end example
7693 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7694 with @command{py-compile} at install time.  @command{py-compile}
7695 actually creates both standard (@file{.pyc}) and optimized
7696 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7697 because byte-compilation occurs at install time, any files listed in
7698 @code{noinst_PYTHON} will not be compiled.  Python source files are
7699 included in the distribution by default, prepend @code{nodist_} (as in
7700 @code{nodist_python_PYTHON}) to omit them.
7702 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7703 that will determine some Python-related directory variables (see
7704 below).  If you have called @code{AM_PATH_PYTHON} from
7705 @file{configure.ac}, then you may use the variables
7706 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7707 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7708 files in your @file{Makefile.am}, depending on where you want your files
7709 installed (see the definitions of @code{pythondir} and
7710 @code{pkgpythondir} below).
7712 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7713   @ovar{action-if-not-found})
7715 Search for a Python interpreter on the system.  This macro takes three
7716 optional arguments.  The first argument, if present, is the minimum
7717 version of Python required for this package: @code{AM_PATH_PYTHON}
7718 will skip any Python interpreter that is older than @var{version}.
7719 If an interpreter is found and satisfies @var{version}, then
7720 @var{action-if-found} is run.  Otherwise, @var{action-if-not-found} is
7721 run.
7723 If @var{action-if-not-found} is not specified, as in the following
7724 example, the default is to abort @command{configure}.
7726 @example
7727 AM_PATH_PYTHON([2.2])
7728 @end example
7730 @noindent
7731 This is fine when Python is an absolute requirement for the package.
7732 If Python >= 2.5 was only @emph{optional} to the package,
7733 @code{AM_PATH_PYTHON} could be called as follows.
7735 @example
7736 AM_PATH_PYTHON([2.5],, [:])
7737 @end example
7739 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7740 called, then that will be the only Python interpreter that is tried.
7742 @code{AM_PATH_PYTHON} creates the following output variables based on
7743 the Python installation found during configuration.
7744 @end defmac
7746 @vtable @code
7747 @item PYTHON
7748 The name of the Python executable, or @samp{:} if no suitable
7749 interpreter could be found.
7751 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7752 will abort if Python is absent), the value of @code{PYTHON} can be used
7753 to setup a conditional in order to disable the relevant part of a build
7754 as follows.
7756 @example
7757 AM_PATH_PYTHON(,, [:])
7758 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7759 @end example
7761 @item PYTHON_VERSION
7762 The Python version number, in the form @var{major}.@var{minor}
7763 (e.g., @samp{2.5}).  This is currently the value of
7764 @samp{sys.version[:3]}.
7766 @item PYTHON_PREFIX
7767 The string @samp{$@{prefix@}}.  This term may be used in future work
7768 that needs the contents of Python's @samp{sys.prefix}, but general
7769 consensus is to always use the value from @command{configure}.
7771 @item PYTHON_EXEC_PREFIX
7772 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7773 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7774 consensus is to always use the value from @command{configure}.
7776 @item PYTHON_PLATFORM
7777 The canonical name used by Python to describe the operating system, as
7778 given by @samp{sys.platform}.  This value is sometimes needed when
7779 building Python extensions.
7781 @item pythondir
7782 The directory name for the @file{site-packages} subdirectory of the
7783 standard Python install tree.
7785 @item pkgpythondir
7786 This is the directory under @code{pythondir} that is named after the
7787 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7788 as a convenience.
7790 @item pyexecdir
7791 This is the directory where Python extension modules (shared libraries)
7792 should be installed.  An extension module written in C could be declared
7793 as follows to Automake:
7795 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7796 @example
7797 pyexec_LTLIBRARIES = quaternion.la
7798 quaternion_la_SOURCES = quaternion.c support.c support.h
7799 quaternion_la_LDFLAGS = -avoid-version -module
7800 @end example
7802 @item pkgpyexecdir
7803 This is a convenience variable that is defined as
7804 @samp{$(pyexecdir)/$(PACKAGE)}.
7805 @end vtable
7807 All of these directory variables have values that start with either
7808 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7809 fine in @file{Makefiles}, but it makes these variables hard to use in
7810 @file{configure}.  This is mandated by the GNU coding standards, so
7811 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7812 manual has a section with more details on this topic
7813 (@pxref{Installation Directory Variables, , Installation Directory
7814 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7815 Install Paths}.
7818 @node Documentation
7819 @chapter Building documentation
7821 Currently Automake provides support for Texinfo and man pages.
7823 @menu
7824 * Texinfo::                     Texinfo
7825 * Man Pages::                   Man pages
7826 @end menu
7829 @node Texinfo
7830 @section Texinfo
7832 @cindex @code{_TEXINFOS} primary, defined
7833 @cindex @code{TEXINFOS} primary, defined
7834 @cindex Primary variable, @code{TEXINFOS}
7835 @cindex HTML output using Texinfo
7836 @cindex PDF output using Texinfo
7837 @cindex PS output using Texinfo
7838 @cindex DVI output using Texinfo
7839 @vindex _TEXINFOS
7840 @vindex info_TEXINFOS
7842 If the current directory contains Texinfo source, you must declare it
7843 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7844 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7845 here.  Any Texinfo source file should have the @file{.texi} extension.
7846 Automake also accepts @file{.txi} or @file{.texinfo} extensions, but their
7847 use is discouraged now, and will elicit runtime warnings.
7849 Automake generates rules to build @file{.info}, @file{.dvi},
7850 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7851 sources.  Following the GNU Coding Standards, only the @file{.info}
7852 files are built by @samp{make all} and installed by @samp{make
7853 install} (unless you use @option{no-installinfo}, see below).
7854 Furthermore, @file{.info} files are automatically distributed so that
7855 Texinfo is not a prerequisite for installing your package.
7857 It is worth noting that, contrary to what happens with the other formats,
7858 the generated @file{.info} files are by default placed in @code{srcdir}
7859 rather than in the @code{builddir}.  This can be changed with the
7860 @option{info-in-builddir} option.
7862 @trindex dvi
7863 @trindex html
7864 @trindex pdf
7865 @trindex ps
7866 @trindex install-dvi
7867 @trindex install-html
7868 @trindex install-pdf
7869 @trindex install-ps
7870 Other documentation formats can be built on request by @samp{make
7871 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7872 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7873 @samp{make install-pdf} and @samp{make install-html} explicitly.
7874 @samp{make uninstall} will remove everything: the Texinfo
7875 documentation installed by default as well as all the above optional
7876 formats.
7878 All of these targets can be extended using @samp{-local} rules
7879 (@pxref{Extending}).
7881 @cindex Texinfo flag, @code{VERSION}
7882 @cindex Texinfo flag, @code{UPDATED}
7883 @cindex Texinfo flag, @code{EDITION}
7884 @cindex Texinfo flag, @code{UPDATED-MONTH}
7886 @cindex @code{VERSION} Texinfo flag
7887 @cindex @code{UPDATED} Texinfo flag
7888 @cindex @code{EDITION} Texinfo flag
7889 @cindex @code{UPDATED-MONTH} Texinfo flag
7891 @cindex @file{mdate-sh}
7893 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7894 that file will be automatically generated.  The file @file{version.texi}
7895 defines four Texinfo flags you can reference using
7896 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7897 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7899 @table @code
7900 @item EDITION
7901 @itemx VERSION
7902 Both of these flags hold the version number of your program.  They are
7903 kept separate for clarity.
7905 @item UPDATED
7906 This holds the date the primary @file{.texi} file was last modified.
7908 @item UPDATED-MONTH
7909 This holds the name of the month in which the primary @file{.texi} file
7910 was last modified.
7911 @end table
7913 The @file{version.texi} support requires the @command{mdate-sh}
7914 script; this script is supplied with Automake and automatically
7915 included when @command{automake} is invoked with the
7916 @option{--add-missing} option.
7918 If you have multiple Texinfo files, and you want to use the
7919 @file{version.texi} feature, then you have to have a separate version
7920 file for each Texinfo file.  Automake will treat any include in a
7921 Texinfo file that matches @file{vers*.texi} just as an automatically
7922 generated version file.
7924 Sometimes an info file actually depends on more than one @file{.texi}
7925 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7926 @file{fdl.texi}.  You can tell Automake about these dependencies using
7927 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7928 @vindex TEXINFOS
7929 @vindex _TEXINFOS
7931 @example
7932 info_TEXINFOS = hello.texi
7933 hello_TEXINFOS = fdl.texi
7934 @end example
7936 @cindex @file{texinfo.tex}
7938 By default, Automake requires the file @file{texinfo.tex} to appear in
7939 the same directory as the @file{Makefile.am} file that lists the
7940 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7941 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7942 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7943 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
7944 @option{--add-missing} is given, and takes care of its distribution.
7945 However, if you set the @code{TEXINFO_TEX} variable (see below),
7946 it overrides the location of the file and turns off its installation
7947 into the source as well as its distribution.
7949 The option @option{no-texinfo.tex} can be used to eliminate the
7950 requirement for the file @file{texinfo.tex}.  Use of the variable
7951 @code{TEXINFO_TEX} is preferable, however, because that allows the
7952 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7954 @cindex Option, @code{no-installinfo}
7955 @cindex Target, @code{install-info}
7956 @cindex @code{install-info} target
7957 @cindex @code{no-installinfo} option
7959 @opindex no-installinfo
7960 @trindex install-info
7962 Automake generates an @code{install-info} rule; some people apparently
7963 use this.  By default, info pages are installed by @samp{make
7964 install}, so running @code{make install-info} is pointless.  This can
7965 be prevented via the @code{no-installinfo} option.  In this case,
7966 @file{.info} files are not installed by default, and user must
7967 request this explicitly using @samp{make install-info}.
7969 @vindex AM_UPDATE_INFO_DIR
7970 By default, @code{make install-info} and @code{make uninstall-info}
7971 will try to run the @command{install-info} program (if available) to
7972 update (or create/remove) the @file{@code{$@{infodir@}}/dir} index.
7973 If this is undesired, it can be prevented by exporting the
7974 @code{AM_UPDATE_INFO_DIR} variable to "@code{no}".
7976 The following variables are used by the Texinfo build rules.
7978 @vtable @code
7979 @item MAKEINFO
7980 The name of the program invoked to build @file{.info} files.  This
7981 variable is defined by Automake.  If the @command{makeinfo} program is
7982 found on the system then it will be used by default; otherwise
7983 @command{missing} will be used instead.
7985 @item MAKEINFOHTML
7986 The command invoked to build @file{.html} files.  Automake
7987 defines this to @samp{$(MAKEINFO) --html}.
7989 @item MAKEINFOFLAGS
7990 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7991 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7992 not expected to be defined in any @file{Makefile}; it can be used by
7993 users to pass extra flags to suit their needs.
7995 @item AM_MAKEINFOFLAGS
7996 @itemx AM_MAKEINFOHTMLFLAGS
7997 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7998 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7999 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
8000 passed to @code{makeinfo} when building @file{.info} files; and
8001 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
8002 files.
8004 @c Keep in sync with txinfo-many-output-formats.sh
8005 For instance, the following setting can be used to obtain one single
8006 @file{.html} file per manual, without node separators.
8007 @example
8008 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
8009 @end example
8011 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
8012 This means that defining @code{AM_MAKEINFOFLAGS} without defining
8013 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
8014 and @file{.html} files.
8016 @item TEXI2DVI
8017 The name of the command that converts a @file{.texi} file into a
8018 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
8019 with the Texinfo package.
8021 @item TEXI2PDF
8022 The name of the command that translates a @file{.texi} file into a
8023 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
8025 @item DVIPS
8026 The name of the command that builds a @file{.ps} file out of a
8027 @file{.dvi} file.  This defaults to @samp{dvips}.
8029 @item TEXINFO_TEX
8031 If your package has Texinfo files in many directories, you can use the
8032 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
8033 @file{texinfo.tex} for your package.  The value of this variable should
8034 be the relative path from the current @file{Makefile.am} to
8035 @file{texinfo.tex}:
8037 @example
8038 TEXINFO_TEX = ../doc/texinfo.tex
8039 @end example
8040 @end vtable
8043 @node Man Pages
8044 @section Man Pages
8046 @cindex @code{_MANS} primary, defined
8047 @cindex @code{MANS} primary, defined
8048 @cindex Primary variable, @code{MANS}
8050 @vindex _MANS
8051 @vindex man_MANS
8052 A package can also include man pages (but see the GNU standards on this
8053 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
8054 pages are declared using the @code{MANS} primary.  Generally the
8055 @code{man_MANS} variable is used.  Man pages are automatically installed in
8056 the correct subdirectory of @code{mandir}, based on the file extension.
8058 File extensions such as @file{.1c} are handled by looking for the valid
8059 part of the extension and using that to determine the correct
8060 subdirectory of @code{mandir}.  Valid section names are the digits
8061 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
8063 Sometimes developers prefer to name a man page something like
8064 @file{foo.man} in the source, and then rename it to have the correct
8065 suffix, for example @file{foo.1}, when installing the file.  Automake
8066 also supports this mode.  For a valid section named @var{section},
8067 there is a corresponding directory named @samp{man@var{section}dir},
8068 and a corresponding @code{_MANS} variable.  Files listed in such a
8069 variable are installed in the indicated section.  If the file already
8070 has a valid suffix, then it is installed as-is; otherwise the file
8071 suffix is changed to match the section.
8073 For instance, consider this example:
8074 @example
8075 man1_MANS = rename.man thesame.1 alsothesame.1c
8076 @end example
8078 @noindent
8079 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8080 installed, but the other files will keep their names.
8082 @cindex Target, @code{install-man}
8083 @cindex Option, @option{no-installman}
8084 @cindex @code{install-man} target
8085 @cindex @option{no-installman} option
8086 @opindex no-installman
8087 @trindex install-man
8089 By default, man pages are installed by @samp{make install}.  However,
8090 since the GNU project does not require man pages, many maintainers do
8091 not expend effort to keep the man pages up to date.  In these cases, the
8092 @option{no-installman} option will prevent the man pages from being
8093 installed by default.  The user can still explicitly install them via
8094 @samp{make install-man}.
8096 For fast installation, with many files it is preferable to use
8097 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8098 do not need to be renamed.
8100 Man pages are not currently considered to be source, because it is not
8101 uncommon for man pages to be automatically generated.  Therefore they
8102 are not automatically included in the distribution.  However, this can
8103 be changed by use of the @code{dist_} prefix.  For instance here is
8104 how to distribute and install the two man pages of GNU @command{cpio}
8105 (which includes both Texinfo documentation and man pages):
8107 @example
8108 dist_man_MANS = cpio.1 mt.1
8109 @end example
8111 The @code{nobase_} prefix is meaningless for man pages and is
8112 disallowed.
8114 @vindex notrans_
8115 @cindex @code{notrans_} prefix
8116 @cindex Man page renaming, avoiding
8117 @cindex Avoiding man page renaming
8119 Executables and manpages may be renamed upon installation
8120 (@pxref{Renaming}).  For manpages this can be avoided by use of the
8121 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
8122 allowing to access a library function @samp{foo} from the command line.
8123 The way to avoid renaming of the @file{foo.3} manpage is:
8125 @example
8126 man_MANS = foo.1
8127 notrans_man_MANS = foo.3
8128 @end example
8130 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8131 @cindex @code{dist_} and @code{notrans_}
8132 @cindex @code{nodist_} and @code{notrans_}
8134 @samp{notrans_} must be specified first when used in conjunction with
8135 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8136 Control}).  For instance:
8138 @example
8139 notrans_dist_man3_MANS = bar.3
8140 @end example
8142 @node Install
8143 @chapter What Gets Installed
8145 @cindex Installation support
8146 @cindex @samp{make install} support
8148 Naturally, Automake handles the details of actually installing your
8149 program once it has been built.  All files named by the various
8150 primaries are automatically installed in the appropriate places when the
8151 user runs @samp{make install}.
8153 @menu
8154 * Basics of Installation::      What gets installed where
8155 * The Two Parts of Install::    Installing data and programs separately
8156 * Extending Installation::      Adding your own rules for installation
8157 * Staged Installs::             Installation in a temporary location
8158 * Install Rules for the User::  Useful additional rules
8159 @end menu
8161 @node Basics of Installation
8162 @section Basics of Installation
8164 A file named in a primary is installed by copying the built file into
8165 the appropriate directory.  The base name of the file is used when
8166 installing.
8168 @example
8169 bin_PROGRAMS = hello subdir/goodbye
8170 @end example
8172 In this example, both @samp{hello} and @samp{goodbye} will be installed
8173 in @samp{$(bindir)}.
8175 Sometimes it is useful to avoid the basename step at install time.  For
8176 instance, you might have a number of header files in subdirectories of
8177 the source tree that are laid out precisely how you want to install
8178 them.  In this situation you can use the @code{nobase_} prefix to
8179 suppress the base name step.  For example:
8181 @example
8182 nobase_include_HEADERS = stdio.h sys/types.h
8183 @end example
8185 @noindent
8186 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8187 in @samp{$(includedir)/sys}.
8189 For most file types, Automake will install multiple files at once, while
8190 avoiding command line length issues (@pxref{Length Limitations}).  Since
8191 some @command{install} programs will not install the same file twice in
8192 one invocation, you may need to ensure that file lists are unique within
8193 one variable such as @samp{nobase_include_HEADERS} above.
8195 You should not rely on the order in which files listed in one variable
8196 are installed.  Likewise, to cater for parallel make, you should not
8197 rely on any particular file installation order even among different
8198 file types (library dependencies are an exception here).
8201 @node The Two Parts of Install
8202 @section The Two Parts of Install
8204 Automake generates separate @code{install-data} and @code{install-exec}
8205 rules, in case the installer is installing on multiple machines that
8206 share directory structure---these targets allow the machine-independent
8207 parts to be installed only once.  @code{install-exec} installs
8208 platform-dependent files, and @code{install-data} installs
8209 platform-independent files.  The @code{install} target depends on both
8210 of these targets.  While Automake tries to automatically segregate
8211 objects into the correct category, the @file{Makefile.am} author is, in
8212 the end, responsible for making sure this is done correctly.
8213 @trindex install-data
8214 @trindex install-exec
8215 @trindex install
8216 @cindex Install, two parts of
8218 Variables using the standard directory prefixes @samp{data},
8219 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8220 @samp{pkgdata}, or @samp{pkginclude} are installed by
8221 @code{install-data}.
8223 Variables using the standard directory prefixes @samp{bin},
8224 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8225 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8227 For instance, @code{data_DATA} files are installed by @code{install-data},
8228 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8230 Any variable using a user-defined directory prefix with
8231 @samp{exec} in the name (e.g.,
8232 @c Keep in sync with primary-prefix-couples-documented-valid.sh
8233 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}.  All
8234 other user-defined prefixes are installed by @code{install-data}.
8236 @node Extending Installation
8237 @section Extending Installation
8239 It is possible to extend this mechanism by defining an
8240 @code{install-exec-local} or @code{install-data-local} rule.  If these
8241 rules exist, they will be run at @samp{make install} time.  These
8242 rules can do almost anything; care is required.
8243 @trindex install-exec-local
8244 @trindex install-data-local
8246 Automake also supports two install hooks, @code{install-exec-hook} and
8247 @code{install-data-hook}.  These hooks are run after all other install
8248 rules of the appropriate type, exec or data, have completed.  So, for
8249 instance, it is possible to perform post-installation modifications
8250 using an install hook.  @xref{Extending}, for some examples.
8251 @cindex Install hook
8253 @node Staged Installs
8254 @section Staged Installs
8256 @vindex DESTDIR
8257 Automake generates support for the @code{DESTDIR} variable in all
8258 install rules.  @code{DESTDIR} is used during the @samp{make install}
8259 step to relocate install objects into a staging area.  Each object and
8260 path is prefixed with the value of @code{DESTDIR} before being copied
8261 into the install area.  Here is an example of typical DESTDIR usage:
8263 @example
8264 mkdir /tmp/staging &&
8265 make DESTDIR=/tmp/staging install
8266 @end example
8268 The @command{mkdir} command avoids a security problem if the attacker
8269 creates a symbolic link from @file{/tmp/staging} to a victim area;
8270 then @command{make} places install objects in a directory tree built under
8271 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8272 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8273 would install @file{/tmp/staging/gnu/bin/foo} and
8274 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8276 This feature is commonly used to build install images and packages
8277 (@pxref{DESTDIR}).
8279 Support for @code{DESTDIR} is implemented by coding it directly into
8280 the install rules.  If your @file{Makefile.am} uses a local install
8281 rule (e.g., @code{install-exec-local}) or an install hook, then you
8282 must write that code to respect @code{DESTDIR}.
8284 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8285 for another usage example.
8287 @node Install Rules for the User
8288 @section Install Rules for the User
8290 Automake also generates rules for targets @code{uninstall},
8291 @code{installdirs}, and @code{install-strip}.
8292 @trindex uninstall
8293 @trindex installdirs
8294 @trindex install-strip
8296 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8297 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8298 these features would not provide additional functionality.
8300 Note that @code{uninstall} is not meant as a replacement for a real
8301 packaging tool.
8304 @node Clean
8305 @chapter What Gets Cleaned
8307 @cindex @samp{make clean} support
8309 The GNU Makefile Standards specify a number of different clean rules.
8310 @xref{Standard Targets, , Standard Targets for Users, standards,
8311 The GNU Coding Standards}.
8313 Generally the files that can be cleaned are determined automatically by
8314 Automake.  Of course, Automake also recognizes some variables that can
8315 be defined to specify additional files to clean.  These variables are
8316 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8317 @code{MAINTAINERCLEANFILES}.
8318 @vindex MOSTLYCLEANFILES
8319 @vindex CLEANFILES
8320 @vindex DISTCLEANFILES
8321 @vindex MAINTAINERCLEANFILES
8323 @trindex mostlyclean-local
8324 @trindex clean-local
8325 @trindex distclean-local
8326 @trindex maintainer-clean-local
8327 When cleaning involves more than deleting some hard-coded list of
8328 files, it is also possible to supplement the cleaning rules with your
8329 own commands.  Simply define a rule for any of the
8330 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8331 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8332 case is deleting a directory, for instance, a directory created by the
8333 test suite:
8335 @example
8336 clean-local:
8337         -rm -rf testSubDir
8338 @end example
8340 Since @command{make} allows only one set of rules for a given target,
8341 a more extensible way of writing this is to use a separate target
8342 listed as a dependency:
8344 @example
8345 clean-local: clean-local-check
8346 .PHONY: clean-local-check
8347 clean-local-check:
8348         -rm -rf testSubDir
8349 @end example
8351 As the GNU Standards aren't always explicit as to which files should
8352 be removed by which rule, we've adopted a heuristic that we believe
8353 was first formulated by Fran@,{c}ois Pinard:
8355 @itemize @bullet
8356 @item
8357 If @command{make} built it, and it is commonly something that one would
8358 want to rebuild (for instance, a @file{.o} file), then
8359 @code{mostlyclean} should delete it.
8361 @item
8362 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8364 @item
8365 If @command{configure} built it, then @code{distclean} should delete it.
8367 @item
8368 If the maintainer built it (for instance, a @file{.info} file), then
8369 @code{maintainer-clean} should delete it.  However
8370 @code{maintainer-clean} should not delete anything that needs to exist
8371 in order to run @samp{./configure && make}.
8372 @end itemize
8374 We recommend that you follow this same set of heuristics in your
8375 @file{Makefile.am}.
8378 @node Dist
8379 @chapter What Goes in a Distribution
8381 @menu
8382 * Basics of Distribution::      Files distributed by default
8383 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8384 * The dist Hook::               A target for last-minute distribution changes
8385 * Checking the Distribution::   @samp{make distcheck} explained
8386 * The Types of Distributions::  A variety of formats and compression methods
8387 @end menu
8389 @node Basics of Distribution
8390 @section Basics of Distribution
8392 @cindex @samp{make dist}
8394 @vindex PACKAGE
8395 @vindex VERSION
8396 @trindex dist
8397 The @code{dist} rule in the generated @file{Makefile.in} can be used
8398 to generate a gzipped @code{tar} file and other flavors of archive for
8399 distribution.  The file is named based on the @code{PACKAGE} and
8400 @code{VERSION} variables automatically defined by either the
8401 @code{AC_INIT} invocation or by a @emph{deprecated} two-arguments
8402 invocation of the @code{AM_INIT_AUTOMAKE} macro (see @ref{Public Macros}
8403 for how these variables get their values, from either defaults or explicit
8404 values -- it's slightly trickier than one would expect).
8405 More precisely the gzipped @code{tar} file is named
8406 @samp{$@{PACKAGE@}-$@{VERSION@}.tar.gz}.
8407 @vindex GZIP_ENV
8408 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8409 is run.  The default setting is @option{--best}.
8411 @cindex @code{m4_include}, distribution
8412 @cindex @code{include}, distribution
8413 @acindex m4_include
8414 @cmindex include
8415 For the most part, the files to distribute are automatically found by
8416 Automake: all source files are automatically included in a distribution,
8417 as are all @file{Makefile.am} and @file{Makefile.in} files.  Automake also
8418 has a built-in list of commonly used files that are automatically
8419 included if they are found in the current directory (either physically,
8420 or as the target of a @file{Makefile.am} rule); this list is printed by
8421 @samp{automake --help}.  Note that some files in this list are actually
8422 distributed only if other certain conditions hold (for example,
8423 @c Keep in sync with autodist-config-headers.sh
8424 the @file{config.h.top} and @file{config.h.bot} files are automatically
8425 distributed only if, e.g., @samp{AC_CONFIG_HEADERS([config.h])} is used
8426 in @file{configure.ac}).  Also, files that are read by @command{configure}
8427 (i.e.@: the source files corresponding to the files specified in various
8428 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8429 automatically distributed.  Files included in a @file{Makefile.am} (using
8430 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8431 helper scripts installed with @samp{automake --add-missing} are also
8432 distributed.
8434 @vindex EXTRA_DIST
8435 Still, sometimes there are files that must be distributed, but which
8436 are not covered in the automatic rules.  These files should be listed in
8437 the @code{EXTRA_DIST} variable.  You can mention files from
8438 subdirectories in @code{EXTRA_DIST}.
8440 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8441 entire directory will be recursively copied into the distribution.
8442 Please note that this will also copy @emph{everything} in the directory,
8443 including, e.g., Subversion's @file{.svn} private directories or CVS/RCS
8444 version control files; thus we recommend against using this feature
8445 as-is.  However, you can use the @code{dist-hook} feature to
8446 ameliorate the problem; @pxref{The dist Hook}.
8448 @vindex SUBDIRS
8449 @vindex DIST_SUBDIRS
8450 If you define @code{SUBDIRS}, Automake will recursively include the
8451 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8452 conditionally (@pxref{Conditionals}), Automake will normally include
8453 all directories that could possibly appear in @code{SUBDIRS} in the
8454 distribution.  If you need to specify the set of directories
8455 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8456 exact list of subdirectories to include in the distribution
8457 (@pxref{Conditional Subdirectories}).
8460 @node Fine-grained Distribution Control
8461 @section Fine-grained Distribution Control
8463 @vindex dist_
8464 @vindex nodist_
8465 Sometimes you need tighter control over what does @emph{not} go into the
8466 distribution; for instance, you might have source files that are
8467 generated and that you do not want to distribute.  In this case
8468 Automake gives fine-grained control using the @code{dist} and
8469 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8470 prefixed with @code{dist_} to add the listed files to the distribution.
8471 Similarly, @code{nodist_} can be used to omit the files from the
8472 distribution.
8474 As an example, here is how you would cause some data to be distributed
8475 while leaving some source code out of the distribution:
8477 @example
8478 dist_data_DATA = distribute-this
8479 bin_PROGRAMS = foo
8480 nodist_foo_SOURCES = do-not-distribute.c
8481 @end example
8483 @node The dist Hook
8484 @section The dist Hook
8486 @trindex dist-hook
8488 Occasionally it is useful to be able to change the distribution before
8489 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8490 after the distribution directory is filled, but before the actual
8491 distribution archives are created.  One way to use this is for
8492 removing unnecessary files that get recursively included by specifying
8493 a directory in @code{EXTRA_DIST}:
8495 @example
8496 EXTRA_DIST = doc
8497 dist-hook:
8498         rm -rf `find $(distdir)/doc -type d -name .svn`
8499 @end example
8501 @c The caveats described here should be documented in 'disthook.sh'.
8502 @noindent
8503 Note that the @code{dist-hook} recipe shouldn't assume that the regular
8504 files in the distribution directory are writable; this might not be the
8505 case if one is packaging from a read-only source tree, or when a
8506 @code{make distcheck} is being done.  For similar reasons, the recipe
8507 shouldn't assume that the subdirectories put into the distribution
8508 directory as effect of having them listed in @code{EXTRA_DIST} are
8509 writable.  So, if the @code{dist-hook} recipe wants to modify the
8510 content of an existing file (or @code{EXTRA_DIST} subdirectory) in the
8511 distribution directory, it should explicitly to make it writable first:
8513 @example
8514 EXTRA_DIST = README doc
8515 dist-hook:
8516         chmod u+w $(distdir)/README $(distdir)/doc
8517         echo "Distribution date: `date`" >> README
8518         rm -f $(distdir)/doc/HACKING
8519 @end example
8521 @vindex distdir
8522 @vindex top_distdir
8523 Two variables that come handy when writing @code{dist-hook} rules are
8524 @samp{$(distdir)} and @samp{$(top_distdir)}.
8526 @samp{$(distdir)} points to the directory where the @code{dist} rule
8527 will copy files from the current directory before creating the
8528 tarball.  If you are at the top-level directory, then @samp{distdir =
8529 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8530 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8531 @samp{$(distdir)} can be a relative or absolute path, do not assume
8532 any form.
8534 @samp{$(top_distdir)} always points to the root directory of the
8535 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8536 In the @file{foo/} subdirectory
8537 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8538 @samp{$(top_distdir)} too can be a relative or absolute path.
8540 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8541 (@pxref{Subpackages}), then @samp{$(distdir)} and
8542 @samp{$(top_distdir)} are relative to the package where @samp{make
8543 dist} was run, not to any sub-packages involved.
8545 @node Checking the Distribution
8546 @section Checking the Distribution
8548 @cindex @samp{make distcheck}
8549 @trindex distcheck
8550 Automake also generates a @code{distcheck} rule that can be of help
8551 to ensure that a given distribution will actually work.  Simplifying
8552 a bit, we can say this rule first makes a distribution, and then,
8553 @emph{operating from it}, takes the following steps:
8554 @itemize
8555 @item
8556 tries to do a @code{VPATH} build (@pxref{VPATH Builds}), with the
8557 @code{srcdir} and all its content made @emph{read-only};
8558 @item
8559 runs the test suite (with @command{make check}) on this fresh build;
8560 @item
8561 installs the package in a temporary directory (with @command{make
8562 install}), and tries runs the test suite on the resulting installation
8563 (with @command{make installcheck});
8564 @item
8565 checks that the package can be correctly uninstalled (by @command{make
8566 uninstall}) and cleaned (by @code{make distclean});
8567 @item
8568 finally, makes another tarball to ensure the distribution is
8569 self-contained.
8570 @end itemize
8572 All of these actions are performed in a temporary directory.  Please
8573 note that the exact location and the exact structure of such a directory
8574 (where the read-only sources are placed, how the temporary build and
8575 install directories are named and how deeply they are nested, etc.) is
8576 to be considered an implementation detail, which can change at any time;
8577 so do not reply on it.
8579 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8580 @vindex DISTCHECK_CONFIGURE_FLAGS
8581 @subheading DISTCHECK_CONFIGURE_FLAGS
8582 Building the package involves running @samp{./configure}.  If you need
8583 to supply additional flags to @command{configure}, define them in the
8584 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8585 @file{Makefile.am}.  The user can still extend or override the flags
8586 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8587 on the command line when invoking @command{make}.
8588 @c See automake bug#14991 for more details about how the following holds.
8589 It's worth noting that @command{make distcheck} needs complete control
8590 over the @command{configure} options @option{--srcdir} and
8591 @option{--prefix}, so those options cannot be overridden by
8592 @code{AM_DISTCHECK_CONFIGURE_FLAGS} nor by
8593 @code{DISTCHECK_CONFIGURE_FLAGS}.
8595 Also note that developers are encouraged to strive to make their code
8596 buildable without requiring any special configure option; thus, in
8597 general, you shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}.
8598 However, there might be few scenarios in which the use of this variable
8599 is justified.
8600 GNU @command{m4} offers an example.  GNU @command{m4} configures by
8601 default with its experimental and seldom used "changeword" feature
8602 disabled; so in its case it is useful to have @command{make distcheck}
8603 run configure with the @option{--with-changeword} option, to ensure that
8604 the code for changeword support still compiles correctly.
8605 GNU @command{m4} also employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS}
8606 variable to stress-test the use of @option{--program-prefix=g}, since at
8607 one point the @command{m4} build system had a bug where @command{make
8608 installcheck} was wrongly assuming it could blindly test "@command{m4}",
8609 rather than the just-installed "@command{gm4}".
8611 @trindex distcheck-hook
8612 @subheading distcheck-hook
8613 If the @code{distcheck-hook} rule is defined in your top-level
8614 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8615 the new distribution has been unpacked, but before the unpacked copy
8616 is configured and built.  Your @code{distcheck-hook} can do almost
8617 anything, though as always caution is advised.  Generally this hook is
8618 used to check for potential distribution errors not caught by the
8619 standard mechanism.  Note that @code{distcheck-hook} as well as
8620 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8621 are not honored in a subpackage @file{Makefile.am}, but the flags from
8622 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8623 are passed down to the @command{configure} script of the subpackage.
8625 @cindex @samp{make distcleancheck}
8626 @trindex distcleancheck
8627 @vindex DISTCLEANFILES
8628 @vindex distcleancheck_listfiles
8630 @subheading distcleancheck
8631 Speaking of potential distribution errors, @code{distcheck} also
8632 ensures that the @code{distclean} rule actually removes all built
8633 files.  This is done by running @samp{make distcleancheck} at the end of
8634 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8635 @code{distclean} and then make sure the build tree has been emptied by
8636 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8637 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8638 variable (@pxref{Clean}).
8640 The @code{distcleancheck} behavior should be OK for most packages,
8641 otherwise you have the possibility to override the definition of
8642 either the @code{distcleancheck} rule, or the
8643 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8644 @code{distcleancheck} completely, add the following rule to your
8645 top-level @file{Makefile.am}:
8647 @example
8648 distcleancheck:
8649         @@:
8650 @end example
8652 If you want @code{distcleancheck} to ignore built files that have not
8653 been cleaned because they are also part of the distribution, add the
8654 following definition instead:
8656 @c Keep in sync with distcleancheck.sh
8657 @example
8658 distcleancheck_listfiles = \
8659   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8660        sh '@{@}' ';'
8661 @end example
8663 The above definition is not the default because it's usually an error if
8664 your Makefiles cause some distributed files to be rebuilt when the user
8665 build the package.  (Think about the user missing the tool required to
8666 build the file; or if the required tool is built by your package,
8667 consider the cross-compilation case where it can't be run.)  There is
8668 an entry in the FAQ about this (@pxref{Errors with distclean}), make
8669 sure you read it before playing with @code{distcleancheck_listfiles}.
8671 @cindex @samp{make distuninstallcheck}
8672 @trindex distuninstallcheck
8673 @vindex distuninstallcheck_listfiles
8675 @subheading distuninstallcheck
8676 @code{distcheck} also checks that the @code{uninstall} rule works
8677 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8678 by invoking @samp{make uninstall}, and then it checks the install tree
8679 to see if any files are left over.  This check will make sure that you
8680 correctly coded your @code{uninstall}-related rules.
8682 By default, the checking is done by the @code{distuninstallcheck} rule,
8683 and the list of files in the install tree is generated by
8684 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8685 a shell command to run that prints the list of files to stdout).
8687 Either of these can be overridden to modify the behavior of
8688 @code{distcheck}.  For instance, to disable this check completely, you
8689 would write:
8691 @example
8692 distuninstallcheck:
8693         @@:
8694 @end example
8696 @node The Types of Distributions
8697 @section The Types of Distributions
8699 Automake generates rules to provide archives of the project for
8700 distributions in various formats.  Their targets are:
8702 @table @asis
8703 @item @code{dist-gzip}
8704 Generate a @samp{gzip} tar archive of the distribution.  This is the
8705 only format enabled by default.
8706 @trindex dist-gzip
8708 @vindex BZIP2
8709 @item @code{dist-bzip2}
8710 Generate a @samp{bzip2} tar archive of the distribution.  bzip2 archives
8711 are frequently smaller than gzipped archives.
8712 By default, this rule makes @samp{bzip2} use a compression option of @option{-9}.
8713 To make it use a different one, set the @env{BZIP2} environment variable.
8714 For example, @samp{make dist-bzip2 BZIP2=-7}.
8715 @trindex dist-bzip2
8717 @item @code{dist-lzip}
8718 Generate an @samp{lzip} tar archive of the distribution.  @command{lzip}
8719 archives are frequently smaller than @command{bzip2}-compressed archives.
8720 @trindex dist-lzip
8722 @vindex XZ_OPT
8723 @item @code{dist-xz}
8724 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8725 archives are frequently smaller than @command{bzip2}-compressed archives.
8726 By default, this rule makes @samp{xz} use a compression option of
8727 @option{-e}.  To make it use a different one, set the @env{XZ_OPT}
8728 environment variable.  For example, run this command to use the
8729 default compression ratio, but with a progress indicator:
8730 @samp{make dist-xz XZ_OPT=-ve}.
8731 @trindex dist-xz
8733 @item @code{dist-zip}
8734 Generate a @samp{zip} archive of the distribution.
8735 @trindex dist-zip
8737 @item @code{dist-tarZ}
8738 Generate a tar archive of the distribution, compressed with the
8739 historical (and obsolescent) program @command{compress}.  This
8740 option is deprecated, and it and the corresponding functionality
8741 will be removed altogether in Automake 2.0.
8742 @trindex dist-tarZ
8744 @item @code{dist-shar}
8745 Generate a @samp{shar} archive of the distribution.  This format
8746 archive is obsolescent, and use of this option is deprecated.
8747 It and the corresponding functionality will be removed altogether
8748 in Automake 2.0.
8749 @trindex dist-shar
8751 @end table
8753 The rule @code{dist} (and its historical synonym @code{dist-all})
8754 will create archives in all the enabled formats (@pxref{List of
8755 Automake options} for how to change this list).  By default, only
8756 the @code{dist-gzip} target is hooked to @code{dist}.
8759 @node Tests
8760 @chapter Support for test suites
8762 @cindex Test suites
8763 @cindex @code{make check}
8764 @trindex check
8766 Automake can generate code to handle two kinds of test suites.  One is
8767 based on integration with the @command{dejagnu} framework.  The other
8768 (and most used) form is based on the use of generic test scripts, and
8769 its activation is triggered by the definition of the special @code{TESTS}
8770 variable.  This second form allows for various degrees of sophistication
8771 and customization; in particular, it allows for concurrent execution
8772 of test scripts, use of established test protocols such as TAP, and
8773 definition of custom test drivers and test runners.
8775 @noindent
8776 In either case, the testsuite is invoked via @samp{make check}.
8778 @menu
8779 * Generalities about Testing::  Concepts and terminology about testing
8780 * Simple Tests::                Listing test scripts in @code{TESTS}
8781 * Custom Test Drivers::         Writing and using custom test drivers
8782 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
8783 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
8784 * Install Tests::               Running tests on installed packages
8785 @end menu
8787 @node Generalities about Testing
8788 @section Generalities about Testing
8790 The purpose of testing is to determine whether a program or system behaves
8791 as expected (e.g., known inputs produce the expected outputs, error
8792 conditions are correctly handled or reported, and older bugs do not
8793 resurface).
8795 @cindex test case
8796 The minimal unit of testing is usually called @emph{test case}, or simply
8797 @emph{test}.  How a test case is defined or delimited, and even what
8798 exactly @emph{constitutes} a test case, depends heavily on the testing
8799 paradigm and/or framework in use, so we won't attempt any more precise
8800 definition.  The set of the test cases for a given program or system
8801 constitutes its @emph{testsuite}.
8803 @cindex test harness
8804 @cindex testsuite harness
8805 A @emph{test harness} (also @emph{testsuite harness}) is a program or
8806 software component that executes all (or part of) the defined test cases,
8807 analyzes their outcomes, and report or register these outcomes
8808 appropriately.  Again, the details of how this is accomplished (and how
8809 the developer and user can influence it or interface with it) varies
8810 wildly, and we'll attempt no precise definition.
8812 @cindex test pass
8813 @cindex test failure
8814 A test is said to @emph{pass} when it can determine that the condition or
8815 behaviour it means to verify holds, and is said to @emph{fail} when it can
8816 determine that such condition of behaviour does @emph{not} hold.
8818 @cindex test skip
8819 Sometimes, tests can rely on non-portable tools or prerequisites, or
8820 simply make no sense on a given system (for example, a test checking a
8821 Windows-specific feature makes no sense on a GNU/Linux system).  In this
8822 case, accordingly to the definition above, the tests can neither be
8823 considered passed nor failed; instead, they are @emph{skipped} -- i.e.,
8824 they are not run, or their result is anyway ignored for what concerns
8825 the count of failures an successes.  Skips are usually explicitly
8826 reported though, so that the user will be aware that not all of the
8827 testsuite has really run.
8829 @cindex xfail
8830 @cindex expected failure
8831 @cindex expected test failure
8832 @cindex xpass
8833 @cindex unexpected pass
8834 @cindex unexpected test pass
8835 It's not uncommon, especially during early development stages, that some
8836 tests fail for known reasons, and that the developer doesn't want to
8837 tackle these failures immediately (this is especially true when the
8838 failing tests deal with corner cases).  In this situation, the better
8839 policy is to declare that each of those failures is an @emph{expected
8840 failure} (or @emph{xfail}).  In case a test that is expected to fail ends
8841 up passing instead, many testing environments will flag the result as a
8842 special kind of failure called @emph{unexpected pass} (or @emph{xpass}).
8844 @cindex hard error
8845 @cindex Distinction between errors and failures in testsuites
8846 Many testing environments and frameworks distinguish between test failures
8847 and hard errors.  As we've seen, a test failure happens when some invariant
8848 or expected behaviour of the software under test is not met.  An @emph{hard
8849 error} happens when e.g., the set-up of a test case scenario fails, or when
8850 some other unexpected or highly undesirable condition is encountered (for
8851 example, the program under test experiences a segmentation fault).
8853 @node Simple Tests
8854 @section Simple Tests
8856 @menu
8857 * Scripts-based Testsuites::    Automake-specific concepts and terminology
8858 * Serial Test Harness::         Older (and discouraged) serial test harness
8859 * Parallel Test Harness::       Generic concurrent test harness
8860 @end menu
8862 @node Scripts-based Testsuites
8863 @subsection Scripts-based Testsuites
8865 If the special variable @code{TESTS} is defined, its value is taken to be
8866 a list of programs or scripts to run in order to do the testing.  Under
8867 the appropriate circumstances, it's possible for @code{TESTS} to list
8868 also data files to be passed to one or more test scripts defined by
8869 different means (the so-called ``log compilers'', @pxref{Parallel Test
8870 Harness}).
8872 Test scripts can be executed serially or concurrently.  Automake supports
8873 both these kinds of test execution, with the parallel test harness being
8874 the default.  The concurrent test harness relies on the concurrence
8875 capabilities (if any) offered by the underlying @command{make}
8876 implementation, and can thus only be as good as those are.
8878 By default, only the exit statuses of the test scripts are considered when
8879 determining the testsuite outcome.  But Automake allows also the use of
8880 more complex test protocols, either standard (@pxref{Using the TAP test
8881 protocol}) or custom (@pxref{Custom Test Drivers}).  Note that you can't
8882 enable such protocols when the serial harness is used, though.
8883 In the rest of this section we are going to concentrate mostly on
8884 protocol-less tests, since we cover test protocols in a later section
8885 (again, @pxref{Custom Test Drivers}).
8887 @cindex Exit status 77, special interpretation
8888 @cindex Exit status 99, special interpretation
8889 When no test protocol is in use, an exit status of 0 from a test script will
8890 denote a success, an exit status of 77 a skipped test, an exit status of 99
8891 an hard error, and any other exit status will denote a failure.
8893 @cindex Tests, expected failure
8894 @cindex Expected test failure
8895 @vindex XFAIL_TESTS
8896 @vindex DISABLE_HARD_ERRORS
8897 @cindex Disabling hard errors
8898 You may define the variable @code{XFAIL_TESTS} to a list of tests
8899 (usually a subset of @code{TESTS}) that are expected to fail; this will
8900 effectively reverse the result of those tests (with the provision that
8901 skips and hard errors remain untouched).  You may also instruct the
8902 testsuite harness to treat hard errors like simple failures, by defining
8903 the @code{DISABLE_HARD_ERRORS} make variable to a nonempty value.
8905 Note however that, for tests based on more complex test protocols,
8906 the exact effects of @code{XFAIL_TESTS} and @code{DISABLE_HARD_ERRORS}
8907 might change, or they might even have no effect at all (for example,
8908 @c Keep this in sync with tap-no-disable-hard-errors.sh
8909 in tests using TAP, there is no way to disable hard errors, and the
8910 @code{DISABLE_HARD_ERRORS} variable has no effect on them).
8912 @anchor{Testsuite progress on console}
8913 @cindex Testsuite progress on console
8914 The result of each test case run by the scripts in @code{TESTS} will be
8915 printed on standard output, along with the test name.  For test protocols
8916 that allow more test cases per test script (such as TAP), a number,
8917 identifier and/or brief description specific for the single test case is
8918 expected to be printed in addition to the name of the test script.  The
8919 possible results (whose meanings should be clear from the previous
8920 @ref{Generalities about Testing}) are @code{PASS}, @code{FAIL},
8921 @code{SKIP}, @code{XFAIL}, @code{XPASS} and @code{ERROR}.  Here is an
8922 example of output from an hypothetical testsuite that uses both plain
8923 and TAP tests:
8924 @c Keep in sync with tap-doc.sh
8925 @example
8926 PASS: foo.sh
8927 PASS: zardoz.tap 1 - Daemon started
8928 PASS: zardoz.tap 2 - Daemon responding
8929 SKIP: zardoz.tap 3 - Daemon uses /proc # SKIP /proc is not mounted
8930 PASS: zardoz.tap 4 - Daemon stopped
8931 SKIP: bar.sh
8932 PASS: mu.tap 1
8933 XFAIL: mu.tap 2 # TODO frobnication not yet implemented
8934 @end example
8936 @noindent
8937 A testsuite summary (expected to report at least the number of run,
8938 skipped and failed tests) will be printed at the end of the testsuite
8939 run.
8941 @anchor{Simple tests and color-tests}
8942 @vindex AM_COLOR_TESTS
8943 @cindex Colorized testsuite output
8944 If the standard output is connected to a capable terminal, then the test
8945 results and the summary are colored appropriately.  The developer and the
8946 user can disable colored output by setting the @command{make} variable
8947 @samp{AM_COLOR_TESTS=no}; the user can in addition force colored output
8948 even without a connecting terminal with @samp{AM_COLOR_TESTS=always}.
8949 It's also worth noting that some @command{make} implementations,
8950 when used in parallel mode, have slightly different semantics
8951 (@pxref{Parallel make,,, autoconf, The Autoconf Manual}), which can
8952 break the automatic detection of a connection to a capable terminal.
8953 If this is the case, the user will have to resort to the use of
8954 @samp{AM_COLOR_TESTS=always} in order to have the testsuite output
8955 colorized.
8957 Test programs that need data files should look for them in @code{srcdir}
8958 (which is both a make variable and an environment variable made available
8959 to the tests), so that they work when building in a separate directory
8960 (@pxref{Build Directories, , Build Directories , autoconf,
8961 The Autoconf Manual}), and in particular for the @code{distcheck} rule
8962 (@pxref{Checking the Distribution}).
8964 @vindex TESTS
8965 @vindex TESTS_ENVIRONMENT
8966 @vindex AM_TESTS_ENVIRONMENT
8967 The @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables can
8968 be used to run initialization code and set environment variables for the
8969 test scripts.  The former variable is developer-reserved, and can be
8970 defined in the @file{Makefile.am}, while the latter is reserved for the
8971 user, which can employ it to extend or override the settings in the
8972 former; for this to work portably, however, the contents of a non-empty
8973 @code{AM_TESTS_ENVIRONMENT} @emph{must} be terminated by a semicolon.
8975 @vindex AM_TESTS_FD_REDIRECT
8976 The @code{AM_TESTS_FD_REDIRECT} variable can be used to define file
8977 descriptor redirections for the test scripts.  One might think that
8978 @code{AM_TESTS_ENVIRONMENT} could be used for this purpose, but experience
8979 has shown that doing so portably is practically impossible.  The main
8980 hurdle is constituted by Korn shells, which usually set the close-on-exec
8981 flag on file descriptors opened with the @command{exec} builtin, thus
8982 rendering an idiom like @code{AM_TESTS_ENVIRONMENT = exec 9>&2;}
8983 ineffectual.  This issue also affects some Bourne shells, such as the
8984 HP-UX's @command{/bin/sh},
8986 @c Keep in sync with tests-environment-backcompat.sh
8987 @example
8988 AM_TESTS_ENVIRONMENT = \
8989 ## Some environment initializations are kept in a separate shell
8990 ## file 'tests-env.sh', which can make it easier to also run tests
8991 ## from the command line.
8992   . $(srcdir)/tests-env.sh; \
8993 ## On Solaris, prefer more POSIX-compliant versions of the standard
8994 ## tools by default.
8995   if test -d /usr/xpg4/bin; then \
8996     PATH=/usr/xpg4/bin:$$PATH; export PATH; \
8997   fi;
8998 @c $$ restore font-lock
8999 ## With this, the test scripts will be able to print diagnostic
9000 ## messages to the original standard error stream, even if the test
9001 ## driver redirects the stderr of the test scripts to a log file
9002 ## before executing them.
9003 AM_TESTS_FD_REDIRECT = 9>&2
9004 @end example
9006 @noindent
9007 Note however that @code{AM_TESTS_ENVIRONMENT} is, for historical and
9008 implementation reasons, @emph{not} supported by the serial harness
9009 (@pxref{Serial Test Harness}).
9011 Automake ensures that each file listed in @code{TESTS} is built before
9012 it is run; you can list both source and derived programs (or scripts)
9013 in @code{TESTS}; the generated rule will look both in @code{srcdir} and
9014 @file{.}.  For instance, you might want to run a C program as a test.
9015 To do this you would list its name in @code{TESTS} and also in
9016 @code{check_PROGRAMS}, and then specify it as you would any other
9017 program.
9019 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
9020 @code{check_LTLIBRARIES}...) are only built during @code{make check},
9021 not during @code{make all}.  You should list there any program needed
9022 by your tests that does not need to be built by @code{make all}.  Note
9023 that @code{check_PROGRAMS} are @emph{not} automatically added to
9024 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
9025 by the tests, not the tests themselves.  Of course you can set
9026 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
9028 @node Serial Test Harness
9029 @subsection Older (and discouraged) serial test harness
9030 @cindex @option{serial-tests}, Using
9032 First, note that today the use of this harness is strongly discouraged in
9033 favour of the parallel test harness (@pxref{Parallel Test Harness}).
9034 Still, there are @emph{few} situations when the advantages offered by
9035 the parallel harness are irrelevant, and when test concurrency can
9036 even cause tricky problems.  In those cases, it might make sense to
9037 still use the serial harness, for simplicity and reliability (we still
9038 suggest trying to give the parallel harness a shot though).
9040 The serial test harness is enabled by the Automake option
9041 @option{serial-tests}. It operates by simply running the tests serially,
9042 one at the time, without any I/O redirection.  It's up to the user to
9043 implement logging of tests' output, if that's required or desired.
9045 For historical and implementation reasons, the @code{AM_TESTS_ENVIRONMENT}
9046 variable is @emph{not} supported by this harness (it will be silently
9047 ignored if defined); only @code{TESTS_ENVIRONMENT} is, and it is to be
9048 considered a developer-reserved variable.  This is done so that, when
9049 using the serial harness, @code{TESTS_ENVIRONMENT} can be defined to an
9050 invocation of an interpreter through which the tests are to be run.
9051 For instance, the following setup may be used to run tests with Perl:
9053 @example
9054 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
9055 TESTS = foo.pl bar.pl baz.pl
9056 @end example
9058 @noindent
9059 It's important to note that the use of @code{TESTS_ENVIRONMENT} endorsed
9060 here would be @emph{invalid} with the parallel harness.  That harness
9061 provides a more elegant way to achieve the same effect, with the further
9062 benefit of freeing the @code{TESTS_ENVIRONMENT} variable for the user
9063 (@pxref{Parallel Test Harness}).
9065 Another, less serious limit of the serial harness is that it doesn't
9066 really distinguish between simple failures and hard errors; this is
9067 due to historical reasons only, and might be fixed in future Automake
9068 versions.
9070 @node Parallel Test Harness
9071 @subsection Parallel Test Harness
9073 By default, Automake generated a parallel (concurrent) test harness.  It
9074 features automatic collection of the test scripts output in @file{.log}
9075 files, concurrent execution of tests with @code{make -j}, specification
9076 of inter-test dependencies, lazy reruns of tests that have not completed
9077 in a prior run, and hard errors for exceptional failures.
9079 @anchor{Basics of test metadata}
9080 @vindex TEST_SUITE_LOG
9081 @vindex TESTS
9082 @cindex @file{.log} files
9083 @cindex @file{.trs} files
9084 @cindex test metadata
9085 The parallel test harness operates by defining a set of @command{make}
9086 rules that run the test scripts listed in @code{TESTS}, and, for each
9087 such script, save its output in a corresponding @file{.log} file and
9088 its results (and other ``metadata'', @pxref{API for Custom Test Drivers})
9089 in a corresponding @file{.trs} (as in @b{T}est @b{R}e@b{S}ults) file.
9090 @c We choose the '.trs' extension also because, at the time of writing,
9091 @c it isn't already used for other significant purposes; see e.g.:
9092 @c   - http://filext.com/file-extension/trs
9093 @c   - http://www.file-extensions.org/search/?searchstring=trs
9094 The @file{.log} file will contain all the output emitted by the test on
9095 its standard output and its standard error.  The @file{.trs} file will
9096 contain, among the other things, the results of the test cases run by
9097 the script.
9099 The parallel test harness will also create a summary log file,
9100 @code{TEST_SUITE_LOG}, which defaults to @file{test-suite.log} and requires
9101 a @file{.log} suffix.  This file depends upon all the @file{.log} and
9102 @file{.trs} files created for the test scripts listed in @code{TESTS}.
9104 @vindex VERBOSE
9105 As with the serial harness above, by default one status line is printed
9106 per completed test, and a short summary after the suite has completed.
9107 However, standard output and standard error of the test are redirected
9108 to a per-test log file, so that parallel execution does not produce
9109 intermingled output.  The output from failed tests is collected in the
9110 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
9111 file is output after the summary.
9113 @vindex TEST_EXTENSIONS
9114 @vindex TEST_LOGS
9115 Each couple of @file{.log} and @file{.trs} files is created when the
9116 corresponding test has completed.  The set of log files is listed in
9117 the read-only variable @code{TEST_LOGS}, and defaults to @code{TESTS},
9118 with the executable extension if any (@pxref{EXEEXT}), as well as any
9119 suffix listed in @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
9120 Results are undefined if a test file name ends in several concatenated
9121 suffixes.  @code{TEST_EXTENSIONS} defaults to @file{.test}; it can be
9122 overridden by the user, in which case any extension listed in it must be
9123 constituted by a dot, followed by a non-digit alphabetic character,
9124 followed by any number of alphabetic characters.
9125 @c Keep in sync with test-extensions.sh
9126 For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
9127 while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
9129 @cindex Configure substitutions in @code{TESTS}
9130 It is important to note that, due to current limitations (unlikely to be
9131 lifted), configure substitutions in the definition of @code{TESTS} can
9132 only work if they will expand to a list of tests that have a suffix listed
9133 in @code{TEST_EXTENSIONS}.
9135 @vindex _LOG_COMPILE
9136 @vindex _LOG_COMPILER
9137 @vindex _LOG_FLAGS
9138 @vindex LOG_COMPILE
9139 @vindex LOG_COMPILER
9140 @vindex LOG_FLAGS
9141 @vindex @var{ext}_LOG_COMPILE
9142 @vindex @var{ext}_LOG_COMPILER
9143 @vindex @var{ext}_LOG_FLAGS
9144 @vindex AM_@var{ext}_LOG_FLAGS
9145 @vindex AM_LOG_FLAGS
9146 For tests that match an extension @code{.@var{ext}} listed in
9147 @code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using
9148 the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case
9149 extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow
9150 the user to pass options in @code{@var{ext}_LOG_FLAGS}.  It will cause
9151 all tests with this extension to be called with this runner.  For all
9152 tests without a registered extension, the variables @code{LOG_COMPILER},
9153 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
9155 @c Keep in sync with parallel-tests-log-compiler-example.sh
9156 @example
9157 TESTS = foo.pl bar.py baz
9158 TEST_EXTENSIONS = .pl .py
9159 PL_LOG_COMPILER = $(PERL)
9160 AM_PL_LOG_FLAGS = -w
9161 PY_LOG_COMPILER = $(PYTHON)
9162 AM_PY_LOG_FLAGS = -v
9163 LOG_COMPILER = ./wrapper-script
9164 AM_LOG_FLAGS = -d
9165 @end example
9167 @noindent
9168 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
9169 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
9170 @file{bar.log}, and @file{baz.log}, respectively.  The @file{foo.trs},
9171 @file{bar.trs} and @file{baz.trs} files will be automatically produced
9172 as a side-effect.
9174 It's important to note that, differently from what we've seen for the
9175 serial test harness (@pxref{Serial Test Harness}), the
9176 @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables
9177 @emph{cannot} be used to define a custom test runner; the
9178 @code{LOG_COMPILER} and @code{LOG_FLAGS} (or their extension-specific
9179 counterparts) should be used instead:
9181 @example
9182 ## This is WRONG!
9183 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib' $(PERL) -Mstrict -w
9184 @end example
9186 @example
9187 ## Do this instead.
9188 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib'; export PERL5LIB;
9189 LOG_COMPILER = $(PERL)
9190 AM_LOG_FLAGS = -Mstrict -w
9191 @end example
9193 By default, the test suite harness will run all tests, but there are
9194 several ways to limit the set of tests that are run:
9196 @itemize @bullet
9197 @item
9198 You can set the @code{TESTS} variable.  For example, you can use a
9199 command like this to run only a subset of the tests:
9201 @example
9202 env TESTS="foo.test bar.test" make -e check
9203 @end example
9205 Note however that the command above will unconditionally overwrite the
9206 @file{test-suite.log} file, thus clobbering the recorded results
9207 of any previous testsuite run.  This might be undesirable for packages
9208 whose testsuite takes long time to execute.  Luckily, this problem can
9209 easily be avoided by overriding also @code{TEST_SUITE_LOG} at runtime;
9210 for example,
9212 @c Keep in sync with parallel-tests-log-override-2.sh
9213 @example
9214 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
9215 @end example
9217 will write the result of the partial testsuite runs to the
9218 @file{partial.log}, without touching @file{test-suite.log}.
9220 @item
9221 You can set the @code{TEST_LOGS} variable.  By default, this variable is
9222 computed at @command{make} run time from the value of @code{TESTS} as
9223 described above.  For example, you can use the following:
9225 @example
9226 set x subset*.log; shift
9227 env TEST_LOGS="foo.log $*" make -e check
9228 @end example
9230 The comments made above about @code{TEST_SUITE_LOG} overriding applies
9231 here too.
9233 @item
9234 @vindex RECHECK_LOGS
9235 @cindex lazy test execution
9236 By default, the test harness removes all old per-test @file{.log} and
9237 @file{.trs} files before it starts running tests to regenerate them.  The
9238 variable @code{RECHECK_LOGS} contains the set of @file{.log} (and, by
9239 implication, @file{.trs}) files which are removed.  @code{RECHECK_LOGS}
9240 defaults to @code{TEST_LOGS}, which means all tests need to be rechecked.
9241 By overriding this variable, you can choose which tests need to be
9242 reconsidered.  For example, you can lazily rerun only those tests which
9243 are outdated, i.e., older than their prerequisite test files, by setting
9244 this variable to the empty value:
9246 @example
9247 env RECHECK_LOGS= make -e check
9248 @end example
9250 @item
9251 @trindex recheck
9252 You can ensure that all tests are rerun which have failed or passed
9253 unexpectedly, by running @code{make recheck} in the test directory.
9254 This convenience target will set @code{RECHECK_LOGS} appropriately
9255 before invoking the main test harness.
9256 @end itemize
9258 @noindent
9259 In order to guarantee an ordering between tests even with @code{make
9260 -j@var{N}}, dependencies between the corresponding @file{.log} files
9261 may be specified through usual @command{make} dependencies.  For example,
9262 the following snippet lets the test named @file{foo-execute.test} depend
9263 upon completion of the test @file{foo-compile.test}:
9265 @example
9266 TESTS = foo-compile.test foo-execute.test
9267 foo-execute.log: foo-compile.log
9268 @end example
9270 @noindent
9271 Please note that this ordering ignores the @emph{results} of required
9272 tests, thus the test @file{foo-execute.test} is run even if the test
9273 @file{foo-compile.test} failed or was skipped beforehand.  Further,
9274 please note that specifying such dependencies currently works only for
9275 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
9277 Tests without such specified dependencies may be run concurrently with
9278 parallel @command{make -j@var{N}}, so be sure they are prepared for
9279 concurrent execution.
9281 @cindex Unit tests
9282 @c Keep in sync with 'parallel-tests-extra-programs.sh'.
9283 The combination of lazy test execution and correct dependencies between
9284 tests and their sources may be exploited for efficient unit testing
9285 during development.  To further speed up the edit-compile-test cycle, it
9286 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
9287 instead of with @code{check_PROGRAMS}, as the former allows intertwined
9288 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
9289 not cleaned automatically, @pxref{Uniform}).
9291 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
9292 conditional parts as well as configure substitutions.  In the latter
9293 case, however, certain restrictions apply: substituted test names
9294 must end with a nonempty test suffix like @file{.test}, so that one of
9295 the inference rules generated by @command{automake} can apply.  For
9296 literal test names, @command{automake} can generate per-target rules
9297 to avoid this limitation.
9299 Please note that it is currently not possible to use @code{$(srcdir)/}
9300 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
9301 limitation is necessary to avoid generating test logs in the source tree
9302 and has the unfortunate consequence that it is not possible to specify
9303 distributed tests that are themselves generated by means of explicit
9304 rules, in a way that is portable to all @command{make} implementations
9305 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
9306 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
9307 In case of doubt you may want to require to use GNU @command{make},
9308 or work around the issue with inference rules to generate the tests.
9310 @node Custom Test Drivers
9311 @section Custom Test Drivers
9313 @menu
9314 * Overview of Custom Test Drivers Support::
9315 * Declaring Custom Test Drivers::
9316 * API for Custom Test Drivers::
9317 @end menu
9319 @node Overview of Custom Test Drivers Support
9320 @subsection Overview of Custom Test Drivers Support
9322 Starting from Automake version 1.12, the parallel test harness allows
9323 the package authors to use third-party custom test drivers, in case the
9324 default ones are inadequate for their purposes, or do not support their
9325 testing protocol of choice.
9327 A custom test driver is expected to properly run the test programs passed
9328 to it (including the command-line arguments passed to those programs, if
9329 any), to analyze their execution and outcome, to create the @file{.log}
9330 and @file{.trs} files associated to these test runs, and to display the test
9331 results on the console. It is responsibility of the author of the test
9332 driver to ensure that it implements all the above steps meaningfully and
9333 correctly; Automake isn't and can't be of any help here.  On the other
9334 hand, the Automake-provided code for testsuite summary generation offers
9335 support for test drivers allowing several test results per test script,
9336 if they take care to register such results properly (@pxref{Log files
9337 generation and test results recording}).
9339 The exact details of how test scripts' results are to be determined and
9340 analyzed is left to the individual drivers.  Some drivers might only
9341 consider the test script exit status (this is done for example by the
9342 default test driver used by the parallel test harness, described
9343 in the previous section).  Other drivers might implement more complex and
9344 advanced test protocols, which might require them to parse and interpreter
9345 the output emitted by the test script they're running (examples of such
9346 protocols are TAP and SubUnit).
9348 It's very important to note that, even when using custom test drivers,
9349 most of the infrastructure described in the previous section about the
9350 parallel harness remains in place; this includes:
9352 @itemize
9353 @item
9354 list of test scripts defined in @code{TESTS}, and overridable at
9355 runtime through the redefinition of @code{TESTS} or @code{TEST_LOGS};
9356 @item
9357 concurrency through the use of @command{make}'s option @option{-j};
9358 @item
9359 per-test @file{.log} and @file{.trs} files, and generation of a summary
9360 @file{.log} file from them;
9361 @item
9362 @code{recheck} target, @code{RECHECK_LOGS} variable, and lazy reruns
9363 of tests;
9364 @item
9365 inter-test dependencies;
9366 @item
9367 support for @code{check_*} variables (@code{check_PROGRAMS},
9368 @code{check_LIBRARIES}, ...);
9369 @item
9370 use of @code{VERBOSE} environment variable to get verbose output on
9371 testsuite failures;
9372 @item
9373 definition and honoring of @code{TESTS_ENVIRONMENT},
9374 @code{AM_TESTS_ENVIRONMENT} and @code{AM_TESTS_FD_REDIRECT}
9375 variables;
9376 @item
9377 definition of generic and extension-specific @code{LOG_COMPILER} and
9378 @code{LOG_FLAGS} variables.
9379 @end itemize
9381 @noindent
9382 On the other hand, the exact semantics of how (and if) testsuite output
9383 colorization, @code{XFAIL_TESTS}, and hard errors are supported and
9384 handled is left to the individual test drivers.
9386 @c TODO: We should really add a working example in the doc/ directory,
9387 @c TODO: and reference if from here.
9389 @node Declaring Custom Test Drivers
9390 @subsection Declaring Custom Test Drivers
9392 @vindex _LOG_DRIVER
9393 @vindex _LOG_DRIVER_FLAGS
9394 @vindex LOG_DRIVER
9395 @vindex LOG_DRIVER_FLAGS
9396 @vindex @var{ext}_LOG_DRIVER
9397 @vindex @var{ext}_LOG_DRIVER_FLAGS
9398 @vindex AM_@var{ext}_LOG_DRIVER_FLAGS
9399 @vindex AM_LOG_DRIVER_FLAGS
9400 Custom testsuite drivers are declared by defining the make variables
9401 @code{LOG_DRIVER} or @code{@var{ext}_LOG_DRIVER} (where @var{ext} must
9402 be declared in @code{TEST_EXTENSIONS}).  They must be defined to
9403 programs or scripts that will be used to drive the execution, logging,
9404 and outcome report of the tests with corresponding extensions (or of
9405 those with no registered extension in the case of @code{LOG_DRIVER}).
9406 Clearly, multiple distinct test drivers can be declared in the same
9407 @file{Makefile.am}.  Note moreover that the @code{LOG_DRIVER} variables
9408 are @emph{not} a substitute for the @code{LOG_COMPILER} variables: the
9409 two sets of variables can, and often do, usefully and legitimately
9410 coexist.
9412 @c TODO: We should really be able to point to a clarifying example here!
9414 The developer-reserved variable @code{AM_LOG_DRIVER_FLAGS} and the
9415 user-reserved variable @code{LOG_DRIVER_FLAGS} can be used to define
9416 flags that will be passed to each invocation of @code{LOG_DRIVER},
9417 with the user-defined flags obviously taking precedence over the
9418 developer-reserved ones.  Similarly, for each extension @var{ext}
9419 declared in @code{TEST_EXTENSIONS}, flags listed in
9420 @code{AM_@var{ext}_LOG_DRIVER_FLAGS} and
9421 @code{@var{ext}_LOG_DRIVER_FLAGS} will be passed to
9422 invocations of @code{@var{ext}_LOG_DRIVER}.
9424 @node API for Custom Test Drivers
9425 @subsection API for Custom Test Drivers
9427 Note that @emph{the APIs described here are still highly experimental},
9428 and will very likely undergo tightenings and likely also extensive changes
9429 in the future, to accommodate for new features or to satisfy additional
9430 portability requirements.
9432 The main characteristic of these APIs is that they are designed to share
9433 as much infrastructure, semantics, and implementation details as possible
9434 with the parallel test harness and its default driver.
9436 @menu
9437 * Command-line arguments for test drivers::
9438 * Log files generation and test results recording::
9439 * Testsuite progress output::
9440 @end menu
9442 @node Command-line arguments for test drivers
9443 @subsubsection Command-line arguments for test drivers
9445 A custom driver can rely on various command-line options and arguments
9446 being passed to it automatically by the Automake-generated test harness.
9447 It is @emph{mandatory} that it understands all of them (even if the exact
9448 interpretation of the associated semantics can legitimately change
9449 between a test driver and another, and even be a no-op in some drivers).
9451 @noindent
9452 Here is the list of options:
9454 @table @option
9455 @item --test-name=@var{NAME}
9456 The name of the test, with VPATH prefix (if any) removed.  This can have a
9457 suffix and a directory component (as in e.g., @file{sub/foo.test}), and is
9458 mostly meant to be used in console reports about testsuite advancements and
9459 results (@pxref{Testsuite progress output}).
9460 @item --log-file=@file{@var{PATH}.log}
9461 The @file{.log} file the test driver must create (@pxref{Basics of
9462 test metadata}).  If it has a directory component (as in e.g.,
9463 @file{sub/foo.log}), the test harness will ensure that such directory
9464 exists @emph{before} the test driver is called.
9465 @item --trs-file=@file{@var{PATH}.trs}
9466 The @file{.trs} file the test driver must create (@pxref{Basics of
9467 test metadata}).  If it has a directory component (as in e.g.,
9468 @file{sub/foo.trs}), the test harness will ensure that such directory
9469 exists @emph{before} the test driver is called.
9470 @item --color-tests=@{yes|no@}
9471 Whether the console output should be colorized or not (@pxref{Simple
9472 tests and color-tests}, to learn when this option gets activated and
9473 when it doesn't).
9474 @item --expect-failure=@{yes|no@}
9475 Whether the tested program is expected to fail.
9476 @item --enable-hard-errors=@{yes|no@}
9477 Whether ``hard errors'' in the tested program should be treated differently
9478 from normal failures or not (the default should be @code{yes}).  The exact
9479 meaning of ``hard error'' is highly dependent from the test protocols or
9480 conventions in use.
9481 @item --
9482 Explicitly terminate the list of options.
9483 @end table
9485 @noindent
9486 The first non-option argument passed to the test driver is the program to
9487 be run, and all the following ones are command-line options and arguments
9488 for this program.
9490 Note that the exact semantics attached to the @option{--color-tests},
9491 @option{--expect-failure} and @option{--enable-hard-errors} options are
9492 left up to the individual test drivers.  Still, having a behaviour
9493 compatible or at least similar to that provided by the default driver
9494 is advised, as that would offer a better consistency and a more pleasant
9495 user experience.
9497 @node Log files generation and test results recording
9498 @subsubsection Log files generation and test results recording
9500 The test driver must correctly generate the files specified by the
9501 @option{--log-file} and @option{--trs-file} option (even when the tested
9502 program fails or crashes).
9504 The @file{.log} file should ideally contain all the output produced by the
9505 tested program, plus optionally other information that might facilitate
9506 debugging or analysis of bug reports.  Apart from that, its format is
9507 basically free.
9509 The @file{.trs} file is used to register some metadata through the use
9510 of custom reStructuredText fields.  This metadata is expected to be
9511 employed in various ways by the parallel test harness; for example, to
9512 count the test results when printing the testsuite summary, or to decide
9513 which tests to re-run upon @command{make recheck}.  Unrecognized metadata
9514 in a @file{.trs} file is currently ignored by the harness, but this might
9515 change in the future. The list of currently recognized metadata follows.
9517 @table @code
9519 @item :test-result:
9520 @cindex Register test result
9521 @cindex Register test case result
9522 @cindex Test result, registering
9523 @cindex Test case result, registering
9524 @cindex @code{:test-result:}
9525 @cindex reStructuredText field, @code{:test-result:}
9526 The test driver must use this field to register the results of @emph{each}
9527 test case run by a test script file.  Several @code{:test-result:} fields
9528 can be present in the same @file{.trs} file; this is done in order to
9529 support test protocols that allow a single test script to run more test
9530 cases.
9532 @c Keep this in sync with lib/am/check-am:$(TEST_SUITE_LOG).
9533 The only recognized test results are currently @code{PASS}, @code{XFAIL},
9534 @code{SKIP}, @code{FAIL}, @code{XPASS} and @code{ERROR}.  These results,
9535 when declared with @code{:test-result:}, can be optionally followed by
9536 text holding the name and/or a brief description of the corresponding
9537 test; the harness will ignore such extra text when generating
9538 @file{test-suite.log} and preparing the testsuite summary.
9540 @c Keep in sync with 'test-metadata-recheck.sh'.
9541 @item @code{:recheck:}
9542 @cindex :recheck:
9543 @cindex reStructuredText field, @code{:recheck:}
9544 If this field is present and defined to @code{no}, then the corresponding
9545 test script will @emph{not} be run upon a @command{make recheck}.  What
9546 happens when two or more @code{:recheck:} fields are present in the same
9547 @file{.trs} file is undefined behaviour.
9549 @c Keep in sync with 'test-metadata-global-log.sh'.
9550 @item @code{:copy-in-global-log:}
9551 @cindex :copy-in-global-log:
9552 @cindex reStructuredText field, @code{:copy-in-global-log:}
9553 If this field is present and defined to @code{no}, then the content
9554 of the @file{.log} file will @emph{not} be copied into the global
9555 @file{test-suite.log}.  We allow to forsake such copying because, while
9556 it can be useful in debugging and analysis of bug report, it can also be
9557 just a waste of space in normal situations, e.g., when a test script is
9558 successful.  What happens when two or more @code{:copy-in-global-log:}
9559 fields are present in the same @file{.trs} file is undefined behaviour.
9561 @c Keep in sync with 'test-metadata-global-result.sh'.
9562 @item @code{:test-global-result:}
9563 @cindex :test-global-result:
9564 @cindex reStructuredText field, @code{:test-global-result:}
9565 This is used to declare the "global result" of the script.  Currently,
9566 the value of this field is needed only to be reported (more or less
9567 verbatim) in the generated global log file @code{$(TEST_SUITE_LOG)},
9568 so it's quite free-form.  For example, a test script which run 10 test
9569 cases, 6 of which pass and 4 of which are skipped, could reasonably have
9570 a @code{PASS/SKIP} value for this field, while a test script which run
9571 19 successful tests and one failed test could have an @code{ALMOST
9572 PASSED} value.  What happens when two or more @code{:test-global-result:}
9573 fields are present in the same @file{.trs} file is undefined behaviour.
9574 @end table
9576 @noindent
9577 Let's see a small example.  Assume a @file{.trs} file contains the
9578 following lines:
9580 @example
9581 :test-result: PASS server starts
9582 :global-log-copy: no
9583 :test-result: PASS HTTP/1.1 request
9584 :test-result: FAIL HTTP/1.0 request
9585 :recheck: yes
9586 :test-result: SKIP HTTPS request (TLS library wasn't available)
9587 :test-result: PASS server stops
9588 @end example
9590 @noindent
9591 Then the corresponding test script will be re-run by @command{make check},
9592 will contribute with @emph{five} test results to the testsuite summary
9593 (three of these tests being successful, one failed, and one skipped), and
9594 the content of the corresponding @file{.log} file will @emph{not} be
9595 copied in the global log file @file{test-suite.log}.
9597 @node Testsuite progress output
9598 @subsubsection Testsuite progress output
9600 A custom test driver also has the task of displaying, on the standard
9601 output, the test results as soon as they become available.  Depending on
9602 the protocol in use, it can also display the reasons for failures and
9603 skips, and, more generally, any useful diagnostic output (but remember
9604 that each line on the screen is precious, so that cluttering the screen
9605 with overly verbose information is bad idea).  The exact format of this
9606 progress output is left up to the test driver; in fact, a custom test
9607 driver might @emph{theoretically} even decide not to do any such report,
9608 leaving it all to the testsuite summary (that would be a very lousy idea,
9609 of course, and serves only to illustrate the flexibility that is
9610 granted here).
9612 Remember that consistency is good; so, if possible, try to be consistent
9613 with the output of the built-in Automake test drivers, providing a similar
9614 ``look & feel''.  In particular, the testsuite progress output should be
9615 colorized when the @option{--color-tests} is passed to the driver.  On the
9616 other end, if you are using a known and widespread test protocol with
9617 well-established implementations, being consistent with those
9618 implementations' output might be a good idea too.
9620 @node Using the TAP test protocol
9621 @section Using the TAP test protocol
9623 @menu
9624 * Introduction to TAP::
9625 * Use TAP with the Automake test harness::
9626 * Incompatibilities with other TAP parsers and drivers::
9627 * Links and external resources on TAP::
9628 @end menu
9630 @node Introduction to TAP
9631 @subsection Introduction to TAP
9633 TAP, the Test Anything Protocol, is a simple text-based interface between
9634 testing modules or programs and a test harness.  The tests (also called
9635 ``TAP producers'' in this context) write test results in a simple format
9636 on standard output; a test harness (also called ``TAP consumer'') will
9637 parse and interpret these results, and properly present them to the user,
9638 and/or register them for later analysis.  The exact details of how this
9639 is accomplished can vary among different test harnesses.  The Automake
9640 harness will present the results on the console in the usual
9641 fashion (@pxref{Testsuite progress on console}), and will use the
9642 @file{.trs} files (@pxref{Basics of test metadata}) to store the test
9643 results and related metadata.  Apart from that, it will try to remain
9644 as much compatible as possible with pre-existing and widespread utilities,
9645 such as the @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9646 @command{prove} utility}, at least for the simpler usages.
9648 TAP started its life as part of the test harness for Perl, but today
9649 it has been (mostly) standardized, and has various independent
9650 implementations in different languages; among them, C, C++, Perl,
9651 Python, PHP, and Java.  For a semi-official specification of the
9652 TAP protocol, please refer to the documentation of
9653 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9654       @samp{Test::Harness::TAP}}.
9656 The most relevant real-world usages of TAP are obviously in the testsuites
9657 of @command{perl} and of many perl modules.  Still, also other important
9658 third-party packages, such as @uref{http://git-scm.com/, @command{git}},
9659 use TAP in their testsuite.
9661 @node Use TAP with the Automake test harness
9662 @subsection Use TAP with the Automake test harness
9664 Currently, the TAP driver that comes with Automake requires some by-hand
9665 steps on the developer's part (this situation should hopefully be improved
9666 in future Automake versions).  You'll have to grab the @file{tap-driver.sh}
9667 script from the Automake distribution by hand, copy it in your source tree,
9668 and use the Automake support for third-party test drivers to instruct the
9669 harness to use the @file{tap-driver.sh} script and the awk program found
9670 by @code{AM_INIT_AUTOMAKE} to run your TAP-producing tests.  See the example
9671 below for clarification.
9673 Apart from the options common to all the Automake test drivers
9674 (@pxref{Command-line arguments for test drivers}), the @file{tap-driver.sh}
9675 supports the following options, whose names are chosen for enhanced
9676 compatibility with the @command{prove} utility.
9678 @table @option
9679 @c Keep in sync with 'tap-exit.sh' and 'tap-signal.tap'.
9680 @item --ignore-exit
9681 Causes the test driver to ignore the exit status of the test scripts;
9682 by default, the driver will report an error if the script exits with a
9683 non-zero status.  This option has effect also on non-zero exit statuses
9684 due to termination by a signal.
9685 @item --comments
9686 Instruct the test driver to display TAP diagnostic (i.e., lines beginning
9687 with the @samp{#} character) in the testsuite progress output too; by
9688 default, TAP diagnostic is only copied to the @file{.log} file.
9689 @item --no-comments
9690 Revert the effects of @option{--comments}.
9691 @item --merge
9692 Instruct the test driver to merge the test scripts' standard error into
9693 their standard output.  This is necessary if you want to ensure that
9694 diagnostics from the test scripts are displayed in the correct order
9695 relative to test results; this can be of great help in debugging
9696 (especially if your test scripts are shell scripts run with shell
9697 tracing active).  As a downside, this option might cause the test
9698 harness to get confused if anything that appears on standard error
9699 looks like a test result.
9700 @item --no-merge
9701 Revert the effects of @option{--merge}.
9702 @item --diagnostic-string=@var{STRING}
9703 Change the string that introduces TAP diagnostic from the default value
9704 of ``@code{#}'' to @code{@var{STRING}}.  This can be useful if your
9705 TAP-based test scripts produce verbose output on which they have limited
9706 control (because, say, the output comes from other tools invoked in the
9707 scripts), and it might contain text that gets spuriously interpreted as
9708 TAP diagnostic: such an issue can be solved by redefining the string that
9709 activates TAP diagnostic to a value you know won't appear by chance in
9710 the tests' output.  Note however that this feature is non-standard, as
9711 the ``official'' TAP protocol does not allow for such a customization; so
9712 don't use it if you can avoid it.
9713 @end table
9715 @noindent
9716 Here is an example of how the TAP driver can be set up and used.
9718 @c Keep in sync with tap-doc2.sh
9719 @example
9720 % @kbd{cat configure.ac}
9721 AC_INIT([GNU Try Tap], [1.0], [bug-automake@@gnu.org])
9722 AC_CONFIG_AUX_DIR([build-aux])
9723 AM_INIT_AUTOMAKE([foreign -Wall -Werror])
9724 AC_CONFIG_FILES([Makefile])
9725 AC_REQUIRE_AUX_FILE([tap-driver.sh])
9726 AC_OUTPUT
9728 % @kbd{cat Makefile.am}
9729 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
9730                   $(top_srcdir)/build-aux/tap-driver.sh
9731 TESTS = foo.test bar.test baz.test
9732 EXTRA_DIST = $(TESTS)
9734 % @kbd{cat foo.test}
9735 #!/bin/sh
9736 echo 1..4 # Number of tests to be executed.
9737 echo 'ok 1 - Swallows fly'
9738 echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
9739 echo 'ok 3 - Pigs fly # SKIP not enough acid'
9740 echo '# I just love word plays ...'
9741 echo 'ok 4 - Flies fly too :-)'
9743 % @kbd{cat bar.test}
9744 #!/bin/sh
9745 echo 1..3
9746 echo 'not ok 1 - Bummer, this test has failed.'
9747 echo 'ok 2 - This passed though.'
9748 echo 'Bail out! Ennui kicking in, sorry...'
9749 echo 'ok 3 - This will not be seen.'
9751 % @kbd{cat baz.test}
9752 #!/bin/sh
9753 echo 1..1
9754 echo ok 1
9755 # Exit with error, even if all the tests have been successful.
9756 exit 7
9758 % @kbd{cp @var{PREFIX}/share/automake-@var{APIVERSION}/tap-driver.sh .}
9759 % @kbd{autoreconf -vi && ./configure && make check}
9761 PASS: foo.test 1 - Swallows fly
9762 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9763 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9764 PASS: foo.test 4 - Flies fly too :-)
9765 FAIL: bar.test 1 - Bummer, this test has failed.
9766 PASS: bar.test 2 - This passed though.
9767 ERROR: bar.test - Bail out! Ennui kicking in, sorry...
9768 PASS: baz.test 1
9769 ERROR: baz.test - exited with status 7
9771 Please report to bug-automake@@gnu.org
9773 % @kbd{echo exit status: $?}
9774 exit status: 1
9776 @c Keep the "skewed" indentation below, it produces pretty PDF output.
9777 % @kbd{env TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit' \
9778       TESTS='foo.test baz.test' make -e check}
9780 PASS: foo.test 1 - Swallows fly
9781 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9782 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9783 # foo.test: I just love word plays...
9784 PASS: foo.test 4 - Flies fly too :-)
9785 PASS: baz.test 1
9787 % @kbd{echo exit status: $?}
9788 exit status: 0
9789 @end example
9791 @node Incompatibilities with other TAP parsers and drivers
9792 @subsection Incompatibilities with other TAP parsers and drivers
9794 For implementation or historical reasons, the TAP driver and harness as
9795 implemented by Automake have some minors incompatibilities with the
9796 mainstream versions, which you should be aware of.
9798 @itemize @bullet
9799 @item
9800 A @code{Bail out!} directive doesn't stop the whole testsuite, but only
9801 the test script it occurs in.  This doesn't follow TAP specifications,
9802 but on the other hand it maximizes compatibility (and code sharing) with
9803 the ``hard error'' concept of the default testsuite driver.
9804 @item
9805 The @code{version} and @code{pragma} directives are not supported.
9806 @item
9807 The @option{--diagnostic-string} option of our driver allows to modify
9808 the string that introduces TAP diagnostic from the default value
9809 of ``@code{#}''.  The standard TAP protocol has currently no way to
9810 allow this, so if you use it your diagnostic will be lost to more
9811 compliant tools like @command{prove} and @code{Test::Harness}
9812 @item
9813 And there are probably some other small and yet undiscovered
9814 incompatibilities, especially in corner cases or with rare usages.
9815 @end itemize
9817 @node Links and external resources on TAP
9818 @subsection Links and external resources on TAP
9820 @noindent
9821 Here are some links to more extensive official or third-party
9822 documentation and resources about the TAP protocol and related
9823 tools and libraries.
9824 @itemize @bullet
9825 @item
9826 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9827       @samp{Test::Harness::TAP}},
9828 the (mostly) official documentation about the TAP format and protocol.
9829 @item
9830 @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9831       @command{prove}},
9832 the most famous command-line TAP test driver, included in the distribution
9833 of @command{perl} and
9834 @uref{http://search.cpan.org/~andya/Test-Harness/lib/Test/Harness.pm,
9835       @samp{Test::Harness}}.
9836 @item
9837 The @uref{http://testanything.org/wiki/index.php/Main_Page,TAP wiki}.
9838 @item
9839 A ``gentle introduction'' to testing for perl coders:
9840 @uref{http://search.cpan.org/dist/Test-Simple/lib/Test/Tutorial.pod,
9841       @samp{Test::Tutorial}}.
9842 @item
9843 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/Simple.pm,
9844       @samp{Test::Simple}}
9846 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/More.pm,
9847       @samp{Test::More}},
9848 the standard perl testing libraries, which are based on TAP.
9849 @item
9850 @uref{http://www.eyrie.org/~eagle/software/c-tap-harness/,C TAP Harness},
9851 a C-based project implementing both a TAP producer and a TAP consumer.
9852 @item
9853 @uref{http://www.tap4j.org/,tap4j},
9854 a Java-based project implementing both a TAP producer and a TAP consumer.
9855 @end itemize
9857 @node DejaGnu Tests
9858 @section DejaGnu Tests
9860 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
9861 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
9862 assumed.  The variable @code{DEJATOOL} is a list of names that are
9863 passed, one at a time, as the @option{--tool} argument to
9864 @command{runtest} invocations; it defaults to the name of the package.
9866 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
9867 @option{--srcdir} flags that are passed to dejagnu by default; this can be
9868 overridden if necessary.
9869 @vindex RUNTESTDEFAULTFLAGS
9871 The variables @code{EXPECT} and @code{RUNTEST} can
9872 also be overridden to provide project-specific values.  For instance,
9873 you will need to do this if you are testing a compiler toolchain,
9874 because the default values do not take into account host and target
9875 names.
9876 @opindex dejagnu
9877 @vindex DEJATOOL
9878 @vindex EXPECT
9879 @vindex RUNTEST
9881 The contents of the variable @code{RUNTESTFLAGS} are passed to the
9882 @code{runtest} invocation.  This is considered a ``user variable''
9883 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
9884 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
9885 @vindex RUNTESTFLAGS
9886 @vindex AM_RUNTESTFLAGS
9888 @cindex @file{site.exp}
9889 Automake will generate rules to create a local @file{site.exp} file,
9890 defining various variables detected by @command{configure}.  This file
9891 is automatically read by DejaGnu.  It is OK for the user of a package
9892 to edit this file in order to tune the test suite.  However this is
9893 not the place where the test suite author should define new variables:
9894 this should be done elsewhere in the real test suite code.
9895 Especially, @file{site.exp} should not be distributed.
9897 Still, if the package author has legitimate reasons to extend
9898 @file{site.exp} at @command{make} time, he can do so by defining
9899 the variable @code{EXTRA_DEJAGNU_SITE_CONFIG}; the files listed
9900 there will be considered @file{site.exp} prerequisites, and their
9901 content will be appended to it (in the same order in which they
9902 appear in @code{EXTRA_DEJAGNU_SITE_CONFIG}).  Note that files are
9903 @emph{not} distributed by default.
9905 For more information regarding DejaGnu test suites, see @ref{Top, , ,
9906 dejagnu, The DejaGnu Manual}.
9908 @node Install Tests
9909 @section Install Tests
9911 The @code{installcheck} target is available to the user as a way to
9912 run any tests after the package has been installed.  You can add tests
9913 to this by writing an @code{installcheck-local} rule.
9916 @node Rebuilding
9917 @chapter Rebuilding Makefiles
9918 @cindex rebuild rules
9920 Automake generates rules to automatically rebuild @file{Makefile}s,
9921 @file{configure}, and other derived files like @file{Makefile.in}.
9923 @acindex AM_MAINTAINER_MODE
9924 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
9925 these automatic rebuilding rules are only enabled in maintainer mode.
9927 @vindex CONFIG_STATUS_DEPENDENCIES
9928 @vindex CONFIGURE_DEPENDENCIES
9929 @cindex @file{version.sh}, example
9930 @cindex @file{version.m4}, example
9932 Sometimes it is convenient to supplement the rebuild rules for
9933 @file{configure} or @file{config.status} with additional dependencies.
9934 The variables @code{CONFIGURE_DEPENDENCIES} and
9935 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
9936 dependencies.  These variables should be defined in all
9937 @file{Makefile}s of the tree (because these two rebuild rules are
9938 output in all them), so it is safer and easier to @code{AC_SUBST} them
9939 from @file{configure.ac}.  For instance, the following statement will
9940 cause @file{configure} to be rerun each time @file{version.sh} is
9941 changed.
9943 @c Keep in sync with remake-config-status-dependencies.sh
9944 @example
9945 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
9946 @end example
9948 @noindent
9949 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
9950 is to be used in all @file{Makefile}s, its value must be sensible at
9951 any level in the build hierarchy.
9953 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
9954 @code{CONFIG_STATUS_DEPENDENCIES}.
9956 @c Keep in sync with remake-configure-dependencies.sh
9957 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
9958 @file{configure} rule, whose effect is to run @command{autoconf}.  This
9959 variable should be seldom used, because @command{automake} already tracks
9960 @code{m4_include}d files.  However it can be useful when playing
9961 tricky games with @code{m4_esyscmd} or similar non-recommendable
9962 macros with side effects.  Be also aware that interactions of this
9963 variable with the @ref{Autom4te Cache, , autom4te cache, autoconf,
9964 The Autoconf Manual} are quite problematic and can cause subtle
9965 breakage, so you might want to disable the cache if you want to use
9966 @code{CONFIGURE_DEPENDENCIES}.
9968 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
9969 @file{config.status} rule, whose effect is to run @file{configure}.
9970 This variable should therefore carry any non-standard source that may
9971 be read as a side effect of running @command{configure}, like @file{version.sh}
9972 in the example above.
9974 Speaking of @file{version.sh} scripts, we recommend against them
9975 today.  They are mainly used when the version of a package is updated
9976 automatically by a script (e.g., in daily builds).  Here is what some
9977 old-style @file{configure.ac}s may look like:
9979 @example
9980 AC_INIT
9981 . $srcdir/version.sh
9982 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
9983 @dots{}
9984 @end example
9986 @noindent
9987 Here, @file{version.sh} is a shell fragment that sets
9988 @code{VERSION_NUMBER}.  The problem with this example is that
9989 @command{automake} cannot track dependencies (listing @file{version.sh}
9990 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
9991 to the user), and that it uses the obsolete form of @code{AC_INIT} and
9992 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
9993 straightforward, because shell variables are not allowed in
9994 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
9995 replaced by an M4 file that is included by @file{configure.ac}:
9997 @example
9998 m4_include([version.m4])
9999 AC_INIT([name], VERSION_NUMBER)
10000 AM_INIT_AUTOMAKE
10001 @dots{}
10002 @end example
10004 @noindent
10005 Here @file{version.m4} could contain something like
10006 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
10007 second form is that @command{automake} will take care of the
10008 dependencies when defining the rebuild rule, and will also distribute
10009 the file automatically.  An inconvenience is that @command{autoconf}
10010 will now be rerun each time the version number is bumped, when only
10011 @file{configure} had to be rerun in the previous setup.
10014 @node Options
10015 @chapter Changing Automake's Behavior
10017 @menu
10018 * Options generalities::        Semantics of Automake option
10019 * List of Automake options::    A comprehensive list of Automake options
10020 @end menu
10022 @node Options generalities
10023 @section Options generalities
10025 Various features of Automake can be controlled by options.  Except where
10026 noted otherwise, options can be specified in one of several ways.  Most
10027 options can be applied on a per-@file{Makefile} basis when listed in a
10028 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
10029 of these options only make sense when specified in the toplevel
10030 @file{Makefile.am} file.  Options are applied globally to all processed
10031 @file{Makefile} files when listed in the first argument of
10032 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
10033 require changes to the @command{configure} script can only be specified
10034 there.  These are annotated below.
10036 As a general rule, options specified in @code{AUTOMAKE_OPTIONS} take
10037 precedence over those specified in @code{AM_INIT_AUTOMAKE}, which in
10038 turn take precedence over those specified on the command line.
10040 Also, some care must be taken about the interactions among strictness
10041 level and warning categories.  As a general rule, strictness-implied
10042 warnings are overridden by those specified by explicit options.  For
10043 example, even if @samp{portability} warnings are disabled by default
10044 in @option{foreign} strictness, an usage like this will end up enabling
10045 them:
10047 @example
10048 AUTOMAKE_OPTIONS = -Wportability foreign
10049 @end example
10051 However, a strictness level specified in a higher-priority context
10052 will override all the explicit warnings specified in a lower-priority
10053 context.  For example, if @file{configure.ac} contains:
10055 @example
10056 AM_INIT_AUTOMAKE([-Wportability])
10057 @end example
10059 @noindent
10060 and @file{Makefile.am} contains:
10062 @example
10063 AUTOMAKE_OPTIONS = foreign
10064 @end example
10066 @noindent
10067 then @samp{portability} warnings will be @emph{disabled} in
10068 @file{Makefile.am}.
10070 @node List of Automake options
10071 @section List of Automake options
10073 @vindex AUTOMAKE_OPTIONS
10075 @table @asis
10076 @item @option{gnits}
10077 @itemx @option{gnu}
10078 @itemx @option{foreign}
10079 @cindex Option, @option{gnits}
10080 @cindex Option, @option{gnu}
10081 @cindex Option, @option{foreign}
10082 @opindex gnits
10083 @opindex gnu
10084 @opindex foreign
10086 Set the strictness as appropriate.  The @option{gnits} option also
10087 implies options @option{readme-alpha} and @option{check-news}.
10089 @item @option{check-news}
10090 @cindex Option, @option{check-news}
10091 @opindex check-news
10092 Cause @samp{make dist} to fail unless the current version number appears
10093 in the first few lines of the @file{NEWS} file.
10095 @item @option{dejagnu}
10096 @cindex Option, @option{dejagnu}
10097 @opindex dejagnu
10098 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
10100 @item @option{dist-bzip2}
10101 @cindex Option, @option{dist-bzip2}
10102 @opindex dist-bzip2
10103 Hook @code{dist-bzip2} to @code{dist}.
10104 @trindex dist-bzip2
10106 @item @option{dist-lzip}
10107 @cindex Option, @option{dist-lzip}
10108 @opindex dist-lzip
10109 Hook @code{dist-lzip} to @code{dist}.
10110 @trindex dist-lzip
10112 @item @option{dist-xz}
10113 @cindex Option, @option{dist-xz}
10114 @opindex dist-xz
10115 Hook @code{dist-xz} to @code{dist}.
10116 @trindex dist-xz
10118 @item @option{dist-zip}
10119 @cindex Option, @option{dist-zip}
10120 @opindex dist-zip
10121 Hook @code{dist-zip} to @code{dist}.
10122 @trindex dist-zip
10124 @item @option{dist-shar}
10125 @cindex Option, @option{dist-shar}
10126 @opindex dist-shar
10127 Hook @code{dist-shar} to @code{dist}.  Use of this option
10128 is deprecated, as the @samp{shar} format is obsolescent and
10129 problematic.  Support for it will be removed altogether in
10130 Automake 2.0.
10131 @trindex dist-shar
10133 @item @option{dist-tarZ}
10134 @cindex Option, @option{dist-tarZ}
10135 @opindex dist-tarZ
10136 Hook @code{dist-tarZ} to @code{dist}.  Use of this option
10137 is deprecated, as the @samp{compress} program is obsolete.
10138 Support for it will be removed altogether in Automake 2.0.
10139 @trindex dist-tarZ
10141 @item @option{filename-length-max=99}
10142 @cindex Option, @option{filename-length-max=99}
10143 @opindex filename-length-max=99
10144 Abort if file names longer than 99 characters are found during
10145 @samp{make dist}.  Such long file names are generally considered not to
10146 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
10147 options below.  This option should be used in the top-level
10148 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
10149 @file{configure.ac}, it will be ignored otherwise.  It will also be
10150 ignored in sub-packages of nested packages (@pxref{Subpackages}).
10152 @item @option{info-in-builddir}
10153 @cindex Option, @option{info-in-builddir}
10154 @opindex info-in-builddir
10155 Instruct Automake to place the generated @file{.info} files in the
10156 @code{builddir} rather than in the @code{srcdir}.  Note that this
10157 might make VPATH builds with some non-GNU make implementations more
10158 brittle.
10160 @item @option{no-define}
10161 @cindex Option, @option{no-define}
10162 @opindex no-define
10163 This option is meaningful only when passed as an argument to
10164 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
10165 @code{VERSION} variables from being @code{AC_DEFINE}d.  But notice
10166 that they will remain defined as shell variables in the generated
10167 @code{configure}, and as make variables in the generated
10168 @code{Makefile}; this is deliberate, and required for backward
10169 compatibility.
10171 @item @option{no-dependencies}
10172 @cindex Option, @option{no-dependencies}
10173 @opindex no-dependencies
10174 This is similar to using @option{--ignore-deps} on the command line,
10175 but is useful for those situations where you don't have the necessary
10176 bits to make automatic dependency tracking work
10177 (@pxref{Dependencies}).  In this case the effect is to effectively
10178 disable automatic dependency tracking.
10180 @item @option{no-dist}
10181 @cindex Option, @option{no-dist}
10182 @opindex no-dist
10183 Don't emit any code related to @code{dist} target.  This is useful
10184 when a package has its own method for making distributions.
10186 @item @option{no-dist-gzip}
10187 @cindex Option, @option{no-dist-gzip}
10188 @opindex no-dist-gzip
10189 Do not hook @code{dist-gzip} to @code{dist}.
10190 @trindex no-dist-gzip
10192 @item @option{no-exeext}
10193 @cindex Option, @option{no-exeext}
10194 @opindex no-exeext
10195 If your @file{Makefile.am} defines a rule for target @code{foo}, it
10196 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
10197 necessary when @code{EXEEXT} is found to be empty.  However, by
10198 default @command{automake} will generate an error for this use.  The
10199 @option{no-exeext} option will disable this error.  This is intended for
10200 use only where it is known in advance that the package will not be
10201 ported to Windows, or any other operating system using extensions on
10202 executables.
10204 @item @option{no-installinfo}
10205 @cindex Option, @option{no-installinfo}
10206 @opindex no-installinfo
10207 The generated @file{Makefile.in} will not cause info pages to be built
10208 or installed by default.  However, @code{info} and @code{install-info}
10209 targets will still be available.  This option is disallowed at
10210 @option{gnu} strictness and above.
10211 @trindex info
10212 @trindex install-info
10214 @item @option{no-installman}
10215 @cindex Option, @option{no-installman}
10216 @opindex no-installman
10217 The generated @file{Makefile.in} will not cause man pages to be
10218 installed by default.  However, an @code{install-man} target will still
10219 be available for optional installation.  This option is disallowed at
10220 @option{gnu} strictness and above.
10221 @trindex install-man
10223 @item @option{nostdinc}
10224 @cindex Option, @option{nostdinc}
10225 @opindex nostdinc
10226 This option can be used to disable the standard @option{-I} options that
10227 are ordinarily automatically provided by Automake.
10229 @item @option{no-texinfo.tex}
10230 @cindex Option, @option{no-texinfo.tex}
10231 @opindex no-texinfo.tex
10232 Don't require @file{texinfo.tex}, even if there are texinfo files in
10233 this directory.
10235 @item @option{serial-tests}
10236 @cindex Option, @option{serial-tests}
10237 @opindex serial-tests
10238 Enable the older serial test suite harness for @code{TESTS} (@pxref{Serial
10239 Test Harness}, for more information).
10241 @item @option{parallel-tests}
10242 @cindex Option, @option{parallel-tests}
10243 @opindex parallel-tests
10244 Enable test suite harness for @code{TESTS} that can run tests in parallel
10245 (@pxref{Parallel Test Harness}, for more information).  This option is
10246 only kept for backward-compatibility, since the parallel test harness is
10247 the default now.
10249 @item @option{readme-alpha}
10250 @cindex Option, @option{readme-alpha}
10251 @opindex readme-alpha
10252 If this release is an alpha release, and the file @file{README-alpha}
10253 exists, then it will be added to the distribution.  If this option is
10254 given, version numbers are expected to follow one of two forms.  The
10255 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
10256 element is a number; the final period and number should be left off for
10257 non-alpha releases.  The second form is
10258 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
10259 letter; it should be omitted for non-alpha releases.
10261 @item @option{std-options}
10262 @cindex Options, @option{std-options}
10263 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
10264 @cindex @option{--help} check
10265 @cindex @option{--version} check
10266 @opindex std-options
10268 Make the @code{installcheck} rule check that installed scripts and
10269 programs support the @option{--help} and @option{--version} options.
10270 This also provides a basic check that the program's
10271 run-time dependencies are satisfied after installation.
10273 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
10274 In a few situations, programs (or scripts) have to be exempted from this
10275 test.  For instance, @command{false} (from GNU coreutils) is never
10276 successful, even for @option{--help} or @option{--version}.  You can list
10277 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
10278 Programs (not scripts) listed in this variable should be suffixed by
10279 @samp{$(EXEEXT)} for the sake of Windows or OS/2.  For instance, suppose we
10280 build @file{false} as a program but @file{true.sh} as a script, and that
10281 neither of them support @option{--help} or @option{--version}:
10283 @example
10284 AUTOMAKE_OPTIONS = std-options
10285 bin_PROGRAMS = false ...
10286 bin_SCRIPTS = true.sh ...
10287 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
10288 @end example
10290 @item @option{subdir-objects}
10291 @cindex Options, @option{subdir-objects}
10292 @opindex subdir-objects
10293 If this option is specified, then objects are placed into the
10294 subdirectory of the build directory corresponding to the subdirectory of
10295 the source file.  For instance, if the source file is
10296 @file{subdir/file.cxx}, then the output file would be
10297 @file{subdir/file.o}.
10299 @anchor{tar-formats}
10300 @item @option{tar-v7}
10301 @itemx @option{tar-ustar}
10302 @itemx @option{tar-pax}
10303 @cindex Option, @option{tar-v7}
10304 @cindex Option, @option{tar-ustar}
10305 @cindex Option, @option{tar-pax}
10306 @cindex @command{tar} formats
10307 @cindex v7 @command{tar} format
10308 @cindex ustar format
10309 @cindex pax format
10310 @opindex tar-v7
10311 @opindex tar-ustar
10312 @opindex tar-pax
10314 These three mutually exclusive options select the tar format to use
10315 when generating tarballs with @samp{make dist}.  (The tar file created
10316 is then compressed according to the set of @option{no-dist-gzip},
10317 @option{dist-bzip2}, @option{dist-lzip}, @option{dist-xz} and
10318 @option{dist-tarZ} options in use.)
10320 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
10321 (@pxref{Macros}) because they can require additional configure checks.
10322 Automake will complain if it sees such options in an
10323 @code{AUTOMAKE_OPTIONS} variable.
10325 @option{tar-v7} selects the old V7 tar format.  This is the historical
10326 default.  This antiquated format is understood by all tar
10327 implementations and supports file names with up to 99 characters.  When
10328 given longer file names some tar implementations will diagnose the
10329 problem while other will generate broken tarballs or use non-portable
10330 extensions.  Furthermore, the V7 format cannot store empty
10331 directories.  When using this format, consider using the
10332 @option{filename-length-max=99} option to catch file names too long.
10334 @option{tar-ustar} selects the ustar format defined by POSIX
10335 1003.1-1988.  This format is believed to be old enough to be portable.
10336 It fully supports empty directories.  It can store file names with up
10337 to 256 characters, provided that the file name can be split at
10338 directory separator in two parts, first of them being at most 155
10339 bytes long.  So, in most cases the maximum file name length will be
10340 shorter than 256 characters.  However you may run against broken tar
10341 implementations that incorrectly handle file names longer than 99
10342 characters (please report them to @email{@value{PACKAGE_BUGREPORT}} so we
10343 can document this accurately).
10345 @option{tar-pax} selects the new pax interchange format defined by POSIX
10346 1003.1-2001.  It does not limit the length of file names.  However,
10347 this format is very young and should probably be restricted to
10348 packages that target only very modern platforms.  There are moves to
10349 change the pax format in an upward-compatible way, so this option may
10350 refer to a more recent version in the future.
10352 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
10353 further discussion about tar formats.
10355 @command{configure} knows several ways to construct these formats.  It
10356 will not abort if it cannot find a tool up to the task (so that the
10357 package can still be built), but @samp{make dist} will fail.
10359 @item @var{version}
10360 @cindex Option, @var{version}
10361 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
10362 newer than the version specified, creation of the @file{Makefile.in}
10363 will be suppressed.
10365 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
10366 @cindex Option, warnings
10367 @cindex Option, @option{-W@var{category}}
10368 @cindex Option, @option{--warnings=@var{category}}
10369 These options behave exactly like their command-line counterpart
10370 (@pxref{automake Invocation}).  This allows you to enable or disable some
10371 warning categories on a per-file basis.  You can also setup some warnings
10372 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
10373 in your @file{configure.ac}.
10375 @end table
10377 Unrecognized options are diagnosed by @command{automake}.
10379 If you want an option to apply to all the files in the tree, you can use
10380 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
10381 @xref{Macros}.
10384 @node Miscellaneous
10385 @chapter Miscellaneous Rules
10387 There are a few rules and variables that didn't fit anywhere else.
10389 @menu
10390 * Tags::                        Interfacing to cscope, etags and mkid
10391 * Suffixes::                    Handling new file extensions
10392 @end menu
10395 @node Tags
10396 @section Interfacing to @command{etags}
10398 @cindex @file{TAGS} support
10400 Automake will generate rules to generate @file{TAGS} files for use with
10401 GNU Emacs under some circumstances.
10403 @trindex tags
10404 If any C, C++ or Fortran 77 source code or headers are present, then
10405 @code{tags} and @code{TAGS} rules will be generated for the directory.
10406 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
10407 @code{_LISP} primaries will be used to generate tags.  Note that
10408 generated source files that are not distributed must be declared in
10409 variables like @code{nodist_noinst_HEADERS} or
10410 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
10412 A @code{tags} rule will be output at the topmost directory of a
10413 multi-directory package.  When run from this topmost directory,
10414 @samp{make tags} will generate a @file{TAGS} file that includes by
10415 reference all @file{TAGS} files from subdirectories.
10417 The @code{tags} rule will also be generated if the variable
10418 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
10419 directories that contain taggable source that @command{etags} does
10420 not understand.  The user can use the @code{ETAGSFLAGS} to pass
10421 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
10422 available for use in @file{Makefile.am}.
10423 @vindex ETAGS_ARGS
10424 @vindex ETAGSFLAGS
10425 @vindex AM_ETAGSFLAGS
10427 Here is how Automake generates tags for its source, and for nodes in its
10428 Texinfo file:
10430 @example
10431 ETAGS_ARGS = automake.in --lang=none \
10432  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
10433 @end example
10435 If you add file names to @code{ETAGS_ARGS}, you will probably also
10436 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
10437 are added directly to the dependencies for the @code{tags} rule.
10438 @vindex TAGS_DEPENDENCIES
10440 Automake also generates a @code{ctags} rule that can be used to
10441 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
10442 is the name of the program to invoke (by default @command{ctags});
10443 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
10444 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
10446 @trindex id
10447 Automake will also generate an @code{ID} rule that will run
10448 @command{mkid} on the source.  This is only supported on a
10449 directory-by-directory basis.
10451 Similarly, the @code{cscope} rule will create a list of all the source
10452 files in the tree and run @command{cscope} to build an inverted index
10453 database.  The variable @code{CSCOPE} is the name of the program to invoke
10454 (by default @command{cscope}); @code{CSCOPEFLAGS} and
10455 @code{CSCOPE_ARGS} can be used by the user to pass additional flags and
10456 file names respectively, while @code{AM_CSCOPEFLAGS} can be used by the
10457 @file{Makefile.am}.  Note that, currently, the Automake-provided
10458 @code{cscope} support, when used in a VPATH build, might not work well
10459 with non-GNU make implementations (especially with make implementations
10460 performing @ref{Automatic Rule Rewriting, , VPATH rewrites, autoconf,
10461 The Autoconf Manual}).
10463 Finally, Automake also emits rules to support the
10464 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
10465 The @code{GTAGS} rule runs Global Tags and puts the
10466 result in the top build directory.  The variable @code{GTAGS_ARGS}
10467 holds arguments that are passed to @command{gtags}.
10468 @vindex GTAGS_ARGS
10471 @node Suffixes
10472 @section Handling new file extensions
10474 @cindex Adding new @code{SUFFIXES}
10475 @cindex @code{SUFFIXES}, adding
10476 @vindex SUFFIXES
10478 It is sometimes useful to introduce a new implicit rule to handle a file
10479 type that Automake does not know about.
10481 For instance, suppose you had a compiler that could compile @file{.foo}
10482 files to @file{.o} files.  You would simply define a suffix rule for
10483 your language:
10485 @example
10486 .foo.o:
10487         foocc -c -o $@@ $<
10488 @end example
10490 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
10491 variable and expect the correct results:
10493 @example
10494 bin_PROGRAMS = doit
10495 doit_SOURCES = doit.foo
10496 @end example
10498 This was the simpler and more common case.  In other cases, you will
10499 have to help Automake to figure out which extensions you are defining your
10500 suffix rule for.  This usually happens when your extension does not
10501 start with a dot.  Then, all you have to do is to put a list of new
10502 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
10503 implicit rule.
10505 For instance, the following definition prevents Automake from misinterpreting
10506 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
10507 @file{.cpp} files.
10509 @c Keep in sync with suffix7.sh
10510 @example
10511 SUFFIXES = .idl C.cpp
10512 .idlC.cpp:
10513         # whatever
10514 @end example
10516 As you may have noted, the @code{SUFFIXES} variable behaves like the
10517 @code{.SUFFIXES} special target of @command{make}.  You should not touch
10518 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
10519 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
10520 @code{SUFFIXES} go at the start of the generated suffixes list, followed
10521 by Automake generated suffixes not already in the list.
10523 @node Include
10524 @chapter Include
10526 @cmindex include
10527 @cindex Including @file{Makefile} fragment
10528 @cindex @file{Makefile} fragment, including
10530 Automake supports an @code{include} directive that  can be used to
10531 include other @file{Makefile} fragments when @command{automake} is run.
10532 Note that these fragments are read and interpreted by @command{automake},
10533 not by @command{make}.  As with conditionals, @command{make} has no idea that
10534 @code{include} is in use.
10536 There are two forms of @code{include}:
10538 @table @code
10539 @item include $(srcdir)/file
10540 Include a fragment that is found relative to the current source
10541 directory.
10543 @item include $(top_srcdir)/file
10544 Include a fragment that is found relative to the top source directory.
10545 @end table
10547 Note that if a fragment is included inside a conditional, then the
10548 condition applies to the entire contents of that fragment.
10550 Makefile fragments included this way are always distributed because
10551 they are needed to rebuild @file{Makefile.in}.
10553 Inside a fragment, the construct @code{%reldir%} is replaced with the
10554 directory of the fragment relative to the base @file{Makefile.am}.
10555 Similarly, @code{%canon_reldir%} is replaced with the canonicalized
10556 (@pxref{Canonicalization}) form of @code{%reldir%}.  As a convenience,
10557 @code{%D%} is a synonym for @code{%reldir%}, and @code{%C%}
10558 is a synonym for @code{%canon_reldir%}.
10560 A special feature is that if the fragment is in the same directory as
10561 the base @file{Makefile.am} (i.e., @code{%reldir%} is @code{.}), then
10562 @code{%reldir%} and @code{%canon_reldir%} will expand to the empty
10563 string as well as eat, if present, a following slash or underscore
10564 respectively.
10566 Thus, a makefile fragment might look like this:
10568 @example
10569 bin_PROGRAMS += %reldir%/mumble
10570 %canon_reldir%_mumble_SOURCES = %reldir%/one.c
10571 @end example
10573 @node Conditionals
10574 @chapter Conditionals
10576 @cindex Conditionals
10578 Automake supports a simple type of conditionals.
10580 These conditionals are not the same as conditionals in
10581 GNU Make.  Automake conditionals are checked at configure time by the
10582 @file{configure} script, and affect the translation from
10583 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
10584 to @file{configure} and on results that @file{configure} has discovered
10585 about the host system.  GNU Make conditionals are checked at @command{make}
10586 time, and are based on variables passed to the make program or defined
10587 in the @file{Makefile}.
10589 Automake conditionals will work with any make program.
10591 @menu
10592 * Usage of Conditionals::       Declaring conditional content
10593 * Limits of Conditionals::      Enclosing complete statements
10594 @end menu
10596 @node Usage of Conditionals
10597 @section Usage of Conditionals
10599 @acindex AM_CONDITIONAL
10600 Before using a conditional, you must define it by using
10601 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
10603 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
10604 The conditional name, @var{conditional}, should be a simple string
10605 starting with a letter and containing only letters, digits, and
10606 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
10607 that are reserved by Automake.
10609 The shell @var{condition} (suitable for use in a shell @code{if}
10610 statement) is evaluated when @command{configure} is run.  Note that you
10611 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
10612 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
10613 conditionally (e.g., in a shell @code{if} statement), then the result
10614 will confuse @command{automake}.
10615 @end defmac
10617 @cindex @option{--enable-debug}, example
10618 @cindex Example conditional @option{--enable-debug}
10619 @cindex Conditional example, @option{--enable-debug}
10621 Conditionals typically depend upon options that the user provides to
10622 the @command{configure} script.  Here is an example of how to write a
10623 conditional that is true if the user uses the @option{--enable-debug}
10624 option.
10626 @example
10627 AC_ARG_ENABLE([debug],
10628 [  --enable-debug    Turn on debugging],
10629 [case "$@{enableval@}" in
10630   yes) debug=true ;;
10631   no)  debug=false ;;
10632   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
10633 esac],[debug=false])
10634 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
10635 @end example
10637 Here is an example of how to use that conditional in @file{Makefile.am}:
10639 @cmindex if
10640 @cmindex endif
10641 @cmindex else
10643 @example
10644 if DEBUG
10645 DBG = debug
10646 else
10647 DBG =
10648 endif
10649 noinst_PROGRAMS = $(DBG)
10650 @end example
10652 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
10653 (@pxref{Conditional Programs}).
10655 You may only test a single variable in an @code{if} statement, possibly
10656 negated using @samp{!}.  The @code{else} statement may be omitted.
10657 Conditionals may be nested to any depth.  You may specify an argument to
10658 @code{else} in which case it must be the negation of the condition used
10659 for the current @code{if}.  Similarly you may specify the condition
10660 that is closed on the @code{endif} line:
10662 @example
10663 if DEBUG
10664 DBG = debug
10665 else !DEBUG
10666 DBG =
10667 endif !DEBUG
10668 @end example
10670 @noindent
10671 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
10672 @code{endif} statements should not be indented, i.e., start on column
10673 one.
10675 The @code{else} branch of the above two examples could be omitted,
10676 since assigning the empty string to an otherwise undefined variable
10677 makes no difference.
10679 @acindex AM_COND_IF
10680 In order to allow access to the condition registered by
10681 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
10682 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
10684 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
10685 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
10686 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
10687 it will cause @command{automake} to output the rules for the respective
10688 files only for the given condition.
10689 @end defmac
10691 @code{AM_COND_IF} macros may be nested when m4 quotation is used
10692 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
10694 @cindex Example conditional @code{AC_CONFIG_FILES}
10695 @cindex @code{AC_CONFIG_FILES}, conditional
10697 Here is an example of how to define a conditional config file:
10699 @example
10700 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
10701 AM_COND_IF([SHELL_WRAPPER],
10702            [AC_CONFIG_FILES([wrapper:wrapper.in])])
10703 @end example
10705 @node Limits of Conditionals
10706 @section Limits of Conditionals
10708 Conditionals should enclose complete statements like variables or
10709 rules definitions.  Automake cannot deal with conditionals used inside
10710 a variable definition, for instance, and is not even able to diagnose
10711 this situation.  The following example would not work:
10713 @example
10714 # This syntax is not understood by Automake
10715 AM_CPPFLAGS = \
10716   -DFEATURE_A \
10717 if WANT_DEBUG
10718   -DDEBUG \
10719 endif
10720   -DFEATURE_B
10721 @end example
10723 However the intended definition of @code{AM_CPPFLAGS} can be achieved
10724 with
10726 @example
10727 if WANT_DEBUG
10728   DEBUGFLAGS = -DDEBUG
10729 endif
10730 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
10731 @end example
10733 @noindent
10736 @example
10737 AM_CPPFLAGS = -DFEATURE_A
10738 if WANT_DEBUG
10739 AM_CPPFLAGS += -DDEBUG
10740 endif
10741 AM_CPPFLAGS += -DFEATURE_B
10742 @end example
10744 More details and examples of conditionals are described alongside
10745 various Automake features in this manual (@pxref{Conditional
10746 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
10747 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
10748 Libtool Sources}).
10750 @node Silencing Make
10751 @chapter Silencing @command{make}
10753 @cindex Silent @command{make}
10754 @cindex Silencing @command{make}
10755 @cindex Silent rules
10756 @cindex Silent @command{make} rules
10758 @menu
10759 * Make verbosity::              Make is verbose by default
10760 * Tricks For Silencing Make::   Standard and generic ways to silence make
10761 * Automake Silent Rules::       How Automake can help in silencing make
10762 @end menu
10764 @node Make verbosity
10765 @section Make is verbose by default
10767 Normally, when executing the set of rules associated with a target,
10768 @command{make} prints each rule before it is executed.  This behaviour,
10769 while having been in place for a long time, and being even mandated by
10770 the POSIX standard, starkly violates the ``silence is golden'' UNIX
10771 principle@footnote{See also
10772 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
10774 @quotation
10775 When a program has nothing interesting or surprising to say, it should
10776 say nothing.  Well-behaved Unix programs do their jobs unobtrusively,
10777 with a minimum of fuss and bother.  Silence is golden.
10778 @end quotation
10780 In fact, while such verbosity of @command{make} can theoretically be
10781 useful to track bugs and understand reasons of failures right away, it
10782 can also hide warning and error messages from @command{make}-invoked
10783 tools, drowning them in a flood of uninteresting and seldom useful
10784 messages, and thus allowing them to go easily undetected.
10786 This problem can be very annoying, especially for developers, who usually
10787 know quite well what's going on behind the scenes, and for whom the
10788 verbose output from @command{make} ends up being mostly noise that hampers
10789 the easy detection of potentially important warning messages.
10791 @node Tricks For Silencing Make
10792 @section Standard and generic ways to silence make
10794 Here we describe some common idioms/tricks to obtain a quieter make
10795 output, with their relative advantages and drawbacks.  In the next
10796 section (@ref{Automake Silent Rules}) we'll see how Automake can help
10797 in this respect, providing more elaborate and flexible idioms.
10799 @itemize @bullet
10801 @item @command{make -s}
10803 This simply causes @command{make} not to print @emph{any} rule before
10804 executing it.
10806 The @option{-s} flag is mandated by POSIX, universally supported, and
10807 its purpose and function are easy to understand.
10809 But it also has its serious limitations too.  First of all, it embodies
10810 an ``all or nothing'' strategy, i.e., either everything is silenced, or
10811 nothing is; this lack of granularity can sometimes be a fatal flaw.
10812 Moreover, when the @option{-s} flag is used, the @command{make} output
10813 might turn out to be too much terse; in case of errors, the user won't
10814 be able to easily see what rule or command have caused them, or even,
10815 in case of tools with poor error reporting, what the errors were!
10817 @item @command{make >/dev/null || make}
10819 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
10820 from stderr are passed through, output reporting is done only in case of
10821 error, and in that case it should provide a verbose-enough report to allow
10822 an easy determination of the error location and causes.
10824 However, calling @command{make} two times in a row might hide errors
10825 (especially intermittent ones), or subtly change the expected semantic
10826 of the @command{make} calls --- things these which can clearly make
10827 debugging and error assessment very difficult.
10829 @item @command{make --no-print-directory}
10831 This is GNU @command{make} specific.  When called with the
10832 @option{--no-print-directory} option, GNU @command{make} will disable
10833 printing of the working directory by invoked sub-@command{make}s (the
10834 well-known ``@i{Entering/Leaving directory ...}'' messages).  This helps
10835 to decrease the verbosity of the output, but experience has shown that
10836 it can also often render debugging considerably harder in projects using
10837 deeply-nested @command{make} recursion.
10839 As an aside, notice that the @option{--no-print-directory} option is
10840 automatically activated if the @option{-s} flag is used.
10842 @c TODO: Other tricks?
10843 @c TODO: Maybe speak about the @code{.SILENT} target?
10844 @c TODO:  - Pros: More granularity on what to silence.
10845 @c TODO:  - Cons: No easy way to temporarily override.
10847 @end itemize
10849 @node Automake Silent Rules
10850 @section How Automake can help in silencing make
10852 The tricks and idioms for silencing @command{make} described in the
10853 previous section can be useful from time to time, but we've seen that
10854 they all have their serious drawbacks and limitations.  That's why
10855 automake provides support for a more advanced and flexible way of
10856 obtaining quieter output from @command{make} (for most rules at least).
10858 To give the gist of what Automake can do in this respect, here is a simple
10859 comparison between a typical @command{make} output (where silent rules
10860 are disabled) and one with silent rules enabled:
10862 @example
10863 % @kbd{cat Makefile.am}
10864 bin_PROGRAMS = foo
10865 foo_SOURCES = main.c func.c
10866 % @kbd{cat main.c}
10867 int main (void) @{ return func (); @}  /* func used undeclared */
10868 % @kbd{cat func.c}
10869 int func (void) @{ int i; return i; @} /* i used uninitialized */
10871 @i{The make output is by default very verbose.  This causes warnings
10872 from the compiler to be somewhat hidden, and not immediate to spot.}
10873 % @kbd{make CFLAGS=-Wall}
10874 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10875 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10876 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
10877 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
10878 main.c: In function â€˜main’:
10879 main.c:3:3: warning: implicit declaration of function â€˜func’
10880 mv -f .deps/main.Tpo .deps/main.Po
10881 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10882 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10883 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
10884 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
10885 func.c: In function â€˜func’:
10886 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10887 mv -f .deps/func.Tpo .deps/func.Po
10888 gcc -Wall -o foo main.o func.o
10890 @i{Clean up, so that we we can rebuild everything from scratch.}
10891 % @kbd{make clean}
10892 test -z "foo" || rm -f foo
10893 rm -f *.o
10895 @i{Silent rules enabled: the output is minimal but informative.  In
10896 particular, the warnings from the compiler stick out very clearly.}
10897 % @kbd{make V=0 CFLAGS=-Wall}
10898   CC     main.o
10899 main.c: In function â€˜main’:
10900 main.c:3:3: warning: implicit declaration of function â€˜func’
10901   CC     func.o
10902 func.c: In function â€˜func’:
10903 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10904   CCLD   foo
10905 @end example
10907 @cindex silent rules and libtool
10908 Also, in projects using @command{libtool}, the use of silent rules can
10909 automatically enable the @command{libtool}'s @option{--silent} option:
10911 @example
10912 % @kbd{cat Makefile.am}
10913 lib_LTLIBRARIES = libx.la
10915 % @kbd{make # Both make and libtool are verbose by default.}
10917 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
10918   -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
10919   -DPIC -o .libs/libx.o
10920 mv -f .deps/libx.Tpo .deps/libx.Plo
10921 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
10922   /usr/local/lib libx.lo
10923 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
10924   -o .libs/libx.so.0.0.0
10925 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
10928 % @kbd{make V=0}
10929   CC     libx.lo
10930   CCLD   libx.la
10931 @end example
10933 For Automake-generated @file{Makefile}s, the user may influence the
10934 verbosity at @command{configure} run time as well as at @command{make}
10935 run time:
10937 @itemize @bullet
10938 @item
10939 @opindex --enable-silent-rules
10940 @opindex --disable-silent-rules
10941 Passing @option{--enable-silent-rules} to @command{configure} will cause
10942 build rules to be less verbose; the option @option{--disable-silent-rules}
10943 will cause normal verbose output.
10944 @item
10945 @vindex @code{V}
10946 At @command{make} run time, the default chosen at @command{configure}
10947 time may be overridden: @code{make V=1} will produce verbose output,
10948 @code{make V=0} less verbose output.
10949 @end itemize
10951 @cindex default verbosity for silent rules
10952 Note that silent rules are @emph{disabled} by default; the user must
10953 enable them explicitly at either @command{configure} run time or at
10954 @command{make} run time.  We think that this is a good policy, since
10955 it provides the casual user with enough information to prepare a good
10956 bug report in case anything breaks.
10958 Still, notwithstanding the rationales above, a developer who really
10959 wants to make silent rules enabled by default in his own package can
10960 do so by calling @code{AM_SILENT_RULES([yes])} in @file{configure.ac}.
10962 @c Keep in sync with silent-configsite.sh
10963 Users who prefer to have silent rules enabled by default can edit their
10964 @file{config.site} file to make the variable @code{enable_silent_rules}
10965 default to @samp{yes}.  This should still allow disabling silent rules
10966 at @command{configure} time and at @command{make} time.
10968 @c FIXME: there's really a need to specify this explicitly?
10969 For portability to different @command{make} implementations, package authors
10970 are advised to not set the variable @code{V} inside the @file{Makefile.am}
10971 file, to allow the user to override the value for subdirectories as well.
10973 To work at its best, the current implementation of this feature normally
10974 uses nested variable expansion @samp{$(@var{var1}$(V))}, a @file{Makefile}
10975 feature that is not required by POSIX 2008 but is widely supported in
10976 practice.  On the rare @command{make} implementations that do not support
10977 nested variable expansion, whether rules are silent is always determined at
10978 configure time, and cannot be overridden at make time.  Future versions of
10979 POSIX are likely to require nested variable expansion, so this minor
10980 limitation should go away with time.
10982 @vindex @code{AM_V_GEN}
10983 @vindex @code{AM_V_at}
10984 @vindex @code{AM_DEFAULT_VERBOSITY}
10985 @vindex @code{AM_V}
10986 @vindex @code{AM_DEFAULT_V}
10987 To extend the silent mode to your own rules, you have few choices:
10989 @itemize @bullet
10991 @item
10992 You can use the predefined variable @code{AM_V_GEN} as a prefix to
10993 commands that should output a status line in silent mode, and
10994 @code{AM_V_at} as a prefix to commands that should not output anything
10995 in silent mode.  When output is to be verbose, both of these variables
10996 will expand to the empty string.
10998 @item
10999 You can silence a recipe unconditionally with @code{@@}, and then use
11000 the predefined variable @code{AM_V_P} to know whether make is being run
11001 in silent or verbose mode, adjust the verbose information your recipe
11002 displays accordingly:
11004 @example
11005 generate-headers:
11006         @set -e; \
11007         ... [commands defining a shell variable '$headers'] ...; \
11008         if $(AM_V_P); then set -x; else echo " GEN   [headers]"; fi; \
11009         rm -f $$headers && generate-header --flags $$headers
11010 @end example
11012 @item
11013 You can add your own variables, so strings of your own choice are shown.
11014 The following snippet shows how you would define your own equivalent of
11015 @code{AM_V_GEN}:
11017 @example
11018 pkg_verbose = $(pkg_verbose_@@AM_V@@)
11019 pkg_verbose_ = $(pkg_verbose_@@AM_DEFAULT_V@@)
11020 pkg_verbose_0 = @@echo PKG-GEN $@@;
11022 foo: foo.in
11023         $(pkg_verbose)cp $(srcdir)/foo.in $@@
11024 @end example
11026 @end itemize
11028 As a final note, observe that, even when silent rules are enabled,
11029 the @option{--no-print-directory} option is still required with GNU
11030 @command{make} if the ``@i{Entering/Leaving directory ...}'' messages
11031 are to be disabled.
11033 @node Gnits
11034 @chapter The effect of @option{--gnu} and @option{--gnits}
11036 @cindex @option{--gnu}, required files
11037 @cindex @option{--gnu}, complete description
11039 The @option{--gnu} option (or @option{gnu} in the
11040 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
11041 the following:
11043 @itemize @bullet
11044 @item
11045 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
11046 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
11047 or @file{COPYING}, are required at the topmost directory of the package.
11049 If the @option{--add-missing} option is given, @command{automake} will
11050 add a generic version of the @file{INSTALL} file as well as the
11051 @file{COPYING} file containing the text of the current version of the
11052 GNU General Public License existing at the time of this Automake release
11053 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
11054 However, an existing @file{COPYING} file will never be overwritten by
11055 @command{automake}.
11057 @item
11058 The options @option{no-installman} and @option{no-installinfo} are
11059 prohibited.
11060 @end itemize
11062 Note that this option will be extended in the future to do even more
11063 checking; it is advisable to be familiar with the precise requirements
11064 of the GNU standards.  Also, @option{--gnu} can require certain
11065 non-standard GNU programs to exist for use by various maintainer-only
11066 rules; for instance, in the future @command{pathchk} might be required for
11067 @samp{make dist}.
11069 @cindex @option{--gnits}, complete description
11071 The @option{--gnits} option does everything that @option{--gnu} does, and
11072 checks the following as well:
11074 @itemize @bullet
11075 @item
11076 @samp{make installcheck} will check to make sure that the @option{--help}
11077 and @option{--version} really print a usage message and a version string,
11078 respectively.  This is the @option{std-options} option (@pxref{Options}).
11080 @item
11081 @samp{make dist} will check to make sure the @file{NEWS} file has been
11082 updated to the current version.
11084 @item
11085 @code{VERSION} is checked to make sure its format complies with Gnits
11086 standards.
11087 @c FIXME xref when standards are finished
11089 @item
11090 @cindex @file{README-alpha}
11091 If @code{VERSION} indicates that this is an alpha release, and the file
11092 @file{README-alpha} appears in the topmost directory of a package, then
11093 it is included in the distribution.  This is done in @option{--gnits}
11094 mode, and no other, because this mode is the only one where version
11095 number formats are constrained, and hence the only mode where Automake
11096 can automatically determine whether @file{README-alpha} should be
11097 included.
11099 @item
11100 The file @file{THANKS} is required.
11101 @end itemize
11104 @node Not Enough
11105 @chapter When Automake Isn't Enough
11107 In some situations, where Automake is not up to one task, one has to
11108 resort to handwritten rules or even handwritten @file{Makefile}s.
11110 @menu
11111 * Extending::                   Adding new rules or overriding existing ones.
11112 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
11113 @end menu
11115 @node Extending
11116 @section Extending Automake Rules
11118 With some minor exceptions (for example @code{_PROGRAMS} variables,
11119 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
11120 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
11121 @file{Makefile.in} verbatim.
11123 @cindex copying semantics
11125 These copying semantics mean that many problems can be worked around
11126 by simply adding some @command{make} variables and rules to
11127 @file{Makefile.am}.  Automake will ignore these additions.
11129 @cindex conflicting definitions
11130 @cindex rules, conflicting
11131 @cindex variables, conflicting
11132 @cindex definitions, conflicts
11134 Since a @file{Makefile.in} is built from data gathered from three
11135 different places (@file{Makefile.am}, @file{configure.ac}, and
11136 @command{automake} itself), it is possible to have conflicting
11137 definitions of rules or variables.  When building @file{Makefile.in}
11138 the following priorities are respected by @command{automake} to ensure
11139 the user always has the last word:
11141 @itemize
11142 @item
11143 User defined variables in @file{Makefile.am} have priority over
11144 variables @code{AC_SUBST}ed from @file{configure.ac}, and
11145 @code{AC_SUBST}ed variables have priority over
11146 @command{automake}-defined variables.
11147 @item
11148 As far as rules are concerned, a user-defined rule overrides any
11149 @command{automake}-defined rule for the same target.
11150 @end itemize
11152 @cindex overriding rules
11153 @cindex overriding semantics
11154 @cindex rules, overriding
11156 These overriding semantics make it possible to fine tune some default
11157 settings of Automake, or replace some of its rules.  Overriding
11158 Automake rules is often inadvisable, particularly in the topmost
11159 directory of a package with subdirectories.  The @option{-Woverride}
11160 option (@pxref{automake Invocation}) comes in handy to catch overridden
11161 definitions.
11163 Note that Automake does not make any distinction between rules with
11164 commands and rules that only specify dependencies.  So it is not
11165 possible to append new dependencies to an @command{automake}-defined
11166 target without redefining the entire rule.
11168 @cindex @option{-local} targets
11169 @cindex local targets
11171 However, various useful targets have a @samp{-local} version you can
11172 specify in your @file{Makefile.am}.  Automake will supplement the
11173 standard target with these user-supplied targets.
11175 @trindex  all
11176 @trindex  all-local
11177 @trindex  info
11178 @trindex  info-local
11179 @trindex  dvi
11180 @trindex  dvi-local
11181 @trindex  ps
11182 @trindex  ps-local
11183 @trindex  pdf
11184 @trindex  pdf-local
11185 @trindex  html
11186 @trindex  html-local
11187 @trindex  check
11188 @trindex  check-local
11189 @trindex  install
11190 @trindex  install-data
11191 @trindex  install-data-local
11192 @trindex  install-dvi
11193 @trindex  install-dvi-local
11194 @trindex  install-exec
11195 @trindex  install-exec-local
11196 @trindex  install-html
11197 @trindex  install-html-local
11198 @trindex  install-info
11199 @trindex  install-info-local
11200 @trindex  install-pdf
11201 @trindex  install-pdf-local
11202 @trindex  install-ps
11203 @trindex  install-ps-local
11204 @trindex  uninstall
11205 @trindex  uninstall-local
11206 @trindex  mostlyclean
11207 @trindex  mostlyclean-local
11208 @trindex  clean
11209 @trindex  clean-local
11210 @trindex  distclean
11211 @trindex  distclean-local
11212 @trindex  installdirs
11213 @trindex  installdirs-local
11214 @trindex  installcheck
11215 @trindex  installcheck-local
11217 The targets that support a local version are @code{all}, @code{info},
11218 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
11219 @code{install-data}, @code{install-dvi}, @code{install-exec},
11220 @code{install-html}, @code{install-info}, @code{install-pdf},
11221 @code{install-ps}, @code{uninstall}, @code{installdirs},
11222 @code{installcheck} and the various @code{clean} targets
11223 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
11224 @code{maintainer-clean}).
11226 Note that there are no @code{uninstall-exec-local} or
11227 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
11228 It doesn't make sense to uninstall just data or just executables.
11230 For instance, here is one way to erase a subdirectory during
11231 @samp{make clean} (@pxref{Clean}).
11233 @example
11234 clean-local:
11235         -rm -rf testSubDir
11236 @end example
11238 You may be tempted to use @code{install-data-local} to install a file
11239 to some hard-coded location, but you should avoid this
11240 (@pxref{Hard-Coded Install Paths}).
11242 With the @code{-local} targets, there is no particular guarantee of
11243 execution order; typically, they are run early, but with parallel
11244 make, there is no way to be sure of that.
11246 @cindex @option{-hook} targets
11247 @cindex hook targets
11248 @trindex install-data-hook
11249 @trindex install-exec-hook
11250 @trindex uninstall-hook
11251 @trindex dist-hook
11253 In contrast, some rules also have a way to run another rule, called a
11254 @dfn{hook}; hooks are always executed after the main rule's work is done.
11255 The hook is named after the principal target, with @samp{-hook} appended.
11256 The targets allowing hooks are @code{install-data},
11257 @code{install-exec}, @code{uninstall}, @code{dist}, and
11258 @code{distcheck}.
11260 For instance, here is how to create a hard link to an installed program:
11262 @example
11263 install-exec-hook:
11264         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
11265            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
11266 @end example
11268 Although cheaper and more portable than symbolic links, hard links
11269 will not work everywhere (for instance, OS/2 does not have
11270 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
11271 @command{ln} does not work.  An easy way, if symbolic links are
11272 acceptable to you, is to add @code{AC_PROG_LN_S} to
11273 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
11274 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
11275 @file{Makefile.am}.
11277 @cindex versioned binaries, installing
11278 @cindex installing versioned binaries
11279 @cindex @code{LN_S} example
11280 For instance, here is how you could install a versioned copy of a
11281 program using @samp{$(LN_S)}:
11283 @c Keep in sync with insthook.sh
11284 @example
11285 install-exec-hook:
11286         cd $(DESTDIR)$(bindir) && \
11287           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
11288           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
11289 @end example
11291 Note that we rename the program so that a new version will erase the
11292 symbolic link, not the real binary.  Also we @command{cd} into the
11293 destination directory in order to create relative links.
11295 When writing @code{install-exec-hook} or @code{install-data-hook},
11296 please bear in mind that the exec/data distinction is based on the
11297 installation directory, not on the primary used (@pxref{The Two Parts of
11298 Install}).
11299 @c Keep in sync with primary-prefix-couples-documented-valid.sh
11300 So a @code{foo_SCRIPTS} will be installed by
11301 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
11302 @code{install-exec}.  You should define your hooks consequently.
11304 @c FIXME should include discussion of variables you can use in these
11305 @c rules
11307 @node Third-Party Makefiles
11308 @section Third-Party @file{Makefile}s
11310 @cindex Third-party packages, interfacing with
11311 @cindex Interfacing with third-party packages
11313 In most projects all @file{Makefile}s are generated by Automake.  In
11314 some cases, however, projects need to embed subdirectories with
11315 handwritten @file{Makefile}s.  For instance, one subdirectory could be
11316 a third-party project with its own build system, not using Automake.
11318 It is possible to list arbitrary directories in @code{SUBDIRS} or
11319 @code{DIST_SUBDIRS} provided each of these directories has a
11320 @file{Makefile} that recognizes all the following recursive targets.
11322 @cindex recursive targets and third-party @file{Makefile}s
11323 When a user runs one of these targets, that target is run recursively
11324 in all subdirectories.  This is why it is important that even
11325 third-party @file{Makefile}s support them.
11327 @table @code
11328 @item all
11329 Compile the entire package.  This is the default target in
11330 Automake-generated @file{Makefile}s, but it does not need to be the
11331 default in third-party @file{Makefile}s.
11333 @item distdir
11334 @trindex distdir
11335 @vindex distdir
11336 @vindex top_distdir
11337 Copy files to distribute into @samp{$(distdir)}, before a tarball is
11338 constructed.  Of course this target is not required if the
11339 @option{no-dist} option (@pxref{Options}) is used.
11341 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
11342 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
11343 when the @code{distdir} target is invoked.  These two variables have
11344 been adjusted for the directory that is being recursed into, so they
11345 are ready to use.
11347 @item install
11348 @itemx install-data
11349 @itemx install-exec
11350 @itemx uninstall
11351 Install or uninstall files (@pxref{Install}).
11353 @item install-dvi
11354 @itemx install-html
11355 @itemx install-info
11356 @itemx install-ps
11357 @itemx install-pdf
11358 Install only some specific documentation format (@pxref{Texinfo}).
11360 @item installdirs
11361 Create install directories, but do not install any files.
11363 @item check
11364 @itemx installcheck
11365 Check the package (@pxref{Tests}).
11367 @item mostlyclean
11368 @itemx clean
11369 @itemx distclean
11370 @itemx maintainer-clean
11371 Cleaning rules (@pxref{Clean}).
11373 @item dvi
11374 @itemx pdf
11375 @itemx ps
11376 @itemx info
11377 @itemx html
11378 Build the documentation in various formats (@pxref{Texinfo}).
11380 @item tags
11381 @itemx ctags
11382 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
11383 @end table
11385 If you have ever used Gettext in a project, this is a good example of
11386 how third-party @file{Makefile}s can be used with Automake.  The
11387 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
11388 @file{intl/} directories are handwritten @file{Makefile}s that
11389 implement all of these targets.  That way they can be added to
11390 @code{SUBDIRS} in Automake packages.
11392 Directories that are only listed in @code{DIST_SUBDIRS} but not in
11393 @code{SUBDIRS} need only the @code{distclean},
11394 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
11395 Subdirectories}).
11397 Usually, many of these rules are irrelevant to the third-party
11398 subproject, but they are required for the whole package to work.  It's
11399 OK to have a rule that does nothing, so if you are integrating a
11400 third-party project with no documentation or tag support, you could
11401 simply augment its @file{Makefile} as follows:
11403 @example
11404 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
11405 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
11406 $(EMPTY_AUTOMAKE_TARGETS):
11407 @end example
11409 Another aspect of integrating third-party build systems is whether
11410 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
11411 subpackage does not support VPATH builds the whole package will not
11412 support VPATH builds.  This in turns means that @samp{make distcheck}
11413 will not work, because it relies on VPATH builds.  Some people can
11414 live without this (actually, many Automake users have never heard of
11415 @samp{make distcheck}).  Other people may prefer to revamp the
11416 existing @file{Makefile}s to support VPATH@.  Doing so does not
11417 necessarily require Automake, only Autoconf is needed (@pxref{Build
11418 Directories, , Build Directories, autoconf, The Autoconf Manual}).
11419 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
11420 and @samp{@@top_builddir@@} are defined by @file{configure} when it
11421 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
11422 Output Variables, autoconf, The Autoconf Manual}), they are not
11423 computed by the Makefile like the aforementioned @samp{$(distdir)} and
11424 @samp{$(top_distdir)} variables.
11426 It is sometimes inconvenient to modify a third-party @file{Makefile}
11427 to introduce the above required targets.  For instance, one may want to
11428 keep the third-party sources untouched to ease upgrades to new
11429 versions.
11431 @cindex @file{GNUmakefile} including @file{Makefile}
11432 Here are two other ideas.  If GNU make is assumed, one possibility is
11433 to add to that subdirectory a @file{GNUmakefile} that defines the
11434 required targets and includes the third-party @file{Makefile}.  For
11435 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
11436 directory; the easiest way to do this is to write a
11437 @file{GNUmakefile.in} instead, and have it processed with
11438 @code{AC_CONFIG_FILES} from the outer package.  For example if we
11439 assume @file{Makefile} defines all targets except the documentation
11440 targets, and that the @code{check} target is actually called
11441 @code{test}, we could write @file{GNUmakefile} (or
11442 @file{GNUmakefile.in}) like this:
11444 @example
11445 # First, include the real Makefile
11446 include Makefile
11447 # Then, define the other targets needed by Automake Makefiles.
11448 .PHONY: dvi pdf ps info html check
11449 dvi pdf ps info html:
11450 check: test
11451 @end example
11453 @cindex Proxy @file{Makefile} for third-party packages
11454 A similar idea that does not use @code{include} is to write a proxy
11455 @file{Makefile} that dispatches rules to the real @file{Makefile},
11456 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
11457 it's OK to rename the original @file{Makefile}) or with @samp{cd
11458 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
11459 subdirectory project one directory deeper).  The good news is that
11460 this proxy @file{Makefile} can be generated with Automake.  All we
11461 need are @option{-local} targets (@pxref{Extending}) that perform the
11462 dispatch.  Of course the other Automake features are available, so you
11463 could decide to let Automake perform distribution or installation.
11464 Here is a possible @file{Makefile.am}:
11466 @example
11467 all-local:
11468         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
11469 check-local:
11470         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
11471 clean-local:
11472         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
11474 # Assuming the package knows how to install itself
11475 install-data-local:
11476         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
11477 install-exec-local:
11478         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
11479 uninstall-local:
11480         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
11482 # Distribute files from here.
11483 EXTRA_DIST = subdir/Makefile subdir/program.c ...
11484 @end example
11486 Pushing this idea to the extreme, it is also possible to ignore the
11487 subproject build system and build everything from this proxy
11488 @file{Makefile.am}.  This might sound very sensible if you need VPATH
11489 builds but the subproject does not support them.
11491 @node Distributing
11492 @chapter Distributing @file{Makefile.in}s
11494 Automake places no restrictions on the distribution of the resulting
11495 @file{Makefile.in}s.  We still encourage software authors to
11496 distribute their work under terms like those of the GPL, but doing so
11497 is not required to use Automake.
11499 Some of the files that can be automatically installed via the
11500 @option{--add-missing} switch do fall under the GPL@.  However, these also
11501 have a special exception allowing you to distribute them with your
11502 package, regardless of the licensing you choose.
11505 @node API Versioning
11506 @chapter Automake API Versioning
11508 New Automake releases usually include bug fixes and new features.
11509 Unfortunately they may also introduce new bugs and incompatibilities.
11510 This makes four reasons why a package may require a particular Automake
11511 version.
11513 Things get worse when maintaining a large tree of packages, each one
11514 requiring a different version of Automake.  In the past, this meant that
11515 any developer (and sometimes users) had to install several versions of
11516 Automake in different places, and switch @samp{$PATH} appropriately for
11517 each package.
11519 Starting with version 1.6, Automake installs versioned binaries.  This
11520 means you can install several versions of Automake in the same
11521 @samp{$prefix}, and can select an arbitrary Automake version by running
11522 @command{automake-1.6} or @command{automake-1.7} without juggling with
11523 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
11524 will use @command{automake-1.6} explicitly in their rebuild rules.
11526 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
11527 not Automake's version.  If a bug fix release is made, for instance
11528 Automake 1.6.1, the API version will remain 1.6.  This means that a
11529 package that works with Automake 1.6 should also work with 1.6.1; after
11530 all, this is what people expect from bug fix releases.
11532 If your package relies on a feature or a bug fix introduced in
11533 a release, you can pass this version as an option to Automake to ensure
11534 older releases will not be used.  For instance, use this in your
11535 @file{configure.ac}:
11537 @example
11538   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
11539 @end example
11541 @noindent
11542 or, in a particular @file{Makefile.am}:
11544 @example
11545   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
11546 @end example
11548 @noindent
11549 Automake will print an error message if its version is
11550 older than the requested version.
11553 @heading What is in the API
11555 Automake's programming interface is not easy to define.  Basically it
11556 should include at least all @strong{documented} variables and targets
11557 that a @file{Makefile.am} author can use, any behavior associated with
11558 them (e.g., the places where @samp{-hook}'s are run), the command line
11559 interface of @command{automake} and @command{aclocal}, @dots{}
11561 @heading What is not in the API
11563 Every undocumented variable, target, or command line option, is not part
11564 of the API@.  You should avoid using them, as they could change from one
11565 version to the other (even in bug fix releases, if this helps to fix a
11566 bug).
11568 If it turns out you need to use such an undocumented feature, contact
11569 @email{automake@@gnu.org} and try to get it documented and exercised by
11570 the test-suite.
11572 @node Upgrading
11573 @chapter Upgrading a Package to a Newer Automake Version
11575 Automake maintains three kind of files in a package.
11577 @itemize
11578 @item @file{aclocal.m4}
11579 @item @file{Makefile.in}s
11580 @item auxiliary tools like @file{install-sh} or @file{py-compile}
11581 @end itemize
11583 @file{aclocal.m4} is generated by @command{aclocal} and contains some
11584 Automake-supplied M4 macros.  Auxiliary tools are installed by
11585 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
11586 built from @file{Makefile.am} by @command{automake}, and rely on the
11587 definitions of the M4 macros put in @file{aclocal.m4} as well as the
11588 behavior of the auxiliary tools installed.
11590 Because all of these files are closely related, it is important to
11591 regenerate all of them when upgrading to a newer Automake release.
11592 The usual way to do that is
11594 @example
11595 aclocal # with any option needed (such a -I m4)
11596 autoconf
11597 automake --add-missing --force-missing
11598 @end example
11600 @noindent
11601 or more conveniently:
11603 @example
11604 autoreconf -vfi
11605 @end example
11607 The use of @option{--force-missing} ensures that auxiliary tools will be
11608 overridden by new versions (@pxref{automake Invocation}).
11610 It is important to regenerate all of these files each time Automake is
11611 upgraded, even between bug fixes releases.  For instance, it is not
11612 unusual for a bug fix to involve changes to both the rules generated
11613 in @file{Makefile.in} and the supporting M4 macros copied to
11614 @file{aclocal.m4}.
11616 Presently @command{automake} is able to diagnose situations where
11617 @file{aclocal.m4} has been generated with another version of
11618 @command{aclocal}.  However it never checks whether auxiliary scripts
11619 are up-to-date.  In other words, @command{automake} will tell you when
11620 @command{aclocal} needs to be rerun, but it will never diagnose a
11621 missing @option{--force-missing}.
11623 Before upgrading to a new major release, it is a good idea to read the
11624 file @file{NEWS}.  This file lists all changes between releases: new
11625 features, obsolete constructs, known incompatibilities, and
11626 workarounds.
11628 @node FAQ
11629 @chapter Frequently Asked Questions about Automake
11631 This chapter covers some questions that often come up on the mailing
11632 lists.
11634 @menu
11635 * CVS::                         CVS and generated files
11636 * maintainer-mode::             missing and AM_MAINTAINER_MODE
11637 * Wildcards::                   Why doesn't Automake support wildcards?
11638 * Limitations on File Names::   Limitations on source and installed file names
11639 * Errors with distclean::       Files left in build directory after distclean
11640 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
11641 * Renamed Objects::             Why are object files sometimes renamed?
11642 * Per-Object Flags::            How to simulate per-object flags?
11643 * Multiple Outputs::            Writing rules for tools with many output files
11644 * Hard-Coded Install Paths::    Installing to hard-coded locations
11645 * Debugging Make Rules::        Strategies when things don't work as expected
11646 * Reporting Bugs::              Feedback on bugs and feature requests
11647 @end menu
11649 @node CVS
11650 @section CVS and generated files
11652 @subheading Background: distributed generated Files
11653 @cindex generated files, distributed
11654 @cindex rebuild rules
11656 Packages made with Autoconf and Automake ship with some generated
11657 files like @file{configure} or @file{Makefile.in}.  These files were
11658 generated on the developer's machine and are distributed so that
11659 end-users do not have to install the maintainer tools required to
11660 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
11661 or Info documentation, are usually distributed on similar grounds.
11663 Automake output rules in @file{Makefile}s to rebuild these files.  For
11664 instance, @command{make} will run @command{autoconf} to rebuild
11665 @file{configure} whenever @file{configure.ac} is changed.  This makes
11666 development safer by ensuring a @file{configure} is never out-of-date
11667 with respect to @file{configure.ac}.
11669 As generated files shipped in packages are up-to-date, and because
11670 @command{tar} preserves times-tamps, these rebuild rules are not
11671 triggered when a user unpacks and builds a package.
11673 @subheading Background: CVS and Timestamps
11674 @cindex timestamps and CVS
11675 @cindex CVS and timestamps
11677 Unless you use CVS keywords (in which case files must be updated at
11678 commit time), CVS preserves timestamp during @samp{cvs commit} and
11679 @samp{cvs import -d} operations.
11681 When you check out a file using @samp{cvs checkout} its timestamp is
11682 set to that of the revision that is being checked out.
11684 However, during @command{cvs update}, files will have the date of the
11685 update, not the original timestamp of this revision.  This is meant to
11686 make sure that @command{make} notices sources files have been updated.
11688 This timestamp shift is troublesome when both sources and generated
11689 files are kept under CVS@.  Because CVS processes files in lexical
11690 order, @file{configure.ac} will appear newer than @file{configure}
11691 after a @command{cvs update} that updates both files, even if
11692 @file{configure} was newer than @file{configure.ac} when it was
11693 checked in.  Calling @command{make} will then trigger a spurious rebuild
11694 of @file{configure}.
11696 @subheading Living with CVS in Autoconfiscated Projects
11697 @cindex CVS and generated files
11698 @cindex generated files and CVS
11700 There are basically two clans amongst maintainers: those who keep all
11701 distributed files under CVS, including generated files, and those who
11702 keep generated files @emph{out} of CVS.
11704 @subsubheading All Files in CVS
11706 @itemize @bullet
11707 @item
11708 The CVS repository contains all distributed files so you know exactly
11709 what is distributed, and you can checkout any prior version entirely.
11711 @item
11712 Maintainers can see how generated files evolve (for instance, you can
11713 see what happens to your @file{Makefile.in}s when you upgrade Automake
11714 and make sure they look OK).
11716 @item
11717 Users do not need the autotools to build a checkout of the project, it
11718 works just like a released tarball.
11720 @item
11721 If users use @command{cvs update} to update their copy, instead of
11722 @command{cvs checkout} to fetch a fresh one, timestamps will be
11723 inaccurate.  Some rebuild rules will be triggered and attempt to
11724 run developer tools such as @command{autoconf} or @command{automake}.
11726 Calls to such tools are all wrapped into a call to the @command{missing}
11727 script discussed later (@pxref{maintainer-mode}), so that the user will
11728 see more descriptive warnings about missing or out-of-date tools, and
11729 possible suggestions about how to obtain them, rather than just some
11730 ``command not found'' error, or (worse) some obscure message from some
11731 older version of the required tool they happen to have installed.
11733 Maintainers interested in keeping their package buildable from a CVS
11734 checkout even for those users that lack maintainer-specific tools might
11735 want to provide an helper script (or to enhance their existing bootstrap
11736 script) to fix the timestamps after a
11737 @command{cvs update} or a @command{git checkout}, to prevent spurious
11738 rebuilds.  In case of a project committing the Autotools-generated
11739 files, as well as the generated @file{.info} files, such script might
11740 look something like this:
11742 @smallexample
11743 #!/bin/sh
11744 # fix-timestamp.sh: prevents useless rebuilds after "cvs update"
11745 sleep 1
11746 # aclocal-generated aclocal.m4 depends on locally-installed
11747 # '.m4' macro files, as well as on 'configure.ac'
11748 touch aclocal.m4
11749 sleep 1
11750 # autoconf-generated configure depends on aclocal.m4 and on
11751 # configure.ac
11752 touch configure
11753 # so does autoheader-generated config.h.in
11754 touch config.h.in
11755 # and all the automake-generated Makefile.in files
11756 touch `find . -name Makefile.in -print`
11757 # finally, the makeinfo-generated '.info' files depend on the
11758 # corresponding '.texi' files
11759 touch doc/*.info
11760 @end smallexample
11762 @item
11763 In distributed development, developers are likely to have different
11764 version of the maintainer tools installed.  In this case rebuilds
11765 triggered by timestamp lossage will lead to spurious changes
11766 to generated files.  There are several solutions to this:
11768 @itemize
11769 @item
11770 All developers should use the same versions, so that the rebuilt files
11771 are identical to files in CVS@.  (This starts to be difficult when each
11772 project you work on uses different versions.)
11773 @item
11774 Or people use a script to fix the timestamp after a checkout (the GCC
11775 folks have such a script).
11776 @item
11777 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
11778 disable all of these rebuild rules by default.  This is further discussed
11779 in @ref{maintainer-mode}.
11780 @end itemize
11782 @item
11783 Although we focused on spurious rebuilds, the converse can also
11784 happen.  CVS's timestamp handling can also let you think an
11785 out-of-date file is up-to-date.
11787 For instance, suppose a developer has modified @file{Makefile.am} and
11788 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
11789 change to @file{Makefile.am} right before checking in both files
11790 (without rebuilding @file{Makefile.in} to account for the change).
11792 This last change to @file{Makefile.am} makes the copy of
11793 @file{Makefile.in} out-of-date.  Since CVS processes files
11794 alphabetically, when another developer @samp{cvs update}s his or her
11795 tree, @file{Makefile.in} will happen to be newer than
11796 @file{Makefile.am}.  This other developer will not see that
11797 @file{Makefile.in} is out-of-date.
11799 @end itemize
11801 @subsubheading Generated Files out of CVS
11803 One way to get CVS and @command{make} working peacefully is to never
11804 store generated files in CVS, i.e., do not CVS-control files that
11805 are @file{Makefile} targets (also called @emph{derived} files).
11807 This way developers are not annoyed by changes to generated files.  It
11808 does not matter if they all have different versions (assuming they are
11809 compatible, of course).  And finally, timestamps are not lost, changes
11810 to sources files can't be missed as in the
11811 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
11813 The drawback is that the CVS repository is not an exact copy of what
11814 is distributed and that users now need to install various development
11815 tools (maybe even specific versions) before they can build a checkout.
11816 But, after all, CVS's job is versioning, not distribution.
11818 Allowing developers to use different versions of their tools can also
11819 hide bugs during distributed development.  Indeed, developers will be
11820 using (hence testing) their own generated files, instead of the
11821 generated files that will be released actually.  The developer who
11822 prepares the tarball might be using a version of the tool that
11823 produces bogus output (for instance a non-portable C file), something
11824 other developers could have noticed if they weren't using their own
11825 versions of this tool.
11827 @subheading Third-party Files
11828 @cindex CVS and third-party files
11829 @cindex third-party files and CVS
11831 Another class of files not discussed here (because they do not cause
11832 timestamp issues) are files that are shipped with a package, but
11833 maintained elsewhere.  For instance, tools like @command{gettextize}
11834 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
11835 Libtool), will install or update files in your package.
11837 These files, whether they are kept under CVS or not, raise similar
11838 concerns about version mismatch between developers' tools.  The
11839 Gettext manual has a section about this, see @ref{CVS Issues, CVS
11840 Issues, Integrating with CVS, gettext, GNU gettext tools}.
11842 @node maintainer-mode
11843 @section @command{missing} and @code{AM_MAINTAINER_MODE}
11845 @subheading @command{missing}
11846 @cindex @command{missing}, purpose
11848 The @command{missing} script is a wrapper around several maintainer
11849 tools, designed to warn users if a maintainer tool is required but
11850 missing.  Typical maintainer tools are @command{autoconf},
11851 @command{automake}, @command{bison}, etc.  Because file generated by
11852 these tools are shipped with the other sources of a package, these
11853 tools shouldn't be required during a user build and they are not
11854 checked for in @file{configure}.
11856 However, if for some reason a rebuild rule is triggered and involves a
11857 missing tool, @command{missing} will notice it and warn the user, even
11858 suggesting how to obtain such a tool (at least in case it is a well-known
11859 one, like @command{makeinfo} or @command{bison}).  This is more helpful
11860 and user-friendly than just having the rebuild rules spewing out a terse
11861 error message like @samp{sh: @var{tool}: command not found}.  Similarly,
11862 @command{missing} will warn the user if it detects that a maintainer
11863 tool it attempted to use seems too old (be warned that diagnosing this
11864 correctly is typically more difficult that detecting missing tools, and
11865 requires cooperation from the tool itself, so it won't always work).
11867 If the required tool is installed, @command{missing} will run it and
11868 won't attempt to continue after failures.  This is correct during
11869 development: developers love fixing failures.  However, users with
11870 missing or too old maintainer tools may get an error when the rebuild
11871 rule is spuriously triggered, halting the build.  This failure to let
11872 the build continue is one of the arguments of the
11873 @code{AM_MAINTAINER_MODE} advocates.
11875 @subheading @code{AM_MAINTAINER_MODE}
11876 @cindex @code{AM_MAINTAINER_MODE}, purpose
11877 @acindex AM_MAINTAINER_MODE
11879 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
11880 "rebuild rules" should be enabled or disabled.  With
11881 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
11882 otherwise they are disabled by default.  In the latter case, if
11883 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
11884 @samp{./configure && make}, then @command{make} will *never* attempt to
11885 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
11886 I.e., this disables build rules for files that are usually distributed
11887 and that users should normally not have to update.
11889 The user can override the default setting by passing either
11890 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
11891 to @command{configure}.
11893 People use @code{AM_MAINTAINER_MODE} either because they do not want their
11894 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
11895 because they simply can't stand the rebuild rules and prefer running
11896 maintainer tools explicitly.
11898 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
11899 rules conditionally.  Some developers use this feature to disable
11900 rules that need exotic tools that users may not have available.
11902 Several years ago Fran@,{c}ois Pinard pointed out several arguments
11903 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
11904 insecurity.  By removing dependencies you get non-dependable builds:
11905 changes to sources files can have no effect on generated files and this
11906 can be very confusing when unnoticed.  He adds that security shouldn't
11907 be reserved to maintainers (what @option{--enable-maintainer-mode}
11908 suggests), on the contrary.  If one user has to modify a
11909 @file{Makefile.am}, then either @file{Makefile.in} should be updated
11910 or a warning should be output (this is what Automake uses
11911 @command{missing} for) but the last thing you want is that nothing
11912 happens and the user doesn't notice it (this is what happens when
11913 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
11915 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
11916 swayed by Fran@,{c}ois's arguments, and got rid of
11917 @code{AM_MAINTAINER_MODE} in all of his packages.
11919 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
11920 it helps them working on projects where all files are kept under version
11921 control, and because @command{missing} isn't enough if you have the
11922 wrong version of the tools.
11925 @node Wildcards
11926 @section Why doesn't Automake support wildcards?
11927 @cindex wildcards
11929 Developers are lazy.  They would often like to use wildcards in
11930 @file{Makefile.am}s, so that they would not need to remember to
11931 update @file{Makefile.am}s every time they add, delete, or rename
11932 a file.
11934 There are several objections to this:
11935 @itemize
11936 @item
11937 When using CVS (or similar) developers need to remember they have to
11938 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
11939 @file{Makefile.am} accordingly quickly becomes a reflex.
11941 Conversely, if your application doesn't compile
11942 because you forgot to add a file in @file{Makefile.am}, it will help
11943 you remember to @samp{cvs add} it.
11945 @item
11946 Using wildcards makes it easy to distribute files by mistake.  For
11947 instance, some code a developer is experimenting with (a test case,
11948 say) that should not be part of the distribution.
11950 @item
11951 Using wildcards it's easy to omit some files by mistake.  For
11952 instance, one developer creates a new file, uses it in many places,
11953 but forgets to commit it.  Another developer then checks out the
11954 incomplete project and is able to run @samp{make dist} successfully,
11955 even though a file is missing. By listing files, @samp{make dist}
11956 @emph{will} complain.
11958 @item
11959 Wildcards are not portable to some non-GNU @command{make} implementations,
11960 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
11961 prerequisites of a target.
11963 @item
11964 Finally, it's really hard to @emph{forget} to add a file to
11965 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
11966 not compiled or installed, so you can't even test them.
11967 @end itemize
11969 Still, these are philosophical objections, and as such you may disagree,
11970 or find enough value in wildcards to dismiss all of them.  Before you
11971 start writing a patch against Automake to teach it about wildcards,
11972 let's see the main technical issue: portability.
11974 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
11975 not portable to other @command{make} implementations.
11977 The only way Automake could support @command{$(wildcard ...)} is by
11978 expanding @command{$(wildcard ...)} when @command{automake} is run.
11979 The resulting @file{Makefile.in}s would be portable since they would
11980 list all files and not use @samp{$(wildcard ...)}.  However that
11981 means developers would need to remember to run @command{automake} each
11982 time they add, delete, or rename files.
11984 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
11985 it's easier and faster to type @samp{automake; make} than to type
11986 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
11987 patch to add support for this syntax.  Some people use scripts to
11988 generate file lists in @file{Makefile.am} or in separate
11989 @file{Makefile} fragments.
11991 Even if you don't care about portability, and are tempted to use
11992 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
11993 should know there are many places where Automake needs to know exactly
11994 which files should be processed.  As Automake doesn't know how to
11995 expand @samp{$(wildcard ...)}, you cannot use it in these places.
11996 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
11997 variables as far Automake is concerned.
11999 You can get warnings about @samp{$(wildcard ...}) constructs using the
12000 @option{-Wportability} flag.
12002 @node Limitations on File Names
12003 @section Limitations on File Names
12004 @cindex file names, limitations on
12006 Automake attempts to support all kinds of file names, even those that
12007 contain unusual characters or are unusually long.  However, some
12008 limitations are imposed by the underlying operating system and tools.
12010 Most operating systems prohibit the use of the null byte in file
12011 names, and reserve @samp{/} as a directory separator.  Also, they
12012 require that file names are properly encoded for the user's locale.
12013 Automake is subject to these limits.
12015 Portable packages should limit themselves to POSIX file
12016 names.  These can contain ASCII letters and digits,
12017 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
12018 separated by @samp{/}.  File name components cannot begin with
12019 @samp{-}.
12021 Portable POSIX file names cannot contain components that exceed a
12022 14-byte limit, but nowadays it's normally safe to assume the
12023 more-generous XOPEN limit of 255 bytes.  POSIX
12024 limits file names to 255 bytes (XOPEN allows 1023 bytes),
12025 but you may want to limit a source tarball to file names of 99 bytes
12026 to avoid interoperability problems with old versions of @command{tar}.
12028 If you depart from these rules (e.g., by using non-ASCII
12029 characters in file names, or by using lengthy file names), your
12030 installers may have problems for reasons unrelated to Automake.
12031 However, if this does not concern you, you should know about the
12032 limitations imposed by Automake itself.  These limitations are
12033 undesirable, but some of them seem to be inherent to underlying tools
12034 like Autoconf, Make, M4, and the shell.  They fall into three
12035 categories: install directories, build directories, and file names.
12037 The following characters:
12039 @example
12040 @r{newline} " # $ ' `
12041 @end example
12043 should not appear in the names of install directories.  For example,
12044 the operand of @command{configure}'s @option{--prefix} option should
12045 not contain these characters.
12047 Build directories suffer the same limitations as install directories,
12048 and in addition should not contain the following characters:
12050 @example
12051 & @@ \
12052 @end example
12054 For example, the full name of the directory containing the source
12055 files should not contain these characters.
12057 Source and installation file names like @file{main.c} are limited even
12058 further: they should conform to the POSIX/XOPEN
12059 rules described above.  In addition, if you plan to port to
12060 non-POSIX environments, you should avoid file names that
12061 differ only in case (e.g., @file{makefile} and @file{Makefile}).
12062 Nowadays it is no longer worth worrying about the 8.3 limits of
12063 DOS file systems.
12065 @c FIXME This should probably be moved in the "Checking the Distribution"
12066 @c FIXME section...
12067 @node Errors with distclean
12068 @section Errors with distclean
12069 @cindex @code{distclean}, diagnostic
12070 @cindex @samp{make distclean}, diagnostic
12071 @cindex dependencies and distributed files
12072 @trindex distclean
12074 This is a diagnostic you might encounter while running @samp{make
12075 distcheck}.
12077 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
12078 attempts to build and check your package for errors like this one.
12080 @samp{make distcheck} will perform a @code{VPATH} build of your
12081 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
12082 Files left in the build directory after @samp{make distclean} has run
12083 are listed after this error.
12085 This diagnostic really covers two kinds of errors:
12087 @itemize @bullet
12088 @item
12089 files that are forgotten by distclean;
12090 @item
12091 distributed files that are erroneously rebuilt.
12092 @end itemize
12094 The former left-over files are not distributed, so the fix is to mark
12095 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
12096 more explanations.
12098 The latter bug is not always easy to understand and fix, so let's
12099 proceed with an example.  Suppose our package contains a program for
12100 which we want to build a man page using @command{help2man}.  GNU
12101 @command{help2man} produces simple manual pages from the @option{--help}
12102 and @option{--version} output of other commands (@pxref{Top, , Overview,
12103 help2man, The Help2man Manual}).  Because we don't want to force our
12104 users to install @command{help2man}, we decide to distribute the
12105 generated man page using the following setup.
12107 @example
12108 # This Makefile.am is bogus.
12109 bin_PROGRAMS = foo
12110 foo_SOURCES = foo.c
12111 dist_man_MANS = foo.1
12113 foo.1: foo$(EXEEXT)
12114         help2man --output=foo.1 ./foo$(EXEEXT)
12115 @end example
12117 This will effectively distribute the man page.  However,
12118 @samp{make distcheck} will fail with:
12120 @example
12121 ERROR: files left in build directory after distclean:
12122 ./foo.1
12123 @end example
12125 Why was @file{foo.1} rebuilt?  Because although distributed,
12126 @file{foo.1} depends on a non-distributed built file:
12127 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
12128 will always appear to be newer than the distributed @file{foo.1}.
12130 @samp{make distcheck} caught an inconsistency in our package.  Our
12131 intent was to distribute @file{foo.1} so users do not need to install
12132 @command{help2man}, however since this rule causes this file to be
12133 always rebuilt, users @emph{do} need @command{help2man}.  Either we
12134 should ensure that @file{foo.1} is not rebuilt by users, or there is
12135 no point in distributing @file{foo.1}.
12137 More generally, the rule is that distributed files should never depend
12138 on non-distributed built files.  If you distribute something
12139 generated, distribute its sources.
12141 One way to fix the above example, while still distributing
12142 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
12143 assuming @command{foo --version} and @command{foo --help} do not
12144 change unless @file{foo.c} or @file{configure.ac} change, we could
12145 write the following @file{Makefile.am}:
12147 @example
12148 bin_PROGRAMS = foo
12149 foo_SOURCES = foo.c
12150 dist_man_MANS = foo.1
12152 foo.1: foo.c $(top_srcdir)/configure.ac
12153         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
12154         help2man --output=foo.1 ./foo$(EXEEXT)
12155 @end example
12157 This way, @file{foo.1} will not get rebuilt every time
12158 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
12159 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
12160 way to ensure this would be to use separate directories for binaries
12161 and man pages, and set @code{SUBDIRS} so that binaries are built
12162 before man pages.
12164 We could also decide not to distribute @file{foo.1}.  In
12165 this case it's fine to have @file{foo.1} dependent upon
12166 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
12167 However it would be impossible to build the package in a
12168 cross-compilation, because building @file{foo.1} involves
12169 an @emph{execution} of @file{foo$(EXEEXT)}.
12171 Another context where such errors are common is when distributed files
12172 are built by tools that are built by the package.  The pattern is
12173 similar:
12175 @example
12176 distributed-file: built-tools distributed-sources
12177         build-command
12178 @end example
12180 @noindent
12181 should be changed to
12183 @example
12184 distributed-file: distributed-sources
12185         $(MAKE) $(AM_MAKEFLAGS) built-tools
12186         build-command
12187 @end example
12189 @noindent
12190 or you could choose not to distribute @file{distributed-file}, if
12191 cross-compilation does not matter.
12193 The points made through these examples are worth a summary:
12195 @cartouche
12196 @itemize
12197 @item
12198 Distributed files should never depend upon non-distributed built
12199 files.
12200 @item
12201 Distributed files should be distributed with all their dependencies.
12202 @item
12203 If a file is @emph{intended} to be rebuilt by users, then there is no point
12204 in distributing it.
12205 @end itemize
12206 @end cartouche
12208 @vrindex distcleancheck_listfiles
12209 For desperate cases, it's always possible to disable this check by
12210 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
12211 the Distribution}.
12212 Make sure you do understand the reason why @samp{make distcheck}
12213 complains before you do this.  @code{distcleancheck_listfiles} is a
12214 way to @emph{hide} errors, not to fix them.  You can always do better.
12216 @node Flag Variables Ordering
12217 @section Flag Variables Ordering
12218 @cindex Ordering flag variables
12219 @cindex Flag variables, ordering
12221 @display
12222 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
12223 @code{mumble_CFLAGS}?
12224 @end display
12226 @display
12227 Why does @command{automake} output @code{CPPFLAGS} after
12228 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
12229 @end display
12231 @display
12232 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
12233 one @file{Makefile.am} I would like to append a new flag, however if I
12234 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
12235 flags, not appended.
12236 @end display
12238 @subheading Compile Flag Variables
12239 @cindex Flag Variables, Ordering
12240 @cindex Compile Flag Variables
12241 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
12242 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
12243 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
12244 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
12245 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
12246 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
12247 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
12248 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
12249 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
12250 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
12251 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
12252 @cindex @code{AM_OBJCXXFLAGS} and @code{OBJXXCFLAGS}
12253 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
12254 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
12255 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
12256 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
12257 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
12258 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
12259 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
12260 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
12261 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
12262 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
12263 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
12264 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
12265 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
12266 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
12267 @cindex @code{OBJCXXFLAGS} and @code{AM_OBJCXXFLAGS}
12268 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
12269 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
12270 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
12272 This section attempts to answer all the above questions.  We will
12273 mostly discuss @code{CPPFLAGS} in our examples, but actually the
12274 answer holds for all the compile flags used in Automake:
12275 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
12276 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
12277 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{OBJCXXFLAGS},
12278 @code{RFLAGS}, @code{UPCFLAGS}, and @code{YFLAGS}.
12280 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
12281 three variables that can be used to pass flags to the C preprocessor
12282 (actually these variables are also used for other languages like C++
12283 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
12284 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
12285 and @code{mumble_CPPFLAGS} is the variable specific to the
12286 @code{mumble} target (we call this a per-target variable,
12287 @pxref{Program and Library Variables}).
12289 Automake always uses two of these variables when compiling C sources
12290 files.  When compiling an object file for the @code{mumble} target,
12291 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
12292 @code{AM_CPPFLAGS} otherwise.  The second variable is always
12293 @code{CPPFLAGS}.
12295 In the following example,
12297 @example
12298 bin_PROGRAMS = foo bar
12299 foo_SOURCES = xyz.c
12300 bar_SOURCES = main.c
12301 foo_CPPFLAGS = -DFOO
12302 AM_CPPFLAGS = -DBAZ
12303 @end example
12305 @noindent
12306 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
12307 (because @file{xyz.o} is part of the @code{foo} target), while
12308 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
12309 (because there is no per-target variable for target @code{bar}).
12311 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
12312 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
12313 is a user variable, i.e., a variable that users are entitled to modify
12314 in order to compile the package.  This variable, like many others,
12315 is documented at the end of the output of @samp{configure --help}.
12317 For instance, someone who needs to add @file{/home/my/usr/include} to
12318 the C compiler's search path would configure a package with
12320 @example
12321 ./configure CPPFLAGS='-I /home/my/usr/include'
12322 @end example
12324 @noindent
12325 and this flag would be propagated to the compile rules of all
12326 @file{Makefile}s.
12328 It is also not uncommon to override a user variable at
12329 @command{make}-time.  Many installers do this with @code{prefix}, but
12330 this can be useful with compiler flags too.  For instance, if, while
12331 debugging a C++ project, you need to disable optimization in one
12332 specific object file, you can run something like
12334 @example
12335 rm file.o
12336 make CXXFLAGS=-O0 file.o
12337 make
12338 @end example
12340 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
12341 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
12342 should always have the last say.  It probably makes more sense if you
12343 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
12344 should supersede any other switch from @code{AM_CXXFLAGS} or
12345 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
12346 of @code{CXXFLAGS}).
12348 You should never redefine a user variable such as @code{CPPFLAGS} in
12349 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
12350 mistakes.  Even something like
12352 @example
12353 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
12354 @end example
12356 @noindent
12357 is erroneous.  Although this preserves @file{configure}'s value of
12358 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
12359 user attempts to override @code{CPPFLAGS} from the @command{make}
12360 command line.
12362 @example
12363 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
12364 @end example
12366 @noindent
12367 is all that is needed here if no per-target flags are used.
12369 You should not add options to these user variables within
12370 @file{configure} either, for the same reason.  Occasionally you need
12371 to modify these variables to perform a test, but you should reset
12372 their values afterwards.  In contrast, it is OK to modify the
12373 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
12374 them, but it is rather rare that you need to do this, unless you
12375 really want to change the default definitions of the @samp{AM_}
12376 variables in all @file{Makefile}s.
12378 What we recommend is that you define extra flags in separate
12379 variables.  For instance, you may write an Autoconf macro that computes
12380 a set of warning options for the C compiler, and @code{AC_SUBST} them
12381 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
12382 determines which compiler and which linker flags should be used to
12383 link with library @file{libfoo}, and @code{AC_SUBST} these in
12384 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
12385 @file{Makefile.am} could use these variables as follows:
12387 @example
12388 AM_CFLAGS = $(WARNINGCFLAGS)
12389 bin_PROGRAMS = prog1 prog2
12390 prog1_SOURCES = @dots{}
12391 prog2_SOURCES = @dots{}
12392 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
12393 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
12394 @end example
12396 In this example both programs will be compiled with the flags
12397 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
12398 additionally be compiled with the flags required to link with
12399 @file{libfoo}.
12401 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
12402 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
12403 every target in a @file{Makefile.in}.
12405 Using variables like this gives you full control over the ordering of
12406 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
12407 you want to negate for a particular target, you can use something like
12408 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all of these flags had
12409 been forcefully appended to @code{CFLAGS}, there would be no way to
12410 disable one flag.  Yet another reason to leave user variables to
12411 users.
12413 Finally, we have avoided naming the variable of the example
12414 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
12415 Automake to think that this is actually a per-target variable (like
12416 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
12418 @subheading Other Variables
12420 There are other variables in Automake that follow similar principles
12421 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
12422 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
12423 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
12424 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
12425 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
12426 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
12427 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
12428 of these rules support per-target flags (yet).
12430 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
12431 obeys this naming scheme.  The slight difference is that
12432 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
12433 @command{make} itself.
12435 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
12436 has neither @code{AM_} nor per-target cousin.
12438 Finally you should not think that the existence of a per-target
12439 variable implies the existence of an @code{AM_} variable or of a user
12440 variable.  For instance, the @code{mumble_LDADD} per-target variable
12441 overrides the makefile-wide @code{LDADD} variable (which is not a user
12442 variable), and @code{mumble_LIBADD} exists only as a per-target
12443 variable.  @xref{Program and Library Variables}.
12446 @node Renamed Objects
12447 @section Why are object files sometimes renamed?
12449 This happens when per-target compilation flags are used.  Object
12450 files need to be renamed just in case they would clash with object
12451 files compiled from the same sources, but with different flags.
12452 Consider the following example.
12454 @example
12455 bin_PROGRAMS = true false
12456 true_SOURCES = generic.c
12457 true_CPPFLAGS = -DEXIT_CODE=0
12458 false_SOURCES = generic.c
12459 false_CPPFLAGS = -DEXIT_CODE=1
12460 @end example
12462 @noindent
12463 Obviously the two programs are built from the same source, but it
12464 would be bad if they shared the same object, because @file{generic.o}
12465 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
12466 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
12467 build two different objects: @file{true-generic.o} and
12468 @file{false-generic.o}.
12470 @command{automake} doesn't actually look whether source files are
12471 shared to decide if it must rename objects.  It will just rename all
12472 objects of a target as soon as it sees per-target compilation flags
12473 used.
12475 It's OK to share object files when per-target compilation flags are not
12476 used.  For instance, @file{true} and @file{false} will both use
12477 @file{version.o} in the following example.
12479 @example
12480 AM_CPPFLAGS = -DVERSION=1.0
12481 bin_PROGRAMS = true false
12482 true_SOURCES = true.c version.c
12483 false_SOURCES = false.c version.c
12484 @end example
12486 Note that the renaming of objects is also affected by the
12487 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
12490 @node Per-Object Flags
12491 @section Per-Object Flags Emulation
12492 @cindex Per-object flags, emulated
12494 @display
12495 One of my source files needs to be compiled with different flags.  How
12496 do I do?
12497 @end display
12499 Automake supports per-program and per-library compilation flags (see
12500 @ref{Program and Library Variables} and @ref{Flag Variables
12501 Ordering}).  With this you can define compilation flags that apply to
12502 all files compiled for a target.  For instance, in
12504 @example
12505 bin_PROGRAMS = foo
12506 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
12507 foo_CFLAGS = -some -flags
12508 @end example
12510 @noindent
12511 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
12512 compiled with @samp{-some -flags}.  (If you wonder about the names of
12513 these object files, see @ref{Renamed Objects}.)  Note that
12514 @code{foo_CFLAGS} gives the flags to use when compiling all the C
12515 sources of the @emph{program} @code{foo}, it has nothing to do with
12516 @file{foo.c} or @file{foo-foo.o} specifically.
12518 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
12519 specific flags, that none of the other files requires?  Obviously
12520 per-program flags are not directly applicable here.  Something like
12521 per-object flags are expected, i.e., flags that would be used only
12522 when creating @file{foo-foo.o}.  Automake does not support that,
12523 however this is easy to simulate using a library that contains only
12524 that object, and compiling this library with per-library flags.
12526 @example
12527 bin_PROGRAMS = foo
12528 foo_SOURCES = bar.c bar.h main.c
12529 foo_CFLAGS = -some -flags
12530 foo_LDADD = libfoo.a
12531 noinst_LIBRARIES = libfoo.a
12532 libfoo_a_SOURCES = foo.c foo.h
12533 libfoo_a_CFLAGS = -some -other -flags
12534 @end example
12536 Here @file{foo-bar.o} and @file{foo-main.o} will all be
12537 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
12538 be compiled using @samp{-some -other -flags}.  Eventually, all
12539 three objects will be linked to form @file{foo}.
12541 This trick can also be achieved using Libtool convenience libraries,
12542 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
12543 Convenience Libraries}).
12545 Another tempting idea to implement per-object flags is to override the
12546 compile rules @command{automake} would output for these files.
12547 Automake will not define a rule for a target you have defined, so you
12548 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
12549 We recommend against this, because this is error prone.  For instance,
12550 if you add such a rule to the first example, it will break the day you
12551 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
12552 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
12553 Objects}).  Also in order to support dependency tracking, the two
12554 @file{.o}/@file{.obj} extensions, and all the other flags variables
12555 involved in a compilation, you will end up modifying a copy of the
12556 rule previously output by @command{automake} for this file.  If a new
12557 release of Automake generates a different rule, your copy will need to
12558 be updated by hand.
12560 @node Multiple Outputs
12561 @section Handling Tools that Produce Many Outputs
12562 @cindex multiple outputs, rules with
12563 @cindex many outputs, rules with
12564 @cindex rules with multiple outputs
12566 This section describes a @command{make} idiom that can be used when a
12567 tool produces multiple output files.  It is not specific to Automake
12568 and can be used in ordinary @file{Makefile}s.
12570 Suppose we have a program called @command{foo} that will read one file
12571 called @file{data.foo} and produce two files named @file{data.c} and
12572 @file{data.h}.  We want to write a @file{Makefile} rule that captures
12573 this one-to-two dependency.
12575 The naive rule is incorrect:
12577 @example
12578 # This is incorrect.
12579 data.c data.h: data.foo
12580         foo data.foo
12581 @end example
12583 @noindent
12584 What the above rule really says is that @file{data.c} and
12585 @file{data.h} each depend on @file{data.foo}, and can each be built by
12586 running @samp{foo data.foo}.  In other words it is equivalent to:
12588 @example
12589 # We do not want this.
12590 data.c: data.foo
12591         foo data.foo
12592 data.h: data.foo
12593         foo data.foo
12594 @end example
12596 @noindent
12597 which means that @command{foo} can be run twice.  Usually it will not
12598 be run twice, because @command{make} implementations are smart enough
12599 to check for the existence of the second file after the first one has
12600 been built; they will therefore detect that it already exists.
12601 However there are a few situations where it can run twice anyway:
12603 @itemize
12604 @item
12605 The most worrying case is when running a parallel @command{make}.  If
12606 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
12607 data.foo} commands will run concurrently.  This is harmful.
12608 @item
12609 Another case is when the dependency (here @file{data.foo}) is
12610 (or depends upon) a phony target.
12611 @end itemize
12613 A solution that works with parallel @command{make} but not with
12614 phony dependencies is the following:
12616 @example
12617 data.c data.h: data.foo
12618         foo data.foo
12619 data.h: data.c
12620 @end example
12622 @noindent
12623 The above rules are equivalent to
12625 @example
12626 data.c: data.foo
12627         foo data.foo
12628 data.h: data.foo data.c
12629         foo data.foo
12630 @end example
12632 @noindent
12633 therefore a parallel @command{make} will have to serialize the builds
12634 of @file{data.c} and @file{data.h}, and will detect that the second is
12635 no longer needed once the first is over.
12637 Using this pattern is probably enough for most cases.  However it does
12638 not scale easily to more output files (in this scheme all output files
12639 must be totally ordered by the dependency relation), so we will
12640 explore a more complicated solution.
12642 Another idea is to write the following:
12644 @example
12645 # There is still a problem with this one.
12646 data.c: data.foo
12647         foo data.foo
12648 data.h: data.c
12649 @end example
12651 @noindent
12652 The idea is that @samp{foo data.foo} is run only when @file{data.c}
12653 needs to be updated, but we further state that @file{data.h} depends
12654 upon @file{data.c}.  That way, if @file{data.h} is required and
12655 @file{data.foo} is out of date, the dependency on @file{data.c} will
12656 trigger the build.
12658 This is almost perfect, but suppose we have built @file{data.h} and
12659 @file{data.c}, and then we erase @file{data.h}.  Then, running
12660 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
12661 just state that @file{data.c} must be up-to-date with respect to
12662 @file{data.foo}, and this is already the case.
12664 What we need is a rule that forces a rebuild when @file{data.h} is
12665 missing.  Here it is:
12667 @example
12668 data.c: data.foo
12669         foo data.foo
12670 data.h: data.c
12671 ## Recover from the removal of $@@
12672         @@if test -f $@@; then :; else \
12673           rm -f data.c; \
12674           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12675         fi
12676 @end example
12678 The above scheme can be extended to handle more outputs and more
12679 inputs.  One of the outputs is selected to serve as a witness to the
12680 successful completion of the command, it depends upon all inputs, and
12681 all other outputs depend upon it.  For instance, if @command{foo}
12682 should additionally read @file{data.bar} and also produce
12683 @file{data.w} and @file{data.x}, we would write:
12685 @example
12686 data.c: data.foo data.bar
12687         foo data.foo data.bar
12688 data.h data.w data.x: data.c
12689 ## Recover from the removal of $@@
12690         @@if test -f $@@; then :; else \
12691           rm -f data.c; \
12692           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12693         fi
12694 @end example
12696 However there are now three minor problems in this setup.  One is related
12697 to the timestamp ordering of @file{data.h}, @file{data.w},
12698 @file{data.x}, and @file{data.c}.  Another one is a race condition
12699 if a parallel @command{make} attempts to run multiple instances of the
12700 recover block at once.  Finally, the recursive rule breaks @samp{make -n}
12701 when run with GNU @command{make} (as well as some other @command{make}
12702 implementations), as it may remove @file{data.h} even when it should not
12703 (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
12704 The GNU Make Manual}).
12706 Let us deal with the first problem.  @command{foo} outputs four files,
12707 but we do not know in which order these files are created.  Suppose
12708 that @file{data.h} is created before @file{data.c}.  Then we have a
12709 weird situation.  The next time @command{make} is run, @file{data.h}
12710 will appear older than @file{data.c}, the second rule will be
12711 triggered, a shell will be started to execute the @samp{if@dots{}fi}
12712 command, but actually it will just execute the @code{then} branch,
12713 that is: nothing.  In other words, because the witness we selected is
12714 not the first file created by @command{foo}, @command{make} will start
12715 a shell to do nothing each time it is run.
12717 A simple riposte is to fix the timestamps when this happens.
12719 @example
12720 data.c: data.foo data.bar
12721         foo data.foo data.bar
12722 data.h data.w data.x: data.c
12723         @@if test -f $@@; then \
12724           touch $@@; \
12725         else \
12726 ## Recover from the removal of $@@
12727           rm -f data.c; \
12728           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12729         fi
12730 @end example
12732 Another solution is to use a different and dedicated file as witness,
12733 rather than using any of @command{foo}'s outputs.
12735 @example
12736 data.stamp: data.foo data.bar
12737         @@rm -f data.tmp
12738         @@touch data.tmp
12739         foo data.foo data.bar
12740         @@mv -f data.tmp $@@
12741 data.c data.h data.w data.x: data.stamp
12742 ## Recover from the removal of $@@
12743         @@if test -f $@@; then :; else \
12744           rm -f data.stamp; \
12745           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12746         fi
12747 @end example
12749 @file{data.tmp} is created before @command{foo} is run, so it has a
12750 timestamp older than output files output by @command{foo}.  It is then
12751 renamed to @file{data.stamp} after @command{foo} has run, because we
12752 do not want to update @file{data.stamp} if @command{foo} fails.
12754 This solution still suffers from the second problem: the race
12755 condition in the recover rule.  If, after a successful build, a user
12756 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
12757 @command{make} may start both recover rules in parallel.  If the two
12758 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
12759 data.stamp} concurrently the build is likely to fail (for instance, the
12760 two rules will create @file{data.tmp}, but only one can rename it).
12762 Admittedly, such a weird situation does not arise during ordinary
12763 builds.  It occurs only when the build tree is mutilated.  Here
12764 @file{data.c} and @file{data.h} have been explicitly removed without
12765 also removing @file{data.stamp} and the other output files.
12766 @code{make clean; make} will always recover from these situations even
12767 with parallel makes, so you may decide that the recover rule is solely
12768 to help non-parallel make users and leave things as-is.  Fixing this
12769 requires some locking mechanism to ensure only one instance of the
12770 recover rule rebuilds @file{data.stamp}.  One could imagine something
12771 along the following lines.
12773 @example
12774 data.c data.h data.w data.x: data.stamp
12775 ## Recover from the removal of $@@
12776         @@if test -f $@@; then :; else \
12777           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
12778 ## mkdir is a portable test-and-set
12779           if mkdir data.lock 2>/dev/null; then \
12780 ## This code is being executed by the first process.
12781             rm -f data.stamp; \
12782             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12783             result=$$?; rm -rf data.lock; exit $$result; \
12784           else \
12785 ## This code is being executed by the follower processes.
12786 ## Wait until the first process is done.
12787             while test -d data.lock; do sleep 1; done; \
12788 ## Succeed if and only if the first process succeeded.
12789             test -f data.stamp; \
12790           fi; \
12791         fi
12792 @end example
12794 Using a dedicated witness, like @file{data.stamp}, is very handy when
12795 the list of output files is not known beforehand.  As an illustration,
12796 consider the following rules to compile many @file{*.el} files into
12797 @file{*.elc} files in a single command.  It does not matter how
12798 @code{ELFILES} is defined (as long as it is not empty: empty targets
12799 are not accepted by POSIX).
12801 @example
12802 ELFILES = one.el two.el three.el @dots{}
12803 ELCFILES = $(ELFILES:=c)
12805 elc-stamp: $(ELFILES)
12806         @@rm -f elc-temp
12807         @@touch elc-temp
12808         $(elisp_comp) $(ELFILES)
12809         @@mv -f elc-temp $@@
12811 $(ELCFILES): elc-stamp
12812         @@if test -f $@@; then :; else \
12813 ## Recover from the removal of $@@
12814           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12815           if mkdir elc-lock 2>/dev/null; then \
12816 ## This code is being executed by the first process.
12817             rm -f elc-stamp; \
12818             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12819             rmdir elc-lock; \
12820           else \
12821 ## This code is being executed by the follower processes.
12822 ## Wait until the first process is done.
12823             while test -d elc-lock; do sleep 1; done; \
12824 ## Succeed if and only if the first process succeeded.
12825             test -f elc-stamp; exit $$?; \
12826 @c $$
12827           fi; \
12828         fi
12829 @end example
12831 These solutions all still suffer from the third problem, namely that
12832 they break the promise that @samp{make -n} should not cause any actual
12833 changes to the tree.  For those solutions that do not create lock files,
12834 it is possible to split the recover rules into two separate recipe
12835 commands, one of which does all work but the recursion, and the
12836 other invokes the recursive @samp{$(MAKE)}.  The solutions involving
12837 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
12838 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
12839 autoconf, The Autoconf Manual}).  Here is an example:
12841 @example
12842 ELFILES = one.el two.el three.el @dots{}
12843 ELCFILES = $(ELFILES:=c)
12845 elc-stamp: $(ELFILES)
12846         @@rm -f elc-temp
12847         @@touch elc-temp
12848         $(elisp_comp) $(ELFILES)
12849         @@mv -f elc-temp $@@
12851 $(ELCFILES): elc-stamp
12852 ## Recover from the removal of $@@
12853         @@dry=; for f in x $$MAKEFLAGS; do \
12854           case $$f in \
12855             *=*|--*);; \
12856             *n*) dry=:;; \
12857           esac; \
12858         done; \
12859         if test -f $@@; then :; else \
12860           $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12861           if $$dry mkdir elc-lock 2>/dev/null; then \
12862 ## This code is being executed by the first process.
12863             $$dry rm -f elc-stamp; \
12864             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12865             $$dry rmdir elc-lock; \
12866           else \
12867 ## This code is being executed by the follower processes.
12868 ## Wait until the first process is done.
12869             while test -d elc-lock && test -z "$$dry"; do \
12870 @c $$
12871               sleep 1; \
12872             done; \
12873 ## Succeed if and only if the first process succeeded.
12874             $$dry test -f elc-stamp; exit $$?; \
12875           fi; \
12876         fi
12877 @end example
12879 For completeness it should be noted that GNU @command{make} is able to
12880 express rules with multiple output files using pattern rules
12881 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
12882 Manual}).  We do not discuss pattern rules here because they are not
12883 portable, but they can be convenient in packages that assume GNU
12884 @command{make}.
12887 @node Hard-Coded Install Paths
12888 @section Installing to Hard-Coded Locations
12890 @display
12891 My package needs to install some configuration file.  I tried to use
12892 the following rule, but @samp{make distcheck} fails.  Why?
12894 @example
12895 # Do not do this.
12896 install-data-local:
12897         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
12898 @end example
12899 @end display
12901 @display
12902 My package needs to populate the installation directory of another
12903 package at install-time.  I can easily compute that installation
12904 directory in @file{configure}, but if I install files therein,
12905 @samp{make distcheck} fails.  How else should I do?
12906 @end display
12908 These two setups share their symptoms: @samp{make distcheck} fails
12909 because they are installing files to hard-coded paths.  In the later
12910 case the path is not really hard-coded in the package, but we can
12911 consider it to be hard-coded in the system (or in whichever tool that
12912 supplies the path).  As long as the path does not use any of the
12913 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
12914 @samp{$(datadir)}, etc.), the effect will be the same:
12915 user-installations are impossible.
12917 As a (non-root) user who wants to install a package, you usually have no
12918 right to install anything in @file{/usr} or @file{/usr/local}.  So you
12919 do something like @samp{./configure --prefix ~/usr} to install a
12920 package in your own @file{~/usr} tree.
12922 If a package attempts to install something to some hard-coded path
12923 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
12924 then the installation will fail.  @samp{make distcheck} performs such
12925 a @option{--prefix} installation, hence it will fail too.
12927 Now, there are some easy solutions.
12929 The above @code{install-data-local} example for installing
12930 @file{/etc/afile} would be better replaced by
12932 @example
12933 sysconf_DATA = afile
12934 @end example
12936 @noindent
12937 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
12938 this is what the GNU Standards require.  When such a package is
12939 installed on an FHS compliant system, the installer will have to set
12940 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
12941 should not be concerned by such site policies: use the appropriate
12942 standard directory variable to install your files so that the installer
12943 can easily redefine these variables to match their site conventions.
12945 Installing files that should be used by another package is slightly
12946 more involved.  Let's take an example and assume you want to install
12947 a shared library that is a Python extension module.  If you ask Python
12948 where to install the library, it will answer something like this:
12950 @example
12951 % @kbd{python -c 'from distutils import sysconfig;
12952              print sysconfig.get_python_lib(1,0)'}
12953 /usr/lib/python2.5/site-packages
12954 @end example
12956 If you indeed use this absolute path to install your shared library,
12957 non-root users will not be able to install the package, hence
12958 distcheck fails.
12960 Let's do better.  The @samp{sysconfig.get_python_lib()} function
12961 actually accepts a third argument that will replace Python's
12962 installation prefix.
12964 @example
12965 % @kbd{python -c 'from distutils import sysconfig;
12966              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
12967 $@{exec_prefix@}/lib/python2.5/site-packages
12968 @end example
12970 You can also use this new path.  If you do
12971 @itemize @bullet
12972 @item
12973 root users can install your package with the same @option{--prefix}
12974 as Python (you get the behavior of the previous attempt)
12976 @item
12977 non-root users can install your package too, they will have the
12978 extension module in a place that is not searched by Python but they
12979 can work around this using environment variables (and if you installed
12980 scripts that use this shared library, it's easy to tell Python were to
12981 look in the beginning of your script, so the script works in both
12982 cases).
12983 @end itemize
12985 The @code{AM_PATH_PYTHON} macro uses similar commands to define
12986 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
12988 Of course not all tools are as advanced as Python regarding that
12989 substitution of @var{prefix}.  So another strategy is to figure the
12990 part of the installation directory that must be preserved.  For
12991 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
12992 computes @samp{$(lispdir)}:
12994 @example
12995 $EMACS -batch -Q -eval '(while load-path
12996   (princ (concat (car load-path) "\n"))
12997   (setq load-path (cdr load-path)))' >conftest.out
12998 lispdir=`sed -n
12999   -e 's,/$,,'
13000   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
13001         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
13002       @}'
13003   -e '/.*\/share\/x*emacs\/site-lisp$/@{
13004         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
13005       @}'
13006   conftest.out`
13007 @end example
13009 I.e., it just picks the first directory that looks like
13010 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
13011 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
13012 @samp{$@{datadir@}} appropriately.
13014 The emacs case looks complicated because it processes a list and
13015 expects two possible layouts, otherwise it's easy, and the benefits for
13016 non-root users are really worth the extra @command{sed} invocation.
13019 @node Debugging Make Rules
13020 @section Debugging Make Rules
13021 @cindex debugging rules
13022 @cindex rules, debugging
13024 The rules and dependency trees generated by @command{automake} can get
13025 rather complex, and leave the developer head-scratching when things
13026 don't work as expected.  Besides the debug options provided by the
13027 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
13028 Manual}), here's a couple of further hints for debugging makefiles
13029 generated by @command{automake} effectively:
13031 @itemize
13032 @item
13033 If less verbose output has been enabled in the package with the use
13034 of silent rules (@pxref{Automake Silent Rules}), you can use
13035 @code{make V=1} to see the commands being executed.
13036 @item
13037 @code{make -n} can help show what would be done without actually doing
13038 it.  Note however, that this will @emph{still execute} commands prefixed
13039 with @samp{+}, and, when using GNU @command{make}, commands that contain
13040 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
13041 Execution,,, make, The GNU Make Manual}).
13042 Typically, this is helpful to show what recursive rules would do, but it
13043 means that, in your own rules, you should not mix such recursion with
13044 actions that change any files.@footnote{Automake's @samp{dist} and
13045 @samp{distcheck} rules had a bug in this regard in that they created
13046 directories even with @option{-n}, but this has been fixed in Automake
13047 1.11.}  Furthermore, note that GNU @command{make} will update
13048 prerequisites for the @file{Makefile} file itself even with @option{-n}
13049 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
13050 @item
13051 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
13052 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
13053 portability quirks associated with this construct.
13054 @item
13055 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
13056 can be handy to examine the expanded value of variables.  You may need
13057 to use a target other than @samp{print} if that is already used or a
13058 file with that name exists.
13059 @item
13060 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
13061 GNU @command{make} command called @command{remake} that copes with
13062 complex GNU @command{make}-specific Makefiles and allows to trace
13063 execution, examine variables, and call rules interactively, much like
13064 a debugger.
13065 @end itemize
13068 @node Reporting Bugs
13069 @section Reporting Bugs
13071 Most nontrivial software has bugs.  Automake is no exception.  Although
13072 we cannot promise we can or will fix a bug, and we might not even agree
13073 that it is a bug, we want to hear about problems you encounter. Often we
13074 agree they are bugs and want to fix them.
13076 To make it possible for us to fix a bug, please report it. In order to
13077 do so effectively, it helps to know when and how to do it.
13079 Before reporting a bug, it is a good idea to see if it is already known.
13080 You can look at the @uref{http://debbugs.gnu.org/, GNU Bug Tracker}
13081 and the @uref{http://lists.gnu.org/@/archive/@/html/@/bug-automake/,
13082 bug-automake mailing list archives} for previous bug reports.  We
13083 previously used a
13084 @uref{http://sourceware.org/@/cgi-bin/@/gnatsweb.pl?database=automake,
13085 Gnats database} for bug tracking, so some bugs might have been reported
13086 there already.  Please do not use it for new bug reports, however.
13088 If the bug is not already known, it should be reported.  It is very
13089 important to report bugs in a way that is useful and efficient.  For
13090 this, please familiarize yourself with
13091 @uref{http://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How to
13092 Report Bugs Effectively} and
13093 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
13094 Questions the Smart Way}.  This helps you and developers to save time
13095 which can then be spent on fixing more bugs and implementing more
13096 features.
13098 For a bug report, a feature request or other suggestions, please send
13099 email to @email{@value{PACKAGE_BUGREPORT}}.  This will then open a new
13100 bug in the @uref{http://debbugs.gnu.org/@/automake, bug tracker}.  Be
13101 sure to include the versions of Autoconf and Automake that you use.
13102 Ideally, post a minimal @file{Makefile.am} and @file{configure.ac} that
13103 reproduces the problem you encounter.  If you have encountered test
13104 suite failures, please attach the @file{test-suite.log} file.
13106 @c ========================================================== Appendices
13108 @page
13109 @node Copying This Manual
13110 @appendix Copying This Manual
13112 @menu
13113 * GNU Free Documentation License::  License for copying this manual
13114 @end menu
13116 @node GNU Free Documentation License
13117 @appendixsec GNU Free Documentation License
13118 @include fdl.texi
13120 @page
13121 @node Indices
13122 @appendix Indices
13124 @menu
13125 * Macro Index::                 Index of Autoconf macros
13126 * Variable Index::              Index of Makefile variables
13127 * General Index::               General index
13128 @end menu
13130 @node Macro Index
13131 @appendixsec Macro Index
13133 @printindex fn
13135 @node Variable Index
13136 @appendixsec Variable Index
13138 @printindex vr
13140 @node General Index
13141 @appendixsec General Index
13143 @printindex cp
13146 @bye
13148 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
13149 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
13150 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
13151 @c  LocalWords:  dir Automake's ac Dist Gnits gnits dfn Autoconf's pxref
13152 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
13153 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
13154 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
13155 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
13156 @c  LocalWords:  libmumble CC YFLAGS itemx de fication config url comp
13157 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
13158 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
13159 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
13160 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
13161 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
13162 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
13163 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
13164 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
13165 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
13166 @c  LocalWords:  dirlist noindent usr TIOCGWINSZ sc
13167 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
13168 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
13169 @c  LocalWords:  dmalloc ldmalloc REGEX regex DEPDIR DEP DEFUN aclocaldir fi
13170 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
13171 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
13172 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
13173 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
13174 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
13175 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
13176 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
13177 @c  LocalWords:  OBJCXXFLAGS
13178 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
13179 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
13180 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
13181 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
13182 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
13183 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
13184 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
13185 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
13186 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
13187 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
13188 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
13189 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
13190 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
13191 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
13192 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
13193 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
13194 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
13195 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
13196 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
13197 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
13198 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
13199 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid cd
13200 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
13201 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
13202 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
13203 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
13204 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
13205 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
13206 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
13207 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
13208 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
13209 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
13210 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
13211 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
13212 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
13213 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
13214 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
13215 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
13216 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
13217 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
13218 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
13219 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
13220 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
13221 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
13222 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
13223 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
13224 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
13225 @c  LocalWords:  barexec Pinard's automatize initialize lzip xz cscope