Merge branch 'yacc-work' into yl-work-for-master
[platform/upstream/automake.git] / doc / automake.texi
1 \input texinfo   @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename automake.info
4 @settitle automake
5 @setchapternewpage off
6 @c %**end of header
7
8 @include version.texi
9
10 @c @ovar(ARG, DEFAULT)
11 @c -------------------
12 @c The ARG is an optional argument.  To be used for macro arguments in
13 @c their documentation (@defmac).
14 @macro ovar{varname}
15 @r{[}@var{\varname\}@r{]}
16 @end macro
17
18 @set PACKAGE_BUGREPORT bug-automake@@gnu.org
19
20 @copying
21
22 This manual is for GNU Automake (version @value{VERSION},
23 @value{UPDATED}), a program that creates GNU standards-compliant
24 Makefiles from template files.
25
26 Copyright @copyright{} 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
27 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software
28 Foundation, Inc.
29
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.''
37
38 @end quotation
39 @end copying
40
41 @dircategory Software development
42 @direntry
43 * Automake: (automake).         Making GNU standards-compliant Makefiles.
44 @end direntry
45
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
51
52 @titlepage
53 @title GNU Automake
54 @subtitle For version @value{VERSION}, @value{UPDATED}
55 @author David MacKenzie
56 @author Tom Tromey
57 @author Alexandre Duret-Lutz
58 @page
59 @vskip 0pt plus 1filll
60 @insertcopying
61 @end titlepage
62
63 @contents
64
65 @c We use the following macros to define indices:
66 @c   @cindex   concepts, and anything that does not fit elsewhere
67 @c   @vindex   Makefile variables
68 @c   @trindex  targets
69 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
70 @c   @opindex  tool options
71
72 @c Define an index of configure macros.
73 @defcodeindex ac
74 @c Define an index of options.
75 @defcodeindex op
76 @c Define an index of targets.
77 @defcodeindex tr
78 @c Define an index of commands.
79 @defcodeindex cm
80
81 @c Put the macros in the function index.
82 @syncodeindex ac fn
83
84 @c Put everything else into one index (arbitrarily chosen to be the
85 @c concept index).
86 @syncodeindex op cp
87 @syncodeindex tr cp
88 @syncodeindex cm cp
89
90 @ifnottex
91 @node Top
92 @comment  node-name,  next,  previous,  up
93 @top GNU Automake
94
95 @insertcopying
96
97 @menu
98 * Introduction::                Automake's purpose
99 * Autotools Introduction::      An Introduction to the Autotools
100 * Generalities::                General ideas
101 * Examples::                    Some example packages
102 * automake Invocation::         Creating a Makefile.in
103 * configure::                   Scanning configure.ac, using aclocal
104 * Directories::                 Declaring subdirectories
105 * Programs::                    Building programs and libraries
106 * Other Objects::               Other derived objects
107 * Other GNU Tools::             Other GNU Tools
108 * Documentation::               Building documentation
109 * Install::                     What gets installed
110 * Clean::                       What gets cleaned
111 * Dist::                        What goes in a distribution
112 * Tests::                       Support for test suites
113 * Rebuilding::                  Automatic rebuilding of Makefile
114 * Options::                     Changing Automake's behavior
115 * Miscellaneous::               Miscellaneous rules
116 * Include::                     Including extra files in an Automake template
117 * Conditionals::                Conditionals
118 * Silencing Make::              Obtain less verbose output from @command{make}
119 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
120 * Cygnus::                      The effect of @option{--cygnus}
121 * Not Enough::                  When Automake is not Enough
122 * Distributing::                Distributing the Makefile.in
123 * API Versioning::              About compatibility between Automake versions
124 * Upgrading::                   Upgrading to a Newer Automake Version
125 * FAQ::                         Frequently Asked Questions
126 * History::                     Notes about the history of Automake
127 * Copying This Manual::         How to make copies of this manual
128 * Indices::                     Indices of variables, macros, and concepts
129
130 @detailmenu
131  --- The Detailed Node Listing ---
132
133 An Introduction to the Autotools
134
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
139
140 Use Cases for the GNU Build System
141
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
155
156 A Small Hello World
157
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::
161
162 General ideas
163
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
171
172 Some example packages
173
174 * Complete::                    A simple example, start to finish
175 * true::                        Building true and false
176
177 Scanning @file{configure.ac}, using @command{aclocal}
178
179 * Requirements::                Configuration requirements
180 * Optional::                    Other things Automake recognizes
181 * aclocal Invocation::          Auto-generating aclocal.m4
182 * Macros::                      Autoconf macros supplied with Automake
183
184 Auto-generating aclocal.m4
185
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
192
193 Autoconf macros supplied with Automake
194
195 * Public Macros::               Macros that you can use.
196 * Obsolete Macros::             Macros that you should stop using.
197 * Private Macros::              Macros that you should not use.
198
199 Directories
200
201 * Subdirectories::              Building subdirectories recursively
202 * Conditional Subdirectories::  Conditionally not building directories
203 * Alternative::                 Subdirectories without recursion
204 * Subpackages::                 Nesting packages
205
206 Conditional Subdirectories
207
208 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
209 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
210 * Subdirectories with AC_SUBST::  Another way for conditional recursion
211 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
212
213 Building Programs and Libraries
214
215 * A Program::                   Building a program
216 * A Library::                   Building a library
217 * A Shared Library::            Building a Libtool library
218 * Program and Library Variables::  Variables controlling program and
219                                 library builds
220 * Default _SOURCES::            Default source files
221 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
222 * Program Variables::           Variables used when building a program
223 * Yacc and Lex::                Yacc and Lex support
224 * C++ Support::                 Compiling 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
235
236 Building a program
237
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
242
243 Building a Shared Library
244
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
254
255 Common Issues Related to Libtool's Use
256
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
259
260 Fortran 77 Support
261
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++
265
266 Mixing Fortran 77 With C and C++
267
268 * How the Linker is Chosen::    Automatic linker selection
269
270 Fortran 9x Support
271
272 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
273
274 Other Derived Objects
275
276 * Scripts::                     Executable scripts
277 * Headers::                     Header files
278 * Data::                        Architecture-independent data files
279 * Sources::                     Derived sources
280
281 Built Sources
282
283 * Built Sources Example::       Several ways to handle built sources.
284
285 Other GNU Tools
286
287 * Emacs Lisp::                  Emacs Lisp
288 * gettext::                     Gettext
289 * Libtool::                     Libtool
290 * Java::                        Java bytecode compilation (deprecated)
291 * Python::                      Python
292
293 Building documentation
294
295 * Texinfo::                     Texinfo
296 * Man Pages::                   Man pages
297
298 What Gets Installed
299
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
305
306 What Goes in a Distribution
307
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
313
314 Support for test suites
315
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
322
323 Simple Tests
324
325 * Scripts-based Testsuites::    Automake-specific concepts and terminology
326 * Serial Test Harness::         Older (and obsolescent) serial test harness
327 * Parallel Test Harness::       Generic concurrent test harness
328
329 Using the TAP test protocol
330
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::
335
336 Custom Test Drivers
337
338 * Overview of Custom Test Drivers Support::
339 * Declaring Custom Test Drivers::
340 * API for Custom Test Drivers::
341
342 API for Custom Test Drivers
343
344 * Command-line arguments for test drivers::
345 * Log files generation and test results recording::
346 * Testsuite progress output::
347
348 Changing Automake's Behavior
349
350 * Options generalities::        Semantics of Automake option
351 * List of Automake options::    A comprehensive list of Automake options
352
353 Miscellaneous Rules
354
355 * Tags::                        Interfacing to cscope, etags and mkid
356 * Suffixes::                    Handling new file extensions
357
358 Conditionals
359
360 * Usage of Conditionals::       Declaring conditional content
361 * Limits of Conditionals::      Enclosing complete statements
362
363 Silencing Make
364
365 * Make verbosity::               Make is verbose by default
366 * Tricks For Silencing Make::    Standard and generic ways to silence make
367 * Automake silent-rules Option:: How Automake can help in silencing make
368
369 When Automake Isn't Enough
370
371 * Extending::                   Adding new rules or overriding existing ones.
372 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
373
374 Frequently Asked Questions about Automake
375
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 * distcleancheck::              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
388
389 History of Automake
390
391 * Timeline::                    The Automake story.
392 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
393 * Releases::                    Statistics about Automake Releases
394
395 Dependency Tracking in Automake
396
397 * First Take on Dependencies::  Precomputed dependency tracking
398 * Dependencies As Side Effects::  Update at developer compile time
399 * Dependencies for the User::   Update at user compile time
400 * Techniques for Dependencies::  Alternative approaches
401 * Recommendations for Tool Writers::  What tool writers can do to help
402 * Future Directions for Dependencies::  Languages Automake does not know
403
404 Copying This Manual
405
406 * GNU Free Documentation License::  License for copying this manual
407
408 Indices
409
410 * Macro Index::                 Index of Autoconf macros
411 * Variable Index::              Index of Makefile variables
412 * General Index::               General index
413
414 @end detailmenu
415 @end menu
416
417 @end ifnottex
418
419
420 @node Introduction
421 @chapter Introduction
422
423 Automake is a tool for automatically generating @file{Makefile.in}s
424 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
425 basically a series of @command{make} variable
426 definitions@footnote{These variables are also called @dfn{make macros}
427 in Make terminology, however in this manual we reserve the term
428 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
429 occasionally.  The generated @file{Makefile.in}s are compliant with
430 the GNU Makefile standards.
431
432 @cindex GNU Makefile standards
433
434 The GNU Makefile Standards Document
435 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
436 is long, complicated, and subject to change.  The goal of Automake is to
437 remove the burden of Makefile maintenance from the back of the
438 individual GNU maintainer (and put it on the back of the Automake
439 maintainers).
440
441 The typical Automake input file is simply a series of variable definitions.
442 Each such file is processed to create a @file{Makefile.in}.  There
443 should generally be one @file{Makefile.am} per directory of a project.
444
445 @cindex Constraints of Automake
446 @cindex Automake constraints
447
448 Automake does constrain a project in certain ways; for instance, it
449 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
450 autoconf, The Autoconf Manual}), and enforces certain restrictions on
451 the @file{configure.ac} contents@footnote{Older Autoconf versions used
452 @file{configure.in}.  Autoconf 2.50 and greater promotes
453 @file{configure.ac} over @file{configure.in}.  The rest of this
454 documentation will refer to @file{configure.ac}, but Automake also
455 supports @file{configure.in} for backward compatibility.}.
456
457 @cindex Automake requirements
458 @cindex Requirements, Automake
459
460 Automake requires @command{perl} in order to generate the
461 @file{Makefile.in}s.  However, the distributions created by Automake are
462 fully GNU standards-compliant, and do not require @command{perl} in order
463 to be built.
464
465 @cindex Bugs, reporting
466 @cindex Reporting bugs
467 @cindex E-mail, bug reports
468
469 For more information on bug reports, @xref{Reporting Bugs}.
470
471 @node Autotools Introduction
472 @chapter An Introduction to the Autotools
473
474 If you are new to Automake, maybe you know that it is part of a set of
475 tools called @emph{The Autotools}.  Maybe you've already delved into a
476 package full of files named @file{configure}, @file{configure.ac},
477 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
478 some of them claiming to be @emph{generated by} Autoconf or Automake.
479 But the exact purpose of these files and their relations is probably
480 fuzzy.  The goal of this chapter is to introduce you to this machinery,
481 to show you how it works and how powerful it is.  If you've never
482 installed or seen such a package, do not worry: this chapter will walk
483 you through it.
484
485 If you need some teaching material, more illustrations, or a less
486 @command{automake}-centered continuation, some slides for this
487 introduction are available in Alexandre Duret-Lutz's
488 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
489 Autotools Tutorial}.
490 This chapter is the written version of the first part of his tutorial.
491
492 @menu
493 * GNU Build System::            Introducing the GNU Build System
494 * Use Cases::                   Use Cases for the GNU Build System
495 * Why Autotools::               How Autotools Help
496 * Hello World::                 A Small Hello World Package
497 @end menu
498
499 @node GNU Build System
500 @section Introducing the GNU Build System
501 @cindex GNU Build System, introduction
502
503 It is a truth universally acknowledged, that as a developer in
504 possession of a new package, you must be in want of a build system.
505
506 In the Unix world, such a build system is traditionally achieved using
507 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
508 Manual}).  You express the recipe to build your package in a
509 @file{Makefile}.  This file is a set of rules to build the files in
510 the package.  For instance the program @file{prog} may be built by
511 running the linker on the files @file{main.o}, @file{foo.o}, and
512 @file{bar.o}; the file @file{main.o} may be built by running the
513 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
514 reads @file{Makefile}, checks the existence and modification time of
515 the files mentioned, decides what files need to be built (or rebuilt),
516 and runs the associated commands.
517
518 When a package needs to be built on a different platform than the one
519 it was developed on, its @file{Makefile} usually needs to be adjusted.
520 For instance the compiler may have another name or require more
521 options.  In 1991, David J. MacKenzie got tired of customizing
522 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
523 handcrafted a little shell script called @file{configure} to
524 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
525 autoconf, The Autoconf Manual}).  Compiling his package was now
526 as simple as running @code{./configure && make}.
527
528 @cindex GNU Coding Standards
529
530 Today this process has been standardized in the GNU project.  The GNU
531 Coding Standards (@pxref{Managing Releases, The Release Process, ,
532 standards, The GNU Coding Standards}) explains how each package of the
533 GNU project should have a @file{configure} script, and the minimal
534 interface it should have.  The @file{Makefile} too should follow some
535 established conventions.  The result?  A unified build system that
536 makes all packages almost indistinguishable by the installer.  In its
537 simplest scenario, all the installer has to do is to unpack the
538 package, run @code{./configure && make && make install}, and repeat
539 with the next package to install.
540
541 We call this build system the @dfn{GNU Build System}, since it was
542 grown out of the GNU project.  However it is used by a vast number of
543 other packages: following any existing convention has its advantages.
544
545 @cindex Autotools, introduction
546
547 The Autotools are tools that will create a GNU Build System for your
548 package.  Autoconf mostly focuses on @file{configure} and Automake on
549 @file{Makefile}s.  It is entirely possible to create a GNU Build
550 System without the help of these tools.  However it is rather
551 burdensome and error-prone.  We will discuss this again after some
552 illustration of the GNU Build System in action.
553
554 @node Use Cases
555 @section Use Cases for the GNU Build System
556 @cindex GNU Build System, use cases
557 @cindex GNU Build System, features
558 @cindex Features of the GNU Build System
559 @cindex Use Cases for the GNU Build System
560 @cindex @file{amhello-1.0.tar.gz}, location
561 @cindex @file{amhello-1.0.tar.gz}, use cases
562
563 In this section we explore several use cases for the GNU Build System.
564 You can replay all these examples on the @file{amhello-1.0.tar.gz}
565 package distributed with Automake.  If Automake is installed on your
566 system, you should find a copy of this file in
567 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
568 @var{prefix} is the installation prefix specified during configuration
569 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
570 installed by some GNU/Linux distribution it most likely has been set
571 to @file{/usr}).  If you do not have a copy of Automake installed,
572 you can find a copy of this file inside the @file{doc/} directory of
573 the Automake package.
574
575 Some of the following use cases present features that are in fact
576 extensions to the GNU Build System.  Read: they are not specified by
577 the GNU Coding Standards, but they are nonetheless part of the build
578 system created by the Autotools.  To keep things simple, we do not
579 point out the difference.  Our objective is to show you many of the
580 features that the build system created by the Autotools will offer to
581 you.
582
583 @menu
584 * Basic Installation::          Common installation procedure
585 * Standard Targets::            A list of standard Makefile targets
586 * Standard Directory Variables::  A list of standard directory variables
587 * Standard Configuration Variables::  Using configuration variables
588 * config.site::                 Using a config.site file
589 * VPATH Builds::                Parallel build trees
590 * Two-Part Install::            Installing data and programs separately
591 * Cross-Compilation::           Building for other architectures
592 * Renaming::                    Renaming programs at install time
593 * DESTDIR::                     Building binary packages with DESTDIR
594 * Preparing Distributions::     Rolling out tarballs
595 * Dependency Tracking::         Automatic dependency tracking
596 * Nested Packages::             The GNU Build Systems can be nested
597 @end menu
598
599 @node Basic Installation
600 @subsection Basic Installation
601 @cindex Configuration, basics
602 @cindex Installation, basics
603 @cindex GNU Build System, basics
604
605 The most common installation procedure looks as follows.
606
607 @example
608 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
609 ~ % @kbd{cd amhello-1.0}
610 ~/amhello-1.0 % @kbd{./configure}
611 @dots{}
612 config.status: creating Makefile
613 config.status: creating src/Makefile
614 @dots{}
615 ~/amhello-1.0 % @kbd{make}
616 @dots{}
617 ~/amhello-1.0 % @kbd{make check}
618 @dots{}
619 ~/amhello-1.0 % @kbd{su}
620 Password:
621 /home/adl/amhello-1.0 # @kbd{make install}
622 @dots{}
623 /home/adl/amhello-1.0 # @kbd{exit}
624 ~/amhello-1.0 % @kbd{make installcheck}
625 @dots{}
626 @end example
627
628 @cindex Unpacking
629
630 The user first unpacks the package.  Here, and in the following
631 examples, we will use the non-portable @code{tar zxf} command for
632 simplicity.  On a system without GNU @command{tar} installed, this
633 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
634
635 The user then enters the newly created directory to run the
636 @file{configure} script.  This script probes the system for various
637 features, and finally creates the @file{Makefile}s.  In this toy
638 example there are only two @file{Makefile}s, but in real-world projects,
639 there may be many more, usually one @file{Makefile} per directory.
640
641 It is now possible to run @code{make}.  This will construct all the
642 programs, libraries, and scripts that need to be constructed for the
643 package.  In our example, this compiles the @file{hello} program.
644 All files are constructed in place, in the source tree; we will see
645 later how this can be changed.
646
647 @code{make check} causes the package's tests to be run.  This step is
648 not mandatory, but it is often good to make sure the programs that
649 have been built behave as they should, before you decide to install
650 them.  Our example does not contain any tests, so running @code{make
651 check} is a no-op.
652
653 @cindex su, before @code{make install}
654 After everything has been built, and maybe tested, it is time to
655 install it on the system.  That means copying the programs,
656 libraries, header files, scripts, and other data files from the
657 source directory to their final destination on the system.  The
658 command @code{make install} will do that.  However, by default
659 everything will be installed in subdirectories of @file{/usr/local}:
660 binaries will go into @file{/usr/local/bin}, libraries will end up in
661 @file{/usr/local/lib}, etc.  This destination is usually not writable
662 by any user, so we assume that we have to become root before we can
663 run @code{make install}.  In our example, running @code{make install}
664 will copy the program @file{hello} into @file{/usr/local/bin}
665 and @file{README} into @file{/usr/local/share/doc/amhello}.
666
667 A last and optional step is to run @code{make installcheck}.  This
668 command may run tests on the installed files.  @code{make check} tests
669 the files in the source tree, while @code{make installcheck} tests
670 their installed copies.  The tests run by the latter can be different
671 from those run by the former.  For instance, there are tests that
672 cannot be run in the source tree.  Conversely, some packages are set
673 up so that @code{make installcheck} will run the very same tests as
674 @code{make check}, only on different files (non-installed
675 vs.@: installed).  It can make a difference, for instance when the
676 source tree's layout is different from that of the installation.
677 Furthermore it may help to diagnose an incomplete installation.
678
679 Presently most packages do not have any @code{installcheck} tests
680 because the existence of @code{installcheck} is little known, and its
681 usefulness is neglected.  Our little toy package is no better: @code{make
682 installcheck} does nothing.
683
684 @node Standard Targets
685 @subsection Standard @file{Makefile} Targets
686
687 So far we have come across four ways to run @command{make} in the GNU
688 Build System: @code{make}, @code{make check}, @code{make install}, and
689 @code{make installcheck}.  The words @code{check}, @code{install}, and
690 @code{installcheck}, passed as arguments to @command{make}, are called
691 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
692 @code{all} being the default target in the GNU Build System.
693
694 Here is a list of the most useful targets that the GNU Coding Standards
695 specify.
696
697 @table @code
698 @item make all
699 @trindex all
700 Build programs, libraries, documentation, etc.@: (same as @code{make}).
701 @item make install
702 @trindex install
703 Install what needs to be installed, copying the files from the
704 package's tree to system-wide directories.
705 @item make install-strip
706 @trindex install-strip
707 Same as @code{make install}, then strip debugging symbols.  Some
708 users like to trade space for useful bug reports@enddots{}
709 @item make uninstall
710 @trindex uninstall
711 The opposite of @code{make install}: erase the installed files.
712 (This needs to be run from the same build tree that was installed.)
713 @item make clean
714 @trindex clean
715 Erase from the build tree the files built by @code{make all}.
716 @item make distclean
717 @trindex distclean
718 Additionally erase anything @code{./configure} created.
719 @item make check
720 @trindex check
721 Run the test suite, if any.
722 @item make installcheck
723 @trindex installcheck
724 Check the installed programs or libraries, if supported.
725 @item make dist
726 @trindex dist
727 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
728 files.
729 @end table
730
731 @node Standard Directory Variables
732 @subsection Standard Directory Variables
733 @cindex directory variables
734
735 The GNU Coding Standards also specify a hierarchy of variables to
736 denote installation directories.  Some of these are:
737
738 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
739 @headitem Directory variable    @tab Default value
740 @item @code{prefix}              @tab @code{/usr/local}
741 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
742 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
743 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
744 @item @w{@ @ @ @ @dots{}}
745 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
746 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
747 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
748 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
749 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
750 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
751 @item @w{@ @ @dots{}}
752 @end multitable
753
754 @c We should provide a complete table somewhere, but not here.  The
755 @c complete list of directory variables it too confusing as-is.  It
756 @c requires some explanations that are too complicated for this
757 @c introduction.  Besides listing directories like localstatedir
758 @c would make the explanations in ``Two-Part Install'' harder.
759
760 Each of these directories has a role which is often obvious from its
761 name.  In a package, any installable file will be installed in one of
762 these directories.  For instance in @code{amhello-1.0}, the program
763 @file{hello} is to be installed in @var{bindir}, the directory for
764 binaries.  The default value for this directory is
765 @file{/usr/local/bin}, but the user can supply a different value when
766 calling @command{configure}.  Also the file @file{README} will be
767 installed into @var{docdir}, which defaults to
768 @file{/usr/local/share/doc/amhello}.
769
770 @opindex --prefix
771
772 As a user, if you wish to install a package on your own account, you
773 could proceed as follows:
774
775 @example
776 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
777 @dots{}
778 ~/amhello-1.0 % @kbd{make}
779 @dots{}
780 ~/amhello-1.0 % @kbd{make install}
781 @dots{}
782 @end example
783
784 This would install @file{~/usr/bin/hello} and
785 @file{~/usr/share/doc/amhello/README}.
786
787 The list of all such directory options is shown by
788 @code{./configure --help}.
789
790 @node Standard Configuration Variables
791 @subsection Standard Configuration Variables
792 @cindex configuration variables, overriding
793
794 The GNU Coding Standards also define a set of standard configuration
795 variables used during the build.  Here are some:
796
797 @table @asis
798 @item @code{CC}
799 C compiler command
800 @item @code{CFLAGS}
801 C compiler flags
802 @item @code{CXX}
803 C++ compiler command
804 @item @code{CXXFLAGS}
805 C++ compiler flags
806 @item @code{LDFLAGS}
807 linker flags
808 @item @code{CPPFLAGS}
809 C/C++ preprocessor flags
810 @item @dots{}
811 @end table
812
813 @command{configure} usually does a good job at setting appropriate
814 values for these variables, but there are cases where you may want to
815 override them.  For instance you may have several versions of a
816 compiler installed and would like to use another one, you may have
817 header files installed outside the default search path of the
818 compiler, or even libraries out of the way of the linker.
819
820 Here is how one would call @command{configure} to force it to use
821 @command{gcc-3} as C compiler, use header files from
822 @file{~/usr/include} when compiling, and libraries from
823 @file{~/usr/lib} when linking.
824
825 @example
826 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
827 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
828 @end example
829
830 Again, a full list of these variables appears in the output of
831 @code{./configure --help}.
832
833 @node config.site
834 @subsection Overriding Default Configuration Setting with @file{config.site}
835 @cindex @file{config.site} example
836
837 When installing several packages using the same setup, it can be
838 convenient to create a file to capture common settings.
839 If a file named @file{@var{prefix}/share/config.site} exists,
840 @command{configure} will source it at the beginning of its execution.
841
842 Recall the command from the previous section:
843
844 @example
845 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
846 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
847 @end example
848
849 Assuming we are installing many package in @file{~/usr}, and will
850 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
851 @code{LDFLAGS}, we can automate this by creating the following
852 @file{~/usr/share/config.site} file:
853
854 @example
855 test -z "$CC" && CC=gcc-3
856 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
857 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
858 @end example
859
860 Now, any time a @file{configure} script is using the @file{~/usr}
861 prefix, it will execute the above @file{config.site} and define
862 these three variables.
863
864 @example
865 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
866 configure: loading site script /home/adl/usr/share/config.site
867 @dots{}
868 @end example
869
870 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
871 Manual}, for more information about this feature.
872
873
874 @node VPATH Builds
875 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
876 @cindex Parallel build trees
877 @cindex VPATH builds
878 @cindex source tree and build tree
879 @cindex build tree and source tree
880 @cindex trees, source vs.@: build
881
882 The GNU Build System distinguishes two trees: the source tree, and
883 the build tree.
884
885 The source tree is rooted in the directory containing
886 @file{configure}.  It contains all the sources files (those that are
887 distributed), and may be arranged using several subdirectories.
888
889 The build tree is rooted in the directory in which @file{configure}
890 was run, and is populated with all object files, programs, libraries,
891 and other derived files built from the sources (and hence not
892 distributed).  The build tree usually has the same subdirectory layout
893 as the source tree; its subdirectories are created automatically by
894 the build system.
895
896 If @file{configure} is executed in its own directory, the source and
897 build trees are combined: derived files are constructed in the same
898 directories as their sources.  This was the case in our first
899 installation example (@pxref{Basic Installation}).
900
901 A common request from users is that they want to confine all derived
902 files to a single directory, to keep their source directories
903 uncluttered.  Here is how we could run @file{configure} to build
904 everything in a subdirectory called @file{build/}.
905
906 @example
907 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
908 ~ % @kbd{cd amhello-1.0}
909 ~/amhello-1.0 % @kbd{mkdir build && cd build}
910 ~/amhello-1.0/build % @kbd{../configure}
911 @dots{}
912 ~/amhello-1.0/build % @kbd{make}
913 @dots{}
914 @end example
915
916 These setups, where source and build trees are different, are often
917 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
918 @emph{parallel build} is misleading: the word @emph{parallel} is a
919 reference to the way the build tree shadows the source tree, it is not
920 about some concurrency in the way build commands are run.  For this
921 reason we refer to such setups using the name @emph{VPATH builds} in
922 the following.  @emph{VPATH} is the name of the @command{make} feature
923 used by the @file{Makefile}s to allow these builds (@pxref{General
924 Search, , @code{VPATH} Search Path for All Prerequisites, make, The
925 GNU Make Manual}).
926
927 @cindex multiple configurations, example
928 @cindex debug build, example
929 @cindex optimized build, example
930
931 VPATH builds have other interesting uses.  One is to build the same
932 sources with multiple configurations.  For instance:
933
934 @c Keep in sync with amhello-cflags.test.
935 @example
936 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
937 ~ % @kbd{cd amhello-1.0}
938 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
939 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
940 @dots{}
941 ~/amhello-1.0/debug % @kbd{make}
942 @dots{}
943 ~/amhello-1.0/debug % cd ../optim
944 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
945 @dots{}
946 ~/amhello-1.0/optim % @kbd{make}
947 @dots{}
948 @end example
949
950 With network file systems, a similar approach can be used to build the
951 same sources on different machines.  For instance, suppose that the
952 sources are installed on a directory shared by two hosts: @code{HOST1}
953 and @code{HOST2}, which may be different platforms.
954
955 @example
956 ~ % @kbd{cd /nfs/src}
957 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
958 @end example
959
960 On the first host, you could create a local build directory:
961 @example
962 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
963 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
964 ...
965 [HOST1] /tmp/amh % @kbd{make && sudo make install}
966 ...
967 @end example
968
969 @noindent
970 (Here we assume that the installer has configured @command{sudo} so it
971 can execute @code{make install} with root privileges; it is more convenient
972 than using @command{su} like in @ref{Basic Installation}).
973
974 On the second host, you would do exactly the same, possibly at
975 the same time:
976 @example
977 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
978 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
979 ...
980 [HOST2] /tmp/amh % @kbd{make && sudo make install}
981 ...
982 @end example
983
984 @cindex read-only source tree
985 @cindex source tree, read-only
986
987 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
988 directory from being read-only.  In fact VPATH builds are also a means
989 of building packages from a read-only medium such as a CD-ROM.  (The
990 FSF used to sell CD-ROM with unpacked source code, before the GNU
991 project grew so big.)
992
993 @node Two-Part Install
994 @subsection Two-Part Installation
995
996 In our last example (@pxref{VPATH Builds}), a source tree was shared
997 by two hosts, but compilation and installation were done separately on
998 each host.
999
1000 The GNU Build System also supports networked setups where part of the
1001 installed files should be shared amongst multiple hosts.  It does so
1002 by distinguishing architecture-dependent files from
1003 architecture-independent files, and providing two @file{Makefile}
1004 targets to install each of these classes of files.
1005
1006 @trindex install-exec
1007 @trindex install-data
1008
1009 These targets are @code{install-exec} for architecture-dependent files
1010 and @code{install-data} for architecture-independent files.
1011 The command we used up to now, @code{make install}, can be thought of
1012 as a shorthand for @code{make install-exec install-data}.
1013
1014 From the GNU Build System point of view, the distinction between
1015 architecture-dependent files and architecture-independent files is
1016 based exclusively on the directory variable used to specify their
1017 installation destination.  In the list of directory variables we
1018 provided earlier (@pxref{Standard Directory Variables}), all the
1019 variables based on @var{exec-prefix} designate architecture-dependent
1020 directories whose files will be installed by @code{make install-exec}.
1021 The others designate architecture-independent directories and will
1022 serve files installed by @code{make install-data}.  @xref{The Two Parts
1023 of Install}, for more details.
1024
1025 Here is how we could revisit our two-host installation example,
1026 assuming that (1) we want to install the package directly in
1027 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
1028 two hosts.
1029
1030 On the first host we would run
1031 @example
1032 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1033 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1034 ...
1035 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1036 ...
1037 @end example
1038
1039 On the second host, however, we need only install the
1040 architecture-specific files.
1041 @example
1042 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1043 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1044 ...
1045 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1046 ...
1047 @end example
1048
1049 In packages that have installation checks, it would make sense to run
1050 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1051 the package works correctly despite the apparent partial installation.
1052
1053 @node Cross-Compilation
1054 @subsection Cross-Compilation
1055 @cindex cross-compilation
1056
1057 To @dfn{cross-compile} is to build on one platform a binary that will
1058 run on another platform.  When speaking of cross-compilation, it is
1059 important to distinguish between the @dfn{build platform} on which
1060 the compilation is performed, and the @dfn{host platform} on which the
1061 resulting executable is expected to run.  The following
1062 @command{configure} options are used to specify each of them:
1063
1064 @table @option
1065 @item --build=@var{build}
1066 @opindex --build=@var{build}
1067 The system on which the package is built.
1068 @item --host=@var{host}
1069 @opindex --host=@var{host}
1070 The system where built programs and libraries will run.
1071 @end table
1072
1073 When the @option{--host} is used, @command{configure} will search for
1074 the cross-compiling suite for this platform.  Cross-compilation tools
1075 commonly have their target architecture as prefix of their name.  For
1076 instance my cross-compiler for MinGW32 has its binaries called
1077 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1078 @code{i586-mingw32msvc-as}, etc.
1079
1080 @cindex MinGW cross-compilation example
1081 @cindex cross-compilation example
1082
1083 Here is how we could build @code{amhello-1.0} for
1084 @code{i586-mingw32msvc} on a GNU/Linux PC.
1085
1086 @c Keep in sync with amhello-cross-compile.test.
1087 @smallexample
1088 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1089 checking for a BSD-compatible install... /usr/bin/install -c
1090 checking whether build environment is sane... yes
1091 checking for gawk... gawk
1092 checking whether make sets $(MAKE)... yes
1093 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1094 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1095 checking for C compiler default output file name... a.exe
1096 checking whether the C compiler works... yes
1097 checking whether we are cross compiling... yes
1098 checking for suffix of executables... .exe
1099 checking for suffix of object files... o
1100 checking whether we are using the GNU C compiler... yes
1101 checking whether i586-mingw32msvc-gcc accepts -g... yes
1102 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1103 @dots{}
1104 ~/amhello-1.0 % @kbd{make}
1105 @dots{}
1106 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1107 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1108 @end smallexample
1109
1110 The @option{--host} and @option{--build} options are usually all we
1111 need for cross-compiling.  The only exception is if the package being
1112 built is itself a cross-compiler: we need a third option to specify
1113 its target architecture.
1114
1115 @table @option
1116 @item --target=@var{target}
1117 @opindex --target=@var{target}
1118 When building compiler tools: the system for which the tools will
1119 create output.
1120 @end table
1121
1122 For instance when installing GCC, the GNU Compiler Collection, we can
1123 use @option{--target=@/@var{target}} to specify that we want to build
1124 GCC as a cross-compiler for @var{target}.  Mixing @option{--build} and
1125 @option{--target}, we can actually cross-compile a cross-compiler;
1126 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1127
1128 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1129 Autoconf Manual}, for more information about these @command{configure}
1130 options.
1131
1132 @node Renaming
1133 @subsection Renaming Programs at Install Time
1134 @cindex Renaming programs
1135 @cindex Transforming program names
1136 @cindex Programs, renaming during installation
1137
1138 The GNU Build System provides means to automatically rename
1139 executables and manpages before they are installed (@pxref{Man Pages}).
1140 This is especially convenient
1141 when installing a GNU package on a system that already has a
1142 proprietary implementation you do not want to overwrite.  For instance,
1143 you may want to install GNU @command{tar} as @command{gtar} so you can
1144 distinguish it from your vendor's @command{tar}.
1145
1146 This can be done using one of these three @command{configure} options.
1147
1148 @table @option
1149 @item --program-prefix=@var{prefix}
1150 @opindex --program-prefix=@var{prefix}
1151 Prepend @var{prefix} to installed program names.
1152 @item --program-suffix=@var{suffix}
1153 @opindex --program-suffix=@var{suffix}
1154 Append @var{suffix} to installed program names.
1155 @item --program-transform-name=@var{program}
1156 @opindex --program-transform-name=@var{program}
1157 Run @code{sed @var{program}} on installed program names.
1158 @end table
1159
1160 The following commands would install @file{hello}
1161 as @file{/usr/local/bin/test-hello}, for instance.
1162
1163 @example
1164 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1165 @dots{}
1166 ~/amhello-1.0 % @kbd{make}
1167 @dots{}
1168 ~/amhello-1.0 % @kbd{sudo make install}
1169 @dots{}
1170 @end example
1171
1172 @node DESTDIR
1173 @subsection Building Binary Packages Using DESTDIR
1174 @vindex DESTDIR
1175
1176 The GNU Build System's @code{make install} and @code{make uninstall}
1177 interface does not exactly fit the needs of a system administrator
1178 who has to deploy and upgrade packages on lots of hosts.  In other
1179 words, the GNU Build System does not replace a package manager.
1180
1181 Such package managers usually need to know which files have been
1182 installed by a package, so a mere @code{make install} is
1183 inappropriate.
1184
1185 @cindex Staged installation
1186
1187 The @code{DESTDIR} variable can be used to perform a staged
1188 installation.  The package should be configured as if it was going to
1189 be installed in its final location (e.g., @code{--prefix /usr}), but
1190 when running @code{make install}, the @code{DESTDIR} should be set to
1191 the absolute name of a directory into which the installation will be
1192 diverted.  From this directory it is easy to review which files are
1193 being installed where, and finally copy them to their final location
1194 by some means.
1195
1196 @cindex Binary package
1197
1198 For instance here is how we could create a binary package containing a
1199 snapshot of all the files to be installed.
1200
1201 @c Keep in sync with amhello-binpkg.test.
1202 @example
1203 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1204 @dots{}
1205 ~/amhello-1.0 % @kbd{make}
1206 @dots{}
1207 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1208 @dots{}
1209 ~/amhello-1.0 % @kbd{cd ~/inst}
1210 ~/inst % @kbd{find . -type f -print > ../files.lst}
1211 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1212 ./usr/bin/hello
1213 ./usr/share/doc/amhello/README
1214 @end example
1215
1216 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1217 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1218 instead of @samp{.} as argument for @command{tar} avoids entries for
1219 each subdirectory in the archive: we would not like @command{tar} to
1220 restore the modification time of @file{/}, @file{/usr/}, etc.)
1221
1222 Note that when building packages for several architectures, it might
1223 be convenient to use @code{make install-data} and @code{make
1224 install-exec} (@pxref{Two-Part Install}) to gather
1225 architecture-independent files in a single package.
1226
1227 @xref{Install}, for more information.
1228
1229 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1230 @c UNINSTALL counterparts.
1231
1232 @node Preparing Distributions
1233 @subsection Preparing Distributions
1234 @cindex Preparing distributions
1235 @cindex Packages, preparation
1236 @cindex Distributions, preparation
1237
1238 We have already mentioned @code{make dist}.  This target collects all
1239 your source files and the necessary parts of the build system to
1240 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1241
1242 @cindex @code{distcheck} better than @code{dist}
1243
1244 Another, more useful command is @code{make distcheck}.  The
1245 @code{distcheck} target constructs
1246 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1247 but it additionally ensures most of the use cases presented so far
1248 work:
1249
1250 @itemize @bullet
1251 @item
1252 It attempts a full compilation of the package (@pxref{Basic
1253 Installation}), unpacking the newly constructed tarball, running
1254 @code{make}, @code{make check}, @code{make install}, as well as
1255 @code{make installcheck}, and even @code{make dist},
1256 @item
1257 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1258 @item
1259 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1260 uninstall} do not omit any file (@pxref{Standard Targets}),
1261 @item
1262 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1263 @end itemize
1264
1265 All of these actions are performed in a temporary subdirectory, so
1266 that no root privileges are required.
1267
1268 Releasing a package that fails @code{make distcheck} means that one of
1269 the scenarios we presented will not work and some users will be
1270 disappointed.  Therefore it is a good practice to release a package
1271 only after a successful @code{make distcheck}.  This of course does
1272 not imply that the package will be flawless, but at least it will
1273 prevent some of the embarrassing errors you may find in packages
1274 released by people who have never heard about @code{distcheck} (like
1275 @code{DESTDIR} not working because of a typo, or a distributed file
1276 being erased by @code{make clean}, or even @code{VPATH} builds not
1277 working).
1278
1279 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1280 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1281 information about @code{distcheck}.
1282
1283 @node Dependency Tracking
1284 @subsection Automatic Dependency Tracking
1285 @cindex Dependency tracking
1286
1287 Dependency tracking is performed as a side-effect of compilation.
1288 Each time the build system compiles a source file, it computes its
1289 list of dependencies (in C these are the header files included by the
1290 source being compiled).  Later, any time @command{make} is run and a
1291 dependency appears to have changed, the dependent files will be
1292 rebuilt.
1293
1294 Automake generates code for automatic dependency tracking by default,
1295 unless the developer chooses to override it; for more information,
1296 @pxref{Dependencies}.
1297
1298 When @command{configure} is executed, you can see it probing each
1299 compiler for the dependency mechanism it supports (several mechanisms
1300 can be used):
1301
1302 @example
1303 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1304 @dots{}
1305 checking dependency style of gcc... gcc3
1306 @dots{}
1307 @end example
1308
1309 Because dependencies are only computed as a side-effect of the
1310 compilation, no dependency information exists the first time a package
1311 is built.  This is OK because all the files need to be built anyway:
1312 @code{make} does not have to decide which files need to be rebuilt.
1313 In fact, dependency tracking is completely useless for one-time builds
1314 and there is a @command{configure} option to disable this:
1315
1316 @table @option
1317 @item --disable-dependency-tracking
1318 @opindex --disable-dependency-tracking
1319 Speed up one-time builds.
1320 @end table
1321
1322 Some compilers do not offer any practical way to derive the list of
1323 dependencies as a side-effect of the compilation, requiring a separate
1324 run (maybe of another tool) to compute these dependencies.  The
1325 performance penalty implied by these methods is important enough to
1326 disable them by default.  The option @option{--enable-dependency-tracking}
1327 must be passed to @command{configure} to activate them.
1328
1329 @table @option
1330 @item --enable-dependency-tracking
1331 @opindex --enable-dependency-tracking
1332 Do not reject slow dependency extractors.
1333 @end table
1334
1335 @xref{Dependency Tracking Evolution}, for some discussion about the
1336 different dependency tracking schemes used by Automake over the years.
1337
1338 @node Nested Packages
1339 @subsection Nested Packages
1340 @cindex Nested packages
1341 @cindex Packages, nested
1342 @cindex Subpackages
1343
1344 Although nesting packages isn't something we would recommend to
1345 someone who is discovering the Autotools, it is a nice feature worthy
1346 of mention in this small advertising tour.
1347
1348 Autoconfiscated packages (that means packages whose build system have
1349 been created by Autoconf and friends) can be nested to arbitrary
1350 depth.
1351
1352 A typical setup is that package A will distribute one of the libraries
1353 it needs in a subdirectory.  This library B is a complete package with
1354 its own GNU Build System.  The @command{configure} script of A will
1355 run the @command{configure} script of B as part of its execution,
1356 building and installing A will also build and install B.  Generating a
1357 distribution for A will also include B.
1358
1359 It is possible to gather several packages like this.  GCC is a heavy
1360 user of this feature.  This gives installers a single package to
1361 configure, build and install, while it allows developers to work on
1362 subpackages independently.
1363
1364 When configuring nested packages, the @command{configure} options
1365 given to the top-level @command{configure} are passed recursively to
1366 nested @command{configure}s.  A package that does not understand an
1367 option will ignore it, assuming it is meaningful to some other
1368 package.
1369
1370 @opindex --help=recursive
1371
1372 The command @code{configure --help=recursive} can be used to display
1373 the options supported by all the included packages.
1374
1375 @xref{Subpackages}, for an example setup.
1376
1377 @node Why Autotools
1378 @section How Autotools Help
1379 @cindex Autotools, purpose
1380
1381 There are several reasons why you may not want to implement the GNU
1382 Build System yourself (read: write a @file{configure} script and
1383 @file{Makefile}s yourself).
1384
1385 @itemize @bullet
1386 @item
1387 As we have seen, the GNU Build System has a lot of
1388 features (@pxref{Use Cases}).
1389 Some users may expect features you have not implemented because
1390 you did not need them.
1391 @item
1392 Implementing these features portably is difficult and exhausting.
1393 Think of writing portable shell scripts, and portable
1394 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1395 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1396 convince yourself.
1397 @item
1398 You will have to upgrade your setup to follow changes to the GNU
1399 Coding Standards.
1400 @end itemize
1401
1402 The GNU Autotools take all this burden off your back and provide:
1403
1404 @itemize @bullet
1405 @item
1406 Tools to create a portable, complete, and self-contained GNU Build
1407 System, from simple instructions.
1408 @emph{Self-contained} meaning the resulting build system does not
1409 require the GNU Autotools.
1410 @item
1411 A central place where fixes and improvements are made:
1412 a bug-fix for a portability issue will benefit every package.
1413 @end itemize
1414
1415 Yet there also exist reasons why you may want NOT to use the
1416 Autotools@enddots{} For instance you may be already using (or used to)
1417 another incompatible build system.  Autotools will only be useful if
1418 you do accept the concepts of the GNU Build System.  People who have their
1419 own idea of how a build system should work will feel frustrated by the
1420 Autotools.
1421
1422 @node Hello World
1423 @section A Small Hello World
1424 @cindex Example Hello World
1425 @cindex Hello World example
1426 @cindex @file{amhello-1.0.tar.gz}, creation
1427
1428 In this section we recreate the @file{amhello-1.0} package from
1429 scratch.  The first subsection shows how to call the Autotools to
1430 instantiate the GNU Build System, while the second explains the
1431 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1432 by the Autotools.
1433
1434 @anchor{amhello Explained}
1435 @menu
1436 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1437 * amhello's configure.ac Setup Explained::
1438 * amhello's Makefile.am Setup Explained::
1439 @end menu
1440
1441 @node Creating amhello
1442 @subsection Creating @file{amhello-1.0.tar.gz}
1443
1444 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1445 The package is simple enough so that we will only need to write 5
1446 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1447 that is distributed with Automake if you do not want to write them.)
1448
1449 Create the following files in an empty directory.
1450
1451 @itemize @bullet
1452
1453 @item
1454 @file{src/main.c} is the source file for the @file{hello} program.  We
1455 store it in the @file{src/} subdirectory, because later, when the package
1456 evolves, it will ease the addition of a @file{man/} directory for man
1457 pages, a @file{data/} directory for data files, etc.
1458 @example
1459 ~/amhello % @kbd{cat src/main.c}
1460 #include <config.h>
1461 #include <stdio.h>
1462
1463 int
1464 main (void)
1465 @{
1466   puts ("Hello World!");
1467   puts ("This is " PACKAGE_STRING ".");
1468   return 0;
1469 @}
1470 @end example
1471
1472 @item
1473 @file{README} contains some very limited documentation for our little
1474 package.
1475 @example
1476 ~/amhello % @kbd{cat README}
1477 This is a demonstration package for GNU Automake.
1478 Type `info Automake' to read the Automake manual.
1479 @end example
1480
1481 @item
1482 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1483 instructions for these two directories.
1484
1485 @example
1486 ~/amhello % @kbd{cat src/Makefile.am}
1487 bin_PROGRAMS = hello
1488 hello_SOURCES = main.c
1489 ~/amhello % @kbd{cat Makefile.am}
1490 SUBDIRS = src
1491 dist_doc_DATA = README
1492 @end example
1493
1494 @item
1495 Finally, @file{configure.ac} contains Autoconf instructions to
1496 create the @command{configure} script.
1497
1498 @example
1499 ~/amhello % @kbd{cat configure.ac}
1500 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1501 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1502 AC_PROG_CC
1503 AC_CONFIG_HEADERS([config.h])
1504 AC_CONFIG_FILES([
1505  Makefile
1506  src/Makefile
1507 ])
1508 AC_OUTPUT
1509 @end example
1510 @end itemize
1511
1512 @cindex @command{autoreconf}, example
1513
1514 Once you have these five files, it is time to run the Autotools to
1515 instantiate the build system.  Do this using the @command{autoreconf}
1516 command as follows:
1517
1518 @example
1519 ~/amhello % @kbd{autoreconf --install}
1520 configure.ac: installing `./install-sh'
1521 configure.ac: installing `./missing'
1522 src/Makefile.am: installing `./depcomp'
1523 @end example
1524
1525 At this point the build system is complete.
1526
1527 In addition to the three scripts mentioned in its output, you can see
1528 that @command{autoreconf} created four other files: @file{configure},
1529 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1530 The latter three files are templates that will be adapted to the
1531 system by @command{configure} under the names @file{config.h},
1532 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1533
1534 @example
1535 ~/amhello % @kbd{./configure}
1536 checking for a BSD-compatible install... /usr/bin/install -c
1537 checking whether build environment is sane... yes
1538 checking for gawk... no
1539 checking for mawk... mawk
1540 checking whether make sets $(MAKE)... yes
1541 checking for gcc... gcc
1542 checking for C compiler default output file name... a.out
1543 checking whether the C compiler works... yes
1544 checking whether we are cross compiling... no
1545 checking for suffix of executables...
1546 checking for suffix of object files... o
1547 checking whether we are using the GNU C compiler... yes
1548 checking whether gcc accepts -g... yes
1549 checking for gcc option to accept ISO C89... none needed
1550 checking for style of include used by make... GNU
1551 checking dependency style of gcc... gcc3
1552 configure: creating ./config.status
1553 config.status: creating Makefile
1554 config.status: creating src/Makefile
1555 config.status: creating config.h
1556 config.status: executing depfiles commands
1557 @end example
1558
1559 @trindex distcheck
1560 @cindex @code{distcheck} example
1561
1562 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1563 being created at the end after @command{configure} has probed the
1564 system.  It is now possible to run all the targets we wish
1565 (@pxref{Standard Targets}).  For instance:
1566
1567 @example
1568 ~/amhello % @kbd{make}
1569 @dots{}
1570 ~/amhello % @kbd{src/hello}
1571 Hello World!
1572 This is amhello 1.0.
1573 ~/amhello % @kbd{make distcheck}
1574 @dots{}
1575 =============================================
1576 amhello-1.0 archives ready for distribution:
1577 amhello-1.0.tar.gz
1578 =============================================
1579 @end example
1580
1581 Note that running @command{autoreconf} is only needed initially when
1582 the GNU Build System does not exist.  When you later change some
1583 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1584 relevant part of the build system will be regenerated automatically
1585 when you execute @command{make}.
1586
1587 @command{autoreconf} is a script that calls @command{autoconf},
1588 @command{automake}, and a bunch of other commands in the right order.
1589 If you are beginning with these tools, it is not important to figure
1590 out in which order all these tools should be invoked and why.  However,
1591 because Autoconf and Automake have separate manuals, the important
1592 point to understand is that @command{autoconf} is in charge of
1593 creating @file{configure} from @file{configure.ac}, while
1594 @command{automake} is in charge of creating @file{Makefile.in}s from
1595 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1596 direct you to the right manual when seeking answers.
1597
1598
1599 @node amhello's configure.ac Setup Explained
1600 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1601
1602 @cindex @file{configure.ac}, Hello World
1603
1604 Let us begin with the contents of @file{configure.ac}.
1605
1606 @example
1607 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1608 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1609 AC_PROG_CC
1610 AC_CONFIG_HEADERS([config.h])
1611 AC_CONFIG_FILES([
1612  Makefile
1613  src/Makefile
1614 ])
1615 AC_OUTPUT
1616 @end example
1617
1618 This file is read by both @command{autoconf} (to create
1619 @file{configure}) and @command{automake} (to create the various
1620 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1621 expanded as shell code to finally form the @file{configure} script.
1622 We will not elaborate on the syntax of this file, because the Autoconf
1623 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1624 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1625
1626 The macros prefixed with @code{AC_} are Autoconf macros, documented
1627 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1628 Index, autoconf, The Autoconf Manual}).  The macros that start with
1629 @code{AM_} are Automake macros, documented later in this manual
1630 (@pxref{Macro Index}).
1631
1632 The first two lines of @file{configure.ac} initialize Autoconf and
1633 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1634 its version number, and a contact address for bug-reports about the
1635 package (this address is output at the end of @code{./configure
1636 --help}, for instance).  When adapting this setup to your own package,
1637 by all means please do not blindly copy Automake's address: use the
1638 mailing list of your package, or your own mail address.
1639
1640 @opindex -Wall
1641 @opindex -Werror
1642 @opindex foreign
1643
1644 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1645 @command{automake} (@pxref{Options}).  @option{-Wall} and
1646 @option{-Werror} ask @command{automake} to turn on all warnings and
1647 report them as errors.  We are speaking of @strong{Automake} warnings
1648 here, such as dubious instructions in @file{Makefile.am}.  This has
1649 absolutely nothing to do with how the compiler will be called, even
1650 though it may support options with similar names.  Using @option{-Wall
1651 -Werror} is a safe setting when starting to work on a package: you do
1652 not want to miss any issues.  Later you may decide to relax things a
1653 bit.  The @option{foreign} option tells Automake that this package
1654 will not follow the GNU Standards.  GNU packages should always
1655 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1656 etc.  We do not want @command{automake} to complain about these
1657 missing files in our small example.
1658
1659 The @code{AC_PROG_CC} line causes the @command{configure} script to
1660 search for a C compiler and define the variable @code{CC} with its
1661 name.  The @file{src/Makefile.in} file generated by Automake uses the
1662 variable @code{CC} to build @file{hello}, so when @command{configure}
1663 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1664 @code{CC} with the value it has found.  If Automake is asked to create
1665 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1666 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1667
1668 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1669 @command{configure} script to create a @file{config.h} file gathering
1670 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1671 case, the @code{AC_INIT} macro already defined a few of them.  Here
1672 is an excerpt of @file{config.h} after @command{configure} has run:
1673
1674 @smallexample
1675 @dots{}
1676 /* Define to the address where bug reports for this package should be sent. */
1677 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1678
1679 /* Define to the full name and version of this package. */
1680 #define PACKAGE_STRING "amhello 1.0"
1681 @dots{}
1682 @end smallexample
1683
1684 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1685 it can use @code{PACKAGE_STRING}.  In a real-world project,
1686 @file{config.h} can grow really big, with one @samp{#define} per
1687 feature probed on the system.
1688
1689 The @code{AC_CONFIG_FILES} macro declares the list of files that
1690 @command{configure} should create from their @file{*.in} templates.
1691 Automake also scans this list to find the @file{Makefile.am} files it must
1692 process.  (This is important to remember: when adding a new directory
1693 to your project, you should add its @file{Makefile} to this list,
1694 otherwise Automake will never process the new @file{Makefile.am} you
1695 wrote in that directory.)
1696
1697 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1698 produces the part of the script in charge of creating the files
1699 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1700
1701 @cindex @command{autoscan}
1702
1703 When starting a new project, we suggest you start with such a simple
1704 @file{configure.ac}, and gradually add the other tests it requires.
1705 The command @command{autoscan} can also suggest a few of the tests
1706 your package may need (@pxref{autoscan Invocation, , Using
1707 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1708 Autoconf Manual}).
1709
1710
1711 @node amhello's Makefile.am Setup Explained
1712 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1713
1714 @cindex @file{Makefile.am}, Hello World
1715
1716 We now turn to @file{src/Makefile.am}.  This file contains
1717 Automake instructions to build and install @file{hello}.
1718
1719 @example
1720 bin_PROGRAMS = hello
1721 hello_SOURCES = main.c
1722 @end example
1723
1724 A @file{Makefile.am} has the same syntax as an ordinary
1725 @file{Makefile}.  When @command{automake} processes a
1726 @file{Makefile.am} it copies the entire file into the output
1727 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1728 @command{configure}) but will react to certain variable definitions
1729 by generating some build rules and other variables.
1730 Often @file{Makefile.am}s contain only a list of variable definitions as
1731 above, but they can also contain other variable and rule definitions that
1732 @command{automake} will pass along without interpretation.
1733
1734 Variables that end with @code{_PROGRAMS} are special variables
1735 that list programs that the resulting @file{Makefile} should build.
1736 In Automake speak, this @code{_PROGRAMS} suffix is called a
1737 @dfn{primary}; Automake recognizes other primaries such as
1738 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1739 to different types of files.
1740
1741 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1742 @command{automake} that the resulting programs should be installed in
1743 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1744 to denote destination directories and allow users to customize these
1745 locations (@pxref{Standard Directory Variables}).  Any such directory
1746 variable can be put in front of a primary (omitting the @code{dir}
1747 suffix) to tell @command{automake} where to install the listed files.
1748
1749 Programs need to be built from source files, so for each program
1750 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1751 @command{automake} will look for another variable named
1752 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1753 than one source file: they will all be compiled and linked together.
1754
1755 Automake also knows that source files need to be distributed when
1756 creating a tarball (unlike built programs).  So a side-effect of this
1757 @code{hello_SOURCES} declaration is that @file{main.c} will be
1758 part of the tarball created by @code{make dist}.
1759
1760 Finally here are some explanations regarding the top-level
1761 @file{Makefile.am}.
1762
1763 @example
1764 SUBDIRS = src
1765 dist_doc_DATA = README
1766 @end example
1767
1768 @code{SUBDIRS} is a special variable listing all directories that
1769 @command{make} should recurse into before processing the current
1770 directory.  So this line is responsible for @command{make} building
1771 @file{src/hello} even though we run it from the top-level.  This line
1772 also causes @code{make install} to install @file{src/hello} before
1773 installing @file{README} (not that this order matters).
1774
1775 The line @code{dist_doc_DATA = README} causes @file{README} to be
1776 distributed and installed in @var{docdir}.  Files listed with the
1777 @code{_DATA} primary are not automatically part of the tarball built
1778 with @code{make dist}, so we add the @code{dist_} prefix so they get
1779 distributed.  However, for @file{README} it would not have been
1780 necessary: @command{automake} automatically distributes any
1781 @file{README} file it encounters (the list of other files
1782 automatically distributed is presented by @code{automake --help}).
1783 The only important effect of this second line is therefore to install
1784 @file{README} during @code{make install}.
1785
1786 One thing not covered in this example is accessing the installation
1787 directory values (@pxref{Standard Directory Variables}) from your
1788 program code, that is, converting them into defined macros.  For this,
1789 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1790
1791
1792 @node Generalities
1793 @chapter General ideas
1794
1795 The following sections cover a few basic ideas that will help you
1796 understand how Automake works.
1797
1798 @menu
1799 * General Operation::           General operation of Automake
1800 * Strictness::                  Standards conformance checking
1801 * Uniform::                     The Uniform Naming Scheme
1802 * Length Limitations::          Staying below the command line length limit
1803 * Canonicalization::            How derived variables are named
1804 * User Variables::              Variables reserved for the user
1805 * Auxiliary Programs::          Programs automake might require
1806 @end menu
1807
1808
1809 @node General Operation
1810 @section General Operation
1811
1812 Automake works by reading a @file{Makefile.am} and generating a
1813 @file{Makefile.in}.  Certain variables and rules defined in the
1814 @file{Makefile.am} instruct Automake to generate more specialized code;
1815 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1816 for compiling and linking programs to be generated.
1817
1818 @cindex Non-standard targets
1819 @cindex @code{git-dist}, non-standard example
1820 @trindex git-dist
1821
1822 The variable definitions and rules in the @file{Makefile.am} are
1823 copied mostly verbatim into the generated file, with all variable
1824 definitions preceding all rules.  This allows you to add almost
1825 arbitrary code into the generated @file{Makefile.in}.  For instance,
1826 the Automake distribution includes a non-standard rule for the
1827 @code{git-dist} target, which the Automake maintainer uses to make
1828 distributions from the source control system.
1829
1830 @cindex GNU make extensions
1831
1832 Note that most GNU make extensions are not recognized by Automake.  Using
1833 such extensions in a @file{Makefile.am} will lead to errors or confusing
1834 behavior.
1835
1836 @cindex Append operator
1837 @cmindex +=
1838 A special exception is that the GNU make append operator, @samp{+=}, is
1839 supported.  This operator appends its right hand argument to the variable
1840 specified on the left.  Automake will translate the operator into
1841 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1842
1843 Automake tries to keep comments grouped with any adjoining rules or
1844 variable definitions.
1845
1846 @cindex Limitations of automake parser
1847 @cindex Automake parser, limitations of
1848 @cindex indentation in Makefile.am
1849 Generally, Automake is not particularly smart in the parsing of unusual
1850 Makefile constructs, so you're advised to avoid fancy constructs or
1851 ``creative'' use of whitespaces.
1852 @c Keep this in sync with doc-parsing-buglets-tabs.test.
1853 For example, @key{TAB} characters cannot be used between a target name
1854 and the following ``@code{:}'' character, and variable assignments
1855 shouldn't be indented with @key{TAB} characters.
1856 @c Keep this in sync with doc-parsing-buglets-colneq-subst.test.
1857 Also, using more complex macro in target names can cause trouble:
1858
1859 @example
1860 % @kbd{cat Makefile.am}
1861 $(FOO:=x): bar
1862 % @kbd{automake}
1863 Makefile.am:1: bad characters in variable name `$(FOO'
1864 Makefile.am:1: `:='-style assignments are not portable
1865 @end example
1866
1867 @cindex Make targets, overriding
1868 @cindex Make rules, overriding
1869 @cindex Overriding make rules
1870 @cindex Overriding make targets
1871
1872 A rule defined in @file{Makefile.am} generally overrides any such
1873 rule of a similar name that would be automatically generated by
1874 @command{automake}.  Although this is a supported feature, it is generally
1875 best to avoid making use of it, as sometimes the generated rules are
1876 very particular.
1877
1878 @cindex Variables, overriding
1879 @cindex Overriding make variables
1880
1881 Similarly, a variable defined in @file{Makefile.am} or
1882 @code{AC_SUBST}ed from @file{configure.ac} will override any
1883 definition of the variable that @command{automake} would ordinarily
1884 create.  This feature is more often useful than the ability to
1885 override a rule.  Be warned that many of the variables generated by
1886 @command{automake} are considered to be for internal use only, and their
1887 names might change in future releases.
1888
1889 @cindex Recursive operation of Automake
1890 @cindex Automake, recursive operation
1891 @cindex Example of recursive operation
1892
1893 When examining a variable definition, Automake will recursively examine
1894 variables referenced in the definition.  For example, if Automake is
1895 looking at the content of @code{foo_SOURCES} in this snippet
1896
1897 @c Keep in sync with interp.test.
1898 @example
1899 xs = a.c b.c
1900 foo_SOURCES = c.c $(xs)
1901 @end example
1902
1903 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1904 contents of @code{foo_SOURCES}.
1905
1906 @cindex @code{##} (special Automake comment)
1907 @cindex Special Automake comment
1908 @cindex Comment, special to Automake
1909
1910 Automake also allows a form of comment that is @emph{not} copied into
1911 the output; all lines beginning with @samp{##} (leading spaces allowed)
1912 are completely ignored by Automake.
1913
1914 It is customary to make the first line of @file{Makefile.am} read:
1915
1916 @cindex Makefile.am, first line
1917 @cindex First line of Makefile.am
1918
1919 @example
1920 ## Process this file with automake to produce Makefile.in
1921 @end example
1922
1923 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1924 @c I don't know quite what to say.
1925
1926 @c FIXME document customary ordering of Makefile.am here!
1927
1928
1929 @node Strictness
1930 @section Strictness
1931
1932 @cindex Non-GNU packages
1933
1934 While Automake is intended to be used by maintainers of GNU packages, it
1935 does make some effort to accommodate those who wish to use it, but do
1936 not want to use all the GNU conventions.
1937
1938 @cindex Strictness, defined
1939 @cindex Strictness, @option{foreign}
1940 @cindex @option{foreign} strictness
1941 @cindex Strictness, @option{gnu}
1942 @cindex @option{gnu} strictness
1943 @cindex Strictness, @option{gnits}
1944 @cindex @option{gnits} strictness
1945
1946 To this end, Automake supports three levels of @dfn{strictness}---the
1947 strictness indicating how stringently Automake should check standards
1948 conformance.
1949
1950 The valid strictness levels are:
1951
1952 @table @option
1953 @item foreign
1954 Automake will check for only those things that are absolutely
1955 required for proper operations.  For instance, whereas GNU standards
1956 dictate the existence of a @file{NEWS} file, it will not be required in
1957 this mode.  This strictness will also turn off some warnings by default
1958 (among them, portability warnings).
1959 The name comes from the fact that Automake is intended to be
1960 used for GNU programs; these relaxed rules are not the standard mode of
1961 operation.
1962
1963 @item gnu
1964 Automake will check---as much as possible---for compliance to the GNU
1965 standards for packages.  This is the default.
1966
1967 @item gnits
1968 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1969 standards}.  These are based on the GNU standards, but are even more
1970 detailed.  Unless you are a Gnits standards contributor, it is
1971 recommended that you avoid this option until such time as the Gnits
1972 standard is actually published (which may never happen).
1973 @end table
1974
1975 @xref{Gnits}, for more information on the precise implications of the
1976 strictness level.
1977
1978 Automake also has a special ``cygnus'' mode that is similar to
1979 strictness but handled differently.  This mode is useful for packages
1980 that are put into a ``Cygnus'' style tree (e.g., the GCC tree).
1981 @xref{Cygnus}, for more information on this mode.
1982
1983
1984 @node Uniform
1985 @section The Uniform Naming Scheme
1986
1987 @cindex Uniform naming scheme
1988
1989 Automake variables generally follow a @dfn{uniform naming scheme} that
1990 makes it easy to decide how programs (and other derived objects) are
1991 built, and how they are installed.  This scheme also supports
1992 @command{configure} time determination of what should be built.
1993
1994 @cindex @code{_PROGRAMS} primary variable
1995 @cindex @code{PROGRAMS} primary variable
1996 @cindex Primary variable, @code{PROGRAMS}
1997 @cindex Primary variable, defined
1998 @vindex _PROGRAMS
1999
2000 At @command{make} time, certain variables are used to determine which
2001 objects are to be built.  The variable names are made of several pieces
2002 that are concatenated together.
2003
2004 The piece that tells @command{automake} what is being built is commonly called
2005 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
2006 list of programs that are to be compiled and linked.
2007 @vindex PROGRAMS
2008
2009 @cindex @code{pkgdatadir}, defined
2010 @cindex @code{pkgincludedir}, defined
2011 @cindex @code{pkglibdir}, defined
2012 @cindex @code{pkglibexecdir}, defined
2013
2014 @vindex pkgdatadir
2015 @vindex pkgincludedir
2016 @vindex pkglibdir
2017 @vindex pkglibexecdir
2018
2019 @cindex @code{PACKAGE}, directory
2020 A different set of names is used to decide where the built objects
2021 should be installed.  These names are prefixes to the primary, and they
2022 indicate which standard directory should be used as the installation
2023 directory.  The standard directory names are given in the GNU standards
2024 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
2025 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
2026 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
2027 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
2028 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
2029
2030 @cindex @code{EXTRA_}, prepending
2031 For each primary, there is one additional variable named by prepending
2032 @samp{EXTRA_} to the primary name.  This variable is used to list
2033 objects that may or may not be built, depending on what
2034 @command{configure} decides.  This variable is required because Automake
2035 must statically know the entire list of objects that may be built in
2036 order to generate a @file{Makefile.in} that will work in all cases.
2037
2038 @cindex @code{EXTRA_PROGRAMS}, defined
2039 @cindex Example, @code{EXTRA_PROGRAMS}
2040 @cindex @command{cpio} example
2041
2042 For instance, @command{cpio} decides at configure time which programs
2043 should be built.  Some of the programs are installed in @code{bindir},
2044 and some are installed in @code{sbindir}:
2045
2046 @example
2047 EXTRA_PROGRAMS = mt rmt
2048 bin_PROGRAMS = cpio pax
2049 sbin_PROGRAMS = $(MORE_PROGRAMS)
2050 @end example
2051
2052 Defining a primary without a prefix as a variable, e.g.,
2053 @samp{PROGRAMS}, is an error.
2054
2055 Note that the common @samp{dir} suffix is left off when constructing the
2056 variable names; thus one writes @samp{bin_PROGRAMS} and not
2057 @samp{bindir_PROGRAMS}.
2058
2059 Not every sort of object can be installed in every directory.  Automake
2060 will flag those attempts it finds in error (but see below how to override
2061 the check if you really need to).
2062 Automake will also diagnose obvious misspellings in directory names.
2063
2064 @cindex Extending list of installation directories
2065 @cindex Installation directories, extending list
2066
2067 Sometimes the standard directories---even as augmented by
2068 Automake---are not enough.  In particular it is sometimes useful, for
2069 clarity, to install objects in a subdirectory of some predefined
2070 directory.  To this end, Automake allows you to extend the list of
2071 possible installation directories.  A given prefix (e.g., @samp{zar})
2072 is valid if a variable of the same name with @samp{dir} appended is
2073 defined (e.g., @samp{zardir}).
2074
2075 For instance, the following snippet will install @file{file.xml} into
2076 @samp{$(datadir)/xml}.
2077
2078 @c Keep in sync with primary-prefix-couples-documented-valid.test.
2079 @example
2080 xmldir = $(datadir)/xml
2081 xml_DATA = file.xml
2082 @end example
2083
2084 This feature can also be used to override the sanity checks Automake
2085 performs to diagnose suspicious directory/primary couples (in the
2086 unlikely case these checks are undesirable, and you really know what
2087 you're doing).  For example, Automake would error out on this input:
2088
2089 @c Should be tested in primary-prefix-invalid-couples.test.
2090 @example
2091 # Forbidden directory combinations, automake will error out on this.
2092 pkglib_PROGRAMS = foo
2093 doc_LIBRARIES = libquux.a
2094 @end example
2095
2096 @noindent
2097 but it will succeed with this:
2098
2099 @c Keep in sync with primary-prefix-couples-documented-valid.test.
2100 @example
2101 # Work around forbidden directory combinations.  Do not use this
2102 # without a very good reason!
2103 my_execbindir = $(pkglibdir)
2104 my_doclibdir = $(docdir)
2105 my_execbin_PROGRAMS = foo
2106 my_doclib_LIBRARIES = libquux.a
2107 @end example
2108
2109 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2110 the files be installed at the right time (@pxref{The Two Parts of
2111 Install}).
2112
2113 @cindex @samp{noinst_} primary prefix, definition
2114 @vindex noinst_
2115
2116 The special prefix @samp{noinst_} indicates that the objects in question
2117 should be built but not installed at all.  This is usually used for
2118 objects required to build the rest of your package, for instance static
2119 libraries (@pxref{A Library}), or helper scripts.
2120
2121 @cindex @samp{check_} primary prefix, definition
2122 @vindex check_
2123
2124 The special prefix @samp{check_} indicates that the objects in question
2125 should not be built until the @samp{make check} command is run.  Those
2126 objects are not installed either.
2127
2128 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2129 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2130 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2131 @samp{TEXINFOS}.
2132 @vindex PROGRAMS
2133 @vindex LIBRARIES
2134 @vindex LTLIBRARIES
2135 @vindex LISP
2136 @vindex PYTHON
2137 @vindex JAVA
2138 @vindex SCRIPTS
2139 @vindex DATA
2140 @vindex HEADERS
2141 @vindex MANS
2142 @vindex TEXINFOS
2143
2144 Some primaries also allow additional prefixes that control other
2145 aspects of @command{automake}'s behavior.  The currently defined prefixes
2146 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2147 These prefixes are explained later (@pxref{Program and Library Variables})
2148 (@pxref{Man Pages}).
2149
2150
2151 @node Length Limitations
2152 @section Staying below the command line length limit
2153
2154 @cindex command line length limit
2155 @cindex ARG_MAX
2156
2157 Traditionally, most unix-like systems have a length limitation for the
2158 command line arguments and environment contents when creating new
2159 processes (see for example
2160 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2161 overview on this issue),
2162 which of course also applies to commands spawned by @command{make}.
2163 POSIX requires this limit to be at least 4096 bytes, and most modern
2164 systems have quite high limits (or are unlimited).
2165
2166 In order to create portable Makefiles that do not trip over these
2167 limits, it is necessary to keep the length of file lists bounded.
2168 Unfortunately, it is not possible to do so fully transparently within
2169 Automake, so your help may be needed.  Typically, you can split long
2170 file lists manually and use different installation directory names for
2171 each list.  For example,
2172
2173 @example
2174 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2175 @end example
2176
2177 @noindent
2178 may also be written as
2179
2180 @c Keep in sync with primary-prefix-couples-documented-valid.test.
2181 @example
2182 data_DATA = file1 @dots{} file@var{N}
2183 data2dir = $(datadir)
2184 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2185 @end example
2186
2187 @noindent
2188 and will cause Automake to treat the two lists separately during
2189 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2190 directory names that will keep the ordering of the two parts of
2191 installation Note that @code{make dist} may still only work on a host
2192 with a higher length limit in this example.
2193
2194 Automake itself employs a couple of strategies to avoid long command
2195 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2196 names, as can happen with above @code{$(data_DATA)} lists, it limits
2197 the amount of arguments passed to external commands.
2198
2199 Unfortunately, some system's @command{make} commands may prepend
2200 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2201 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2202 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2203 may have to switch to use GNU Make, or refrain from using VPATH builds,
2204 in order to stay below the length limit.
2205
2206 For libraries and programs built from many sources, convenience archives
2207 may be used as intermediates in order to limit the object list length
2208 (@pxref{Libtool Convenience Libraries}).
2209
2210
2211 @node Canonicalization
2212 @section How derived variables are named
2213
2214 @cindex canonicalizing Automake variables
2215
2216 Sometimes a Makefile variable name is derived from some text the
2217 maintainer supplies.  For instance, a program name listed in
2218 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2219 variable.  In cases like this, Automake canonicalizes the text, so that
2220 program names and the like do not have to follow Makefile variable naming
2221 rules.  All characters in the name except for letters, numbers, the
2222 strudel (@@), and the underscore are turned into underscores when making
2223 variable references.
2224
2225 For example, if your program is named @file{sniff-glue}, the derived
2226 variable name would be @samp{sniff_glue_SOURCES}, not
2227 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2228 @file{libmumble++.a} should be listed in the
2229 @samp{libmumble___a_SOURCES} variable.
2230
2231 The strudel is an addition, to make the use of Autoconf substitutions in
2232 variable names less obfuscating.
2233
2234
2235 @node User Variables
2236 @section Variables reserved for the user
2237
2238 @cindex variables, reserved for the user
2239 @cindex user variables
2240
2241 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2242 for the use of the ``user''---the person building the package.  For
2243 instance, @code{CFLAGS} is one such variable.
2244
2245 Sometimes package developers are tempted to set user variables such as
2246 @code{CFLAGS} because it appears to make their job easier.  However,
2247 the package itself should never set a user variable, particularly not
2248 to include switches that are required for proper compilation of the
2249 package.  Since these variables are documented as being for the
2250 package builder, that person rightfully expects to be able to override
2251 any of these variables at build time.
2252
2253 To get around this problem, Automake introduces an automake-specific
2254 shadow variable for each user flag variable.  (Shadow variables are
2255 not introduced for variables like @code{CC}, where they would make no
2256 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2257 user variable's name.  For instance, the shadow variable for
2258 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2259 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2260 files---may adjust these shadow variables however necessary.
2261
2262 @xref{Flag Variables Ordering}, for more discussion about these
2263 variables and how they interact with per-target variables.
2264
2265 @node Auxiliary Programs
2266 @section Programs automake might require
2267
2268 @cindex Programs, auxiliary
2269 @cindex Auxiliary programs
2270
2271 Automake sometimes requires helper programs so that the generated
2272 @file{Makefile} can do its work properly.  There are a fairly large
2273 number of them, and we list them here.
2274
2275 Although all of these files are distributed and installed with
2276 Automake, a couple of them are maintained separately.  The Automake
2277 copies are updated before each release, but we mention the original
2278 source in case you need more recent versions.
2279
2280 @table @code
2281 @item ar-lib
2282 This is a wrapper primarily for the Microsoft lib archiver, to make
2283 it more POSIX-like.
2284
2285 @item compile
2286 This is a wrapper for compilers that do not accept options @option{-c}
2287 and @option{-o} at the same time.  It is only used when absolutely
2288 required.  Such compilers are rare, with the Microsoft C/C++ Compiler
2289 as the most notable exception. This wrapper also makes the following
2290 common options available for that compiler, while performing file name
2291 translation where needed: @option{-I}, @option{-L}, @option{-l},
2292 @option{-Wl,} and @option{-Xlinker}.
2293
2294 @item config.guess
2295 @itemx config.sub
2296 These two programs compute the canonical triplets for the given build,
2297 host, or target architecture.  These programs are updated regularly to
2298 support new architectures and fix probes broken by changes in new
2299 kernel versions.  Each new release of Automake comes with up-to-date
2300 copies of these programs.  If your copy of Automake is getting old,
2301 you are encouraged to fetch the latest versions of these files from
2302 @url{http://savannah.gnu.org/git/?group=config} before making a
2303 release.
2304
2305 @item depcomp
2306 This program understands how to run a compiler so that it will
2307 generate not only the desired output but also dependency information
2308 that is then used by the automatic dependency tracking feature
2309 (@pxref{Dependencies}).
2310
2311 @item elisp-comp
2312 This program is used to byte-compile Emacs Lisp code.
2313
2314 @item install-sh
2315 This is a replacement for the @command{install} program that works on
2316 platforms where @command{install} is unavailable or unusable.
2317
2318 @item mdate-sh
2319 This script is used to generate a @file{version.texi} file.  It examines
2320 a file and prints some date information about it.
2321
2322 @item missing
2323 This wraps a number of programs that are typically only required by
2324 maintainers.  If the program in question doesn't exist,
2325 @command{missing} prints an informative warning and attempts to fix
2326 things so that the build can continue.
2327
2328 @item mkinstalldirs
2329 This script used to be a wrapper around @samp{mkdir -p}, which is not
2330 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2331 finds that @samp{mkdir -p} does not work, this makes one less script to
2332 distribute.
2333
2334 For backward compatibility @file{mkinstalldirs} is still used and
2335 distributed when @command{automake} finds it in a package.  But it is no
2336 longer installed automatically, and it should be safe to remove it.
2337
2338 @item py-compile
2339 This is used to byte-compile Python scripts.
2340
2341 @item test-driver
2342 This implements the default test driver offered by the parallel
2343 testsuite harness.
2344
2345 @item texinfo.tex
2346 Not a program, this file is required for @samp{make dvi}, @samp{make
2347 ps} and @samp{make pdf} to work when Texinfo sources are in the
2348 package.  The latest version can be downloaded from
2349 @url{http://www.gnu.org/software/texinfo/}.
2350
2351 @item ylwrap
2352 This program wraps @command{lex} and @command{yacc} to rename their
2353 output files.  It also ensures that, for instance, multiple
2354 @command{yacc} instances can be invoked in a single directory in
2355 parallel.
2356
2357 @end table
2358
2359
2360 @node Examples
2361 @chapter Some example packages
2362
2363 This section contains two small examples.
2364
2365 The first example (@pxref{Complete}) assumes you have an existing
2366 project already using Autoconf, with handcrafted @file{Makefile}s, and
2367 that you want to convert it to using Automake.  If you are discovering
2368 both tools, it is probably better that you look at the Hello World
2369 example presented earlier (@pxref{Hello World}).
2370
2371 The second example (@pxref{true}) shows how two programs can be built
2372 from the same file, using different compilation parameters.  It
2373 contains some technical digressions that are probably best skipped on
2374 first read.
2375
2376 @menu
2377 * Complete::                    A simple example, start to finish
2378 * true::                        Building true and false
2379 @end menu
2380
2381
2382 @node Complete
2383 @section A simple example, start to finish
2384
2385 @cindex Complete example
2386
2387 Let's suppose you just finished writing @code{zardoz}, a program to make
2388 your head float from vortex to vortex.  You've been using Autoconf to
2389 provide a portability framework, but your @file{Makefile.in}s have been
2390 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2391
2392 @cindex @code{AM_INIT_AUTOMAKE}, example use
2393
2394 The first step is to update your @file{configure.ac} to include the
2395 commands that @command{automake} needs.  The way to do this is to add an
2396 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2397
2398 @example
2399 AC_INIT([zardoz], [1.0])
2400 AM_INIT_AUTOMAKE
2401 @dots{}
2402 @end example
2403
2404 Since your program doesn't have any complicating factors (e.g., it
2405 doesn't use @code{gettext}, it doesn't want to build a shared library),
2406 you're done with this part.  That was easy!
2407
2408 @cindex @command{aclocal} program, introduction
2409 @cindex @file{aclocal.m4}, preexisting
2410 @cindex @file{acinclude.m4}, defined
2411
2412 Now you must regenerate @file{configure}.  But to do that, you'll need
2413 to tell @command{autoconf} how to find the new macro you've used.  The
2414 easiest way to do this is to use the @command{aclocal} program to
2415 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2416 already have an @file{aclocal.m4}, because you had to write some hairy
2417 macros for your program.  The @command{aclocal} program lets you put
2418 your own macros into @file{acinclude.m4}, so simply rename and then
2419 run:
2420
2421 @example
2422 mv aclocal.m4 acinclude.m4
2423 aclocal
2424 autoconf
2425 @end example
2426
2427 @cindex @command{zardoz} example
2428
2429 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2430 Since @code{zardoz} is a user program, you want to install it where the
2431 rest of the user programs go: @code{bindir}.  Additionally,
2432 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2433 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2434 @samp{$(LIBOBJS)}.  So here's what you'd write:
2435
2436 @example
2437 bin_PROGRAMS = zardoz
2438 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2439 zardoz_LDADD = $(LIBOBJS)
2440
2441 info_TEXINFOS = zardoz.texi
2442 @end example
2443
2444 Now you can run @samp{automake --add-missing} to generate your
2445 @file{Makefile.in} and grab any auxiliary files you might need, and
2446 you're done!
2447
2448
2449 @node true
2450 @section Building true and false
2451
2452 @cindex Example, @command{false} and @command{true}
2453 @cindex @command{false} Example
2454 @cindex @command{true} Example
2455
2456 Here is another, trickier example.  It shows how to generate two
2457 programs (@code{true} and @code{false}) from the same source file
2458 (@file{true.c}).  The difficult part is that each compilation of
2459 @file{true.c} requires different @code{cpp} flags.
2460
2461 @example
2462 bin_PROGRAMS = true false
2463 false_SOURCES =
2464 false_LDADD = false.o
2465
2466 true.o: true.c
2467         $(COMPILE) -DEXIT_CODE=0 -c true.c
2468
2469 false.o: true.c
2470         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2471 @end example
2472
2473 Note that there is no @code{true_SOURCES} definition.  Automake will
2474 implicitly assume that there is a source file named @file{true.c}
2475 (@pxref{Default _SOURCES}), and
2476 define rules to compile @file{true.o} and link @file{true}.  The
2477 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2478 will override the Automake generated rule to build @file{true.o}.
2479
2480 @code{false_SOURCES} is defined to be empty---that way no implicit value
2481 is substituted.  Because we have not listed the source of
2482 @file{false}, we have to tell Automake how to link the program.  This is
2483 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2484 variable, holding the dependencies of the @file{false} target will be
2485 automatically generated by Automake from the content of
2486 @code{false_LDADD}.
2487
2488 The above rules won't work if your compiler doesn't accept both
2489 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2490 bogus dependency (to avoid problems with a parallel @command{make}):
2491
2492 @example
2493 true.o: true.c false.o
2494         $(COMPILE) -DEXIT_CODE=0 -c true.c
2495
2496 false.o: true.c
2497         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2498 @end example
2499
2500 As it turns out, there is also a much easier way to do this same task.
2501 Some of the above technique is useful enough that we've kept the
2502 example in the manual.  However if you were to build @code{true} and
2503 @code{false} in real life, you would probably use per-program
2504 compilation flags, like so:
2505
2506 @c Keep in sync with specflg7.test and specflg8.test.
2507 @example
2508 bin_PROGRAMS = false true
2509
2510 false_SOURCES = true.c
2511 false_CPPFLAGS = -DEXIT_CODE=1
2512
2513 true_SOURCES = true.c
2514 true_CPPFLAGS = -DEXIT_CODE=0
2515 @end example
2516
2517 In this case Automake will cause @file{true.c} to be compiled twice,
2518 with different flags.  In this instance, the names of the object files
2519 would be chosen by automake; they would be @file{false-true.o} and
2520 @file{true-true.o}. (The name of the object files rarely matters.)
2521
2522 @node automake Invocation
2523 @chapter Creating a @file{Makefile.in}
2524 @c This node used to be named "Invoking automake".  This @anchor
2525 @c allows old links to still work.
2526 @anchor{Invoking automake}
2527
2528 @cindex Multiple @file{configure.ac} files
2529 @cindex Invoking @command{automake}
2530 @cindex @command{automake}, invoking
2531 @cindex Invocation of @command{automake}
2532 @cindex @command{automake}, invocation
2533
2534 To create all the @file{Makefile.in}s for a package, run the
2535 @command{automake} program in the top level directory, with no
2536 arguments.  @command{automake} will automatically find each
2537 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2538 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2539 Note that @command{automake} has a rather simplistic view of what
2540 constitutes a package; it assumes that a package has only one
2541 @file{configure.ac}, at the top.  If your package has multiple
2542 @file{configure.ac}s, then you must run @command{automake} in each
2543 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2544 on Autoconf's @command{autoreconf}, which is able to recurse your
2545 package tree and run @command{automake} where appropriate.)
2546
2547 You can optionally give @command{automake} an argument; @file{.am} is
2548 appended to the argument and the result is used as the name of the
2549 input file.  This feature is generally only used to automatically
2550 rebuild an out-of-date @file{Makefile.in}.  Note that
2551 @command{automake} must always be run from the topmost directory of a
2552 project, even if being used to regenerate the @file{Makefile.in} in
2553 some subdirectory.  This is necessary because @command{automake} must
2554 scan @file{configure.ac}, and because @command{automake} uses the
2555 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2556 behavior in some cases.
2557
2558 @vindex AUTOCONF
2559 Automake will run @command{autoconf} to scan @file{configure.ac} and
2560 its dependencies (i.e., @file{aclocal.m4} and any included file),
2561 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2562 an @env{AUTOCONF} variable in your environment it will be used
2563 instead of @command{autoconf}, this allows you to select a particular
2564 version of Autoconf.  By the way, don't misunderstand this paragraph:
2565 @command{automake} runs @command{autoconf} to @strong{scan} your
2566 @file{configure.ac}, this won't build @file{configure} and you still
2567 have to run @command{autoconf} yourself for this purpose.
2568
2569 @cindex @command{automake} options
2570 @cindex Options, @command{automake}
2571 @cindex Strictness, command line
2572
2573 @command{automake} accepts the following options:
2574
2575 @cindex Extra files distributed with Automake
2576 @cindex Files distributed with Automake
2577 @cindex @file{config.guess}
2578
2579 @table @code
2580 @item -a
2581 @itemx --add-missing
2582 @opindex -a
2583 @opindex --add-missing
2584 Automake requires certain common files to exist in certain situations;
2585 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2586 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2587 files (@pxref{Auxiliary Programs}); this option will cause the missing
2588 ones to be automatically added to the package, whenever possible.  In
2589 general if Automake tells you a file is missing, try using this option.
2590 By default Automake tries to make a symbolic link pointing to its own
2591 copy of the missing file; this can be changed with @option{--copy}.
2592
2593 Many of the potentially-missing files are common scripts whose
2594 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2595 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2596 file is considered missing, and where the missing file is added
2597 (@pxref{Optional}).
2598
2599 In some strictness modes, additional files are installed, see @ref{Gnits}
2600 for more information.
2601
2602 @item --libdir=@var{dir}
2603 @opindex --libdir
2604 Look for Automake data files in directory @var{dir} instead of in the
2605 installation directory.  This is typically used for debugging.
2606
2607 @item -c
2608 @opindex -c
2609 @itemx --copy
2610 @opindex --copy
2611 When used with @option{--add-missing}, causes installed files to be
2612 copied.  The default is to make a symbolic link.
2613
2614 @item --cygnus
2615 @opindex --cygnus
2616 Causes the generated @file{Makefile.in}s to follow Cygnus rules, instead
2617 of GNU or Gnits rules.  For more information, see @ref{Cygnus}.
2618
2619 @item -f
2620 @opindex -f
2621 @itemx --force-missing
2622 @opindex --force-missing
2623 When used with @option{--add-missing}, causes standard files to be reinstalled
2624 even if they already exist in the source tree.  This involves removing
2625 the file from the source tree before creating the new symlink (or, with
2626 @option{--copy}, copying the new file).
2627
2628 @item --foreign
2629 @opindex --foreign
2630 Set the global strictness to @option{foreign}.  For more information, see
2631 @ref{Strictness}.
2632
2633 @item --gnits
2634 @opindex --gnits
2635 Set the global strictness to @option{gnits}.  For more information, see
2636 @ref{Gnits}.
2637
2638 @item --gnu
2639 @opindex --gnu
2640 Set the global strictness to @option{gnu}.  For more information, see
2641 @ref{Gnits}.  This is the default strictness.
2642
2643 @item --help
2644 @opindex --help
2645 Print a summary of the command line options and exit.
2646
2647 @item -i
2648 @itemx --ignore-deps
2649 @opindex -i
2650 This disables the dependency tracking feature in generated
2651 @file{Makefile}s; see @ref{Dependencies}.
2652
2653 @item --include-deps
2654 @opindex --include-deps
2655 This enables the dependency tracking feature.  This feature is enabled
2656 by default.  This option is provided for historical reasons only and
2657 probably should not be used.
2658
2659 @item --no-force
2660 @opindex --no-force
2661 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2662 @file{configure.ac}.  This option causes it to only update those
2663 @file{Makefile.in}s that are out of date with respect to one of their
2664 dependents.
2665
2666 @item -o @var{dir}
2667 @itemx --output-dir=@var{dir}
2668 @opindex -o
2669 @opindex --output-dir
2670 Put the generated @file{Makefile.in} in the directory @var{dir}.
2671 Ordinarily each @file{Makefile.in} is created in the directory of the
2672 corresponding @file{Makefile.am}.  This option is deprecated and will be
2673 removed in a future release.
2674
2675 @item -v
2676 @itemx --verbose
2677 @opindex -v
2678 @opindex --verbose
2679 Cause Automake to print information about which files are being read or
2680 created.
2681
2682 @item --version
2683 @opindex --version
2684 Print the version number of Automake and exit.
2685
2686 @item -W CATEGORY
2687 @itemx --warnings=@var{category}
2688 @opindex -W
2689 @opindex --warnings
2690 Output warnings falling in @var{category}.  @var{category} can be
2691 one of:
2692 @table @code
2693 @item gnu
2694 warnings related to the GNU Coding Standards
2695 (@pxref{Top, , , standards, The GNU Coding Standards}).
2696 @item obsolete
2697 obsolete features or constructions
2698 @item override
2699 user redefinitions of Automake rules or variables
2700 @item portability
2701 portability issues (e.g., use of @command{make} features that are
2702 known to be not portable)
2703 @item extra-portability
2704 extra portability issues related to obscure tools.  One example of such
2705 a tool is the Microsoft @command{lib} archiver.
2706 @item syntax
2707 weird syntax, unused variables, typos
2708 @item unsupported
2709 unsupported or incomplete features
2710 @item all
2711 all the warnings
2712 @item none
2713 turn off all the warnings
2714 @item error
2715 treat warnings as errors
2716 @end table
2717
2718 A category can be turned off by prefixing its name with @samp{no-}.  For
2719 instance, @option{-Wno-syntax} will hide the warnings about unused
2720 variables.
2721
2722 The categories output by default are @samp{syntax} and
2723 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2724 are enabled in @option{--gnu} and @option{--gnits} strictness.
2725 On the other hand, the @option{silent-rules} options (@pxref{Options})
2726 turns off portability warnings about recursive variable expansions.
2727
2728 @c Checked by extra-portability.test
2729 Turning off @samp{portability} will also turn off @samp{extra-portability},
2730 and similarly turning on @samp{extra-portability} will also turn on
2731 @samp{portability}.  However, turning on @samp{portability} or turning
2732 off @samp{extra-portability} will not affect the other category.
2733
2734 @vindex WARNINGS
2735 The environment variable @env{WARNINGS} can contain a comma separated
2736 list of categories to enable.  It will be taken into account before the
2737 command-line switches, this way @option{-Wnone} will also ignore any
2738 warning category enabled by @env{WARNINGS}.  This variable is also used
2739 by other tools like @command{autoconf}; unknown categories are ignored
2740 for this reason.
2741
2742 @end table
2743
2744 @vindex AUTOMAKE_JOBS
2745 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2746 number, it is taken as the maximum number of Perl threads to use in
2747 @command{automake} for generating multiple @file{Makefile.in} files
2748 concurrently.  This is an experimental feature.
2749
2750
2751 @node configure
2752 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2753
2754 @cindex @file{configure.ac}, scanning
2755 @cindex Scanning @file{configure.ac}
2756 @cindex Using @command{aclocal}
2757 @cindex @command{aclocal}, using
2758
2759 Automake scans the package's @file{configure.ac} to determine certain
2760 information about the package.  Some @command{autoconf} macros are required
2761 and some variables must be defined in @file{configure.ac}.  Automake
2762 will also use information from @file{configure.ac} to further tailor its
2763 output.
2764
2765 Automake also supplies some Autoconf macros to make the maintenance
2766 easier.  These macros can automatically be put into your
2767 @file{aclocal.m4} using the @command{aclocal} program.
2768
2769 @menu
2770 * Requirements::                Configuration requirements
2771 * Optional::                    Other things Automake recognizes
2772 * aclocal Invocation::          Auto-generating aclocal.m4
2773 * Macros::                      Autoconf macros supplied with Automake
2774 @end menu
2775
2776
2777 @node Requirements
2778 @section Configuration requirements
2779
2780 @cindex Automake requirements
2781 @cindex Requirements of Automake
2782
2783 @acindex AM_INIT_AUTOMAKE
2784 The one real requirement of Automake is that your @file{configure.ac}
2785 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2786 required for proper Automake operation (@pxref{Macros}).
2787
2788 Here are the other macros that Automake requires but which are not run
2789 by @code{AM_INIT_AUTOMAKE}:
2790
2791 @table @code
2792 @item AC_CONFIG_FILES
2793 @itemx AC_OUTPUT
2794 @acindex AC_CONFIG_FILES
2795 @acindex AC_OUTPUT
2796 These two macros are usually invoked as follows near the end of
2797 @file{configure.ac}.
2798
2799 @example
2800 @dots{}
2801 AC_CONFIG_FILES([
2802   Makefile
2803   doc/Makefile
2804   src/Makefile
2805   src/lib/Makefile
2806   @dots{}
2807 ])
2808 AC_OUTPUT
2809 @end example
2810
2811 Automake uses these to determine which files to create (@pxref{Output, ,
2812 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2813 is considered to be an Automake generated @file{Makefile} if there
2814 exists a file with the same name and the @file{.am} extension appended.
2815 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2816 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2817
2818 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2819
2820 @example
2821 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2822 @end example
2823
2824 @noindent
2825 @command{automake} will generate the first @file{.in} input file for
2826 which a @file{.am} file exists.  If no such file exists the output
2827 file is not considered to be generated by Automake.
2828
2829 Files created by @code{AC_CONFIG_FILES}, be they Automake
2830 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2831 Their inputs are automatically distributed, unless they
2832 are the output of prior @code{AC_CONFIG_FILES} commands.
2833 Finally, rebuild rules are generated in the Automake @file{Makefile}
2834 existing in the subdirectory of the output file, if there is one, or
2835 in the top-level @file{Makefile} otherwise.
2836
2837 The above machinery (cleaning, distributing, and rebuilding) works
2838 fine if the @code{AC_CONFIG_FILES} specifications contain only
2839 literals.  If part of the specification uses shell variables,
2840 @command{automake} will not be able to fulfill this setup, and you will
2841 have to complete the missing bits by hand.  For instance, on
2842
2843 @c Keep in sync with output11.test.
2844 @example
2845 file=input
2846 @dots{}
2847 AC_CONFIG_FILES([output:$file],, [file=$file])
2848 @end example
2849
2850 @noindent
2851 @command{automake} will output rules to clean @file{output}, and
2852 rebuild it.  However the rebuild rule will not depend on @file{input},
2853 and this file will not be distributed either.  (You must add
2854 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2855 source file.)
2856
2857 Similarly
2858
2859 @c Keep in sync with output11.test.
2860 @example
2861 file=output
2862 file2=out:in
2863 @dots{}
2864 AC_CONFIG_FILES([$file:input],, [file=$file])
2865 AC_CONFIG_FILES([$file2],, [file2=$file2])
2866 @end example
2867
2868 @noindent
2869 will only cause @file{input} to be distributed.  No file will be
2870 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2871 yourself), and no rebuild rule will be output.
2872
2873 Obviously @command{automake} cannot guess what value @samp{$file} is
2874 going to hold later when @file{configure} is run, and it cannot use
2875 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2876 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2877 that is compatible with @command{make}'s syntax) and furthermore use
2878 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2879 @file{Makefile}, then @command{automake} will be able to use
2880 @samp{$@{file@}} to generate all these rules.  For instance, here is
2881 how the Automake package itself generates versioned scripts for its
2882 test suite:
2883
2884 @example
2885 AC_SUBST([APIVERSION], @dots{})
2886 @dots{}
2887 AC_CONFIG_FILES(
2888   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2889   [chmod +x tests/aclocal-$@{APIVERSION@}],
2890   [APIVERSION=$APIVERSION])
2891 AC_CONFIG_FILES(
2892   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2893   [chmod +x tests/automake-$@{APIVERSION@}])
2894 @end example
2895
2896 @noindent
2897 Here cleaning, distributing, and rebuilding are done automatically,
2898 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2899
2900 Note that you should not use shell variables to declare
2901 @file{Makefile} files for which @command{automake} must create
2902 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2903 @command{automake} needs to know the file name when it runs in order
2904 to check whether @file{Makefile.am} exists.  (In the very hairy case
2905 that your setup requires such use of variables, you will have to tell
2906 Automake which @file{Makefile.in}s to generate on the command-line.)
2907
2908 It is possible to let @command{automake} emit conditional rules for
2909 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2910 (@pxref{Optional}).
2911
2912 To summarize:
2913 @itemize @bullet
2914 @item
2915 Use literals for @file{Makefile}s, and for other files whenever possible.
2916 @item
2917 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2918 for files that @command{automake} should ignore.
2919 @item
2920 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2921 that @command{automake} should not ignore.
2922 @end itemize
2923
2924 @end table
2925
2926
2927 @node Optional
2928 @section Other things Automake recognizes
2929
2930 @cindex Macros Automake recognizes
2931 @cindex Recognized macros by Automake
2932
2933 Every time Automake is run it calls Autoconf to trace
2934 @file{configure.ac}.  This way it can recognize the use of certain
2935 macros and tailor the generated @file{Makefile.in} appropriately.
2936 Currently recognized macros and their effects are:
2937
2938 @ftable @code
2939 @item AC_CANONICAL_BUILD
2940 @itemx AC_CANONICAL_HOST
2941 @itemx AC_CANONICAL_TARGET
2942 @vindex build_triplet
2943 @vindex host_triplet
2944 @vindex target_triplet
2945 Automake will ensure that @file{config.guess} and @file{config.sub}
2946 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2947 @code{host_triplet} and @code{target_triplet} are introduced.  See
2948 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2949 The Autoconf Manual}.
2950
2951 @item AC_CONFIG_AUX_DIR
2952 Automake will look for various helper scripts, such as
2953 @file{install-sh}, in the directory named in this macro invocation.
2954 @c This list is accurate relative to version 1.11
2955 (The full list of scripts is:
2956 @file{ar-lib},
2957 @file{config.guess},
2958 @file{config.sub},
2959 @file{depcomp},
2960 @file{elisp-comp},
2961 @file{compile},
2962 @file{install-sh},
2963 @file{ltmain.sh},
2964 @file{mdate-sh},
2965 @file{missing},
2966 @file{mkinstalldirs},
2967 @file{py-compile},
2968 @file{test-driver},
2969 @file{texinfo.tex},
2970 @file{ylwrap}.)
2971 Not all scripts are always searched for; some scripts
2972 will only be sought if the generated @file{Makefile.in} requires them.
2973
2974 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2975 their standard locations.  For @file{mdate-sh},
2976 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2977 source directory corresponding to the current @file{Makefile.am}.  For
2978 the rest, the standard location is the first one of @file{.}, @file{..},
2979 or @file{../..} (relative to the top source directory) that provides any
2980 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2981 autoconf, The Autoconf Manual}.
2982
2983 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2984 distributed, even if there is no @file{Makefile.am} in this directory.
2985
2986 @item AC_CONFIG_LIBOBJ_DIR
2987 Automake will require the sources file declared with
2988 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2989 macro.
2990
2991 @item AC_CONFIG_HEADERS
2992 Automake will generate rules to rebuild these headers.  Older versions
2993 of Automake required the use of @code{AM_CONFIG_HEADER}
2994 (@pxref{Macros}); this is no longer the case.
2995
2996 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2997 specification using shell variables will be ignored as far as
2998 cleaning, distributing, and rebuilding is concerned.
2999
3000 @item AC_CONFIG_LINKS
3001 Automake will generate rules to remove @file{configure} generated
3002 links on @samp{make distclean} and to distribute named source files as
3003 part of @samp{make dist}.
3004
3005 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
3006 specification using shell variables will be ignored as far as cleaning
3007 and distributing is concerned.  (There are no rebuild rules for links.)
3008
3009 @item AC_LIBOBJ
3010 @itemx AC_LIBSOURCE
3011 @itemx AC_LIBSOURCES
3012 @vindex LIBOBJS
3013 Automake will automatically distribute any file listed in
3014 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
3015
3016 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
3017 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
3018 @file{file.c} will be distributed automatically by Automake.  This
3019 encompasses many macros like @code{AC_FUNC_ALLOCA},
3020 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
3021
3022 By the way, direct assignments to @code{LIBOBJS} are no longer
3023 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
3024 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
3025 autoconf, The Autoconf Manual}.
3026
3027 @item AC_PROG_RANLIB
3028 This is required if any libraries are built in the package.
3029 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3030 Autoconf Manual}.
3031
3032 @item AC_PROG_CXX
3033 This is required if any C++ source is included.  @xref{Particular
3034 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3035
3036 @item AC_PROG_OBJC
3037 This is required if any Objective C source is included.  @xref{Particular
3038 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3039
3040 @item AC_PROG_F77
3041 This is required if any Fortran 77 source is included.  This macro is
3042 distributed with Autoconf version 2.13 and later.  @xref{Particular
3043 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3044
3045 @item AC_F77_LIBRARY_LDFLAGS
3046 This is required for programs and shared libraries that are a mixture of
3047 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
3048 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
3049
3050 @item AC_FC_SRCEXT
3051 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
3052 of files with the respective source extension (@pxref{Fortran Compiler, ,
3053 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
3054
3055 @item AC_PROG_FC
3056 This is required if any Fortran 90/95 source is included.  This macro is
3057 distributed with Autoconf version 2.58 and later.  @xref{Particular
3058 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3059
3060 @item AC_PROG_LIBTOOL
3061 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
3062 Introduction, libtool, The Libtool Manual}).
3063
3064 @item AC_PROG_YACC
3065 @vindex YACC
3066 If a Yacc source file is seen, then you must either use this macro or
3067 define the variable @code{YACC} in @file{configure.ac}.  The former is
3068 preferred (@pxref{Particular Programs, , Particular Program Checks,
3069 autoconf, The Autoconf Manual}).
3070
3071 @item AC_PROG_LEX
3072 If a Lex source file is seen, then this macro must be used.
3073 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3074 Autoconf Manual}.
3075
3076 @item AC_REQUIRE_AUX_FILE
3077 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3078 @command{automake} will ensure that @file{@var{file}} exists in the
3079 aux directory, and will complain otherwise.  It
3080 will also automatically distribute the file.  This macro should be
3081 used by third-party Autoconf macros that require some supporting
3082 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3083 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
3084 The Autoconf Manual}.
3085
3086 @item AC_SUBST
3087 The first argument is automatically defined as a variable in each
3088 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3089 used for this variable.  @xref{Setting Output Variables, , Setting
3090 Output Variables, autoconf, The Autoconf Manual}.
3091
3092 For every substituted variable @var{var}, @command{automake} will add
3093 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3094 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3095 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3096 @code{X_LIBS}.  Thus, you can access these variables as
3097 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3098 if @code{AC_PATH_XTRA} is called.
3099
3100 @item AM_CONDITIONAL
3101 This introduces an Automake conditional (@pxref{Conditionals}).
3102
3103 @item AM_COND_IF
3104 This macro allows @code{automake} to detect subsequent access within
3105 @file{configure.ac} to a conditional previously introduced with
3106 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3107 (@pxref{Usage of Conditionals}).
3108
3109 @item AM_GNU_GETTEXT
3110 This macro is required for packages that use GNU gettext
3111 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
3112 this macro it ensures that the package meets some of gettext's
3113 requirements.
3114
3115 @item AM_GNU_GETTEXT_INTL_SUBDIR
3116 This macro specifies that the @file{intl/} subdirectory is to be built,
3117 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3118 of @samp{external}.
3119
3120 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3121 @opindex --enable-maintainer-mode
3122 @opindex --disable-maintainer-mode
3123 This macro adds an @option{--enable-maintainer-mode} option to
3124 @command{configure}.  If this is used, @command{automake} will cause
3125 ``maintainer-only'' rules to be turned off by default in the
3126 generated @file{Makefile.in}s, unless @var{default-mode} is
3127 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3128 conditional, which you can use in your own @file{Makefile.am}.
3129 @xref{maintainer-mode}.
3130
3131 @item AM_SUBST_NOTMAKE(@var{var})
3132 Prevent Automake from defining a variable @var{var}, even if it is
3133 substituted by @command{config.status}.  Normally, Automake defines a
3134 @command{make} variable for each @command{configure} substitution,
3135 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3136 definition from Automake.  If @code{AC_SUBST} has not been called
3137 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3138 Preventing variable definitions may be useful for substitution of
3139 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3140 unintended results.
3141
3142 @item m4_include
3143 Files included by @file{configure.ac} using this macro will be
3144 detected by Automake and automatically distributed.  They will also
3145 appear as dependencies in @file{Makefile} rules.
3146
3147 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3148 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3149 some required macros come from files local to your package (as opposed to
3150 macros installed in a system-wide directory, @pxref{aclocal Invocation}).
3151
3152 @end ftable
3153
3154 @node aclocal Invocation
3155 @section Auto-generating aclocal.m4
3156 @c This node used to be named "Invoking automake".  This @anchor
3157 @c allows old links to still work.
3158 @anchor{Invoking aclocal}
3159
3160 @cindex Invocation of @command{aclocal}
3161 @cindex @command{aclocal}, Invocation
3162 @cindex Invoking @command{aclocal}
3163 @cindex @command{aclocal}, Invoking
3164
3165 Automake includes a number of Autoconf macros that can be used in
3166 your package (@pxref{Macros}); some of them are actually required by
3167 Automake in certain situations.  These macros must be defined in your
3168 @file{aclocal.m4}; otherwise they will not be seen by
3169 @command{autoconf}.
3170
3171 The @command{aclocal} program will automatically generate
3172 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3173 This provides a convenient way to get Automake-provided macros,
3174 without having to search around.  The @command{aclocal} mechanism
3175 allows other packages to supply their own macros (@pxref{Extending
3176 aclocal}).  You can also use it to maintain your own set of custom
3177 macros (@pxref{Local Macros}).
3178
3179 At startup, @command{aclocal} scans all the @file{.m4} files it can
3180 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3181 it scans @file{configure.ac}.  Any mention of one of the macros found
3182 in the first step causes that macro, and any macros it in turn
3183 requires, to be put into @file{aclocal.m4}.
3184
3185 @emph{Putting} the file that contains the macro definition into
3186 @file{aclocal.m4} is usually done by copying the entire text of this
3187 file, including unused macro definitions as well as both @samp{#} and
3188 @samp{dnl} comments.  If you want to make a comment that will be
3189 completely ignored by @command{aclocal}, use @samp{##} as the comment
3190 leader.
3191
3192 When a file selected by @command{aclocal} is located in a subdirectory
3193 specified as a relative search path with @command{aclocal}'s @option{-I}
3194 argument, @command{aclocal} assumes the file belongs to the package
3195 and uses @code{m4_include} instead of copying it into
3196 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3197 tracking, and cause the file to be distributed automatically.
3198 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3199 system-wide directory, or via an absolute search path will be copied.
3200 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3201 some relative directory should be considered outside the package.
3202
3203 The contents of @file{acinclude.m4}, if this file exists, are also
3204 automatically included in @file{aclocal.m4}.  We recommend against
3205 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3206
3207 @vindex AUTOM4TE
3208 @cindex autom4te
3209 While computing @file{aclocal.m4}, @command{aclocal} runs
3210 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3211 autoconf, The Autoconf Manual}) in order to trace the macros that are
3212 really used, and omit from @file{aclocal.m4} all macros that are
3213 mentioned but otherwise unexpanded (this can happen when a macro is
3214 called conditionally).  @command{autom4te} is expected to be in the
3215 @env{PATH}, just as @command{autoconf}.  Its location can be
3216 overridden using the @env{AUTOM4TE} environment variable.
3217
3218 @menu
3219 * aclocal Options::             Options supported by aclocal
3220 * Macro Search Path::           How aclocal finds .m4 files
3221 * Extending aclocal::           Writing your own aclocal macros
3222 * Local Macros::                Organizing local macros
3223 * Serials::                     Serial lines in Autoconf macros
3224 * Future of aclocal::           aclocal's scheduled death
3225 @end menu
3226
3227 @node aclocal Options
3228 @subsection aclocal Options
3229
3230 @cindex @command{aclocal}, Options
3231 @cindex Options, @command{aclocal}
3232
3233 @command{aclocal} accepts the following options:
3234
3235 @table @code
3236 @item --automake-acdir=@var{dir}
3237 @opindex --automake-acdir
3238 Look for the automake-provided macro files in @var{dir} instead of
3239 in the installation directory.  This is typically used for debugging.
3240
3241 @item --system-acdir=@var{dir}
3242 @opindex --system-acdir
3243 Look for the system-wide third-party macro files (and the special
3244 @file{dirlist} file) in @var{dir} instead of in the installation
3245 directory.  This is typically used for debugging.
3246
3247 @item --diff[=@var{command}]
3248 @opindex --diff
3249 Run @var{command} on M4 file that would be installed or overwritten
3250 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3251 This option implies @option{--install} and @option{--dry-run}.
3252
3253 @item --dry-run
3254 @opindex --dry-run
3255 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3256 files installed by @option{--install}.
3257
3258 @item --help
3259 @opindex --help
3260 Print a summary of the command line options and exit.
3261
3262 @item -I @var{dir}
3263 @opindex -I
3264 Add the directory @var{dir} to the list of directories searched for
3265 @file{.m4} files.
3266
3267 @item --install
3268 @opindex --install
3269 Install system-wide third-party macros into the first directory
3270 specified with @samp{-I @var{dir}} instead of copying them in the
3271 output file.
3272 @c The following semantics is checked by `aclocal-install-absdir.test'.
3273 Note that this will happen also if @var{dir} is an absolute path.
3274
3275 @cindex serial number and @option{--install}
3276 When this option is used, and only when this option is used,
3277 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3278 that appear in macros: an M4 file is ignored if there exists another
3279 M4 file with the same basename and a greater serial number in the
3280 search path (@pxref{Serials}).
3281
3282 @item --force
3283 @opindex --force
3284 Always overwrite the output file.  The default is to overwrite the output
3285 file only when really needed, i.e., when its contents changes or if one
3286 of its dependencies is younger.
3287
3288 This option forces the update of @file{aclocal.m4} (or the file
3289 specified with @file{--output} below) and only this file, it has
3290 absolutely no influence on files that may need to be installed by
3291 @option{--install}.
3292
3293 @item --output=@var{file}
3294 @opindex --output
3295 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3296
3297 @item --print-ac-dir
3298 @opindex --print-ac-dir
3299 Prints the name of the directory that @command{aclocal} will search to
3300 find third-party @file{.m4} files.  When this option is given, normal
3301 processing is suppressed.  This option was used @emph{in the past} by
3302 third-party packages to determine where to install @file{.m4} macro
3303 files, but @emph{this usage is today discouraged}, since it causes
3304 @samp{$(prefix)} not to be thoroughly honoured (which violates the
3305 GNU Coding Standards), and a similar semantics can be better obtained
3306 with the @env{ACLOCAL_PATH} environment variable; @pxref{Extending aclocal}.
3307
3308 @item --verbose
3309 @opindex --verbose
3310 Print the names of the files it examines.
3311
3312 @item --version
3313 @opindex --version
3314 Print the version number of Automake and exit.
3315
3316 @item -W CATEGORY
3317 @item --warnings=@var{category}
3318 @opindex -W
3319 @opindex --warnings
3320 Output warnings falling in @var{category}.  @var{category} can be
3321 one of:
3322 @table @code
3323 @item syntax
3324 dubious syntactic constructs, underquoted macros, unused macros, etc.
3325 @item unsupported
3326 unknown macros
3327 @item all
3328 all the warnings, this is the default
3329 @item none
3330 turn off all the warnings
3331 @item error
3332 treat warnings as errors
3333 @end table
3334
3335 All warnings are output by default.
3336
3337 @vindex WARNINGS
3338 The environment variable @env{WARNINGS} is honored in the same
3339 way as it is for @command{automake} (@pxref{automake Invocation}).
3340
3341 @end table
3342
3343 @node Macro Search Path
3344 @subsection Macro Search Path
3345
3346 @cindex Macro search path
3347 @cindex @command{aclocal} search path
3348
3349 By default, @command{aclocal} searches for @file{.m4} files in the following
3350 directories, in this order:
3351
3352 @table @code
3353 @item @var{acdir-APIVERSION}
3354 This is where the @file{.m4} macros distributed with Automake itself
3355 are stored.  @var{APIVERSION} depends on the Automake release used;
3356 for example, for Automake 1.11.x, @var{APIVERSION} = @code{1.11}.
3357
3358 @item @var{acdir}
3359 This directory is intended for third party @file{.m4} files, and is
3360 configured when @command{automake} itself is built.  This is
3361 @file{@@datadir@@/aclocal/}, which typically
3362 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3363 value of @var{acdir}, use the @option{--print-ac-dir} option
3364 (@pxref{aclocal Options}).
3365 @end table
3366
3367 As an example, suppose that @command{automake-1.11.2} was configured with
3368 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3369
3370 @enumerate
3371 @item @file{/usr/local/share/aclocal-1.11.2/}
3372 @item @file{/usr/local/share/aclocal/}
3373 @end enumerate
3374
3375 The paths for the @var{acdir} and @var{acdir-APIVERSION} directories can
3376 be changed respectively through aclocal options @option{--system-acdir}
3377 and @option{--automake-acdir} (@pxref{aclocal Options}).  Note however
3378 that these options are only intended for use by the internal Automake
3379 test suite, or for debugging under highly unusual situations; they are
3380 not ordinarily needed by end-users.
3381
3382 As explained in (@pxref{aclocal Options}), there are several options that
3383 can be used to change or extend this search path.
3384
3385 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3386
3387 Any extra directories specified using @option{-I} options
3388 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3389 @samp{aclocal -I /foo -I /bar} results in the following search path:
3390
3391 @enumerate
3392 @item @file{/foo}
3393 @item @file{/bar}
3394 @item @var{acdir}-@var{APIVERSION}
3395 @item @var{acdir}
3396 @end enumerate
3397
3398 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3399 @cindex @file{dirlist}
3400
3401 There is a third mechanism for customizing the search path.  If a
3402 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3403 contain a list of directory patterns, one per line.  @command{aclocal}
3404 expands these patterns to directory names, and adds them to the search
3405 list @emph{after} all other directories.  @file{dirlist} entries may
3406 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3407
3408 For example, suppose
3409 @file{@var{acdir}/dirlist} contains the following:
3410
3411 @example
3412 /test1
3413 /test2
3414 /test3*
3415 @end example
3416
3417 @noindent
3418 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3419 Then, the search path would be
3420
3421 @c @code looks better than @file here
3422 @enumerate
3423 @item @code{/foo}
3424 @item @code{/bar}
3425 @item @var{acdir}-@var{APIVERSION}
3426 @item @var{acdir}
3427 @item @code{/test1}
3428 @item @code{/test2}
3429 @end enumerate
3430
3431 @noindent
3432 and all directories with path names starting with @code{/test3}.
3433
3434 If the @option{--system-acdir=@var{dir}} option is used, then
3435 @command{aclocal} will search for the @file{dirlist} file in
3436 @var{dir}; but remember the warnings  above against the use of
3437 @option{--system-acdir}.
3438
3439 @file{dirlist} is useful in the following situation: suppose that
3440 @command{automake} version @code{1.11.2} is installed with
3441 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3442 directories are
3443
3444 @c @code looks better than @file here
3445 @enumerate
3446 @item @code{/usr/share/aclocal-1.11/}
3447 @item @code{/usr/share/aclocal/}
3448 @end enumerate
3449
3450 However, suppose further that many packages have been manually
3451 installed on the system, with $prefix=/usr/local, as is typical.  In
3452 that case, many of these ``extra'' @file{.m4} files are in
3453 @file{/usr/local/share/aclocal}.  The only way to force
3454 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3455 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3456 inconvenient.  With @file{dirlist}, one may create a file
3457 @file{/usr/share/aclocal/dirlist} containing only the single line
3458
3459 @example
3460 /usr/local/share/aclocal
3461 @end example
3462
3463 Now, the ``default'' search path on the affected system is
3464
3465 @c @code looks better than @file here
3466 @enumerate
3467 @item @code{/usr/share/aclocal-1.11/}
3468 @item @code{/usr/share/aclocal/}
3469 @item @code{/usr/local/share/aclocal/}
3470 @end enumerate
3471
3472 without the need for @option{-I} options; @option{-I} options can be reserved
3473 for project-specific needs (@file{my-source-dir/m4/}), rather than
3474 using it to work around local system-dependent tool installation
3475 directories.
3476
3477 Similarly, @file{dirlist} can be handy if you have installed a local
3478 copy of Automake in your account and want @command{aclocal} to look for
3479 macros installed at other places on the system.
3480
3481 @anchor{ACLOCAL_PATH}
3482 @subsubheading Modifying the Macro Search Path: @file{ACLOCAL_PATH}
3483 @cindex @env{ACLOCAL_PATH}
3484
3485 The fourth and last mechanism to customize the macro search path is
3486 also the simplest.  Any directory included in the colon-separated
3487 environment variable @env{ACLOCAL_PATH} is added to the search path
3488 @c Keep in sync with aclocal-path-precedence.test.
3489 and takes precedence over system directories (including those found via
3490 @file{dirlist}), with the exception of the versioned directory
3491 @var{acdir-APIVERSION} (@pxref{Macro Search Path}).  However, directories
3492 passed via @option{-I} will take precedence over directories in
3493 @env{ACLOCAL_PATH}.
3494
3495 @c Keep in sync with aclocal-path-installed.test.
3496 Also note that, if the @option{--install} option is used, any @file{.m4}
3497 file containing a required macro that is found in a directory listed in
3498 @env{ACLOCAL_PATH} will be installed locally.
3499 @c Keep in sync with aclocal-path-installed-serial.test.
3500 In this case, serial numbers in @file{.m4} are honoured too,
3501 @pxref{Serials}.
3502
3503 Conversely to @file{dirlist}, @env{ACLOCAL_PATH} is useful if you are
3504 using a global copy of Automake and want @command{aclocal} to look for
3505 macros somewhere under your home directory.
3506
3507 @subsubheading Planned future incompatibilities
3508
3509 The order in which the directories in the macro search path are currently
3510 looked up is confusing and/or suboptimal in various aspects, and is
3511 probably going to be changed in the future Automake release.  In
3512 particular, directories in @env{ACLOCAL_PATH} and @file{@var{acdir}}
3513 might end up taking precedence over @file{@var{acdir-APIVERSION}}, and
3514 directories in @file{@var{acdir}/dirlist} might end up taking precedence
3515 over @file{@var{acdir}}.  @emph{This is a possible future incompatibility!}
3516
3517 @node Extending aclocal
3518 @subsection Writing your own aclocal macros
3519
3520 @cindex @command{aclocal}, extending
3521 @cindex Extending @command{aclocal}
3522
3523 The @command{aclocal} program doesn't have any built-in knowledge of any
3524 macros, so it is easy to extend it with your own macros.
3525
3526 This can be used by libraries that want to supply their own Autoconf
3527 macros for use by other programs.  For instance, the @command{gettext}
3528 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3529 any package using @command{gettext}.  When the library is installed, it
3530 installs this macro so that @command{aclocal} will find it.
3531
3532 A macro file's name should end in @file{.m4}.  Such files should be
3533 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3534
3535 @c Keep in sync with primary-prefix-couples-documented-valid.test.
3536 @example
3537 aclocaldir = $(datadir)/aclocal
3538 aclocal_DATA = mymacro.m4 myothermacro.m4
3539 @end example
3540
3541 @noindent
3542 Please do use @file{$(datadir)/aclocal}, and not something based on
3543 the result of @samp{aclocal --print-ac-dir} (@pxref{Hard-Coded Install
3544 Paths}, for arguments).  It might also be helpful to suggest to
3545 the user to add the @file{$(datadir)/aclocal} directory to his
3546 @env{ACLOCAL_PATH} variable (@pxref{ACLOCAL_PATH}) so that
3547 @command{aclocal} will find the @file{.m4} files installed by your
3548 package automatically.
3549
3550 A file of macros should be a series of properly quoted
3551 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3552 Autoconf Manual}).  The @command{aclocal} programs also understands
3553 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3554 Autoconf Manual}), so it is safe to put each macro in a separate file.
3555 Each file should have no side effects but macro definitions.
3556 Especially, any call to @code{AC_PREREQ} should be done inside the
3557 defined macro, not at the beginning of the file.
3558
3559 @cindex underquoted @code{AC_DEFUN}
3560 @acindex AC_DEFUN
3561 @acindex AC_PREREQ
3562
3563 Starting with Automake 1.8, @command{aclocal} will warn about all
3564 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3565 lot of people, because @command{aclocal} was not so strict in the past
3566 and many third party macros are underquoted; and we have to apologize
3567 for this temporary inconvenience.  The reason we have to be stricter
3568 is that a future implementation of @command{aclocal} (@pxref{Future of
3569 aclocal}) will have to temporarily include all these third party
3570 @file{.m4} files, maybe several times, including even files that are
3571 not actually needed.  Doing so should alleviate many problems of the
3572 current implementation, however it requires a stricter style from the
3573 macro authors.  Hopefully it is easy to revise the existing macros.
3574 For instance,
3575
3576 @example
3577 # bad style
3578 AC_PREREQ(2.57)
3579 AC_DEFUN(AX_FOOBAR,
3580 [AC_REQUIRE([AX_SOMETHING])dnl
3581 AX_FOO
3582 AX_BAR
3583 ])
3584 @end example
3585
3586 @noindent
3587 should be rewritten as
3588
3589 @example
3590 AC_DEFUN([AX_FOOBAR],
3591 [AC_PREREQ([2.57])dnl
3592 AC_REQUIRE([AX_SOMETHING])dnl
3593 AX_FOO
3594 AX_BAR
3595 ])
3596 @end example
3597
3598 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3599 Autoconf 2.57 will not be required if @code{AX_FOOBAR} is not actually
3600 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3601 allows the macro to be redefined or included twice (otherwise this
3602 first argument would be expanded during the second definition).  For
3603 consistency we like to quote even arguments such as @code{2.57} that
3604 do not require it.
3605
3606 If you have been directed here by the @command{aclocal} diagnostic but
3607 are not the maintainer of the implicated macro, you will want to
3608 contact the maintainer of that macro.  Please make sure you have the
3609 latest version of the macro and that the problem hasn't already been
3610 reported before doing so: people tend to work faster when they aren't
3611 flooded by mails.
3612
3613 Another situation where @command{aclocal} is commonly used is to
3614 manage macros that are used locally by the package, @ref{Local
3615 Macros}.
3616
3617 @node Local Macros
3618 @subsection Handling Local Macros
3619
3620 Feature tests offered by Autoconf do not cover all needs.  People
3621 often have to supplement existing tests with their own macros, or
3622 with third-party macros.
3623
3624 There are two ways to organize custom macros in a package.
3625
3626 The first possibility (the historical practice) is to list all your
3627 macros in @file{acinclude.m4}.  This file will be included in
3628 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3629 henceforth be visible to @command{autoconf}.  However if it contains
3630 numerous macros, it will rapidly become difficult to maintain, and it
3631 will be almost impossible to share macros between packages.
3632
3633 @vindex ACLOCAL_AMFLAGS
3634 The second possibility, which we do recommend, is to write each macro
3635 in its own file and gather all these files in a directory.  This
3636 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3637 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3638 From the command line, this is done with @samp{aclocal -I m4}.  The
3639 top-level @file{Makefile.am} should also be updated to define
3640
3641 @example
3642 ACLOCAL_AMFLAGS = -I m4
3643 @end example
3644
3645 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3646 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3647 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3648 Using @command{autoreconf} to Update @file{configure} Scripts,
3649 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3650 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3651 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3652 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3653 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3654 the place where Gettext's macros should be installed.  So even if you
3655 do not really care about the rebuild rules, you should define
3656 @code{ACLOCAL_AMFLAGS}.
3657
3658 When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
3659 that @code{m4_include}s any file from @file{m4/} that defines a
3660 required macro.  Macros not found locally will still be searched in
3661 system-wide directories, as explained in @ref{Macro Search Path}.
3662
3663 Custom macros should be distributed for the same reason that
3664 @file{configure.ac} is: so that other people have all the sources of
3665 your package if they want to work on it.  Actually, this distribution
3666 happens automatically because all @code{m4_include}d files are
3667 distributed.
3668
3669 However there is no consensus on the distribution of third-party
3670 macros that your package may use.  Many libraries install their own
3671 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3672 aclocal}).  For instance, Guile ships with a file called
3673 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3674 be used to define setup compiler and linker flags appropriate for
3675 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3676 cause @command{aclocal} to copy @file{guile.m4} into
3677 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3678 it will not be distributed.  Technically, that means a user who
3679 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3680 This is probably OK, if Guile already is a requirement to build the
3681 package.  However, if Guile is only an optional feature, or if your
3682 package might run on architectures where Guile cannot be installed,
3683 this requirement will hinder development.  An easy solution is to copy
3684 such third-party macros in your local @file{m4/} directory so they get
3685 distributed.
3686
3687 Since Automake 1.10, @command{aclocal} offers an option to copy these
3688 system-wide third-party macros in your local macro directory, solving
3689 the above problem.  Simply use:
3690
3691 @example
3692 ACLOCAL_AMFLAGS = -I m4 --install
3693 @end example
3694
3695 @noindent
3696 With this setup, system-wide macros will be copied to @file{m4/}
3697 the first time you run @command{autoreconf}.  Then the locally
3698 installed macros will have precedence over the system-wide installed
3699 macros each time @command{aclocal} is run again.
3700
3701 One reason why you should keep @option{--install} in the flags even
3702 after the first run is that when you later edit @file{configure.ac}
3703 and depend on a new macro, this macro will be installed in your
3704 @file{m4/} automatically.  Another one is that serial numbers
3705 (@pxref{Serials}) can be used to update the macros in your source tree
3706 automatically when new system-wide versions are installed.  A serial
3707 number should be a single line of the form
3708
3709 @example
3710 #serial @var{nnn}
3711 @end example
3712
3713 @noindent
3714 where @var{nnn} contains only digits and dots.  It should appear in
3715 the M4 file before any macro definition.  It is a good practice to
3716 maintain a serial number for each macro you distribute, even if you do
3717 not use the @option{--install} option of @command{aclocal}: this allows
3718 other people to use it.
3719
3720
3721 @node Serials
3722 @subsection Serial Numbers
3723 @cindex serial numbers in macros
3724 @cindex macro serial numbers
3725 @cindex @code{#serial} syntax
3726 @cindex @command{aclocal} and serial numbers
3727
3728 Because third-party macros defined in @file{*.m4} files are naturally
3729 shared between multiple projects, some people like to version them.
3730 This makes it easier to tell which of two M4 files is newer.  Since at
3731 least 1996, the tradition is to use a @samp{#serial} line for this.
3732
3733 A serial number should be a single line of the form
3734
3735 @example
3736 # serial @var{version}
3737 @end example
3738
3739 @noindent
3740 where @var{version} is a version number containing only digits and
3741 dots.  Usually people use a single integer, and they increment it each
3742 time they change the macro (hence the name of ``serial'').  Such a
3743 line should appear in the M4 file before any macro definition.
3744
3745 The @samp{#} must be the first character on the line,
3746 and it is OK to have extra words after the version, as in
3747
3748 @example
3749 #serial @var{version} @var{garbage}
3750 @end example
3751
3752 Normally these serial numbers are completely ignored by
3753 @command{aclocal} and @command{autoconf}, like any genuine comment.
3754 However when using @command{aclocal}'s @option{--install} feature, these
3755 serial numbers will modify the way @command{aclocal} selects the
3756 macros to install in the package: if two files with the same basename
3757 exist in your search path, and if at least one of them uses a
3758 @samp{#serial} line, @command{aclocal} will ignore the file that has
3759 the older @samp{#serial} line (or the file that has none).
3760
3761 Note that a serial number applies to a whole M4 file, not to any macro
3762 it contains.  A file can contains multiple macros, but only one
3763 serial.
3764
3765 Here is a use case that illustrates the use of @option{--install} and
3766 its interaction with serial numbers.  Let's assume we maintain a
3767 package called MyPackage, the @file{configure.ac} of which requires a
3768 third-party macro @code{AX_THIRD_PARTY} defined in
3769 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3770
3771 @example
3772 # serial 1
3773 AC_DEFUN([AX_THIRD_PARTY], [...])
3774 @end example
3775
3776 MyPackage uses an @file{m4/} directory to store local macros as
3777 explained in @ref{Local Macros}, and has
3778
3779 @example
3780 ACLOCAL_AMFLAGS = -I m4 --install
3781 @end example
3782
3783 @noindent
3784 in its top-level @file{Makefile.am}.
3785
3786 Initially the @file{m4/} directory is empty.  The first time we run
3787 @command{autoreconf}, it will fetch the options to pass to
3788 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3789 --install}.  @command{aclocal} will notice that
3790
3791 @itemize @bullet
3792 @item
3793 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3794 @item
3795 No local macros define @code{AX_THIRD_PARTY}
3796 @item
3797 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3798 with serial 1.
3799 @end itemize
3800
3801 @noindent
3802 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3803 and @command{aclocal} was given the @option{--install} option, it will
3804 copy this file in @file{m4/thirdparty.m4}, and output an
3805 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3806
3807 The next time @samp{aclocal -I m4 --install} is run (either via
3808 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3809 rules) something different happens.  @command{aclocal} notices that
3810
3811 @itemize @bullet
3812 @item
3813 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3814 @item
3815 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3816 with serial 1.
3817 @item
3818 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3819 with serial 1.
3820 @end itemize
3821
3822 @noindent
3823 Because both files have the same serial number, @command{aclocal} uses
3824 the first it found in its search path order (@pxref{Macro Search
3825 Path}).  @command{aclocal} therefore ignores
3826 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3827 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3828
3829 Local directories specified with @option{-I} are always searched before
3830 system-wide directories, so a local file will always be preferred to
3831 the system-wide file in case of equal serial numbers.
3832
3833 Now suppose the system-wide third-party macro is changed.  This can
3834 happen if the package installing this macro is updated.  Let's suppose
3835 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3836 --install} is run the situation is the following:
3837
3838 @itemize @bullet
3839 @item
3840 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3841 @item
3842 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3843 with serial 1.
3844 @item
3845 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3846 with serial 2.
3847 @end itemize
3848
3849 @noindent
3850 When @command{aclocal} sees a greater serial number, it immediately
3851 forgets anything it knows from files that have the same basename and a
3852 smaller serial number.  So after it has found
3853 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3854 @command{aclocal} will proceed as if it had never seen
3855 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3856 to that at the beginning of our example, where no local file defined
3857 the macro.  @command{aclocal} will install the new version of the
3858 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3859 version.  MyPackage just had its macro updated as a side effect of
3860 running @command{aclocal}.
3861
3862 If you are leery of letting @command{aclocal} update your local macro,
3863 you can run @samp{aclocal -I m4 --diff} to review the changes
3864 @samp{aclocal -I m4 --install} would perform on these macros.
3865
3866 Finally, note that the @option{--force} option of @command{aclocal} has
3867 absolutely no effect on the files installed by @option{--install}.  For
3868 instance, if you have modified your local macros, do not expect
3869 @option{--install --force} to replace the local macros by their
3870 system-wide versions.  If you want to do so, simply erase the local
3871 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3872
3873
3874 @node Future of aclocal
3875 @subsection The Future of @command{aclocal}
3876 @cindex @command{aclocal}'s scheduled death
3877
3878 @command{aclocal} is expected to disappear.  This feature really
3879 should not be offered by Automake.  Automake should focus on
3880 generating @file{Makefile}s; dealing with M4 macros really is
3881 Autoconf's job.  The fact that some people install Automake just to use
3882 @command{aclocal}, but do not use @command{automake} otherwise is an
3883 indication of how that feature is misplaced.
3884
3885 The new implementation will probably be done slightly differently.
3886 For instance, it could enforce the @file{m4/}-style layout discussed in
3887 @ref{Local Macros}.
3888
3889 We have no idea when and how this will happen.  This has been
3890 discussed several times in the past, but someone still has to commit
3891 to that non-trivial task.
3892
3893 From the user point of view, @command{aclocal}'s removal might turn
3894 out to be painful.  There is a simple precaution that you may take to
3895 make that switch more seamless: never call @command{aclocal} yourself.
3896 Keep this guy under the exclusive control of @command{autoreconf} and
3897 Automake's rebuild rules.  Hopefully you won't need to worry about
3898 things breaking, when @command{aclocal} disappears, because everything
3899 will have been taken care of.  If otherwise you used to call
3900 @command{aclocal} directly yourself or from some script, you will
3901 quickly notice the change.
3902
3903 Many packages come with a script called @file{bootstrap.sh} or
3904 @file{autogen.sh}, that will just call @command{aclocal},
3905 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3906 @command{autoconf}, @command{autoheader}, and @command{automake} in
3907 the right order.  Actually this is precisely what @command{autoreconf}
3908 can do for you.  If your package has such a @file{bootstrap.sh} or
3909 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3910 should simplify its logic a lot (less things to maintain, yum!), it's
3911 even likely you will not need the script anymore, and more to the point
3912 you will not call @command{aclocal} directly anymore.
3913
3914 For the time being, third-party packages should continue to install
3915 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3916 is replaced by another tool it might make sense to rename the
3917 directory, but supporting @file{/usr/share/aclocal/} for backward
3918 compatibility should be really easy provided all macros are properly
3919 written (@pxref{Extending aclocal}).
3920
3921
3922
3923 @node Macros
3924 @section Autoconf macros supplied with Automake
3925
3926 Automake ships with several Autoconf macros that you can use from your
3927 @file{configure.ac}.  When you use one of them it will be included by
3928 @command{aclocal} in @file{aclocal.m4}.
3929
3930 @menu
3931 * Public Macros::               Macros that you can use.
3932 * Obsolete Macros::             Macros that you should stop using.
3933 * Private Macros::              Macros that you should not use.
3934 @end menu
3935
3936 @c consider generating the following subsections automatically from m4 files.
3937
3938 @node Public Macros
3939 @subsection Public Macros
3940
3941 @table @code
3942
3943 @item AM_INIT_AUTOMAKE([OPTIONS])
3944 @itemx AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
3945 @acindex AM_INIT_AUTOMAKE
3946 Runs many macros required for proper operation of the generated Makefiles.
3947
3948 @vindex AUTOMAKE_OPTIONS
3949 This macro has two forms, the first of which is preferred.
3950 In this form, @code{AM_INIT_AUTOMAKE} is called with a
3951 single argument: a space-separated list of Automake options that should
3952 be applied to every @file{Makefile.am} in the tree.  The effect is as if
3953 each option were listed in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3954
3955 @acindex AC_INIT
3956 The second, deprecated, form of @code{AM_INIT_AUTOMAKE} has two required
3957 arguments: the package and the version number.  This form is
3958 obsolete because the @var{package} and @var{version} can be obtained
3959 from Autoconf's @code{AC_INIT} macro (which itself has an old and a new
3960 form).
3961
3962 If your @file{configure.ac} has:
3963
3964 @example
3965 AC_INIT([src/foo.c])
3966 AM_INIT_AUTOMAKE([mumble], [1.5])
3967 @end example
3968
3969 @noindent
3970 you can modernize it as follows:
3971
3972 @example
3973 AC_INIT([mumble], [1.5])
3974 AC_CONFIG_SRCDIR([src/foo.c])
3975 AM_INIT_AUTOMAKE
3976 @end example
3977
3978 Note that if you're upgrading your @file{configure.ac} from an earlier
3979 version of Automake, it is not always correct to simply move the
3980 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3981 @code{AC_INIT}, as in the example above.  The first argument to
3982 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3983 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3984 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3985 tarball name from the package name, which should work for most but not
3986 all package names.  (If it doesn't work for yours, you can use the
3987 four-argument form of @code{AC_INIT} to provide the tarball name
3988 explicitly).
3989
3990 @cindex @code{PACKAGE}, prevent definition
3991 @cindex @code{VERSION}, prevent definition
3992 @opindex no-define
3993 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3994 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3995 option, as in:
3996 @example
3997 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3998 @end example
3999 or by passing a third non-empty argument to the obsolete form.
4000
4001 @item AM_PATH_LISPDIR
4002 @acindex AM_PATH_LISPDIR
4003 @vindex EMACS
4004 @vindex lispdir
4005 Searches for the program @command{emacs}, and, if found, sets the
4006 output variable @code{lispdir} to the full path to Emacs' site-lisp
4007 directory.
4008
4009 Note that this test assumes the @command{emacs} found to be a version
4010 that supports Emacs Lisp (such as GNU Emacs or XEmacs).  Other
4011 emacsen can cause this test to hang (some, like old versions of
4012 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
4013 exit, which is hardly obvious for a non-emacs user).  In most cases,
4014 however, you should be able to use @kbd{C-c} to kill the test.  In
4015 order to avoid problems, you can set @env{EMACS} to ``no'' in the
4016 environment, or use the @option{--with-lispdir} option to
4017 @command{configure} to explicitly set the correct path (if you're sure
4018 you have an @command{emacs} that supports Emacs Lisp).
4019
4020 @item AM_PROG_AR(@ovar{act-if-fail})
4021 @acindex AM_PROG_AR
4022 @vindex AR
4023 You must use this macro when you use the archiver in your project, if
4024 you want support for unusual archivers such as Microsoft @command{lib}.
4025 The content of the optional argument is executed if the archiver
4026 interface is not recognized; the default action is to abort configure
4027 with an error message.
4028
4029 @item AM_PROG_AS
4030 @acindex AM_PROG_AS
4031 @vindex CCAS
4032 @vindex CCASFLAGS
4033 Use this macro when you have assembly code in your project.  This will
4034 choose the assembler for you (by default the C compiler) and set
4035 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
4036
4037 @item AM_PROG_CC_C_O
4038 @acindex AM_PROG_CC_C_O
4039 @acindex AC_PROG_CC_C_O
4040 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
4041 the manner required by Automake.  You must use this instead of
4042 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
4043 using per-target flags or subdir-objects with C sources.
4044
4045 @item AM_PROG_LEX
4046 @acindex AM_PROG_LEX
4047 @acindex AC_PROG_LEX
4048 @cindex HP-UX 10, @command{lex} problems
4049 @cindex @command{lex} problems with HP-UX 10
4050 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
4051 Program Checks, autoconf, The Autoconf Manual}), but uses the
4052 @command{missing} script on systems that do not have @command{lex}.
4053 HP-UX 10 is one such system.
4054
4055 @item AM_PROG_GCJ
4056 @acindex AM_PROG_GCJ
4057 @vindex GCJ
4058 @vindex GCJFLAGS
4059 This macro finds the @command{gcj} program or causes an error.  It sets
4060 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
4061 GNU Compiler Collection.
4062
4063 @item AM_PROG_UPC([@var{compiler-search-list}])
4064 @acindex AM_PROG_UPC
4065 @vindex UPC
4066 Find a compiler for Unified Parallel C and define the @code{UPC}
4067 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
4068 This macro will abort @command{configure} if no Unified Parallel C
4069 compiler is found.
4070
4071 @item AM_SILENT_RULES
4072 @acindex AM_SILENT_RULES
4073 Enable the machinery for less verbose build output (@pxref{Options}).
4074
4075 @item AM_WITH_DMALLOC
4076 @acindex AM_WITH_DMALLOC
4077 @cindex @command{dmalloc}, support for
4078 @vindex WITH_DMALLOC
4079 @opindex --with-dmalloc
4080 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
4081 the user runs @command{configure} with @option{--with-dmalloc}, then
4082 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
4083
4084 @end table
4085
4086
4087 @node Obsolete Macros
4088 @subsection Obsolete Macros
4089 @cindex obsolete macros
4090 @cindex autoupdate
4091
4092 Although using some of the following macros was required in past
4093 releases, you should not use any of them in new code.  Running
4094 @command{autoupdate} should adjust your @file{configure.ac}
4095 automatically (@pxref{autoupdate Invocation, , Using
4096 @command{autoupdate} to Modernize @file{configure.ac}, autoconf, The
4097 Autoconf Manual}).
4098
4099 @table @code
4100
4101 @item AM_CONFIG_HEADER
4102 @acindex AM_CONFIG_HEADER
4103 Automake will generate rules to automatically regenerate the config
4104 header.  This obsolete macro is a synonym of @code{AC_CONFIG_HEADERS}
4105 today (@pxref{Optional}).
4106
4107 @item AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4108 @acindex AM_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
4109 If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
4110 define @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can be
4111 found in @file{<termios.h>}.  This macro is obsolete, you should
4112 use Autoconf's @code{AC_HEADER_TIOCGWINSZ} instead.
4113
4114 @item AM_PROG_MKDIR_P
4115 @acindex AM_PROG_MKDIR_P
4116 @cindex @code{mkdir -p}, macro check
4117 @vindex MKDIR_P
4118 @vindex mkdir_p
4119
4120 From Automake 1.8 to 1.9.6 this macro used to define the output
4121 variable @code{mkdir_p} to one of @code{mkdir -p}, @code{install-sh
4122 -d}, or @code{mkinstalldirs}.
4123
4124 Nowadays Autoconf provides a similar functionality with
4125 @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs, , Particular
4126 Program Checks, autoconf, The Autoconf Manual}), however this defines
4127 the output variable @code{MKDIR_P} instead.  Therefore
4128 @code{AM_PROG_MKDIR_P} has been rewritten as a thin wrapper around
4129 @code{AC_PROG_MKDIR_P} to define @code{mkdir_p} to the same value as
4130 @code{MKDIR_P} for backward compatibility.
4131
4132 If you are using Automake, there is normally no reason to call this
4133 macro, because @code{AM_INIT_AUTOMAKE} already does so.  However, make
4134 sure that the custom rules in your @file{Makefile}s use
4135 @code{$(MKDIR_P)} and not @code{$(mkdir_p)}.  Even if both variables
4136 still work, the latter should be considered obsolete.
4137
4138 If you are not using Automake, please call @code{AC_PROG_MKDIR_P}
4139 instead of @code{AM_PROG_MKDIR_P}.
4140
4141 @item AM_SYS_POSIX_TERMIOS
4142 @acindex AM_SYS_POSIX_TERMIOS
4143 @cindex POSIX termios headers
4144 @cindex termios POSIX headers
4145 Check to see if POSIX termios headers and functions are available on the
4146 system.  If so, set the shell variable @code{am_cv_sys_posix_termios} to
4147 @samp{yes}.  If not, set the variable to @samp{no}.  This macro is obsolete,
4148 you should use Autoconf's @code{AC_SYS_POSIX_TERMIOS} instead.
4149
4150 @end table
4151
4152
4153 @node Private Macros
4154 @subsection Private Macros
4155
4156 The following macros are private macros you should not call directly.
4157 They are called by the other public macros when appropriate.  Do not
4158 rely on them, as they might be changed in a future version.  Consider
4159 them as implementation details; or better, do not consider them at all:
4160 skip this section!
4161
4162 @ftable @code
4163 @item _AM_DEPENDENCIES
4164 @itemx AM_SET_DEPDIR
4165 @itemx AM_DEP_TRACK
4166 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4167 These macros are used to implement Automake's automatic dependency
4168 tracking scheme.  They are called automatically by Automake when
4169 required, and there should be no need to invoke them manually.
4170
4171 @item AM_MAKE_INCLUDE
4172 This macro is used to discover how the user's @command{make} handles
4173 @code{include} statements.  This macro is automatically invoked when
4174 needed; there should be no need to invoke it manually.
4175
4176 @item AM_PROG_INSTALL_STRIP
4177 This is used to find a version of @code{install} that can be used to
4178 strip a program at installation time.  This macro is automatically
4179 included when required.
4180
4181 @item AM_SANITY_CHECK
4182 This checks to make sure that a file created in the build directory is
4183 newer than a file in the source directory.  This can fail on systems
4184 where the clock is set incorrectly.  This macro is automatically run
4185 from @code{AM_INIT_AUTOMAKE}.
4186
4187 @end ftable
4188
4189
4190 @node Directories
4191 @chapter Directories
4192
4193 For simple projects that distribute all files in the same directory
4194 it is enough to have a single @file{Makefile.am} that builds
4195 everything in place.
4196
4197 In larger projects it is common to organize files in different
4198 directories, in a tree.  For instance one directory per program, per
4199 library or per module.  The traditional approach is to build these
4200 subdirectories recursively: each directory contains its @file{Makefile}
4201 (generated from @file{Makefile.am}), and when @command{make} is run
4202 from the top level directory it enters each subdirectory in turn to
4203 build its contents.
4204
4205 @menu
4206 * Subdirectories::              Building subdirectories recursively
4207 * Conditional Subdirectories::  Conditionally not building directories
4208 * Alternative::                 Subdirectories without recursion
4209 * Subpackages::                 Nesting packages
4210 @end menu
4211
4212 @node Subdirectories
4213 @section Recursing subdirectories
4214
4215 @cindex @code{SUBDIRS}, explained
4216
4217 In packages with subdirectories, the top level @file{Makefile.am} must
4218 tell Automake which subdirectories are to be built.  This is done via
4219 the @code{SUBDIRS} variable.
4220 @vindex SUBDIRS
4221
4222 The @code{SUBDIRS} variable holds a list of subdirectories in which
4223 building of various sorts can occur.  The rules for many targets
4224 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4225 both locally and in all specified subdirectories.  Note that the
4226 directories listed in @code{SUBDIRS} are not required to contain
4227 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4228 This allows inclusion of libraries from packages that do not use
4229 Automake (such as @code{gettext}; see also @ref{Third-Party
4230 Makefiles}).
4231
4232 In packages that use subdirectories, the top-level @file{Makefile.am} is
4233 often very short.  For instance, here is the @file{Makefile.am} from the
4234 GNU Hello distribution:
4235
4236 @example
4237 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4238 SUBDIRS = doc intl po src tests
4239 @end example
4240
4241 When Automake invokes @command{make} in a subdirectory, it uses the value
4242 of the @code{MAKE} variable.  It passes the value of the variable
4243 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4244 @file{Makefile.am} if there are flags you must always pass to
4245 @command{make}.
4246 @vindex MAKE
4247 @vindex AM_MAKEFLAGS
4248
4249 The directories mentioned in @code{SUBDIRS} are usually direct
4250 children of the current directory, each subdirectory containing its
4251 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4252 subdirectories.  Automake can be used to construct packages of
4253 arbitrary depth this way.
4254
4255 By default, Automake generates @file{Makefiles} that work depth-first
4256 in postfix order: the subdirectories are built before the current
4257 directory.  However, it is possible to change this ordering.  You can
4258 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4259 putting @samp{.} first will cause a prefix ordering of
4260 directories.
4261
4262 Using
4263
4264 @example
4265 SUBDIRS = lib src . test
4266 @end example
4267
4268 @noindent
4269 will cause @file{lib/} to be built before @file{src/}, then the
4270 current directory will be built, finally the @file{test/} directory
4271 will be built.  It is customary to arrange test directories to be
4272 built after everything else since they are meant to test what has
4273 been constructed.
4274
4275 All @code{clean} rules are run in reverse order of build rules.
4276
4277 @node Conditional Subdirectories
4278 @section Conditional Subdirectories
4279 @cindex Subdirectories, building conditionally
4280 @cindex Conditional subdirectories
4281 @cindex @code{SUBDIRS}, conditional
4282 @cindex Conditional @code{SUBDIRS}
4283
4284 It is possible to define the @code{SUBDIRS} variable conditionally if,
4285 like in the case of GNU Inetutils, you want to only build a subset of
4286 the entire package.
4287
4288 To illustrate how this works, let's assume we have two directories
4289 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4290 want to decide in @command{configure} whether @file{opt/} will be built
4291 or not.  (For this example we will assume that @file{opt/} should be
4292 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4293
4294 Running @command{make} should thus recurse into @file{src/} always, and
4295 then maybe in @file{opt/}.
4296
4297 However @samp{make dist} should always recurse into both @file{src/}
4298 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4299 is not needed in the current configuration.  This means
4300 @file{opt/Makefile} should be created @emph{unconditionally}.
4301
4302 There are two ways to setup a project like this.  You can use Automake
4303 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4304 variables (@pxref{Setting Output Variables, , Setting Output
4305 Variables, autoconf, The Autoconf Manual}).  Using Automake
4306 conditionals is the preferred solution.  Before we illustrate these
4307 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4308
4309 @menu
4310 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4311 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4312 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4313 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4314 @end menu
4315
4316 @node SUBDIRS vs DIST_SUBDIRS
4317 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4318 @cindex @code{DIST_SUBDIRS}, explained
4319
4320 Automake considers two sets of directories, defined by the variables
4321 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4322
4323 @code{SUBDIRS} contains the subdirectories of the current directory
4324 that must be built (@pxref{Subdirectories}).  It must be defined
4325 manually; Automake will never guess a directory is to be built.  As we
4326 will see in the next two sections, it is possible to define it
4327 conditionally so that some directory will be omitted from the build.
4328
4329 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4330 directories, even those that have been conditionally left out of the
4331 build.  Recall our example where we may not want to build subdirectory
4332 @file{opt/}, but yet we want to distribute it?  This is where
4333 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4334 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4335
4336 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4337 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4338 other recursive rules use @code{SUBDIRS}.
4339
4340 If @code{SUBDIRS} is defined conditionally using Automake
4341 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4342 from the possible values of @code{SUBDIRS} in all conditions.
4343
4344 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4345 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4346 does not know the possible values of these variables.  In this case
4347 @code{DIST_SUBDIRS} needs to be defined manually.
4348
4349 @node Subdirectories with AM_CONDITIONAL
4350 @subsection Subdirectories with @code{AM_CONDITIONAL}
4351 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4352 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4353
4354 @c Keep in sync with subcond2.test.
4355
4356 @file{configure} should output the @file{Makefile} for each directory
4357 and define a condition into which @file{opt/} should be built.
4358
4359 @example
4360 @dots{}
4361 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4362 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4363 @dots{}
4364 @end example
4365
4366 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4367 as follows.
4368
4369 @example
4370 if COND_OPT
4371   MAYBE_OPT = opt
4372 endif
4373 SUBDIRS = src $(MAYBE_OPT)
4374 @end example
4375
4376 As you can see, running @command{make} will rightly recurse into
4377 @file{src/} and maybe @file{opt/}.
4378
4379 @vindex DIST_SUBDIRS
4380 As you can't see, running @samp{make dist} will recurse into both
4381 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4382 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4383 @code{DIST_SUBDIRS} variable.
4384
4385 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4386 automatically because it knows that @code{MAYBE_OPT} can contain
4387 @samp{opt} in some condition.
4388
4389 @node Subdirectories with AC_SUBST
4390 @subsection Subdirectories with @code{AC_SUBST}
4391 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4392 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4393
4394 @c Keep in sync with subcond3.test.
4395
4396 Another possibility is to define @code{MAYBE_OPT} from
4397 @file{./configure} using @code{AC_SUBST}:
4398
4399 @example
4400 @dots{}
4401 if test "$want_opt" = yes; then
4402   MAYBE_OPT=opt
4403 else
4404   MAYBE_OPT=
4405 fi
4406 AC_SUBST([MAYBE_OPT])
4407 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4408 @dots{}
4409 @end example
4410
4411 In this case the top-level @file{Makefile.am} should look as follows.
4412
4413 @example
4414 SUBDIRS = src $(MAYBE_OPT)
4415 DIST_SUBDIRS = src opt
4416 @end example
4417
4418 The drawback is that since Automake cannot guess what the possible
4419 values of @code{MAYBE_OPT} are, it is necessary to define
4420 @code{DIST_SUBDIRS}.
4421
4422 @node Unconfigured Subdirectories
4423 @subsection Unconfigured Subdirectories
4424 @cindex Subdirectories, configured conditionally
4425
4426 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4427 users that try to @emph{configure and build} subdirectories
4428 conditionally.  Here by configuring we mean creating the
4429 @file{Makefile} (it might also involve running a nested
4430 @command{configure} script: this is a costly operation that explains
4431 why people want to do it conditionally, but only the @file{Makefile}
4432 is relevant to the discussion).
4433
4434 The above examples all assume that every @file{Makefile} is created,
4435 even in directories that are not going to be built.  The simple reason
4436 is that we want @samp{make dist} to distribute even the directories
4437 that are not being built (e.g., platform-dependent code), hence
4438 @file{make dist} must recurse into the subdirectory, hence this
4439 directory must be configured and appear in @code{DIST_SUBDIRS}.
4440
4441 Building packages that do not configure every subdirectory is a tricky
4442 business, and we do not recommend it to the novice as it is easy to
4443 produce an incomplete tarball by mistake.  We will not discuss this
4444 topic in depth here, yet for the adventurous here are a few rules to
4445 remember.
4446
4447 @cartouche
4448 @itemize
4449 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4450
4451 It makes little sense to have a directory in @code{SUBDIRS} that
4452 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4453 which directories listed in the latter should be built.
4454 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4455 must be configured.
4456
4457 I.e., the @file{Makefile} must exists or the recursive @command{make}
4458 rules will not be able to process the directory.
4459 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4460
4461 So that the cleaning rules remove the generated @file{Makefile}s.
4462 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4463 lists all the directories that have been configured.
4464 @end itemize
4465 @end cartouche
4466
4467 In order to prevent recursion in some unconfigured directory you
4468 must therefore ensure that this directory does not appear in
4469 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4470 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4471 @code{DIST_SUBDIRS} explicitly, it will be default to
4472 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4473 = $(SUBDIRS)}.
4474
4475 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4476 not be distributed unless you make other arrangements for this to
4477 happen (for instance, always running @samp{make dist} in a
4478 configuration where all directories are known to appear in
4479 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4480 distribute these directories).
4481
4482 @cindex Subdirectories, not distributed
4483 In few packages, unconfigured directories are not even expected to
4484 be distributed.  Although these packages do not require the
4485 aforementioned extra arrangements, there is another pitfall.  If the
4486 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4487 @command{automake} will make sure the directory exists.  Consequently
4488 @command{automake} cannot be run on such a distribution when one
4489 directory has been omitted.  One way to avoid this check is to use the
4490 @code{AC_SUBST} method to declare conditional directories; since
4491 @command{automake} does not know the values of @code{AC_SUBST}
4492 variables it cannot ensure the corresponding directory exists.
4493
4494 @node Alternative
4495 @section An Alternative Approach to Subdirectories
4496
4497 If you've ever read Peter Miller's excellent paper,
4498 @uref{http://miller.emu.id.au/pmiller/books/rmch/,
4499 Recursive Make Considered Harmful}, the preceding sections on the use of
4500 subdirectories will probably come as unwelcome advice.  For those who
4501 haven't read the paper, Miller's main thesis is that recursive
4502 @command{make} invocations are both slow and error-prone.
4503
4504 Automake provides sufficient cross-directory support @footnote{We
4505 believe.  This work is new and there are probably warts.
4506 @xref{Introduction}, for information on reporting bugs.} to enable you
4507 to write a single @file{Makefile.am} for a complex multi-directory
4508 package.
4509
4510
4511 By default an installable file specified in a subdirectory will have its
4512 directory name stripped before installation.  For instance, in this
4513 example, the header file will be installed as
4514 @file{$(includedir)/stdio.h}:
4515
4516 @example
4517 include_HEADERS = inc/stdio.h
4518 @end example
4519
4520 @vindex nobase_
4521 @cindex @code{nobase_} prefix
4522 @cindex Path stripping, avoiding
4523 @cindex Avoiding path stripping
4524
4525 However, the @samp{nobase_} prefix can be used to circumvent this path
4526 stripping.  In this example, the header file will be installed as
4527 @file{$(includedir)/sys/types.h}:
4528
4529 @example
4530 nobase_include_HEADERS = sys/types.h
4531 @end example
4532
4533 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4534 @cindex @code{dist_} and @code{nobase_}
4535 @cindex @code{nodist_} and @code{nobase_}
4536 @vindex dist_
4537 @vindex nodist_
4538
4539 @samp{nobase_} should be specified first when used in conjunction with
4540 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4541 Control}).  For instance:
4542
4543 @example
4544 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4545 @end example
4546
4547 Finally, note that a variable using the @samp{nobase_} prefix can
4548 often be replaced by several variables, one for each destination
4549 directory (@pxref{Uniform}).  For instance, the last example could be
4550 rewritten as follows:
4551
4552 @c Keep in sync with primary-prefix-couples-documented-valid.test.
4553 @example
4554 imagesdir = $(pkgdatadir)/images
4555 soundsdir = $(pkgdatadir)/sounds
4556 dist_images_DATA = images/vortex.pgm
4557 dist_sounds_DATA = sounds/whirl.ogg
4558 @end example
4559
4560 @noindent
4561 This latter syntax makes it possible to change one destination
4562 directory without changing the layout of the source tree.
4563
4564 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4565 rule, in that there is no particular installation order guarantee for
4566 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4567
4568 @node Subpackages
4569 @section Nesting Packages
4570 @cindex Nesting packages
4571 @cindex Subpackages
4572 @acindex AC_CONFIG_SUBDIRS
4573 @acindex AC_CONFIG_AUX_DIR
4574
4575
4576 In the GNU Build System, packages can be nested to arbitrary depth.
4577 This means that a package can embed other packages with their own
4578 @file{configure}, @file{Makefile}s, etc.
4579
4580 These other packages should just appear as subdirectories of their
4581 parent package.  They must be listed in @code{SUBDIRS} like other
4582 ordinary directories.  However the subpackage's @file{Makefile}s
4583 should be output by its own @file{configure} script, not by the
4584 parent's @file{configure}.  This is achieved using the
4585 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4586 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4587 autoconf, The Autoconf Manual}).
4588
4589 Here is an example package for an @code{arm} program that links with
4590 a @code{hand} library that is a nested package in subdirectory
4591 @file{hand/}.
4592
4593 @code{arm}'s @file{configure.ac}:
4594
4595 @example
4596 AC_INIT([arm], [1.0])
4597 AC_CONFIG_AUX_DIR([.])
4598 AM_INIT_AUTOMAKE
4599 AC_PROG_CC
4600 AC_CONFIG_FILES([Makefile])
4601 # Call hand's ./configure script recursively.
4602 AC_CONFIG_SUBDIRS([hand])
4603 AC_OUTPUT
4604 @end example
4605
4606 @code{arm}'s @file{Makefile.am}:
4607
4608 @example
4609 # Build the library in the hand subdirectory first.
4610 SUBDIRS = hand
4611
4612 # Include hand's header when compiling this directory.
4613 AM_CPPFLAGS = -I$(srcdir)/hand
4614
4615 bin_PROGRAMS = arm
4616 arm_SOURCES = arm.c
4617 # link with the hand library.
4618 arm_LDADD = hand/libhand.a
4619 @end example
4620
4621 Now here is @code{hand}'s @file{hand/configure.ac}:
4622
4623 @example
4624 AC_INIT([hand], [1.2])
4625 AC_CONFIG_AUX_DIR([.])
4626 AM_INIT_AUTOMAKE
4627 AC_PROG_CC
4628 AM_PROG_AR
4629 AC_PROG_RANLIB
4630 AC_CONFIG_FILES([Makefile])
4631 AC_OUTPUT
4632 @end example
4633
4634 @noindent
4635 and its @file{hand/Makefile.am}:
4636
4637 @example
4638 lib_LIBRARIES = libhand.a
4639 libhand_a_SOURCES = hand.c
4640 @end example
4641
4642 When @samp{make dist} is run from the top-level directory it will
4643 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4644 code as well as the @file{hand} subdirectory.  This package can be
4645 built and installed like any ordinary package, with the usual
4646 @samp{./configure && make && make install} sequence (the @code{hand}
4647 subpackage will be built and installed by the process).
4648
4649 When @samp{make dist} is run from the hand directory, it will create a
4650 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4651 to be embedded in another package, it can still be used separately.
4652
4653 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4654 force Automake and Autoconf to search for auxiliary scripts in the
4655 current directory.  For instance, this means that there will be two
4656 copies of @file{install-sh}: one in the top-level of the @code{arm}
4657 package, and another one in the @file{hand/} subdirectory for the
4658 @code{hand} package.
4659
4660 The historical default is to search for these auxiliary scripts in
4661 the parent directory and the grandparent directory.  So if the
4662 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4663 @file{hand/configure.ac}, that subpackage would share the auxiliary
4664 script of the @code{arm} package.  This may looks like a gain in size
4665 (a few kilobytes), but it is actually a loss of modularity as the
4666 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4667 in the subdirectory will not work anymore).
4668
4669 Packages that do not use Automake need more work to be integrated this
4670 way.  @xref{Third-Party Makefiles}.
4671
4672 @node Programs
4673 @chapter Building Programs and Libraries
4674
4675 A large part of Automake's functionality is dedicated to making it easy
4676 to build programs and libraries.
4677
4678 @menu
4679 * A Program::                   Building a program
4680 * A Library::                   Building a library
4681 * A Shared Library::            Building a Libtool library
4682 * Program and Library Variables::  Variables controlling program and
4683                                 library builds
4684 * Default _SOURCES::            Default source files
4685 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4686 * Program Variables::           Variables used when building a program
4687 * Yacc and Lex::                Yacc and Lex support
4688 * C++ Support::                 Compiling C++ sources
4689 * Objective C Support::         Compiling Objective C sources
4690 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4691 * Assembly Support::            Compiling assembly sources
4692 * Fortran 77 Support::          Compiling Fortran 77 sources
4693 * Fortran 9x Support::          Compiling Fortran 9x sources
4694 * Java Support with gcj::       Compiling Java sources using gcj
4695 * Vala Support::                Compiling Vala sources
4696 * Support for Other Languages::  Compiling other languages
4697 * Dependencies::                Automatic dependency tracking
4698 * EXEEXT::                      Support for executable extensions
4699 @end menu
4700
4701
4702 @node A Program
4703 @section Building a program
4704
4705 In order to build a program, you need to tell Automake which sources
4706 are part of it, and which libraries it should be linked with.
4707
4708 This section also covers conditional compilation of sources or
4709 programs.  Most of the comments about these also apply to libraries
4710 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4711
4712 @menu
4713 * Program Sources::             Defining program sources
4714 * Linking::                     Linking with libraries or extra objects
4715 * Conditional Sources::         Handling conditional sources
4716 * Conditional Programs::        Building a program conditionally
4717 @end menu
4718
4719 @node Program Sources
4720 @subsection Defining program sources
4721
4722 @cindex @code{PROGRAMS}, @code{bindir}
4723 @vindex _PROGRAMS
4724 @vindex bin_PROGRAMS
4725 @vindex sbin_PROGRAMS
4726 @vindex libexec_PROGRAMS
4727 @vindex pkglibexec_PROGRAMS
4728 @vindex noinst_PROGRAMS
4729 @vindex check_PROGRAMS
4730
4731 In a directory containing source that gets built into a program (as
4732 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4733 Programs can be installed in @code{bindir}, @code{sbindir},
4734 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4735 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4736 which case the prefix is @samp{check_}.
4737
4738 For instance:
4739
4740 @example
4741 bin_PROGRAMS = hello
4742 @end example
4743
4744 In this simple case, the resulting @file{Makefile.in} will contain code
4745 to generate a program named @code{hello}.
4746
4747 Associated with each program are several assisting variables that are
4748 named after the program.  These variables are all optional, and have
4749 reasonable defaults.  Each variable, its use, and default is spelled out
4750 below; we use the ``hello'' example throughout.
4751
4752 The variable @code{hello_SOURCES} is used to specify which source files
4753 get built into an executable:
4754
4755 @example
4756 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4757 @end example
4758
4759 This causes each mentioned @file{.c} file to be compiled into the
4760 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4761
4762 @cindex @code{_SOURCES} primary, defined
4763 @cindex @code{SOURCES} primary, defined
4764 @cindex Primary variable, @code{SOURCES}
4765 @vindex _SOURCES
4766
4767 If @code{hello_SOURCES} is not specified, then it defaults to the single
4768 file @file{hello.c} (@pxref{Default _SOURCES}).
4769 @vindex _SOURCES
4770 @vindex SOURCES
4771
4772 Multiple programs can be built in a single directory.  Multiple programs
4773 can share a single source file, which must be listed in each
4774 @code{_SOURCES} definition.
4775
4776 @cindex Header files in @code{_SOURCES}
4777 @cindex @code{_SOURCES} and header files
4778
4779 Header files listed in a @code{_SOURCES} definition will be included in
4780 the distribution but otherwise ignored.  In case it isn't obvious, you
4781 should not include the header file generated by @file{configure} in a
4782 @code{_SOURCES} variable; this file should not be distributed.  Lex
4783 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4784 and Lex}.
4785
4786
4787 @node Linking
4788 @subsection Linking the program
4789
4790 If you need to link against libraries that are not found by
4791 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4792 used to specify additional objects or libraries to link with; it is
4793 inappropriate for specifying specific linker flags, you should use
4794 @code{AM_LDFLAGS} for this purpose.
4795 @vindex LDADD
4796 @vindex AM_LDFLAGS
4797
4798 @cindex @code{prog_LDADD}, defined
4799
4800 Sometimes, multiple programs are built in one directory but do not share
4801 the same link-time requirements.  In this case, you can use the
4802 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4803 program as it appears in some @code{_PROGRAMS} variable, and usually
4804 written in lowercase) to override @code{LDADD}.  If this variable exists
4805 for a given program, then that program is not linked using @code{LDADD}.
4806 @vindex maude_LDADD
4807
4808 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4809 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4810 built in the same directory, and has no such link requirement.  Also,
4811 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4812 is what cpio's @file{src/Makefile.am} looks like (abridged):
4813
4814 @example
4815 bin_PROGRAMS = cpio pax $(MT)
4816 libexec_PROGRAMS = $(RMT)
4817 EXTRA_PROGRAMS = mt rmt
4818
4819 LDADD = ../lib/libcpio.a $(INTLLIBS)
4820 rmt_LDADD =
4821
4822 cpio_SOURCES = @dots{}
4823 pax_SOURCES = @dots{}
4824 mt_SOURCES = @dots{}
4825 rmt_SOURCES = @dots{}
4826 @end example
4827
4828 @cindex @code{_LDFLAGS}, defined
4829 @vindex maude_LDFLAGS
4830 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4831 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4832 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4833 this purpose.
4834
4835 @cindex @code{_DEPENDENCIES}, defined
4836 @vindex maude_DEPENDENCIES
4837 @vindex EXTRA_maude_DEPENDENCIES
4838 It is also occasionally useful to have a program depend on some other
4839 target that is not actually part of that program.  This can be done
4840 using either the @code{@var{prog}_DEPENDENCIES} or the
4841 @code{EXTRA_@var{prog}_DEPENDENCIES} variable.  Each program depends on
4842 the contents both variables, but no further interpretation is done.
4843
4844 Since these dependencies are associated to the link rule used to
4845 create the programs they should normally list files used by the link
4846 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4847 files.  In rare cases you may need to add other kinds of files such as
4848 linker scripts, but @emph{listing a source file in
4849 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4850 before all the components of a program are built, consider using the
4851 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4852
4853 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4854 Automake.  The automatically-assigned value is the contents of
4855 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4856 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4857 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4858 @samp{$(ALLOCA)}; these are left because it is known that they will not
4859 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4860 generated.
4861
4862 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4863 may be used.
4864
4865 The @code{EXTRA_@var{prog}_DEPENDENCIES} may be useful for cases where
4866 you merely want to augment the @command{automake}-generated
4867 @code{@var{prog}_DEPENDENCIES} rather than replacing it.
4868
4869 @cindex @code{LDADD} and @option{-l}
4870 @cindex @option{-l} and @code{LDADD}
4871 We recommend that you avoid using @option{-l} options in @code{LDADD}
4872 or @code{@var{prog}_LDADD} when referring to libraries built by your
4873 package.  Instead, write the file name of the library explicitly as in
4874 the above @code{cpio} example.  Use @option{-l} only to list
4875 third-party libraries.  If you follow this rule, the default value of
4876 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4877 omit the other ones.
4878
4879
4880 @node Conditional Sources
4881 @subsection Conditional compilation of sources
4882
4883 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4884 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4885 @code{_SOURCES} variable.  The reason for this is a bit hard to
4886 explain, but suffice to say that it simply won't work.  Automake will
4887 give an error if you try to do this.
4888
4889 Fortunately there are two other ways to achieve the same result.  One is
4890 to use configure substitutions in @code{_LDADD} variables, the other is
4891 to use an Automake conditional.
4892
4893 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4894
4895 @cindex @code{EXTRA_prog_SOURCES}, defined
4896
4897 Automake must know all the source files that could possibly go into a
4898 program, even if not all the files are built in every circumstance.  Any
4899 files that are only conditionally built should be listed in the
4900 appropriate @code{EXTRA_} variable.  For instance, if
4901 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4902 in @code{hello}, the @file{Makefile.am} would contain:
4903
4904 @example
4905 bin_PROGRAMS = hello
4906 hello_SOURCES = hello-common.c
4907 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4908 hello_LDADD = $(HELLO_SYSTEM)
4909 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4910 @end example
4911
4912 @noindent
4913 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4914 @file{configure.ac}:
4915
4916 @example
4917 @dots{}
4918 case $host in
4919   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4920   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4921 esac
4922 AC_SUBST([HELLO_SYSTEM])
4923 @dots{}
4924 @end example
4925
4926 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4927 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4928 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4929 built and linked in.
4930
4931 @subsubheading Conditional Compilation using Automake Conditionals
4932
4933 An often simpler way to compile source files conditionally is to use
4934 Automake conditionals.  For instance, you could use this
4935 @file{Makefile.am} construct to build the same @file{hello} example:
4936
4937 @example
4938 bin_PROGRAMS = hello
4939 if LINUX
4940 hello_SOURCES = hello-linux.c hello-common.c
4941 else
4942 hello_SOURCES = hello-generic.c hello-common.c
4943 endif
4944 @end example
4945
4946 In this case, @file{configure.ac} should setup the @code{LINUX}
4947 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4948
4949 When using conditionals like this you don't need to use the
4950 @code{EXTRA_} variable, because Automake will examine the contents of
4951 each variable to construct the complete list of source files.
4952
4953 If your program uses a lot of files, you will probably prefer a
4954 conditional @samp{+=}.
4955
4956 @example
4957 bin_PROGRAMS = hello
4958 hello_SOURCES = hello-common.c
4959 if LINUX
4960 hello_SOURCES += hello-linux.c
4961 else
4962 hello_SOURCES += hello-generic.c
4963 endif
4964 @end example
4965
4966 @node Conditional Programs
4967 @subsection Conditional compilation of programs
4968 @cindex Conditional programs
4969 @cindex Programs, conditional
4970
4971 Sometimes it is useful to determine the programs that are to be built
4972 at configure time.  For instance, GNU @code{cpio} only builds
4973 @code{mt} and @code{rmt} under special circumstances.  The means to
4974 achieve conditional compilation of programs are the same you can use
4975 to compile source files conditionally: substitutions or conditionals.
4976
4977 @subsubheading Conditional Programs using @command{configure} Substitutions
4978
4979 @vindex EXTRA_PROGRAMS
4980 @cindex @code{EXTRA_PROGRAMS}, defined
4981 In this case, you must notify Automake of all the programs that can
4982 possibly be built, but at the same time cause the generated
4983 @file{Makefile.in} to use the programs specified by @command{configure}.
4984 This is done by having @command{configure} substitute values into each
4985 @code{_PROGRAMS} definition, while listing all optionally built programs
4986 in @code{EXTRA_PROGRAMS}.
4987
4988 @example
4989 bin_PROGRAMS = cpio pax $(MT)
4990 libexec_PROGRAMS = $(RMT)
4991 EXTRA_PROGRAMS = mt rmt
4992 @end example
4993
4994 As explained in @ref{EXEEXT}, Automake will rewrite
4995 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4996 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4997 Obviously it cannot rewrite values obtained at run-time through
4998 @command{configure} substitutions, therefore you should take care of
4999 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
5000 ['mt$@{EXEEXT@}'])}.
5001
5002 @subsubheading Conditional Programs using Automake Conditionals
5003
5004 You can also use Automake conditionals (@pxref{Conditionals}) to
5005 select programs to be built.  In this case you don't have to worry
5006 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
5007
5008 @c Keep in sync with exeext.test.
5009 @example
5010 bin_PROGRAMS = cpio pax
5011 if WANT_MT
5012   bin_PROGRAMS += mt
5013 endif
5014 if WANT_RMT
5015   libexec_PROGRAMS = rmt
5016 endif
5017 @end example
5018
5019
5020 @node A Library
5021 @section Building a library
5022
5023 @cindex @code{_LIBRARIES} primary, defined
5024 @cindex @code{LIBRARIES} primary, defined
5025 @cindex Primary variable, @code{LIBRARIES}
5026 @vindex _LIBRARIES
5027
5028 @vindex lib_LIBRARIES
5029 @vindex pkglib_LIBRARIES
5030 @vindex noinst_LIBRARIES
5031
5032 Building a library is much like building a program.  In this case, the
5033 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
5034 @code{libdir} or @code{pkglibdir}.
5035
5036 @xref{A Shared Library}, for information on how to build shared
5037 libraries using libtool and the @code{LTLIBRARIES} primary.
5038
5039 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
5040 For instance, to create a library named @file{libcpio.a}, but not install
5041 it, you would write:
5042
5043 @example
5044 noinst_LIBRARIES = libcpio.a
5045 libcpio_a_SOURCES = @dots{}
5046 @end example
5047
5048 The sources that go into a library are determined exactly as they are
5049 for programs, via the @code{_SOURCES} variables.  Note that the library
5050 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
5051 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
5052 not @samp{libcpio.a_SOURCES}.
5053
5054 @vindex maude_LIBADD
5055 Extra objects can be added to a library using the
5056 @code{@var{library}_LIBADD} variable.  This should be used for objects
5057 determined by @command{configure}.  Again from @code{cpio}:
5058
5059 @c Keep in sync with pr401c.test.
5060 @example
5061 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5062 @end example
5063
5064 In addition, sources for extra objects that will not exist until
5065 configure-time must be added to the @code{BUILT_SOURCES} variable
5066 (@pxref{Sources}).
5067
5068 Building a static library is done by compiling all object files, then
5069 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
5070 library and the list of objects, and finally by calling
5071 @samp{$(RANLIB)} on that library.  You should call
5072 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
5073 @code{RANLIB} (Automake will complain otherwise).  You should also
5074 call @code{AM_PROG_AR} to define @code{AR}, in order to support unusual
5075 archivers such as Microsoft lib.  @code{ARFLAGS} will default to
5076 @code{cru}; you can override this variable by setting it in your
5077 @file{Makefile.am} or by @code{AC_SUBST}ing it from your
5078 @file{configure.ac}.  You can override the @code{AR} variable by
5079 defining a per-library @code{maude_AR} variable (@pxref{Program and
5080 Library Variables}).
5081
5082 @cindex Empty libraries
5083 Be careful when selecting library components conditionally.  Because
5084 building an empty library is not portable, you should ensure that any
5085 library always contains at least one object.
5086
5087 To use a static library when building a program, add it to
5088 @code{LDADD} for this program.  In the following example, the program
5089 @file{cpio} is statically linked with the library @file{libcpio.a}.
5090
5091 @example
5092 noinst_LIBRARIES = libcpio.a
5093 libcpio_a_SOURCES = @dots{}
5094
5095 bin_PROGRAMS = cpio
5096 cpio_SOURCES = cpio.c @dots{}
5097 cpio_LDADD = libcpio.a
5098 @end example
5099
5100
5101 @node A Shared Library
5102 @section Building a Shared Library
5103
5104 @cindex Shared libraries, support for
5105
5106 Building shared libraries portably is a relatively complex matter.
5107 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5108 Libtool Manual}) was created to help build shared libraries in a
5109 platform-independent way.
5110
5111 @menu
5112 * Libtool Concept::             Introducing Libtool
5113 * Libtool Libraries::           Declaring Libtool Libraries
5114 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
5115 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
5116 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
5117 * Libtool Modules::             Building Libtool Modules
5118 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5119 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
5120 * Libtool Issues::              Common Issues Related to Libtool's Use
5121 @end menu
5122
5123 @node Libtool Concept
5124 @subsection The Libtool Concept
5125
5126 @cindex @command{libtool}, introduction
5127 @cindex libtool library, definition
5128 @cindex suffix @file{.la}, defined
5129 @cindex @file{.la} suffix, defined
5130
5131 Libtool abstracts shared and static libraries into a unified concept
5132 henceforth called @dfn{libtool libraries}.  Libtool libraries are
5133 files using the @file{.la} suffix, and can designate a static library,
5134 a shared library, or maybe both.  Their exact nature cannot be
5135 determined until @file{./configure} is run: not all platforms support
5136 all kinds of libraries, and users can explicitly select which
5137 libraries should be built.  (However the package's maintainers can
5138 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
5139 macro, libtool, The Libtool Manual}.)
5140
5141 @cindex suffix @file{.lo}, defined
5142 Because object files for shared and static libraries must be compiled
5143 differently, libtool is also used during compilation.  Object files
5144 built by libtool are called @dfn{libtool objects}: these are files
5145 using the @file{.lo} suffix.  Libtool libraries are built from these
5146 libtool objects.
5147
5148 You should not assume anything about the structure of @file{.la} or
5149 @file{.lo} files and how libtool constructs them: this is libtool's
5150 concern, and the last thing one wants is to learn about libtool's
5151 guts.  However the existence of these files matters, because they are
5152 used as targets and dependencies in @file{Makefile}s rules when
5153 building libtool libraries.  There are situations where you may have
5154 to refer to these, for instance when expressing dependencies for
5155 building source files conditionally (@pxref{Conditional Libtool
5156 Sources}).
5157
5158 @cindex @file{libltdl}, introduction
5159
5160 People considering writing a plug-in system, with dynamically loaded
5161 modules, should look into @file{libltdl}: libtool's dlopening library
5162 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5163 This offers a portable dlopening facility to load libtool libraries
5164 dynamically, and can also achieve static linking where unavoidable.
5165
5166 Before we discuss how to use libtool with Automake in details, it
5167 should be noted that the libtool manual also has a section about how
5168 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5169 with Libtool, libtool, The Libtool Manual}).
5170
5171 @node Libtool Libraries
5172 @subsection Building Libtool Libraries
5173
5174 @cindex @code{_LTLIBRARIES} primary, defined
5175 @cindex @code{LTLIBRARIES} primary, defined
5176 @cindex Primary variable, @code{LTLIBRARIES}
5177 @cindex Example of shared libraries
5178 @vindex lib_LTLIBRARIES
5179 @vindex pkglib_LTLIBRARIES
5180 @vindex _LTLIBRARIES
5181
5182 Automake uses libtool to build libraries declared with the
5183 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5184 list of libtool libraries to build.  For instance, to create a libtool
5185 library named @file{libgettext.la}, and install it in @code{libdir},
5186 write:
5187
5188 @example
5189 lib_LTLIBRARIES = libgettext.la
5190 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5191 @end example
5192
5193 Automake predefines the variable @code{pkglibdir}, so you can use
5194 @code{pkglib_LTLIBRARIES} to install libraries in
5195 @samp{$(libdir)/@@PACKAGE@@/}.
5196
5197 If @file{gettext.h} is a public header file that needs to be installed
5198 in order for people to use the library, it should be declared using a
5199 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5200 Headers listed in the latter should be internal headers that are not
5201 part of the public interface.
5202
5203 @example
5204 lib_LTLIBRARIES = libgettext.la
5205 libgettext_la_SOURCES = gettext.c @dots{}
5206 include_HEADERS = gettext.h @dots{}
5207 @end example
5208
5209 A package can build and install such a library along with other
5210 programs that use it.  This dependency should be specified using
5211 @code{LDADD}.  The following example builds a program named
5212 @file{hello} that is linked with @file{libgettext.la}.
5213
5214 @example
5215 lib_LTLIBRARIES = libgettext.la
5216 libgettext_la_SOURCES = gettext.c @dots{}
5217
5218 bin_PROGRAMS = hello
5219 hello_SOURCES = hello.c @dots{}
5220 hello_LDADD = libgettext.la
5221 @end example
5222
5223 @noindent
5224 Whether @file{hello} is statically or dynamically linked with
5225 @file{libgettext.la} is not yet known: this will depend on the
5226 configuration of libtool and the capabilities of the host.
5227
5228
5229 @node Conditional Libtool Libraries
5230 @subsection Building Libtool Libraries Conditionally
5231 @cindex libtool libraries, conditional
5232 @cindex conditional libtool libraries
5233
5234 Like conditional programs (@pxref{Conditional Programs}), there are
5235 two main ways to build conditional libraries: using Automake
5236 conditionals or using Autoconf @code{AC_SUBST}itutions.
5237
5238 The important implementation detail you have to be aware of is that
5239 the place where a library will be installed matters to libtool: it
5240 needs to be indicated @emph{at link-time} using the @option{-rpath}
5241 option.
5242
5243 For libraries whose destination directory is known when Automake runs,
5244 Automake will automatically supply the appropriate @option{-rpath}
5245 option to libtool.  This is the case for libraries listed explicitly in
5246 some installable @code{_LTLIBRARIES} variables such as
5247 @code{lib_LTLIBRARIES}.
5248
5249 However, for libraries determined at configure time (and thus
5250 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5251 final installation directory.  For such libraries you must add the
5252 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5253 hand.
5254
5255 The examples below illustrate the differences between these two methods.
5256
5257 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5258 variable set at @file{./configure}-time to either @file{libfoo.la},
5259 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5260 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5261 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5262 the link rule for these two libraries.  Therefore the @option{-rpath}
5263 argument must be explicitly supplied.
5264
5265 @c Keep in sync with ltcond.test.
5266 @example
5267 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5268 lib_LTLIBRARIES = $(WANTEDLIBS)
5269 libfoo_la_SOURCES = foo.c @dots{}
5270 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5271 libbar_la_SOURCES = bar.c @dots{}
5272 libbar_la_LDFLAGS = -rpath '$(libdir)'
5273 @end example
5274
5275 Here is how the same @file{Makefile.am} would look using Automake
5276 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5277 Automake is able to compute the @option{-rpath} setting itself, because
5278 it's clear that both libraries will end up in @samp{$(libdir)} if they
5279 are installed.
5280
5281 @c Keep in sync with ltcond.test.
5282 @example
5283 lib_LTLIBRARIES =
5284 if WANT_LIBFOO
5285 lib_LTLIBRARIES += libfoo.la
5286 endif
5287 if WANT_LIBBAR
5288 lib_LTLIBRARIES += libbar.la
5289 endif
5290 libfoo_la_SOURCES = foo.c @dots{}
5291 libbar_la_SOURCES = bar.c @dots{}
5292 @end example
5293
5294 @node Conditional Libtool Sources
5295 @subsection Libtool Libraries with Conditional Sources
5296
5297 Conditional compilation of sources in a library can be achieved in the
5298 same way as conditional compilation of sources in a program
5299 (@pxref{Conditional Sources}).  The only difference is that
5300 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5301 should mention libtool objects (@file{.lo} files).
5302
5303 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5304 we could build a @file{libhello.la} library using either
5305 @file{hello-linux.c} or @file{hello-generic.c} with the following
5306 @file{Makefile.am}.
5307
5308 @c Keep in sync with ltcond2.test.
5309 @example
5310 lib_LTLIBRARIES = libhello.la
5311 libhello_la_SOURCES = hello-common.c
5312 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5313 libhello_la_LIBADD = $(HELLO_SYSTEM)
5314 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5315 @end example
5316
5317 @noindent
5318 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5319 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5320
5321 Or we could simply use an Automake conditional as follows.
5322
5323 @c Keep in sync with ltcond2.test.
5324 @example
5325 lib_LTLIBRARIES = libhello.la
5326 libhello_la_SOURCES = hello-common.c
5327 if LINUX
5328 libhello_la_SOURCES += hello-linux.c
5329 else
5330 libhello_la_SOURCES += hello-generic.c
5331 endif
5332 @end example
5333
5334 @node Libtool Convenience Libraries
5335 @subsection Libtool Convenience Libraries
5336 @cindex convenience libraries, libtool
5337 @cindex libtool convenience libraries
5338 @vindex noinst_LTLIBRARIES
5339 @vindex check_LTLIBRARIES
5340
5341 Sometimes you want to build libtool libraries that should not be
5342 installed.  These are called @dfn{libtool convenience libraries} and
5343 are typically used to encapsulate many sublibraries, later gathered
5344 into one big installed library.
5345
5346 Libtool convenience libraries are declared by directory-less variables
5347 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5348 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5349 not need an @option{-rpath} flag at link time (actually this is the only
5350 difference).
5351
5352 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5353 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5354 @samp{make check}.  Finally, libraries listed in
5355 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5356 rules to build them, but if the library does not appear as a Makefile
5357 dependency anywhere it won't be built (this is why
5358 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5359
5360 Here is a sample setup merging libtool convenience libraries from
5361 subdirectories into one main @file{libtop.la} library.
5362
5363 @c Keep in sync with ltconv.test.
5364 @example
5365 # -- Top-level Makefile.am --
5366 SUBDIRS = sub1 sub2 @dots{}
5367 lib_LTLIBRARIES = libtop.la
5368 libtop_la_SOURCES =
5369 libtop_la_LIBADD = \
5370   sub1/libsub1.la \
5371   sub2/libsub2.la \
5372   @dots{}
5373
5374 # -- sub1/Makefile.am --
5375 noinst_LTLIBRARIES = libsub1.la
5376 libsub1_la_SOURCES = @dots{}
5377
5378 # -- sub2/Makefile.am --
5379 # showing nested convenience libraries
5380 SUBDIRS = sub2.1 sub2.2 @dots{}
5381 noinst_LTLIBRARIES = libsub2.la
5382 libsub2_la_SOURCES =
5383 libsub2_la_LIBADD = \
5384   sub21/libsub21.la \
5385   sub22/libsub22.la \
5386   @dots{}
5387 @end example
5388
5389 When using such setup, beware that @command{automake} will assume
5390 @file{libtop.la} is to be linked with the C linker.  This is because
5391 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5392 default language.  If @code{libtop_la_SOURCES} was not empty,
5393 @command{automake} would select the linker as explained in @ref{How
5394 the Linker is Chosen}.
5395
5396 If one of the sublibraries contains non-C source, it is important that
5397 the appropriate linker be chosen.  One way to achieve this is to
5398 pretend that there is such a non-C file among the sources of the
5399 library, thus forcing @command{automake} to select the appropriate
5400 linker.  Here is the top-level @file{Makefile} of our example updated
5401 to force C++ linking.
5402
5403 @example
5404 SUBDIRS = sub1 sub2 @dots{}
5405 lib_LTLIBRARIES = libtop.la
5406 libtop_la_SOURCES =
5407 # Dummy C++ source to cause C++ linking.
5408 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5409 libtop_la_LIBADD = \
5410   sub1/libsub1.la \
5411   sub2/libsub2.la \
5412   @dots{}
5413 @end example
5414
5415 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5416 files that might be compiled (this is mostly useful when doing
5417 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5418 Libtool Sources}), and the @code{nodist_} prefix means the listed
5419 sources are not to be distributed (@pxref{Program and Library
5420 Variables}).  In effect the file @file{dummy.cxx} does not need to
5421 exist in the source tree.  Of course if you have some real source file
5422 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5423 @code{nodist_EXTRA_libtop_la_SOURCES}.
5424
5425
5426 @node Libtool Modules
5427 @subsection Libtool Modules
5428 @cindex modules, libtool
5429 @cindex libtool modules
5430 @cindex @option{-module}, libtool
5431
5432 These are libtool libraries meant to be dlopened.  They are
5433 indicated to libtool by passing @option{-module} at link-time.
5434
5435 @example
5436 pkglib_LTLIBRARIES = mymodule.la
5437 mymodule_la_SOURCES = doit.c
5438 mymodule_la_LDFLAGS = -module
5439 @end example
5440
5441 Ordinarily, Automake requires that a library's name start with
5442 @code{lib}.  However, when building a dynamically loadable module you
5443 might wish to use a "nonstandard" name.  Automake will not complain
5444 about such nonstandard names if it knows the library being built is a
5445 libtool module, i.e., if @option{-module} explicitly appears in the
5446 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5447 variable when no per-library @code{_LDFLAGS} variable is defined).
5448
5449 As always, @code{AC_SUBST} variables are black boxes to Automake since
5450 their values are not yet known when @command{automake} is run.
5451 Therefore if @option{-module} is set via such a variable, Automake
5452 cannot notice it and will proceed as if the library was an ordinary
5453 libtool library, with strict naming.
5454
5455 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5456 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5457
5458 @node Libtool Flags
5459 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5460 @cindex @code{_LIBADD}, libtool
5461 @cindex @code{_LDFLAGS}, libtool
5462 @cindex @code{_LIBTOOLFLAGS}, libtool
5463 @vindex AM_LIBTOOLFLAGS
5464 @vindex LIBTOOLFLAGS
5465 @vindex maude_LIBTOOLFLAGS
5466
5467 As shown in previous sections, the @samp{@var{library}_LIBADD}
5468 variable should be used to list extra libtool objects (@file{.lo}
5469 files) or libtool libraries (@file{.la}) to add to @var{library}.
5470
5471 The @samp{@var{library}_LDFLAGS} variable is the place to list
5472 additional libtool linking flags, such as @option{-version-info},
5473 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5474 libtool, The Libtool Manual}.
5475
5476 The @command{libtool} command has two kinds of options: mode-specific
5477 options and generic options.  Mode-specific options such as the
5478 aforementioned linking flags should be lumped with the other flags
5479 passed to the tool invoked by @command{libtool} (hence the use of
5480 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5481 options include @option{--tag=@var{tag}} and @option{--silent}
5482 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5483 Libtool Manual} for more options) should appear before the mode
5484 selection on the command line; in @file{Makefile.am}s they should
5485 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5486
5487 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5488 @code{AM_LIBTOOLFLAGS} is used instead.
5489
5490 These flags are passed to libtool after the @option{--tag=@var{tag}}
5491 option computed by Automake (if any), so
5492 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5493 good place to override or supplement the @option{--tag=@var{tag}}
5494 setting.
5495
5496 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5497 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5498 Variables Ordering}.  It allows users to run @samp{make
5499 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5500 @command{libtool} can also be influenced with the Automake
5501 @option{silent-rules} option (@pxref{Options}).
5502
5503
5504 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5505 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5506 @cindex @code{LTLIBOBJS}, special handling
5507 @cindex @code{LIBOBJS}, and Libtool
5508 @cindex @code{LTALLOCA}, special handling
5509 @cindex @code{ALLOCA}, and Libtool
5510 @vindex LTLIBOBJS
5511 @vindex LIBOBJS
5512 @vindex LTALLOCA
5513 @vindex ALLOCA
5514 @acindex AC_LIBOBJ
5515
5516 Where an ordinary library might include @samp{$(LIBOBJS)} or
5517 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5518 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5519 the object files that libtool operates on do not necessarily end in
5520 @file{.o}.
5521
5522 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5523 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5524 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5525
5526 @node Libtool Issues
5527 @subsection Common Issues Related to Libtool's Use
5528
5529 @menu
5530 * Error required file ltmain.sh not found::  The need to run libtoolize
5531 * Objects created both with libtool and without::  Avoid a specific build race
5532 @end menu
5533
5534 @node Error required file ltmain.sh not found
5535 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5536 @cindex @file{ltmain.sh} not found
5537 @cindex @command{libtoolize}, no longer run by @command{automake}
5538 @cindex @command{libtoolize} and @command{autoreconf}
5539 @cindex @command{autoreconf} and @command{libtoolize}
5540 @cindex @file{bootstrap.sh} and @command{autoreconf}
5541 @cindex @file{autogen.sh} and @command{autoreconf}
5542
5543 Libtool comes with a tool called @command{libtoolize} that will
5544 install libtool's supporting files into a package.  Running this
5545 command will install @file{ltmain.sh}.  You should execute it before
5546 @command{aclocal} and @command{automake}.
5547
5548 People upgrading old packages to newer autotools are likely to face
5549 this issue because older Automake versions used to call
5550 @command{libtoolize}.  Therefore old build scripts do not call
5551 @command{libtoolize}.
5552
5553 Since Automake 1.6, it has been decided that running
5554 @command{libtoolize} was none of Automake's business.  Instead, that
5555 functionality has been moved into the @command{autoreconf} command
5556 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5557 The Autoconf Manual}).  If you do not want to remember what to run and
5558 when, just learn the @command{autoreconf} command.  Hopefully,
5559 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5560 a call to @command{autoreconf} should also free you from any similar
5561 incompatible change in the future.
5562
5563 @node Objects created both with libtool and without
5564 @subsubsection Objects @samp{created with both libtool and without}
5565
5566 Sometimes, the same source file is used both to build a libtool
5567 library and to build another non-libtool target (be it a program or
5568 another library).
5569
5570 Let's consider the following @file{Makefile.am}.
5571
5572 @example
5573 bin_PROGRAMS = prog
5574 prog_SOURCES = prog.c foo.c @dots{}
5575
5576 lib_LTLIBRARIES = libfoo.la
5577 libfoo_la_SOURCES = foo.c @dots{}
5578 @end example
5579
5580 @noindent
5581 (In this trivial case the issue could be avoided by linking
5582 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5583 @code{prog_SOURCES}.  But let's assume we really want to keep
5584 @file{prog} and @file{libfoo.la} separate.)
5585
5586 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5587 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5588 that in the course of creating @file{foo.lo}, libtool may erase (or
5589 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5590
5591 Therefore, when Automake detects this situation it will complain
5592 with a message such as
5593 @example
5594 object `foo.$(OBJEXT)' created both with libtool and without
5595 @end example
5596
5597 A workaround for this issue is to ensure that these two objects get
5598 different basenames.  As explained in @ref{Renamed Objects}, this
5599 happens automatically when per-targets flags are used.
5600
5601 @example
5602 bin_PROGRAMS = prog
5603 prog_SOURCES = prog.c foo.c @dots{}
5604 prog_CFLAGS = $(AM_CFLAGS)
5605
5606 lib_LTLIBRARIES = libfoo.la
5607 libfoo_la_SOURCES = foo.c @dots{}
5608 @end example
5609
5610 @noindent
5611 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5612 when the @code{prog_CFLAGS} is defined, it is used instead of
5613 @code{AM_CFLAGS}.  However as a side effect it will cause
5614 @file{prog.c} and @file{foo.c} to be compiled as
5615 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5616 the issue.
5617
5618 @node Program and Library Variables
5619 @section Program and Library Variables
5620
5621 Associated with each program is a collection of variables that can be
5622 used to modify how that program is built.  There is a similar list of
5623 such variables for each library.  The canonical name of the program (or
5624 library) is used as a base for naming these variables.
5625
5626 In the list below, we use the name ``maude'' to refer to the program or
5627 library.  In your @file{Makefile.am} you would replace this with the
5628 canonical name of your program.  This list also refers to ``maude'' as a
5629 program, but in general the same rules apply for both static and dynamic
5630 libraries; the documentation below notes situations where programs and
5631 libraries differ.
5632
5633 @vtable @code
5634 @item maude_SOURCES
5635 This variable, if it exists, lists all the source files that are
5636 compiled to build the program.  These files are added to the
5637 distribution by default.  When building the program, Automake will cause
5638 each source file to be compiled to a single @file{.o} file (or
5639 @file{.lo} when using libtool).  Normally these object files are named
5640 after the source file, but other factors can change this.  If a file in
5641 the @code{_SOURCES} variable has an unrecognized extension, Automake
5642 will do one of two things with it.  If a suffix rule exists for turning
5643 files with the unrecognized extension into @file{.o} files, then
5644 @command{automake} will treat this file as it will any other source file
5645 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5646 ignored as though it were a header file.
5647
5648 The prefixes @code{dist_} and @code{nodist_} can be used to control
5649 whether files listed in a @code{_SOURCES} variable are distributed.
5650 @code{dist_} is redundant, as sources are distributed by default, but it
5651 can be specified for clarity if desired.
5652
5653 It is possible to have both @code{dist_} and @code{nodist_} variants of
5654 a given @code{_SOURCES} variable at once; this lets you easily
5655 distribute some files and not others, for instance:
5656
5657 @example
5658 nodist_maude_SOURCES = nodist.c
5659 dist_maude_SOURCES = dist-me.c
5660 @end example
5661
5662 By default the output file (on Unix systems, the @file{.o} file) will
5663 be put into the current build directory.  However, if the option
5664 @option{subdir-objects} is in effect in the current directory then the
5665 @file{.o} file will be put into the subdirectory named after the
5666 source file.  For instance, with @option{subdir-objects} enabled,
5667 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5668 people prefer this mode of operation.  You can specify
5669 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5670 @cindex Subdirectory, objects in
5671 @cindex Objects in subdirectory
5672
5673
5674 @item EXTRA_maude_SOURCES
5675 Automake needs to know the list of files you intend to compile
5676 @emph{statically}.  For one thing, this is the only way Automake has of
5677 knowing what sort of language support a given @file{Makefile.in}
5678 requires.  @footnote{There are other, more obscure reasons for
5679 this limitation as well.}  This means that, for example, you can't put a
5680 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5681 variable.  If you intend to conditionally compile source files and use
5682 @file{configure} to substitute the appropriate object names into, e.g.,
5683 @code{_LDADD} (see below), then you should list the corresponding source
5684 files in the @code{EXTRA_} variable.
5685
5686 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5687 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5688 sources that may need to be built, but should not be distributed.
5689
5690 @item maude_AR
5691 A static library is created by default by invoking @samp{$(AR)
5692 $(ARFLAGS)} followed by the name of the library and then the objects
5693 being put into the library.  You can override this by setting the
5694 @code{_AR} variable.  This is usually used with C++; some C++
5695 compilers require a special invocation in order to instantiate all the
5696 templates that should go into a library.  For instance, the SGI C++
5697 compiler likes this variable set like so:
5698 @example
5699 libmaude_a_AR = $(CXX) -ar -o
5700 @end example
5701
5702 @item maude_LIBADD
5703 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5704 variable.  For instance, this should be used for objects determined by
5705 @command{configure} (@pxref{A Library}).
5706
5707 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5708 to other libtool libraries.
5709
5710 @item maude_LDADD
5711 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5712 @file{*.la}) can be added to a @emph{program} by listing them in the
5713 @code{_LDADD} variable.  For instance, this should be used for objects
5714 determined by @command{configure} (@pxref{Linking}).
5715
5716 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5717 program-specific linker flags (except for @option{-l}, @option{-L},
5718 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5719 for this purpose.
5720
5721 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5722 could link your program against the X libraries like so:
5723
5724 @example
5725 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5726 @end example
5727
5728 We recommend that you use @option{-l} and @option{-L} only when
5729 referring to third-party libraries, and give the explicit file names
5730 of any library built by your package.  Doing so will ensure that
5731 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5732
5733 @item maude_LDFLAGS
5734 This variable is used to pass extra flags to the link step of a program
5735 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5736
5737 @item maude_LIBTOOLFLAGS
5738 This variable is used to pass extra options to @command{libtool}.
5739 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5740 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5741 option, so they should not be mode-specific options (those belong to
5742 the compiler or linker flags).  @xref{Libtool Flags}.
5743
5744 @item maude_DEPENDENCIES
5745 @itemx EXTRA_maude_DEPENDENCIES
5746 It is also occasionally useful to have a target (program or library)
5747 depend on some other file that is not actually part of that target.
5748 This can be done using the @code{_DEPENDENCIES} variable.  Each
5749 target depends on the contents of such a variable, but no further
5750 interpretation is done.
5751
5752 Since these dependencies are associated to the link rule used to
5753 create the programs they should normally list files used by the link
5754 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5755 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5756 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5757 may need to add other kinds of files such as linker scripts, but
5758 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5759 some source file needs to be built before all the components of a
5760 program are built, consider using the @code{BUILT_SOURCES} variable
5761 (@pxref{Sources}).
5762
5763 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5764 The automatically-assigned value is the contents of @code{_LDADD} or
5765 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5766 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5767 substitutions that are left in are only @samp{$(LIBOBJS)} and
5768 @samp{$(ALLOCA)}; these are left because it is known that they will not
5769 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5770
5771 @code{_DEPENDENCIES} is more likely used to perform conditional
5772 compilation using an @code{AC_SUBST} variable that contains a list of
5773 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5774 Sources}.
5775
5776 The @code{EXTRA_*_DEPENDENCIES} variable may be useful for cases where
5777 you merely want to augment the @command{automake}-generated
5778 @code{_DEPENDENCIES} variable rather than replacing it.
5779
5780 @item maude_LINK
5781 You can override the linker on a per-program basis.  By default the
5782 linker is chosen according to the languages used by the program.  For
5783 instance, a program that includes C++ source code would use the C++
5784 compiler to link.  The @code{_LINK} variable must hold the name of a
5785 command that can be passed all the @file{.o} file names and libraries
5786 to link against as arguments.  Note that the name of the underlying
5787 program is @emph{not} passed to @code{_LINK}; typically one uses
5788 @samp{$@@}:
5789
5790 @example
5791 maude_LINK = $(CCLD) -magic -o $@@
5792 @end example
5793
5794 If a @code{_LINK} variable is not supplied, it may still be generated
5795 and used by Automake due to the use of per-target link flags such as
5796 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5797 they apply.
5798
5799 @item maude_CCASFLAGS
5800 @itemx maude_CFLAGS
5801 @itemx maude_CPPFLAGS
5802 @itemx maude_CXXFLAGS
5803 @itemx maude_FFLAGS
5804 @itemx maude_GCJFLAGS
5805 @itemx maude_LFLAGS
5806 @itemx maude_OBJCFLAGS
5807 @itemx maude_RFLAGS
5808 @itemx maude_UPCFLAGS
5809 @itemx maude_YFLAGS
5810 @cindex per-target compilation flags, defined
5811 Automake allows you to set compilation flags on a per-program (or
5812 per-library) basis.  A single source file can be included in several
5813 programs, and it will potentially be compiled with different flags for
5814 each program.  This works for any language directly supported by
5815 Automake.  These @dfn{per-target compilation flags} are
5816 @samp{_CCASFLAGS},
5817 @samp{_CFLAGS},
5818 @samp{_CPPFLAGS},
5819 @samp{_CXXFLAGS},
5820 @samp{_FFLAGS},
5821 @samp{_GCJFLAGS},
5822 @samp{_LFLAGS},
5823 @samp{_OBJCFLAGS},
5824 @samp{_RFLAGS},
5825 @samp{_UPCFLAGS}, and
5826 @samp{_YFLAGS}.
5827
5828 When using a per-target compilation flag, Automake will choose a
5829 different name for the intermediate object files.  Ordinarily a file
5830 like @file{sample.c} will be compiled to produce @file{sample.o}.
5831 However, if the program's @code{_CFLAGS} variable is set, then the
5832 object file will be named, for instance, @file{maude-sample.o}.  (See
5833 also @ref{Renamed Objects}.)  The use of per-target compilation flags
5834 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5835 from @file{configure.ac}.
5836
5837 In compilations with per-target flags, the ordinary @samp{AM_} form of
5838 the flags variable is @emph{not} automatically included in the
5839 compilation (however, the user form of the variable @emph{is} included).
5840 So for instance, if you want the hypothetical @file{maude} compilations
5841 to also use the value of @code{AM_CFLAGS}, you would need to write:
5842
5843 @example
5844 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5845 @end example
5846
5847 @xref{Flag Variables Ordering}, for more discussion about the
5848 interaction between user variables, @samp{AM_} shadow variables, and
5849 per-target variables.
5850
5851 @item maude_SHORTNAME
5852 On some platforms the allowable file names are very short.  In order to
5853 support these systems and per-target compilation flags at the same
5854 time, Automake allows you to set a ``short name'' that will influence
5855 how intermediate object files are named.  For instance, in the following
5856 example,
5857
5858 @example
5859 bin_PROGRAMS = maude
5860 maude_CPPFLAGS = -DSOMEFLAG
5861 maude_SHORTNAME = m
5862 maude_SOURCES = sample.c @dots{}
5863 @end example
5864
5865 @noindent
5866 the object file would be named @file{m-sample.o} rather than
5867 @file{maude-sample.o}.
5868
5869 This facility is rarely needed in practice,
5870 and we recommend avoiding it until you find it is required.
5871 @end vtable
5872
5873 @node Default _SOURCES
5874 @section Default @code{_SOURCES}
5875
5876 @vindex _SOURCES
5877 @vindex SOURCES
5878 @cindex @code{_SOURCES}, default
5879 @cindex default @code{_SOURCES}
5880 @vindex AM_DEFAULT_SOURCE_EXT
5881
5882 @code{_SOURCES} variables are used to specify source files of programs
5883 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5884 libraries (@pxref{A Shared Library}).
5885
5886 When no such variable is specified for a target, Automake will define
5887 one itself.  The default is to compile a single C file whose base name
5888 is the name of the target itself, with any extension replaced by
5889 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5890
5891 For example if you have the following somewhere in your
5892 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5893
5894 @example
5895 lib_LIBRARIES = libfoo.a sub/libc++.a
5896 @end example
5897
5898 @noindent
5899 @file{libfoo.a} will be built using a default source file named
5900 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5901 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5902 would be built from @file{sub_libc___a.c}, i.e., the default source
5903 was the canonized name of the target, with @file{.c} appended.
5904 We believe the new behavior is more sensible, but for backward
5905 compatibility @command{automake} will use the old name if a file or a rule
5906 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5907
5908 @cindex @code{check_PROGRAMS} example
5909 @vindex check_PROGRAMS
5910 Default sources are mainly useful in test suites, when building many
5911 test programs each from a single source.  For instance, in
5912
5913 @example
5914 check_PROGRAMS = test1 test2 test3
5915 AM_DEFAULT_SOURCE_EXT = .cpp
5916 @end example
5917
5918 @noindent
5919 @file{test1}, @file{test2}, and @file{test3} will be built
5920 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5921 Without the last line, they will be built from @file{test1.c},
5922 @file{test2.c}, and @file{test3.c}.
5923
5924 @cindex Libtool modules, default source example
5925 @cindex default source, Libtool modules example
5926 Another case where this is convenient is building many Libtool modules
5927 (@file{module@var{n}.la}), each defined in its own file
5928 (@file{module@var{n}.c}).
5929
5930 @example
5931 AM_LDFLAGS = -module
5932 lib_LTLIBRARIES = module1.la module2.la module3.la
5933 @end example
5934
5935 @cindex empty @code{_SOURCES}
5936 @cindex @code{_SOURCES}, empty
5937 Finally, there is one situation where this default source computation
5938 needs to be avoided: when a target should not be built from sources.
5939 We already saw such an example in @ref{true}; this happens when all
5940 the constituents of a target have already been compiled and just need
5941 to be combined using a @code{_LDADD} variable.  Then it is necessary
5942 to define an empty @code{_SOURCES} variable, so that @command{automake}
5943 does not compute a default.
5944
5945 @example
5946 bin_PROGRAMS = target
5947 target_SOURCES =
5948 target_LDADD = libmain.a libmisc.a
5949 @end example
5950
5951 @node LIBOBJS
5952 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5953
5954 @cindex @code{LIBOBJS}, example
5955 @cindex @code{ALLOCA}, example
5956 @cindex @code{LIBOBJS}, special handling
5957 @cindex @code{ALLOCA}, special handling
5958 @vindex LTLIBOBJS
5959 @vindex LIBOBJS
5960 @vindex LTALLOCA
5961 @vindex ALLOCA
5962
5963 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5964 files that should be compiled into the project to provide an
5965 implementation for functions that are missing or broken on the host
5966 system.  They are substituted by @file{configure}.
5967
5968 @acindex AC_LIBOBJ
5969
5970 These variables are defined by Autoconf macros such as
5971 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5972 Generic Function Checks, autoconf, The Autoconf Manual}), or
5973 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5974 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5975 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5976 populate @samp{$(LIBOBJS)}.
5977
5978 @acindex AC_LIBSOURCE
5979
5980 Using these variables is very similar to doing conditional compilation
5981 using @code{AC_SUBST} variables, as described in @ref{Conditional
5982 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5983 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5984 variable, or to the @samp{*_LIBADD} variable when building a library.
5985 However there is no need to list the corresponding sources in
5986 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5987 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5988 dependencies, and it will discover the list of corresponding source
5989 files automatically (by tracing the invocations of the
5990 @code{AC_LIBSOURCE} Autoconf macros).  If you have already defined
5991 @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then you
5992 either need to add these variables manually, or use
5993 @samp{EXTRA_*_DEPENDENCIES} instead of @samp{*_DEPENDENCIES}.
5994
5995 These variables are usually used to build a portability library that
5996 is linked with all the programs of the project.  We now review a
5997 sample setup.  First, @file{configure.ac} contains some checks that
5998 affect either @code{LIBOBJS} or @code{ALLOCA}.
5999
6000 @example
6001 # configure.ac
6002 @dots{}
6003 AC_CONFIG_LIBOBJ_DIR([lib])
6004 @dots{}
6005 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
6006 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
6007 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
6008 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
6009 @dots{}
6010 AC_CONFIG_FILES([
6011   lib/Makefile
6012   src/Makefile
6013 ])
6014 AC_OUTPUT
6015 @end example
6016
6017 @acindex AC_CONFIG_LIBOBJ_DIR
6018
6019 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
6020 of these object files are to be found in the @file{lib/} directory.
6021 Automake can also use this information, otherwise it expects the
6022 source files are to be in the directory where the @samp{$(LIBOBJS)}
6023 and @samp{$(ALLOCA)} variables are used.
6024
6025 The @file{lib/} directory should therefore contain @file{malloc.c},
6026 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
6027 @file{Makefile.am}:
6028
6029 @example
6030 # lib/Makefile.am
6031
6032 noinst_LIBRARIES = libcompat.a
6033 libcompat_a_SOURCES =
6034 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
6035 @end example
6036
6037 The library can have any name, of course, and anyway it is not going
6038 to be installed: it just holds the replacement versions of the missing
6039 or broken functions so we can later link them in.  Many projects
6040 also include extra functions, specific to the project, in that
6041 library: they are simply added on the @code{_SOURCES} line.
6042
6043 @cindex Empty libraries and @samp{$(LIBOBJS)}
6044 @cindex @samp{$(LIBOBJS)} and empty libraries
6045 There is a small trap here, though: @samp{$(LIBOBJS)} and
6046 @samp{$(ALLOCA)} might be empty, and building an empty library is not
6047 portable.  You should ensure that there is always something to put in
6048 @file{libcompat.a}.  Most projects will also add some utility
6049 functions in that directory, and list them in
6050 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
6051 be empty.
6052
6053 Finally here is how this library could be used from the @file{src/}
6054 directory.
6055
6056 @example
6057 # src/Makefile.am
6058
6059 # Link all programs in this directory with libcompat.a
6060 LDADD = ../lib/libcompat.a
6061
6062 bin_PROGRAMS = tool1 tool2 @dots{}
6063 tool1_SOURCES = @dots{}
6064 tool2_SOURCES = @dots{}
6065 @end example
6066
6067 When option @option{subdir-objects} is not used, as in the above
6068 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
6069 be used in the directory where their sources lie.  E.g., here it would
6070 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
6071 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
6072 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
6073 in other directories.  For instance @file{src/Makefile.am} could be
6074 changed as follows.
6075
6076 @example
6077 # src/Makefile.am
6078
6079 AUTOMAKE_OPTIONS = subdir-objects
6080 LDADD = $(LIBOBJS) $(ALLOCA)
6081
6082 bin_PROGRAMS = tool1 tool2 @dots{}
6083 tool1_SOURCES = @dots{}
6084 tool2_SOURCES = @dots{}
6085 @end example
6086
6087 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
6088 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
6089 Libtool libraries (where the expected object extension is @file{.lo}):
6090 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
6091
6092 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
6093 be defined by hand (as in the past), however at the time of writing
6094 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6095 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6096 autoconf, The Autoconf Manual}.
6097
6098
6099 @node Program Variables
6100 @section Variables used when building a program
6101
6102 Occasionally it is useful to know which @file{Makefile} variables
6103 Automake uses for compilations, and in which order (@pxref{Flag
6104 Variables Ordering}); for instance, you might need to do your own
6105 compilation in some special cases.
6106
6107 Some variables are inherited from Autoconf; these are @code{CC},
6108 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6109 @code{LIBS}.
6110 @vindex CC
6111 @vindex CFLAGS
6112 @vindex CPPFLAGS
6113 @vindex DEFS
6114 @vindex LDFLAGS
6115 @vindex LIBS
6116
6117 There are some additional variables that Automake defines on its own:
6118
6119 @vtable @code
6120 @item AM_CPPFLAGS
6121 The contents of this variable are passed to every compilation that invokes
6122 the C preprocessor; it is a list of arguments to the preprocessor.  For
6123 instance, @option{-I} and @option{-D} options should be listed here.
6124
6125 Automake already provides some @option{-I} options automatically, in a
6126 separate variable that is also passed to every compilation that invokes
6127 the C preprocessor.  In particular it generates @samp{-I.},
6128 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6129 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS} or
6130 @code{AM_CONFIG_HEADER}).  You can disable the default @option{-I}
6131 options using the @option{nostdinc} option.
6132
6133 When a file to be included is generated during the build and not part
6134 of a distribution tarball, its location is under @code{$(builddir)},
6135 not under @code{$(srcdir)}.  This matters especially for packages that
6136 use header files placed in sub-directories and want to allow builds
6137 outside the source tree (@pxref{VPATH Builds}). In that case we
6138 recommend to use a pair of @option{-I} options, such as, e.g.,
6139 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6140 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6141 Note that the reference to the build tree should come before the
6142 reference to the source tree, so that accidentally leftover generated
6143 files in the source directory are ignored.
6144
6145 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6146 per-library) @code{_CPPFLAGS} variable if it is defined.
6147
6148 @item INCLUDES
6149 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6150 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
6151 same functionality.  This variable is deprecated; we suggest using
6152 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6153
6154 @item AM_CFLAGS
6155 This is the variable the @file{Makefile.am} author can use to pass
6156 in additional C compiler flags.  It is more fully documented elsewhere.
6157 In some situations, this is not used, in preference to the
6158 per-executable (or per-library) @code{_CFLAGS}.
6159
6160 @item COMPILE
6161 This is the command used to actually compile a C source file.  The
6162 file name is appended to form the complete command line.
6163
6164 @item AM_LDFLAGS
6165 This is the variable the @file{Makefile.am} author can use to pass
6166 in additional linker flags.  In some situations, this is not used, in
6167 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6168
6169 @item LINK
6170 This is the command used to actually link a C program.  It already
6171 includes @samp{-o $@@} and the usual variable references (for instance,
6172 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
6173 and libraries to link in.  This variable is not used when the linker is
6174 overridden with a per-target @code{_LINK} variable or per-target flags
6175 cause Automake to define such a @code{_LINK} variable.
6176 @end vtable
6177
6178
6179 @node Yacc and Lex
6180 @section Yacc and Lex support
6181
6182 Automake has somewhat idiosyncratic support for Yacc and Lex.
6183
6184 Automake assumes that the @file{.c} file generated by @command{yacc}
6185 (or @command{lex}) should be named using the basename of the input
6186 file.  That is, for a yacc source file @file{foo.y}, Automake will
6187 cause the intermediate file to be named @file{foo.c} (as opposed to
6188 @file{y.tab.c}, which is more traditional).
6189
6190 The extension of a yacc source file is used to determine the extension
6191 of the resulting C or C++ source and header files.  Note that header
6192 files are generated only when the @option{-d} Yacc option is used; see
6193 below for more information about this flag, and how to specify it.
6194 Files with the extension @file{.y} will thus be turned into @file{.c}
6195 sources and @file{.h} headers; likewise, @file{.yy} will become
6196 @file{.cc} and @file{.hh}, @file{.y++} will become @file{c++} and
6197 @file{h++}, @file{.yxx} will become @file{.cxx} and @file{.hxx},
6198 and @file{.ypp} will become @file{.cpp} and @file{.hpp}.
6199
6200 Similarly, lex source files can be used to generate C or C++; the
6201 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6202 @file{.lpp} are recognized.
6203
6204 You should never explicitly mention the intermediate (C or C++) file
6205 in any @code{SOURCES} variable; only list the source file.
6206
6207 The intermediate files generated by @command{yacc} (or @command{lex})
6208 will be included in any distribution that is made.  That way the user
6209 doesn't need to have @command{yacc} or @command{lex}.
6210
6211 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6212 define the variable @code{YACC}.  This is most easily done by invoking
6213 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6214 Program Checks, autoconf, The Autoconf Manual}).
6215
6216 @vindex YFLAGS
6217 @vindex AM_YFLAGS
6218 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6219 @code{YFLAGS}.  The latter is a user variable and the former is
6220 intended for the @file{Makefile.am} author.
6221
6222 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6223 @command{yacc}.  Automake knows what this means and will automatically
6224 adjust its rules to update and distribute the header file built by
6225 @samp{yacc -d}@footnote{Please note that @command{automake} recognizes
6226 @option{-d} in @code{AM_YFLAGS} only if it is not clustered with other
6227 options; for example, it won't be recognized if @code{AM_YFLAGS} is
6228 @option{-dt}, but it will be if @code{AM_YFLAGS} is @option{-d -t} or
6229 @option{-d -t}}.
6230 What Automake cannot guess, though, is where this
6231 header will be used: it is up to you to ensure the header gets built
6232 before it is first used.  Typically this is necessary in order for
6233 dependency tracking to work when the header is included by another
6234 file.  The common solution is listing the header file in
6235 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6236
6237 @example
6238 BUILT_SOURCES = parser.h
6239 AM_YFLAGS = -d
6240 bin_PROGRAMS = foo
6241 foo_SOURCES = @dots{} parser.y @dots{}
6242 @end example
6243
6244 If a @command{lex} source file is seen, then your @file{configure.ac}
6245 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6246 to do this (@pxref{Particular Programs, , Particular Program Checks,
6247 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6248 (@pxref{Macros}) is recommended.
6249
6250 @vindex LFLAGS
6251 @vindex AM_LFLAGS
6252 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6253 @code{LFLAGS}.  The latter is a user variable and the former is
6254 intended for the @file{Makefile.am} author.
6255
6256 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6257 rebuild rule for distributed Yacc and Lex sources are only used when
6258 @code{maintainer-mode} is enabled, or when the files have been erased.
6259
6260 @cindex @command{ylwrap}
6261 @cindex @command{yacc}, multiple parsers
6262 @cindex Multiple @command{yacc} parsers
6263 @cindex Multiple @command{lex} lexers
6264 @cindex @command{lex}, multiple lexers
6265
6266 When @command{lex} or @command{yacc} sources are used, @code{automake
6267 -i} automatically installs an auxiliary program called
6268 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
6269 program is used by the build rules to rename the output of these
6270 tools, and makes it possible to include multiple @command{yacc} (or
6271 @command{lex}) source files in a single directory.  (This is necessary
6272 because yacc's output file name is fixed, and a parallel make could
6273 conceivably invoke more than one instance of @command{yacc}
6274 simultaneously.)
6275
6276 For @command{yacc}, simply managing locking is insufficient.  The output of
6277 @command{yacc} always uses the same symbol names internally, so it isn't
6278 possible to link two @command{yacc} parsers into the same executable.
6279
6280 We recommend using the following renaming hack used in @command{gdb}:
6281 @example
6282 #define yymaxdepth c_maxdepth
6283 #define yyparse c_parse
6284 #define yylex   c_lex
6285 #define yyerror c_error
6286 #define yylval  c_lval
6287 #define yychar  c_char
6288 #define yydebug c_debug
6289 #define yypact  c_pact
6290 #define yyr1    c_r1
6291 #define yyr2    c_r2
6292 #define yydef   c_def
6293 #define yychk   c_chk
6294 #define yypgo   c_pgo
6295 #define yyact   c_act
6296 #define yyexca  c_exca
6297 #define yyerrflag c_errflag
6298 #define yynerrs c_nerrs
6299 #define yyps    c_ps
6300 #define yypv    c_pv
6301 #define yys     c_s
6302 #define yy_yys  c_yys
6303 #define yystate c_state
6304 #define yytmp   c_tmp
6305 #define yyv     c_v
6306 #define yy_yyv  c_yyv
6307 #define yyval   c_val
6308 #define yylloc  c_lloc
6309 #define yyreds  c_reds
6310 #define yytoks  c_toks
6311 #define yylhs   c_yylhs
6312 #define yylen   c_yylen
6313 #define yydefred c_yydefred
6314 #define yydgoto  c_yydgoto
6315 #define yysindex c_yysindex
6316 #define yyrindex c_yyrindex
6317 #define yygindex c_yygindex
6318 #define yytable  c_yytable
6319 #define yycheck  c_yycheck
6320 #define yyname   c_yyname
6321 #define yyrule   c_yyrule
6322 @end example
6323
6324 For each define, replace the @samp{c_} prefix with whatever you like.
6325 These defines work for @command{bison}, @command{byacc}, and
6326 traditional @code{yacc}s.  If you find a parser generator that uses a
6327 symbol not covered here, please report the new name so it can be added
6328 to the list.
6329
6330
6331 @node C++ Support
6332 @section C++ Support
6333
6334 @cindex C++ support
6335 @cindex Support for C++
6336
6337 Automake includes full support for C++.
6338
6339 Any package including C++ code must define the output variable
6340 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6341 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6342 Program Checks, autoconf, The Autoconf Manual}).
6343
6344 A few additional variables are defined when a C++ source file is seen:
6345
6346 @vtable @code
6347 @item CXX
6348 The name of the C++ compiler.
6349
6350 @item CXXFLAGS
6351 Any flags to pass to the C++ compiler.
6352
6353 @item AM_CXXFLAGS
6354 The maintainer's variant of @code{CXXFLAGS}.
6355
6356 @item CXXCOMPILE
6357 The command used to actually compile a C++ source file.  The file name
6358 is appended to form the complete command line.
6359
6360 @item CXXLINK
6361 The command used to actually link a C++ program.
6362 @end vtable
6363
6364
6365 @node Objective C Support
6366 @section Objective C Support
6367
6368 @cindex Objective C support
6369 @cindex Support for Objective C
6370
6371 Automake includes some support for Objective C.
6372
6373 Any package including Objective C code must define the output variable
6374 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6375 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6376 Program Checks, autoconf, The Autoconf Manual}).
6377
6378 A few additional variables are defined when an Objective C source file
6379 is seen:
6380
6381 @vtable @code
6382 @item OBJC
6383 The name of the Objective C compiler.
6384
6385 @item OBJCFLAGS
6386 Any flags to pass to the Objective C compiler.
6387
6388 @item AM_OBJCFLAGS
6389 The maintainer's variant of @code{OBJCFLAGS}.
6390
6391 @item OBJCCOMPILE
6392 The command used to actually compile an Objective C source file.  The
6393 file name is appended to form the complete command line.
6394
6395 @item OBJCLINK
6396 The command used to actually link an Objective C program.
6397 @end vtable
6398
6399
6400 @node Unified Parallel C Support
6401 @section Unified Parallel C Support
6402
6403 @cindex Unified Parallel C support
6404 @cindex Support for Unified Parallel C
6405
6406 Automake includes some support for Unified Parallel C.
6407
6408 Any package including Unified Parallel C code must define the output
6409 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6410 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6411
6412 A few additional variables are defined when a Unified Parallel C
6413 source file is seen:
6414
6415 @vtable @code
6416 @item UPC
6417 The name of the Unified Parallel C compiler.
6418
6419 @item UPCFLAGS
6420 Any flags to pass to the Unified Parallel C compiler.
6421
6422 @item AM_UPCFLAGS
6423 The maintainer's variant of @code{UPCFLAGS}.
6424
6425 @item UPCCOMPILE
6426 The command used to actually compile a Unified Parallel C source file.
6427 The file name is appended to form the complete command line.
6428
6429 @item UPCLINK
6430 The command used to actually link a Unified Parallel C program.
6431 @end vtable
6432
6433
6434 @node Assembly Support
6435 @section Assembly Support
6436
6437 Automake includes some support for assembly code.  There are two forms
6438 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6439 (@file{*.S} or @file{*.sx}).
6440
6441 @vindex CCAS
6442 @vindex CCASFLAGS
6443 @vindex CPPFLAGS
6444 @vindex AM_CCASFLAGS
6445 @vindex AM_CPPFLAGS
6446 The variable @code{CCAS} holds the name of the compiler used to build
6447 assembly code.  This compiler must work a bit like a C compiler; in
6448 particular it must accept @option{-c} and @option{-o}.  The values of
6449 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6450 definition) is passed to the compilation.  For preprocessed files,
6451 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6452 and @code{AM_CPPFLAGS} are also used.
6453
6454 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6455 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6456 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6457 flags), but you are free to define these variables by other means.
6458
6459 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6460 @command{automake} as being files containing assembly code.
6461
6462
6463 @node Fortran 77 Support
6464 @comment  node-name,  next,  previous,  up
6465 @section Fortran 77 Support
6466
6467 @cindex Fortran 77 support
6468 @cindex Support for Fortran 77
6469
6470 Automake includes full support for Fortran 77.
6471
6472 Any package including Fortran 77 code must define the output variable
6473 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6474 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6475 Program Checks, autoconf, The Autoconf Manual}).
6476
6477 A few additional variables are defined when a Fortran 77 source file is
6478 seen:
6479
6480 @vtable @code
6481
6482 @item F77
6483 The name of the Fortran 77 compiler.
6484
6485 @item FFLAGS
6486 Any flags to pass to the Fortran 77 compiler.
6487
6488 @item AM_FFLAGS
6489 The maintainer's variant of @code{FFLAGS}.
6490
6491 @item RFLAGS
6492 Any flags to pass to the Ratfor compiler.
6493
6494 @item AM_RFLAGS
6495 The maintainer's variant of @code{RFLAGS}.
6496
6497 @item F77COMPILE
6498 The command used to actually compile a Fortran 77 source file.  The file
6499 name is appended to form the complete command line.
6500
6501 @item FLINK
6502 The command used to actually link a pure Fortran 77 program or shared
6503 library.
6504
6505 @end vtable
6506
6507 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6508 addition to compiling them@footnote{Much, if not most, of the
6509 information in the following sections pertaining to preprocessing
6510 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6511 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6512 also contains some support for creating programs and shared libraries
6513 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6514 Fortran 77 With C and C++}).
6515
6516 These issues are covered in the following sections.
6517
6518 @menu
6519 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6520 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6521 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6522 @end menu
6523
6524
6525 @node Preprocessing Fortran 77
6526 @comment  node-name,  next,  previous,  up
6527 @subsection Preprocessing Fortran 77
6528
6529 @cindex Preprocessing Fortran 77
6530 @cindex Fortran 77, Preprocessing
6531 @cindex Ratfor programs
6532
6533 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6534 rule runs just the preprocessor to convert a preprocessable Fortran 77
6535 or Ratfor source file into a strict Fortran 77 source file.  The precise
6536 command used is as follows:
6537
6538 @table @file
6539
6540 @item .F
6541 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6542 $(AM_FFLAGS) $(FFLAGS)}
6543
6544 @item .r
6545 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6546
6547 @end table
6548
6549
6550 @node Compiling Fortran 77 Files
6551 @comment  node-name,  next,  previous,  up
6552 @subsection Compiling Fortran 77 Files
6553
6554 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6555 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6556 is as follows:
6557
6558 @table @file
6559
6560 @item .f
6561 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6562
6563 @item .F
6564 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6565 $(AM_FFLAGS) $(FFLAGS)}
6566
6567 @item .r
6568 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6569
6570 @end table
6571
6572
6573 @node Mixing Fortran 77 With C and C++
6574 @comment  node-name,  next,  previous,  up
6575 @subsection Mixing Fortran 77 With C and C++
6576
6577 @cindex Fortran 77, mixing with C and C++
6578 @cindex Mixing Fortran 77 with C and C++
6579 @cindex Linking Fortran 77 with C and C++
6580 @cindex cfortran
6581 @cindex Mixing Fortran 77 with C and/or C++
6582
6583 Automake currently provides @emph{limited} support for creating programs
6584 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6585 However, there are many other issues related to mixing Fortran 77 with
6586 other languages that are @emph{not} (currently) handled by Automake, but
6587 that are handled by other packages@footnote{For example,
6588 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6589 addresses all of these inter-language issues, and runs under nearly all
6590 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6591 @command{cfortran} is not yet Free Software, but it will be in the next
6592 major release.}.
6593
6594 Automake can help in two ways:
6595
6596 @enumerate
6597 @item
6598 Automatic selection of the linker depending on which combinations of
6599 source code.
6600
6601 @item
6602 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6603 @option{-l}) to pass to the automatically selected linker in order to link
6604 in the appropriate Fortran 77 intrinsic and run-time libraries.
6605
6606 @cindex @code{FLIBS}, defined
6607 @vindex FLIBS
6608 These extra Fortran 77 linker flags are supplied in the output variable
6609 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro
6610 supplied with newer versions of Autoconf (Autoconf version 2.13 and
6611 later).  @xref{Fortran Compiler, , Fortran Compiler Characteristics,
6612 autoconf, The Autoconf Manual}.
6613 @end enumerate
6614
6615 If Automake detects that a program or shared library (as mentioned in
6616 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6617 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6618 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6619 @file{configure.ac}, and that either @code{$(FLIBS)}
6620 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6621 (for shared libraries) variables.  It is the responsibility of the
6622 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6623 appears in the appropriate @code{_LDADD} or
6624 @code{_LIBADD} variable.
6625
6626 @cindex Mixed language example
6627 @cindex Example, mixed language
6628
6629 For example, consider the following @file{Makefile.am}:
6630
6631 @example
6632 bin_PROGRAMS = foo
6633 foo_SOURCES  = main.cc foo.f
6634 foo_LDADD    = libfoo.la $(FLIBS)
6635
6636 pkglib_LTLIBRARIES = libfoo.la
6637 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6638 libfoo_la_LIBADD   = $(FLIBS)
6639 @end example
6640
6641 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6642 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6643 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6644 Automake would have issued a warning.
6645
6646 @menu
6647 * How the Linker is Chosen::    Automatic linker selection
6648 @end menu
6649
6650 @node How the Linker is Chosen
6651 @comment  node-name,  next,  previous,  up
6652 @subsubsection How the Linker is Chosen
6653
6654 @cindex Automatic linker selection
6655 @cindex Selecting the linker automatically
6656
6657 When a program or library mixes several languages, Automake choose the
6658 linker according to the following priorities.  (The names in
6659 parentheses are the variables containing the link command.)
6660
6661 @enumerate
6662 @item
6663 @vindex GCJLINK
6664 Native Java (@code{GCJLINK})
6665 @item
6666 @vindex CXXLINK
6667 C++ (@code{CXXLINK})
6668 @item
6669 @vindex F77LINK
6670 Fortran 77 (@code{F77LINK})
6671 @item
6672 @vindex FCLINK
6673 Fortran (@code{FCLINK})
6674 @item
6675 @vindex OBJCLINK
6676 Objective C (@code{OBJCLINK})
6677 @item
6678 @vindex UPCLINK
6679 Unified Parallel C (@code{UPCLINK})
6680 @item
6681 @vindex LINK
6682 C (@code{LINK})
6683 @end enumerate
6684
6685 For example, if Fortran 77, C and C++ source code is compiled
6686 into a program, then the C++ linker will be used.  In this case, if the
6687 C or Fortran 77 linkers required any special libraries that weren't
6688 included by the C++ linker, then they must be manually added to an
6689 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6690 @file{Makefile.am}.
6691
6692 Automake only looks at the file names listed in @file{_SOURCES}
6693 variables to choose the linker, and defaults to the C linker.
6694 Sometimes this is inconvenient because you are linking against a
6695 library written in another language and would like to set the linker
6696 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6697 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6698
6699 A per-target @code{_LINK} variable will override the above selection.
6700 Per-target link flags will cause Automake to write a per-target
6701 @code{_LINK} variable according to the language chosen as above.
6702
6703
6704 @node Fortran 9x Support
6705 @comment  node-name,  next,  previous,  up
6706 @section Fortran 9x Support
6707
6708 @cindex Fortran 9x support
6709 @cindex Support for Fortran 9x
6710
6711 Automake includes support for Fortran 9x.
6712
6713 Any package including Fortran 9x code must define the output variable
6714 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6715 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6716 Program Checks, autoconf, The Autoconf Manual}).
6717
6718 A few additional variables are defined when a Fortran 9x source file is
6719 seen:
6720
6721 @vtable @code
6722
6723 @item FC
6724 The name of the Fortran 9x compiler.
6725
6726 @item FCFLAGS
6727 Any flags to pass to the Fortran 9x compiler.
6728
6729 @item AM_FCFLAGS
6730 The maintainer's variant of @code{FCFLAGS}.
6731
6732 @item FCCOMPILE
6733 The command used to actually compile a Fortran 9x source file.  The file
6734 name is appended to form the complete command line.
6735
6736 @item FCLINK
6737 The command used to actually link a pure Fortran 9x program or shared
6738 library.
6739
6740 @end vtable
6741
6742 @menu
6743 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6744 @end menu
6745
6746 @node Compiling Fortran 9x Files
6747 @comment  node-name,  next,  previous,  up
6748 @subsection Compiling Fortran 9x Files
6749
6750 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6751 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6752 by running the Fortran 9x compiler.  The precise command used
6753 is as follows:
6754
6755 @table @file
6756
6757 @item .f90
6758 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6759
6760 @item .f95
6761 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6762
6763 @item .f03
6764 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6765
6766 @item .f08
6767 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6768
6769 @end table
6770
6771 @node Java Support with gcj
6772 @comment  node-name,  next,  previous,  up
6773 @section Compiling Java sources using gcj
6774
6775 @cindex Java support with gcj
6776 @cindex Support for Java with gcj
6777 @cindex Java to native code, compilation
6778 @cindex Compilation of Java to native code
6779
6780 Automake includes support for natively compiled Java, using @command{gcj},
6781 the Java front end to the GNU Compiler Collection (rudimentary support
6782 for compiling Java to bytecode using the @command{javac} compiler is
6783 also present, @emph{albeit deprecated}; @pxref{Java}).
6784
6785 Any package including Java code to be compiled must define the output
6786 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6787 must also be defined somehow (either in @file{configure.ac} or
6788 @file{Makefile.am}).  The simplest way to do this is to use the
6789 @code{AM_PROG_GCJ} macro.
6790
6791 @vindex GCJFLAGS
6792
6793 By default, programs including Java source files are linked with
6794 @command{gcj}.
6795
6796 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6797 compilation invoking @command{gcj} (in its role as an ahead-of-time
6798 compiler, when invoking it to create @file{.class} files,
6799 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6800 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6801 the user variable @code{GCJFLAGS}, should be used.
6802
6803 @vindex AM_GCJFLAGS
6804
6805 @command{gcj} can be used to compile @file{.java}, @file{.class},
6806 @file{.zip}, or @file{.jar} files.
6807
6808 When linking, @command{gcj} requires that the main class be specified
6809 using the @option{--main=} option.  The easiest way to do this is to use
6810 the @code{_LDFLAGS} variable for the program.
6811
6812
6813 @node Vala Support
6814 @comment  node-name,  next,  previous,  up
6815 @section Vala Support
6816
6817 @cindex Vala Support
6818 @cindex Support for Vala
6819
6820 Automake provides initial support for Vala
6821 (@uref{http://www.vala-project.org/}).
6822 This requires valac version 0.7.0 or later, and currently requires
6823 the user to use GNU @command{make}.
6824
6825 @example
6826 foo_SOURCES = foo.vala bar.vala zardoc.c
6827 @end example
6828
6829 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6830 compiled into C code by the Vala compiler. The generated @file{.c} files are
6831 distributed. The end user does not need to have a Vala compiler installed.
6832
6833 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6834 that will locate the Vala compiler and optionally check its version
6835 number.
6836
6837 @defmac AM_PROG_VALAC (@ovar{minimum-version})
6838 Try to find a Vala compiler in @env{PATH}. If it is found, the variable
6839 @code{VALAC} is set. Optionally a minimum release number of the compiler
6840 can be requested:
6841
6842 @example
6843 AM_PROG_VALAC([0.7.0])
6844 @end example
6845 @end defmac
6846
6847 There are a few variables that are used when compiling Vala sources:
6848
6849 @vtable @code
6850 @item VALAC
6851 Path to the Vala compiler.
6852
6853 @item VALAFLAGS
6854 Additional arguments for the Vala compiler.
6855
6856 @item AM_VALAFLAGS
6857 The maintainer's variant of @code{VALAFLAGS}.
6858
6859 @example
6860 lib_LTLIBRARIES = libfoo.la
6861 libfoo_la_SOURCES = foo.vala
6862 @end example
6863 @end vtable
6864
6865 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
6866 (@pxref{Renamed Objects}) to produce different C files from one Vala
6867 source file.
6868
6869
6870 @node Support for Other Languages
6871 @comment  node-name,  next,  previous,  up
6872 @section Support for Other Languages
6873
6874 Automake currently only includes full support for C, C++ (@pxref{C++
6875 Support}), Objective C (@pxref{Objective C Support}), Fortran 77
6876 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6877 and Java (@pxref{Java Support with gcj}).  There is only rudimentary
6878 support for other languages, support for which will be improved based
6879 on user demand.
6880
6881 Some limited support for adding your own languages is available via the
6882 suffix rule handling (@pxref{Suffixes}).
6883
6884 @node Dependencies
6885 @section Automatic dependency tracking
6886
6887 As a developer it is often painful to continually update the
6888 @file{Makefile.am} whenever the include-file dependencies change in a
6889 project.  Automake supplies a way to automatically track dependency
6890 changes (@pxref{Dependency Tracking}).
6891
6892 @cindex Dependency tracking
6893 @cindex Automatic dependency tracking
6894
6895 Automake always uses complete dependencies for a compilation,
6896 including system headers.  Automake's model is that dependency
6897 computation should be a side effect of the build.  To this end,
6898 dependencies are computed by running all compilations through a
6899 special wrapper program called @command{depcomp}.  @command{depcomp}
6900 understands how to coax many different C and C++ compilers into
6901 generating dependency information in the format it requires.
6902 @samp{automake -a} will install @command{depcomp} into your source
6903 tree for you.  If @command{depcomp} can't figure out how to properly
6904 invoke your compiler, dependency tracking will simply be disabled for
6905 your build.
6906
6907 @cindex @command{depcomp}
6908
6909 Experience with earlier versions of Automake (@pxref{Dependency
6910 Tracking Evolution}) taught us that it is not reliable to generate
6911 dependencies only on the maintainer's system, as configurations vary
6912 too much.  So instead Automake implements dependency tracking at build
6913 time.
6914
6915 Automatic dependency tracking can be suppressed by putting
6916 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6917 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6918 (this should be the preferred way).  Or, you can invoke @command{automake}
6919 with the @option{-i} option.  Dependency tracking is enabled by default.
6920
6921 @vindex AUTOMAKE_OPTIONS
6922 @opindex no-dependencies
6923
6924 The person building your package also can choose to disable dependency
6925 tracking by configuring with @option{--disable-dependency-tracking}.
6926
6927 @cindex Disabling dependency tracking
6928 @cindex Dependency tracking, disabling
6929
6930
6931 @node EXEEXT
6932 @section Support for executable extensions
6933
6934 @cindex Executable extension
6935 @cindex Extension, executable
6936 @cindex Windows
6937
6938 On some platforms, such as Windows, executables are expected to have an
6939 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6940 among them) will automatically generate @file{foo.exe} when asked to
6941 generate @file{foo}.
6942
6943 Automake provides mostly-transparent support for this.  Unfortunately
6944 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6945 dictionary is revised, you will have to assist Automake if your package
6946 must support those platforms.
6947
6948 One thing you must be aware of is that, internally, Automake rewrites
6949 something like this:
6950
6951 @example
6952 bin_PROGRAMS = liver
6953 @end example
6954
6955 to this:
6956
6957 @example
6958 bin_PROGRAMS = liver$(EXEEXT)
6959 @end example
6960
6961 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6962 extension.
6963
6964 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests})
6965 are also rewritten if they contain filenames that have been declared as
6966 programs in the same @file{Makefile}.  (This is mostly useful when some
6967 programs from @code{check_PROGRAMS} are listed in @code{TESTS}.)
6968
6969 However, Automake cannot apply this rewriting to @command{configure}
6970 substitutions.  This means that if you are conditionally building a
6971 program using such a substitution, then your @file{configure.ac} must
6972 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6973
6974 With Autoconf 2.13 and earlier, you must explicitly use @code{AC_EXEEXT}
6975 to get this support.  With Autoconf 2.50, @code{AC_EXEEXT} is run
6976 automatically if you configure a compiler (say, through
6977 @code{AC_PROG_CC}).
6978
6979 Sometimes maintainers like to write an explicit link rule for their
6980 program.  Without executable extension support, this is easy---you
6981 simply write a rule whose target is the name of the program.  However,
6982 when executable extension support is enabled, you must instead add the
6983 @samp{$(EXEEXT)} suffix.
6984
6985 Unfortunately, due to the change in Autoconf 2.50, this means you must
6986 always add this extension.  However, this is a problem for maintainers
6987 who know their package will never run on a platform that has
6988 executable extensions.  For those maintainers, the @option{no-exeext}
6989 option (@pxref{Options}) will disable this feature.  This works in a
6990 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6991 rule for a target named @code{foo} in @file{Makefile.am} will override
6992 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
6993 the @option{no-exeext} option, this use will give a diagnostic.
6994
6995
6996 @node Other Objects
6997 @chapter Other Derived Objects
6998
6999 Automake can handle derived objects that are not C programs.  Sometimes
7000 the support for actually building such objects must be explicitly
7001 supplied, but Automake will still automatically handle installation and
7002 distribution.
7003
7004 @menu
7005 * Scripts::                     Executable scripts
7006 * Headers::                     Header files
7007 * Data::                        Architecture-independent data files
7008 * Sources::                     Derived sources
7009 @end menu
7010
7011
7012 @node Scripts
7013 @section Executable Scripts
7014
7015 @cindex @code{_SCRIPTS} primary, defined
7016 @cindex @code{SCRIPTS} primary, defined
7017 @cindex Primary variable, @code{SCRIPTS}
7018 @vindex _SCRIPTS
7019 @cindex Installing scripts
7020
7021 It is possible to define and install programs that are scripts.  Such
7022 programs are listed using the @code{SCRIPTS} primary name.  When the
7023 script is distributed in its final, installable form, the
7024 @file{Makefile} usually looks as follows:
7025 @vindex SCRIPTS
7026
7027 @example
7028 # Install my_script in $(bindir) and distribute it.
7029 dist_bin_SCRIPTS = my_script
7030 @end example
7031
7032 Scripts are not distributed by default; as we have just seen, those
7033 that should be distributed can be specified using a @code{dist_}
7034 prefix as with other primaries.
7035
7036 @cindex @code{SCRIPTS}, installation directories
7037 @vindex bin_SCRIPTS
7038 @vindex sbin_SCRIPTS
7039 @vindex libexec_SCRIPTS
7040 @vindex pkgdata_SCRIPTS
7041 @vindex pkglibexec_SCRIPTS
7042 @vindex noinst_SCRIPTS
7043 @vindex check_SCRIPTS
7044
7045 Scripts can be installed in @code{bindir}, @code{sbindir},
7046 @code{libexecdir}, @code{pkglibexecdir}, or @code{pkgdatadir}.
7047
7048 Scripts that need not be installed can be listed in
7049 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7050 @samp{make check} should go in @code{check_SCRIPTS}.
7051
7052 When a script needs to be built, the @file{Makefile.am} should include
7053 the appropriate rules.  For instance the @command{automake} program
7054 itself is a Perl script that is generated from @file{automake.in}.
7055 Here is how this is handled:
7056
7057 @example
7058 bin_SCRIPTS = automake
7059 CLEANFILES = $(bin_SCRIPTS)
7060 EXTRA_DIST = automake.in
7061
7062 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7063             -e 's,[@@]PERL[@@],$(PERL),g' \
7064             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7065             -e 's,[@@]VERSION[@@],$(VERSION),g' \
7066             @dots{}
7067
7068 automake: automake.in Makefile
7069         $(do_subst) < $(srcdir)/automake.in > automake
7070         chmod +x automake
7071 @end example
7072
7073 Such scripts for which a build rule has been supplied need to be
7074 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7075 sources have to be distributed, usually with @code{EXTRA_DIST}
7076 (@pxref{Basics of Distribution}).
7077
7078 Another common way to build scripts is to process them from
7079 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
7080 Automake knows which files should be cleaned and distributed, and what
7081 the rebuild rules should look like.
7082
7083 For instance if @file{configure.ac} contains
7084
7085 @example
7086 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7087 @end example
7088
7089 @noindent
7090 to build @file{src/my_script} from @file{src/my_script.in}, then a
7091 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7092 be as simple as
7093
7094 @example
7095 bin_SCRIPTS = my_script
7096 CLEANFILES = $(bin_SCRIPTS)
7097 @end example
7098
7099 @noindent
7100 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7101 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7102 @code{CLEANFILES} is still useful, because by default Automake will
7103 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7104 @code{clean}.
7105
7106 Although this looks simpler, building scripts this way has one
7107 drawback: directory variables such as @code{$(datadir)} are not fully
7108 expanded and may refer to other directory variables.
7109
7110 @node Headers
7111 @section Header files
7112
7113 @cindex @code{_HEADERS} primary, defined
7114 @cindex @code{HEADERS} primary, defined
7115 @cindex Primary variable, @code{HEADERS}
7116 @vindex _HEADERS
7117 @vindex noinst_HEADERS
7118 @cindex @code{HEADERS}, installation directories
7119 @cindex Installing headers
7120 @vindex include_HEADERS
7121 @vindex oldinclude_HEADERS
7122 @vindex pkginclude_HEADERS
7123
7124
7125 Header files that must be installed are specified by the
7126 @code{HEADERS} family of variables.  Headers can be installed in
7127 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7128 other directory you may have defined (@pxref{Uniform}).  For instance,
7129
7130 @example
7131 include_HEADERS = foo.h bar/bar.h
7132 @end example
7133
7134 @noindent
7135 will install the two files as @file{$(includedir)/foo.h} and
7136 @file{$(includedir)/bar.h}.
7137
7138 The @code{nobase_} prefix is also supported,
7139
7140 @example
7141 nobase_include_HEADERS = foo.h bar/bar.h
7142 @end example
7143
7144 @noindent
7145 will install the two files as @file{$(includedir)/foo.h} and
7146 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7147
7148 @vindex noinst_HEADERS
7149 Usually, only header files that accompany installed libraries need to
7150 be installed.  Headers used by programs or convenience libraries are
7151 not installed.  The @code{noinst_HEADERS} variable can be used for
7152 such headers.  However when the header actually belongs to a single
7153 convenience library or program, we recommend listing it in the
7154 program's or library's @code{_SOURCES} variable (@pxref{Program
7155 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7156 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7157 right variable to use in a directory containing only headers and no
7158 associated library or program.
7159
7160 All header files must be listed somewhere; in a @code{_SOURCES}
7161 variable or in a @code{_HEADERS} variable.  Missing ones will not
7162 appear in the distribution.
7163
7164 For header files that are built and must not be distributed, use the
7165 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7166 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7167 during the build, you must also ensure they exist before they are
7168 used (@pxref{Sources}).
7169
7170
7171 @node Data
7172 @section Architecture-independent data files
7173
7174 @cindex @code{_DATA} primary, defined
7175 @cindex @code{DATA} primary, defined
7176 @cindex Primary variable, @code{DATA}
7177 @vindex _DATA
7178
7179 Automake supports the installation of miscellaneous data files using the
7180 @code{DATA} family of variables.
7181 @vindex DATA
7182
7183 @vindex data_DATA
7184 @vindex sysconf_DATA
7185 @vindex sharedstate_DATA
7186 @vindex localstate_DATA
7187 @vindex pkgdata_DATA
7188
7189 Such data can be installed in the directories @code{datadir},
7190 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7191 @code{pkgdatadir}.
7192
7193 By default, data files are @emph{not} included in a distribution.  Of
7194 course, you can use the @code{dist_} prefix to change this on a
7195 per-variable basis.
7196
7197 Here is how Automake declares its auxiliary data files:
7198
7199 @example
7200 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7201 @end example
7202
7203
7204 @node Sources
7205 @section Built Sources
7206
7207 Because Automake's automatic dependency tracking works as a side-effect
7208 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7209 target should not be compiled before its dependencies are made, but
7210 these dependencies are unknown until the target is first compiled.
7211
7212 Ordinarily this is not a problem, because dependencies are distributed
7213 sources: they preexist and do not need to be built.  Suppose that
7214 @file{foo.c} includes @file{foo.h}.  When it first compiles
7215 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7216 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7217 records the @file{foo.h} dependency so that following invocations of
7218 @command{make} will honor it.  In these conditions, it's clear there is
7219 no problem: either @file{foo.o} doesn't exist and has to be built
7220 (regardless of the dependencies), or accurate dependencies exist and
7221 they can be used to decide whether @file{foo.o} should be rebuilt.
7222
7223 It's a different story if @file{foo.h} doesn't exist by the first
7224 @command{make} run.  For instance, there might be a rule to build
7225 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7226 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7227 rule to build @file{foo.h} first by lack of dependency information.
7228
7229 @vindex BUILT_SOURCES
7230 @cindex @code{BUILT_SOURCES}, defined
7231
7232 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7233 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7234 or @samp{make check} (or even @samp{make install}) before other
7235 targets are processed.  However, such a source file is not
7236 @emph{compiled} unless explicitly requested by mentioning it in some
7237 other @code{_SOURCES} variable.
7238
7239 So, to conclude our introductory example, we could use
7240 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7241 any other target (including @file{foo.o}) during @samp{make all} or
7242 @samp{make check}.
7243
7244 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7245 must be created early in the build process can be listed in this
7246 variable.  Moreover, all built sources do not necessarily have to be
7247 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7248 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7249 another source), because it's a known dependency of the associated
7250 object.
7251
7252 It might be important to emphasize that @code{BUILT_SOURCES} is
7253 honored only by @samp{make all}, @samp{make check} and @samp{make
7254 install}.  This means you cannot build a specific target (e.g.,
7255 @samp{make foo}) in a clean tree if it depends on a built source.
7256 However it will succeed if you have run @samp{make all} earlier,
7257 because accurate dependencies are already available.
7258
7259 The next section illustrates and discusses the handling of built sources
7260 on a toy example.
7261
7262 @menu
7263 * Built Sources Example::       Several ways to handle built sources.
7264 @end menu
7265
7266 @node Built Sources Example
7267 @subsection Built Sources Example
7268
7269 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7270 installation-dependent and not distributed: it needs to be built.  Here
7271 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7272 value of the @command{make} variable @code{bindir} (inherited from
7273 @file{configure}).
7274
7275 We suggest several implementations below.  It's not meant to be an
7276 exhaustive listing of all ways to handle built sources, but it will give
7277 you a few ideas if you encounter this issue.
7278
7279 @subsubheading First Try
7280
7281 This first implementation will illustrate the bootstrap issue mentioned
7282 in the previous section (@pxref{Sources}).
7283
7284 Here is a tentative @file{Makefile.am}.
7285
7286 @example
7287 # This won't work.
7288 bin_PROGRAMS = foo
7289 foo_SOURCES = foo.c
7290 nodist_foo_SOURCES = bindir.h
7291 CLEANFILES = bindir.h
7292 bindir.h: Makefile
7293         echo '#define bindir "$(bindir)"' >$@@
7294 @end example
7295
7296 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7297 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7298 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7299 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7300 The symptom is as follows.
7301
7302 @example
7303 % make
7304 source='foo.c' object='foo.o' libtool=no \
7305 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7306 depmode=gcc /bin/sh ./depcomp \
7307 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7308 foo.c:2: bindir.h: No such file or directory
7309 make: *** [foo.o] Error 1
7310 @end example
7311
7312 In this example @file{bindir.h} is not distributed nor installed, and
7313 it is not even being built on-time.  One may wonder if the
7314 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7315 line simply states that @file{bindir.h} is a source of @code{foo}, so
7316 for instance, it should be inspected while generating tags
7317 (@pxref{Tags}).  In other words, it does not help our present problem,
7318 and the build would fail identically without it.
7319
7320 @subsubheading Using @code{BUILT_SOURCES}
7321
7322 A solution is to require @file{bindir.h} to be built before anything
7323 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7324
7325 @example
7326 bin_PROGRAMS = foo
7327 foo_SOURCES = foo.c
7328 nodist_foo_SOURCES = bindir.h
7329 BUILT_SOURCES = bindir.h
7330 CLEANFILES = bindir.h
7331 bindir.h: Makefile
7332         echo '#define bindir "$(bindir)"' >$@@
7333 @end example
7334
7335 See how @file{bindir.h} gets built first:
7336
7337 @example
7338 % make
7339 echo '#define bindir "/usr/local/bin"' >bindir.h
7340 make  all-am
7341 make[1]: Entering directory `/home/adl/tmp'
7342 source='foo.c' object='foo.o' libtool=no \
7343 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7344 depmode=gcc /bin/sh ./depcomp \
7345 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7346 gcc  -g -O2   -o foo  foo.o
7347 make[1]: Leaving directory `/home/adl/tmp'
7348 @end example
7349
7350 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7351 @code{all}, @code{check}, and @code{install} targets.  It still fails
7352 if you try to run @samp{make foo} explicitly:
7353
7354 @example
7355 % make clean
7356 test -z "bindir.h" || rm -f bindir.h
7357 test -z "foo" || rm -f foo
7358 rm -f *.o
7359 % : > .deps/foo.Po # Suppress previously recorded dependencies
7360 % make foo
7361 source='foo.c' object='foo.o' libtool=no \
7362 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7363 depmode=gcc /bin/sh ./depcomp \
7364 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7365 foo.c:2: bindir.h: No such file or directory
7366 make: *** [foo.o] Error 1
7367 @end example
7368
7369 @subsubheading Recording Dependencies manually
7370
7371 Usually people are happy enough with @code{BUILT_SOURCES} because they
7372 never build targets such as @samp{make foo} before @samp{make all}, as
7373 in the previous example.  However if this matters to you, you can
7374 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7375 the @file{Makefile.am}.
7376
7377 @example
7378 bin_PROGRAMS = foo
7379 foo_SOURCES = foo.c
7380 nodist_foo_SOURCES = bindir.h
7381 foo.$(OBJEXT): bindir.h
7382 CLEANFILES = bindir.h
7383 bindir.h: Makefile
7384         echo '#define bindir "$(bindir)"' >$@@
7385 @end example
7386
7387 You don't have to list @emph{all} the dependencies of @file{foo.o}
7388 explicitly, only those that might need to be built.  If a dependency
7389 already exists, it will not hinder the first compilation and will be
7390 recorded by the normal dependency tracking code.  (Note that after
7391 this first compilation the dependency tracking code will also have
7392 recorded the dependency between @file{foo.o} and
7393 @file{bindir.h}; so our explicit dependency is really useful to
7394 the first build only.)
7395
7396 Adding explicit dependencies like this can be a bit dangerous if you are
7397 not careful enough.  This is due to the way Automake tries not to
7398 overwrite your rules (it assumes you know better than it).
7399 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7400 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7401 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7402 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7403 Always check the generated @file{Makefile.in} if you do this.
7404
7405 @subsubheading Build @file{bindir.h} from @file{configure}
7406
7407 It's possible to define this preprocessor macro from @file{configure},
7408 either in @file{config.h} (@pxref{Defining Directories, , Defining
7409 Directories, autoconf, The Autoconf Manual}), or by processing a
7410 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7411 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7412 Autoconf Manual}).
7413
7414 At this point it should be clear that building @file{bindir.h} from
7415 @file{configure} works well for this example.  @file{bindir.h} will exist
7416 before you build any target, hence will not cause any dependency issue.
7417
7418 The Makefile can be shrunk as follows.  We do not even have to mention
7419 @file{bindir.h}.
7420
7421 @example
7422 bin_PROGRAMS = foo
7423 foo_SOURCES = foo.c
7424 @end example
7425
7426 However, it's not always possible to build sources from
7427 @file{configure}, especially when these sources are generated by a tool
7428 that needs to be built first.
7429
7430 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7431
7432 Another attractive idea is to define @code{bindir} as a variable or
7433 function exported from @file{bindir.o}, and build @file{bindir.c}
7434 instead of @file{bindir.h}.
7435
7436 @example
7437 noinst_PROGRAMS = foo
7438 foo_SOURCES = foo.c bindir.h
7439 nodist_foo_SOURCES = bindir.c
7440 CLEANFILES = bindir.c
7441 bindir.c: Makefile
7442         echo 'const char bindir[] = "$(bindir)";' >$@@
7443 @end example
7444
7445 @file{bindir.h} contains just the variable's declaration and doesn't
7446 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7447 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7448 first.
7449
7450 @subsubheading Which is best?
7451
7452 There is no panacea, of course.  Each solution has its merits and
7453 drawbacks.
7454
7455 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7456 foo} on a clean tree is important to you.
7457
7458 You won't add explicit dependencies if you are leery of overriding
7459 an Automake rule by mistake.
7460
7461 Building files from @file{./configure} is not always possible, neither
7462 is converting @file{.h} files into @file{.c} files.
7463
7464
7465 @node Other GNU Tools
7466 @chapter Other GNU Tools
7467
7468 Since Automake is primarily intended to generate @file{Makefile.in}s for
7469 use in GNU programs, it tries hard to interoperate with other GNU tools.
7470
7471 @menu
7472 * Emacs Lisp::                  Emacs Lisp
7473 * gettext::                     Gettext
7474 * Libtool::                     Libtool
7475 * Java::                        Java bytecode compilation (deprecated)
7476 * Python::                      Python
7477 @end menu
7478
7479
7480 @node Emacs Lisp
7481 @section Emacs Lisp
7482
7483 @cindex @code{_LISP} primary, defined
7484 @cindex @code{LISP} primary, defined
7485 @cindex Primary variable, @code{LISP}
7486
7487 @vindex _LISP
7488 @vindex lisp_LISP
7489 @vindex noinst_LISP
7490
7491 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7492 is used to hold a list of @file{.el} files.  Possible prefixes for this
7493 primary are @code{lisp_} and @code{noinst_}.  Note that if
7494 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7495 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7496
7497 @vindex dist_lisp_LISP
7498 @vindex dist_noinst_LISP
7499 Lisp sources are not distributed by default.  You can prefix the
7500 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7501 @code{dist_noinst_LISP}, to indicate that these files should be
7502 distributed.
7503
7504 Automake will byte-compile all Emacs Lisp source files using the Emacs
7505 found by @code{AM_PATH_LISPDIR}, if any was found.
7506
7507 Byte-compiled Emacs Lisp files are not portable among all versions of
7508 Emacs, so it makes sense to turn this off if you expect sites to have
7509 more than one version of Emacs installed.  Furthermore, many packages
7510 don't actually benefit from byte-compilation.  Still, we recommend
7511 that you byte-compile your Emacs Lisp sources.  It is probably better
7512 for sites with strange setups to cope for themselves than to make the
7513 installation less nice for everybody else.
7514
7515 There are two ways to avoid byte-compiling.  Historically, we have
7516 recommended the following construct.
7517
7518 @example
7519 lisp_LISP = file1.el file2.el
7520 ELCFILES =
7521 @end example
7522
7523 @noindent
7524 @code{ELCFILES} is an internal Automake variable that normally lists
7525 all @file{.elc} files that must be byte-compiled.  Automake defines
7526 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7527 variable explicitly prevents byte-compilation.
7528
7529 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7530
7531 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7532 @example
7533 lisp_DATA = file1.el file2.el
7534 @end example
7535
7536 Note that these two constructs are not equivalent.  @code{_LISP} will
7537 not install a file if Emacs is not installed, while @code{_DATA} will
7538 always install its files.
7539
7540 @node gettext
7541 @section Gettext
7542
7543 @cindex GNU Gettext support
7544 @cindex Gettext support
7545 @cindex Support for GNU Gettext
7546
7547 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7548 turns on support for GNU gettext, a message catalog system for
7549 internationalization
7550 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7551
7552 The @code{gettext} support in Automake requires the addition of one or
7553 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7554 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7555 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7556 Automake ensures that these directories exist and are mentioned in
7557 @code{SUBDIRS}.
7558
7559 @node Libtool
7560 @section Libtool
7561
7562 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7563 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7564 @xref{A Shared Library}.
7565
7566
7567 @node Java
7568 @section Java bytecode compilation (deprecated)
7569
7570 @cindex @code{_JAVA} primary, defined
7571 @cindex @code{JAVA} primary, defined
7572 @cindex Primary variable, @code{JAVA}
7573 @cindex Java to bytecode, compilation
7574 @cindex Compilation of Java to bytecode
7575
7576 Automake provides some minimal support for Java bytecode compilation with
7577 the @code{JAVA} primary (in addition to the support for compiling Java to
7578 native machine code; @pxref{Java Support with gcj}).  Note however that
7579 @emph{the interface and most features described here are deprecated}; the
7580 next automake release will strive to provide a better and cleaner
7581 interface, which however @emph{won't be backward-compatible}; the present
7582 interface will probably be removed altogether in future automake releases
7583 (1.13 or later), so don't use it in new code.
7584
7585 Any @file{.java} files listed in a @code{_JAVA} variable will be
7586 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7587 files are not included in the distribution, you should use the
7588 @code{dist_} prefix to distribute them.
7589
7590 Here is a typical setup for distributing @file{.java} files and
7591 installing the @file{.class} files resulting from their compilation.
7592
7593 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7594 @example
7595 javadir = $(datadir)/java
7596 dist_java_JAVA = a.java b.java @dots{}
7597 @end example
7598
7599 @cindex @code{JAVA} restrictions
7600 @cindex Restrictions for @code{JAVA}
7601
7602 Currently Automake enforces the restriction that only one @code{_JAVA}
7603 primary can be used in a given @file{Makefile.am}.  The reason for this
7604 restriction is that, in general, it isn't possible to know which
7605 @file{.class} files were generated from which @file{.java} files, so
7606 it would be impossible to know which files to install where.  For
7607 instance, a @file{.java} file can define multiple classes; the resulting
7608 @file{.class} file names cannot be predicted without parsing the
7609 @file{.java} file.
7610
7611 There are a few variables that are used when compiling Java sources:
7612
7613 @vtable @code
7614 @item JAVAC
7615 The name of the Java compiler.  This defaults to @samp{javac}.
7616
7617 @item JAVACFLAGS
7618 The flags to pass to the compiler.  This is considered to be a user
7619 variable (@pxref{User Variables}).
7620
7621 @item AM_JAVACFLAGS
7622 More flags to pass to the Java compiler.  This, and not
7623 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7624 compiler flags into @file{Makefile.am}.
7625
7626 @item JAVAROOT
7627 The value of this variable is passed to the @option{-d} option to
7628 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7629
7630 @item CLASSPATH_ENV
7631 This variable is a shell expression that is used to set the
7632 @env{CLASSPATH} environment variable on the @code{javac} command line.
7633 (In the future we will probably handle class path setting differently.)
7634 @end vtable
7635
7636
7637 @node Python
7638 @section Python
7639
7640 @cindex @code{_PYTHON} primary, defined
7641 @cindex @code{PYTHON} primary, defined
7642 @cindex Primary variable, @code{PYTHON}
7643 @vindex _PYTHON
7644
7645 Automake provides support for Python compilation with the
7646 @code{PYTHON} primary.  A typical setup is to call
7647 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7648 following in @file{Makefile.am}:
7649
7650 @example
7651 python_PYTHON = tree.py leave.py
7652 @end example
7653
7654 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7655 with @command{py-compile} at install time.  @command{py-compile}
7656 actually creates both standard (@file{.pyc}) and optimized
7657 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7658 because byte-compilation occurs at install time, any files listed in
7659 @code{noinst_PYTHON} will not be compiled.  Python source files are
7660 included in the distribution by default, prepend @code{nodist_} (as in
7661 @code{nodist_python_PYTHON}) to omit them.
7662
7663 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7664 that will determine some Python-related directory variables (see
7665 below).  If you have called @code{AM_PATH_PYTHON} from
7666 @file{configure.ac}, then you may use the variables
7667 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7668 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7669 files in your @file{Makefile.am}, depending on where you want your files
7670 installed (see the definitions of @code{pythondir} and
7671 @code{pkgpythondir} below).
7672
7673 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7674   @ovar{action-if-not-found})
7675
7676 Search for a Python interpreter on the system.  This macro takes three
7677 optional arguments.  The first argument, if present, is the minimum
7678 version of Python required for this package: @code{AM_PATH_PYTHON}
7679 will skip any Python interpreter that is older than @var{version}.
7680 If an interpreter is found and satisfies @var{version}, then
7681 @var{action-if-found} is run.  Otherwise, @var{action-if-not-found} is
7682 run.
7683
7684 If @var{action-if-not-found} is not specified, as in the following
7685 example, the default is to abort @command{configure}.
7686
7687 @example
7688 AM_PATH_PYTHON([2.2])
7689 @end example
7690
7691 @noindent
7692 This is fine when Python is an absolute requirement for the package.
7693 If Python >= 2.5 was only @emph{optional} to the package,
7694 @code{AM_PATH_PYTHON} could be called as follows.
7695
7696 @example
7697 AM_PATH_PYTHON([2.5],, [:])
7698 @end example
7699
7700 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7701 called, then that will be the only Python interpreter that is tried.
7702
7703 @code{AM_PATH_PYTHON} creates the following output variables based on
7704 the Python installation found during configuration.
7705 @end defmac
7706
7707 @vtable @code
7708 @item PYTHON
7709 The name of the Python executable, or @samp{:} if no suitable
7710 interpreter could be found.
7711
7712 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7713 will abort if Python is absent), the value of @code{PYTHON} can be used
7714 to setup a conditional in order to disable the relevant part of a build
7715 as follows.
7716
7717 @example
7718 AM_PATH_PYTHON(,, [:])
7719 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7720 @end example
7721
7722 @item PYTHON_VERSION
7723 The Python version number, in the form @var{major}.@var{minor}
7724 (e.g., @samp{2.5}).  This is currently the value of
7725 @samp{sys.version[:3]}.
7726
7727 @item PYTHON_PREFIX
7728 The string @samp{$@{prefix@}}.  This term may be used in future work
7729 that needs the contents of Python's @samp{sys.prefix}, but general
7730 consensus is to always use the value from @command{configure}.
7731
7732 @item PYTHON_EXEC_PREFIX
7733 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7734 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7735 consensus is to always use the value from @command{configure}.
7736
7737 @item PYTHON_PLATFORM
7738 The canonical name used by Python to describe the operating system, as
7739 given by @samp{sys.platform}.  This value is sometimes needed when
7740 building Python extensions.
7741
7742 @item pythondir
7743 The directory name for the @file{site-packages} subdirectory of the
7744 standard Python install tree.
7745
7746 @item pkgpythondir
7747 This is the directory under @code{pythondir} that is named after the
7748 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7749 as a convenience.
7750
7751 @item pyexecdir
7752 This is the directory where Python extension modules (shared libraries)
7753 should be installed.  An extension module written in C could be declared
7754 as follows to Automake:
7755
7756 @c Keep in sync with primary-prefix-couples-documented-valid.test.
7757 @example
7758 pyexec_LTLIBRARIES = quaternion.la
7759 quaternion_la_SOURCES = quaternion.c support.c support.h
7760 quaternion_la_LDFLAGS = -avoid-version -module
7761 @end example
7762
7763 @item pkgpyexecdir
7764 This is a convenience variable that is defined as
7765 @samp{$(pyexecdir)/$(PACKAGE)}.
7766 @end vtable
7767
7768 All these directory variables have values that start with either
7769 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7770 fine in @file{Makefiles}, but it makes these variables hard to use in
7771 @file{configure}.  This is mandated by the GNU coding standards, so
7772 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7773 manual has a section with more details on this topic
7774 (@pxref{Installation Directory Variables, , Installation Directory
7775 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7776 Install Paths}.
7777
7778
7779 @node Documentation
7780 @chapter Building documentation
7781
7782 Currently Automake provides support for Texinfo and man pages.
7783
7784 @menu
7785 * Texinfo::                     Texinfo
7786 * Man Pages::                   Man pages
7787 @end menu
7788
7789
7790 @node Texinfo
7791 @section Texinfo
7792
7793 @cindex @code{_TEXINFOS} primary, defined
7794 @cindex @code{TEXINFOS} primary, defined
7795 @cindex Primary variable, @code{TEXINFOS}
7796 @cindex HTML output using Texinfo
7797 @cindex PDF output using Texinfo
7798 @cindex PS output using Texinfo
7799 @cindex DVI output using Texinfo
7800 @vindex _TEXINFOS
7801 @vindex info_TEXINFOS
7802
7803 If the current directory contains Texinfo source, you must declare it
7804 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7805 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7806 here.  Any Texinfo source file must end in the @file{.texi},
7807 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7808 for new manuals.
7809
7810 Automake generates rules to build @file{.info}, @file{.dvi},
7811 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7812 sources.  Following the GNU Coding Standards, only the @file{.info}
7813 files are built by @samp{make all} and installed by @samp{make
7814 install} (unless you use @option{no-installinfo}, see below).
7815 Furthermore, @file{.info} files are automatically distributed so that
7816 Texinfo is not a prerequisite for installing your package.
7817
7818 @trindex dvi
7819 @trindex html
7820 @trindex pdf
7821 @trindex ps
7822 @trindex install-dvi
7823 @trindex install-html
7824 @trindex install-pdf
7825 @trindex install-ps
7826 Other documentation formats can be built on request by @samp{make
7827 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7828 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7829 @samp{make install-pdf} and @samp{make install-html} explicitly.
7830 @samp{make uninstall} will remove everything: the Texinfo
7831 documentation installed by default as well as all the above optional
7832 formats.
7833
7834 All these targets can be extended using @samp{-local} rules
7835 (@pxref{Extending}).
7836
7837 @cindex Texinfo flag, @code{VERSION}
7838 @cindex Texinfo flag, @code{UPDATED}
7839 @cindex Texinfo flag, @code{EDITION}
7840 @cindex Texinfo flag, @code{UPDATED-MONTH}
7841
7842 @cindex @code{VERSION} Texinfo flag
7843 @cindex @code{UPDATED} Texinfo flag
7844 @cindex @code{EDITION} Texinfo flag
7845 @cindex @code{UPDATED-MONTH} Texinfo flag
7846
7847 @cindex @file{mdate-sh}
7848
7849 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7850 that file will be automatically generated.  The file @file{version.texi}
7851 defines four Texinfo flag you can reference using
7852 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7853 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7854
7855 @table @code
7856 @item EDITION
7857 @itemx VERSION
7858 Both of these flags hold the version number of your program.  They are
7859 kept separate for clarity.
7860
7861 @item UPDATED
7862 This holds the date the primary @file{.texi} file was last modified.
7863
7864 @item UPDATED-MONTH
7865 This holds the name of the month in which the primary @file{.texi} file
7866 was last modified.
7867 @end table
7868
7869 The @file{version.texi} support requires the @command{mdate-sh}
7870 script; this script is supplied with Automake and automatically
7871 included when @command{automake} is invoked with the
7872 @option{--add-missing} option.
7873
7874 If you have multiple Texinfo files, and you want to use the
7875 @file{version.texi} feature, then you have to have a separate version
7876 file for each Texinfo file.  Automake will treat any include in a
7877 Texinfo file that matches @file{vers*.texi} just as an automatically
7878 generated version file.
7879
7880 Sometimes an info file actually depends on more than one @file{.texi}
7881 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7882 @file{fdl.texi}.  You can tell Automake about these dependencies using
7883 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7884 @vindex TEXINFOS
7885 @vindex _TEXINFOS
7886
7887 @example
7888 info_TEXINFOS = hello.texi
7889 hello_TEXINFOS = fdl.texi
7890 @end example
7891
7892 @cindex @file{texinfo.tex}
7893
7894 By default, Automake requires the file @file{texinfo.tex} to appear in
7895 the same directory as the @file{Makefile.am} file that lists the
7896 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7897 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7898 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7899 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
7900 @option{--add-missing} is given, and takes care of its distribution.
7901 However, if you set the @code{TEXINFO_TEX} variable (see below),
7902 it overrides the location of the file and turns off its installation
7903 into the source as well as its distribution.
7904
7905 The option @option{no-texinfo.tex} can be used to eliminate the
7906 requirement for the file @file{texinfo.tex}.  Use of the variable
7907 @code{TEXINFO_TEX} is preferable, however, because that allows the
7908 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7909
7910 @cindex Option, @code{no-installinfo}
7911 @cindex Target, @code{install-info}
7912 @cindex @code{install-info} target
7913 @cindex @code{no-installinfo} option
7914
7915 @opindex no-installinfo
7916 @trindex install-info
7917
7918 Automake generates an @code{install-info} rule; some people apparently
7919 use this.  By default, info pages are installed by @samp{make
7920 install}, so running @code{make install-info} is pointless.  This can
7921 be prevented via the @code{no-installinfo} option.  In this case,
7922 @file{.info} files are not installed by default, and user must
7923 request this explicitly using @samp{make install-info}.
7924
7925 @vindex AM_UPDATE_INFO_DIR
7926 By default, @code{make install-info} will try to run the
7927 @command{install-info} program (if available) to update (or create)
7928 the @file{@code{$@{infodir@}}/dir} index.  If this is undesired, it
7929 can be prevented by exporting the @code{AM_UPDATE_INFO_DIR} variable
7930 to "@code{no}".
7931
7932 The following variables are used by the Texinfo build rules.
7933
7934 @vtable @code
7935 @item MAKEINFO
7936 The name of the program invoked to build @file{.info} files.  This
7937 variable is defined by Automake.  If the @command{makeinfo} program is
7938 found on the system then it will be used by default; otherwise
7939 @command{missing} will be used instead.
7940
7941 @item MAKEINFOHTML
7942 The command invoked to build @file{.html} files.  Automake
7943 defines this to @samp{$(MAKEINFO) --html}.
7944
7945 @item MAKEINFOFLAGS
7946 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7947 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7948 not expected to be defined in any @file{Makefile}; it can be used by
7949 users to pass extra flags to suit their needs.
7950
7951 @item AM_MAKEINFOFLAGS
7952 @itemx AM_MAKEINFOHTMLFLAGS
7953 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7954 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7955 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7956 passed to @code{makeinfo} when building @file{.info} files; and
7957 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7958 files.
7959
7960 @c Keep in sync with txinfo21.test.
7961 For instance, the following setting can be used to obtain one single
7962 @file{.html} file per manual, without node separators.
7963 @example
7964 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7965 @end example
7966
7967 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7968 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7969 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7970 and @file{.html} files.
7971
7972 @item TEXI2DVI
7973 The name of the command that converts a @file{.texi} file into a
7974 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7975 with the Texinfo package.
7976
7977 @item TEXI2PDF
7978 The name of the command that translates a @file{.texi} file into a
7979 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7980
7981 @item DVIPS
7982 The name of the command that builds a @file{.ps} file out of a
7983 @file{.dvi} file.  This defaults to @samp{dvips}.
7984
7985 @item TEXINFO_TEX
7986
7987 If your package has Texinfo files in many directories, you can use the
7988 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7989 @file{texinfo.tex} for your package.  The value of this variable should
7990 be the relative path from the current @file{Makefile.am} to
7991 @file{texinfo.tex}:
7992
7993 @example
7994 TEXINFO_TEX = ../doc/texinfo.tex
7995 @end example
7996 @end vtable
7997
7998
7999 @node Man Pages
8000 @section Man Pages
8001
8002 @cindex @code{_MANS} primary, defined
8003 @cindex @code{MANS} primary, defined
8004 @cindex Primary variable, @code{MANS}
8005
8006 @vindex _MANS
8007 @vindex man_MANS
8008 A package can also include man pages (but see the GNU standards on this
8009 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
8010 pages are declared using the @code{MANS} primary.  Generally the
8011 @code{man_MANS} variable is used.  Man pages are automatically installed in
8012 the correct subdirectory of @code{mandir}, based on the file extension.
8013
8014 File extensions such as @file{.1c} are handled by looking for the valid
8015 part of the extension and using that to determine the correct
8016 subdirectory of @code{mandir}.  Valid section names are the digits
8017 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
8018
8019 Sometimes developers prefer to name a man page something like
8020 @file{foo.man} in the source, and then rename it to have the correct
8021 suffix, for example @file{foo.1}, when installing the file.  Automake
8022 also supports this mode.  For a valid section named @var{section},
8023 there is a corresponding directory named @samp{man@var{section}dir},
8024 and a corresponding @code{_MANS} variable.  Files listed in such a
8025 variable are installed in the indicated section.  If the file already
8026 has a valid suffix, then it is installed as-is; otherwise the file
8027 suffix is changed to match the section.
8028
8029 For instance, consider this example:
8030 @example
8031 man1_MANS = rename.man thesame.1 alsothesame.1c
8032 @end example
8033
8034 @noindent
8035 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8036 installed, but the other files will keep their names.
8037
8038 @cindex Target, @code{install-man}
8039 @cindex Option, @option{no-installman}
8040 @cindex @code{install-man} target
8041 @cindex @option{no-installman} option
8042 @opindex no-installman
8043 @trindex install-man
8044
8045 By default, man pages are installed by @samp{make install}.  However,
8046 since the GNU project does not require man pages, many maintainers do
8047 not expend effort to keep the man pages up to date.  In these cases, the
8048 @option{no-installman} option will prevent the man pages from being
8049 installed by default.  The user can still explicitly install them via
8050 @samp{make install-man}.
8051
8052 For fast installation, with many files it is preferable to use
8053 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8054 do not need to be renamed.
8055
8056 Man pages are not currently considered to be source, because it is not
8057 uncommon for man pages to be automatically generated.  Therefore they
8058 are not automatically included in the distribution.  However, this can
8059 be changed by use of the @code{dist_} prefix.  For instance here is
8060 how to distribute and install the two man pages of GNU @command{cpio}
8061 (which includes both Texinfo documentation and man pages):
8062
8063 @example
8064 dist_man_MANS = cpio.1 mt.1
8065 @end example
8066
8067 The @code{nobase_} prefix is meaningless for man pages and is
8068 disallowed.
8069
8070 @vindex notrans_
8071 @cindex @code{notrans_} prefix
8072 @cindex Man page renaming, avoiding
8073 @cindex Avoiding man page renaming
8074
8075 Executables and manpages may be renamed upon installation
8076 (@pxref{Renaming}).  For manpages this can be avoided by use of the
8077 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
8078 allowing to access a library function @samp{foo} from the command line.
8079 The way to avoid renaming of the @file{foo.3} manpage is:
8080
8081 @example
8082 man_MANS = foo.1
8083 notrans_man_MANS = foo.3
8084 @end example
8085
8086 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8087 @cindex @code{dist_} and @code{notrans_}
8088 @cindex @code{nodist_} and @code{notrans_}
8089
8090 @samp{notrans_} must be specified first when used in conjunction with
8091 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8092 Control}).  For instance:
8093
8094 @example
8095 notrans_dist_man3_MANS = bar.3
8096 @end example
8097
8098 @node Install
8099 @chapter What Gets Installed
8100
8101 @cindex Installation support
8102 @cindex @samp{make install} support
8103
8104 Naturally, Automake handles the details of actually installing your
8105 program once it has been built.  All files named by the various
8106 primaries are automatically installed in the appropriate places when the
8107 user runs @samp{make install}.
8108
8109 @menu
8110 * Basics of Installation::      What gets installed where
8111 * The Two Parts of Install::    Installing data and programs separately
8112 * Extending Installation::      Adding your own rules for installation
8113 * Staged Installs::             Installation in a temporary location
8114 * Install Rules for the User::  Useful additional rules
8115 @end menu
8116
8117 @node Basics of Installation
8118 @section Basics of Installation
8119
8120 A file named in a primary is installed by copying the built file into
8121 the appropriate directory.  The base name of the file is used when
8122 installing.
8123
8124 @example
8125 bin_PROGRAMS = hello subdir/goodbye
8126 @end example
8127
8128 In this example, both @samp{hello} and @samp{goodbye} will be installed
8129 in @samp{$(bindir)}.
8130
8131 Sometimes it is useful to avoid the basename step at install time.  For
8132 instance, you might have a number of header files in subdirectories of
8133 the source tree that are laid out precisely how you want to install
8134 them.  In this situation you can use the @code{nobase_} prefix to
8135 suppress the base name step.  For example:
8136
8137 @example
8138 nobase_include_HEADERS = stdio.h sys/types.h
8139 @end example
8140
8141 @noindent
8142 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8143 in @samp{$(includedir)/sys}.
8144
8145 For most file types, Automake will install multiple files at once, while
8146 avoiding command line length issues (@pxref{Length Limitations}).  Since
8147 some @command{install} programs will not install the same file twice in
8148 one invocation, you may need to ensure that file lists are unique within
8149 one variable such as @samp{nobase_include_HEADERS} above.
8150
8151 You should not rely on the order in which files listed in one variable
8152 are installed.  Likewise, to cater for parallel make, you should not
8153 rely on any particular file installation order even among different
8154 file types (library dependencies are an exception here).
8155
8156
8157 @node The Two Parts of Install
8158 @section The Two Parts of Install
8159
8160 Automake generates separate @code{install-data} and @code{install-exec}
8161 rules, in case the installer is installing on multiple machines that
8162 share directory structure---these targets allow the machine-independent
8163 parts to be installed only once.  @code{install-exec} installs
8164 platform-dependent files, and @code{install-data} installs
8165 platform-independent files.  The @code{install} target depends on both
8166 of these targets.  While Automake tries to automatically segregate
8167 objects into the correct category, the @file{Makefile.am} author is, in
8168 the end, responsible for making sure this is done correctly.
8169 @trindex install-data
8170 @trindex install-exec
8171 @trindex install
8172 @cindex Install, two parts of
8173
8174 Variables using the standard directory prefixes @samp{data},
8175 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8176 @samp{pkgdata}, or @samp{pkginclude} are installed by
8177 @code{install-data}.
8178
8179 Variables using the standard directory prefixes @samp{bin},
8180 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8181 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8182
8183 For instance, @code{data_DATA} files are installed by @code{install-data},
8184 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8185
8186 Any variable using a user-defined directory prefix with
8187 @samp{exec} in the name (e.g.,
8188 @c Keep in sync with primary-prefix-couples-documented-valid.test.
8189 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}.  All
8190 other user-defined prefixes are installed by @code{install-data}.
8191
8192 @node Extending Installation
8193 @section Extending Installation
8194
8195 It is possible to extend this mechanism by defining an
8196 @code{install-exec-local} or @code{install-data-local} rule.  If these
8197 rules exist, they will be run at @samp{make install} time.  These
8198 rules can do almost anything; care is required.
8199 @trindex install-exec-local
8200 @trindex install-data-local
8201
8202 Automake also supports two install hooks, @code{install-exec-hook} and
8203 @code{install-data-hook}.  These hooks are run after all other install
8204 rules of the appropriate type, exec or data, have completed.  So, for
8205 instance, it is possible to perform post-installation modifications
8206 using an install hook.  @xref{Extending}, for some examples.
8207 @cindex Install hook
8208
8209 @node Staged Installs
8210 @section Staged Installs
8211
8212 @vindex DESTDIR
8213 Automake generates support for the @code{DESTDIR} variable in all
8214 install rules.  @code{DESTDIR} is used during the @samp{make install}
8215 step to relocate install objects into a staging area.  Each object and
8216 path is prefixed with the value of @code{DESTDIR} before being copied
8217 into the install area.  Here is an example of typical DESTDIR usage:
8218
8219 @example
8220 mkdir /tmp/staging &&
8221 make DESTDIR=/tmp/staging install
8222 @end example
8223
8224 The @command{mkdir} command avoids a security problem if the attacker
8225 creates a symbolic link from @file{/tmp/staging} to a victim area;
8226 then @command{make} places install objects in a directory tree built under
8227 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8228 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8229 would install @file{/tmp/staging/gnu/bin/foo} and
8230 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8231
8232 This feature is commonly used to build install images and packages
8233 (@pxref{DESTDIR}).
8234
8235 Support for @code{DESTDIR} is implemented by coding it directly into
8236 the install rules.  If your @file{Makefile.am} uses a local install
8237 rule (e.g., @code{install-exec-local}) or an install hook, then you
8238 must write that code to respect @code{DESTDIR}.
8239
8240 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8241 for another usage example.
8242
8243 @node Install Rules for the User
8244 @section Install Rules for the User
8245
8246 Automake also generates rules for targets @code{uninstall},
8247 @code{installdirs}, and @code{install-strip}.
8248 @trindex uninstall
8249 @trindex installdirs
8250 @trindex install-strip
8251
8252 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8253 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8254 these features would not provide additional functionality.
8255
8256 Note that @code{uninstall} is not meant as a replacement for a real
8257 packaging tool.
8258
8259
8260 @node Clean
8261 @chapter What Gets Cleaned
8262
8263 @cindex @samp{make clean} support
8264
8265 The GNU Makefile Standards specify a number of different clean rules.
8266 @xref{Standard Targets, , Standard Targets for Users, standards,
8267 The GNU Coding Standards}.
8268
8269 Generally the files that can be cleaned are determined automatically by
8270 Automake.  Of course, Automake also recognizes some variables that can
8271 be defined to specify additional files to clean.  These variables are
8272 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8273 @code{MAINTAINERCLEANFILES}.
8274 @vindex MOSTLYCLEANFILES
8275 @vindex CLEANFILES
8276 @vindex DISTCLEANFILES
8277 @vindex MAINTAINERCLEANFILES
8278
8279 @trindex mostlyclean-local
8280 @trindex clean-local
8281 @trindex distclean-local
8282 @trindex maintainer-clean-local
8283 When cleaning involves more than deleting some hard-coded list of
8284 files, it is also possible to supplement the cleaning rules with your
8285 own commands.  Simply define a rule for any of the
8286 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8287 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8288 case is deleting a directory, for instance, a directory created by the
8289 test suite:
8290
8291 @example
8292 clean-local:
8293         -rm -rf testSubDir
8294 @end example
8295
8296 Since @command{make} allows only one set of rules for a given target,
8297 a more extensible way of writing this is to use a separate target
8298 listed as a dependency:
8299
8300 @example
8301 clean-local: clean-local-check
8302 .PHONY: clean-local-check
8303 clean-local-check:
8304         -rm -rf testSubDir
8305 @end example
8306
8307 As the GNU Standards aren't always explicit as to which files should
8308 be removed by which rule, we've adopted a heuristic that we believe
8309 was first formulated by Fran@,{c}ois Pinard:
8310
8311 @itemize @bullet
8312 @item
8313 If @command{make} built it, and it is commonly something that one would
8314 want to rebuild (for instance, a @file{.o} file), then
8315 @code{mostlyclean} should delete it.
8316
8317 @item
8318 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8319
8320 @item
8321 If @command{configure} built it, then @code{distclean} should delete it.
8322
8323 @item
8324 If the maintainer built it (for instance, a @file{.info} file), then
8325 @code{maintainer-clean} should delete it.  However
8326 @code{maintainer-clean} should not delete anything that needs to exist
8327 in order to run @samp{./configure && make}.
8328 @end itemize
8329
8330 We recommend that you follow this same set of heuristics in your
8331 @file{Makefile.am}.
8332
8333
8334 @node Dist
8335 @chapter What Goes in a Distribution
8336
8337 @menu
8338 * Basics of Distribution::      Files distributed by default
8339 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8340 * The dist Hook::               A target for last-minute distribution changes
8341 * Checking the Distribution::   @samp{make distcheck} explained
8342 * The Types of Distributions::  A variety of formats and compression methods
8343 @end menu
8344
8345 @node Basics of Distribution
8346 @section Basics of Distribution
8347
8348 @cindex @samp{make dist}
8349
8350 @vindex PACKAGE
8351 @vindex VERSION
8352 @trindex dist
8353 The @code{dist} rule in the generated @file{Makefile.in} can be used
8354 to generate a gzipped @code{tar} file and other flavors of archive for
8355 distribution.  The file is named based on the @code{PACKAGE} and
8356 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8357 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8358 @samp{@var{package}-@var{version}.tar.gz}.
8359 @vindex GZIP_ENV
8360 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8361 is run.  The default setting is @option{--best}.
8362
8363 @cindex @code{m4_include}, distribution
8364 @cindex @code{include}, distribution
8365 @acindex m4_include
8366 @cmindex include
8367 For the most part, the files to distribute are automatically found by
8368 Automake: all source files are automatically included in a distribution,
8369 as are all @file{Makefile.am} and @file{Makefile.in} files.  Automake also
8370 has a built-in list of commonly used files that are automatically
8371 included if they are found in the current directory (either physically,
8372 or as the target of a @file{Makefile.am} rule); this list is printed by
8373 @samp{automake --help}.  Note that some files in this list are actually
8374 distributed only if other certain conditions hold (for example,
8375 @c Keep in sync with autodist-config-headers.test.
8376 the @file{config.h.top} and @file{config.h.bot} files are automatically
8377 distributed only if, e.g., @samp{AC_CONFIG_HEADERS([config.h])} is used
8378 in @file{configure.ac}).  Also, files that are read by @command{configure}
8379 (i.e.@: the source files corresponding to the files specified in various
8380 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8381 automatically distributed.  Files included in a @file{Makefile.am} (using
8382 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8383 helper scripts installed with @samp{automake --add-missing} are also
8384 distributed.
8385
8386 @vindex EXTRA_DIST
8387 Still, sometimes there are files that must be distributed, but which
8388 are not covered in the automatic rules.  These files should be listed in
8389 the @code{EXTRA_DIST} variable.  You can mention files from
8390 subdirectories in @code{EXTRA_DIST}.
8391
8392 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8393 entire directory will be recursively copied into the distribution.
8394 Please note that this will also copy @emph{everything} in the directory,
8395 including, e.g., Subversion's @file{.svn} private directories or CVS/RCS
8396 version control files.  We recommend against using this feature.
8397
8398 @vindex SUBDIRS
8399 @vindex DIST_SUBDIRS
8400 If you define @code{SUBDIRS}, Automake will recursively include the
8401 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8402 conditionally (@pxref{Conditionals}), Automake will normally include
8403 all directories that could possibly appear in @code{SUBDIRS} in the
8404 distribution.  If you need to specify the set of directories
8405 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8406 exact list of subdirectories to include in the distribution
8407 (@pxref{Conditional Subdirectories}).
8408
8409
8410 @node Fine-grained Distribution Control
8411 @section Fine-grained Distribution Control
8412
8413 @vindex dist_
8414 @vindex nodist_
8415 Sometimes you need tighter control over what does @emph{not} go into the
8416 distribution; for instance, you might have source files that are
8417 generated and that you do not want to distribute.  In this case
8418 Automake gives fine-grained control using the @code{dist} and
8419 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8420 prefixed with @code{dist_} to add the listed files to the distribution.
8421 Similarly, @code{nodist_} can be used to omit the files from the
8422 distribution.
8423
8424 As an example, here is how you would cause some data to be distributed
8425 while leaving some source code out of the distribution:
8426
8427 @example
8428 dist_data_DATA = distribute-this
8429 bin_PROGRAMS = foo
8430 nodist_foo_SOURCES = do-not-distribute.c
8431 @end example
8432
8433 @node The dist Hook
8434 @section The dist Hook
8435
8436 @trindex dist-hook
8437
8438 Occasionally it is useful to be able to change the distribution before
8439 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8440 after the distribution directory is filled, but before the actual tar
8441 (or shar) file is created.  One way to use this is for distributing
8442 files in subdirectories for which a new @file{Makefile.am} is overkill:
8443
8444 @example
8445 dist-hook:
8446         mkdir $(distdir)/random
8447         cp -p $(srcdir)/random/a1 $(srcdir)/random/a2 $(distdir)/random
8448 @end example
8449
8450 Another way to use this is for removing unnecessary files that get
8451 recursively included by specifying a directory in EXTRA_DIST:
8452
8453 @example
8454 EXTRA_DIST = doc
8455
8456 dist-hook:
8457         rm -rf `find $(distdir)/doc -type d -name .svn`
8458 @end example
8459
8460 @vindex distdir
8461 @vindex top_distdir
8462 Two variables that come handy when writing @code{dist-hook} rules are
8463 @samp{$(distdir)} and @samp{$(top_distdir)}.
8464
8465 @samp{$(distdir)} points to the directory where the @code{dist} rule
8466 will copy files from the current directory before creating the
8467 tarball.  If you are at the top-level directory, then @samp{distdir =
8468 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8469 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8470 @samp{$(distdir)} can be a relative or absolute path, do not assume
8471 any form.
8472
8473 @samp{$(top_distdir)} always points to the root directory of the
8474 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8475 In the @file{foo/} subdirectory
8476 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8477 @samp{$(top_distdir)} too can be a relative or absolute path.
8478
8479 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8480 (@pxref{Subpackages}), then @samp{$(distdir)} and
8481 @samp{$(top_distdir)} are relative to the package where @samp{make
8482 dist} was run, not to any sub-packages involved.
8483
8484 @node Checking the Distribution
8485 @section Checking the Distribution
8486
8487 @cindex @samp{make distcheck}
8488 @cindex @samp{make distcleancheck}
8489 @vindex distcleancheck_listfiles
8490 @cindex @samp{make distuninstallcheck}
8491 @vindex distuninstallcheck_listfiles
8492
8493 @trindex distcheck
8494 Automake also generates a @code{distcheck} rule that can be of help to
8495 ensure that a given distribution will actually work.  @code{distcheck}
8496 makes a distribution, then tries to do a @code{VPATH} build
8497 (@pxref{VPATH Builds}), run the test suite, and finally make another
8498 tarball to ensure the distribution is self-contained.
8499
8500 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8501 @vindex DISTCHECK_CONFIGURE_FLAGS
8502 Building the package involves running @samp{./configure}.  If you need
8503 to supply additional flags to @command{configure}, define them in the
8504 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8505 @file{Makefile.am}.  The user can still extend or override the flags
8506 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8507 on the command line when invoking @command{make}.
8508
8509 Still, developers are encouraged to strive to make their code buildable
8510 without requiring any special configure option; thus, in general, you
8511 shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}. However, there
8512 might be few scenarios in which the use of this variable is justified.
8513 GNU @command{m4} offers an example.  GNU @command{m4} configures by
8514 default with its experimental and seldom used "changeword" feature
8515 disabled; so in its case it is useful to have @command{make distcheck}
8516 run configure with the @option{--with-changeword} option, to ensure that
8517 the code for changeword support still compiles correctly.
8518 GNU @command{m4} also employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS}
8519 variable to stress-test the use of @option{--program-prefix=g}, since at
8520 one point the @command{m4} build system had a bug where @command{make
8521 installcheck} was wrongly assuming it could blindly test "@command{m4}",
8522 rather than the just-installed "@command{gm4}".
8523
8524 @trindex distcheck-hook
8525 If the @code{distcheck-hook} rule is defined in your top-level
8526 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8527 the new distribution has been unpacked, but before the unpacked copy
8528 is configured and built.  Your @code{distcheck-hook} can do almost
8529 anything, though as always caution is advised.  Generally this hook is
8530 used to check for potential distribution errors not caught by the
8531 standard mechanism.  Note that @code{distcheck-hook} as well as
8532 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8533 are not honored in a subpackage @file{Makefile.am}, but the flags from
8534 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8535 are passed down to the @command{configure} script of the subpackage.
8536
8537 @trindex distcleancheck
8538 @vindex DISTCLEANFILES
8539 @vindex distcleancheck_listfiles
8540 Speaking of potential distribution errors, @code{distcheck} also
8541 ensures that the @code{distclean} rule actually removes all built
8542 files.  This is done by running @samp{make distcleancheck} at the end of
8543 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8544 @code{distclean} and then make sure the build tree has been emptied by
8545 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8546 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8547 variable (@pxref{Clean}).
8548
8549 The @code{distcleancheck} behavior should be OK for most packages,
8550 otherwise you have the possibility to override the definition of
8551 either the @code{distcleancheck} rule, or the
8552 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8553 @code{distcleancheck} completely, add the following rule to your
8554 top-level @file{Makefile.am}:
8555
8556 @example
8557 distcleancheck:
8558         @@:
8559 @end example
8560
8561 If you want @code{distcleancheck} to ignore built files that have not
8562 been cleaned because they are also part of the distribution, add the
8563 following definition instead:
8564
8565 @c Keep in sync with distcleancheck.test.
8566 @example
8567 distcleancheck_listfiles = \
8568   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8569        sh '@{@}' ';'
8570 @end example
8571
8572 The above definition is not the default because it's usually an error if
8573 your Makefiles cause some distributed files to be rebuilt when the user
8574 build the package.  (Think about the user missing the tool required to
8575 build the file; or if the required tool is built by your package,
8576 consider the cross-compilation case where it can't be run.)  There is
8577 an entry in the FAQ about this (@pxref{distcleancheck}), make sure you
8578 read it before playing with @code{distcleancheck_listfiles}.
8579
8580 @code{distcheck} also checks that the @code{uninstall} rule works
8581 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8582 by invoking @samp{make uninstall}, and then it checks the install tree
8583 to see if any files are left over.  This check will make sure that you
8584 correctly coded your @code{uninstall}-related rules.
8585
8586 By default, the checking is done by the @code{distuninstallcheck} rule,
8587 and the list of files in the install tree is generated by
8588 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8589 a shell command to run that prints the list of files to stdout).
8590
8591 Either of these can be overridden to modify the behavior of
8592 @code{distcheck}.  For instance, to disable this check completely, you
8593 would write:
8594
8595 @example
8596 distuninstallcheck:
8597         @@:
8598 @end example
8599
8600 @node The Types of Distributions
8601 @section The Types of Distributions
8602
8603 Automake generates rules to provide archives of the project for
8604 distributions in various formats.  Their targets are:
8605
8606 @table @asis
8607 @vindex BZIP2
8608 @item @code{dist-bzip2}
8609 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8610 frequently smaller than gzipped archives.
8611 By default, this rule makes @samp{bzip2} use a compression option of @option{-9}.
8612 To make it use a different one, set the @env{BZIP2} environment variable.
8613 For example, @samp{make dist-bzip2 BZIP2=-7}.
8614 @trindex dist-bzip2
8615
8616 @item @code{dist-gzip}
8617 Generate a gzip tar archive of the distribution.
8618 @trindex dist-gzip
8619
8620 @item @code{dist-lzip}
8621 Generate an @samp{lzip} tar archive of the distribution.  @command{lzip}
8622 archives are frequently smaller than @command{bzip2}-compressed archives.
8623 @trindex dist-lzip
8624
8625 @item @code{dist-lzma}
8626 Generate an @samp{lzma} tar archive of the distribution.
8627 The @samp{lzma} format is obsolete, you should use the @samp{xz} format
8628 instead. @emph{Support for @samp{lzma}-compressed archives will be
8629 removed in the next major Automake release.}
8630 @trindex dist-lzma
8631
8632 @item @code{dist-shar}
8633 Generate a shar archive of the distribution.
8634 @trindex dist-shar
8635
8636 @vindex XZ_OPT
8637 @item @code{dist-xz}
8638 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8639 archives are frequently smaller than @command{bzip2}-compressed archives.
8640 The @samp{xz} format displaces the obsolete @samp{lzma} format.
8641 By default, this rule makes @samp{xz} use a compression option of
8642 @option{-e}.  To make it use a different one, set the @env{XZ_OPT}
8643 environment variable.  For example, run this command to use the
8644 default compression ratio, but with a progress indicator:
8645 @samp{make dist-xz XZ_OPT=-7e}.
8646 @trindex dist-xz
8647
8648 @item @code{dist-zip}
8649 Generate a zip archive of the distribution.
8650 @trindex dist-zip
8651
8652 @item @code{dist-tarZ}
8653 Generate a compressed tar archive of
8654 the distribution.
8655 @trindex dist-tarZ
8656 @end table
8657
8658 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8659 create archives in all the enabled formats, @ref{Options}.  By
8660 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8661
8662
8663 @node Tests
8664 @chapter Support for test suites
8665
8666 @cindex Test suites
8667 @cindex @code{make check}
8668 @trindex check
8669
8670 Automake can generate code to handle two kinds of test suites.  One is
8671 based on integration with the @command{dejagnu} framework.  The other
8672 (and most used) form is based on the use of generic test scripts, and
8673 its activation is triggered by the definition of the special @code{TESTS}
8674 variable.  This second form allows for various degrees of sophistication
8675 and customization; in particular, it allows for concurrent execution
8676 of test scripts, use of established test protocols such as TAP, and
8677 definition of custom test drivers and test runners.
8678
8679 @noindent
8680 In either case, the testsuite is invoked via @samp{make check}.
8681
8682 @menu
8683 * Generalities about Testing::  Concepts and terminology about testing
8684 * Simple Tests::                Listing test scripts in @code{TESTS}
8685 * Custom Test Drivers::         Writing and using custom test drivers
8686 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
8687 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
8688 * Install Tests::               Running tests on installed packages
8689 @end menu
8690
8691 @node Generalities about Testing
8692 @section Generalities about Testing
8693
8694 The purpose of testing is to determine whether a program or system behaves
8695 as expected (e.g., known inputs produce the expected outputs, error
8696 conditions are correctly handled or reported, and older bugs do not
8697 resurface).
8698
8699 @cindex test case
8700 The minimal unit of testing is usually called @emph{test case}, or simply
8701 @emph{test}.  How a test case is defined or delimited, and even what
8702 exactly @emph{constitutes} a test case, depends heavily on the testing
8703 paradigm and/or framework in use, so we won't attempt any more precise
8704 definition.  The set of the test cases for a given program or system
8705 constitutes its @emph{testsuite}.
8706
8707 @cindex test harness
8708 @cindex testsuite harness
8709 A @emph{test harness} (also @emph{testsuite harness}) is a program or
8710 software component that executes all (or part of) the defined test cases,
8711 analyzes their outcomes, and report or register these outcomes
8712 appropriately.  Again, the details of how this is accomplished (and how
8713 the developer and user can influence it or interface with it) varies
8714 wildly, and we'll attempt no precise definition.
8715
8716 @cindex test pass
8717 @cindex test failure
8718 A test is said to @emph{pass} when it can determine that the condition or
8719 behaviour it means to verify holds, and is said to @emph{fail} when it can
8720 determine that such condition of behaviour does @emph{not} hold.
8721
8722 @cindex test skip
8723 Sometimes, tests can rely on non-portable tools or prerequisites, or
8724 simply make no sense on a given system (for example, a test checking a
8725 Windows-specific feature makes no sense on a GNU/Linux system).  In this
8726 case, accordingly to the definition above, the tests can neither be
8727 considered passed nor failed; instead, they are @emph{skipped} -- i.e.,
8728 they are not run, or their result is anyway ignored for what concerns
8729 the count of failures an successes.  Skips are usually explicitly
8730 reported though, so that the user will be aware that not all of the
8731 testsuite has really run.
8732
8733 @cindex xfail
8734 @cindex expected failure
8735 @cindex expected test failure
8736 @cindex xpass
8737 @cindex unexpected pass
8738 @cindex unexpected test pass
8739 It's not uncommon, especially during early development stages, that some
8740 tests fail for known reasons, and that the developer doesn't want to
8741 tackle these failures immediately (this is especially true when the
8742 failing tests deal with corner cases).  In this situation, the better
8743 policy is to declare that each of those failures is an @emph{expected
8744 failure} (or @emph{xfail}).  In case a test that is expected to fail ends
8745 up passing instead, many testing environments will flag the result as a
8746 special kind of failure called @emph{unexpected pass} (or @emph{xpass}).
8747
8748 @cindex hard error
8749 @cindex Distinction between errors and failures in testsuites
8750 Many testing environments and frameworks distinguish between test failures
8751 and hard errors.  As we've seen, a test failure happens when some invariant
8752 or expected behaviour of the software under test is not met.  An @emph{hard
8753 error} happens when e.g., the set-up of a test case scenario fails, or when
8754 some other unexpected or highly undesirable condition is encountered (for
8755 example, the program under test experiences a segmentation fault).
8756
8757 @emph{TODO}: Links to other test harnesses (esp. those sharing our
8758 terminology)?
8759
8760 @node Simple Tests
8761 @section Simple Tests
8762
8763 @menu
8764 * Scripts-based Testsuites::    Automake-specific concepts and terminology
8765 * Serial Test Harness::         Older (and obsolescent) serial test harness
8766 * Parallel Test Harness::       Generic concurrent test harness
8767 @end menu
8768
8769 @node Scripts-based Testsuites
8770 @subsection Scripts-based Testsuites
8771
8772 If the special variable @code{TESTS} is defined, its value is taken to be
8773 a list of programs or scripts to run in order to do the testing.  Under
8774 the appropriate circumstances, it's possible for @code{TESTS} to list
8775 also data files to be passed to one or more test scripts defined by
8776 different means (the so-called ``log compilers'', @pxref{Parallel Test
8777 Harness}).
8778
8779 Test scripts can be executed serially or concurrently.  Automake
8780 supports both these kinds of test execution, with the serial test harness
8781 being the default (for backward-compatibility reasons only, as its use
8782 is nowadays discouraged).  The concurrent test harness relies on the
8783 concurrence capabilities (if any) offered by the underlying @command{make}
8784 implementation, and can thus only be as good as those are.
8785
8786 By default, only the exit statuses of the test scripts are considered when
8787 determining the testsuite outcome.  But Automake allows also the use of
8788 more complex test protocols, either standard (@pxref{Using the TAP test
8789 protocol}) or custom (@pxref{Custom Test Drivers}).  Note that you can
8790 enable such protocols only when the parallel harness is used: they won't
8791 work with the serial test harness.  In the rest of this section we are
8792 going to concentrate mostly on protocol-less tests, since  we'll have later
8793 a whole section devoted to the use of test protocols (again, @pxref{Custom
8794 Test Drivers}).
8795
8796 @cindex Exit status 77, special interpretation
8797 @cindex Exit status 99, special interpretation
8798 When no test protocol is in use, an exit status of 0 from a test script will
8799 denote a success, an exit status of 77 a skipped test, an exit status of 99
8800 an hard error, and any other exit status will denote a failure.
8801
8802 @cindex Tests, expected failure
8803 @cindex Expected test failure
8804 @vindex XFAIL_TESTS
8805 @vindex DISABLE_HARD_ERRORS
8806 @cindex Disabling hard errors
8807 You may define the variable @code{XFAIL_TESTS} to a list of tests
8808 (usually a subset of @code{TESTS}) that are expected to fail; this will
8809 effectively reverse the result of those tests (with the provision that
8810 skips and hard errors remain untouched).  You may also instruct the
8811 testsuite harness to treat hard errors like simple failures, by defining
8812 the @code{DISABLE_HARD_ERRORS} make variable to a nonempty value.
8813
8814 Note however that, for tests based on more complex test protocols,
8815 the exact effects of @code{XFAIL_TESTS} and @code{DISABLE_HARD_ERRORS}
8816 might change, or they might even have no effect at all (for example,
8817 @c Keep this in sync with tap-no-disable-hard-errors.test.
8818 in tests using TAP, there is not way to disable hard errors, and the
8819 @code{DISABLE_HARD_ERRORS} variable has no effect on them).
8820
8821 @anchor{Testsuite progress on console}
8822 @cindex Testsuite progress on console
8823 The result of each test case run by the scripts in @code{TESTS} will be
8824 printed on standard output, along with the test name.  For test protocols
8825 that allow more test cases per test script (such as TAP), a number,
8826 identifier and/or brief description specific for the single test case is
8827 expected to be printed in addition to the name of the test script.  The
8828 possible results (whose meanings should be clear from the previous
8829 @ref{Generalities about Testing}) are @code{PASS}, @code{FAIL},
8830 @code{SKIP}, @code{XFAIL}, @code{XPASS} and @code{ERROR}.  Here is an
8831 example of output from an hypothetical testsuite that uses both plain
8832 and TAP tests:
8833 @c Keep in sync with tap-doc.test.
8834 @example
8835 PASS: foo.sh
8836 PASS: zardoz.tap 1 - Daemon started
8837 PASS: zardoz.tap 2 - Daemon responding
8838 SKIP: zardoz.tap 3 - Daemon uses /proc # SKIP /proc is not mounted
8839 PASS: zardoz.tap 4 - Daemon stopped
8840 SKIP: bar.sh
8841 PASS: mu.tap 1
8842 XFAIL: mu.tap 2 # TODO frobnication not yet implemented
8843 @end example
8844
8845 @noindent
8846 A testsuite summary (expected to report at least the number of run,
8847 skipped and failed tests) will be printed at the end of the testsuite
8848 run.
8849
8850 @anchor{Simple tests and color-tests}
8851 @vindex AM_COLOR_TESTS
8852 @cindex Colorized testsuite output
8853 If the Automake option @code{color-tests} is used (@pxref{Options})
8854 and standard output is connected to a capable terminal, then the test
8855 results and the summary are colored appropriately.  The user can disable
8856 colored output by setting the @command{make} variable
8857 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8858 terminal with @samp{AM_COLOR_TESTS=always}.  It's also worth noting that
8859 some @command{make} implementations, when used in parallel mode, have
8860 slightly different semantics (@pxref{Parallel make,,, autoconf,
8861 The Autoconf Manual}), which can break the automatic detection of a
8862 connection to a capable terminal.  If this is the case, you'll have to
8863 resort to the use of @samp{AM_COLOR_TESTS=always} in order to have the
8864 testsuite output colorized.
8865
8866 Test programs that need data files should look for them in @code{srcdir}
8867 (which is both a make variable and an environment variable made available
8868 to the tests), so that they work when building in a separate directory
8869 (@pxref{Build Directories, , Build Directories , autoconf,
8870 The Autoconf Manual}), and in particular for the @code{distcheck} rule
8871 (@pxref{Checking the Distribution}).
8872
8873 @vindex TESTS
8874 @vindex TESTS_ENVIRONMENT
8875 @vindex AM_TESTS_ENVIRONMENT
8876 The @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables can
8877 be used to run initialization code and set environment variables for the
8878 test scripts.  The former variable is developer-reserved, and can be
8879 defined in the @file{Makefile.am}, while the latter is reserved for the
8880 user, which can employ it to extend or override the settings in the
8881 former; for this to work portably, however, the contents of a non-empty
8882 @code{AM_TESTS_ENVIRONMENT} @emph{must} be terminated by a semicolon.
8883
8884 @vindex AM_TESTS_FD_REDIRECT
8885 The @code{AM_TESTS_FD_REDIRECT} variable can be used to define file
8886 descriptor redirections for the test scripts.  One might think that
8887 @code{AM_TESTS_ENVIRONMENT} could be used for this purpose, but experience
8888 has shown that doing so portably is practically impossible.  The main
8889 hurdle is constituted by Korn shells, which usually set the close-on-exec
8890 flag on file descriptors opened with the @command{exec} builtin, thus
8891 rendering an idiom like @code{AM_TESTS_ENVIRONMENT = exec 9>&2;}
8892 ineffectual.  This issue also affects some Bourne shells, such as the
8893 HP-UX's @command{/bin/sh},
8894 @c FIXME: should we offer a link to the relevant discussions on the
8895 @c bug-autoconf list?
8896
8897 @c Keep in sync with tests-environment-backcompat.test.
8898 @example
8899 AM_TESTS_ENVIRONMENT = \
8900 ## Some environment initializations are kept in a separate shell
8901 ## file `tests-env.sh', which can make it easier to also run tests
8902 ## from the command line.
8903   . $(srcdir)/tests-env.sh; \
8904 ## On Solaris, prefer more POSIX-compliant versions of the standard
8905 ## tools by default.
8906   if test -d /usr/xpg4/bin; then \
8907     PATH=/usr/xpg4/bin:$$PATH; export PATH; \
8908   fi;
8909 @c $$ restore font-lock
8910 ## With this, the test scripts will be able to print diagnostic
8911 ## messages to the original standard error stream, even if the test
8912 ## driver redirects the stderr of the test scripts to a log file
8913 ## before executing them.
8914 AM_TESTS_FD_REDIRECT = 9>&2
8915 @end example
8916
8917 @noindent
8918 Note however that @code{AM_TESTS_ENVIRONMENT} is, for historical and
8919 implementation reasons, @emph{not} supported by the serial harness
8920 (@pxref{Serial Test Harness}).
8921
8922 Automake ensures that each file listed in @code{TESTS} is built before
8923 it is run; you can list both source and derived programs (or scripts)
8924 in @code{TESTS}; the generated rule will look both in @code{srcdir} and
8925 @file{.}.  For instance, you might want to run a C program as a test.
8926 To do this you would list its name in @code{TESTS} and also in
8927 @code{check_PROGRAMS}, and then specify it as you would any other
8928 program.
8929
8930 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8931 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8932 not during @code{make all}.  You should list there any program needed
8933 by your tests that does not need to be built by @code{make all}.  Note
8934 that @code{check_PROGRAMS} are @emph{not} automatically added to
8935 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8936 by the tests, not the tests themselves.  Of course you can set
8937 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8938
8939 @node Serial Test Harness
8940 @subsection Serial Test Harness
8941
8942 @emph{NOTE:} This harness, while still being the default one, is
8943 obsolescent, and kept mostly for backward-compatibility reasons.
8944 The user is advised to use the parallel test harness instead
8945 (@pxref{Parallel Test Harness}).
8946
8947 The serial harness operates by simply running the tests serially, one at
8948 the time, without any I/O redirection.  It's up to the user to implement
8949 logging of tests' output, if that's requited or desired.
8950 @c TODO: give an example of how this can be done.
8951
8952 For historical and implementation reasons, the @code{AM_TESTS_ENVIRONMENT}
8953 variable is @emph{not} supported by this harness (it will be silently
8954 ignored if defined); only @code{TESTS_ENVIRONMENT} is, and it is to be
8955 considered a developer-reserved variable.  This is done so that, when
8956 using the serial harness, @code{TESTS_ENVIRONMENT} can be defined to an
8957 invocation of an interpreter through which the tests are to be run.
8958 For instance, the following setup may be used to run tests with Perl:
8959
8960 @example
8961 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
8962 TESTS = foo.pl bar.pl baz.pl
8963 @end example
8964
8965 @noindent
8966 It's important to note that the use of @code{TESTS_ENVIRONMENT} endorsed
8967 here would be @emph{invalid} with the parallel harness.  That harness
8968 provides a more elegant way to achieve the same effect, with the further
8969 benefit of freeing the @code{TESTS_ENVIRONMENT} variable for the user
8970 (@pxref{Parallel Test Harness}).
8971
8972 Another, less serious limit of the serial harness is that it doesn't
8973 really distinguish between simple failures and hard errors; this is
8974 due to historical reasons only, and might be fixed in future Automake
8975 versions.
8976
8977 @node Parallel Test Harness
8978 @subsection Parallel Test Harness
8979 @cindex @option{parallel-tests}, Using
8980
8981 The parallel (or concurrent) test harness is enabled by the Automake option
8982 @option{parallel-tests}.  It features automatic collection of the test
8983 scripts output in @file{.log} files, concurrent execution of tests with
8984 @code{make -j}, specification of inter-test dependencies, lazy reruns of
8985 tests that have not completed in a prior run, and hard errors for exceptional
8986 failures.
8987
8988 This harness is still somewhat experimental and may undergo changes in
8989 order to satisfy additional portability requirements.
8990
8991 @anchor{Basics of test metadata}
8992 @vindex TEST_SUITE_LOG
8993 @vindex TESTS
8994 @cindex @file{.log} files
8995 @cindex @file{.trs} files
8996 @cindex test metadata
8997 The parallel test harness operates by defining a set of @command{make}
8998 rules that run the test scripts listed in @code{TESTS}, and, for each
8999 such script, save its output in a corresponding @file{.log} file and
9000 its results (and other ``metadata'', @pxref{API for Custom Test Drivers})
9001 in a corresponding @file{.trs} (as in @b{T}est @b{R}e@b{S}ults) file.
9002 @c We choose the `.trs' extension also because, at the time of writing,
9003 @c it isn't already used for other significant purposes; see e.g.:
9004 @c   - http://filext.com/file-extension/trs
9005 @c   - http://www.file-extensions.org/search/?searchstring=trs
9006 The @file{.log} file will contain all the output emitted by the test on
9007 its standard output and its standard error.  The @file{.trs} file will
9008 contain, among the other things, the results of the test cases run by
9009 the script.
9010
9011 The parallel test harness will also create a summary log file,
9012 @code{TEST_SUITE_LOG}, which defaults to @file{test-suite.log} and requires
9013 a @file{.log} suffix.  This file depends upon all the @file{.log} and
9014 @file{.trs} files created for the test scripts listed in @code{TESTS}.
9015
9016 @vindex VERBOSE
9017 As with the serial harness above, by default one status line is printed
9018 per completed test, and a short summary after the suite has completed.
9019 However, standard output and standard error of the test are redirected
9020 to a per-test log file, so that parallel execution does not produce
9021 intermingled output.  The output from failed tests is collected in the
9022 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
9023 file is output after the summary.
9024 @c FIXME: we should be clearer about what we mean exactly here ...
9025 For best results, the tests should be verbose by default now.
9026
9027 @vindex TEST_EXTENSIONS
9028 @vindex TEST_LOGS
9029 Each couple of @file{.log} and @file{.trs} files is created when the
9030 corresponding test has completed.  The set of log files is listed in
9031 the read-only variable @code{TEST_LOGS}, and defaults to @code{TESTS},
9032 with the executable extension if any (@pxref{EXEEXT}), as well as any
9033 suffix listed in @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
9034 Results are undefined if a test file name ends in several concatenated
9035 suffixes.  @code{TEST_EXTENSIONS} defaults to @file{.test}; it can be
9036 overridden by the user, in which case any extension listed in it must be
9037 constituted by a dot, followed by a non-digit alphabetic character,
9038 followed by any number of alphabetic characters.
9039 @c Keep in sync with test-extensions.test.
9040 For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
9041 while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
9042
9043 @vindex _LOG_COMPILE
9044 @vindex _LOG_COMPILER
9045 @vindex _LOG_FLAGS
9046 @vindex LOG_COMPILE
9047 @vindex LOG_COMPILER
9048 @vindex LOG_FLAGS
9049 @vindex @var{ext}_LOG_COMPILE
9050 @vindex @var{ext}_LOG_COMPILER
9051 @vindex @var{ext}_LOG_FLAGS
9052 @vindex AM_@var{ext}_LOG_FLAGS
9053 @vindex AM_LOG_FLAGS
9054 For tests that match an extension @code{.@var{ext}} listed in
9055 @code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using
9056 the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case
9057 extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow
9058 the user to pass options in @code{@var{ext}_LOG_FLAGS}.  It will cause
9059 all tests with this extension to be called with this runner.  For all
9060 tests without a registered extension, the variables @code{LOG_COMPILER},
9061 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
9062
9063 @c Keep in sync with parallel-tests-log-compiler-example.test.
9064 @example
9065 TESTS = foo.pl bar.py baz
9066 TEST_EXTENSIONS = .pl .py
9067 PL_LOG_COMPILER = $(PERL)
9068 AM_PL_LOG_FLAGS = -w
9069 PY_LOG_COMPILER = $(PYTHON)
9070 AM_PY_LOG_FLAGS = -v
9071 LOG_COMPILER = ./wrapper-script
9072 AM_LOG_FLAGS = -d
9073 @end example
9074
9075 @noindent
9076 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
9077 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
9078 @file{bar.log}, and @file{baz.log}, respectively.  The @file{foo.trs},
9079 @file{bar.trs} and @file{baz.trs} files will be automatically produced
9080 as a side-effect.
9081
9082 It's important to note that, differently from what we've seen for the
9083 serial test harness (@pxref{Parallel Test Harness}), the
9084 @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables
9085 @emph{cannot} be use to define a custom test runner; the
9086 @code{LOG_COMPILER} and @code{LOG_FLAGS} (or their extension-specific
9087 counterparts) should be used instead:
9088
9089 @example
9090 ## This is WRONG!
9091 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib' $(PERL) -Mstrict -w
9092 @end example
9093
9094 @example
9095 ## Do this instead.
9096 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib'; export PERL5LIB;
9097 LOG_COMPILER = $(PERL)
9098 AM_LOG_FLAGS = -Mstrict -w
9099 @end example
9100
9101 By default, the test suite harness will run all tests, but there are
9102 several ways to limit the set of tests that are run:
9103
9104 @itemize @bullet
9105 @item
9106 You can set the @code{TESTS} variable.  For example, you can use a
9107 command like this to run only a subset of the tests:
9108
9109 @example
9110 env TESTS="foo.test bar.test" make -e check
9111 @end example
9112
9113 Note however that the command above will unconditionally overwrite the
9114 @file{test-suite.log} file, thus clobbering the recorded results
9115 of any previous testsuite run.  This might be undesirable for packages
9116 whose testsuite takes long time to execute.  Luckily, this problem can
9117 easily be avoided by overriding also @code{TEST_SUITE_LOG} at runtime;
9118 for example,
9119
9120 @c Keep in sync with parallel-tests-log-override-2.test.
9121 @example
9122 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
9123 @end example
9124
9125 will write the result of the partial testsuite runs to the
9126 @file{partial.log}, without touching @file{test-suite.log}.
9127
9128 @item
9129 You can set the @code{TEST_LOGS} variable.  By default, this variable is
9130 computed at @command{make} run time from the value of @code{TESTS} as
9131 described above.  For example, you can use the following:
9132
9133 @example
9134 set x subset*.log; shift
9135 env TEST_LOGS="foo.log $*" make -e check
9136 @end example
9137
9138 The comments made above about @code{TEST_SUITE_LOG} overriding applies
9139 here too.
9140
9141 @item
9142 @vindex RECHECK_LOGS
9143 @cindex lazy test execution
9144 By default, the test harness removes all old per-test @file{.log} and
9145 @file{.trs} files before it starts running tests to regenerate them.  The
9146 variable @code{RECHECK_LOGS} contains the set of @file{.log} (and, by
9147 implication, @file{.trs}) files which are removed.  @code{RECHECK_LOGS}
9148 defaults to @code{TEST_LOGS}, which means all tests need to be rechecked.
9149 By overriding this variable, you can choose which tests need to be
9150 reconsidered.  For example, you can lazily rerun only those tests which
9151 are outdated, i.e., older than their prerequisite test files, by setting
9152 this variable to the empty value:
9153
9154 @example
9155 env RECHECK_LOGS= make -e check
9156 @end example
9157
9158 @item
9159 @trindex recheck
9160 You can ensure that all tests are rerun which have failed or passed
9161 unexpectedly, by running @code{make recheck} in the test directory.
9162 This convenience target will set @code{RECHECK_LOGS} appropriately
9163 before invoking the main test harness.
9164 @end itemize
9165
9166 @noindent
9167 In order to guarantee an ordering between tests even with @code{make
9168 -j@var{N}}, dependencies between the corresponding @file{.log} files
9169 may be specified through usual @command{make} dependencies.  For example,
9170 the following snippet lets the test named @file{foo-execute.test} depend
9171 upon completion of the test @file{foo-compile.test}:
9172
9173 @example
9174 TESTS = foo-compile.test foo-execute.test
9175 foo-execute.log: foo-compile.log
9176 @end example
9177
9178 @noindent
9179 Please note that this ordering ignores the @emph{results} of required
9180 tests, thus the test @file{foo-execute.test} is run even if the test
9181 @file{foo-compile.test} failed or was skipped beforehand.  Further,
9182 please note that specifying such dependencies currently works only for
9183 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
9184
9185 Tests without such specified dependencies may be run concurrently with
9186 parallel @command{make -j@var{N}}, so be sure they are prepared for
9187 concurrent execution.
9188
9189 @cindex Unit tests
9190 @c Keep in sync with 'parallel-tests-extra-programs.test'.
9191 The combination of lazy test execution and correct dependencies between
9192 tests and their sources may be exploited for efficient unit testing
9193 during development.  To further speed up the edit-compile-test cycle, it
9194 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
9195 instead of with @code{check_PROGRAMS}, as the former allows intertwined
9196 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
9197 not cleaned automatically, @pxref{Uniform}).
9198
9199 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
9200 conditional parts as well as configure substitutions.  In the latter
9201 case, however, certain restrictions apply: substituted test names
9202 must end with a nonempty test suffix like @file{.test}, so that one of
9203 the inference rules generated by @command{automake} can apply.  For
9204 literal test names, @command{automake} can generate per-target rules
9205 to avoid this limitation.
9206
9207 Please note that it is currently not possible to use @code{$(srcdir)/}
9208 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
9209 limitation is necessary to avoid generating test logs in the source tree
9210 and has the unfortunate consequence that it is not possible to specify
9211 distributed tests that are themselves generated by means of explicit
9212 rules, in a way that is portable to all @command{make} implementations
9213 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
9214 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
9215 In case of doubt you may want to require to use GNU @command{make},
9216 or work around the issue with inference rules to generate the tests.
9217
9218 @node Custom Test Drivers
9219 @section Custom Test Drivers
9220
9221 @menu
9222 * Overview of Custom Test Drivers Support::
9223 * Declaring Custom Test Drivers::
9224 * API for Custom Test Drivers::
9225 @end menu
9226
9227 @node Overview of Custom Test Drivers Support
9228 @subsection Overview of Custom Test Drivers Support
9229
9230 Starting from Automake version 1.12, the parallel test harness allows
9231 the package authors to use third-party custom test drivers, in case the
9232 default ones are inadequate for their purposes, or do not support their
9233 testing protocol of choice.
9234
9235 A custom test driver is expected to properly run the test programs passed
9236 to it (including the command-line arguments passed to those programs, if
9237 any), to analyze their execution and outcome, to create the @file{.log}
9238 and @file{.trs} files associated to these test runs, and to display the test
9239 results on the console. It is responsibility of the author of the test
9240 driver to ensure that it implements all the above steps meaningfully and
9241 correctly; Automake isn't and can't be of any help here.  On the other
9242 hand, the Automake-provided code for testsuite summary generation offers
9243 support for test drivers allowing several test results per test script,
9244 if they take care to register such results properly (@pxref{Log files
9245 generation and test results recording}).
9246
9247 The exact details of how test scripts' results are to be determined and
9248 analyzed is left to the individual drivers.  Some drivers might only
9249 consider the test script exit status (this is done for example by the
9250 default test driver used by the parallel test harness, described
9251 in the previous section).  Other drivers might implement more complex and
9252 advanced test protocols, which might require them to parse and interpreter
9253 the output emitted by the test script they're running (examples of such
9254 protocols are TAP and SubUnit).
9255
9256 It's very important to note that, even when using custom test drivers,
9257 most of the infrastructure described in the previous section about the
9258 parallel harness remains in place; this includes:
9259
9260 @itemize
9261 @item
9262 list of test scripts defined in @code{TESTS}, and overridable at
9263 runtime through the redefinition of @code{TESTS} or @code{TEST_LOGS};
9264 @item
9265 concurrency through the use of @command{make}'s option @option{-j};
9266 @item
9267 per-test @file{.log} and @file{.trs} files, and generation of a summary
9268 @file{.log} file from them;
9269 @item
9270 @code{recheck} target, @code{RECHECK_LOGS} variable, and lazy reruns
9271 of tests;
9272 @item
9273 inter-test dependencies;
9274 @item
9275 support for @code{check_*} variables (@code{check_PROGRAMS},
9276 @code{check_LIBRARIES}, ...);
9277 @item
9278 use of @code{VERBOSE} environment variable to get verbose output on
9279 testsuite failures;
9280 @item
9281 definition and honoring of @code{TESTS_ENVIRONMENT},
9282 @code{AM_TESTS_ENVIRONMENT} and @code{AM_TESTS_FD_REDIRECT}
9283 variables;
9284 @item
9285 definition of generic and extension-specific @code{LOG_COMPILER} and
9286 @code{LOG_FLAGS} variables.
9287 @end itemize
9288
9289 @noindent
9290 On the other hand, the exact semantics of how (and if)
9291 @option{color-tests}, @code{XFAIL_TESTS}, and hard errors are supported
9292 and handled is left to the individual test drivers.
9293
9294 @c TODO: We should really add a working example in the doc/ directory,
9295 @c TODO: and reference if from here.
9296
9297 @node Declaring Custom Test Drivers
9298 @subsection Declaring Custom Test Drivers
9299
9300 @vindex _LOG_DRIVER
9301 @vindex _LOG_DRIVER_FLAGS
9302 @vindex LOG_DRIVER
9303 @vindex LOG_DRIVER_FLAGS
9304 @vindex @var{ext}_LOG_DRIVER
9305 @vindex @var{ext}_LOG_DRIVER_FLAGS
9306 @vindex AM_@var{ext}_LOG_DRIVER_FLAGS
9307 @vindex AM_LOG_DRIVER_FLAGS
9308 Custom testsuite drivers are declared by defining the make variables
9309 @code{LOG_DRIVER} or @code{@var{ext}_LOG_DRIVER} (where @var{ext} must
9310 be declared in @code{TEST_EXTENSIONS}).  They must be defined to
9311 programs or scripts that will be used to drive the execution, logging,
9312 and outcome report of the tests with corresponding extensions (or of
9313 those with no registered extension in the case of @code{LOG_DRIVER}).
9314 Clearly, multiple distinct test drivers can be declared in the same
9315 @file{Makefile.am}.  Note moreover that the @code{LOG_DRIVER} variables
9316 are @emph{not} a substitute for the @code{LOG_COMPILER} variables: the
9317 two sets of variables can, and often do, usefully and legitimately
9318 coexist.
9319
9320 @c TODO: We should really be able to point to a clarifying example here!
9321
9322 The developer-reserved variable @code{AM_LOG_DRIVER_FLAGS} and the
9323 user-reserved variable @code{LOG_DRIVER_FLAGS} can be used to define
9324 flags that will be passed to each invocation of @code{LOG_DRIVER},
9325 with the user-defined flags obviously taking precedence over the
9326 developer-reserved ones.  Similarly, for each extension @var{ext}
9327 declared in @code{TEST_EXTENSIONS}, flags listed in
9328 @code{AM_@var{ext}_LOG_DRIVER_FLAGS} and
9329 @code{@var{ext}_LOG_DRIVER_FLAGS} will be passed to
9330 invocations of @code{@var{ext}_LOG_DRIVER}.
9331
9332 @node API for Custom Test Drivers
9333 @subsection API for Custom Test Drivers
9334
9335 Note that @emph{the APIs described here are still highly experimental},
9336 and will very likely undergo tightenings and likely also extensive changes
9337 in the future, to accommodate for new features or to satisfy additional
9338 portability requirements.
9339
9340 The main characteristic of these APIs is that they are designed to share
9341 as much infrastructure, semantics, and implementation details as possible
9342 with the parallel test harness and its default driver.
9343
9344 @menu
9345 * Command-line arguments for test drivers::
9346 * Log files generation and test results recording::
9347 * Testsuite progress output::
9348 @end menu
9349
9350 @node Command-line arguments for test drivers
9351 @subsubsection Command-line arguments for test drivers
9352
9353 A custom driver can rely on various command-line options and arguments
9354 being passed to it automatically by the Automake's @option{parallel-tests}
9355 harness.  It is @emph{mandatory} that it understands all of them (even
9356 if the exact interpretation of the associated semantics can legitimately
9357 change between a test driver and another, and even be a no-op in some
9358 drivers).
9359
9360 @noindent
9361 Here is the list of options:
9362
9363 @table @option
9364 @item --test-name=@var{NAME}
9365 The name of the test, with VPATH prefix (if any) removed.  This can have a
9366 suffix and a directory component (as in e.g., @file{sub/foo.test}), and is
9367 mostly meant to be used in console reports about testsuite advancements and
9368 results (@pxref{Testsuite progress output}).
9369 @item --log-file=@file{@var{PATH}.log}
9370 The @file{.log} file the test driver must create (@pxref{Basics of
9371 test metadata}).  If it has a directory component (as in e.g.,
9372 @file{sub/foo.log}), the test harness will ensure that such directory
9373 exists @emph{before} the test driver is called.
9374 @item --trs-file=@file{@var{PATH}.trs}
9375 The @file{.trs} file the test driver must create (@pxref{Basics of
9376 test metadata}).  If it has a directory component (as in e.g.,
9377 @file{sub/foo.trs}), the test harness will ensure that such directory
9378 exists @emph{before} the test driver is called.
9379 @item --color-tests=@{yes|no@}
9380 Whether the console output should be colorized or not (@pxref{Simple
9381 tests and color-tests}, to learn when this option gets activated and
9382 when it doesn't).
9383 @item --expect-failure=@{yes|no@}
9384 Whether the tested program is expected to fail.
9385 @item --enable-hard-errors=@{yes|no@}
9386 Whether ``hard errors'' in the tested program should be treated differently
9387 from normal failures or not (the default should be @code{yes}).  The exact
9388 meaning of ``hard error'' is highly dependent from the test protocols or
9389 conventions in use.
9390 @item --
9391 Explicitly terminate the list of options.
9392 @end table
9393
9394 @noindent
9395 The first non-option argument passed to the test driver is the program to
9396 be run, and all the following ones are command-line options and arguments
9397 for this program.
9398
9399 Note that the exact semantics attached to the @option{--color-tests},
9400 @option{--expect-failure} and @option{--enable-hard-errors} options are
9401 left up to the individual test drivers.  Still, having a behaviour
9402 compatible or at least similar to that provided by the default
9403 @option{parallel-tests} driver is advised, as that would offer a better
9404 consistency and a more pleasant user experience.
9405
9406 @node Log files generation and test results recording
9407 @subsubsection Log files generation and test results recording
9408
9409 The test driver must correctly generate the files specified by the
9410 @option{--log-file} and @option{--trs-file} option (even when the tested
9411 program fails or crashes).
9412
9413 The @file{.log} file should ideally contain all the output produced by the
9414 tested program, plus optionally other information that might facilitate
9415 debugging or analysis of bug reports.  Apart from that, its format is
9416 basically free.
9417
9418 The @file{.trs} file is used to register some metadata through the use
9419 of custom reStructuredText fields.  This metadata is expected to be
9420 employed in various ways by the parallel test harness; for example, to
9421 count the test results when printing the testsuite summary, or to decide
9422 which tests to re-run upon @command{make reheck}.  Unrecognized metadata
9423 in a @file{.trs} file is currently ignored by the harness, but this might
9424 change in the future. The list of currently recognized metadata follows.
9425
9426 @table @code
9427
9428 @item :test-result:
9429 @cindex Register test result
9430 @cindex Register test case result
9431 @cindex Test result, registering
9432 @cindex Test case result, registering
9433 @cindex @code{:test-result:}
9434 @cindex reStructuredText field, @code{:test-result:}
9435 The test driver must use this field to register the results of @emph{each}
9436 test case run by a test script file.  Several @code{:test-result:} fields
9437 can be present in the same @file{.trs} file; this is done in order to
9438 support test protocols that allow a single test script to run more test
9439 cases.
9440
9441 @c Keep this in sync with lib/am/check-am:$(TEST_SUITE_LOG).
9442 The only recognized test results are currently @code{PASS}, @code{XFAIL},
9443 @code{SKIP}, @code{FAIL}, @code{XPASS} and @code{ERROR}.  These results,
9444 when declared with @code{:test-result:}, can be optionally followed by
9445 text holding the name and/or a brief description of the corresponding
9446 test; the @option{parallel-tests} harness will ignore such extra text when
9447 generating @file{test-suite.log} and preparing the testsuite summary.
9448
9449 @c Keep in sync with 'test-metadata-recheck.test'.
9450 @item @code{:recheck:}
9451 @cindex :recheck:
9452 @cindex reStructuredText field, @code{:recheck:}
9453 If this field is present and defined to @code{no}, then the corresponding
9454 test script will @emph{not} be run upon a @command{make recheck}.  What
9455 happens when two or more @code{:recheck:} fields are present in the same
9456 @file{.trs} file is undefined behaviour.
9457
9458 @c Keep in sync with 'test-metadata-global-log.test'.
9459 @item @code{:copy-in-global-log:}
9460 @cindex :copy-in-global-log:
9461 @cindex reStructuredText field, @code{:copy-in-global-log:}
9462 If this field is present and defined to @code{no}, then the content
9463 of the @file{.log} file will @emph{not} be copied into the global
9464 @file{test-suite.log}.  We allow to forsake such copying because, while
9465 it can be useful in debugging and analysis of bug report, it can also be
9466 just a waste of space in normal situations, e.g., when a test script is
9467 successful.  What happens when two or more @code{:copy-in-global-log:}
9468 fields are present in the same @file{.trs} file is undefined behaviour.
9469
9470 @c Keep in sync with 'test-metadata-global-result.test'.
9471 @item @code{:test-global-result:}
9472 @cindex :test-global-result:
9473 @cindex reStructuredText field, @code{:test-global-result:}
9474 This is used to declare the "global result" of the script.  Currently,
9475 the value of this field is needed only to be reported (more or less
9476 verbatim) in the generated global log file @code{$(TEST_SUITE_LOG)},
9477 so it's quite free-form.  For example, a test script which run 10 test
9478 cases, 6 of which pass and 4 of which are skipped, could reasonably have
9479 a @code{PASS/SKIP} value for this field, while a test script which run
9480 19 successful tests and one failed test could have an @code{ALMOST
9481 PASSED} value.  What happens when two or more @code{:test-global-result:}
9482 fields are present in the same @file{.trs} file is undefined behaviour.
9483 @end table
9484
9485 @noindent
9486 Let's see a small example.  Assume a @file{.trs} file contains the
9487 following lines:
9488
9489 @example
9490 :test-result: PASS server starts
9491 :global-log-copy: no
9492 :test-result: PASS HTTP/1.1 request
9493 :test-result: FAIL HTTP/1.0 request
9494 :recheck: yes
9495 :test-result: SKIP HTTPS request (TLS library wasn't available)
9496 :test-result: PASS server stops
9497 @end example
9498
9499 @noindent
9500 Then the corresponding test script will be re-run by @command{make check},
9501 will contribute with @emph{five} test results to the testsuite summary
9502 (three of these tests being successful, one failed, and one skipped), and
9503 the content of the corresponding @file{.log} file will @emph{not} be
9504 copied in the global log file @file{test-suite.log}.
9505
9506 @node Testsuite progress output
9507 @subsubsection Testsuite progress output
9508
9509 A custom test driver also has the task of displaying, on the standard
9510 output, the test results as soon as they become available.  Depending on
9511 the protocol in use, it can also display the reasons for failures and
9512 skips, and, more generally, any useful diagnostic output (but remember
9513 that each line on the screen is precious, so that cluttering the screen
9514 with overly verbose information is bad idea).  The exact format of this
9515 progress output is left up to the test driver; in fact, a custom test
9516 driver might @emph{theoretically} even decide not to do any such report,
9517 leaving it all to the testsuite summary (that would be a very lousy idea,
9518 of course, and serves only to illustrate the flexibility that is
9519 granted here).
9520
9521 Remember that consistency is good; so, if possible, try to be consistent
9522 with the output of the built-in Automake test drivers, providing a similar
9523 ``look & feel''.  In particular, the testsuite progress output should be
9524 colorized when the @option{--color-tests} is passed to the driver.  On the
9525 other end, if you are using a known and widespread test protocol with
9526 well-established implementations, being consistent with those
9527 implementations' output might be a good idea too.
9528
9529 @c TODO: Give an example, maybe inspired to py.test-style output.
9530 @c TODO: That is a good idea because it shows a test driver that allows
9531 @c TODO: for different levels of verbosity in the progress output (could
9532 @c TODO: be implemented either using a driver cmdline flag, or an
9533 @c TODO: environment variable, or both).
9534
9535 @node Using the TAP test protocol
9536 @section Using the TAP test protocol
9537
9538 @menu
9539 * Introduction to TAP::
9540 * Use TAP with the Automake test harness::
9541 * Incompatibilities with other TAP parsers and drivers::
9542 * Links and external resources on TAP::
9543 @end menu
9544
9545 @node Introduction to TAP
9546 @subsection Introduction to TAP
9547
9548 TAP, the Test Anything Protocol, is a simple text-based interface between
9549 testing modules or programs and a test harness.  The tests (also called
9550 ``TAP producers'' in this context) write test results in a simple format
9551 on standard output; a test harness (also called ``TAP consumer'') will
9552 parse and interpret these results, and properly present them to the user,
9553 and/or register them for later analysis.  The exact details of how this
9554 is accomplished can vary among different test harnesses.  The Automake
9555 parallel harness will present the results on the console in the usual
9556 fashion (@pxref{Testsuite progress on console}), and will use the
9557 @file{.trs} files (@pxref{Basics of test metadata}) to store the test
9558 results and related metadata.  Apart from that, it will try to remain
9559 as much compatible as possible with pre-existing and widespread utilities,
9560 such as the @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9561 @command{prove} utility}, at least for the simpler usages.
9562
9563 TAP started its life as part of the test harness for Perl, but today
9564 it has been (mostly) standardized, and has various independent
9565 implementations in different languages; among them, C, C++, Perl,
9566 Python, PHP, and Java.  For a semi-official specification of the
9567 TAP protocol, please refer to the documentation of
9568 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9569       @samp{Test::Harness::TAP}}.
9570
9571 The most relevant real-world usages of TAP are obviously in the testsuites
9572 of @command{perl} and of many perl modules.  Still, also other important
9573 third-party packages, such as @uref{http://git-scm.com/, @command{git}},
9574 use TAP in their testsuite.
9575
9576 @node Use TAP with the Automake test harness
9577 @subsection Use TAP with the Automake test harness
9578
9579 Currently, the TAP driver that comes with Automake requires a perl
9580 interpreter to work, and requires various by-hand steps on the
9581 developer's part (this should be fixed in future Automake versions).
9582 You'll have grab the @file{tap-driver.pl} script from the Automake
9583 distribution by hand, copy it in your source tree, add code to
9584 @file{configure.ac} to search a perl interpreter and to define the
9585 @code{$(PERL)} variable accordingly, and use the Automake support
9586 for third-party test drivers to instruct the harness to use the
9587 @file{tap-driver.pl} to run your TAP-producing tests.  See the example
9588 below for clarification.
9589
9590 Apart from the options common to all the Automake test drivers
9591 (@pxref{Command-line arguments for test drivers}), the @file{tap-driver.pl}
9592 supports the following options, whose names are chosen for enhanced
9593 compatibility with the @command{prove} utility.
9594
9595 @table @option
9596 @c Keep in sync with 'tap-exit.test' and 'tap-signal.test'.
9597 @item --ignore-exit
9598 Causes the test driver to ignore the exit status of the test scripts;
9599 by default, the driver will report an error if the script exit with a
9600 non-zero status.  This option has effect also
9601 @item --comments
9602 Instruct the test driver to display TAP diagnostic (i.e., lines beginning
9603 with the @samp{#} character) in the testsuite progress output too; by
9604 default, TAP diagnostic is only copied in the @file{.log} file.
9605 @item --no-comments
9606 Revert the effects of @option{--comments}.
9607 @item --merge
9608 Instruct the test driver to merge the test scripts' standard error into
9609 their standard output.  This is necessary if you want to ensure that
9610 diagnostics from the test scripts are displayed in the correct order
9611 relative to test results; this can be of great help in debugging
9612 (especially if your test scripts are shell scripts run with shell
9613 tracing active).  As a downside, this option might cause the test
9614 harness to get confused if anything that appears on standard error
9615 looks like a test result.
9616 @item --no-merge
9617 Revert the effects of @option{--merge}.
9618 @item --diagnostic-string=@var{STRING}
9619 Change the string that introduces TAP diagnostic from the default value
9620 of ``@code{#}'' to @code{@var{STRING}}.  This can be useful if your
9621 TAP-based test scripts produce verbose output on which they have limited
9622 control (because, say, the output comes by other tools invoked in the
9623 scripts), and it might contain text that gets spuriously interpreted as
9624 TAP diagnostic: such an issue can be solved by redefining the string that
9625 activates TAP diagnostic to a value you know won't appear by chance in
9626 the tests' output.  Note however that this feature is non-standard, as
9627 the ``official'' TAP protocol does not allow for such a customization; so
9628 don't use it if you can avoid it.
9629 @end table
9630
9631 @noindent
9632 Here is an example of how the TAP driver can be set up and used.
9633
9634 @c Keep in sync with tap-doc2.test.
9635 @example
9636 % @kbd{cat configure.ac}
9637 AC_INIT([GNU Try Tap], [1.0], [bug-automake@@gnu.org])
9638 AC_CONFIG_AUX_DIR([build-aux])
9639 AM_INIT_AUTOMAKE([foreign parallel-tests -Wall -Werror])
9640 AC_CONFIG_FILES([Makefile])
9641 AC_REQUIRE_AUX_FILE([tap-driver.pl])
9642 AC_PATH_PROG([PERL], [perl])
9643 test -n "$PERL" || AC_MSG_ERROR([perl not found])
9644 $PERL -MTAP::Parser -e 1 || AC_MSG_ERROR([TAP::Parser not found])
9645 AC_OUTPUT
9646
9647 % @kbd{cat Makefile.am}
9648 TEST_LOG_DRIVER = $(PERL) $(srcdir)/build-aux/tap-driver.pl
9649 TESTS = foo.test bar.test baz.test
9650 EXTRA_DIST = $(TESTS)
9651
9652 % @kbd{cat foo.test}
9653 #!/bin/sh
9654 echo 1..4 # Number of tests to be executed.
9655 echo 'ok 1 - Swallows fly'
9656 echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
9657 echo 'ok 3 - Pigs fly # SKIP not enough acid'
9658 echo '# I just love word plays ...'
9659 echo 'ok 4 - Flies fly too :-)'
9660
9661 % @kbd{cat bar.test}
9662 #!/bin/sh
9663 echo 1..3
9664 echo 'not ok 1 - Bummer, this test has failed.'
9665 echo 'ok 2 - This passed though.'
9666 echo 'Bail out! Ennui kicking in, sorry...'
9667 echo 'ok 3 - This will not be seen.'
9668
9669 % @kbd{cat baz.test}
9670 #!/bin/sh
9671 echo 1..1
9672 echo ok 1
9673 # Exit with error, even if all the test case has been successful.
9674 exit 7
9675
9676 % @kbd{cp @var{PREFIX}/share/automake-@var{APIVERSION}/tap-driver.pl .}
9677 % @kbd{autoreconf -vi && ./configure && make check}
9678 ...
9679 PASS: foo.test 1 - Swallows fly
9680 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9681 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9682 PASS: foo.test 4 - Flies fly too :-)
9683 FAIL: bar.test 1 - Bummer, this test has failed.
9684 PASS: bar.test 2 - This passed though.
9685 ERROR: bar.test - Bail out! Ennui kicking in, sorry...
9686 PASS: baz.test 1
9687 ERROR: baz.test - exited with status 7
9688 ...
9689 Please report to bug-automake@@gnu.org
9690 ...
9691 % @kbd{echo exit status: $?}
9692 exit status: 1
9693
9694 @c Keep the "skewed" indentation below, it produces pretty PDF output.
9695 % @kbd{env TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit' \
9696       TESTS='foo.test baz.test' make -e check}
9697 ...
9698 PASS: foo.test 1 - Swallows fly
9699 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9700 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9701 # foo.test: I just love word plays...
9702 PASS: foo.test 4 - Flies fly too :-)
9703 PASS: baz.test 1
9704 ...
9705 % @kbd{echo exit status: $?}
9706 exit status: 0
9707 @end example
9708
9709 @node Incompatibilities with other TAP parsers and drivers
9710 @subsection Incompatibilities with other TAP parsers and drivers
9711
9712 For implementation or historical reasons, the TAP driver and harness as
9713 implemented by Automake have some minors incompatibilities with the
9714 mainstream versions, which you should be aware of.
9715
9716 @itemize @bullet
9717 @item
9718 A @code{Bail out!} directive doesn't stop the whole testsuite, but only
9719 the test script it occurs into.  This doesn't follows TAP specifications,
9720 but on the other hand it maximizes compatibility (and code sharing) with
9721 the ``hard error'' concept of the default @option{parallel-tests} driver.
9722 @item
9723 The @code{version} and @code{pragma} directives are not supported.
9724 @item
9725 The @option{--diagnostic-string} option of out driver allows to modify
9726 the string that introduces TAP diagnostic from the default value
9727 of ``@code{#}''.  The standard TAP protocol has currently no way to
9728 allow this, so if you use it your diagnostic will be lost to more
9729 compliant tools like @command{prove} and @code{Test::Harness}
9730 @item
9731 And there are probably some other small and yet undiscovered
9732 incompatibilities, especially in corner cases or with rare usages.
9733 @end itemize
9734
9735 @node Links and external resources on TAP
9736 @subsection Links and external resources on TAP
9737
9738 @noindent
9739 Here are some links to more extensive official or third-party
9740 documentation and resources about the TAP protocol and related
9741 tools and libraries.
9742 @itemize @bullet
9743 @item
9744 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9745       @samp{Test::Harness::TAP}},
9746 the (mostly) official documentation about the TAP format and protocol.
9747 @item
9748 @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9749       @command{prove}},
9750 the most famous command-line TAP test driver, included in the distribution
9751 of @command{perl} and
9752 @uref{http://search.cpan.org/~andya/Test-Harness/lib/Test/Harness.pm,
9753       @samp{Test::Harness}}.
9754 @item
9755 The @uref{http://testanything.org/wiki/index.php/Main_Page,TAP wiki}.
9756 @item
9757 A ``gentle introduction'' to testing for perl coders:
9758 @uref{http://search.cpan.org/dist/Test-Simple/lib/Test/Tutorial.pod,
9759       @samp{Test::Tutorial}}.
9760 @item
9761 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/Simple.pm,
9762       @samp{Test::Simple}}
9763 and
9764 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/More.pm,
9765       @samp{Test::More}},
9766 the standard perl testing libraries, which are based on TAP.
9767 @item
9768 @uref{http://www.eyrie.org/~eagle/software/c-tap-harness/,C TAP Harness},
9769 a C-based project implementing both a TAP producer and a TAP consumer.
9770 @item
9771 @uref{http://www.tap4j.org/,tap4j},
9772 a Java-based project implementing both a TAP producer and a TAP consumer.
9773 @end itemize
9774
9775 @node DejaGnu Tests
9776 @section DejaGnu Tests
9777
9778 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
9779 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
9780 assumed.  The variable @code{DEJATOOL} is a list of names that are
9781 passed, one at a time, as the @option{--tool} argument to
9782 @command{runtest} invocations; it defaults to the name of the package.
9783
9784 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
9785 @option{--srcdir} flags that are passed to dejagnu by default; this can be
9786 overridden if necessary.
9787 @vindex RUNTESTDEFAULTFLAGS
9788
9789 The variables @code{EXPECT} and @code{RUNTEST} can
9790 also be overridden to provide project-specific values.  For instance,
9791 you will need to do this if you are testing a compiler toolchain,
9792 because the default values do not take into account host and target
9793 names.
9794 @opindex dejagnu
9795 @vindex DEJATOOL
9796 @vindex EXPECT
9797 @vindex RUNTEST
9798
9799 The contents of the variable @code{RUNTESTFLAGS} are passed to the
9800 @code{runtest} invocation.  This is considered a ``user variable''
9801 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
9802 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
9803 @vindex RUNTESTFLAGS
9804 @vindex AM_RUNTESTFLAGS
9805
9806 @cindex @file{site.exp}
9807 Automake will generate rules to create a local @file{site.exp} file,
9808 defining various variables detected by @command{configure}.  This file
9809 is automatically read by DejaGnu.  It is OK for the user of a package
9810 to edit this file in order to tune the test suite.  However this is
9811 not the place where the test suite author should define new variables:
9812 this should be done elsewhere in the real test suite code.
9813 Especially, @file{site.exp} should not be distributed.
9814
9815 Still, if the package author has legitimate reasons to extend
9816 @file{site.exp} at @command{make} time, he can do so by defining
9817 the variable @code{EXTRA_DEJAGNU_SITE_CONFIG}; the files listed
9818 there will be considered @file{site.exp} prerequisites, and their
9819 content will be appended to it (in the same order in which they
9820 appear in @code{EXTRA_DEJAGNU_SITE_CONFIG}).  Note that files are
9821 @emph{not} distributed by default.
9822
9823 For more information regarding DejaGnu test suites, see @ref{Top, , ,
9824 dejagnu, The DejaGnu Manual}.
9825
9826 @node Install Tests
9827 @section Install Tests
9828
9829 The @code{installcheck} target is available to the user as a way to
9830 run any tests after the package has been installed.  You can add tests
9831 to this by writing an @code{installcheck-local} rule.
9832
9833
9834 @node Rebuilding
9835 @chapter Rebuilding Makefiles
9836 @cindex rebuild rules
9837
9838 Automake generates rules to automatically rebuild @file{Makefile}s,
9839 @file{configure}, and other derived files like @file{Makefile.in}.
9840
9841 @acindex AM_MAINTAINER_MODE
9842 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
9843 these automatic rebuilding rules are only enabled in maintainer mode.
9844
9845 @vindex ACLOCAL_AMFLAGS
9846 Sometimes you need to run @command{aclocal} with an argument like
9847 @option{-I} to tell it where to find @file{.m4} files.  Since
9848 sometimes @command{make} will automatically run @command{aclocal}, you
9849 need a way to specify these arguments.  You can do this by defining
9850 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
9851 to @command{aclocal}.  This variable is only useful in the top-level
9852 @file{Makefile.am}.
9853
9854 @vindex CONFIG_STATUS_DEPENDENCIES
9855 @vindex CONFIGURE_DEPENDENCIES
9856 @cindex @file{version.sh}, example
9857 @cindex @file{version.m4}, example
9858
9859 Sometimes it is convenient to supplement the rebuild rules for
9860 @file{configure} or @file{config.status} with additional dependencies.
9861 The variables @code{CONFIGURE_DEPENDENCIES} and
9862 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
9863 dependencies.  These variables should be defined in all
9864 @file{Makefile}s of the tree (because these two rebuild rules are
9865 output in all them), so it is safer and easier to @code{AC_SUBST} them
9866 from @file{configure.ac}.  For instance, the following statement will
9867 cause @file{configure} to be rerun each time @file{version.sh} is
9868 changed.
9869
9870 @example
9871 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
9872 @end example
9873
9874 @noindent
9875 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
9876 is to be used in all @file{Makefile}s, its value must be sensible at
9877 any level in the build hierarchy.
9878
9879 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
9880 @code{CONFIG_STATUS_DEPENDENCIES}.
9881
9882 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
9883 @file{configure} rule, whose effect is to run @command{autoconf}.  This
9884 variable should be seldom used, because @command{automake} already tracks
9885 @code{m4_include}d files.  However it can be useful when playing
9886 tricky games with @code{m4_esyscmd} or similar non-recommendable
9887 macros with side effects.
9888
9889 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
9890 @file{config.status} rule, whose effect is to run @file{configure}.
9891 This variable should therefore carry any non-standard source that may
9892 be read as a side effect of running @command{configure}, like @file{version.sh}
9893 in the example above.
9894
9895 Speaking of @file{version.sh} scripts, we recommend against them
9896 today.  They are mainly used when the version of a package is updated
9897 automatically by a script (e.g., in daily builds).  Here is what some
9898 old-style @file{configure.ac}s may look like:
9899
9900 @example
9901 AC_INIT
9902 . $srcdir/version.sh
9903 AM_INIT_AUTOMAKE([name], $VERSION_NUMBER)
9904 @dots{}
9905 @end example
9906
9907 @noindent
9908 Here, @file{version.sh} is a shell fragment that sets
9909 @code{VERSION_NUMBER}.  The problem with this example is that
9910 @command{automake} cannot track dependencies (listing @file{version.sh}
9911 in @command{CONFIG_STATUS_DEPENDENCIES}, and distributing this file is up
9912 to the user), and that it uses the obsolete form of @code{AC_INIT} and
9913 @code{AM_INIT_AUTOMAKE}.  Upgrading to the new syntax is not
9914 straightforward, because shell variables are not allowed in
9915 @code{AC_INIT}'s arguments.  We recommend that @file{version.sh} be
9916 replaced by an M4 file that is included by @file{configure.ac}:
9917
9918 @example
9919 m4_include([version.m4])
9920 AC_INIT([name], VERSION_NUMBER)
9921 AM_INIT_AUTOMAKE
9922 @dots{}
9923 @end example
9924
9925 @noindent
9926 Here @file{version.m4} could contain something like
9927 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
9928 second form is that @command{automake} will take care of the
9929 dependencies when defining the rebuild rule, and will also distribute
9930 the file automatically.  An inconvenience is that @command{autoconf}
9931 will now be rerun each time the version number is bumped, when only
9932 @file{configure} had to be rerun in the previous setup.
9933
9934
9935 @node Options
9936 @chapter Changing Automake's Behavior
9937
9938 @menu
9939 * Options generalities::        Semantics of Automake option
9940 * List of Automake options::    A comprehensive list of Automake options
9941 @end menu
9942
9943 @node Options generalities
9944 @section Options generalities
9945
9946 Various features of Automake can be controlled by options.  Except where
9947 noted otherwise, options can be specified in one of several ways.  Most
9948 options can be applied on a per-@file{Makefile} basis when listed in a
9949 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
9950 of these options only make sense when specified in the toplevel
9951 @file{Makefile.am} file.  Options are applied globally to all processed
9952 @file{Makefile} files when listed in the first argument of
9953 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
9954 require changes to the @command{configure} script can only be specified
9955 there.  These are annotated below.
9956
9957 As a general rule, options specified in @code{AUTOMAKE_OPTIONS} take
9958 precedence over those specified in @code{AM_INIT_AUTOMAKE}, which in
9959 turn take precedence over those specified on the command line.
9960
9961 Also, some care must be taken about the interactions among strictness
9962 level and warning categories.  As a general rule, strictness-implied
9963 warnings are overridden by those specified by explicit options.  For
9964 example, even if @samp{portability} warnings are disabled by default
9965 in @option{foreign} strictness, an usage like this will end up enabling
9966 them:
9967
9968 @example
9969 AUTOMAKE_OPTIONS = -Wportability foreign
9970 @end example
9971
9972 However, a strictness level specified in a higher-priority context
9973 will override all the explicit warnings specified in a lower-priority
9974 context.  For example, if @file{configure.ac} contains:
9975
9976 @example
9977 AM_INIT_AUTOMAKE([-Wportability])
9978 @end example
9979
9980 @noindent
9981 and @file{Makefile.am} contains:
9982
9983 @example
9984 AUTOMAKE_OPTIONS = foreign
9985 @end example
9986
9987 @noindent
9988 then @samp{portability} warnings will be @emph{disabled} in
9989 @file{Makefile.am}.
9990
9991 @node List of Automake options
9992 @section List of Automake options
9993
9994 @vindex AUTOMAKE_OPTIONS
9995
9996 @table @asis
9997 @item @option{gnits}
9998 @itemx @option{gnu}
9999 @itemx @option{foreign}
10000 @itemx @option{cygnus}
10001 @cindex Option, @option{gnits}
10002 @cindex Option, @option{gnu}
10003 @cindex Option, @option{foreign}
10004 @cindex Option, @option{cygnus}
10005 @opindex gnits
10006 @opindex gnu
10007 @opindex foreign
10008 @opindex cygnus
10009
10010 Set the strictness as appropriate.  The @option{gnits} option also
10011 implies options @option{readme-alpha} and @option{check-news}.
10012
10013 @item @option{check-news}
10014 @cindex Option, @option{check-news}
10015 @opindex check-news
10016 Cause @samp{make dist} to fail unless the current version number appears
10017 in the first few lines of the @file{NEWS} file.
10018
10019 @item @option{color-tests}
10020 @cindex Option, @option{color-tests}
10021 @opindex color-tests
10022 Cause output of the serial and parallel test harnesses (see @ref{Simple
10023 Tests}) and of properly-written custom test drivers (@pxref{Custom Test
10024 Drivers}) to be colorized on capable terminals.
10025
10026 @item @option{dejagnu}
10027 @cindex Option, @option{dejagnu}
10028 @opindex dejagnu
10029 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
10030
10031 @item @option{dist-bzip2}
10032 @cindex Option, @option{dist-bzip2}
10033 @opindex dist-bzip2
10034 Hook @code{dist-bzip2} to @code{dist}.
10035 @trindex dist-bzip2
10036
10037 @item @option{dist-lzip}
10038 @cindex Option, @option{dist-lzip}
10039 @opindex dist-lzip
10040 Hook @code{dist-lzip} to @code{dist}.
10041 @trindex dist-lzip
10042
10043 @item @option{dist-lzma}
10044 @cindex Option, @option{dist-lzma}
10045 @opindex dist-lzma
10046 Hook @code{dist-lzma} to @code{dist}.  Obsoleted by @code{dist-xz}.
10047 @trindex dist-lzma
10048
10049 @item @option{dist-shar}
10050 @cindex Option, @option{dist-shar}
10051 @opindex dist-shar
10052 Hook @code{dist-shar} to @code{dist}.
10053 @trindex dist-shar
10054
10055 @item @option{dist-zip}
10056 @cindex Option, @option{dist-zip}
10057 @opindex dist-zip
10058 Hook @code{dist-zip} to @code{dist}.
10059 @trindex dist-zip
10060
10061 @item @option{dist-tarZ}
10062 @cindex Option, @option{dist-tarZ}
10063 @opindex dist-tarZ
10064 Hook @code{dist-tarZ} to @code{dist}.
10065 @trindex dist-tarZ
10066
10067 @item @option{filename-length-max=99}
10068 @cindex Option, @option{filename-length-max=99}
10069 @opindex filename-length-max=99
10070 Abort if file names longer than 99 characters are found during
10071 @samp{make dist}.  Such long file names are generally considered not to
10072 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
10073 options below.  This option should be used in the top-level
10074 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
10075 @file{configure.ac}, it will be ignored otherwise.  It will also be
10076 ignored in sub-packages of nested packages (@pxref{Subpackages}).
10077
10078 @item @option{no-define}
10079 @cindex Option, @option{no-define}
10080 @opindex no-define
10081 This option is meaningful only when passed as an argument to
10082 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
10083 @code{VERSION} variables from being @code{AC_DEFINE}d.
10084
10085 @item @option{no-dependencies}
10086 @cindex Option, @option{no-dependencies}
10087 @opindex no-dependencies
10088 This is similar to using @option{--ignore-deps} on the command line,
10089 but is useful for those situations where you don't have the necessary
10090 bits to make automatic dependency tracking work
10091 (@pxref{Dependencies}).  In this case the effect is to effectively
10092 disable automatic dependency tracking.
10093
10094 @item @option{no-dist}
10095 @cindex Option, @option{no-dist}
10096 @opindex no-dist
10097 Don't emit any code related to @code{dist} target.  This is useful
10098 when a package has its own method for making distributions.
10099
10100 @item @option{no-dist-gzip}
10101 @cindex Option, @option{no-dist-gzip}
10102 @opindex no-dist-gzip
10103 Do not hook @code{dist-gzip} to @code{dist}.
10104 @trindex no-dist-gzip
10105
10106 @item @option{no-exeext}
10107 @cindex Option, @option{no-exeext}
10108 @opindex no-exeext
10109 If your @file{Makefile.am} defines a rule for target @code{foo}, it
10110 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
10111 necessary when @code{EXEEXT} is found to be empty.  However, by
10112 default @command{automake} will generate an error for this use.  The
10113 @option{no-exeext} option will disable this error.  This is intended for
10114 use only where it is known in advance that the package will not be
10115 ported to Windows, or any other operating system using extensions on
10116 executables.
10117
10118 @item @option{no-installinfo}
10119 @cindex Option, @option{no-installinfo}
10120 @opindex no-installinfo
10121 The generated @file{Makefile.in} will not cause info pages to be built
10122 or installed by default.  However, @code{info} and @code{install-info}
10123 targets will still be available.  This option is disallowed at
10124 @option{gnu} strictness and above.
10125 @trindex info
10126 @trindex install-info
10127
10128 @item @option{no-installman}
10129 @cindex Option, @option{no-installman}
10130 @opindex no-installman
10131 The generated @file{Makefile.in} will not cause man pages to be
10132 installed by default.  However, an @code{install-man} target will still
10133 be available for optional installation.  This option is disallowed at
10134 @option{gnu} strictness and above.
10135 @trindex install-man
10136
10137 @item @option{nostdinc}
10138 @cindex Option, @option{nostdinc}
10139 @opindex nostdinc
10140 This option can be used to disable the standard @option{-I} options that
10141 are ordinarily automatically provided by Automake.
10142
10143 @item @option{no-texinfo.tex}
10144 @cindex Option, @option{no-texinfo.tex}
10145 @opindex no-texinfo.tex
10146 Don't require @file{texinfo.tex}, even if there are texinfo files in
10147 this directory.
10148
10149 @item @option{parallel-tests}
10150 @cindex Option, @option{parallel-tests}
10151 @opindex parallel-tests
10152 Enable test suite harness for @code{TESTS} that can run tests in parallel
10153 (@pxref{Parallel Test Harness}, for more information).
10154
10155 @item @option{readme-alpha}
10156 @cindex Option, @option{readme-alpha}
10157 @opindex readme-alpha
10158 If this release is an alpha release, and the file @file{README-alpha}
10159 exists, then it will be added to the distribution.  If this option is
10160 given, version numbers are expected to follow one of two forms.  The
10161 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
10162 element is a number; the final period and number should be left off for
10163 non-alpha releases.  The second form is
10164 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
10165 letter; it should be omitted for non-alpha releases.
10166
10167 @item @option{silent-rules}
10168 @cindex Option, @option{silent-rules}
10169 @opindex silent-rules
10170 Enable less verbose build rules.  This can be used to let build rules
10171 output status lines of the form:
10172 @example
10173 GEN @var{output-file}
10174  CC @var{object-file}
10175 @end example
10176 @noindent
10177 instead of printing the command that will be executed to update
10178 @var{output-file} or to compile @var{object-file}.  It can also
10179 silence @command{libtool} output.
10180
10181 For more information about how to use, enable, or disable silent
10182 rules, @pxref{Automake silent-rules Option}.
10183
10184 @item @option{std-options}
10185 @cindex Options, @option{std-options}
10186 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
10187 @cindex @option{--help} check
10188 @cindex @option{--version} check
10189 @opindex std-options
10190
10191 Make the @code{installcheck} rule check that installed scripts and
10192 programs support the @option{--help} and @option{--version} options.
10193 This also provides a basic check that the program's
10194 run-time dependencies are satisfied after installation.
10195
10196 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
10197 In a few situations, programs (or scripts) have to be exempted from this
10198 test.  For instance, @command{false} (from GNU coreutils) is never
10199 successful, even for @option{--help} or @option{--version}.  You can list
10200 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
10201 Programs (not scripts) listed in this variable should be suffixed by
10202 @samp{$(EXEEXT)} for the sake of Windows or OS/2.  For instance, suppose we
10203 build @file{false} as a program but @file{true.sh} as a script, and that
10204 neither of them support @option{--help} or @option{--version}:
10205
10206 @example
10207 AUTOMAKE_OPTIONS = std-options
10208 bin_PROGRAMS = false ...
10209 bin_SCRIPTS = true.sh ...
10210 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
10211 @end example
10212
10213 @item @option{subdir-objects}
10214 @cindex Options, @option{subdir-objects}
10215 @opindex subdir-objects
10216 If this option is specified, then objects are placed into the
10217 subdirectory of the build directory corresponding to the subdirectory of
10218 the source file.  For instance, if the source file is
10219 @file{subdir/file.cxx}, then the output file would be
10220 @file{subdir/file.o}.
10221
10222 In order to use this option with C sources, you should add
10223 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
10224
10225 @anchor{tar-formats}
10226 @item @option{tar-v7}
10227 @itemx @option{tar-ustar}
10228 @itemx @option{tar-pax}
10229 @cindex Option, @option{tar-v7}
10230 @cindex Option, @option{tar-ustar}
10231 @cindex Option, @option{tar-pax}
10232 @cindex @command{tar} formats
10233 @cindex v7 @command{tar} format
10234 @cindex ustar format
10235 @cindex pax format
10236 @opindex tar-v7
10237 @opindex tar-ustar
10238 @opindex tar-pax
10239
10240 These three mutually exclusive options select the tar format to use
10241 when generating tarballs with @samp{make dist}.  (The tar file created
10242 is then compressed according to the set of @option{no-dist-gzip},
10243 @option{dist-bzip2}, @option{dist-lzip}, @option{dist-xz} and
10244 @option{dist-tarZ} options in use.)
10245
10246 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
10247 (@pxref{Macros}) because they can require additional configure checks.
10248 Automake will complain if it sees such options in an
10249 @code{AUTOMAKE_OPTIONS} variable.
10250
10251 @option{tar-v7} selects the old V7 tar format.  This is the historical
10252 default.  This antiquated format is understood by all tar
10253 implementations and supports file names with up to 99 characters.  When
10254 given longer file names some tar implementations will diagnose the
10255 problem while other will generate broken tarballs or use non-portable
10256 extensions.  Furthermore, the V7 format cannot store empty
10257 directories.  When using this format, consider using the
10258 @option{filename-length-max=99} option to catch file names too long.
10259
10260 @option{tar-ustar} selects the ustar format defined by POSIX
10261 1003.1-1988.  This format is believed to be old enough to be portable.
10262 It fully supports empty directories.  It can store file names with up
10263 to 256 characters, provided that the file name can be split at
10264 directory separator in two parts, first of them being at most 155
10265 bytes long.  So, in most cases the maximum file name length will be
10266 shorter than 256 characters.  However you may run against broken tar
10267 implementations that incorrectly handle file names longer than 99
10268 characters (please report them to @email{@value{PACKAGE_BUGREPORT}} so we
10269 can document this accurately).
10270
10271 @option{tar-pax} selects the new pax interchange format defined by POSIX
10272 1003.1-2001.  It does not limit the length of file names.  However,
10273 this format is very young and should probably be restricted to
10274 packages that target only very modern platforms.  There are moves to
10275 change the pax format in an upward-compatible way, so this option may
10276 refer to a more recent version in the future.
10277
10278 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
10279 further discussion about tar formats.
10280
10281 @command{configure} knows several ways to construct these formats.  It
10282 will not abort if it cannot find a tool up to the task (so that the
10283 package can still be built), but @samp{make dist} will fail.
10284
10285 @item @var{version}
10286 @cindex Option, @var{version}
10287 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
10288 newer than the version specified, creation of the @file{Makefile.in}
10289 will be suppressed.
10290
10291 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
10292 @cindex Option, warnings
10293 @cindex Option, @option{-W@var{category}}
10294 @cindex Option, @option{--warnings=@var{category}}
10295 These options behave exactly like their command-line counterpart
10296 (@pxref{automake Invocation}).  This allows you to enable or disable some
10297 warning categories on a per-file basis.  You can also setup some warnings
10298 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
10299 in your @file{configure.ac}.
10300
10301 @end table
10302
10303 Unrecognized options are diagnosed by @command{automake}.
10304
10305 If you want an option to apply to all the files in the tree, you can use
10306 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
10307 @xref{Macros}.
10308
10309
10310 @node Miscellaneous
10311 @chapter Miscellaneous Rules
10312
10313 There are a few rules and variables that didn't fit anywhere else.
10314
10315 @menu
10316 * Tags::                        Interfacing to cscope, etags and mkid
10317 * Suffixes::                    Handling new file extensions
10318 @end menu
10319
10320
10321 @node Tags
10322 @section Interfacing to @command{etags}
10323
10324 @cindex @file{TAGS} support
10325
10326 Automake will generate rules to generate @file{TAGS} files for use with
10327 GNU Emacs under some circumstances.
10328
10329 @trindex tags
10330 If any C, C++ or Fortran 77 source code or headers are present, then
10331 @code{tags} and @code{TAGS} rules will be generated for the directory.
10332 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
10333 @code{_LISP} primaries will be used to generate tags.  Note that
10334 generated source files that are not distributed must be declared in
10335 variables like @code{nodist_noinst_HEADERS} or
10336 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
10337
10338 A @code{tags} rule will be output at the topmost directory of a
10339 multi-directory package.  When run from this topmost directory,
10340 @samp{make tags} will generate a @file{TAGS} file that includes by
10341 reference all @file{TAGS} files from subdirectories.
10342
10343 The @code{tags} rule will also be generated if the variable
10344 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
10345 directories that contain taggable source that @command{etags} does
10346 not understand.  The user can use the @code{ETAGSFLAGS} to pass
10347 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
10348 available for use in @file{Makefile.am}.
10349 @vindex ETAGS_ARGS
10350 @vindex ETAGSFLAGS
10351 @vindex AM_ETAGSFLAGS
10352
10353 Here is how Automake generates tags for its source, and for nodes in its
10354 Texinfo file:
10355
10356 @example
10357 ETAGS_ARGS = automake.in --lang=none \
10358  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
10359 @end example
10360
10361 If you add file names to @code{ETAGS_ARGS}, you will probably also
10362 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
10363 are added directly to the dependencies for the @code{tags} rule.
10364 @vindex TAGS_DEPENDENCIES
10365
10366 Automake also generates a @code{ctags} rule that can be used to
10367 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
10368 is the name of the program to invoke (by default @command{ctags});
10369 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
10370 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
10371
10372 Automake will also generate an @code{ID} rule that will run
10373 @command{mkid} on the source.  This is only supported on a
10374 directory-by-directory basis.
10375 @trindex id
10376
10377 Similarly, the @code{cscope} rule will create a list of all the source
10378 files in the tree and run @command{cscope} to build an inverted index
10379 database.  The variable @code{CSCOPE} is the name of the program to invoke
10380 (by default @command{cscope}); @code{CSCOPEFLAGS} and
10381 @code{CSCOPE_ARGS} can be used by the user to pass additional flags and
10382 file names respectively, while @code{AM_CSCOPEFLAGS} can be used by the
10383 @file{Makefile.am}.
10384
10385 Finally, Automake also emits rules to support the
10386 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
10387 The @code{GTAGS} rule runs Global Tags and puts the
10388 result in the top build directory.  The variable @code{GTAGS_ARGS}
10389 holds arguments that are passed to @command{gtags}.
10390 @vindex GTAGS_ARGS
10391
10392
10393 @node Suffixes
10394 @section Handling new file extensions
10395
10396 @cindex Adding new @code{SUFFIXES}
10397 @cindex @code{SUFFIXES}, adding
10398 @vindex SUFFIXES
10399
10400 It is sometimes useful to introduce a new implicit rule to handle a file
10401 type that Automake does not know about.
10402
10403 For instance, suppose you had a compiler that could compile @file{.foo}
10404 files to @file{.o} files.  You would simply define a suffix rule for
10405 your language:
10406
10407 @example
10408 .foo.o:
10409         foocc -c -o $@@ $<
10410 @end example
10411
10412 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
10413 variable and expect the correct results:
10414
10415 @example
10416 bin_PROGRAMS = doit
10417 doit_SOURCES = doit.foo
10418 @end example
10419
10420 This was the simpler and more common case.  In other cases, you will
10421 have to help Automake to figure out which extensions you are defining your
10422 suffix rule for.  This usually happens when your extension does not
10423 start with a dot.  Then, all you have to do is to put a list of new
10424 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
10425 implicit rule.
10426
10427 For instance, the following definition prevents Automake from misinterpreting
10428 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
10429 @file{.cpp} files.
10430
10431 @c Keep in sync with suffix7.test.
10432 @example
10433 SUFFIXES = .idl C.cpp
10434 .idlC.cpp:
10435         # whatever
10436 @end example
10437
10438 As you may have noted, the @code{SUFFIXES} variable behaves like the
10439 @code{.SUFFIXES} special target of @command{make}.  You should not touch
10440 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
10441 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
10442 @code{SUFFIXES} go at the start of the generated suffixes list, followed
10443 by Automake generated suffixes not already in the list.
10444
10445 @node Include
10446 @chapter Include
10447
10448 @cmindex include
10449 @cindex Including @file{Makefile} fragment
10450 @cindex @file{Makefile} fragment, including
10451
10452 Automake supports an @code{include} directive that  can be used to
10453 include other @file{Makefile} fragments when @command{automake} is run.
10454 Note that these fragments are read and interpreted by @command{automake},
10455 not by @command{make}.  As with conditionals, @command{make} has no idea that
10456 @code{include} is in use.
10457
10458 There are two forms of @code{include}:
10459
10460 @table @code
10461 @item include $(srcdir)/file
10462 Include a fragment that is found relative to the current source
10463 directory.
10464
10465 @item include $(top_srcdir)/file
10466 Include a fragment that is found relative to the top source directory.
10467 @end table
10468
10469 Note that if a fragment is included inside a conditional, then the
10470 condition applies to the entire contents of that fragment.
10471
10472 Makefile fragments included this way are always distributed because
10473 they are needed to rebuild @file{Makefile.in}.
10474
10475 @node Conditionals
10476 @chapter Conditionals
10477
10478 @cindex Conditionals
10479
10480 Automake supports a simple type of conditionals.
10481
10482 These conditionals are not the same as conditionals in
10483 GNU Make.  Automake conditionals are checked at configure time by the
10484 @file{configure} script, and affect the translation from
10485 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
10486 to @file{configure} and on results that @file{configure} has discovered
10487 about the host system.  GNU Make conditionals are checked at @command{make}
10488 time, and are based on variables passed to the make program or defined
10489 in the @file{Makefile}.
10490
10491 Automake conditionals will work with any make program.
10492
10493 @menu
10494 * Usage of Conditionals::       Declaring conditional content
10495 * Limits of Conditionals::      Enclosing complete statements
10496 @end menu
10497
10498 @node Usage of Conditionals
10499 @section Usage of Conditionals
10500
10501 @acindex AM_CONDITIONAL
10502 Before using a conditional, you must define it by using
10503 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
10504
10505 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
10506 The conditional name, @var{conditional}, should be a simple string
10507 starting with a letter and containing only letters, digits, and
10508 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
10509 that are reserved by Automake.
10510
10511 The shell @var{condition} (suitable for use in a shell @code{if}
10512 statement) is evaluated when @command{configure} is run.  Note that you
10513 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
10514 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
10515 conditionally (e.g., in a shell @code{if} statement), then the result
10516 will confuse @command{automake}.
10517 @end defmac
10518
10519 @cindex @option{--enable-debug}, example
10520 @cindex Example conditional @option{--enable-debug}
10521 @cindex Conditional example, @option{--enable-debug}
10522
10523 Conditionals typically depend upon options that the user provides to
10524 the @command{configure} script.  Here is an example of how to write a
10525 conditional that is true if the user uses the @option{--enable-debug}
10526 option.
10527
10528 @example
10529 AC_ARG_ENABLE([debug],
10530 [  --enable-debug    Turn on debugging],
10531 [case "$@{enableval@}" in
10532   yes) debug=true ;;
10533   no)  debug=false ;;
10534   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
10535 esac],[debug=false])
10536 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
10537 @end example
10538
10539 Here is an example of how to use that conditional in @file{Makefile.am}:
10540
10541 @cmindex if
10542 @cmindex endif
10543 @cmindex else
10544
10545 @example
10546 if DEBUG
10547 DBG = debug
10548 else
10549 DBG =
10550 endif
10551 noinst_PROGRAMS = $(DBG)
10552 @end example
10553
10554 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
10555 (@pxref{Conditional Programs}).
10556
10557 You may only test a single variable in an @code{if} statement, possibly
10558 negated using @samp{!}.  The @code{else} statement may be omitted.
10559 Conditionals may be nested to any depth.  You may specify an argument to
10560 @code{else} in which case it must be the negation of the condition used
10561 for the current @code{if}.  Similarly you may specify the condition
10562 that is closed on the @code{endif} line:
10563
10564 @example
10565 if DEBUG
10566 DBG = debug
10567 else !DEBUG
10568 DBG =
10569 endif !DEBUG
10570 @end example
10571
10572 @noindent
10573 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
10574 @code{endif} statements should not be indented, i.e., start on column
10575 one.
10576
10577 The @code{else} branch of the above two examples could be omitted,
10578 since assigning the empty string to an otherwise undefined variable
10579 makes no difference.
10580
10581 @acindex AM_COND_IF
10582 In order to allow access to the condition registered by
10583 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
10584 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
10585
10586 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
10587 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
10588 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
10589 it will cause @command{automake} to output the rules for the respective
10590 files only for the given condition.
10591 @end defmac
10592
10593 @code{AM_COND_IF} macros may be nested when m4 quotation is used
10594 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
10595
10596 @cindex Example conditional @code{AC_CONFIG_FILES}
10597 @cindex @code{AC_CONFIG_FILES}, conditional
10598
10599 Here is an example of how to define a conditional config file:
10600
10601 @example
10602 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
10603 AM_COND_IF([SHELL_WRAPPER],
10604            [AC_CONFIG_FILES([wrapper:wrapper.in])])
10605 @end example
10606
10607 @node Limits of Conditionals
10608 @section Limits of Conditionals
10609
10610 Conditionals should enclose complete statements like variables or
10611 rules definitions.  Automake cannot deal with conditionals used inside
10612 a variable definition, for instance, and is not even able to diagnose
10613 this situation.  The following example would not work:
10614
10615 @example
10616 # This syntax is not understood by Automake
10617 AM_CPPFLAGS = \
10618   -DFEATURE_A \
10619 if WANT_DEBUG
10620   -DDEBUG \
10621 endif
10622   -DFEATURE_B
10623 @end example
10624
10625 However the intended definition of @code{AM_CPPFLAGS} can be achieved
10626 with
10627
10628 @example
10629 if WANT_DEBUG
10630   DEBUGFLAGS = -DDEBUG
10631 endif
10632 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
10633 @end example
10634
10635 @noindent
10636 or
10637
10638 @example
10639 AM_CPPFLAGS = -DFEATURE_A
10640 if WANT_DEBUG
10641 AM_CPPFLAGS += -DDEBUG
10642 endif
10643 AM_CPPFLAGS += -DFEATURE_B
10644 @end example
10645
10646 More details and examples of conditionals are described alongside
10647 various Automake features in this manual (@pxref{Conditional
10648 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
10649 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
10650 Libtool Sources}).
10651
10652 @node Silencing Make
10653 @chapter Silencing @command{make}
10654
10655 @cindex Silent @command{make}
10656 @cindex Silencing @command{make}
10657 @cindex Silent rules
10658 @cindex Silent @command{make} rules
10659
10660 @menu
10661 * Make verbosity::               Make is verbose by default
10662 * Tricks For Silencing Make::    Standard and generic ways to silence make
10663 * Automake silent-rules Option:: How Automake can help in silencing make
10664 @end menu
10665
10666 @node Make verbosity
10667 @section Make is verbose by default
10668
10669 Normally, when executing the set of rules associated with a target,
10670 @command{make} prints each rule before it is executed.  This behaviour,
10671 while having been in place for a long time, and being even mandated by
10672 the POSIX standard, starkly violates the ``silence is golden'' UNIX
10673 principle@footnote{See also
10674 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
10675
10676 @quotation
10677 When a program has nothing interesting or surprising to say, it should
10678 say nothing.  Well-behaved Unix programs do their jobs unobtrusively,
10679 with a minimum of fuss and bother.  Silence is golden.
10680 @end quotation
10681
10682 In fact, while such verbosity of @command{make} can theoretically be
10683 useful to track bugs and understand reasons of failures right away, it
10684 can also hide warning and error messages from @command{make}-invoked
10685 tools, drowning them in a flood of uninteresting and seldom useful
10686 messages, and thus allowing them to go easily undetected.
10687
10688 This problem can be very annoying, especially for developers, who usually
10689 know quite well what's going on behind the scenes, and for whom the
10690 verbose output from @command{make} ends up being mostly noise that hampers
10691 the easy detection of potentially important warning messages.
10692
10693 @node Tricks For Silencing Make
10694 @section Standard and generic ways to silence make
10695
10696 Here we describe some common idioms/tricks to obtain a quieter make
10697 output, with their relative advantages and drawbacks.  In the next
10698 section (@ref{Automake silent-rules Option}) we'll see how Automake
10699 can help in this respect.
10700
10701 @itemize @bullet
10702
10703 @item @command{make -s}
10704
10705 This simply causes @command{make} not to print @emph{any} rule before
10706 executing it.
10707
10708 The @option{-s} flag is mandated by POSIX, universally supported, and
10709 its purpose and function are easy to understand.
10710
10711 But it also has its serious limitations too.  First of all, it embodies
10712 an ``all or nothing'' strategy, i.e., either everything is silenced, or
10713 nothing is; this lack of granularity can sometimes be a fatal flaw.
10714 Moreover, when the @option{-s} flag is used, the @command{make} output
10715 might turn out to be too much terse; in case of errors, the user won't
10716 be able to easily see what rule or command have caused them, or even,
10717 in case of tools with poor error reporting, what the errors were!
10718
10719 @item @command{make >/dev/null || make}
10720
10721 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
10722 from stderr are passed through, output reporting is done only in case of
10723 error, and in that case it should provide a verbose-enough report to allow
10724 an easy determination of the error location and causes.
10725
10726 However, calling @command{make} two times in a row might hide errors
10727 (especially intermittent ones), or subtly change the expected semantic
10728 of the @command{make} calls --- things these which can clearly make
10729 debugging and error assessment very difficult.
10730
10731 @item @command{make --no-print-directory}
10732
10733 This is GNU @command{make} specific.  When called with the
10734 @option{--no-print-directory} option, GNU @command{make} will disable
10735 printing of the working directory by invoked sub-@command{make}s (the
10736 well-known ``@i{Entering/Leaving directory ...}'' messages).  This helps
10737 to decrease the verbosity of the output, but experience has shown that
10738 it can also often render debugging considerably harder in projects using
10739 deeply-nested @command{make} recursion.
10740
10741 As an aside, notice that the @option{--no-print-directory} option is
10742 automatically activated if the @option{-s} flag is used.
10743
10744 @c TODO: Other tricks?
10745 @c TODO: Maybe speak about the @code{.SILENT} target?
10746 @c TODO:  - Pros: More granularity on what to silence.
10747 @c TODO:  - Cons: No easy way to temporarily override.
10748
10749 @end itemize
10750
10751 @node Automake silent-rules Option
10752 @section How Automake can help in silencing make
10753
10754 The tricks and idioms for silencing @command{make} described in the
10755 previous section can be useful from time to time, but we've seen that
10756 they all have their serious drawbacks and limitations.  That's why
10757 automake provides support for a more advanced and flexible way of
10758 obtaining quieter output from @command{make}: the @option{silent-rules}
10759 mode.
10760
10761 @c TODO: Maybe describe in brief the precedent set by the build system
10762 @c of the Linux Kernel, from which Automake took inspiration ... Links?
10763
10764 To give the gist of what @option{silent-rules} can do, here is a simple
10765 comparison between a typical @command{make} output (where silent rules
10766 are disabled) and one with silent rules enabled:
10767
10768 @example
10769 % @kbd{cat Makefile.am}
10770 bin_PROGRAMS = foo
10771 foo_SOURCES = main.c func.c
10772 % @kbd{cat main.c}
10773 int main (void) @{ return func (); @}  /* func used undeclared */
10774 % @kbd{cat func.c}
10775 int func (void) @{ int i; return i; @} /* i used uninitialized */
10776
10777 @i{The make output is by default very verbose.  This causes warnings
10778 from the compiler to be somewhat hidden, and not immediate to spot.}
10779 % @kbd{make CFLAGS=-Wall}
10780 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10781 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10782 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
10783 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
10784 main.c: In function â€˜main’:
10785 main.c:3:3: warning: implicit declaration of function â€˜func’
10786 mv -f .deps/main.Tpo .deps/main.Po
10787 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10788 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10789 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
10790 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
10791 func.c: In function â€˜func’:
10792 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10793 mv -f .deps/func.Tpo .deps/func.Po
10794 gcc -Wall -o foo main.o func.o
10795
10796 @i{Clean up, so that we we can rebuild everything from scratch.}
10797 % @kbd{make clean}
10798 test -z "foo" || rm -f foo
10799 rm -f *.o
10800
10801 @i{Silent rules enabled: the output is minimal but informative.  In
10802 particular, the warnings from the compiler stick out very clearly.}
10803 % @kbd{make V=0 CFLAGS=-Wall}
10804   CC     main.o
10805 main.c: In function â€˜main’:
10806 main.c:3:3: warning: implicit declaration of function â€˜func’
10807   CC     func.o
10808 func.c: In function â€˜func’:
10809 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10810   CCLD   foo
10811 @end example
10812
10813 @cindex silent-rules and libtool
10814 Also, in projects using @command{libtool}, the use of silent rules can
10815 automatically enable the @command{libtool}'s @option{--silent} option:
10816
10817 @example
10818 % @kbd{cat Makefile.am}
10819 lib_LTLIBRARIES = libx.la
10820
10821 % @kbd{make # Both make and libtool are verbose by default.}
10822 ...
10823 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
10824   -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
10825   -DPIC -o .libs/libx.o
10826 mv -f .deps/libx.Tpo .deps/libx.Plo
10827 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
10828   /usr/local/lib libx.lo
10829 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
10830   -o .libs/libx.so.0.0.0
10831 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
10832 ...
10833
10834 % @kbd{make V=0}
10835   CC     libx.lo
10836   CCLD   libx.la
10837 @end example
10838
10839 Let's now see how the @option{silent-rules} mode interfaces with the
10840 package developer and the package user.
10841
10842 To enable the use of @option{silent-rules} in his package, a developer
10843 needs to do either of the following:
10844
10845 @itemize @bullet
10846 @item
10847 Add the @option{silent-rules} option as argument to @code{AM_INIT_AUTOMAKE}.
10848 @item
10849 Call the @code{AM_SILENT_RULES} macro from within the @file{configure.ac}
10850 file.
10851 @end itemize
10852
10853 It is not possible to instead specify @option{silent-rules} in a
10854 @file{Makefile.am} file.
10855
10856 If the developer has done either of the above, then the user of the
10857 package may influence the verbosity at @command{configure} run time as
10858 well as at @command{make} run time:
10859
10860 @itemize @bullet
10861 @item
10862 @opindex --enable-silent-rules
10863 @opindex --disable-silent-rules
10864 Passing @option{--enable-silent-rules} to @command{configure} will cause
10865 build rules to be less verbose; the option @option{--disable-silent-rules}
10866 will cause normal verbose output.
10867 @item
10868 @vindex @code{V}
10869 At @command{make} run time, the default chosen at @command{configure}
10870 time may be overridden: @code{make V=1} will produce verbose output,
10871 @code{make V=0} less verbose output.
10872 @end itemize
10873
10874 @cindex default verbosity for silent-rules
10875 Note that silent rules are @emph{disabled} by default; the user must
10876 enable them explicitly at either @command{configure} run time or at
10877 @command{make} run time.  We think that this is a good policy, since
10878 it provides the casual user with enough information to prepare a good
10879 bug report in case anything breaks.
10880
10881 Still, notwithstanding the rationales above, a developer who wants to
10882 make silent rules enabled by default in his own package can do so by
10883 adding a @samp{yes} argument to the @code{AM_SILENT_RULES} call in
10884 @file{configure.ac}.  We advise against this approach, though.
10885
10886 @c Keep in sync with silent-configsite.test
10887 Users who prefer to have silent rules enabled by default can edit their
10888 @file{config.site} file to make the variable @code{enable_silent_rules}
10889 default to @samp{yes}.  This should still allow disabling silent rules
10890 at @command{configure} time and at @command{make} time.
10891
10892 @c FIXME: there's really a need to specify this explicitly?
10893 For portability to different @command{make} implementations, package authors
10894 are advised to not set the variable @code{V} inside the @file{Makefile.am}
10895 file, to allow the user to override the value for subdirectories as well.
10896
10897 The current implementation of this feature normally uses nested
10898 variable expansion @samp{$(@var{var1}$(V))}, a @file{Makefile} feature
10899 that is not required by POSIX 2008 but is widely supported in
10900 practice.  The @option{silent-rules} option thus turns off warnings
10901 about recursive variable expansion, which are in turn enabled by
10902 @option{-Wportability} (@pxref{automake Invocation}).  On the rare
10903 @command{make} implementations that do not support nested variable
10904 expansion, whether rules are silent is always determined at configure
10905 time, and cannot be overridden at make time.  Future versions of POSIX
10906 are likely to require nested variable expansion, so this minor
10907 limitation should go away with time.
10908
10909 @vindex @code{AM_V_GEN}
10910 @vindex @code{AM_V_at}
10911 @vindex @code{AM_DEFAULT_VERBOSITY}
10912 @vindex @code{AM_V}
10913 @vindex @code{AM_DEFAULT_V}
10914 To extend the silent mode to your own rules, you have two choices:
10915
10916 @itemize @bullet
10917 @item
10918 You can use the predefined variable @code{AM_V_GEN} as a prefix to
10919 commands that should output a status line in silent mode, and
10920 @code{AM_V_at} as a prefix to commands that should not output anything
10921 in silent mode.  When output is to be verbose, both of these variables
10922 will expand to the empty string.
10923 @item
10924 You can add your own variables, so strings of your own choice are shown.
10925 The following snippet shows how you would define your own equivalent of
10926 @code{AM_V_GEN}:
10927
10928 @example
10929 pkg_verbose = $(pkg_verbose_@@AM_V@@)
10930 pkg_verbose_ = $(pkg_verbose_@@AM_DEFAULT_V@@)
10931 pkg_verbose_0 = @@echo PKG-GEN $@@;
10932
10933 foo: foo.in
10934         $(pkg_verbose)cp $(srcdir)/foo.in $@@
10935 @end example
10936
10937 @end itemize
10938
10939 As a final note, observe that, even when silent rules are enabled,
10940 the @option{--no-print-directory} option is still required with GNU
10941 @command{make} if the ``@i{Entering/Leaving directory ...}'' messages
10942 are to be disabled.
10943
10944 @node Gnits
10945 @chapter The effect of @option{--gnu} and @option{--gnits}
10946
10947 @cindex @option{--gnu}, required files
10948 @cindex @option{--gnu}, complete description
10949
10950 The @option{--gnu} option (or @option{gnu} in the
10951 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
10952 the following:
10953
10954 @itemize @bullet
10955 @item
10956 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
10957 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
10958 or @file{COPYING}, are required at the topmost directory of the package.
10959
10960 If the @option{--add-missing} option is given, @command{automake} will
10961 add a generic version of the @file{INSTALL} file as well as the
10962 @file{COPYING} file containing the text of the current version of the
10963 GNU General Public License existing at the time of this Automake release
10964 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
10965 However, an existing @file{COPYING} file will never be overwritten by
10966 @command{automake}.
10967
10968 @item
10969 The options @option{no-installman} and @option{no-installinfo} are
10970 prohibited.
10971 @end itemize
10972
10973 Note that this option will be extended in the future to do even more
10974 checking; it is advisable to be familiar with the precise requirements
10975 of the GNU standards.  Also, @option{--gnu} can require certain
10976 non-standard GNU programs to exist for use by various maintainer-only
10977 rules; for instance, in the future @command{pathchk} might be required for
10978 @samp{make dist}.
10979
10980 @cindex @option{--gnits}, complete description
10981
10982 The @option{--gnits} option does everything that @option{--gnu} does, and
10983 checks the following as well:
10984
10985 @itemize @bullet
10986 @item
10987 @samp{make installcheck} will check to make sure that the @option{--help}
10988 and @option{--version} really print a usage message and a version string,
10989 respectively.  This is the @option{std-options} option (@pxref{Options}).
10990
10991 @item
10992 @samp{make dist} will check to make sure the @file{NEWS} file has been
10993 updated to the current version.
10994
10995 @item
10996 @code{VERSION} is checked to make sure its format complies with Gnits
10997 standards.
10998 @c FIXME xref when standards are finished
10999
11000 @item
11001 @cindex @file{README-alpha}
11002 If @code{VERSION} indicates that this is an alpha release, and the file
11003 @file{README-alpha} appears in the topmost directory of a package, then
11004 it is included in the distribution.  This is done in @option{--gnits}
11005 mode, and no other, because this mode is the only one where version
11006 number formats are constrained, and hence the only mode where Automake
11007 can automatically determine whether @file{README-alpha} should be
11008 included.
11009
11010 @item
11011 The file @file{THANKS} is required.
11012 @end itemize
11013
11014
11015 @node Cygnus
11016 @chapter The effect of @option{--cygnus}
11017
11018 @cindex @option{cygnus} strictness
11019
11020 Some packages, notably GNU GCC and GNU gdb, have a build environment
11021 originally written at Cygnus Support (subsequently renamed Cygnus
11022 Solutions, and then later purchased by Red Hat).  Packages with this
11023 ancestry are sometimes referred to as ``Cygnus'' trees.
11024
11025 A Cygnus tree has slightly different rules for how a
11026 @file{Makefile.in} is to be constructed.  Passing @option{--cygnus} to
11027 @command{automake} will cause any generated @file{Makefile.in} to
11028 comply with Cygnus rules.
11029
11030 Here are the precise effects of @option{--cygnus}:
11031
11032 @itemize @bullet
11033 @item
11034 Info files are always created in the build directory, and not in the
11035 source directory.
11036
11037 @item
11038 @file{texinfo.tex} is not required if a Texinfo source file is
11039 specified.  The assumption is that the file will be supplied, but in a
11040 place that Automake cannot find.  This assumption is an artifact of how
11041 Cygnus packages are typically bundled.
11042
11043 @item
11044 @samp{make dist} is not supported, and the rules for it are not
11045 generated.  Cygnus-style trees use their own distribution mechanism.
11046
11047 @item
11048 Certain tools will be searched for in the build tree as well as in the
11049 user's @env{PATH}.  These tools are @command{runtest}, @command{expect},
11050 @command{makeinfo} and @command{texi2dvi}.
11051
11052 @item
11053 @option{--foreign} is implied.
11054
11055 @item
11056 The options @option{no-installinfo} and @option{no-dependencies} are
11057 implied.
11058
11059 @item
11060 The macro @code{AM_MAINTAINER_MODE} is required.
11061
11062 @item
11063 The @code{check} target doesn't depend on @code{all}.
11064 @end itemize
11065
11066 GNU maintainers are advised to use @option{gnu} strictness in preference
11067 to the special Cygnus mode.  Some day, perhaps, the differences between
11068 Cygnus trees and GNU trees will disappear (for instance, as GCC is made
11069 more standards compliant).  At that time the special Cygnus mode will be
11070 removed.
11071
11072
11073 @node Not Enough
11074 @chapter When Automake Isn't Enough
11075
11076 In some situations, where Automake is not up to one task, one has to
11077 resort to handwritten rules or even handwritten @file{Makefile}s.
11078
11079 @menu
11080 * Extending::                   Adding new rules or overriding existing ones.
11081 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
11082 @end menu
11083
11084 @node Extending
11085 @section Extending Automake Rules
11086
11087 With some minor exceptions (for example @code{_PROGRAMS} variables,
11088 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
11089 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
11090 @file{Makefile.in} verbatim.
11091
11092 @cindex copying semantics
11093
11094 These copying semantics mean that many problems can be worked around
11095 by simply adding some @command{make} variables and rules to
11096 @file{Makefile.am}.  Automake will ignore these additions.
11097
11098 @cindex conflicting definitions
11099 @cindex rules, conflicting
11100 @cindex variables, conflicting
11101 @cindex definitions, conflicts
11102
11103 Since a @file{Makefile.in} is built from data gathered from three
11104 different places (@file{Makefile.am}, @file{configure.ac}, and
11105 @command{automake} itself), it is possible to have conflicting
11106 definitions of rules or variables.  When building @file{Makefile.in}
11107 the following priorities are respected by @command{automake} to ensure
11108 the user always has the last word:
11109
11110 @itemize
11111 @item
11112 User defined variables in @file{Makefile.am} have priority over
11113 variables @code{AC_SUBST}ed from @file{configure.ac}, and
11114 @code{AC_SUBST}ed variables have priority over
11115 @command{automake}-defined variables.
11116 @item
11117 As far as rules are concerned, a user-defined rule overrides any
11118 @command{automake}-defined rule for the same target.
11119 @end itemize
11120
11121 @cindex overriding rules
11122 @cindex overriding semantics
11123 @cindex rules, overriding
11124
11125 These overriding semantics make it possible to fine tune some default
11126 settings of Automake, or replace some of its rules.  Overriding
11127 Automake rules is often inadvisable, particularly in the topmost
11128 directory of a package with subdirectories.  The @option{-Woverride}
11129 option (@pxref{automake Invocation}) comes in handy to catch overridden
11130 definitions.
11131
11132 Note that Automake does not make any distinction between rules with
11133 commands and rules that only specify dependencies.  So it is not
11134 possible to append new dependencies to an @command{automake}-defined
11135 target without redefining the entire rule.
11136
11137 @cindex @option{-local} targets
11138 @cindex local targets
11139
11140 However, various useful targets have a @samp{-local} version you can
11141 specify in your @file{Makefile.am}.  Automake will supplement the
11142 standard target with these user-supplied targets.
11143
11144 @trindex  all
11145 @trindex  all-local
11146 @trindex  info
11147 @trindex  info-local
11148 @trindex  dvi
11149 @trindex  dvi-local
11150 @trindex  ps
11151 @trindex  ps-local
11152 @trindex  pdf
11153 @trindex  pdf-local
11154 @trindex  html
11155 @trindex  html-local
11156 @trindex  check
11157 @trindex  check-local
11158 @trindex  install
11159 @trindex  install-data
11160 @trindex  install-data-local
11161 @trindex  install-dvi
11162 @trindex  install-dvi-local
11163 @trindex  install-exec
11164 @trindex  install-exec-local
11165 @trindex  install-html
11166 @trindex  install-html-local
11167 @trindex  install-info
11168 @trindex  install-info-local
11169 @trindex  install-pdf
11170 @trindex  install-pdf-local
11171 @trindex  install-ps
11172 @trindex  install-ps-local
11173 @trindex  uninstall
11174 @trindex  uninstall-local
11175 @trindex  mostlyclean
11176 @trindex  mostlyclean-local
11177 @trindex  clean
11178 @trindex  clean-local
11179 @trindex  distclean
11180 @trindex  distclean-local
11181 @trindex  installdirs
11182 @trindex  installdirs-local
11183 @trindex  installcheck
11184 @trindex  installcheck-local
11185
11186 The targets that support a local version are @code{all}, @code{info},
11187 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
11188 @code{install-data}, @code{install-dvi}, @code{install-exec},
11189 @code{install-html}, @code{install-info}, @code{install-pdf},
11190 @code{install-ps}, @code{uninstall}, @code{installdirs},
11191 @code{installcheck} and the various @code{clean} targets
11192 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
11193 @code{maintainer-clean}).
11194
11195 Note that there are no @code{uninstall-exec-local} or
11196 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
11197 It doesn't make sense to uninstall just data or just executables.
11198
11199 For instance, here is one way to erase a subdirectory during
11200 @samp{make clean} (@pxref{Clean}).
11201
11202 @example
11203 clean-local:
11204         -rm -rf testSubDir
11205 @end example
11206
11207 You may be tempted to use @code{install-data-local} to install a file
11208 to some hard-coded location, but you should avoid this
11209 (@pxref{Hard-Coded Install Paths}).
11210
11211 With the @code{-local} targets, there is no particular guarantee of
11212 execution order; typically, they are run early, but with parallel
11213 make, there is no way to be sure of that.
11214
11215 @cindex @option{-hook} targets
11216 @cindex hook targets
11217 @trindex install-data-hook
11218 @trindex install-exec-hook
11219 @trindex uninstall-hook
11220 @trindex dist-hook
11221
11222 In contrast, some rules also have a way to run another rule, called a
11223 @dfn{hook}; hooks are always executed after the main rule's work is done.
11224 The hook is named after the principal target, with @samp{-hook} appended.
11225 The targets allowing hooks are @code{install-data},
11226 @code{install-exec}, @code{uninstall}, @code{dist}, and
11227 @code{distcheck}.
11228
11229 For instance, here is how to create a hard link to an installed program:
11230
11231 @example
11232 install-exec-hook:
11233         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
11234            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
11235 @end example
11236
11237 Although cheaper and more portable than symbolic links, hard links
11238 will not work everywhere (for instance, OS/2 does not have
11239 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
11240 @command{ln} does not work.  An easy way, if symbolic links are
11241 acceptable to you, is to add @code{AC_PROG_LN_S} to
11242 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
11243 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
11244 @file{Makefile.am}.
11245
11246 @cindex versioned binaries, installing
11247 @cindex installing versioned binaries
11248 @cindex @code{LN_S} example
11249 For instance, here is how you could install a versioned copy of a
11250 program using @samp{$(LN_S)}:
11251
11252 @c Keep in sync with insthook.test
11253 @example
11254 install-exec-hook:
11255         cd $(DESTDIR)$(bindir) && \
11256           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
11257           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
11258 @end example
11259
11260 Note that we rename the program so that a new version will erase the
11261 symbolic link, not the real binary.  Also we @command{cd} into the
11262 destination directory in order to create relative links.
11263
11264 When writing @code{install-exec-hook} or @code{install-data-hook},
11265 please bear in mind that the exec/data distinction is based on the
11266 installation directory, not on the primary used (@pxref{The Two Parts of
11267 Install}).
11268 @c Keep in sync with primary-prefix-couples-documented-valid.test.
11269 So a @code{foo_SCRIPTS} will be installed by
11270 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
11271 @code{install-exec}.  You should define your hooks consequently.
11272
11273 @c FIXME should include discussion of variables you can use in these
11274 @c rules
11275
11276 @node Third-Party Makefiles
11277 @section Third-Party @file{Makefile}s
11278
11279 @cindex Third-party packages, interfacing with
11280 @cindex Interfacing with third-party packages
11281
11282 In most projects all @file{Makefile}s are generated by Automake.  In
11283 some cases, however, projects need to embed subdirectories with
11284 handwritten @file{Makefile}s.  For instance, one subdirectory could be
11285 a third-party project with its own build system, not using Automake.
11286
11287 It is possible to list arbitrary directories in @code{SUBDIRS} or
11288 @code{DIST_SUBDIRS} provided each of these directories has a
11289 @file{Makefile} that recognizes all the following recursive targets.
11290
11291 @cindex recursive targets and third-party @file{Makefile}s
11292 When a user runs one of these targets, that target is run recursively
11293 in all subdirectories.  This is why it is important that even
11294 third-party @file{Makefile}s support them.
11295
11296 @table @code
11297 @item all
11298 Compile the entire package.  This is the default target in
11299 Automake-generated @file{Makefile}s, but it does not need to be the
11300 default in third-party @file{Makefile}s.
11301
11302 @item distdir
11303 @trindex distdir
11304 @vindex distdir
11305 @vindex top_distdir
11306 Copy files to distribute into @samp{$(distdir)}, before a tarball is
11307 constructed.  Of course this target is not required if the
11308 @option{no-dist} option (@pxref{Options}) is used.
11309
11310 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
11311 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
11312 when the @code{distdir} target is invoked.  These two variables have
11313 been adjusted for the directory that is being recursed into, so they
11314 are ready to use.
11315
11316 @item install
11317 @itemx install-data
11318 @itemx install-exec
11319 @itemx uninstall
11320 Install or uninstall files (@pxref{Install}).
11321
11322 @item install-dvi
11323 @itemx install-html
11324 @itemx install-info
11325 @itemx install-ps
11326 @itemx install-pdf
11327 Install only some specific documentation format (@pxref{Texinfo}).
11328
11329 @item installdirs
11330 Create install directories, but do not install any files.
11331
11332 @item check
11333 @itemx installcheck
11334 Check the package (@pxref{Tests}).
11335
11336 @item mostlyclean
11337 @itemx clean
11338 @itemx distclean
11339 @itemx maintainer-clean
11340 Cleaning rules (@pxref{Clean}).
11341
11342 @item dvi
11343 @itemx pdf
11344 @itemx ps
11345 @itemx info
11346 @itemx html
11347 Build the documentation in various formats (@pxref{Texinfo}).
11348
11349 @item tags
11350 @itemx ctags
11351 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
11352 @end table
11353
11354 If you have ever used Gettext in a project, this is a good example of
11355 how third-party @file{Makefile}s can be used with Automake.  The
11356 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
11357 @file{intl/} directories are handwritten @file{Makefile}s that
11358 implement all these targets.  That way they can be added to
11359 @code{SUBDIRS} in Automake packages.
11360
11361 Directories that are only listed in @code{DIST_SUBDIRS} but not in
11362 @code{SUBDIRS} need only the @code{distclean},
11363 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
11364 Subdirectories}).
11365
11366 Usually, many of these rules are irrelevant to the third-party
11367 subproject, but they are required for the whole package to work.  It's
11368 OK to have a rule that does nothing, so if you are integrating a
11369 third-party project with no documentation or tag support, you could
11370 simply augment its @file{Makefile} as follows:
11371
11372 @example
11373 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
11374 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
11375 $(EMPTY_AUTOMAKE_TARGETS):
11376 @end example
11377
11378 Another aspect of integrating third-party build systems is whether
11379 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
11380 subpackage does not support VPATH builds the whole package will not
11381 support VPATH builds.  This in turns means that @samp{make distcheck}
11382 will not work, because it relies on VPATH builds.  Some people can
11383 live without this (actually, many Automake users have never heard of
11384 @samp{make distcheck}).  Other people may prefer to revamp the
11385 existing @file{Makefile}s to support VPATH@.  Doing so does not
11386 necessarily require Automake, only Autoconf is needed (@pxref{Build
11387 Directories, , Build Directories, autoconf, The Autoconf Manual}).
11388 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
11389 and @samp{@@top_builddir@@} are defined by @file{configure} when it
11390 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
11391 Output Variables, autoconf, The Autoconf Manual}), they are not
11392 computed by the Makefile like the aforementioned @samp{$(distdir)} and
11393 @samp{$(top_distdir)} variables.
11394
11395 It is sometimes inconvenient to modify a third-party @file{Makefile}
11396 to introduce the above required targets.  For instance, one may want to
11397 keep the third-party sources untouched to ease upgrades to new
11398 versions.
11399
11400 @cindex @file{GNUmakefile} including @file{Makefile}
11401 Here are two other ideas.  If GNU make is assumed, one possibility is
11402 to add to that subdirectory a @file{GNUmakefile} that defines the
11403 required targets and includes the third-party @file{Makefile}.  For
11404 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
11405 directory; the easiest way to do this is to write a
11406 @file{GNUmakefile.in} instead, and have it processed with
11407 @code{AC_CONFIG_FILES} from the outer package.  For example if we
11408 assume @file{Makefile} defines all targets except the documentation
11409 targets, and that the @code{check} target is actually called
11410 @code{test}, we could write @file{GNUmakefile} (or
11411 @file{GNUmakefile.in}) like this:
11412
11413 @example
11414 # First, include the real Makefile
11415 include Makefile
11416 # Then, define the other targets needed by Automake Makefiles.
11417 .PHONY: dvi pdf ps info html check
11418 dvi pdf ps info html:
11419 check: test
11420 @end example
11421
11422 @cindex Proxy @file{Makefile} for third-party packages
11423 A similar idea that does not use @code{include} is to write a proxy
11424 @file{Makefile} that dispatches rules to the real @file{Makefile},
11425 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
11426 it's OK to rename the original @file{Makefile}) or with @samp{cd
11427 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
11428 subdirectory project one directory deeper).  The good news is that
11429 this proxy @file{Makefile} can be generated with Automake.  All we
11430 need are @option{-local} targets (@pxref{Extending}) that perform the
11431 dispatch.  Of course the other Automake features are available, so you
11432 could decide to let Automake perform distribution or installation.
11433 Here is a possible @file{Makefile.am}:
11434
11435 @example
11436 all-local:
11437         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
11438 check-local:
11439         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
11440 clean-local:
11441         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
11442
11443 # Assuming the package knows how to install itself
11444 install-data-local:
11445         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
11446 install-exec-local:
11447         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
11448 uninstall-local:
11449         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
11450
11451 # Distribute files from here.
11452 EXTRA_DIST = subdir/Makefile subdir/program.c ...
11453 @end example
11454
11455 Pushing this idea to the extreme, it is also possible to ignore the
11456 subproject build system and build everything from this proxy
11457 @file{Makefile.am}.  This might sound very sensible if you need VPATH
11458 builds but the subproject does not support them.
11459
11460 @node Distributing
11461 @chapter Distributing @file{Makefile.in}s
11462
11463 Automake places no restrictions on the distribution of the resulting
11464 @file{Makefile.in}s.  We still encourage software authors to
11465 distribute their work under terms like those of the GPL, but doing so
11466 is not required to use Automake.
11467
11468 Some of the files that can be automatically installed via the
11469 @option{--add-missing} switch do fall under the GPL@.  However, these also
11470 have a special exception allowing you to distribute them with your
11471 package, regardless of the licensing you choose.
11472
11473
11474 @node API Versioning
11475 @chapter Automake API Versioning
11476
11477 New Automake releases usually include bug fixes and new features.
11478 Unfortunately they may also introduce new bugs and incompatibilities.
11479 This makes four reasons why a package may require a particular Automake
11480 version.
11481
11482 Things get worse when maintaining a large tree of packages, each one
11483 requiring a different version of Automake.  In the past, this meant that
11484 any developer (and sometimes users) had to install several versions of
11485 Automake in different places, and switch @samp{$PATH} appropriately for
11486 each package.
11487
11488 Starting with version 1.6, Automake installs versioned binaries.  This
11489 means you can install several versions of Automake in the same
11490 @samp{$prefix}, and can select an arbitrary Automake version by running
11491 @command{automake-1.6} or @command{automake-1.7} without juggling with
11492 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
11493 will use @command{automake-1.6} explicitly in their rebuild rules.
11494
11495 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
11496 not Automake's version.  If a bug fix release is made, for instance
11497 Automake 1.6.1, the API version will remain 1.6.  This means that a
11498 package that works with Automake 1.6 should also work with 1.6.1; after
11499 all, this is what people expect from bug fix releases.
11500
11501 If your package relies on a feature or a bug fix introduced in
11502 a release, you can pass this version as an option to Automake to ensure
11503 older releases will not be used.  For instance, use this in your
11504 @file{configure.ac}:
11505
11506 @example
11507   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
11508 @end example
11509
11510 @noindent
11511 or, in a particular @file{Makefile.am}:
11512
11513 @example
11514   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
11515 @end example
11516
11517 @noindent
11518 Automake will print an error message if its version is
11519 older than the requested version.
11520
11521
11522 @heading What is in the API
11523
11524 Automake's programming interface is not easy to define.  Basically it
11525 should include at least all @strong{documented} variables and targets
11526 that a @file{Makefile.am} author can use, any behavior associated with
11527 them (e.g., the places where @samp{-hook}'s are run), the command line
11528 interface of @command{automake} and @command{aclocal}, @dots{}
11529
11530 @heading What is not in the API
11531
11532 Every undocumented variable, target, or command line option, is not part
11533 of the API@.  You should avoid using them, as they could change from one
11534 version to the other (even in bug fix releases, if this helps to fix a
11535 bug).
11536
11537 If it turns out you need to use such an undocumented feature, contact
11538 @email{automake@@gnu.org} and try to get it documented and exercised by
11539 the test-suite.
11540
11541 @node Upgrading
11542 @chapter Upgrading a Package to a Newer Automake Version
11543
11544 Automake maintains three kind of files in a package.
11545
11546 @itemize
11547 @item @file{aclocal.m4}
11548 @item @file{Makefile.in}s
11549 @item auxiliary tools like @file{install-sh} or @file{py-compile}
11550 @end itemize
11551
11552 @file{aclocal.m4} is generated by @command{aclocal} and contains some
11553 Automake-supplied M4 macros.  Auxiliary tools are installed by
11554 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
11555 built from @file{Makefile.am} by @command{automake}, and rely on the
11556 definitions of the M4 macros put in @file{aclocal.m4} as well as the
11557 behavior of the auxiliary tools installed.
11558
11559 Because all these files are closely related, it is important to
11560 regenerate all of them when upgrading to a newer Automake release.
11561 The usual way to do that is
11562
11563 @example
11564 aclocal # with any option needed (such a -I m4)
11565 autoconf
11566 automake --add-missing --force-missing
11567 @end example
11568
11569 @noindent
11570 or more conveniently:
11571
11572 @example
11573 autoreconf -vfi
11574 @end example
11575
11576 The use of @option{--force-missing} ensures that auxiliary tools will be
11577 overridden by new versions (@pxref{automake Invocation}).
11578
11579 It is important to regenerate all these files each time Automake is
11580 upgraded, even between bug fixes releases.  For instance, it is not
11581 unusual for a bug fix to involve changes to both the rules generated
11582 in @file{Makefile.in} and the supporting M4 macros copied to
11583 @file{aclocal.m4}.
11584
11585 Presently @command{automake} is able to diagnose situations where
11586 @file{aclocal.m4} has been generated with another version of
11587 @command{aclocal}.  However it never checks whether auxiliary scripts
11588 are up-to-date.  In other words, @command{automake} will tell you when
11589 @command{aclocal} needs to be rerun, but it will never diagnose a
11590 missing @option{--force-missing}.
11591
11592 Before upgrading to a new major release, it is a good idea to read the
11593 file @file{NEWS}.  This file lists all changes between releases: new
11594 features, obsolete constructs, known incompatibilities, and
11595 workarounds.
11596
11597 @node FAQ
11598 @chapter Frequently Asked Questions about Automake
11599
11600 This chapter covers some questions that often come up on the mailing
11601 lists.
11602
11603 @menu
11604 * CVS::                         CVS and generated files
11605 * maintainer-mode::             missing and AM_MAINTAINER_MODE
11606 * Wildcards::                   Why doesn't Automake support wildcards?
11607 * Limitations on File Names::   Limitations on source and installed file names
11608 * distcleancheck::              Files left in build directory after distclean
11609 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
11610 * Renamed Objects::             Why are object files sometimes renamed?
11611 * Per-Object Flags::            How to simulate per-object flags?
11612 * Multiple Outputs::            Writing rules for tools with many output files
11613 * Hard-Coded Install Paths::    Installing to hard-coded locations
11614 * Debugging Make Rules::        Strategies when things don't work as expected
11615 * Reporting Bugs::              Feedback on bugs and feature requests
11616 @end menu
11617
11618 @node CVS
11619 @section CVS and generated files
11620
11621 @subheading Background: distributed generated Files
11622 @cindex generated files, distributed
11623 @cindex rebuild rules
11624
11625 Packages made with Autoconf and Automake ship with some generated
11626 files like @file{configure} or @file{Makefile.in}.  These files were
11627 generated on the developer's host and are distributed so that
11628 end-users do not have to install the maintainer tools required to
11629 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
11630 or Info documentation, are usually distributed on similar grounds.
11631
11632 Automake outputs rules in @file{Makefile}s to rebuild these files.  For
11633 instance, @command{make} will run @command{autoconf} to rebuild
11634 @file{configure} whenever @file{configure.ac} is changed.  This makes
11635 development safer by ensuring a @file{configure} is never out-of-date
11636 with respect to @file{configure.ac}.
11637
11638 As generated files shipped in packages are up-to-date, and because
11639 @command{tar} preserves times-tamps, these rebuild rules are not
11640 triggered when a user unpacks and builds a package.
11641
11642 @subheading Background: CVS and Timestamps
11643 @cindex timestamps and CVS
11644 @cindex CVS and timestamps
11645
11646 Unless you use CVS keywords (in which case files must be updated at
11647 commit time), CVS preserves timestamp during @samp{cvs commit} and
11648 @samp{cvs import -d} operations.
11649
11650 When you check out a file using @samp{cvs checkout} its timestamp is
11651 set to that of the revision that is being checked out.
11652
11653 However, during @command{cvs update}, files will have the date of the
11654 update, not the original timestamp of this revision.  This is meant to
11655 make sure that @command{make} notices sources files have been updated.
11656
11657 This timestamp shift is troublesome when both sources and generated
11658 files are kept under CVS@.  Because CVS processes files in lexical
11659 order, @file{configure.ac} will appear newer than @file{configure}
11660 after a @command{cvs update} that updates both files, even if
11661 @file{configure} was newer than @file{configure.ac} when it was
11662 checked in.  Calling @command{make} will then trigger a spurious rebuild
11663 of @file{configure}.
11664
11665 @subheading Living with CVS in Autoconfiscated Projects
11666 @cindex CVS and generated files
11667 @cindex generated files and CVS
11668
11669 There are basically two clans amongst maintainers: those who keep all
11670 distributed files under CVS, including generated files, and those who
11671 keep generated files @emph{out} of CVS.
11672
11673 @subsubheading All Files in CVS
11674
11675 @itemize @bullet
11676 @item
11677 The CVS repository contains all distributed files so you know exactly
11678 what is distributed, and you can checkout any prior version entirely.
11679
11680 @item
11681 Maintainers can see how generated files evolve (for instance, you can
11682 see what happens to your @file{Makefile.in}s when you upgrade Automake
11683 and make sure they look OK).
11684
11685 @item
11686 Users do not need the autotools to build a checkout of the project, it
11687 works just like a released tarball.
11688
11689 @item
11690 If users use @command{cvs update} to update their copy, instead of
11691 @command{cvs checkout} to fetch a fresh one, timestamps will be
11692 inaccurate.  Some rebuild rules will be triggered and attempt to
11693 run developer tools such as @command{autoconf} or @command{automake}.
11694
11695 Actually, calls to such tools are all wrapped into a call to the
11696 @command{missing} script discussed later (@pxref{maintainer-mode}).
11697 @command{missing} will take care of fixing the timestamps when these
11698 tools are not installed, so that the build can continue.
11699
11700 @item
11701 In distributed development, developers are likely to have different
11702 version of the maintainer tools installed.  In this case rebuilds
11703 triggered by timestamp lossage will lead to spurious changes
11704 to generated files.  There are several solutions to this:
11705
11706 @itemize
11707 @item
11708 All developers should use the same versions, so that the rebuilt files
11709 are identical to files in CVS@.  (This starts to be difficult when each
11710 project you work on uses different versions.)
11711 @item
11712 Or people use a script to fix the timestamp after a checkout (the GCC
11713 folks have such a script).
11714 @item
11715 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
11716 disable all these rebuild rules by default.  This is further discussed
11717 in @ref{maintainer-mode}.
11718 @end itemize
11719
11720 @item
11721 Although we focused on spurious rebuilds, the converse can also
11722 happen.  CVS's timestamp handling can also let you think an
11723 out-of-date file is up-to-date.
11724
11725 For instance, suppose a developer has modified @file{Makefile.am} and
11726 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
11727 change to @file{Makefile.am} right before checking in both files
11728 (without rebuilding @file{Makefile.in} to account for the change).
11729
11730 This last change to @file{Makefile.am} makes the copy of
11731 @file{Makefile.in} out-of-date.  Since CVS processes files
11732 alphabetically, when another developer @samp{cvs update}s his or her
11733 tree, @file{Makefile.in} will happen to be newer than
11734 @file{Makefile.am}.  This other developer will not see that
11735 @file{Makefile.in} is out-of-date.
11736
11737 @end itemize
11738
11739 @subsubheading Generated Files out of CVS
11740
11741 One way to get CVS and @command{make} working peacefully is to never
11742 store generated files in CVS, i.e., do not CVS-control files that
11743 are @file{Makefile} targets (also called @emph{derived} files).
11744
11745 This way developers are not annoyed by changes to generated files.  It
11746 does not matter if they all have different versions (assuming they are
11747 compatible, of course).  And finally, timestamps are not lost, changes
11748 to sources files can't be missed as in the
11749 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
11750
11751 The drawback is that the CVS repository is not an exact copy of what
11752 is distributed and that users now need to install various development
11753 tools (maybe even specific versions) before they can build a checkout.
11754 But, after all, CVS's job is versioning, not distribution.
11755
11756 Allowing developers to use different versions of their tools can also
11757 hide bugs during distributed development.  Indeed, developers will be
11758 using (hence testing) their own generated files, instead of the
11759 generated files that will be released actually.  The developer who
11760 prepares the tarball might be using a version of the tool that
11761 produces bogus output (for instance a non-portable C file), something
11762 other developers could have noticed if they weren't using their own
11763 versions of this tool.
11764
11765 @subheading Third-party Files
11766 @cindex CVS and third-party files
11767 @cindex third-party files and CVS
11768
11769 Another class of files not discussed here (because they do not cause
11770 timestamp issues) are files that are shipped with a package, but
11771 maintained elsewhere.  For instance, tools like @command{gettextize}
11772 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
11773 Libtool), will install or update files in your package.
11774
11775 These files, whether they are kept under CVS or not, raise similar
11776 concerns about version mismatch between developers' tools.  The
11777 Gettext manual has a section about this, see @ref{CVS Issues, CVS
11778 Issues, Integrating with CVS, gettext, GNU gettext tools}.
11779
11780 @node maintainer-mode
11781 @section @command{missing} and @code{AM_MAINTAINER_MODE}
11782
11783 @subheading @command{missing}
11784 @cindex @command{missing}, purpose
11785
11786 The @command{missing} script is a wrapper around several maintainer
11787 tools, designed to warn users if a maintainer tool is required but
11788 missing.  Typical maintainer tools are @command{autoconf},
11789 @command{automake}, @command{bison}, etc.  Because file generated by
11790 these tools are shipped with the other sources of a package, these
11791 tools shouldn't be required during a user build and they are not
11792 checked for in @file{configure}.
11793
11794 However, if for some reason a rebuild rule is triggered and involves a
11795 missing tool, @command{missing} will notice it and warn the user.
11796 Besides the warning, when a tool is missing, @command{missing} will
11797 attempt to fix timestamps in a way that allows the build to continue.
11798 For instance, @command{missing} will touch @file{configure} if
11799 @command{autoconf} is not installed.  When all distributed files are
11800 kept under version control, this feature of @command{missing} allows a
11801 user @emph{with no maintainer tools} to build a package off its version
11802 control repository, bypassing any timestamp inconsistency (implied by
11803 e.g.@: @samp{cvs update} or @samp{git clone}).
11804
11805 If the required tool is installed, @command{missing} will run it and
11806 won't attempt to continue after failures.  This is correct during
11807 development: developers love fixing failures.  However, users with
11808 wrong versions of maintainer tools may get an error when the rebuild
11809 rule is spuriously triggered, halting the build.  This failure to let
11810 the build continue is one of the arguments of the
11811 @code{AM_MAINTAINER_MODE} advocates.
11812
11813 @subheading @code{AM_MAINTAINER_MODE}
11814 @cindex @code{AM_MAINTAINER_MODE}, purpose
11815 @acindex AM_MAINTAINER_MODE
11816
11817 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
11818 "rebuild rules" should be enabled or disabled.  With
11819 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
11820 otherwise they are disabled by default.  In the latter case, if
11821 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
11822 @samp{./configure && make}, then @command{make} will *never* attempt to
11823 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
11824 I.e., this disables build rules for files that are usually distributed
11825 and that users should normally not have to update.
11826
11827 The user can override the default setting by passing either
11828 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
11829 to @command{configure}.
11830
11831 People use @code{AM_MAINTAINER_MODE} either because they do not want their
11832 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
11833 because they simply can't stand the rebuild rules and prefer running
11834 maintainer tools explicitly.
11835
11836 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
11837 rules conditionally.  Some developers use this feature to disable
11838 rules that need exotic tools that users may not have available.
11839
11840 Several years ago Fran@,{c}ois Pinard pointed out several arguments
11841 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
11842 insecurity.  By removing dependencies you get non-dependable builds:
11843 changes to sources files can have no effect on generated files and this
11844 can be very confusing when unnoticed.  He adds that security shouldn't
11845 be reserved to maintainers (what @option{--enable-maintainer-mode}
11846 suggests), on the contrary.  If one user has to modify a
11847 @file{Makefile.am}, then either @file{Makefile.in} should be updated
11848 or a warning should be output (this is what Automake uses
11849 @command{missing} for) but the last thing you want is that nothing
11850 happens and the user doesn't notice it (this is what happens when
11851 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
11852
11853 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
11854 swayed by Fran@,{c}ois's arguments, and got rid of
11855 @code{AM_MAINTAINER_MODE} in all of his packages.
11856
11857 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
11858 it helps them working on projects where all files are kept under version
11859 control, and because @command{missing} isn't enough if you have the
11860 wrong version of the tools.
11861
11862
11863 @node Wildcards
11864 @section Why doesn't Automake support wildcards?
11865 @cindex wildcards
11866
11867 Developers are lazy.  They would often like to use wildcards in
11868 @file{Makefile.am}s, so that they would not need to remember to
11869 update @file{Makefile.am}s every time they add, delete, or rename
11870 a file.
11871
11872 There are several objections to this:
11873 @itemize
11874 @item
11875 When using CVS (or similar) developers need to remember they have to
11876 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
11877 @file{Makefile.am} accordingly quickly becomes a reflex.
11878
11879 Conversely, if your application doesn't compile
11880 because you forgot to add a file in @file{Makefile.am}, it will help
11881 you remember to @samp{cvs add} it.
11882
11883 @item
11884 Using wildcards makes it easy to distribute files by mistake.  For
11885 instance, some code a developer is experimenting with (a test case,
11886 say) that should not be part of the distribution.
11887
11888 @item
11889 Using wildcards it's easy to omit some files by mistake.  For
11890 instance, one developer creates a new file, uses it in many places,
11891 but forgets to commit it.  Another developer then checks out the
11892 incomplete project and is able to run @samp{make dist} successfully,
11893 even though a file is missing. By listing files, @samp{make dist}
11894 @emph{will} complain.
11895
11896 @item
11897 Wildcards are not portable to some non-GNU @command{make} implementations,
11898 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
11899 prerequisites of a target.
11900
11901 @item
11902 Finally, it's really hard to @emph{forget} to add a file to
11903 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
11904 not compiled or installed, so you can't even test them.
11905 @end itemize
11906
11907 Still, these are philosophical objections, and as such you may disagree,
11908 or find enough value in wildcards to dismiss all of them.  Before you
11909 start writing a patch against Automake to teach it about wildcards,
11910 let's see the main technical issue: portability.
11911
11912 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
11913 not portable to other @command{make} implementations.
11914
11915 The only way Automake could support @command{$(wildcard ...)} is by
11916 expending @command{$(wildcard ...)} when @command{automake} is run.
11917 The resulting @file{Makefile.in}s would be portable since they would
11918 list all files and not use @samp{$(wildcard ...)}.  However that
11919 means developers would need to remember to run @command{automake} each
11920 time they add, delete, or rename files.
11921
11922 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
11923 it's easier and faster to type @samp{automake; make} than to type
11924 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
11925 patch to add support for this syntax.  Some people use scripts to
11926 generate file lists in @file{Makefile.am} or in separate
11927 @file{Makefile} fragments.
11928
11929 Even if you don't care about portability, and are tempted to use
11930 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
11931 should know there are many places where Automake needs to know exactly
11932 which files should be processed.  As Automake doesn't know how to
11933 expand @samp{$(wildcard ...)}, you cannot use it in these places.
11934 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
11935 variables as far Automake is concerned.
11936
11937 You can get warnings about @samp{$(wildcard ...}) constructs using the
11938 @option{-Wportability} flag.
11939
11940 @node Limitations on File Names
11941 @section Limitations on File Names
11942 @cindex file names, limitations on
11943
11944 Automake attempts to support all kinds of file names, even those that
11945 contain unusual characters or are unusually long.  However, some
11946 limitations are imposed by the underlying operating system and tools.
11947
11948 Most operating systems prohibit the use of the null byte in file
11949 names, and reserve @samp{/} as a directory separator.  Also, they
11950 require that file names are properly encoded for the user's locale.
11951 Automake is subject to these limits.
11952
11953 Portable packages should limit themselves to POSIX file
11954 names.  These can contain ASCII letters and digits,
11955 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
11956 separated by @samp{/}.  File name components cannot begin with
11957 @samp{-}.
11958
11959 Portable POSIX file names cannot contain components that exceed a
11960 14-byte limit, but nowadays it's normally safe to assume the
11961 more-generous XOPEN limit of 255 bytes.  POSIX
11962 limits file names to 255 bytes (XOPEN allows 1023 bytes),
11963 but you may want to limit a source tarball to file names of 99 bytes
11964 to avoid interoperability problems with old versions of @command{tar}.
11965
11966 If you depart from these rules (e.g., by using non-ASCII
11967 characters in file names, or by using lengthy file names), your
11968 installers may have problems for reasons unrelated to Automake.
11969 However, if this does not concern you, you should know about the
11970 limitations imposed by Automake itself.  These limitations are
11971 undesirable, but some of them seem to be inherent to underlying tools
11972 like Autoconf, Make, M4, and the shell.  They fall into three
11973 categories: install directories, build directories, and file names.
11974
11975 The following characters:
11976
11977 @example
11978 @r{newline} " # $ ' `
11979 @end example
11980
11981 should not appear in the names of install directories.  For example,
11982 the operand of @command{configure}'s @option{--prefix} option should
11983 not contain these characters.
11984
11985 Build directories suffer the same limitations as install directories,
11986 and in addition should not contain the following characters:
11987
11988 @example
11989 & @@ \
11990 @end example
11991
11992 For example, the full name of the directory containing the source
11993 files should not contain these characters.
11994
11995 Source and installation file names like @file{main.c} are limited even
11996 further: they should conform to the POSIX/XOPEN
11997 rules described above.  In addition, if you plan to port to
11998 non-POSIX environments, you should avoid file names that
11999 differ only in case (e.g., @file{makefile} and @file{Makefile}).
12000 Nowadays it is no longer worth worrying about the 8.3 limits of
12001 DOS file systems.
12002
12003 @node distcleancheck
12004 @section Files left in build directory after distclean
12005 @cindex @code{distclean}, diagnostic
12006 @cindex @samp{make distclean}, diagnostic
12007 @cindex dependencies and distributed files
12008 @trindex distclean
12009 @trindex distcleancheck
12010
12011 This is a diagnostic you might encounter while running @samp{make
12012 distcheck}.
12013
12014 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
12015 attempts to build and check your package for errors like this one.
12016
12017 @samp{make distcheck} will perform a @code{VPATH} build of your
12018 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
12019 Files left in the build directory after @samp{make distclean} has run
12020 are listed after this error.
12021
12022 This diagnostic really covers two kinds of errors:
12023
12024 @itemize @bullet
12025 @item
12026 files that are forgotten by distclean;
12027 @item
12028 distributed files that are erroneously rebuilt.
12029 @end itemize
12030
12031 The former left-over files are not distributed, so the fix is to mark
12032 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
12033 more explanations.
12034
12035 The latter bug is not always easy to understand and fix, so let's
12036 proceed with an example.  Suppose our package contains a program for
12037 which we want to build a man page using @command{help2man}.  GNU
12038 @command{help2man} produces simple manual pages from the @option{--help}
12039 and @option{--version} output of other commands (@pxref{Top, , Overview,
12040 help2man, The Help2man Manual}).  Because we don't want to force our
12041 users to install @command{help2man}, we decide to distribute the
12042 generated man page using the following setup.
12043
12044 @example
12045 # This Makefile.am is bogus.
12046 bin_PROGRAMS = foo
12047 foo_SOURCES = foo.c
12048 dist_man_MANS = foo.1
12049
12050 foo.1: foo$(EXEEXT)
12051         help2man --output=foo.1 ./foo$(EXEEXT)
12052 @end example
12053
12054 This will effectively distribute the man page.  However,
12055 @samp{make distcheck} will fail with:
12056
12057 @example
12058 ERROR: files left in build directory after distclean:
12059 ./foo.1
12060 @end example
12061
12062 Why was @file{foo.1} rebuilt?  Because although distributed,
12063 @file{foo.1} depends on a non-distributed built file:
12064 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
12065 will always appear to be newer than the distributed @file{foo.1}.
12066
12067 @samp{make distcheck} caught an inconsistency in our package.  Our
12068 intent was to distribute @file{foo.1} so users do not need to install
12069 @command{help2man}, however since this rule causes this file to be
12070 always rebuilt, users @emph{do} need @command{help2man}.  Either we
12071 should ensure that @file{foo.1} is not rebuilt by users, or there is
12072 no point in distributing @file{foo.1}.
12073
12074 More generally, the rule is that distributed files should never depend
12075 on non-distributed built files.  If you distribute something
12076 generated, distribute its sources.
12077
12078 One way to fix the above example, while still distributing
12079 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
12080 assuming @command{foo --version} and @command{foo --help} do not
12081 change unless @file{foo.c} or @file{configure.ac} change, we could
12082 write the following @file{Makefile.am}:
12083
12084 @example
12085 bin_PROGRAMS = foo
12086 foo_SOURCES = foo.c
12087 dist_man_MANS = foo.1
12088
12089 foo.1: foo.c $(top_srcdir)/configure.ac
12090         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
12091         help2man --output=foo.1 ./foo$(EXEEXT)
12092 @end example
12093
12094 This way, @file{foo.1} will not get rebuilt every time
12095 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
12096 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
12097 way to ensure this would be to use separate directories for binaries
12098 and man pages, and set @code{SUBDIRS} so that binaries are built
12099 before man pages.
12100
12101 We could also decide not to distribute @file{foo.1}.  In
12102 this case it's fine to have @file{foo.1} dependent upon
12103 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
12104 However it would be impossible to build the package in a
12105 cross-compilation, because building @file{foo.1} involves
12106 an @emph{execution} of @file{foo$(EXEEXT)}.
12107
12108 Another context where such errors are common is when distributed files
12109 are built by tools that are built by the package.  The pattern is
12110 similar:
12111
12112 @example
12113 distributed-file: built-tools distributed-sources
12114         build-command
12115 @end example
12116
12117 @noindent
12118 should be changed to
12119
12120 @example
12121 distributed-file: distributed-sources
12122         $(MAKE) $(AM_MAKEFLAGS) built-tools
12123         build-command
12124 @end example
12125
12126 @noindent
12127 or you could choose not to distribute @file{distributed-file}, if
12128 cross-compilation does not matter.
12129
12130 The points made through these examples are worth a summary:
12131
12132 @cartouche
12133 @itemize
12134 @item
12135 Distributed files should never depend upon non-distributed built
12136 files.
12137 @item
12138 Distributed files should be distributed with all their dependencies.
12139 @item
12140 If a file is @emph{intended} to be rebuilt by users, then there is no point
12141 in distributing it.
12142 @end itemize
12143 @end cartouche
12144
12145 @vrindex distcleancheck_listfiles
12146 For desperate cases, it's always possible to disable this check by
12147 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
12148 the Distribution}.
12149 Make sure you do understand the reason why @samp{make distcheck}
12150 complains before you do this.  @code{distcleancheck_listfiles} is a
12151 way to @emph{hide} errors, not to fix them.  You can always do better.
12152
12153 @node Flag Variables Ordering
12154 @section Flag Variables Ordering
12155 @cindex Ordering flag variables
12156 @cindex Flag variables, ordering
12157
12158 @display
12159 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
12160 @code{mumble_CFLAGS}?
12161 @end display
12162
12163 @display
12164 Why does @command{automake} output @code{CPPFLAGS} after
12165 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
12166 @end display
12167
12168 @display
12169 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
12170 one @file{Makefile.am} I would like to append a new flag, however if I
12171 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
12172 flags, not appended.
12173 @end display
12174
12175 @subheading Compile Flag Variables
12176 @cindex Flag Variables, Ordering
12177 @cindex Compile Flag Variables
12178 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
12179 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
12180 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
12181 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
12182 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
12183 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
12184 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
12185 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
12186 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
12187 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
12188 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
12189 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
12190 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
12191 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
12192 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
12193 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
12194 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
12195 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
12196 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
12197 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
12198 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
12199 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
12200 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
12201 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
12202 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
12203 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
12204 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
12205 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
12206
12207 This section attempts to answer all the above questions.  We will
12208 mostly discuss @code{CPPFLAGS} in our examples, but actually the
12209 answer holds for all the compile flags used in Automake:
12210 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
12211 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
12212 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{RFLAGS},
12213 @code{UPCFLAGS}, and @code{YFLAGS}.
12214
12215 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
12216 three variables that can be used to pass flags to the C preprocessor
12217 (actually these variables are also used for other languages like C++
12218 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
12219 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
12220 and @code{mumble_CPPFLAGS} is the variable specific to the
12221 @code{mumble} target (we call this a per-target variable,
12222 @pxref{Program and Library Variables}).
12223
12224 Automake always uses two of these variables when compiling C sources
12225 files.  When compiling an object file for the @code{mumble} target,
12226 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
12227 @code{AM_CPPFLAGS} otherwise.  The second variable is always
12228 @code{CPPFLAGS}.
12229
12230 In the following example,
12231
12232 @example
12233 bin_PROGRAMS = foo bar
12234 foo_SOURCES = xyz.c
12235 bar_SOURCES = main.c
12236 foo_CPPFLAGS = -DFOO
12237 AM_CPPFLAGS = -DBAZ
12238 @end example
12239
12240 @noindent
12241 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
12242 (because @file{xyz.o} is part of the @code{foo} target), while
12243 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
12244 (because there is no per-target variable for target @code{bar}).
12245
12246 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
12247 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
12248 is a user variable, i.e., a variable that users are entitled to modify
12249 in order to compile the package.  This variable, like many others,
12250 is documented at the end of the output of @samp{configure --help}.
12251
12252 For instance, someone who needs to add @file{/home/my/usr/include} to
12253 the C compiler's search path would configure a package with
12254
12255 @example
12256 ./configure CPPFLAGS='-I /home/my/usr/include'
12257 @end example
12258
12259 @noindent
12260 and this flag would be propagated to the compile rules of all
12261 @file{Makefile}s.
12262
12263 It is also not uncommon to override a user variable at
12264 @command{make}-time.  Many installers do this with @code{prefix}, but
12265 this can be useful with compiler flags too.  For instance, if, while
12266 debugging a C++ project, you need to disable optimization in one
12267 specific object file, you can run something like
12268
12269 @example
12270 rm file.o
12271 make CXXFLAGS=-O0 file.o
12272 make
12273 @end example
12274
12275 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
12276 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
12277 should always have the last say.  It probably makes more sense if you
12278 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
12279 should supersede any other switch from @code{AM_CXXFLAGS} or
12280 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
12281 of @code{CXXFLAGS}).
12282
12283 You should never redefine a user variable such as @code{CPPFLAGS} in
12284 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
12285 mistakes.  Even something like
12286
12287 @example
12288 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
12289 @end example
12290
12291 @noindent
12292 is erroneous.  Although this preserves @file{configure}'s value of
12293 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
12294 user attempts to override @code{CPPFLAGS} from the @command{make}
12295 command line.
12296
12297 @example
12298 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
12299 @end example
12300
12301 @noindent
12302 is all that is needed here if no per-target flags are used.
12303
12304 You should not add options to these user variables within
12305 @file{configure} either, for the same reason.  Occasionally you need
12306 to modify these variables to perform a test, but you should reset
12307 their values afterwards.  In contrast, it is OK to modify the
12308 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
12309 them, but it is rather rare that you need to do this, unless you
12310 really want to change the default definitions of the @samp{AM_}
12311 variables in all @file{Makefile}s.
12312
12313 What we recommend is that you define extra flags in separate
12314 variables.  For instance, you may write an Autoconf macro that computes
12315 a set of warning options for the C compiler, and @code{AC_SUBST} them
12316 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
12317 determines which compiler and which linker flags should be used to
12318 link with library @file{libfoo}, and @code{AC_SUBST} these in
12319 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
12320 @file{Makefile.am} could use these variables as follows:
12321
12322 @example
12323 AM_CFLAGS = $(WARNINGCFLAGS)
12324 bin_PROGRAMS = prog1 prog2
12325 prog1_SOURCES = @dots{}
12326 prog2_SOURCES = @dots{}
12327 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
12328 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
12329 @end example
12330
12331 In this example both programs will be compiled with the flags
12332 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
12333 additionally be compiled with the flags required to link with
12334 @file{libfoo}.
12335
12336 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
12337 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
12338 every target in a @file{Makefile.in}.
12339
12340 Using variables like this gives you full control over the ordering of
12341 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
12342 you want to negate for a particular target, you can use something like
12343 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all these flags had
12344 been forcefully appended to @code{CFLAGS}, there would be no way to
12345 disable one flag.  Yet another reason to leave user variables to
12346 users.
12347
12348 Finally, we have avoided naming the variable of the example
12349 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
12350 Automake to think that this is actually a per-target variable (like
12351 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
12352
12353 @subheading Other Variables
12354
12355 There are other variables in Automake that follow similar principles
12356 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
12357 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
12358 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
12359 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
12360 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
12361 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
12362 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
12363 of these rules support per-target flags (yet).
12364
12365 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
12366 obeys this naming scheme.  The slight difference is that
12367 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
12368 @command{make} itself.
12369
12370 However you should not think that all variables ending with
12371 @code{FLAGS} follow this convention.  For instance,
12372 @code{DISTCHECK_CONFIGURE_FLAGS} (@pxref{Checking the Distribution}) and
12373 @code{ACLOCAL_AMFLAGS} (see @ref{Rebuilding} and @ref{Local Macros}),
12374 are two variables that are only useful to the maintainer and have no
12375 user counterpart.
12376
12377 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
12378 has neither @code{AM_} nor per-target cousin.
12379
12380 Finally you should not think that the existence of a per-target
12381 variable implies the existence of an @code{AM_} variable or of a user
12382 variable.  For instance, the @code{mumble_LDADD} per-target variable
12383 overrides the makefile-wide @code{LDADD} variable (which is not a user
12384 variable), and @code{mumble_LIBADD} exists only as a per-target
12385 variable.  @xref{Program and Library Variables}.
12386
12387
12388 @node Renamed Objects
12389 @section Why are object files sometimes renamed?
12390
12391 This happens when per-target compilation flags are used.  Object
12392 files need to be renamed just in case they would clash with object
12393 files compiled from the same sources, but with different flags.
12394 Consider the following example.
12395
12396 @example
12397 bin_PROGRAMS = true false
12398 true_SOURCES = generic.c
12399 true_CPPFLAGS = -DEXIT_CODE=0
12400 false_SOURCES = generic.c
12401 false_CPPFLAGS = -DEXIT_CODE=1
12402 @end example
12403
12404 @noindent
12405 Obviously the two programs are built from the same source, but it
12406 would be bad if they shared the same object, because @file{generic.o}
12407 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
12408 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
12409 build two different objects: @file{true-generic.o} and
12410 @file{false-generic.o}.
12411
12412 @command{automake} doesn't actually look whether source files are
12413 shared to decide if it must rename objects.  It will just rename all
12414 objects of a target as soon as it sees per-target compilation flags
12415 used.
12416
12417 It's OK to share object files when per-target compilation flags are not
12418 used.  For instance, @file{true} and @file{false} will both use
12419 @file{version.o} in the following example.
12420
12421 @example
12422 AM_CPPFLAGS = -DVERSION=1.0
12423 bin_PROGRAMS = true false
12424 true_SOURCES = true.c version.c
12425 false_SOURCES = false.c version.c
12426 @end example
12427
12428 Note that the renaming of objects is also affected by the
12429 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
12430
12431
12432 @node Per-Object Flags
12433 @section Per-Object Flags Emulation
12434 @cindex Per-object flags, emulated
12435
12436 @display
12437 One of my source files needs to be compiled with different flags.  How
12438 do I do?
12439 @end display
12440
12441 Automake supports per-program and per-library compilation flags (see
12442 @ref{Program and Library Variables} and @ref{Flag Variables
12443 Ordering}).  With this you can define compilation flags that apply to
12444 all files compiled for a target.  For instance, in
12445
12446 @example
12447 bin_PROGRAMS = foo
12448 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
12449 foo_CFLAGS = -some -flags
12450 @end example
12451
12452 @noindent
12453 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
12454 compiled with @samp{-some -flags}.  (If you wonder about the names of
12455 these object files, see @ref{Renamed Objects}.)  Note that
12456 @code{foo_CFLAGS} gives the flags to use when compiling all the C
12457 sources of the @emph{program} @code{foo}, it has nothing to do with
12458 @file{foo.c} or @file{foo-foo.o} specifically.
12459
12460 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
12461 specific flags, that none of the other files requires?  Obviously
12462 per-program flags are not directly applicable here.  Something like
12463 per-object flags are expected, i.e., flags that would be used only
12464 when creating @file{foo-foo.o}.  Automake does not support that,
12465 however this is easy to simulate using a library that contains only
12466 that object, and compiling this library with per-library flags.
12467
12468 @example
12469 bin_PROGRAMS = foo
12470 foo_SOURCES = bar.c bar.h main.c
12471 foo_CFLAGS = -some -flags
12472 foo_LDADD = libfoo.a
12473 noinst_LIBRARIES = libfoo.a
12474 libfoo_a_SOURCES = foo.c foo.h
12475 libfoo_a_CFLAGS = -some -other -flags
12476 @end example
12477
12478 Here @file{foo-bar.o} and @file{foo-main.o} will all be
12479 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
12480 be compiled using @samp{-some -other -flags}.  Eventually, all
12481 three objects will be linked to form @file{foo}.
12482
12483 This trick can also be achieved using Libtool convenience libraries,
12484 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
12485 Convenience Libraries}).
12486
12487 Another tempting idea to implement per-object flags is to override the
12488 compile rules @command{automake} would output for these files.
12489 Automake will not define a rule for a target you have defined, so you
12490 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
12491 We recommend against this, because this is error prone.  For instance,
12492 if you add such a rule to the first example, it will break the day you
12493 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
12494 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
12495 Objects}).  Also in order to support dependency tracking, the two
12496 @file{.o}/@file{.obj} extensions, and all the other flags variables
12497 involved in a compilation, you will end up modifying a copy of the
12498 rule previously output by @command{automake} for this file.  If a new
12499 release of Automake generates a different rule, your copy will need to
12500 be updated by hand.
12501
12502 @node Multiple Outputs
12503 @section Handling Tools that Produce Many Outputs
12504 @cindex multiple outputs, rules with
12505 @cindex many outputs, rules with
12506 @cindex rules with multiple outputs
12507
12508 This section describes a @command{make} idiom that can be used when a
12509 tool produces multiple output files.  It is not specific to Automake
12510 and can be used in ordinary @file{Makefile}s.
12511
12512 Suppose we have a program called @command{foo} that will read one file
12513 called @file{data.foo} and produce two files named @file{data.c} and
12514 @file{data.h}.  We want to write a @file{Makefile} rule that captures
12515 this one-to-two dependency.
12516
12517 The naive rule is incorrect:
12518
12519 @example
12520 # This is incorrect.
12521 data.c data.h: data.foo
12522         foo data.foo
12523 @end example
12524
12525 @noindent
12526 What the above rule really says is that @file{data.c} and
12527 @file{data.h} each depend on @file{data.foo}, and can each be built by
12528 running @samp{foo data.foo}.  In other words it is equivalent to:
12529
12530 @example
12531 # We do not want this.
12532 data.c: data.foo
12533         foo data.foo
12534 data.h: data.foo
12535         foo data.foo
12536 @end example
12537
12538 @noindent
12539 which means that @command{foo} can be run twice.  Usually it will not
12540 be run twice, because @command{make} implementations are smart enough
12541 to check for the existence of the second file after the first one has
12542 been built; they will therefore detect that it already exists.
12543 However there are a few situations where it can run twice anyway:
12544
12545 @itemize
12546 @item
12547 The most worrying case is when running a parallel @command{make}.  If
12548 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
12549 data.foo} commands will run concurrently.  This is harmful.
12550 @item
12551 Another case is when the dependency (here @file{data.foo}) is
12552 (or depends upon) a phony target.
12553 @end itemize
12554
12555 A solution that works with parallel @command{make} but not with
12556 phony dependencies is the following:
12557
12558 @example
12559 data.c data.h: data.foo
12560         foo data.foo
12561 data.h: data.c
12562 @end example
12563
12564 @noindent
12565 The above rules are equivalent to
12566
12567 @example
12568 data.c: data.foo
12569         foo data.foo
12570 data.h: data.foo data.c
12571         foo data.foo
12572 @end example
12573
12574 @noindent
12575 therefore a parallel @command{make} will have to serialize the builds
12576 of @file{data.c} and @file{data.h}, and will detect that the second is
12577 no longer needed once the first is over.
12578
12579 Using this pattern is probably enough for most cases.  However it does
12580 not scale easily to more output files (in this scheme all output files
12581 must be totally ordered by the dependency relation), so we will
12582 explore a more complicated solution.
12583
12584 Another idea is to write the following:
12585
12586 @example
12587 # There is still a problem with this one.
12588 data.c: data.foo
12589         foo data.foo
12590 data.h: data.c
12591 @end example
12592
12593 @noindent
12594 The idea is that @samp{foo data.foo} is run only when @file{data.c}
12595 needs to be updated, but we further state that @file{data.h} depends
12596 upon @file{data.c}.  That way, if @file{data.h} is required and
12597 @file{data.foo} is out of date, the dependency on @file{data.c} will
12598 trigger the build.
12599
12600 This is almost perfect, but suppose we have built @file{data.h} and
12601 @file{data.c}, and then we erase @file{data.h}.  Then, running
12602 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
12603 just state that @file{data.c} must be up-to-date with respect to
12604 @file{data.foo}, and this is already the case.
12605
12606 What we need is a rule that forces a rebuild when @file{data.h} is
12607 missing.  Here it is:
12608
12609 @example
12610 data.c: data.foo
12611         foo data.foo
12612 data.h: data.c
12613 ## Recover from the removal of $@@
12614         @@if test -f $@@; then :; else \
12615           rm -f data.c; \
12616           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12617         fi
12618 @end example
12619
12620 The above scheme can be extended to handle more outputs and more
12621 inputs.  One of the outputs is selected to serve as a witness to the
12622 successful completion of the command, it depends upon all inputs, and
12623 all other outputs depend upon it.  For instance, if @command{foo}
12624 should additionally read @file{data.bar} and also produce
12625 @file{data.w} and @file{data.x}, we would write:
12626
12627 @example
12628 data.c: data.foo data.bar
12629         foo data.foo data.bar
12630 data.h data.w data.x: data.c
12631 ## Recover from the removal of $@@
12632         @@if test -f $@@; then :; else \
12633           rm -f data.c; \
12634           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12635         fi
12636 @end example
12637
12638 However there are now three minor problems in this setup.  One is related
12639 to the timestamp ordering of @file{data.h}, @file{data.w},
12640 @file{data.x}, and @file{data.c}.  Another one is a race condition
12641 if a parallel @command{make} attempts to run multiple instances of the
12642 recover block at once.  Finally, the recursive rule breaks @samp{make -n}
12643 when run with GNU @command{make} (as well as some other @command{make}
12644 implementations), as it may remove @file{data.h} even when it should not
12645 (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
12646 The GNU Make Manual}).
12647
12648 Let us deal with the first problem.  @command{foo} outputs four files,
12649 but we do not know in which order these files are created.  Suppose
12650 that @file{data.h} is created before @file{data.c}.  Then we have a
12651 weird situation.  The next time @command{make} is run, @file{data.h}
12652 will appear older than @file{data.c}, the second rule will be
12653 triggered, a shell will be started to execute the @samp{if@dots{}fi}
12654 command, but actually it will just execute the @code{then} branch,
12655 that is: nothing.  In other words, because the witness we selected is
12656 not the first file created by @command{foo}, @command{make} will start
12657 a shell to do nothing each time it is run.
12658
12659 A simple riposte is to fix the timestamps when this happens.
12660
12661 @example
12662 data.c: data.foo data.bar
12663         foo data.foo data.bar
12664 data.h data.w data.x: data.c
12665         @@if test -f $@@; then \
12666           touch $@@; \
12667         else \
12668 ## Recover from the removal of $@@
12669           rm -f data.c; \
12670           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12671         fi
12672 @end example
12673
12674 Another solution is to use a different and dedicated file as witness,
12675 rather than using any of @command{foo}'s outputs.
12676
12677 @example
12678 data.stamp: data.foo data.bar
12679         @@rm -f data.tmp
12680         @@touch data.tmp
12681         foo data.foo data.bar
12682         @@mv -f data.tmp $@@
12683 data.c data.h data.w data.x: data.stamp
12684 ## Recover from the removal of $@@
12685         @@if test -f $@@; then :; else \
12686           rm -f data.stamp; \
12687           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12688         fi
12689 @end example
12690
12691 @file{data.tmp} is created before @command{foo} is run, so it has a
12692 timestamp older than output files output by @command{foo}.  It is then
12693 renamed to @file{data.stamp} after @command{foo} has run, because we
12694 do not want to update @file{data.stamp} if @command{foo} fails.
12695
12696 This solution still suffers from the second problem: the race
12697 condition in the recover rule.  If, after a successful build, a user
12698 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
12699 @command{make} may start both recover rules in parallel.  If the two
12700 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
12701 data.stamp} concurrently the build is likely to fail (for instance, the
12702 two rules will create @file{data.tmp}, but only one can rename it).
12703
12704 Admittedly, such a weird situation does not arise during ordinary
12705 builds.  It occurs only when the build tree is mutilated.  Here
12706 @file{data.c} and @file{data.h} have been explicitly removed without
12707 also removing @file{data.stamp} and the other output files.
12708 @code{make clean; make} will always recover from these situations even
12709 with parallel makes, so you may decide that the recover rule is solely
12710 to help non-parallel make users and leave things as-is.  Fixing this
12711 requires some locking mechanism to ensure only one instance of the
12712 recover rule rebuilds @file{data.stamp}.  One could imagine something
12713 along the following lines.
12714
12715 @example
12716 data.c data.h data.w data.x: data.stamp
12717 ## Recover from the removal of $@@
12718         @@if test -f $@@; then :; else \
12719           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
12720 ## mkdir is a portable test-and-set
12721           if mkdir data.lock 2>/dev/null; then \
12722 ## This code is being executed by the first process.
12723             rm -f data.stamp; \
12724             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12725             result=$$?; rm -rf data.lock; exit $$result; \
12726           else \
12727 ## This code is being executed by the follower processes.
12728 ## Wait until the first process is done.
12729             while test -d data.lock; do sleep 1; done; \
12730 ## Succeed if and only if the first process succeeded.
12731             test -f data.stamp; \
12732           fi; \
12733         fi
12734 @end example
12735
12736 Using a dedicated witness, like @file{data.stamp}, is very handy when
12737 the list of output files is not known beforehand.  As an illustration,
12738 consider the following rules to compile many @file{*.el} files into
12739 @file{*.elc} files in a single command.  It does not matter how
12740 @code{ELFILES} is defined (as long as it is not empty: empty targets
12741 are not accepted by POSIX).
12742
12743 @example
12744 ELFILES = one.el two.el three.el @dots{}
12745 ELCFILES = $(ELFILES:=c)
12746
12747 elc-stamp: $(ELFILES)
12748         @@rm -f elc-temp
12749         @@touch elc-temp
12750         $(elisp_comp) $(ELFILES)
12751         @@mv -f elc-temp $@@
12752
12753 $(ELCFILES): elc-stamp
12754         @@if test -f $@@; then :; else \
12755 ## Recover from the removal of $@@
12756           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12757           if mkdir elc-lock 2>/dev/null; then \
12758 ## This code is being executed by the first process.
12759             rm -f elc-stamp; \
12760             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12761             rmdir elc-lock; \
12762           else \
12763 ## This code is being executed by the follower processes.
12764 ## Wait until the first process is done.
12765             while test -d elc-lock; do sleep 1; done; \
12766 ## Succeed if and only if the first process succeeded.
12767             test -f elc-stamp; exit $$?; \
12768 @c $$
12769           fi; \
12770         fi
12771 @end example
12772
12773 These solutions all still suffer from the third problem, namely that
12774 they break the promise that @samp{make -n} should not cause any actual
12775 changes to the tree.  For those solutions that do not create lock files,
12776 it is possible to split the recover rules into two separate recipe
12777 commands, one of which does all work but the recursion, and the
12778 other invokes the recursive @samp{$(MAKE)}.  The solutions involving
12779 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
12780 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
12781 autoconf, The Autoconf Manual}).  Here is an example:
12782
12783 @example
12784 ELFILES = one.el two.el three.el @dots{}
12785 ELCFILES = $(ELFILES:=c)
12786
12787 elc-stamp: $(ELFILES)
12788         @@rm -f elc-temp
12789         @@touch elc-temp
12790         $(elisp_comp) $(ELFILES)
12791         @@mv -f elc-temp $@@
12792
12793 $(ELCFILES): elc-stamp
12794 ## Recover from the removal of $@@
12795         @@dry=; for f in x $$MAKEFLAGS; do \
12796           case $$f in \
12797             *=*|--*);; \
12798             *n*) dry=:;; \
12799           esac; \
12800         done; \
12801         if test -f $@@; then :; else \
12802           $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12803           if $$dry mkdir elc-lock 2>/dev/null; then \
12804 ## This code is being executed by the first process.
12805             $$dry rm -f elc-stamp; \
12806             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12807             $$dry rmdir elc-lock; \
12808           else \
12809 ## This code is being executed by the follower processes.
12810 ## Wait until the first process is done.
12811             while test -d elc-lock && test -z "$$dry"; do \
12812 @c $$
12813               sleep 1; \
12814             done; \
12815 ## Succeed if and only if the first process succeeded.
12816             $$dry test -f elc-stamp; exit $$?; \
12817           fi; \
12818         fi
12819 @end example
12820
12821 For completeness it should be noted that GNU @command{make} is able to
12822 express rules with multiple output files using pattern rules
12823 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
12824 Manual}).  We do not discuss pattern rules here because they are not
12825 portable, but they can be convenient in packages that assume GNU
12826 @command{make}.
12827
12828
12829 @node Hard-Coded Install Paths
12830 @section Installing to Hard-Coded Locations
12831
12832 @display
12833 My package needs to install some configuration file.  I tried to use
12834 the following rule, but @samp{make distcheck} fails.  Why?
12835
12836 @example
12837 # Do not do this.
12838 install-data-local:
12839         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
12840 @end example
12841 @end display
12842
12843 @display
12844 My package needs to populate the installation directory of another
12845 package at install-time.  I can easily compute that installation
12846 directory in @file{configure}, but if I install files therein,
12847 @samp{make distcheck} fails.  How else should I do?
12848 @end display
12849
12850 These two setups share their symptoms: @samp{make distcheck} fails
12851 because they are installing files to hard-coded paths.  In the later
12852 case the path is not really hard-coded in the package, but we can
12853 consider it to be hard-coded in the system (or in whichever tool that
12854 supplies the path).  As long as the path does not use any of the
12855 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
12856 @samp{$(datadir)}, etc.), the effect will be the same:
12857 user-installations are impossible.
12858
12859 As a (non-root) user who wants to install a package, you usually have no
12860 right to install anything in @file{/usr} or @file{/usr/local}.  So you
12861 do something like @samp{./configure --prefix ~/usr} to install a
12862 package in your own @file{~/usr} tree.
12863
12864 If a package attempts to install something to some hard-coded path
12865 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
12866 then the installation will fail.  @samp{make distcheck} performs such
12867 a @option{--prefix} installation, hence it will fail too.
12868
12869 Now, there are some easy solutions.
12870
12871 The above @code{install-data-local} example for installing
12872 @file{/etc/afile} would be better replaced by
12873
12874 @example
12875 sysconf_DATA = afile
12876 @end example
12877
12878 @noindent
12879 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
12880 this is what the GNU Standards require.  When such a package is
12881 installed on an FHS compliant system, the installer will have to set
12882 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
12883 should not be concerned by such site policies: use the appropriate
12884 standard directory variable to install your files so that the installer
12885 can easily redefine these variables to match their site conventions.
12886
12887 Installing files that should be used by another package is slightly
12888 more involved.  Let's take an example and assume you want to install
12889 a shared library that is a Python extension module.  If you ask Python
12890 where to install the library, it will answer something like this:
12891
12892 @example
12893 % @kbd{python -c 'from distutils import sysconfig;
12894              print sysconfig.get_python_lib(1,0)'}
12895 /usr/lib/python2.5/site-packages
12896 @end example
12897
12898 If you indeed use this absolute path to install your shared library,
12899 non-root users will not be able to install the package, hence
12900 distcheck fails.
12901
12902 Let's do better.  The @samp{sysconfig.get_python_lib()} function
12903 actually accepts a third argument that will replace Python's
12904 installation prefix.
12905
12906 @example
12907 % @kbd{python -c 'from distutils import sysconfig;
12908              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
12909 $@{exec_prefix@}/lib/python2.5/site-packages
12910 @end example
12911
12912 You can also use this new path.  If you do
12913 @itemize @bullet
12914 @item
12915 root users can install your package with the same @option{--prefix}
12916 as Python (you get the behavior of the previous attempt)
12917
12918 @item
12919 non-root users can install your package too, they will have the
12920 extension module in a place that is not searched by Python but they
12921 can work around this using environment variables (and if you installed
12922 scripts that use this shared library, it's easy to tell Python were to
12923 look in the beginning of your script, so the script works in both
12924 cases).
12925 @end itemize
12926
12927 The @code{AM_PATH_PYTHON} macro uses similar commands to define
12928 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
12929
12930 Of course not all tools are as advanced as Python regarding that
12931 substitution of @var{prefix}.  So another strategy is to figure the
12932 part of the installation directory that must be preserved.  For
12933 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
12934 computes @samp{$(lispdir)}:
12935
12936 @example
12937 $EMACS -batch -q -eval '(while load-path
12938   (princ (concat (car load-path) "\n"))
12939   (setq load-path (cdr load-path)))' >conftest.out
12940 lispdir=`sed -n
12941   -e 's,/$,,'
12942   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
12943         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
12944       @}'
12945   -e '/.*\/share\/x*emacs\/site-lisp$/@{
12946         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
12947       @}'
12948   conftest.out`
12949 @end example
12950
12951 I.e., it just picks the first directory that looks like
12952 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
12953 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
12954 @samp{$@{datadir@}} appropriately.
12955
12956 The emacs case looks complicated because it processes a list and
12957 expects two possible layouts, otherwise it's easy, and the benefits for
12958 non-root users are really worth the extra @command{sed} invocation.
12959
12960
12961 @node Debugging Make Rules
12962 @section Debugging Make Rules
12963 @cindex debugging rules
12964 @cindex rules, debugging
12965
12966 The rules and dependency trees generated by @command{automake} can get
12967 rather complex, and leave the developer head-scratching when things
12968 don't work as expected.  Besides the debug options provided by the
12969 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
12970 Manual}), here's a couple of further hints for debugging makefiles
12971 generated by @command{automake} effectively:
12972
12973 @itemize
12974 @item
12975 If less verbose output has been enabled in the package with the
12976 @samp{silent-rules} option (@pxref{Options}), you can use
12977 @code{make V=1} to see the commands being executed.
12978 @item
12979 @code{make -n} can help show what would be done without actually doing
12980 it.  Note however, that this will @emph{still execute} commands prefixed
12981 with @samp{+}, and, when using GNU @command{make}, commands that contain
12982 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
12983 Execution,,, make, The GNU Make Manual}).
12984 Typically, this is helpful to show what recursive rules would do, but it
12985 means that, in your own rules, you should not mix such recursion with
12986 actions that change any files.@footnote{Automake's @samp{dist} and
12987 @samp{distcheck} rules had a bug in this regard in that they created
12988 directories even with @option{-n}, but this has been fixed in Automake
12989 1.11.}  Furthermore, note that GNU @command{make} will update
12990 prerequisites for the @file{Makefile} file itself even with @option{-n}
12991 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
12992 @item
12993 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
12994 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
12995 portability quirks associated with this construct.
12996 @item
12997 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
12998 can be handy to examine the expanded value of variables.  You may need
12999 to use a target other than @samp{print} if that is already used or a
13000 file with that name exists.
13001 @item
13002 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
13003 GNU @command{make} command called @command{remake} that copes with
13004 complex GNU @command{make}-specific Makefiles and allows to trace
13005 execution, examine variables, and call rules interactively, much like
13006 a debugger.
13007 @end itemize
13008
13009
13010 @node Reporting Bugs
13011 @section Reporting Bugs
13012
13013 Most nontrivial software has bugs.  Automake is no exception.  Although
13014 we cannot promise we can or will fix a bug, and we might not even agree
13015 that it is a bug, we want to hear about problems you encounter. Often we
13016 agree they are bugs and want to fix them.
13017
13018 To make it possible for us to fix a bug, please report it. In order to
13019 do so effectively, it helps to know when and how to do it.
13020
13021 Before reporting a bug, it is a good idea to see if it is already known.
13022 You can look at the @uref{http://debbugs.gnu.org/, GNU Bug Tracker}
13023 and the @uref{http://lists.gnu.org/@/archive/@/html/@/bug-automake/,
13024 bug-automake mailing list archives} for previous bug reports.  We
13025 previously used a
13026 @uref{http://sourceware.org/@/cgi-bin/@/gnatsweb.pl?database=automake,
13027 Gnats database} for bug tracking, so some bugs might have been reported
13028 there already.  Please do not use it for new bug reports, however.
13029
13030 If the bug is not already known, it should be reported.  It is very
13031 important to report bugs in a way that is useful and efficient.  For
13032 this, please familiarize yourself with
13033 @uref{http://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How to
13034 Report Bugs Effectively} and
13035 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
13036 Questions the Smart Way}.  This helps you and developers to save time
13037 which can then be spent on fixing more bugs and implementing more
13038 features.
13039
13040 For a bug report, a feature request or other suggestions, please send
13041 email to @email{@value{PACKAGE_BUGREPORT}}.  This will then open a new
13042 bug in the @uref{http://debbugs.gnu.org/@/automake, bug tracker}.  Be
13043 sure to include the versions of Autoconf and Automake that you use.
13044 Ideally, post a minimal @file{Makefile.am} and @file{configure.ac} that
13045 reproduces the problem you encounter.  If you have encountered test
13046 suite failures, please attach the @file{tests/test-suite.log} file.
13047
13048
13049 @node History
13050 @chapter History of Automake
13051
13052 This chapter presents various aspects of the history of Automake.  The
13053 exhausted reader can safely skip it; this will be more of interest to
13054 nostalgic people, or to those curious to learn about the evolution of
13055 Automake.
13056
13057 @menu
13058 * Timeline::                    The Automake story.
13059 * Dependency Tracking Evolution::  Evolution of Automatic Dependency Tracking
13060 * Releases::                    Statistics about Automake Releases
13061 @end menu
13062
13063 @node Timeline
13064 @section Timeline
13065
13066 @table @asis
13067 @item 1994-09-19 First CVS commit.
13068
13069 If we can trust the CVS repository, David J.@tie{}MacKenzie (djm) started
13070 working on Automake (or AutoMake, as it was spelt then) this Monday.
13071
13072 The first version of the @command{automake} script looks as follows.
13073
13074 @example
13075 #!/bin/sh
13076
13077 status=0
13078
13079 for makefile
13080 do
13081   if test ! -f $@{makefile@}.am; then
13082     echo "automake: $@{makefile@}.am: No such honkin' file"
13083     status=1
13084     continue
13085   fi
13086
13087   exec 4> $@{makefile@}.in
13088
13089 done
13090 @end example
13091
13092 From this you can already see that Automake will be about reading
13093 @file{*.am} file and producing @file{*.in} files.  You cannot see
13094 anything else, but if you also know that David is the one who created
13095 Autoconf two years before you can guess the rest.
13096
13097 Several commits follow, and by the end of the day Automake is
13098 reported to work for GNU fileutils and GNU m4.
13099
13100 The modus operandi is the one that is still used today: variable
13101 assignments in @file{Makefile.am} files trigger injections of
13102 precanned @file{Makefile} fragments into the generated
13103 @file{Makefile.in}.  The use of @file{Makefile} fragments was inspired
13104 by the 4.4BSD @command{make} and include files, however Automake aims
13105 to be portable and to conform to the GNU standards for @file{Makefile}
13106 variables and targets.
13107
13108 At this point, the most recent release of Autoconf is version 1.11,
13109 and David is preparing to release Autoconf 2.0 in late October.  As a
13110 matter of fact, he will barely touch Automake after September.
13111
13112 @item 1994-11-05 David MacKenzie's last commit.
13113
13114 At this point Automake is a 200 line portable shell script, plus 332
13115 lines of @file{Makefile} fragments.  In the @file{README}, David
13116 states his ambivalence between ``portable shell'' and ``more
13117 appropriate language'':
13118
13119 @quotation
13120 I wrote it keeping in mind the possibility of it becoming an Autoconf
13121 macro, so it would run at configure-time.  That would slow
13122 configuration down a bit, but allow users to modify the Makefile.am
13123 without needing to fetch the AutoMake package.  And, the Makefile.in
13124 files wouldn't need to be distributed.  But all of AutoMake would.  So
13125 I might reimplement AutoMake in Perl, m4, or some other more
13126 appropriate language.
13127 @end quotation
13128
13129 Automake is described as ``an experimental Makefile generator''.
13130 There is no documentation.  Adventurous users are referred to the
13131 examples and patches needed to use Automake with GNU m4 1.3, fileutils
13132 3.9, time 1.6, and development versions of find and indent.
13133
13134 These examples seem to have been lost.  However at the time of writing
13135 (10 years later in September, 2004) the FSF still distributes a
13136 package that uses this version of Automake: check out GNU termutils
13137 2.0.
13138
13139 @item 1995-11-12 Tom Tromey's first commit.
13140
13141 After one year of inactivity, Tom Tromey takes over the package.
13142 Tom was working on GNU cpio back then, and doing this just for fun,
13143 having trouble finding a project to contribute to.  So while hacking
13144 he wanted to bring the @file{Makefile.in} up to GNU standards.  This
13145 was hard, and one day he saw Automake on @url{ftp://alpha.gnu.org/},
13146 grabbed it and tried it out.
13147
13148 Tom didn't talk to djm about it until later, just to make sure he
13149 didn't mind if he made a release.  He did a bunch of early releases to
13150 the Gnits folks.
13151
13152 Gnits was (and still is) totally informal, just a few GNU friends who
13153 Fran@,cois Pinard knew, who were all interested in making a common
13154 infrastructure for GNU projects, and shared a similar outlook on how
13155 to do it.  So they were able to make some progress.  It came along
13156 with Autoconf and extensions thereof, and then Automake from David and
13157 Tom (who were both gnitsians).  One of their ideas was to write a
13158 document paralleling the GNU standards, that was more strict in some
13159 ways and more detailed.  They never finished the GNITS standards, but
13160 the ideas mostly made their way into Automake.
13161
13162 @item 1995-11-23 Automake 0.20
13163
13164 Besides introducing automatic dependency tracking (@pxref{Dependency
13165 Tracking Evolution}), this version also supplies a 9-page manual.
13166
13167 At this time @command{aclocal} and @code{AM_INIT_AUTOMAKE} did not
13168 exist, so many things had to be done by hand.  For instance, here is
13169 what a configure.in (this is the former name of the
13170 @file{configure.ac} we use today) must contain in order to use
13171 Automake 0.20:
13172
13173 @example
13174 PACKAGE=cpio
13175 VERSION=2.3.911
13176 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
13177 AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
13178 AC_SUBST(PACKAGE)
13179 AC_SUBST(VERSION)
13180 AC_ARG_PROGRAM
13181 AC_PROG_INSTALL
13182 @end example
13183
13184 (Today all of the above is achieved by @code{AC_INIT} and
13185 @code{AM_INIT_AUTOMAKE}.)
13186
13187 Here is how programs are specified in @file{Makefile.am}:
13188
13189 @example
13190 PROGRAMS = hello
13191 hello_SOURCES = hello.c
13192 @end example
13193
13194 This looks pretty much like what we do today, except the
13195 @code{PROGRAMS} variable has no directory prefix specifying where
13196 @file{hello} should be installed: all programs are installed in
13197 @samp{$(bindir)}.  @code{LIBPROGRAMS} can be used to specify programs
13198 that must be built but not installed (it is called
13199 @code{noinst_PROGRAMS} nowadays).
13200
13201 Programs can be built conditionally using @code{AC_SUBST}itutions:
13202
13203 @example
13204 PROGRAMS = @@progs@@
13205 AM_PROGRAMS = foo bar baz
13206 @end example
13207
13208 (@code{AM_PROGRAMS} has since then been renamed to
13209 @code{EXTRA_PROGRAMS}.)
13210
13211 Similarly scripts, static libraries, and data can be built and installed
13212 using the @code{LIBRARIES}, @code{SCRIPTS}, and @code{DATA} variables.
13213 However @code{LIBRARIES} were treated a bit specially in that Automake
13214 did automatically supply the @file{lib} and @file{.a} prefixes.
13215 Therefore to build @file{libcpio.a}, one had to write
13216
13217 @example
13218 LIBRARIES = cpio
13219 cpio_SOURCES = ...
13220 @end example
13221
13222 Extra files to distribute must be listed in @code{DIST_OTHER} (the
13223 ancestor of @code{EXTRA_DIST}).  Also extra directories that are to be
13224 distributed should appear in @code{DIST_SUBDIRS}, but the manual
13225 describes this as a temporary ugly hack (today extra directories should
13226 also be listed in @code{EXTRA_DIST}, and @code{DIST_SUBDIRS} is used
13227 for another purpose, @pxref{Conditional Subdirectories}).
13228
13229 @item 1995-11-26 Automake 0.21
13230
13231 In less time than it takes to cook a frozen pizza, Tom rewrites
13232 Automake using Perl.  At this time Perl 5 is only one year old, and
13233 Perl 4.036 is in use at many sites.  Supporting several Perl versions
13234 has been a source of problems through the whole history of Automake.
13235
13236 If you never used Perl 4, imagine Perl 5 without objects, without
13237 @samp{my} variables (only dynamically scoped @samp{local} variables),
13238 without function prototypes, with function calls that needs to be
13239 prefixed with @samp{&}, etc.  Traces of this old style can still be
13240 found in today's @command{automake}.
13241
13242 @item 1995-11-28 Automake 0.22
13243 @itemx 1995-11-29 Automake 0.23
13244
13245 Bug fixes.
13246
13247 @item 1995-12-08 Automake 0.24
13248 @itemx 1995-12-10 Automake 0.25
13249
13250 Releases are raining.  0.24 introduces the uniform naming scheme we
13251 use today, i.e., @code{bin_PROGRAMS} instead of @code{PROGRAMS},
13252 @code{noinst_LIBRARIES} instead of @code{LIBLIBRARIES}, etc.  (However
13253 @code{EXTRA_PROGRAMS} does not exist yet, @code{AM_PROGRAMS} is still
13254 in use; and @code{TEXINFOS} and @code{MANS} still have no directory
13255 prefixes.)  Adding support for prefixes like that was one of the major
13256 ideas in @command{automake}; it has lasted pretty well.
13257
13258 AutoMake is renamed to Automake (Tom seems to recall it was Fran@,cois
13259 Pinard's doing).
13260
13261 0.25 fixes a Perl 4 portability bug.
13262
13263 @item 1995-12-18 Jim Meyering starts using Automake in GNU Textutils.
13264 @item 1995-12-31 Fran@,cois Pinard starts using Automake in GNU tar.
13265
13266 @item 1996-01-03 Automake 0.26
13267 @itemx 1996-01-03 Automake 0.27
13268
13269 Of the many changes and suggestions sent by Fran@,cois Pinard and
13270 included in 0.26, perhaps the most important is the advice that to
13271 ease customization a user rule or variable definition should always
13272 override an Automake rule or definition.
13273
13274 Gordon Matzigkeit and Jim Meyering are two other early contributors
13275 that have been sending fixes.
13276
13277 0.27 fixes yet another Perl 4 portability bug.
13278
13279 @item 1996-01-13 Automake 0.28
13280
13281 Automake starts scanning @file{configure.in} for @code{LIBOBJS}
13282 support.  This is an important step because until this version
13283 Automake only knew about the @file{Makefile.am}s it processed.
13284 @file{configure.in} was Autoconf's world and the link between Autoconf
13285 and Automake had to be done by the @file{Makefile.am} author.  For
13286 instance, if @file{config.h} was generated by @file{configure}, it was the
13287 package maintainer's responsibility to define the @code{CONFIG_HEADER}
13288 variable in each @file{Makefile.am}.
13289
13290 Succeeding releases will rely more and more on scanning
13291 @file{configure.in} to better automate the Autoconf integration.
13292
13293 0.28 also introduces the @code{AUTOMAKE_OPTIONS} variable and the
13294 @option{--gnu} and @option{--gnits} options, the latter being stricter.
13295
13296 @item 1996-02-07 Automake 0.29
13297
13298 Thanks to @file{configure.in} scanning, @code{CONFIG_HEADER} is gone,
13299 and rebuild rules for @file{configure}-generated file are
13300 automatically output.
13301
13302 @code{TEXINFOS} and @code{MANS} converted to the uniform naming
13303 scheme.
13304
13305 @item 1996-02-24 Automake 0.30
13306
13307 The test suite is born.  It contains 9 tests.  From now on test cases
13308 will be added pretty regularly (@pxref{Releases}), and this proved to
13309 be really helpful later on.
13310
13311 @code{EXTRA_PROGRAMS} finally replaces @code{AM_PROGRAMS}.
13312
13313 All the third-party Autoconf macros, written mostly by Fran@,cois
13314 Pinard (and later Jim Meyering), are distributed in Automake's
13315 hand-written @file{aclocal.m4} file.  Package maintainers are expected
13316 to extract the necessary macros from this file.  (In previous versions
13317 you had to copy and paste them from the manual...)
13318
13319 @item 1996-03-11 Automake 0.31
13320
13321 The test suite in 0.30 was run via a long @code{check-local} rule.  Upon
13322 Ulrich Drepper's suggestion, 0.31 makes it an Automake rule output
13323 whenever the @code{TESTS} variable is defined.
13324
13325 @code{DIST_OTHER} is renamed to @code{EXTRA_DIST}, and the @code{check_}
13326 prefix is introduced.  The syntax is now the same as today.
13327
13328 @item 1996-03-15 Gordon Matzigkeit starts writing libtool.
13329
13330 @item 1996-04-27 Automake 0.32
13331
13332 @code{-hook} targets are introduced; an idea from Dieter Baron.
13333
13334 @file{*.info} files, which were output in the build directory are
13335 now built in the source directory, because they are distributed.  It
13336 seems these files like to move back and forth as that will happen
13337 again in future versions.
13338
13339 @item 1996-05-18 Automake 0.33
13340
13341 Gord Matzigkeit's main two contributions:
13342
13343 @itemize
13344 @item very preliminary libtool support
13345 @item the distcheck rule
13346 @end itemize
13347
13348 Although they were very basic at this point, these are probably
13349 among the top features for Automake today.
13350
13351 Jim Meyering also provides the infamous @code{jm_MAINTAINER_MODE},
13352 since then renamed to @code{AM_MAINTAINER_MODE} and abandoned by its
13353 author (@pxref{maintainer-mode}).
13354
13355 @item 1996-05-28 Automake 1.0
13356
13357 After only six months of heavy development, the @command{automake} script is
13358 3134 lines long, plus 973 lines of @file{Makefile} fragments.  The
13359 package has 30 pages of documentation, and 38 test cases.
13360 @file{aclocal.m4} contains 4 macros.
13361
13362 From now on and until version 1.4, new releases will occur at a rate
13363 of about one a year.  1.1 did not exist, actually 1.1b to 1.1p have
13364 been the name of beta releases for 1.2.  This is the first time
13365 Automake uses suffix letters to designate beta releases, a habit that
13366 lasts.
13367
13368 @item 1996-10-10 Kevin Dalley packages Automake 1.0 for Debian GNU/Linux.
13369
13370 @item 1996-11-26 David J.@tie{}MacKenzie releases Autoconf 2.12.
13371
13372 Between June and October, the Autoconf development is almost stalled.
13373 Roland McGrath has been working at the beginning of the year.  David
13374 comes back in November to release 2.12, but he won't touch Autoconf
13375 anymore after this year, and Autoconf then really stagnates.  The
13376 desolate Autoconf @file{ChangeLog} for 1997 lists only 7 commits.
13377
13378 @item 1997-02-28 @email{automake@@gnu.ai.mit.edu} list alive
13379
13380 The mailing list is announced as follows:
13381 @smallexample
13382 I've created the "automake" mailing list.  It is
13383 "automake@@gnu.ai.mit.edu".  Administrivia, as always, to
13384 automake-request@@gnu.ai.mit.edu.
13385
13386 The charter of this list is discussion of automake, autoconf, and
13387 other configuration/portability tools (e.g., libtool).  It is expected
13388 that discussion will range from pleas for help all the way up to
13389 patches.
13390
13391 This list is archived on the FSF machines.  Offhand I don't know if
13392 you can get the archive without an account there.
13393
13394 This list is open to anybody who wants to join.  Tell all your
13395 friends!
13396 -- Tom Tromey
13397 @end smallexample
13398
13399 Before that people were discussing Automake privately, on the Gnits
13400 mailing list (which is not public either), and less frequently on
13401 @code{gnu.misc.discuss}.
13402
13403 @code{gnu.ai.mit.edu} is now @code{gnu.org}, in case you never
13404 noticed.  The archives of the early years of the
13405 @code{automake@@gnu.org} list have been lost, so today it is almost
13406 impossible to find traces of discussions that occurred before 1999.
13407 This has been annoying more than once, as such discussions can be
13408 useful to understand the rationale behind a piece of uncommented code
13409 that was introduced back then.
13410
13411 @item 1997-06-22 Automake 1.2
13412
13413 Automake developments continues, and more and more new Autoconf macros
13414 are required.  Distributing them in @file{aclocal.m4} and requiring
13415 people to browse this file to extract the relevant macros becomes
13416 uncomfortable.  Ideally, some of them should be contributed to
13417 Autoconf so that they can be used directly, however Autoconf is
13418 currently inactive.  Automake 1.2 consequently introduces
13419 @command{aclocal} (@command{aclocal} was actually started on
13420 1996-07-28), a tool that automatically constructs an @file{aclocal.m4}
13421 file from a repository of third-party macros.  Because Autoconf has
13422 stalled, Automake also becomes a kind of repository for such
13423 third-party macros, even macros completely unrelated to Automake (for
13424 instance macros that fix broken Autoconf macros).
13425
13426 The 1.2 release contains 20 macros, including the
13427 @code{AM_INIT_AUTOMAKE} macro that simplifies the creation of
13428 @file{configure.in}.
13429
13430 Libtool is fully supported using @code{*_LTLIBRARIES}.
13431
13432 The missing script is introduced by Fran@,cois Pinard; it is meant to be
13433 a better solution than @code{AM_MAINTAINER_MODE}
13434 (@pxref{maintainer-mode}).
13435
13436 Conditionals support was implemented by Ian Lance Taylor.  At the
13437 time, Tom and Ian were working on an internal project at Cygnus.  They
13438 were using ILU, which is pretty similar to CORBA@.  They wanted to
13439 integrate ILU into their build, which was all @file{configure}-based,
13440 and Ian thought that adding conditionals to @command{automake} was
13441 simpler than doing all the work in @file{configure} (which was the
13442 standard at the time).  So this was actually funded by Cygnus.
13443
13444 This very useful but tricky feature will take a lot of time to
13445 stabilize.  (At the time this text is written, there are still
13446 primaries that have not been updated to support conditional
13447 definitions in Automake 1.9.)
13448
13449 The @command{automake} script has almost doubled: 6089 lines of Perl,
13450 plus 1294 lines of @file{Makefile} fragments.
13451
13452 @item 1997-07-08 Gordon Matzigkeit releases Libtool 1.0.
13453
13454 @item 1998-04-05 Automake 1.3
13455
13456 This is a small advance compared to 1.2.
13457 It adds support for assembly, and preliminary support for Java.
13458
13459 Perl 5.004_04 is out, but fixes to support Perl 4 are still
13460 regularly submitted whenever Automake breaks it.
13461
13462 @item 1998-09-06 @code{sourceware.cygnus.com} is on-line.
13463
13464 Sourceware was setup by Jason Molenda to host open source projects.
13465
13466 @item 1998-09-19  Automake CVS repository moved to @code{sourceware.cygnus.com}
13467 @itemx 1998-10-26  @code{sourceware.cygnus.com} announces it hosts Automake:
13468 Automake is now hosted on @code{sourceware.cygnus.com}.  It has a
13469 publicly accessible CVS repository.  This CVS repository is a copy of
13470 the one Tom was using on his machine, which in turn is based on
13471 a copy of the CVS repository of David MacKenzie.  This is why we still
13472 have to full source history.  (Automake was on Sourceware until 2007-10-29,
13473 when it moved to a git repository on @code{savannah.gnu.org},
13474 but the Sourceware host had been renamed to @code{sources.redhat.com}.)
13475
13476 The oldest file in the administrative directory of the CVS repository
13477 that was created on Sourceware is dated 1998-09-19, while the
13478 announcement that @command{automake} and @command{autoconf} had joined
13479 @command{sourceware} was made on 1998-10-26.  They were among the
13480 first projects to be hosted there.
13481
13482 The heedful reader will have noticed Automake was exactly 4 years old
13483 on 1998-09-19.
13484
13485 @item 1999-01-05 Ben Elliston releases Autoconf 2.13.
13486
13487 @item 1999-01-14 Automake 1.4
13488
13489 This release adds support for Fortran 77 and for the @code{include}
13490 statement.  Also, @samp{+=} assignments are introduced, but it is
13491 still quite easy to fool Automake when mixing this with conditionals.
13492
13493 These two releases, Automake 1.4 and Autoconf 2.13 make a duo that
13494 will be used together for years.
13495
13496 @command{automake} is 7228 lines, plus 1591 lines of Makefile
13497 fragment, 20 macros (some 1.3 macros were finally contributed back to
13498 Autoconf), 197 test cases, and 51 pages of documentation.
13499
13500 @item 1999-03-27 The @code{user-dep-branch} is created on the CVS repository.
13501
13502 This implements a new dependency tracking schemed that should be
13503 able to handle automatic dependency tracking using any compiler (not
13504 just gcc) and any make (not just GNU @command{make}).  In addition,
13505 the new scheme should be more reliable than the old one, as
13506 dependencies are generated on the end user's machine.  Alexandre Oliva
13507 creates depcomp for this purpose.
13508
13509 @xref{Dependency Tracking Evolution}, for more details about the
13510 evolution of automatic dependency tracking in Automake.
13511
13512 @item 1999-11-21 The @code{user-dep-branch} is merged into the main trunk.
13513
13514 This was a huge problem since we also had patches going in on the
13515 trunk.  The merge took a long time and was very painful.
13516
13517 @item 2000-05-10
13518
13519 Since September 1999 and until 2003, Akim Demaille will be zealously
13520 revamping Autoconf.
13521
13522 @quotation
13523 I think the next release should be called "3.0".@*
13524 Let's face it: you've basically rewritten autoconf.@*
13525 Every weekend there are 30 new patches.@*
13526 I don't see how we could call this "2.15" with a straight face.@*
13527 -- Tom Tromey on @email{autoconf@@gnu.org}
13528 @end quotation
13529
13530 Actually Akim works like a submarine: he will pile up patches while he
13531 works off-line during the weekend, and flush them in batch when he
13532 resurfaces on Monday.
13533
13534 @item 2001-01-24
13535
13536 On this Wednesday, Autoconf 2.49c, the last beta before Autoconf 2.50
13537 is out, and Akim has to find something to do during his week-end :)
13538
13539 @item 2001-01-28
13540
13541 Akim sends a batch of 14 patches to @email{automake@@gnu.org}.
13542
13543 @quotation
13544 Aiieeee!  I was dreading the day that the Demaillator turned his
13545 sights on automake@dots{} and now it has arrived! -- Tom Tromey
13546 @end quotation
13547
13548 It's only the beginning: in two months he will send 192 patches.  Then
13549 he would slow down so Tom can catch up and review all this.  Initially
13550 Tom actually read all these patches, then he probably trustingly
13551 answered OK to most of them, and finally gave up and let Akim apply
13552 whatever he wanted.  There was no way to keep up with that patch rate.
13553
13554 @quotation
13555 Anyway the patch below won't apply since it predates Akim's
13556 sourcequake; I have yet to figure where the relevant passage has
13557 been moved :) -- Alexandre Duret-Lutz
13558 @end quotation
13559
13560 All these patches were sent to and discussed on
13561 @email{automake@@gnu.org}, so subscribed users were literally drowning in
13562 technical mails.  Eventually, the @email{automake-patches@@gnu.org}
13563 mailing list was created in May.
13564
13565 Year after year, Automake had drifted away from its initial design:
13566 construct @file{Makefile.in} by assembling various @file{Makefile}
13567 fragments.  In 1.4, lots of @file{Makefile} rules are being emitted at
13568 various places in the @command{automake} script itself; this does not
13569 help ensuring a consistent treatment of these rules (for instance
13570 making sure that user-defined rules override Automake's own rules).
13571 One of Akim's goal was moving all these hard-coded rules to separate
13572 @file{Makefile} fragments, so the logic could be centralized in a
13573 @file{Makefile} fragment processor.
13574
13575 Another significant contribution of Akim is the interface with the
13576 ``trace'' feature of Autoconf.  The way to scan @file{configure.in} at
13577 this time was to read the file and grep the various macro of interest
13578 to Automake.  Doing so could break in many unexpected ways; @command{automake}
13579 could miss some definition (for instance @samp{AC_SUBST([$1], [$2])}
13580 where the arguments are known only when M4 is run), or conversely it
13581 could detect some macro that was not expanded (because it is called
13582 conditionally).  In the CVS version of Autoconf, Akim had implemented
13583 the @option{--trace} option, which provides accurate information about
13584 where macros are actually called and with what arguments.  Akim will
13585 equip Automake with a second @file{configure.in} scanner that uses
13586 this @option{--trace} interface.  Since it was not sensible to drop the
13587 Autoconf 2.13 compatibility yet, this experimental scanner was only
13588 used when an environment variable was set, the traditional
13589 grep-scanner being still the default.
13590
13591 @item 2001-04-25 Gary V.@tie{}Vaughan releases Libtool 1.4
13592
13593 It has been more than two years since Automake 1.4, CVS Automake has
13594 suffered lot's of heavy changes and still is not ready for release.
13595 Libtool 1.4 had to be distributed with a patch against Automake 1.4.
13596
13597 @item 2001-05-08 Automake 1.4-p1
13598 @itemx 2001-05-24 Automake 1.4-p2
13599
13600 Gary V.@tie{}Vaughan, the principal Libtool maintainer, makes a ``patch
13601 release'' of Automake:
13602
13603 @quotation
13604 The main purpose of this release is to have a stable automake
13605 which is compatible with the latest stable libtool.
13606 @end quotation
13607
13608 The release also contains obvious fixes for bugs in Automake 1.4,
13609 some of which were reported almost monthly.
13610
13611 @item 2001-05-21 Akim Demaille releases Autoconf 2.50
13612
13613 @item 2001-06-07 Automake 1.4-p3
13614 @itemx 2001-06-10 Automake 1.4-p4
13615 @itemx 2001-07-15 Automake 1.4-p5
13616
13617 Gary continues his patch-release series.  These also add support for
13618 some new Autoconf 2.50 idioms.  Essentially, Autoconf now advocates
13619 @file{configure.ac} over @file{configure.in}, and it introduces a new
13620 syntax for @code{AC_OUTPUT}ing files.
13621
13622 @item 2001-08-23 Automake 1.5
13623
13624 A major and long-awaited release, that comes more than two years after
13625 1.4.  It brings many changes, among which:
13626 @itemize
13627 @item The new dependency tracking scheme that uses @command{depcomp}.
13628 Aside from the improvement on the dependency tracking itself
13629 (@pxref{Dependency Tracking Evolution}), this also streamlines the use
13630 of @command{automake}-generated @file{Makefile.in}s as the @file{Makefile.in}s
13631 used during development are now the same as those used in
13632 distributions.  Before that the @file{Makefile.in}s generated for
13633 maintainers required GNU @command{make} and GCC, they were different
13634 from the portable @file{Makefile} generated for distribution; this was
13635 causing some confusion.
13636
13637 @item Support for per-target compilation flags.
13638
13639 @item Support for reference to files in subdirectories in most
13640 @file{Makefile.am} variables.
13641
13642 @item Introduction of the @code{dist_}, @code{nodist_}, and @code{nobase_}
13643 prefixes.
13644 @item Perl 4 support is finally dropped.
13645 @end itemize
13646
13647 1.5 did break several packages that worked with 1.4.  Enough so that
13648 Linux distributions could not easily install the new Automake version
13649 without breaking many of the packages for which they had to run
13650 @command{automake}.
13651
13652 Some of these breakages were effectively bugs that would eventually be
13653 fixed in the next release.  However, a lot of damage was caused by
13654 some changes made deliberately to render Automake stricter on some
13655 setup we did consider bogus.  For instance, @samp{make distcheck} was
13656 improved to check that @samp{make uninstall} did remove all the files
13657 @samp{make install} installed, that @samp{make distclean} did not omit
13658 some file, and that a VPATH build would work even if the source
13659 directory was read-only.  Similarly, Automake now rejects multiple
13660 definitions of the same variable (because that would mix very badly
13661 with conditionals), and @samp{+=} assignments with no previous
13662 definition.  Because these changes all occurred suddenly after 1.4 had
13663 been established for more than two years, it hurt users.
13664
13665 To make matter worse, meanwhile Autoconf (now at version 2.52) was
13666 facing similar troubles, for similar reasons.
13667
13668 @item 2002-03-05 Automake 1.6
13669
13670 This release introduced versioned installation (@pxref{API
13671 Versioning}).  This was mainly pushed by Havoc Pennington, taking the
13672 GNOME source tree as motive: due to incompatibilities between the
13673 autotools it's impossible for the GNOME packages to switch to Autoconf
13674 2.53 and Automake 1.5 all at once, so they are currently stuck with
13675 Autoconf 2.13 and Automake 1.4.
13676
13677 The idea was to call this version @file{automake-1.6}, call all its
13678 bug-fix versions identically, and switch to @file{automake-1.7} for
13679 the next release that adds new features or changes some rules.  This
13680 scheme implies maintaining a bug-fix branch in addition to the
13681 development trunk, which means more work from the maintainer, but
13682 providing regular bug-fix releases proved to be really worthwhile.
13683
13684 Like 1.5, 1.6 also introduced a bunch of incompatibilities, intentional or
13685 not.  Perhaps the more annoying was the dependence on the newly
13686 released Autoconf 2.53.  Autoconf seemed to have stabilized enough
13687 since its explosive 2.50 release and included changes required to fix
13688 some bugs in Automake.  In order to upgrade to Automake 1.6, people
13689 now had to upgrade Autoconf too; for some packages it was no picnic.
13690
13691 While versioned installation helped people to upgrade, it also
13692 unfortunately allowed people not to upgrade.  At the time of writing,
13693 some Linux distributions are shipping packages for Automake 1.4, 1.5,
13694 1.6, 1.7, 1.8, and 1.9.  Most of these still install 1.4 by default.
13695 Some distribution also call 1.4 the ``stable'' version, and present
13696 ``1.9'' as the development version; this does not really makes sense
13697 since 1.9 is way more solid than 1.4.  All this does not help the
13698 newcomer.
13699
13700 @item 2002-04-11 Automake 1.6.1
13701
13702 1.6, and the upcoming 1.4-p6 release were the last release by Tom.
13703 This one and those following will be handled by Alexandre
13704 Duret-Lutz.  Tom is still around, and will be there until about 1.7,
13705 but his interest into Automake is drifting away towards projects like
13706 @command{gcj}.
13707
13708 Alexandre has been using Automake since 2000, and started to
13709 contribute mostly on Akim's incitement (Akim and Alexandre have been
13710 working in the same room from 1999 to 2002).  In 2001 and 2002 he had
13711 a lot of free time to enjoy hacking Automake.
13712
13713 @item 2002-06-14 Automake 1.6.2
13714
13715 @item 2002-07-28 Automake 1.6.3
13716 @itemx 2002-07-28 Automake 1.4-p6
13717
13718 Two releases on the same day.  1.6.3 is a bug-fix release.
13719
13720 Tom Tromey backported the versioned installation mechanism on the 1.4
13721 branch, so that Automake 1.6.x and Automake 1.4-p6 could be installed
13722 side by side.  Another request from the GNOME folks.
13723
13724 @item 2002-09-25 Automake 1.7
13725
13726 This release switches to the new @file{configure.ac} scanner Akim
13727 was experimenting in 1.5.
13728
13729 @item 2002-10-16 Automake 1.7.1
13730 @itemx 2002-12-06 Automake 1.7.2
13731 @itemx 2003-02-20 Automake 1.7.3
13732 @itemx 2003-04-23 Automake 1.7.4
13733 @itemx 2003-05-18 Automake 1.7.5
13734 @itemx 2003-07-10 Automake 1.7.6
13735 @itemx 2003-09-07 Automake 1.7.7
13736 @itemx 2003-10-07 Automake 1.7.8
13737
13738 Many bug-fix releases.  1.7 lasted because the development version
13739 (upcoming 1.8) was suffering some major internal revamping.
13740
13741 @item 2003-10-26 Automake on screen
13742
13743 Episode 49, `Repercussions', in the third season of the `Alias' TV
13744 show is first aired.
13745
13746 Marshall, one of the characters, is working on a computer virus that he
13747 has to modify before it gets into the wrong hands or something like
13748 that.  The screenshots you see do not show any program code, they show
13749 a @file{Makefile.in} @code{generated by automake}...
13750
13751 @item 2003-11-09 Automake 1.7.9
13752
13753 @item 2003-12-10 Automake 1.8
13754
13755 The most striking update is probably that of @command{aclocal}.
13756
13757 @command{aclocal} now uses @code{m4_include} in the produced
13758 @file{aclocal.m4} when the included macros are already distributed
13759 with the package (an idiom used in many packages), which reduces code
13760 duplication.  Many people liked that, but in fact this change was
13761 really introduced to fix a bug in rebuild rules: @file{Makefile.in}
13762 must be rebuilt whenever a dependency of @file{configure} changes, but
13763 all the @file{m4} files included in @file{aclocal.m4} where unknown
13764 from @command{automake}.  Now @command{automake} can just trace the
13765 @code{m4_include}s to discover the dependencies.
13766
13767 @command{aclocal} also starts using the @option{--trace} Autoconf option
13768 in order to discover used macros more accurately.  This will turn out
13769 to be very tricky (later releases will improve this) as people had
13770 devised many ways to cope with the limitation of previous
13771 @command{aclocal} versions, notably using handwritten
13772 @code{m4_include}s: @command{aclocal} must make sure not to redefine a
13773 rule that is already included by such statement.
13774
13775 Automake also has seen its guts rewritten.  Although this rewriting
13776 took a lot of efforts, it is only apparent to the users in that some
13777 constructions previously disallowed by the implementation now work
13778 nicely.  Conditionals, Locations, Variable and Rule definitions,
13779 Options: these items on which Automake works have been rewritten as
13780 separate Perl modules, and documented.
13781
13782 @itemx 2004-01-11 Automake 1.8.1
13783 @itemx 2004-01-12 Automake 1.8.2
13784 @itemx 2004-03-07 Automake 1.8.3
13785 @itemx 2004-04-25 Automake 1.8.4
13786 @itemx 2004-05-16 Automake 1.8.5
13787
13788 @item 2004-07-28 Automake 1.9
13789
13790 This release tries to simplify the compilation rules it outputs to
13791 reduce the size of the Makefile.  The complaint initially come from
13792 the libgcj developers.  Their @file{Makefile.in} generated with
13793 Automake 1.4 and custom build rules (1.4 did not support compiled
13794 Java) is 250KB@.  The one generated by 1.8 was over 9MB@!  1.9 gets it
13795 down to 1.2MB@.
13796
13797 Aside from this it contains mainly minor changes and bug-fixes.
13798
13799 @itemx 2004-08-11 Automake 1.9.1
13800 @itemx 2004-09-19 Automake 1.9.2
13801
13802 Automake has ten years.  This chapter of the manual was initially
13803 written for this occasion.
13804
13805 @itemx 2007-10-29 Automake repository moves to @code{savannah.gnu.org} and uses
13806 git as primary repository.
13807
13808 @end table
13809
13810 @node Dependency Tracking Evolution
13811 @section Dependency Tracking in Automake
13812
13813 Over the years Automake has deployed three different dependency
13814 tracking methods.  Each method, including the current one, has had
13815 flaws of various sorts.  Here we lay out the different dependency
13816 tracking methods, their flaws, and their fixes.  We conclude with
13817 recommendations for tool writers, and by indicating future directions
13818 for dependency tracking work in Automake.
13819
13820 @menu
13821 * First Take on Dependencies::  Precomputed dependency tracking
13822 * Dependencies As Side Effects::  Update at developer compile time
13823 * Dependencies for the User::   Update at user compile time
13824 * Techniques for Dependencies::  Alternative approaches
13825 * Recommendations for Tool Writers::  What tool writers can do to help
13826 * Future Directions for Dependencies::  Languages Automake does not know
13827 @end menu
13828
13829 @node First Take on Dependencies
13830 @subsection First Take on Dependency Tracking
13831 @unnumberedsubsubsec Description
13832
13833 Our first attempt at automatic dependency tracking was based on the
13834 method recommended by GNU @command{make}.  (@pxref{Automatic
13835 Prerequisites, , Generating Prerequisites Automatically, make, The GNU
13836 make Manual})
13837
13838 This version worked by precomputing dependencies ahead of time.  For
13839 each source file, it had a special @file{.P} file that held the
13840 dependencies.  There was a rule to generate a @file{.P} file by
13841 invoking the compiler appropriately.  All such @file{.P} files were
13842 included by the @file{Makefile}, thus implicitly becoming dependencies
13843 of @file{Makefile}.
13844
13845 @unnumberedsubsubsec Bugs
13846
13847 This approach had several critical bugs.
13848
13849 @itemize
13850 @item
13851 The code to generate the @file{.P} file relied on @command{gcc}.
13852 (A limitation, not technically a bug.)
13853 @item
13854 The dependency tracking mechanism itself relied on GNU @command{make}.
13855 (A limitation, not technically a bug.)
13856 @item
13857 Because each @file{.P} file was a dependency of @file{Makefile}, this
13858 meant that dependency tracking was done eagerly by @command{make}.
13859 For instance, @samp{make clean} would cause all the dependency files
13860 to be updated, and then immediately removed.  This eagerness also
13861 caused problems with some configurations; if a certain source file
13862 could not be compiled on a given architecture for some reason,
13863 dependency tracking would fail, aborting the entire build.
13864 @item
13865 As dependency tracking was done as a pre-pass, compile times were
13866 doubled--the compiler had to be run twice per source file.
13867 @item
13868 @samp{make dist} re-ran @command{automake} to generate a
13869 @file{Makefile} that did not have automatic dependency tracking (and
13870 that was thus portable to any version of @command{make}).  In order to
13871 do this portably, Automake had to scan the dependency files and remove
13872 any reference that was to a source file not in the distribution.
13873 This process was error-prone.  Also, if @samp{make dist} was run in an
13874 environment where some object file had a dependency on a source file
13875 that was only conditionally created, Automake would generate a
13876 @file{Makefile} that referred to a file that might not appear in the
13877 end user's build.  A special, hacky mechanism was required to work
13878 around this.
13879 @end itemize
13880
13881 @unnumberedsubsubsec Historical Note
13882
13883 The code generated by Automake is often inspired by the
13884 @file{Makefile} style of a particular author.  In the case of the first
13885 implementation of dependency tracking, I believe the impetus and
13886 inspiration was Jim Meyering.  (I could be mistaken.  If you know
13887 otherwise feel free to correct me.)
13888
13889 @node Dependencies As Side Effects
13890 @subsection Dependencies As Side Effects
13891 @unnumberedsubsubsec Description
13892
13893 The next refinement of Automake's automatic dependency tracking scheme
13894 was to implement dependencies as side effects of the compilation.
13895 This was aimed at solving the most commonly reported problems with the
13896 first approach.  In particular we were most concerned with eliminating
13897 the weird rebuilding effect associated with make clean.
13898
13899 In this approach, the @file{.P} files were included using the
13900 @code{-include} command, which let us create these files lazily.  This
13901 avoided the @samp{make clean} problem.
13902
13903 We only computed dependencies when a file was actually compiled.  This
13904 avoided the performance penalty associated with scanning each file
13905 twice.  It also let us avoid the other problems associated with the
13906 first, eager, implementation.  For instance, dependencies would never
13907 be generated for a source file that was not compilable on a given
13908 architecture (because it in fact would never be compiled).
13909
13910 @unnumberedsubsubsec Bugs
13911
13912 @itemize
13913 @item
13914 This approach also relied on the existence of @command{gcc} and GNU
13915 @command{make}.  (A limitation, not technically a bug.)
13916 @item
13917 Dependency tracking was still done by the developer, so the problems
13918 from the first implementation relating to massaging of dependencies by
13919 @samp{make dist} were still in effect.
13920 @item
13921 This implementation suffered from the ``deleted header file'' problem.
13922 Suppose a lazily-created @file{.P} file includes a dependency on a
13923 given header file, like this:
13924
13925 @example
13926 maude.o: maude.c something.h
13927 @end example
13928
13929 Now suppose that you remove @file{something.h} and update @file{maude.c}
13930 so that this include is no longer needed.  If you run @command{make},
13931 you will get an error because there is no way to create
13932 @file{something.h}.
13933
13934 We fixed this problem in a later release by further massaging the
13935 output of @command{gcc} to include a dummy dependency for each header
13936 file.
13937 @end itemize
13938
13939 @node Dependencies for the User
13940 @subsection Dependencies for the User
13941 @unnumberedsubsubsec Description
13942
13943 The bugs associated with @samp{make dist}, over time, became a real
13944 problem.  Packages using Automake were being built on a large number
13945 of platforms, and were becoming increasingly complex.  Broken
13946 dependencies were distributed in ``portable'' @file{Makefile.in}s,
13947 leading to user complaints.  Also, the requirement for @command{gcc}
13948 and GNU @command{make} was a constant source of bug reports.  The next
13949 implementation of dependency tracking aimed to remove these problems.
13950
13951 We realized that the only truly reliable way to automatically track
13952 dependencies was to do it when the package itself was built.  This
13953 meant discovering a method portable to any version of make and any
13954 compiler.  Also, we wanted to preserve what we saw as the best point
13955 of the second implementation: dependency computation as a side effect
13956 of compilation.
13957
13958 In the end we found that most modern make implementations support some
13959 form of include directive.  Also, we wrote a wrapper script that let
13960 us abstract away differences between dependency tracking methods for
13961 compilers.  For instance, some compilers cannot generate dependencies
13962 as a side effect of compilation.  In this case we simply have the
13963 script run the compiler twice.  Currently our wrapper script
13964 (@command{depcomp}) knows about twelve different compilers (including
13965 a "compiler" that simply invokes @command{makedepend} and then the
13966 real compiler, which is assumed to be a standard Unix-like C compiler
13967 with no way to do dependency tracking).
13968
13969 @unnumberedsubsubsec Bugs
13970
13971 @itemize
13972 @item
13973 Running a wrapper script for each compilation slows down the build.
13974 @item
13975 Many users don't really care about precise dependencies.
13976 @item
13977 This implementation, like every other automatic dependency tracking
13978 scheme in common use today (indeed, every one we've ever heard of),
13979 suffers from the ``duplicated new header'' bug.
13980
13981 This bug occurs because dependency tracking tools, such as the
13982 compiler, only generate dependencies on the successful opening of a
13983 file, and not on every probe.
13984
13985 Suppose for instance that the compiler searches three directories for
13986 a given header, and that the header is found in the third directory.
13987 If the programmer erroneously adds a header file with the same name to
13988 the first directory, then a clean rebuild from scratch could fail
13989 (suppose the new header file is buggy), whereas an incremental rebuild
13990 will succeed.
13991
13992 What has happened here is that people have a misunderstanding of what
13993 a dependency is.  Tool writers think a dependency encodes information
13994 about which files were read by the compiler.  However, a dependency
13995 must actually encode information about what the compiler tried to do.
13996
13997 This problem is not serious in practice.  Programmers typically do not
13998 use the same name for a header file twice in a given project.  (At
13999 least, not in C or C++.  This problem may be more troublesome in
14000 Java.)  This problem is easy to fix, by modifying dependency
14001 generators to record every probe, instead of every successful open.
14002
14003 @item
14004 Since Automake generates dependencies as a side effect of compilation,
14005 there is a bootstrapping problem when header files are generated by
14006 running a program.  The problem is that, the first time the build is
14007 done, there is no way by default to know that the headers are
14008 required, so make might try to run a compilation for which the headers
14009 have not yet been built.
14010
14011 This was also a problem in the previous dependency tracking implementation.
14012
14013 The current fix is to use @code{BUILT_SOURCES} to list built headers
14014 (@pxref{Sources}).  This causes them to be built before any other
14015 build rules are run.  This is unsatisfactory as a general solution,
14016 however in practice it seems sufficient for most actual programs.
14017 @end itemize
14018
14019 This code is used since Automake 1.5.
14020
14021 In GCC 3.0, we managed to convince the maintainers to add special
14022 command-line options to help Automake more efficiently do its job.  We
14023 hoped this would let us avoid the use of a wrapper script when
14024 Automake's automatic dependency tracking was used with @command{gcc}.
14025
14026 Unfortunately, this code doesn't quite do what we want.  In
14027 particular, it removes the dependency file if the compilation fails;
14028 we'd prefer that it instead only touch the file in any way if the
14029 compilation succeeds.
14030
14031 Nevertheless, since Automake 1.7, when a recent @command{gcc} is
14032 detected at @command{configure} time, we inline the
14033 dependency-generation code and do not use the @command{depcomp}
14034 wrapper script.  This makes compilations faster for those using this
14035 compiler (probably our primary user base).  The counterpart is that
14036 because we have to encode two compilation rules in @file{Makefile}
14037 (with or without @command{depcomp}), the produced @file{Makefile}s are
14038 larger.
14039
14040 @node Techniques for Dependencies
14041 @subsection Techniques for Computing Dependencies
14042
14043 There are actually several ways for a build tool like Automake to
14044 cause tools to generate dependencies.
14045
14046 @table @asis
14047 @item @command{makedepend}
14048 This was a commonly-used method in the past.  The idea is to run a
14049 special program over the source and have it generate dependency
14050 information.  Traditional implementations of @command{makedepend} are
14051 not completely precise; ordinarily they were conservative and
14052 discovered too many dependencies.
14053 @item The tool
14054 An obvious way to generate dependencies is to simply write the tool so
14055 that it can generate the information needed by the build tool.  This is
14056 also the most portable method.  Many compilers have an option to
14057 generate dependencies.  Unfortunately, not all tools provide such an
14058 option.
14059 @item The file system
14060 It is possible to write a special file system that tracks opens,
14061 reads, writes, etc, and then feed this information back to the build
14062 tool.  @command{clearmake} does this.  This is a very powerful
14063 technique, as it doesn't require cooperation from the
14064 tool.  Unfortunately it is also very difficult to implement and also
14065 not practical in the general case.
14066 @item @code{LD_PRELOAD}
14067 Rather than use the file system, one could write a special library to
14068 intercept @code{open} and other syscalls.  This technique is also quite
14069 powerful, but unfortunately it is not portable enough for use in
14070 @command{automake}.
14071 @end table
14072
14073 @node Recommendations for Tool Writers
14074 @subsection Recommendations for Tool Writers
14075
14076 We think that every compilation tool ought to be able to generate
14077 dependencies as a side effect of compilation.  Furthermore, at least
14078 while @command{make}-based tools are nearly universally in use (at
14079 least in the free software community), the tool itself should generate
14080 dummy dependencies for header files, to avoid the deleted header file
14081 bug.  Finally, the tool should generate a dependency for each probe,
14082 instead of each successful file open, in order to avoid the duplicated
14083 new header bug.
14084
14085 @node Future Directions for Dependencies
14086 @subsection Future Directions for Dependencies
14087
14088 Currently, only languages and compilers understood by Automake can
14089 have dependency tracking enabled.  We would like to see if it is
14090 practical (and worthwhile) to let this support be extended by the user
14091 to languages unknown to Automake.
14092
14093 @node Releases
14094 @section Release Statistics
14095
14096 The following table (inspired by @samp{perlhist(1)}) quantifies the
14097 evolution of Automake using these metrics:
14098
14099 @table @asis
14100 @item Date, Rel
14101 The date and version of the release.
14102 @item am
14103 The number of lines of the @command{automake} script.
14104 @item acl
14105 The number of lines of the @command{aclocal} script.
14106 @item pm
14107 The number of lines of the @command{Perl} supporting modules.
14108 @item @file{*.am}
14109 The number of lines of the @file{Makefile} fragments.  The number in
14110 parentheses is the number of files.
14111 @item m4
14112 The number of lines (and files) of Autoconf macros.
14113 @item doc
14114 The number of pages of the documentation (the Postscript version).
14115 @item t
14116 The number of test cases in the test suite.  Of those, the number in
14117 parentheses is the number of generated test cases.
14118 @end table
14119
14120 @multitable {8888-88-88} {8.8-p8} {8888} {8888} {8888} {8888 (88)} {8888 (88)} {888} {888 (88)}
14121 @headitem Date   @tab Rel    @tab   am @tab acl @tab   pm @tab @file{*.am} @tab m4 @tab doc @tab t
14122 @item 1994-09-19 @tab CVS    @tab  141 @tab     @tab      @tab  299 (24) @tab           @tab     @tab
14123 @item 1994-11-05 @tab CVS    @tab  208 @tab     @tab      @tab  332 (28) @tab           @tab     @tab
14124 @item 1995-11-23 @tab 0.20   @tab  533 @tab     @tab      @tab  458 (35) @tab           @tab   9 @tab
14125 @item 1995-11-26 @tab 0.21   @tab  613 @tab     @tab      @tab  480 (36) @tab           @tab  11 @tab
14126 @item 1995-11-28 @tab 0.22   @tab 1116 @tab     @tab      @tab  539 (38) @tab           @tab  12 @tab
14127 @item 1995-11-29 @tab 0.23   @tab 1240 @tab     @tab      @tab  541 (38) @tab           @tab  12 @tab
14128 @item 1995-12-08 @tab 0.24   @tab 1462 @tab     @tab      @tab  504 (33) @tab           @tab  14 @tab
14129 @item 1995-12-10 @tab 0.25   @tab 1513 @tab     @tab      @tab  511 (37) @tab           @tab  15 @tab
14130 @item 1996-01-03 @tab 0.26   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
14131 @item 1996-01-03 @tab 0.27   @tab 1706 @tab     @tab      @tab  438 (36) @tab           @tab  16 @tab
14132 @item 1996-01-13 @tab 0.28   @tab 1964 @tab     @tab      @tab  934 (33) @tab           @tab  16 @tab
14133 @item 1996-02-07 @tab 0.29   @tab 2299 @tab     @tab      @tab  936 (33) @tab           @tab  17 @tab
14134 @item 1996-02-24 @tab 0.30   @tab 2544 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  20 @tab 9
14135 @item 1996-03-11 @tab 0.31   @tab 2877 @tab     @tab      @tab  919 (32) @tab   85 (1)  @tab  29 @tab 17
14136 @item 1996-04-27 @tab 0.32   @tab 3058 @tab     @tab      @tab  921 (31) @tab   85 (1)  @tab  30 @tab 26
14137 @item 1996-05-18 @tab 0.33   @tab 3110 @tab     @tab      @tab  926 (31) @tab  105 (1)  @tab  30 @tab 35
14138 @item 1996-05-28 @tab 1.0    @tab 3134 @tab     @tab      @tab  973 (32) @tab  105 (1)  @tab  30 @tab 38
14139 @item 1997-06-22 @tab 1.2    @tab 6089 @tab 385 @tab      @tab 1294 (36) @tab  592 (20) @tab  37 @tab 126
14140 @item 1998-04-05 @tab 1.3    @tab 6415 @tab 422 @tab      @tab 1470 (39) @tab  741 (23) @tab  39 @tab 156
14141 @item 1999-01-14 @tab 1.4    @tab 7240 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
14142 @item 2001-05-08 @tab 1.4-p1 @tab 7251 @tab 426 @tab      @tab 1591 (40) @tab  734 (20) @tab  51 @tab 197
14143 @item 2001-05-24 @tab 1.4-p2 @tab 7268 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
14144 @item 2001-06-07 @tab 1.4-p3 @tab 7312 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 197
14145 @item 2001-06-10 @tab 1.4-p4 @tab 7321 @tab 439 @tab      @tab 1591 (40) @tab  734 (20) @tab  49 @tab 198
14146 @item 2001-07-15 @tab 1.4-p5 @tab 7228 @tab 426 @tab      @tab 1596 (40) @tab  734 (20) @tab  51 @tab 198
14147 @item 2001-08-23 @tab 1.5    @tab 8016 @tab 475 @tab  600 @tab 2654 (39) @tab 1166 (29) @tab  63 @tab 327
14148 @item 2002-03-05 @tab 1.6    @tab 8465 @tab 475 @tab 1136 @tab 2732 (39) @tab 1603 (27) @tab  66 @tab 365
14149 @item 2002-04-11 @tab 1.6.1  @tab 8544 @tab 475 @tab 1136 @tab 2741 (39) @tab 1603 (27) @tab  66 @tab 372
14150 @item 2002-06-14 @tab 1.6.2  @tab 8575 @tab 475 @tab 1136 @tab 2800 (39) @tab 1609 (27) @tab  67 @tab 386
14151 @item 2002-07-28 @tab 1.6.3  @tab 8600 @tab 475 @tab 1153 @tab 2809 (39) @tab 1609 (27) @tab  67 @tab 391
14152 @item 2002-07-28 @tab 1.4-p6 @tab 7332 @tab 455 @tab      @tab 1596 (40) @tab  735 (20) @tab  49 @tab 197
14153 @item 2002-09-25 @tab 1.7    @tab 9189 @tab 471 @tab 1790 @tab 2965 (39) @tab 1606 (28) @tab  73 @tab 430
14154 @item 2002-10-16 @tab 1.7.1  @tab 9229 @tab 475 @tab 1790 @tab 2977 (39) @tab 1606 (28) @tab  73 @tab 437
14155 @item 2002-12-06 @tab 1.7.2  @tab 9334 @tab 475 @tab 1790 @tab 2988 (39) @tab 1606 (28) @tab  77 @tab 445
14156 @item 2003-02-20 @tab 1.7.3  @tab 9389 @tab 475 @tab 1790 @tab 3023 (39) @tab 1651 (29) @tab  84 @tab 448
14157 @item 2003-04-23 @tab 1.7.4  @tab 9429 @tab 475 @tab 1790 @tab 3031 (39) @tab 1644 (29) @tab  85 @tab 458
14158 @item 2003-05-18 @tab 1.7.5  @tab 9429 @tab 475 @tab 1790 @tab 3033 (39) @tab 1645 (29) @tab  85 @tab 459
14159 @item 2003-07-10 @tab 1.7.6  @tab 9442 @tab 475 @tab 1790 @tab 3033 (39) @tab 1660 (29) @tab  85 @tab 461
14160 @item 2003-09-07 @tab 1.7.7  @tab 9443 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 467
14161 @item 2003-10-07 @tab 1.7.8  @tab 9444 @tab 475 @tab 1790 @tab 3041 (39) @tab 1660 (29) @tab  90 @tab 468
14162 @item 2003-11-09 @tab 1.7.9  @tab 9444 @tab 475 @tab 1790 @tab 3048 (39) @tab 1660 (29) @tab  90 @tab 468
14163 @item 2003-12-10 @tab 1.8    @tab 7171 @tab 585 @tab 7730 @tab 3236 (39) @tab 1666 (31) @tab 104 @tab 521
14164 @item 2004-01-11 @tab 1.8.1  @tab 7217 @tab 663 @tab 7726 @tab 3287 (39) @tab 1686 (31) @tab 104 @tab 525
14165 @item 2004-01-12 @tab 1.8.2  @tab 7217 @tab 663 @tab 7726 @tab 3288 (39) @tab 1686 (31) @tab 104 @tab 526
14166 @item 2004-03-07 @tab 1.8.3  @tab 7214 @tab 686 @tab 7735 @tab 3303 (39) @tab 1695 (31) @tab 111 @tab 530
14167 @item 2004-04-25 @tab 1.8.4  @tab 7214 @tab 686 @tab 7736 @tab 3310 (39) @tab 1701 (31) @tab 112 @tab 531
14168 @item 2004-05-16 @tab 1.8.5  @tab 7240 @tab 686 @tab 7736 @tab 3299 (39) @tab 1701 (31) @tab 112 @tab 533
14169 @item 2004-07-28 @tab 1.9    @tab 7508 @tab 715 @tab 7794 @tab 3352 (40) @tab 1812 (32) @tab 115 @tab 551
14170 @item 2004-08-11 @tab 1.9.1  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 115 @tab 552
14171 @item 2004-09-19 @tab 1.9.2  @tab 7512 @tab 715 @tab 7794 @tab 3354 (40) @tab 1812 (32) @tab 132 @tab 554
14172 @item 2004-11-01 @tab 1.9.3  @tab 7507 @tab 718 @tab 7804 @tab 3354 (40) @tab 1812 (32) @tab 134 @tab 556
14173 @item 2004-12-18 @tab 1.9.4  @tab 7508 @tab 718 @tab 7856 @tab 3361 (40) @tab 1811 (32) @tab 140 @tab 560
14174 @item 2005-02-13 @tab 1.9.5  @tab 7523 @tab 719 @tab 7859 @tab 3373 (40) @tab 1453 (32) @tab 142 @tab 562
14175 @item 2005-07-10 @tab 1.9.6  @tab 7539 @tab 699 @tab 7867 @tab 3400 (40) @tab 1453 (32) @tab 144 @tab 570
14176 @item 2006-10-15 @tab 1.10   @tab 7859 @tab 1072 @tab 8024 @tab 3512 (40) @tab 1496 (34) @tab 172 @tab 604
14177 @item 2008-01-19 @tab 1.10.1 @tab 7870 @tab 1089 @tab 8025 @tab 3520 (40) @tab 1499 (34) @tab 173 @tab 617
14178 @item 2008-11-23 @tab 1.10.2 @tab 7882 @tab 1089 @tab 8027 @tab 3540 (40) @tab 1509 (34) @tab 176 @tab 628
14179 @item 2009-05-17 @tab 1.11   @tab 8721 @tab 1092 @tab 8289 @tab 4164 (42) @tab 1714 (37) @tab 181 @tab 732 (20)
14180 @end multitable
14181
14182
14183 @c ========================================================== Appendices
14184
14185 @page
14186 @node Copying This Manual
14187 @appendix Copying This Manual
14188
14189 @menu
14190 * GNU Free Documentation License::  License for copying this manual
14191 @end menu
14192
14193 @node GNU Free Documentation License
14194 @appendixsec GNU Free Documentation License
14195 @include fdl.texi
14196
14197 @page
14198 @node Indices
14199 @appendix Indices
14200
14201 @menu
14202 * Macro Index::                 Index of Autoconf macros
14203 * Variable Index::              Index of Makefile variables
14204 * General Index::               General index
14205 @end menu
14206
14207 @node Macro Index
14208 @appendixsec Macro Index
14209
14210 @printindex fn
14211
14212 @node Variable Index
14213 @appendixsec Variable Index
14214
14215 @printindex vr
14216
14217 @node General Index
14218 @appendixsec General Index
14219
14220 @printindex cp
14221
14222
14223 @bye
14224
14225 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
14226 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
14227 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
14228 @c  LocalWords:  dir Automake's ac Dist Gnits gnits cygnus dfn Autoconf's pxref
14229 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
14230 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
14231 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
14232 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
14233 @c  LocalWords:  libmumble CC YFLAGS itemx de fication config url comp
14234 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
14235 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
14236 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
14237 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
14238 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
14239 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
14240 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
14241 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
14242 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
14243 @c  LocalWords:  dirlist noindent usr TIOCGWINSZ sc
14244 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
14245 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
14246 @c  LocalWords:  dmalloc ldmalloc REGEX regex DEPDIR DEP DEFUN aclocaldir fi
14247 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
14248 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
14249 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
14250 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
14251 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
14252 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
14253 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
14254 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
14255 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
14256 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
14257 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
14258 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
14259 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
14260 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
14261 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
14262 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
14263 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
14264 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
14265 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
14266 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
14267 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
14268 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
14269 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
14270 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
14271 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
14272 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
14273 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
14274 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
14275 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid cd
14276 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
14277 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
14278 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
14279 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
14280 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
14281 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
14282 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
14283 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
14284 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
14285 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
14286 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
14287 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
14288 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
14289 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
14290 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
14291 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
14292 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
14293 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
14294 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
14295 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
14296 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
14297 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
14298 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
14299 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
14300 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
14301 @c  LocalWords:  barexec Pinard's automatize initialize lzip lzma xz cscope