Merge branch 'maint'
[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-2012 Free Software Foundation, Inc.
27
28 @quotation
29 Permission is granted to copy, distribute and/or modify this document
30 under the terms of the GNU Free Documentation License,
31 Version 1.3 or any later version published by the Free Software
32 Foundation; with no Invariant Sections, with no Front-Cover texts,
33 and with no Back-Cover Texts.  A copy of the license is included in the
34 section entitled ``GNU Free Documentation License.''
35
36 @end quotation
37 @end copying
38
39 @dircategory Software development
40 @direntry
41 * Automake: (automake).         Making GNU standards-compliant Makefiles.
42 @end direntry
43
44 @dircategory Individual utilities
45 @direntry
46 * aclocal-invocation: (automake)aclocal Invocation.   Generating aclocal.m4.
47 * automake-invocation: (automake)automake Invocation. Generating Makefile.in.
48 @end direntry
49
50 @titlepage
51 @title GNU Automake
52 @subtitle For version @value{VERSION}, @value{UPDATED}
53 @author David MacKenzie
54 @author Tom Tromey
55 @author Alexandre Duret-Lutz
56 @page
57 @vskip 0pt plus 1filll
58 @insertcopying
59 @end titlepage
60
61 @contents
62
63 @c We use the following macros to define indices:
64 @c   @cindex   concepts, and anything that does not fit elsewhere
65 @c   @vindex   Makefile variables
66 @c   @trindex  targets
67 @c   @acindex  Autoconf/Automake/Libtool/M4/... macros
68 @c   @opindex  tool options
69
70 @c Define an index of configure macros.
71 @defcodeindex ac
72 @c Define an index of options.
73 @defcodeindex op
74 @c Define an index of targets.
75 @defcodeindex tr
76 @c Define an index of commands.
77 @defcodeindex cm
78
79 @c Put the macros in the function index.
80 @syncodeindex ac fn
81
82 @c Put everything else into one index (arbitrarily chosen to be the
83 @c concept index).
84 @syncodeindex op cp
85 @syncodeindex tr cp
86 @syncodeindex cm cp
87
88 @ifnottex
89 @node Top
90 @comment  node-name,  next,  previous,  up
91 @top GNU Automake
92
93 @insertcopying
94
95 @menu
96 * Introduction::                Automake's purpose
97 * Autotools Introduction::      An Introduction to the Autotools
98 * Generalities::                General ideas
99 * Examples::                    Some example packages
100 * automake Invocation::         Creating a Makefile.in
101 * configure::                   Scanning configure.ac, using aclocal
102 * Directories::                 Declaring subdirectories
103 * Programs::                    Building programs and libraries
104 * Other Objects::               Other derived objects
105 * Other GNU Tools::             Other GNU Tools
106 * Documentation::               Building documentation
107 * Install::                     What gets installed
108 * Clean::                       What gets cleaned
109 * Dist::                        What goes in a distribution
110 * Tests::                       Support for test suites
111 * Rebuilding::                  Automatic rebuilding of Makefile
112 * Options::                     Changing Automake's behavior
113 * Miscellaneous::               Miscellaneous rules
114 * Include::                     Including extra files in an Automake template
115 * Conditionals::                Conditionals
116 * Silencing Make::              Obtain less verbose output from @command{make}
117 * Gnits::                       The effect of @option{--gnu} and @option{--gnits}
118 * Not Enough::                  When Automake is not Enough
119 * Distributing::                Distributing the Makefile.in
120 * API Versioning::              About compatibility between Automake versions
121 * Upgrading::                   Upgrading to a Newer Automake Version
122 * FAQ::                         Frequently Asked Questions
123 * Copying This Manual::         How to make copies of this manual
124 * Indices::                     Indices of variables, macros, and concepts
125
126 @detailmenu
127  --- The Detailed Node Listing ---
128
129 An Introduction to the Autotools
130
131 * GNU Build System::            Introducing the GNU Build System
132 * Use Cases::                   Use Cases for the GNU Build System
133 * Why Autotools::               How Autotools Help
134 * Hello World::                 A Small Hello World Package
135
136 Use Cases for the GNU Build System
137
138 * Basic Installation::          Common installation procedure
139 * Standard Targets::            A list of standard Makefile targets
140 * Standard Directory Variables::  A list of standard directory variables
141 * Standard Configuration Variables::  Using configuration variables
142 * config.site::                 Using a config.site file
143 * VPATH Builds::                Parallel build trees
144 * Two-Part Install::            Installing data and programs separately
145 * Cross-Compilation::           Building for other architectures
146 * Renaming::                    Renaming programs at install time
147 * DESTDIR::                     Building binary packages with DESTDIR
148 * Preparing Distributions::     Rolling out tarballs
149 * Dependency Tracking::         Automatic dependency tracking
150 * Nested Packages::             The GNU Build Systems can be nested
151
152 A Small Hello World
153
154 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
155 * amhello's configure.ac Setup Explained::
156 * amhello's Makefile.am Setup Explained::
157
158 General ideas
159
160 * General Operation::           General operation of Automake
161 * Strictness::                  Standards conformance checking
162 * Uniform::                     The Uniform Naming Scheme
163 * Length Limitations::          Staying below the command line length limit
164 * Canonicalization::            How derived variables are named
165 * User Variables::              Variables reserved for the user
166 * Auxiliary Programs::          Programs automake might require
167
168 Some example packages
169
170 * Complete::                    A simple example, start to finish
171 * true::                        Building true and false
172
173 Scanning @file{configure.ac}, using @command{aclocal}
174
175 * Requirements::                Configuration requirements
176 * Optional::                    Other things Automake recognizes
177 * aclocal Invocation::          Auto-generating aclocal.m4
178 * Macros::                      Autoconf macros supplied with Automake
179
180 Auto-generating aclocal.m4
181
182 * aclocal Options::             Options supported by aclocal
183 * Macro Search Path::           How aclocal finds .m4 files
184 * Extending aclocal::           Writing your own aclocal macros
185 * Local Macros::                Organizing local macros
186 * Serials::                     Serial lines in Autoconf macros
187 * Future of aclocal::           aclocal's scheduled death
188
189 Autoconf macros supplied with Automake
190
191 * Public Macros::               Macros that you can use.
192 * Private Macros::              Macros that you should not use.
193
194 Directories
195
196 * Subdirectories::              Building subdirectories recursively
197 * Conditional Subdirectories::  Conditionally not building directories
198 * Alternative::                 Subdirectories without recursion
199 * Subpackages::                 Nesting packages
200
201 Conditional Subdirectories
202
203 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
204 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
205 * Subdirectories with AC_SUBST::  Another way for conditional recursion
206 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
207
208 Building Programs and Libraries
209
210 * A Program::                   Building a program
211 * A Library::                   Building a library
212 * A Shared Library::            Building a Libtool library
213 * Program and Library Variables::  Variables controlling program and
214                                 library builds
215 * Default _SOURCES::            Default source files
216 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
217 * Program Variables::           Variables used when building a program
218 * Yacc and Lex::                Yacc and Lex support
219 * C++ Support::                 Compiling C++ sources
220 * Objective C Support::         Compiling Objective C sources
221 * Objective C++ Support::       Compiling Objective C++ sources
222 * Unified Parallel C Support::  Compiling Unified Parallel C sources
223 * Assembly Support::            Compiling assembly sources
224 * Fortran 77 Support::          Compiling Fortran 77 sources
225 * Fortran 9x Support::          Compiling Fortran 9x sources
226 * Java Support with gcj::       Compiling Java sources using gcj
227 * Vala Support::                Compiling Vala sources
228 * Support for Other Languages::  Compiling other languages
229 * Dependencies::                Automatic dependency tracking
230 * EXEEXT::                      Support for executable extensions
231
232 Building a program
233
234 * Program Sources::             Defining program sources
235 * Linking::                     Linking with libraries or extra objects
236 * Conditional Sources::         Handling conditional sources
237 * Conditional Programs::        Building a program conditionally
238
239 Building a Shared Library
240
241 * Libtool Concept::             Introducing Libtool
242 * Libtool Libraries::           Declaring Libtool Libraries
243 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
244 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
245 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
246 * Libtool Modules::             Building Libtool Modules
247 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
248 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
249 * Libtool Issues::              Common Issues Related to Libtool's Use
250
251 Common Issues Related to Libtool's Use
252
253 * Error required file ltmain.sh not found::  The need to run libtoolize
254 * Objects created both with libtool and without::  Avoid a specific build race
255
256 Fortran 77 Support
257
258 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
259 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
260 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
261
262 Mixing Fortran 77 With C and C++
263
264 * How the Linker is Chosen::    Automatic linker selection
265
266 Fortran 9x Support
267
268 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
269
270 Other Derived Objects
271
272 * Scripts::                     Executable scripts
273 * Headers::                     Header files
274 * Data::                        Architecture-independent data files
275 * Sources::                     Derived sources
276
277 Built Sources
278
279 * Built Sources Example::       Several ways to handle built sources.
280
281 Other GNU Tools
282
283 * Emacs Lisp::                  Emacs Lisp
284 * gettext::                     Gettext
285 * Libtool::                     Libtool
286 * Java::                        Java bytecode compilation (deprecated)
287 * Python::                      Python
288
289 Building documentation
290
291 * Texinfo::                     Texinfo
292 * Man Pages::                   Man pages
293
294 What Gets Installed
295
296 * Basics of Installation::      What gets installed where
297 * The Two Parts of Install::    Installing data and programs separately
298 * Extending Installation::      Adding your own rules for installation
299 * Staged Installs::             Installation in a temporary location
300 * Install Rules for the User::  Useful additional rules
301
302 What Goes in a Distribution
303
304 * Basics of Distribution::      Files distributed by default
305 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
306 * The dist Hook::               A target for last-minute distribution changes
307 * Checking the Distribution::   @samp{make distcheck} explained
308 * The Types of Distributions::  A variety of formats and compression methods
309
310 Support for test suites
311
312 * Generalities about Testing::  Generic concepts and terminology about testing
313 * Simple Tests::                Listing test scripts in @code{TESTS}
314 * Custom Test Drivers::         Writing and using custom test drivers
315 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
316 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
317 * Install Tests::               Running tests on installed packages
318
319 Simple Tests
320
321 * Scripts-based Testsuites::    Automake-specific concepts and terminology
322 * Serial Test Harness::         Older (and obsolescent) serial test harness
323 * Parallel Test Harness::       Generic concurrent test harness
324
325 Using the TAP test protocol
326
327 * Introduction to TAP::
328 * Use TAP with the Automake test harness::
329 * Incompatibilities with other TAP parsers and drivers::
330 * Links and external resources on TAP::
331
332 Custom Test Drivers
333
334 * Overview of Custom Test Drivers Support::
335 * Declaring Custom Test Drivers::
336 * API for Custom Test Drivers::
337
338 API for Custom Test Drivers
339
340 * Command-line arguments for test drivers::
341 * Log files generation and test results recording::
342 * Testsuite progress output::
343
344 Changing Automake's Behavior
345
346 * Options generalities::        Semantics of Automake option
347 * List of Automake options::    A comprehensive list of Automake options
348
349 Miscellaneous Rules
350
351 * Tags::                        Interfacing to cscope, etags and mkid
352 * Suffixes::                    Handling new file extensions
353
354 Conditionals
355
356 * Usage of Conditionals::       Declaring conditional content
357 * Limits of Conditionals::      Enclosing complete statements
358
359 Silencing Make
360
361 * Make verbosity::              Make is verbose by default
362 * Tricks For Silencing Make::   Standard and generic ways to silence make
363 * Automake Silent Rules::       How Automake can help in silencing make
364
365 When Automake Isn't Enough
366
367 * Extending::                   Adding new rules or overriding existing ones.
368 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
369
370 Frequently Asked Questions about Automake
371
372 * CVS::                         CVS and generated files
373 * maintainer-mode::             missing and AM_MAINTAINER_MODE
374 * Wildcards::                   Why doesn't Automake support wildcards?
375 * Limitations on File Names::   Limitations on source and installed file names
376 * Errors with distclean::       Files left in build directory after distclean
377 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
378 * Renamed Objects::             Why are object files sometimes renamed?
379 * Per-Object Flags::            How to simulate per-object flags?
380 * Multiple Outputs::            Writing rules for tools with many output files
381 * Hard-Coded Install Paths::    Installing to hard-coded locations
382 * Debugging Make Rules::        Strategies when things don't work as expected
383 * Reporting Bugs::              Feedback on bugs and feature requests
384
385 Copying This Manual
386
387 * GNU Free Documentation License::  License for copying this manual
388
389 Indices
390
391 * Macro Index::                 Index of Autoconf macros
392 * Variable Index::              Index of Makefile variables
393 * General Index::               General index
394
395 @end detailmenu
396 @end menu
397
398 @end ifnottex
399
400
401 @node Introduction
402 @chapter Introduction
403
404 Automake is a tool for automatically generating @file{Makefile.in}s
405 from files called @file{Makefile.am}.  Each @file{Makefile.am} is
406 basically a series of @command{make} variable
407 definitions@footnote{These variables are also called @dfn{make macros}
408 in Make terminology, however in this manual we reserve the term
409 @dfn{macro} for Autoconf's macros.}, with rules being thrown in
410 occasionally.  The generated @file{Makefile.in}s are compliant with
411 the GNU Makefile standards.
412
413 @cindex GNU Makefile standards
414
415 The GNU Makefile Standards Document
416 (@pxref{Makefile Conventions, , , standards, The GNU Coding Standards})
417 is long, complicated, and subject to change.  The goal of Automake is to
418 remove the burden of Makefile maintenance from the back of the
419 individual GNU maintainer (and put it on the back of the Automake
420 maintainers).
421
422 The typical Automake input file is simply a series of variable definitions.
423 Each such file is processed to create a @file{Makefile.in}.  There
424 should generally be one @file{Makefile.am} per directory of a project.
425
426 @cindex Constraints of Automake
427 @cindex Automake constraints
428
429 Automake does constrain a project in certain ways; for instance, it
430 assumes that the project uses Autoconf (@pxref{Top, , Introduction,
431 autoconf, The Autoconf Manual}), and enforces certain restrictions on
432 the @file{configure.ac} contents.
433
434 @cindex Automake requirements
435 @cindex Requirements, Automake
436
437 Automake requires @command{perl} in order to generate the
438 @file{Makefile.in}s.  However, the distributions created by Automake are
439 fully GNU standards-compliant, and do not require @command{perl} in order
440 to be built.
441
442 @cindex Bugs, reporting
443 @cindex Reporting bugs
444 @cindex E-mail, bug reports
445
446 For more information on bug reports, @xref{Reporting Bugs}.
447
448 @node Autotools Introduction
449 @chapter An Introduction to the Autotools
450
451 If you are new to Automake, maybe you know that it is part of a set of
452 tools called @emph{The Autotools}.  Maybe you've already delved into a
453 package full of files named @file{configure}, @file{configure.ac},
454 @file{Makefile.in}, @file{Makefile.am}, @file{aclocal.m4}, @dots{},
455 some of them claiming to be @emph{generated by} Autoconf or Automake.
456 But the exact purpose of these files and their relations is probably
457 fuzzy.  The goal of this chapter is to introduce you to this machinery,
458 to show you how it works and how powerful it is.  If you've never
459 installed or seen such a package, do not worry: this chapter will walk
460 you through it.
461
462 If you need some teaching material, more illustrations, or a less
463 @command{automake}-centered continuation, some slides for this
464 introduction are available in Alexandre Duret-Lutz's
465 @uref{http://www.lrde.epita.fr/@/~adl/@/autotools.html,
466 Autotools Tutorial}.
467 This chapter is the written version of the first part of his tutorial.
468
469 @menu
470 * GNU Build System::            Introducing the GNU Build System
471 * Use Cases::                   Use Cases for the GNU Build System
472 * Why Autotools::               How Autotools Help
473 * Hello World::                 A Small Hello World Package
474 @end menu
475
476 @node GNU Build System
477 @section Introducing the GNU Build System
478 @cindex GNU Build System, introduction
479
480 It is a truth universally acknowledged, that as a developer in
481 possession of a new package, you must be in want of a build system.
482
483 In the Unix world, such a build system is traditionally achieved using
484 the command @command{make} (@pxref{Top, , Overview, make, The GNU Make
485 Manual}).  You express the recipe to build your package in a
486 @file{Makefile}.  This file is a set of rules to build the files in
487 the package.  For instance the program @file{prog} may be built by
488 running the linker on the files @file{main.o}, @file{foo.o}, and
489 @file{bar.o}; the file @file{main.o} may be built by running the
490 compiler on @file{main.c}; etc.  Each time @command{make} is run, it
491 reads @file{Makefile}, checks the existence and modification time of
492 the files mentioned, decides what files need to be built (or rebuilt),
493 and runs the associated commands.
494
495 When a package needs to be built on a different platform than the one
496 it was developed on, its @file{Makefile} usually needs to be adjusted.
497 For instance the compiler may have another name or require more
498 options.  In 1991, David J. MacKenzie got tired of customizing
499 @file{Makefile} for the 20 platforms he had to deal with.  Instead, he
500 handcrafted a little shell script called @file{configure} to
501 automatically adjust the @file{Makefile} (@pxref{Genesis, , Genesis,
502 autoconf, The Autoconf Manual}).  Compiling his package was now
503 as simple as running @code{./configure && make}.
504
505 @cindex GNU Coding Standards
506
507 Today this process has been standardized in the GNU project.  The GNU
508 Coding Standards (@pxref{Managing Releases, The Release Process, ,
509 standards, The GNU Coding Standards}) explains how each package of the
510 GNU project should have a @file{configure} script, and the minimal
511 interface it should have.  The @file{Makefile} too should follow some
512 established conventions.  The result?  A unified build system that
513 makes all packages almost indistinguishable by the installer.  In its
514 simplest scenario, all the installer has to do is to unpack the
515 package, run @code{./configure && make && make install}, and repeat
516 with the next package to install.
517
518 We call this build system the @dfn{GNU Build System}, since it was
519 grown out of the GNU project.  However it is used by a vast number of
520 other packages: following any existing convention has its advantages.
521
522 @cindex Autotools, introduction
523
524 The Autotools are tools that will create a GNU Build System for your
525 package.  Autoconf mostly focuses on @file{configure} and Automake on
526 @file{Makefile}s.  It is entirely possible to create a GNU Build
527 System without the help of these tools.  However it is rather
528 burdensome and error-prone.  We will discuss this again after some
529 illustration of the GNU Build System in action.
530
531 @node Use Cases
532 @section Use Cases for the GNU Build System
533 @cindex GNU Build System, use cases
534 @cindex GNU Build System, features
535 @cindex Features of the GNU Build System
536 @cindex Use Cases for the GNU Build System
537 @cindex @file{amhello-1.0.tar.gz}, location
538 @cindex @file{amhello-1.0.tar.gz}, use cases
539
540 In this section we explore several use cases for the GNU Build System.
541 You can replay all of these examples on the @file{amhello-1.0.tar.gz}
542 package distributed with Automake.  If Automake is installed on your
543 system, you should find a copy of this file in
544 @file{@var{prefix}/share/doc/automake/amhello-1.0.tar.gz}, where
545 @var{prefix} is the installation prefix specified during configuration
546 (@var{prefix} defaults to @file{/usr/local}, however if Automake was
547 installed by some GNU/Linux distribution it most likely has been set
548 to @file{/usr}).  If you do not have a copy of Automake installed,
549 you can find a copy of this file inside the @file{doc/} directory of
550 the Automake package.
551
552 Some of the following use cases present features that are in fact
553 extensions to the GNU Build System.  Read: they are not specified by
554 the GNU Coding Standards, but they are nonetheless part of the build
555 system created by the Autotools.  To keep things simple, we do not
556 point out the difference.  Our objective is to show you many of the
557 features that the build system created by the Autotools will offer to
558 you.
559
560 @menu
561 * Basic Installation::          Common installation procedure
562 * Standard Targets::            A list of standard Makefile targets
563 * Standard Directory Variables::  A list of standard directory variables
564 * Standard Configuration Variables::  Using configuration variables
565 * config.site::                 Using a config.site file
566 * VPATH Builds::                Parallel build trees
567 * Two-Part Install::            Installing data and programs separately
568 * Cross-Compilation::           Building for other architectures
569 * Renaming::                    Renaming programs at install time
570 * DESTDIR::                     Building binary packages with DESTDIR
571 * Preparing Distributions::     Rolling out tarballs
572 * Dependency Tracking::         Automatic dependency tracking
573 * Nested Packages::             The GNU Build Systems can be nested
574 @end menu
575
576 @node Basic Installation
577 @subsection Basic Installation
578 @cindex Configuration, basics
579 @cindex Installation, basics
580 @cindex GNU Build System, basics
581
582 The most common installation procedure looks as follows.
583
584 @example
585 ~ % @kbd{tar zxf amhello-1.0.tar.gz}
586 ~ % @kbd{cd amhello-1.0}
587 ~/amhello-1.0 % @kbd{./configure}
588 @dots{}
589 config.status: creating Makefile
590 config.status: creating src/Makefile
591 @dots{}
592 ~/amhello-1.0 % @kbd{make}
593 @dots{}
594 ~/amhello-1.0 % @kbd{make check}
595 @dots{}
596 ~/amhello-1.0 % @kbd{su}
597 Password:
598 /home/adl/amhello-1.0 # @kbd{make install}
599 @dots{}
600 /home/adl/amhello-1.0 # @kbd{exit}
601 ~/amhello-1.0 % @kbd{make installcheck}
602 @dots{}
603 @end example
604
605 @cindex Unpacking
606
607 The user first unpacks the package.  Here, and in the following
608 examples, we will use the non-portable @code{tar zxf} command for
609 simplicity.  On a system without GNU @command{tar} installed, this
610 command should read @code{gunzip -c amhello-1.0.tar.gz | tar xf -}.
611
612 The user then enters the newly created directory to run the
613 @file{configure} script.  This script probes the system for various
614 features, and finally creates the @file{Makefile}s.  In this toy
615 example there are only two @file{Makefile}s, but in real-world projects,
616 there may be many more, usually one @file{Makefile} per directory.
617
618 It is now possible to run @code{make}.  This will construct all the
619 programs, libraries, and scripts that need to be constructed for the
620 package.  In our example, this compiles the @file{hello} program.
621 All files are constructed in place, in the source tree; we will see
622 later how this can be changed.
623
624 @code{make check} causes the package's tests to be run.  This step is
625 not mandatory, but it is often good to make sure the programs that
626 have been built behave as they should, before you decide to install
627 them.  Our example does not contain any tests, so running @code{make
628 check} is a no-op.
629
630 @cindex su, before @code{make install}
631 After everything has been built, and maybe tested, it is time to
632 install it on the system.  That means copying the programs,
633 libraries, header files, scripts, and other data files from the
634 source directory to their final destination on the system.  The
635 command @code{make install} will do that.  However, by default
636 everything will be installed in subdirectories of @file{/usr/local}:
637 binaries will go into @file{/usr/local/bin}, libraries will end up in
638 @file{/usr/local/lib}, etc.  This destination is usually not writable
639 by any user, so we assume that we have to become root before we can
640 run @code{make install}.  In our example, running @code{make install}
641 will copy the program @file{hello} into @file{/usr/local/bin}
642 and @file{README} into @file{/usr/local/share/doc/amhello}.
643
644 A last and optional step is to run @code{make installcheck}.  This
645 command may run tests on the installed files.  @code{make check} tests
646 the files in the source tree, while @code{make installcheck} tests
647 their installed copies.  The tests run by the latter can be different
648 from those run by the former.  For instance, there are tests that
649 cannot be run in the source tree.  Conversely, some packages are set
650 up so that @code{make installcheck} will run the very same tests as
651 @code{make check}, only on different files (non-installed
652 vs.@: installed).  It can make a difference, for instance when the
653 source tree's layout is different from that of the installation.
654 Furthermore it may help to diagnose an incomplete installation.
655
656 Presently most packages do not have any @code{installcheck} tests
657 because the existence of @code{installcheck} is little known, and its
658 usefulness is neglected.  Our little toy package is no better: @code{make
659 installcheck} does nothing.
660
661 @node Standard Targets
662 @subsection Standard @file{Makefile} Targets
663
664 So far we have come across four ways to run @command{make} in the GNU
665 Build System: @code{make}, @code{make check}, @code{make install}, and
666 @code{make installcheck}.  The words @code{check}, @code{install}, and
667 @code{installcheck}, passed as arguments to @command{make}, are called
668 @dfn{targets}.  @code{make} is a shorthand for @code{make all},
669 @code{all} being the default target in the GNU Build System.
670
671 Here is a list of the most useful targets that the GNU Coding Standards
672 specify.
673
674 @table @code
675 @item make all
676 @trindex all
677 Build programs, libraries, documentation, etc.@: (same as @code{make}).
678 @item make install
679 @trindex install
680 Install what needs to be installed, copying the files from the
681 package's tree to system-wide directories.
682 @item make install-strip
683 @trindex install-strip
684 Same as @code{make install}, then strip debugging symbols.  Some
685 users like to trade space for useful bug reports@enddots{}
686 @item make uninstall
687 @trindex uninstall
688 The opposite of @code{make install}: erase the installed files.
689 (This needs to be run from the same build tree that was installed.)
690 @item make clean
691 @trindex clean
692 Erase from the build tree the files built by @code{make all}.
693 @item make distclean
694 @trindex distclean
695 Additionally erase anything @code{./configure} created.
696 @item make check
697 @trindex check
698 Run the test suite, if any.
699 @item make installcheck
700 @trindex installcheck
701 Check the installed programs or libraries, if supported.
702 @item make dist
703 @trindex dist
704 Recreate @file{@var{package}-@var{version}.tar.gz} from all the source
705 files.
706 @end table
707
708 @node Standard Directory Variables
709 @subsection Standard Directory Variables
710 @cindex directory variables
711
712 The GNU Coding Standards also specify a hierarchy of variables to
713 denote installation directories.  Some of these are:
714
715 @multitable {Directory variable} {@code{$@{datarootdir@}/doc/$@{PACKAGE@}}}
716 @headitem Directory variable    @tab Default value
717 @item @code{prefix}              @tab @code{/usr/local}
718 @item @w{@ @ @code{exec_prefix}} @tab @code{$@{prefix@}}
719 @item @w{@ @ @ @ @code{bindir}}  @tab @code{$@{exec_prefix@}/bin}
720 @item @w{@ @ @ @ @code{libdir}}  @tab @code{$@{exec_prefix@}/lib}
721 @item @w{@ @ @ @ @dots{}}
722 @item @w{@ @ @code{includedir}}  @tab @code{$@{prefix@}/include}
723 @item @w{@ @ @code{datarootdir}} @tab @code{$@{prefix@}/share}
724 @item @w{@ @ @ @ @code{datadir}} @tab @code{$@{datarootdir@}}
725 @item @w{@ @ @ @ @code{mandir}}  @tab @code{$@{datarootdir@}/man}
726 @item @w{@ @ @ @ @code{infodir}} @tab @code{$@{datarootdir@}/info}
727 @item @w{@ @ @ @ @code{docdir}}  @tab @code{$@{datarootdir@}/doc/$@{PACKAGE@}}
728 @item @w{@ @ @dots{}}
729 @end multitable
730
731 @c We should provide a complete table somewhere, but not here.  The
732 @c complete list of directory variables it too confusing as-is.  It
733 @c requires some explanations that are too complicated for this
734 @c introduction.  Besides listing directories like localstatedir
735 @c would make the explanations in ``Two-Part Install'' harder.
736
737 Each of these directories has a role which is often obvious from its
738 name.  In a package, any installable file will be installed in one of
739 these directories.  For instance in @code{amhello-1.0}, the program
740 @file{hello} is to be installed in @var{bindir}, the directory for
741 binaries.  The default value for this directory is
742 @file{/usr/local/bin}, but the user can supply a different value when
743 calling @command{configure}.  Also the file @file{README} will be
744 installed into @var{docdir}, which defaults to
745 @file{/usr/local/share/doc/amhello}.
746
747 @opindex --prefix
748
749 As a user, if you wish to install a package on your own account, you
750 could proceed as follows:
751
752 @example
753 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
754 @dots{}
755 ~/amhello-1.0 % @kbd{make}
756 @dots{}
757 ~/amhello-1.0 % @kbd{make install}
758 @dots{}
759 @end example
760
761 This would install @file{~/usr/bin/hello} and
762 @file{~/usr/share/doc/amhello/README}.
763
764 The list of all such directory options is shown by
765 @code{./configure --help}.
766
767 @node Standard Configuration Variables
768 @subsection Standard Configuration Variables
769 @cindex configuration variables, overriding
770
771 The GNU Coding Standards also define a set of standard configuration
772 variables used during the build.  Here are some:
773
774 @table @asis
775 @item @code{CC}
776 C compiler command
777 @item @code{CFLAGS}
778 C compiler flags
779 @item @code{CXX}
780 C++ compiler command
781 @item @code{CXXFLAGS}
782 C++ compiler flags
783 @item @code{LDFLAGS}
784 linker flags
785 @item @code{CPPFLAGS}
786 C/C++ preprocessor flags
787 @item @dots{}
788 @end table
789
790 @command{configure} usually does a good job at setting appropriate
791 values for these variables, but there are cases where you may want to
792 override them.  For instance you may have several versions of a
793 compiler installed and would like to use another one, you may have
794 header files installed outside the default search path of the
795 compiler, or even libraries out of the way of the linker.
796
797 Here is how one would call @command{configure} to force it to use
798 @command{gcc-3} as C compiler, use header files from
799 @file{~/usr/include} when compiling, and libraries from
800 @file{~/usr/lib} when linking.
801
802 @example
803 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
804 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
805 @end example
806
807 Again, a full list of these variables appears in the output of
808 @code{./configure --help}.
809
810 @node config.site
811 @subsection Overriding Default Configuration Setting with @file{config.site}
812 @cindex @file{config.site} example
813
814 When installing several packages using the same setup, it can be
815 convenient to create a file to capture common settings.
816 If a file named @file{@var{prefix}/share/config.site} exists,
817 @command{configure} will source it at the beginning of its execution.
818
819 Recall the command from the previous section:
820
821 @example
822 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr CC=gcc-3 \
823 CPPFLAGS=-I$HOME/usr/include LDFLAGS=-L$HOME/usr/lib}
824 @end example
825
826 Assuming we are installing many package in @file{~/usr}, and will
827 always want to use these definitions of @code{CC}, @code{CPPFLAGS}, and
828 @code{LDFLAGS}, we can automate this by creating the following
829 @file{~/usr/share/config.site} file:
830
831 @example
832 test -z "$CC" && CC=gcc-3
833 test -z "$CPPFLAGS" && CPPFLAGS=-I$HOME/usr/include
834 test -z "$LDFLAGS" && LDFLAGS=-L$HOME/usr/lib
835 @end example
836
837 Now, any time a @file{configure} script is using the @file{~/usr}
838 prefix, it will execute the above @file{config.site} and define
839 these three variables.
840
841 @example
842 ~/amhello-1.0 % @kbd{./configure --prefix ~/usr}
843 configure: loading site script /home/adl/usr/share/config.site
844 @dots{}
845 @end example
846
847 @xref{Site Defaults, , Setting Site Defaults, autoconf, The Autoconf
848 Manual}, for more information about this feature.
849
850
851 @node VPATH Builds
852 @subsection Parallel Build Trees (a.k.a.@: VPATH Builds)
853 @cindex Parallel build trees
854 @cindex VPATH builds
855 @cindex source tree and build tree
856 @cindex build tree and source tree
857 @cindex trees, source vs.@: build
858
859 The GNU Build System distinguishes two trees: the source tree, and
860 the build tree.
861
862 The source tree is rooted in the directory containing
863 @file{configure}.  It contains all the sources files (those that are
864 distributed), and may be arranged using several subdirectories.
865
866 The build tree is rooted in the directory in which @file{configure}
867 was run, and is populated with all object files, programs, libraries,
868 and other derived files built from the sources (and hence not
869 distributed).  The build tree usually has the same subdirectory layout
870 as the source tree; its subdirectories are created automatically by
871 the build system.
872
873 If @file{configure} is executed in its own directory, the source and
874 build trees are combined: derived files are constructed in the same
875 directories as their sources.  This was the case in our first
876 installation example (@pxref{Basic Installation}).
877
878 A common request from users is that they want to confine all derived
879 files to a single directory, to keep their source directories
880 uncluttered.  Here is how we could run @file{configure} to build
881 everything in a subdirectory called @file{build/}.
882
883 @example
884 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
885 ~ % @kbd{cd amhello-1.0}
886 ~/amhello-1.0 % @kbd{mkdir build && cd build}
887 ~/amhello-1.0/build % @kbd{../configure}
888 @dots{}
889 ~/amhello-1.0/build % @kbd{make}
890 @dots{}
891 @end example
892
893 These setups, where source and build trees are different, are often
894 called @dfn{parallel builds} or @dfn{VPATH builds}.  The expression
895 @emph{parallel build} is misleading: the word @emph{parallel} is a
896 reference to the way the build tree shadows the source tree, it is not
897 about some concurrency in the way build commands are run.  For this
898 reason we refer to such setups using the name @emph{VPATH builds} in
899 the following.  @emph{VPATH} is the name of the @command{make} feature
900 used by the @file{Makefile}s to allow these builds (@pxref{General
901 Search, , @code{VPATH} Search Path for All Prerequisites, make, The
902 GNU Make Manual}).
903
904 @cindex multiple configurations, example
905 @cindex debug build, example
906 @cindex optimized build, example
907
908 VPATH builds have other interesting uses.  One is to build the same
909 sources with multiple configurations.  For instance:
910
911 @c Keep in sync with amhello-cflags.sh
912 @example
913 ~ % @kbd{tar zxf ~/amhello-1.0.tar.gz}
914 ~ % @kbd{cd amhello-1.0}
915 ~/amhello-1.0 % @kbd{mkdir debug optim && cd debug}
916 ~/amhello-1.0/debug % @kbd{../configure CFLAGS='-g -O0'}
917 @dots{}
918 ~/amhello-1.0/debug % @kbd{make}
919 @dots{}
920 ~/amhello-1.0/debug % cd ../optim
921 ~/amhello-1.0/optim % @kbd{../configure CFLAGS='-O3 -fomit-frame-pointer'}
922 @dots{}
923 ~/amhello-1.0/optim % @kbd{make}
924 @dots{}
925 @end example
926
927 With network file systems, a similar approach can be used to build the
928 same sources on different machines.  For instance, suppose that the
929 sources are installed on a directory shared by two hosts: @code{HOST1}
930 and @code{HOST2}, which may be different platforms.
931
932 @example
933 ~ % @kbd{cd /nfs/src}
934 /nfs/src % @kbd{tar zxf ~/amhello-1.0.tar.gz}
935 @end example
936
937 On the first host, you could create a local build directory:
938 @example
939 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
940 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
941 ...
942 [HOST1] /tmp/amh % @kbd{make && sudo make install}
943 ...
944 @end example
945
946 @noindent
947 (Here we assume that the installer has configured @command{sudo} so it
948 can execute @code{make install} with root privileges; it is more convenient
949 than using @command{su} like in @ref{Basic Installation}).
950
951 On the second host, you would do exactly the same, possibly at
952 the same time:
953 @example
954 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
955 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure}
956 ...
957 [HOST2] /tmp/amh % @kbd{make && sudo make install}
958 ...
959 @end example
960
961 @cindex read-only source tree
962 @cindex source tree, read-only
963
964 In this scenario, nothing forbids the @file{/nfs/src/amhello-1.0}
965 directory from being read-only.  In fact VPATH builds are also a means
966 of building packages from a read-only medium such as a CD-ROM.  (The
967 FSF used to sell CD-ROM with unpacked source code, before the GNU
968 project grew so big.)
969
970 @node Two-Part Install
971 @subsection Two-Part Installation
972
973 In our last example (@pxref{VPATH Builds}), a source tree was shared
974 by two hosts, but compilation and installation were done separately on
975 each host.
976
977 The GNU Build System also supports networked setups where part of the
978 installed files should be shared amongst multiple hosts.  It does so
979 by distinguishing architecture-dependent files from
980 architecture-independent files, and providing two @file{Makefile}
981 targets to install each of these classes of files.
982
983 @trindex install-exec
984 @trindex install-data
985
986 These targets are @code{install-exec} for architecture-dependent files
987 and @code{install-data} for architecture-independent files.
988 The command we used up to now, @code{make install}, can be thought of
989 as a shorthand for @code{make install-exec install-data}.
990
991 From the GNU Build System point of view, the distinction between
992 architecture-dependent files and architecture-independent files is
993 based exclusively on the directory variable used to specify their
994 installation destination.  In the list of directory variables we
995 provided earlier (@pxref{Standard Directory Variables}), all the
996 variables based on @var{exec-prefix} designate architecture-dependent
997 directories whose files will be installed by @code{make install-exec}.
998 The others designate architecture-independent directories and will
999 serve files installed by @code{make install-data}.  @xref{The Two Parts
1000 of Install}, for more details.
1001
1002 Here is how we could revisit our two-host installation example,
1003 assuming that (1) we want to install the package directly in
1004 @file{/usr}, and (2) the directory @file{/usr/share} is shared by the
1005 two hosts.
1006
1007 On the first host we would run
1008 @example
1009 [HOST1] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1010 [HOST1] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1011 ...
1012 [HOST1] /tmp/amh % @kbd{make && sudo make install}
1013 ...
1014 @end example
1015
1016 On the second host, however, we need only install the
1017 architecture-specific files.
1018 @example
1019 [HOST2] ~ % @kbd{mkdir /tmp/amh && cd /tmp/amh}
1020 [HOST2] /tmp/amh % @kbd{/nfs/src/amhello-1.0/configure --prefix /usr}
1021 ...
1022 [HOST2] /tmp/amh % @kbd{make && sudo make install-exec}
1023 ...
1024 @end example
1025
1026 In packages that have installation checks, it would make sense to run
1027 @code{make installcheck} (@pxref{Basic Installation}) to verify that
1028 the package works correctly despite the apparent partial installation.
1029
1030 @node Cross-Compilation
1031 @subsection Cross-Compilation
1032 @cindex cross-compilation
1033
1034 To @dfn{cross-compile} is to build on one platform a binary that will
1035 run on another platform.  When speaking of cross-compilation, it is
1036 important to distinguish between the @dfn{build platform} on which
1037 the compilation is performed, and the @dfn{host platform} on which the
1038 resulting executable is expected to run.  The following
1039 @command{configure} options are used to specify each of them:
1040
1041 @table @option
1042 @item --build=@var{build}
1043 @opindex --build=@var{build}
1044 The system on which the package is built.
1045 @item --host=@var{host}
1046 @opindex --host=@var{host}
1047 The system where built programs and libraries will run.
1048 @end table
1049
1050 When the @option{--host} is used, @command{configure} will search for
1051 the cross-compiling suite for this platform.  Cross-compilation tools
1052 commonly have their target architecture as prefix of their name.  For
1053 instance my cross-compiler for MinGW32 has its binaries called
1054 @code{i586-mingw32msvc-gcc}, @code{i586-mingw32msvc-ld},
1055 @code{i586-mingw32msvc-as}, etc.
1056
1057 @cindex MinGW cross-compilation example
1058 @cindex cross-compilation example
1059
1060 Here is how we could build @code{amhello-1.0} for
1061 @code{i586-mingw32msvc} on a GNU/Linux PC.
1062
1063 @c Keep in sync with amhello-cross-compile.sh
1064 @smallexample
1065 ~/amhello-1.0 % @kbd{./configure --build i686-pc-linux-gnu --host i586-mingw32msvc}
1066 checking for a BSD-compatible install... /usr/bin/install -c
1067 checking whether build environment is sane... yes
1068 checking for gawk... gawk
1069 checking whether make sets $(MAKE)... yes
1070 checking for i586-mingw32msvc-strip... i586-mingw32msvc-strip
1071 checking for i586-mingw32msvc-gcc... i586-mingw32msvc-gcc
1072 checking for C compiler default output file name... a.exe
1073 checking whether the C compiler works... yes
1074 checking whether we are cross compiling... yes
1075 checking for suffix of executables... .exe
1076 checking for suffix of object files... o
1077 checking whether we are using the GNU C compiler... yes
1078 checking whether i586-mingw32msvc-gcc accepts -g... yes
1079 checking for i586-mingw32msvc-gcc option to accept ANSI C...
1080 @dots{}
1081 ~/amhello-1.0 % @kbd{make}
1082 @dots{}
1083 ~/amhello-1.0 % @kbd{cd src; file hello.exe}
1084 hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable
1085 @end smallexample
1086
1087 The @option{--host} and @option{--build} options are usually all we
1088 need for cross-compiling.  The only exception is if the package being
1089 built is itself a cross-compiler: we need a third option to specify
1090 its target architecture.
1091
1092 @table @option
1093 @item --target=@var{target}
1094 @opindex --target=@var{target}
1095 When building compiler tools: the system for which the tools will
1096 create output.
1097 @end table
1098
1099 For instance when installing GCC, the GNU Compiler Collection, we can
1100 use @option{--target=@/@var{target}} to specify that we want to build
1101 GCC as a cross-compiler for @var{target}.  Mixing @option{--build} and
1102 @option{--target}, we can actually cross-compile a cross-compiler;
1103 such a three-way cross-compilation is known as a @dfn{Canadian cross}.
1104
1105 @xref{Specifying Names, , Specifying the System Type, autoconf, The
1106 Autoconf Manual}, for more information about these @command{configure}
1107 options.
1108
1109 @node Renaming
1110 @subsection Renaming Programs at Install Time
1111 @cindex Renaming programs
1112 @cindex Transforming program names
1113 @cindex Programs, renaming during installation
1114
1115 The GNU Build System provides means to automatically rename
1116 executables and manpages before they are installed (@pxref{Man Pages}).
1117 This is especially convenient
1118 when installing a GNU package on a system that already has a
1119 proprietary implementation you do not want to overwrite.  For instance,
1120 you may want to install GNU @command{tar} as @command{gtar} so you can
1121 distinguish it from your vendor's @command{tar}.
1122
1123 This can be done using one of these three @command{configure} options.
1124
1125 @table @option
1126 @item --program-prefix=@var{prefix}
1127 @opindex --program-prefix=@var{prefix}
1128 Prepend @var{prefix} to installed program names.
1129 @item --program-suffix=@var{suffix}
1130 @opindex --program-suffix=@var{suffix}
1131 Append @var{suffix} to installed program names.
1132 @item --program-transform-name=@var{program}
1133 @opindex --program-transform-name=@var{program}
1134 Run @code{sed @var{program}} on installed program names.
1135 @end table
1136
1137 The following commands would install @file{hello}
1138 as @file{/usr/local/bin/test-hello}, for instance.
1139
1140 @example
1141 ~/amhello-1.0 % @kbd{./configure --program-prefix test-}
1142 @dots{}
1143 ~/amhello-1.0 % @kbd{make}
1144 @dots{}
1145 ~/amhello-1.0 % @kbd{sudo make install}
1146 @dots{}
1147 @end example
1148
1149 @node DESTDIR
1150 @subsection Building Binary Packages Using DESTDIR
1151 @vindex DESTDIR
1152
1153 The GNU Build System's @code{make install} and @code{make uninstall}
1154 interface does not exactly fit the needs of a system administrator
1155 who has to deploy and upgrade packages on lots of hosts.  In other
1156 words, the GNU Build System does not replace a package manager.
1157
1158 Such package managers usually need to know which files have been
1159 installed by a package, so a mere @code{make install} is
1160 inappropriate.
1161
1162 @cindex Staged installation
1163
1164 The @code{DESTDIR} variable can be used to perform a staged
1165 installation.  The package should be configured as if it was going to
1166 be installed in its final location (e.g., @code{--prefix /usr}), but
1167 when running @code{make install}, the @code{DESTDIR} should be set to
1168 the absolute name of a directory into which the installation will be
1169 diverted.  From this directory it is easy to review which files are
1170 being installed where, and finally copy them to their final location
1171 by some means.
1172
1173 @cindex Binary package
1174
1175 For instance here is how we could create a binary package containing a
1176 snapshot of all the files to be installed.
1177
1178 @c Keep in sync with amhello-binpkg.sh
1179 @example
1180 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1181 @dots{}
1182 ~/amhello-1.0 % @kbd{make}
1183 @dots{}
1184 ~/amhello-1.0 % @kbd{make DESTDIR=$HOME/inst install}
1185 @dots{}
1186 ~/amhello-1.0 % @kbd{cd ~/inst}
1187 ~/inst % @kbd{find . -type f -print > ../files.lst}
1188 ~/inst % @kbd{tar zcvf ~/amhello-1.0-i686.tar.gz `cat ../files.lst`}
1189 ./usr/bin/hello
1190 ./usr/share/doc/amhello/README
1191 @end example
1192
1193 After this example, @code{amhello-1.0-i686.tar.gz} is ready to be
1194 uncompressed in @file{/} on many hosts.  (Using @code{`cat ../files.lst`}
1195 instead of @samp{.} as argument for @command{tar} avoids entries for
1196 each subdirectory in the archive: we would not like @command{tar} to
1197 restore the modification time of @file{/}, @file{/usr/}, etc.)
1198
1199 Note that when building packages for several architectures, it might
1200 be convenient to use @code{make install-data} and @code{make
1201 install-exec} (@pxref{Two-Part Install}) to gather
1202 architecture-independent files in a single package.
1203
1204 @xref{Install}, for more information.
1205
1206 @c We should document PRE_INSTALL/POST_INSTALL/NORMAL_INSTALL and their
1207 @c UNINSTALL counterparts.
1208
1209 @node Preparing Distributions
1210 @subsection Preparing Distributions
1211 @cindex Preparing distributions
1212 @cindex Packages, preparation
1213 @cindex Distributions, preparation
1214
1215 We have already mentioned @code{make dist}.  This target collects all
1216 your source files and the necessary parts of the build system to
1217 create a tarball named @file{@var{package}-@var{version}.tar.gz}.
1218
1219 @cindex @code{distcheck} better than @code{dist}
1220
1221 Another, more useful command is @code{make distcheck}.  The
1222 @code{distcheck} target constructs
1223 @file{@var{package}-@var{version}.tar.gz} just as well as @code{dist},
1224 but it additionally ensures most of the use cases presented so far
1225 work:
1226
1227 @itemize @bullet
1228 @item
1229 It attempts a full compilation of the package (@pxref{Basic
1230 Installation}), unpacking the newly constructed tarball, running
1231 @code{make}, @code{make check}, @code{make install}, as well as
1232 @code{make installcheck}, and even @code{make dist},
1233 @item
1234 it tests VPATH builds with read-only source tree (@pxref{VPATH Builds}),
1235 @item
1236 it makes sure @code{make clean}, @code{make distclean}, and @code{make
1237 uninstall} do not omit any file (@pxref{Standard Targets}),
1238 @item
1239 and it checks that @code{DESTDIR} installations work (@pxref{DESTDIR}).
1240 @end itemize
1241
1242 All of these actions are performed in a temporary subdirectory, so
1243 that no root privileges are required.
1244
1245 Releasing a package that fails @code{make distcheck} means that one of
1246 the scenarios we presented will not work and some users will be
1247 disappointed.  Therefore it is a good practice to release a package
1248 only after a successful @code{make distcheck}.  This of course does
1249 not imply that the package will be flawless, but at least it will
1250 prevent some of the embarrassing errors you may find in packages
1251 released by people who have never heard about @code{distcheck} (like
1252 @code{DESTDIR} not working because of a typo, or a distributed file
1253 being erased by @code{make clean}, or even @code{VPATH} builds not
1254 working).
1255
1256 @xref{Creating amhello}, to recreate @file{amhello-1.0.tar.gz} using
1257 @code{make distcheck}.  @xref{Checking the Distribution}, for more
1258 information about @code{distcheck}.
1259
1260 @node Dependency Tracking
1261 @subsection Automatic Dependency Tracking
1262 @cindex Dependency tracking
1263
1264 Dependency tracking is performed as a side-effect of compilation.
1265 Each time the build system compiles a source file, it computes its
1266 list of dependencies (in C these are the header files included by the
1267 source being compiled).  Later, any time @command{make} is run and a
1268 dependency appears to have changed, the dependent files will be
1269 rebuilt.
1270
1271 Automake generates code for automatic dependency tracking by default,
1272 unless the developer chooses to override it; for more information,
1273 @pxref{Dependencies}.
1274
1275 When @command{configure} is executed, you can see it probing each
1276 compiler for the dependency mechanism it supports (several mechanisms
1277 can be used):
1278
1279 @example
1280 ~/amhello-1.0 % @kbd{./configure --prefix /usr}
1281 @dots{}
1282 checking dependency style of gcc... gcc3
1283 @dots{}
1284 @end example
1285
1286 Because dependencies are only computed as a side-effect of the
1287 compilation, no dependency information exists the first time a package
1288 is built.  This is OK because all the files need to be built anyway:
1289 @code{make} does not have to decide which files need to be rebuilt.
1290 In fact, dependency tracking is completely useless for one-time builds
1291 and there is a @command{configure} option to disable this:
1292
1293 @table @option
1294 @item --disable-dependency-tracking
1295 @opindex --disable-dependency-tracking
1296 Speed up one-time builds.
1297 @end table
1298
1299 Some compilers do not offer any practical way to derive the list of
1300 dependencies as a side-effect of the compilation, requiring a separate
1301 run (maybe of another tool) to compute these dependencies.  The
1302 performance penalty implied by these methods is important enough to
1303 disable them by default.  The option @option{--enable-dependency-tracking}
1304 must be passed to @command{configure} to activate them.
1305
1306 @table @option
1307 @item --enable-dependency-tracking
1308 @opindex --enable-dependency-tracking
1309 Do not reject slow dependency extractors.
1310 @end table
1311
1312 @xref{Dependency Tracking Evolution, , Dependency Tracking Evolution,
1313 automake-history, Brief History of Automake}, for some discussion about
1314 the different dependency tracking schemes used by Automake over the years.
1315
1316 @node Nested Packages
1317 @subsection Nested Packages
1318 @cindex Nested packages
1319 @cindex Packages, nested
1320 @cindex Subpackages
1321
1322 Although nesting packages isn't something we would recommend to
1323 someone who is discovering the Autotools, it is a nice feature worthy
1324 of mention in this small advertising tour.
1325
1326 Autoconfiscated packages (that means packages whose build system have
1327 been created by Autoconf and friends) can be nested to arbitrary
1328 depth.
1329
1330 A typical setup is that package A will distribute one of the libraries
1331 it needs in a subdirectory.  This library B is a complete package with
1332 its own GNU Build System.  The @command{configure} script of A will
1333 run the @command{configure} script of B as part of its execution,
1334 building and installing A will also build and install B.  Generating a
1335 distribution for A will also include B.
1336
1337 It is possible to gather several packages like this.  GCC is a heavy
1338 user of this feature.  This gives installers a single package to
1339 configure, build and install, while it allows developers to work on
1340 subpackages independently.
1341
1342 When configuring nested packages, the @command{configure} options
1343 given to the top-level @command{configure} are passed recursively to
1344 nested @command{configure}s.  A package that does not understand an
1345 option will ignore it, assuming it is meaningful to some other
1346 package.
1347
1348 @opindex --help=recursive
1349
1350 The command @code{configure --help=recursive} can be used to display
1351 the options supported by all the included packages.
1352
1353 @xref{Subpackages}, for an example setup.
1354
1355 @node Why Autotools
1356 @section How Autotools Help
1357 @cindex Autotools, purpose
1358
1359 There are several reasons why you may not want to implement the GNU
1360 Build System yourself (read: write a @file{configure} script and
1361 @file{Makefile}s yourself).
1362
1363 @itemize @bullet
1364 @item
1365 As we have seen, the GNU Build System has a lot of
1366 features (@pxref{Use Cases}).
1367 Some users may expect features you have not implemented because
1368 you did not need them.
1369 @item
1370 Implementing these features portably is difficult and exhausting.
1371 Think of writing portable shell scripts, and portable
1372 @file{Makefile}s, for systems you may not have handy.  @xref{Portable
1373 Shell, , Portable Shell Programming, autoconf, The Autoconf Manual}, to
1374 convince yourself.
1375 @item
1376 You will have to upgrade your setup to follow changes to the GNU
1377 Coding Standards.
1378 @end itemize
1379
1380 The GNU Autotools take all this burden off your back and provide:
1381
1382 @itemize @bullet
1383 @item
1384 Tools to create a portable, complete, and self-contained GNU Build
1385 System, from simple instructions.
1386 @emph{Self-contained} meaning the resulting build system does not
1387 require the GNU Autotools.
1388 @item
1389 A central place where fixes and improvements are made:
1390 a bug-fix for a portability issue will benefit every package.
1391 @end itemize
1392
1393 Yet there also exist reasons why you may want NOT to use the
1394 Autotools@enddots{} For instance you may be already using (or used to)
1395 another incompatible build system.  Autotools will only be useful if
1396 you do accept the concepts of the GNU Build System.  People who have their
1397 own idea of how a build system should work will feel frustrated by the
1398 Autotools.
1399
1400 @node Hello World
1401 @section A Small Hello World
1402 @cindex Example Hello World
1403 @cindex Hello World example
1404 @cindex @file{amhello-1.0.tar.gz}, creation
1405
1406 In this section we recreate the @file{amhello-1.0} package from
1407 scratch.  The first subsection shows how to call the Autotools to
1408 instantiate the GNU Build System, while the second explains the
1409 meaning of the @file{configure.ac} and @file{Makefile.am} files read
1410 by the Autotools.
1411
1412 @anchor{amhello Explained}
1413 @menu
1414 * Creating amhello::            Create @file{amhello-1.0.tar.gz} from scratch
1415 * amhello's configure.ac Setup Explained::
1416 * amhello's Makefile.am Setup Explained::
1417 @end menu
1418
1419 @node Creating amhello
1420 @subsection Creating @file{amhello-1.0.tar.gz}
1421
1422 Here is how we can recreate @file{amhello-1.0.tar.gz} from scratch.
1423 The package is simple enough so that we will only need to write 5
1424 files.  (You may copy them from the final @file{amhello-1.0.tar.gz}
1425 that is distributed with Automake if you do not want to write them.)
1426
1427 Create the following files in an empty directory.
1428
1429 @itemize @bullet
1430
1431 @item
1432 @file{src/main.c} is the source file for the @file{hello} program.  We
1433 store it in the @file{src/} subdirectory, because later, when the package
1434 evolves, it will ease the addition of a @file{man/} directory for man
1435 pages, a @file{data/} directory for data files, etc.
1436 @example
1437 ~/amhello % @kbd{cat src/main.c}
1438 #include <config.h>
1439 #include <stdio.h>
1440
1441 int
1442 main (void)
1443 @{
1444   puts ("Hello World!");
1445   puts ("This is " PACKAGE_STRING ".");
1446   return 0;
1447 @}
1448 @end example
1449
1450 @item
1451 @file{README} contains some very limited documentation for our little
1452 package.
1453 @example
1454 ~/amhello % @kbd{cat README}
1455 This is a demonstration package for GNU Automake.
1456 Type 'info Automake' to read the Automake manual.
1457 @end example
1458
1459 @item
1460 @file{Makefile.am} and @file{src/Makefile.am} contain Automake
1461 instructions for these two directories.
1462
1463 @example
1464 ~/amhello % @kbd{cat src/Makefile.am}
1465 bin_PROGRAMS = hello
1466 hello_SOURCES = main.c
1467 ~/amhello % @kbd{cat Makefile.am}
1468 SUBDIRS = src
1469 dist_doc_DATA = README
1470 @end example
1471
1472 @item
1473 Finally, @file{configure.ac} contains Autoconf instructions to
1474 create the @command{configure} script.
1475
1476 @example
1477 ~/amhello % @kbd{cat configure.ac}
1478 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1479 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1480 AC_PROG_CC
1481 AC_CONFIG_HEADERS([config.h])
1482 AC_CONFIG_FILES([
1483  Makefile
1484  src/Makefile
1485 ])
1486 AC_OUTPUT
1487 @end example
1488 @end itemize
1489
1490 @cindex @command{autoreconf}, example
1491
1492 Once you have these five files, it is time to run the Autotools to
1493 instantiate the build system.  Do this using the @command{autoreconf}
1494 command as follows:
1495
1496 @example
1497 ~/amhello % @kbd{autoreconf --install}
1498 configure.ac: installing './install-sh'
1499 configure.ac: installing './missing'
1500 src/Makefile.am: installing './depcomp'
1501 @end example
1502
1503 At this point the build system is complete.
1504
1505 In addition to the three scripts mentioned in its output, you can see
1506 that @command{autoreconf} created four other files: @file{configure},
1507 @file{config.h.in}, @file{Makefile.in}, and @file{src/Makefile.in}.
1508 The latter three files are templates that will be adapted to the
1509 system by @command{configure} under the names @file{config.h},
1510 @file{Makefile}, and @file{src/Makefile}.  Let's do this:
1511
1512 @example
1513 ~/amhello % @kbd{./configure}
1514 checking for a BSD-compatible install... /usr/bin/install -c
1515 checking whether build environment is sane... yes
1516 checking for gawk... no
1517 checking for mawk... mawk
1518 checking whether make sets $(MAKE)... yes
1519 checking for gcc... gcc
1520 checking for C compiler default output file name... a.out
1521 checking whether the C compiler works... yes
1522 checking whether we are cross compiling... no
1523 checking for suffix of executables...
1524 checking for suffix of object files... o
1525 checking whether we are using the GNU C compiler... yes
1526 checking whether gcc accepts -g... yes
1527 checking for gcc option to accept ISO C89... none needed
1528 checking for style of include used by make... GNU
1529 checking dependency style of gcc... gcc3
1530 configure: creating ./config.status
1531 config.status: creating Makefile
1532 config.status: creating src/Makefile
1533 config.status: creating config.h
1534 config.status: executing depfiles commands
1535 @end example
1536
1537 @trindex distcheck
1538 @cindex @code{distcheck} example
1539
1540 You can see @file{Makefile}, @file{src/Makefile}, and @file{config.h}
1541 being created at the end after @command{configure} has probed the
1542 system.  It is now possible to run all the targets we wish
1543 (@pxref{Standard Targets}).  For instance:
1544
1545 @example
1546 ~/amhello % @kbd{make}
1547 @dots{}
1548 ~/amhello % @kbd{src/hello}
1549 Hello World!
1550 This is amhello 1.0.
1551 ~/amhello % @kbd{make distcheck}
1552 @dots{}
1553 =============================================
1554 amhello-1.0 archives ready for distribution:
1555 amhello-1.0.tar.gz
1556 =============================================
1557 @end example
1558
1559 Note that running @command{autoreconf} is only needed initially when
1560 the GNU Build System does not exist.  When you later change some
1561 instructions in a @file{Makefile.am} or @file{configure.ac}, the
1562 relevant part of the build system will be regenerated automatically
1563 when you execute @command{make}.
1564
1565 @command{autoreconf} is a script that calls @command{autoconf},
1566 @command{automake}, and a bunch of other commands in the right order.
1567 If you are beginning with these tools, it is not important to figure
1568 out in which order all of these tools should be invoked and why.  However,
1569 because Autoconf and Automake have separate manuals, the important
1570 point to understand is that @command{autoconf} is in charge of
1571 creating @file{configure} from @file{configure.ac}, while
1572 @command{automake} is in charge of creating @file{Makefile.in}s from
1573 @file{Makefile.am}s and @file{configure.ac}.  This should at least
1574 direct you to the right manual when seeking answers.
1575
1576
1577 @node amhello's configure.ac Setup Explained
1578 @subsection @code{amhello}'s @file{configure.ac} Setup Explained
1579
1580 @cindex @file{configure.ac}, Hello World
1581
1582 Let us begin with the contents of @file{configure.ac}.
1583
1584 @example
1585 AC_INIT([amhello], [1.0], [@value{PACKAGE_BUGREPORT}])
1586 AM_INIT_AUTOMAKE([-Wall -Werror foreign])
1587 AC_PROG_CC
1588 AC_CONFIG_HEADERS([config.h])
1589 AC_CONFIG_FILES([
1590  Makefile
1591  src/Makefile
1592 ])
1593 AC_OUTPUT
1594 @end example
1595
1596 This file is read by both @command{autoconf} (to create
1597 @file{configure}) and @command{automake} (to create the various
1598 @file{Makefile.in}s).  It contains a series of M4 macros that will be
1599 expanded as shell code to finally form the @file{configure} script.
1600 We will not elaborate on the syntax of this file, because the Autoconf
1601 manual has a whole section about it (@pxref{Writing Autoconf Input, ,
1602 Writing @file{configure.ac}, autoconf, The Autoconf Manual}).
1603
1604 The macros prefixed with @code{AC_} are Autoconf macros, documented
1605 in the Autoconf manual (@pxref{Autoconf Macro Index, , Autoconf Macro
1606 Index, autoconf, The Autoconf Manual}).  The macros that start with
1607 @code{AM_} are Automake macros, documented later in this manual
1608 (@pxref{Macro Index}).
1609
1610 The first two lines of @file{configure.ac} initialize Autoconf and
1611 Automake.  @code{AC_INIT} takes in as parameters the name of the package,
1612 its version number, and a contact address for bug-reports about the
1613 package (this address is output at the end of @code{./configure
1614 --help}, for instance).  When adapting this setup to your own package,
1615 by all means please do not blindly copy Automake's address: use the
1616 mailing list of your package, or your own mail address.
1617
1618 @opindex -Wall
1619 @opindex -Werror
1620 @opindex foreign
1621
1622 The argument to @code{AM_INIT_AUTOMAKE} is a list of options for
1623 @command{automake} (@pxref{Options}).  @option{-Wall} and
1624 @option{-Werror} ask @command{automake} to turn on all warnings and
1625 report them as errors.  We are speaking of @strong{Automake} warnings
1626 here, such as dubious instructions in @file{Makefile.am}.  This has
1627 absolutely nothing to do with how the compiler will be called, even
1628 though it may support options with similar names.  Using @option{-Wall
1629 -Werror} is a safe setting when starting to work on a package: you do
1630 not want to miss any issues.  Later you may decide to relax things a
1631 bit.  The @option{foreign} option tells Automake that this package
1632 will not follow the GNU Standards.  GNU packages should always
1633 distribute additional files such as @file{ChangeLog}, @file{AUTHORS},
1634 etc.  We do not want @command{automake} to complain about these
1635 missing files in our small example.
1636
1637 The @code{AC_PROG_CC} line causes the @command{configure} script to
1638 search for a C compiler and define the variable @code{CC} with its
1639 name.  The @file{src/Makefile.in} file generated by Automake uses the
1640 variable @code{CC} to build @file{hello}, so when @command{configure}
1641 creates @file{src/Makefile} from @file{src/Makefile.in}, it will define
1642 @code{CC} with the value it has found.  If Automake is asked to create
1643 a @file{Makefile.in} that uses @code{CC} but @file{configure.ac} does
1644 not define it, it will suggest you add a call to @code{AC_PROG_CC}.
1645
1646 The @code{AC_CONFIG_HEADERS([config.h])} invocation causes the
1647 @command{configure} script to create a @file{config.h} file gathering
1648 @samp{#define}s defined by other macros in @file{configure.ac}.  In our
1649 case, the @code{AC_INIT} macro already defined a few of them.  Here
1650 is an excerpt of @file{config.h} after @command{configure} has run:
1651
1652 @smallexample
1653 @dots{}
1654 /* Define to the address where bug reports for this package should be sent. */
1655 #define PACKAGE_BUGREPORT "@value{PACKAGE_BUGREPORT}"
1656
1657 /* Define to the full name and version of this package. */
1658 #define PACKAGE_STRING "amhello 1.0"
1659 @dots{}
1660 @end smallexample
1661
1662 As you probably noticed, @file{src/main.c} includes @file{config.h} so
1663 it can use @code{PACKAGE_STRING}.  In a real-world project,
1664 @file{config.h} can grow really big, with one @samp{#define} per
1665 feature probed on the system.
1666
1667 The @code{AC_CONFIG_FILES} macro declares the list of files that
1668 @command{configure} should create from their @file{*.in} templates.
1669 Automake also scans this list to find the @file{Makefile.am} files it must
1670 process.  (This is important to remember: when adding a new directory
1671 to your project, you should add its @file{Makefile} to this list,
1672 otherwise Automake will never process the new @file{Makefile.am} you
1673 wrote in that directory.)
1674
1675 Finally, the @code{AC_OUTPUT} line is a closing command that actually
1676 produces the part of the script in charge of creating the files
1677 registered with @code{AC_CONFIG_HEADERS} and @code{AC_CONFIG_FILES}.
1678
1679 @cindex @command{autoscan}
1680
1681 When starting a new project, we suggest you start with such a simple
1682 @file{configure.ac}, and gradually add the other tests it requires.
1683 The command @command{autoscan} can also suggest a few of the tests
1684 your package may need (@pxref{autoscan Invocation, , Using
1685 @command{autoscan} to Create @file{configure.ac}, autoconf, The
1686 Autoconf Manual}).
1687
1688
1689 @node amhello's Makefile.am Setup Explained
1690 @subsection @code{amhello}'s @file{Makefile.am} Setup Explained
1691
1692 @cindex @file{Makefile.am}, Hello World
1693
1694 We now turn to @file{src/Makefile.am}.  This file contains
1695 Automake instructions to build and install @file{hello}.
1696
1697 @example
1698 bin_PROGRAMS = hello
1699 hello_SOURCES = main.c
1700 @end example
1701
1702 A @file{Makefile.am} has the same syntax as an ordinary
1703 @file{Makefile}.  When @command{automake} processes a
1704 @file{Makefile.am} it copies the entire file into the output
1705 @file{Makefile.in} (that will be later turned into @file{Makefile} by
1706 @command{configure}) but will react to certain variable definitions
1707 by generating some build rules and other variables.
1708 Often @file{Makefile.am}s contain only a list of variable definitions as
1709 above, but they can also contain other variable and rule definitions that
1710 @command{automake} will pass along without interpretation.
1711
1712 Variables that end with @code{_PROGRAMS} are special variables
1713 that list programs that the resulting @file{Makefile} should build.
1714 In Automake speak, this @code{_PROGRAMS} suffix is called a
1715 @dfn{primary}; Automake recognizes other primaries such as
1716 @code{_SCRIPTS}, @code{_DATA}, @code{_LIBRARIES}, etc.@: corresponding
1717 to different types of files.
1718
1719 The @samp{bin} part of the @code{bin_PROGRAMS} tells
1720 @command{automake} that the resulting programs should be installed in
1721 @var{bindir}.  Recall that the GNU Build System uses a set of variables
1722 to denote destination directories and allow users to customize these
1723 locations (@pxref{Standard Directory Variables}).  Any such directory
1724 variable can be put in front of a primary (omitting the @code{dir}
1725 suffix) to tell @command{automake} where to install the listed files.
1726
1727 Programs need to be built from source files, so for each program
1728 @code{@var{prog}} listed in a @code{@w{_PROGRAMS}} variable,
1729 @command{automake} will look for another variable named
1730 @code{@var{prog}_SOURCES} listing its source files.  There may be more
1731 than one source file: they will all be compiled and linked together.
1732
1733 Automake also knows that source files need to be distributed when
1734 creating a tarball (unlike built programs).  So a side-effect of this
1735 @code{hello_SOURCES} declaration is that @file{main.c} will be
1736 part of the tarball created by @code{make dist}.
1737
1738 Finally here are some explanations regarding the top-level
1739 @file{Makefile.am}.
1740
1741 @example
1742 SUBDIRS = src
1743 dist_doc_DATA = README
1744 @end example
1745
1746 @code{SUBDIRS} is a special variable listing all directories that
1747 @command{make} should recurse into before processing the current
1748 directory.  So this line is responsible for @command{make} building
1749 @file{src/hello} even though we run it from the top-level.  This line
1750 also causes @code{make install} to install @file{src/hello} before
1751 installing @file{README} (not that this order matters).
1752
1753 The line @code{dist_doc_DATA = README} causes @file{README} to be
1754 distributed and installed in @var{docdir}.  Files listed with the
1755 @code{_DATA} primary are not automatically part of the tarball built
1756 with @code{make dist}, so we add the @code{dist_} prefix so they get
1757 distributed.  However, for @file{README} it would not have been
1758 necessary: @command{automake} automatically distributes any
1759 @file{README} file it encounters (the list of other files
1760 automatically distributed is presented by @code{automake --help}).
1761 The only important effect of this second line is therefore to install
1762 @file{README} during @code{make install}.
1763
1764 One thing not covered in this example is accessing the installation
1765 directory values (@pxref{Standard Directory Variables}) from your
1766 program code, that is, converting them into defined macros.  For this,
1767 @pxref{Defining Directories,,, autoconf, The Autoconf Manual}.
1768
1769
1770 @node Generalities
1771 @chapter General ideas
1772
1773 The following sections cover a few basic ideas that will help you
1774 understand how Automake works.
1775
1776 @menu
1777 * General Operation::           General operation of Automake
1778 * Strictness::                  Standards conformance checking
1779 * Uniform::                     The Uniform Naming Scheme
1780 * Length Limitations::          Staying below the command line length limit
1781 * Canonicalization::            How derived variables are named
1782 * User Variables::              Variables reserved for the user
1783 * Auxiliary Programs::          Programs automake might require
1784 @end menu
1785
1786
1787 @node General Operation
1788 @section General Operation
1789
1790 Automake works by reading a @file{Makefile.am} and generating a
1791 @file{Makefile.in}.  Certain variables and rules defined in the
1792 @file{Makefile.am} instruct Automake to generate more specialized code;
1793 for instance, a @code{bin_PROGRAMS} variable definition will cause rules
1794 for compiling and linking programs to be generated.
1795
1796 @cindex Non-standard targets
1797 @cindex @code{git-dist}, non-standard example
1798 @trindex git-dist
1799
1800 The variable definitions and rules in the @file{Makefile.am} are
1801 copied mostly verbatim into the generated file, with all variable
1802 definitions preceding all rules.  This allows you to add almost
1803 arbitrary code into the generated @file{Makefile.in}.  For instance,
1804 the Automake distribution includes a non-standard rule for the
1805 @code{git-dist} target, which the Automake maintainer uses to make
1806 distributions from the source control system.
1807
1808 @cindex GNU make extensions
1809
1810 Note that most GNU make extensions are not recognized by Automake.  Using
1811 such extensions in a @file{Makefile.am} will lead to errors or confusing
1812 behavior.
1813
1814 @cindex Append operator
1815 @cmindex +=
1816 A special exception is that the GNU make append operator, @samp{+=}, is
1817 supported.  This operator appends its right hand argument to the variable
1818 specified on the left.  Automake will translate the operator into
1819 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
1820
1821 Automake tries to keep comments grouped with any adjoining rules or
1822 variable definitions.
1823
1824 @cindex Limitations of automake parser
1825 @cindex Automake parser, limitations of
1826 @cindex indentation in Makefile.am
1827 Generally, Automake is not particularly smart in the parsing of unusual
1828 Makefile constructs, so you're advised to avoid fancy constructs or
1829 ``creative'' use of whitespaces.
1830 @c Keep this in sync with doc-parsing-buglets-tabs.sh
1831 For example, @key{TAB} characters cannot be used between a target name
1832 and the following ``@code{:}'' character, and variable assignments
1833 shouldn't be indented with @key{TAB} characters.
1834 @c Keep this in sync with doc-parsing-buglets-colneq-subst.sh
1835 Also, using more complex macro in target names can cause trouble:
1836
1837 @example
1838 % @kbd{cat Makefile.am}
1839 $(FOO:=x): bar
1840 % @kbd{automake}
1841 Makefile.am:1: bad characters in variable name '$(FOO'
1842 Makefile.am:1: ':='-style assignments are not portable
1843 @end example
1844
1845 @cindex Make targets, overriding
1846 @cindex Make rules, overriding
1847 @cindex Overriding make rules
1848 @cindex Overriding make targets
1849
1850 A rule defined in @file{Makefile.am} generally overrides any such
1851 rule of a similar name that would be automatically generated by
1852 @command{automake}.  Although this is a supported feature, it is generally
1853 best to avoid making use of it, as sometimes the generated rules are
1854 very particular.
1855
1856 @cindex Variables, overriding
1857 @cindex Overriding make variables
1858
1859 Similarly, a variable defined in @file{Makefile.am} or
1860 @code{AC_SUBST}ed from @file{configure.ac} will override any
1861 definition of the variable that @command{automake} would ordinarily
1862 create.  This feature is more often useful than the ability to
1863 override a rule.  Be warned that many of the variables generated by
1864 @command{automake} are considered to be for internal use only, and their
1865 names might change in future releases.
1866
1867 @cindex Recursive operation of Automake
1868 @cindex Automake, recursive operation
1869 @cindex Example of recursive operation
1870
1871 When examining a variable definition, Automake will recursively examine
1872 variables referenced in the definition.  For example, if Automake is
1873 looking at the content of @code{foo_SOURCES} in this snippet
1874
1875 @c Keep in sync with interp.sh
1876 @example
1877 xs = a.c b.c
1878 foo_SOURCES = c.c $(xs)
1879 @end example
1880
1881 it would use the files @file{a.c}, @file{b.c}, and @file{c.c} as the
1882 contents of @code{foo_SOURCES}.
1883
1884 @cindex @code{##} (special Automake comment)
1885 @cindex Special Automake comment
1886 @cindex Comment, special to Automake
1887
1888 Automake also allows a form of comment that is @emph{not} copied into
1889 the output; all lines beginning with @samp{##} (leading spaces allowed)
1890 are completely ignored by Automake.
1891
1892 It is customary to make the first line of @file{Makefile.am} read:
1893
1894 @cindex Makefile.am, first line
1895 @cindex First line of Makefile.am
1896
1897 @example
1898 ## Process this file with automake to produce Makefile.in
1899 @end example
1900
1901 @c FIXME discuss putting a copyright into Makefile.am here?  I would but
1902 @c I don't know quite what to say.
1903
1904 @c FIXME document customary ordering of Makefile.am here!
1905
1906
1907 @node Strictness
1908 @section Strictness
1909
1910 @cindex Non-GNU packages
1911
1912 While Automake is intended to be used by maintainers of GNU packages, it
1913 does make some effort to accommodate those who wish to use it, but do
1914 not want to use all the GNU conventions.
1915
1916 @cindex Strictness, defined
1917 @cindex Strictness, @option{foreign}
1918 @cindex @option{foreign} strictness
1919 @cindex Strictness, @option{gnu}
1920 @cindex @option{gnu} strictness
1921 @cindex Strictness, @option{gnits}
1922 @cindex @option{gnits} strictness
1923
1924 To this end, Automake supports three levels of @dfn{strictness}---the
1925 strictness indicating how stringently Automake should check standards
1926 conformance.
1927
1928 The valid strictness levels are:
1929
1930 @table @option
1931 @item foreign
1932 Automake will check for only those things that are absolutely
1933 required for proper operations.  For instance, whereas GNU standards
1934 dictate the existence of a @file{NEWS} file, it will not be required in
1935 this mode.  This strictness will also turn off some warnings by default
1936 (among them, portability warnings).
1937 The name comes from the fact that Automake is intended to be
1938 used for GNU programs; these relaxed rules are not the standard mode of
1939 operation.
1940
1941 @item gnu
1942 Automake will check---as much as possible---for compliance to the GNU
1943 standards for packages.  This is the default.
1944
1945 @item gnits
1946 Automake will check for compliance to the as-yet-unwritten @dfn{Gnits
1947 standards}.  These are based on the GNU standards, but are even more
1948 detailed.  Unless you are a Gnits standards contributor, it is
1949 recommended that you avoid this option until such time as the Gnits
1950 standard is actually published (which may never happen).
1951 @end table
1952
1953 @xref{Gnits}, for more information on the precise implications of the
1954 strictness level.
1955
1956
1957 @node Uniform
1958 @section The Uniform Naming Scheme
1959
1960 @cindex Uniform naming scheme
1961
1962 Automake variables generally follow a @dfn{uniform naming scheme} that
1963 makes it easy to decide how programs (and other derived objects) are
1964 built, and how they are installed.  This scheme also supports
1965 @command{configure} time determination of what should be built.
1966
1967 @cindex @code{_PROGRAMS} primary variable
1968 @cindex @code{PROGRAMS} primary variable
1969 @cindex Primary variable, @code{PROGRAMS}
1970 @cindex Primary variable, defined
1971 @vindex _PROGRAMS
1972
1973 At @command{make} time, certain variables are used to determine which
1974 objects are to be built.  The variable names are made of several pieces
1975 that are concatenated together.
1976
1977 The piece that tells @command{automake} what is being built is commonly called
1978 the @dfn{primary}.  For instance, the primary @code{PROGRAMS} holds a
1979 list of programs that are to be compiled and linked.
1980 @vindex PROGRAMS
1981
1982 @cindex @code{pkgdatadir}, defined
1983 @cindex @code{pkgincludedir}, defined
1984 @cindex @code{pkglibdir}, defined
1985 @cindex @code{pkglibexecdir}, defined
1986
1987 @vindex pkgdatadir
1988 @vindex pkgincludedir
1989 @vindex pkglibdir
1990 @vindex pkglibexecdir
1991
1992 @cindex @code{PACKAGE}, directory
1993 A different set of names is used to decide where the built objects
1994 should be installed.  These names are prefixes to the primary, and they
1995 indicate which standard directory should be used as the installation
1996 directory.  The standard directory names are given in the GNU standards
1997 (@pxref{Directory Variables, , , standards, The GNU Coding Standards}).
1998 Automake extends this list with @code{pkgdatadir}, @code{pkgincludedir},
1999 @code{pkglibdir}, and @code{pkglibexecdir}; these are the same as the
2000 non-@samp{pkg} versions, but with @samp{$(PACKAGE)} appended.  For instance,
2001 @code{pkglibdir} is defined as @samp{$(libdir)/$(PACKAGE)}.
2002
2003 @cindex @code{EXTRA_}, prepending
2004 For each primary, there is one additional variable named by prepending
2005 @samp{EXTRA_} to the primary name.  This variable is used to list
2006 objects that may or may not be built, depending on what
2007 @command{configure} decides.  This variable is required because Automake
2008 must statically know the entire list of objects that may be built in
2009 order to generate a @file{Makefile.in} that will work in all cases.
2010
2011 @cindex @code{EXTRA_PROGRAMS}, defined
2012 @cindex Example, @code{EXTRA_PROGRAMS}
2013 @cindex @command{cpio} example
2014
2015 For instance, @command{cpio} decides at configure time which programs
2016 should be built.  Some of the programs are installed in @code{bindir},
2017 and some are installed in @code{sbindir}:
2018
2019 @example
2020 EXTRA_PROGRAMS = mt rmt
2021 bin_PROGRAMS = cpio pax
2022 sbin_PROGRAMS = $(MORE_PROGRAMS)
2023 @end example
2024
2025 Defining a primary without a prefix as a variable, e.g.,
2026 @samp{PROGRAMS}, is an error.
2027
2028 Note that the common @samp{dir} suffix is left off when constructing the
2029 variable names; thus one writes @samp{bin_PROGRAMS} and not
2030 @samp{bindir_PROGRAMS}.
2031
2032 Not every sort of object can be installed in every directory.  Automake
2033 will flag those attempts it finds in error (but see below how to override
2034 the check if you really need to).
2035 Automake will also diagnose obvious misspellings in directory names.
2036
2037 @cindex Extending list of installation directories
2038 @cindex Installation directories, extending list
2039
2040 Sometimes the standard directories---even as augmented by
2041 Automake---are not enough.  In particular it is sometimes useful, for
2042 clarity, to install objects in a subdirectory of some predefined
2043 directory.  To this end, Automake allows you to extend the list of
2044 possible installation directories.  A given prefix (e.g., @samp{zar})
2045 is valid if a variable of the same name with @samp{dir} appended is
2046 defined (e.g., @samp{zardir}).
2047
2048 For instance, the following snippet will install @file{file.xml} into
2049 @samp{$(datadir)/xml}.
2050
2051 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2052 @example
2053 xmldir = $(datadir)/xml
2054 xml_DATA = file.xml
2055 @end example
2056
2057 This feature can also be used to override the sanity checks Automake
2058 performs to diagnose suspicious directory/primary couples (in the
2059 unlikely case these checks are undesirable, and you really know what
2060 you're doing).  For example, Automake would error out on this input:
2061
2062 @c Should be tested in primary-prefix-invalid-couples.sh
2063 @example
2064 # Forbidden directory combinations, automake will error out on this.
2065 pkglib_PROGRAMS = foo
2066 doc_LIBRARIES = libquux.a
2067 @end example
2068
2069 @noindent
2070 but it will succeed with this:
2071
2072 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2073 @example
2074 # Work around forbidden directory combinations.  Do not use this
2075 # without a very good reason!
2076 my_execbindir = $(pkglibdir)
2077 my_doclibdir = $(docdir)
2078 my_execbin_PROGRAMS = foo
2079 my_doclib_LIBRARIES = libquux.a
2080 @end example
2081
2082 The @samp{exec} substring of the @samp{my_execbindir} variable lets
2083 the files be installed at the right time (@pxref{The Two Parts of
2084 Install}).
2085
2086 @cindex @samp{noinst_} primary prefix, definition
2087 @vindex noinst_
2088
2089 The special prefix @samp{noinst_} indicates that the objects in question
2090 should be built but not installed at all.  This is usually used for
2091 objects required to build the rest of your package, for instance static
2092 libraries (@pxref{A Library}), or helper scripts.
2093
2094 @cindex @samp{check_} primary prefix, definition
2095 @vindex check_
2096
2097 The special prefix @samp{check_} indicates that the objects in question
2098 should not be built until the @samp{make check} command is run.  Those
2099 objects are not installed either.
2100
2101 The current primary names are @samp{PROGRAMS}, @samp{LIBRARIES},
2102 @samp{LTLIBRARIES}, @samp{LISP}, @samp{PYTHON}, @samp{JAVA},
2103 @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS}, and
2104 @samp{TEXINFOS}.
2105 @vindex PROGRAMS
2106 @vindex LIBRARIES
2107 @vindex LTLIBRARIES
2108 @vindex LISP
2109 @vindex PYTHON
2110 @vindex JAVA
2111 @vindex SCRIPTS
2112 @vindex DATA
2113 @vindex HEADERS
2114 @vindex MANS
2115 @vindex TEXINFOS
2116
2117 Some primaries also allow additional prefixes that control other
2118 aspects of @command{automake}'s behavior.  The currently defined prefixes
2119 are @samp{dist_}, @samp{nodist_}, @samp{nobase_}, and @samp{notrans_}.
2120 These prefixes are explained later (@pxref{Program and Library Variables})
2121 (@pxref{Man Pages}).
2122
2123
2124 @node Length Limitations
2125 @section Staying below the command line length limit
2126
2127 @cindex command line length limit
2128 @cindex ARG_MAX
2129
2130 Traditionally, most unix-like systems have a length limitation for the
2131 command line arguments and environment contents when creating new
2132 processes (see for example
2133 @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/argmax/} for an
2134 overview on this issue),
2135 which of course also applies to commands spawned by @command{make}.
2136 POSIX requires this limit to be at least 4096 bytes, and most modern
2137 systems have quite high limits (or are unlimited).
2138
2139 In order to create portable Makefiles that do not trip over these
2140 limits, it is necessary to keep the length of file lists bounded.
2141 Unfortunately, it is not possible to do so fully transparently within
2142 Automake, so your help may be needed.  Typically, you can split long
2143 file lists manually and use different installation directory names for
2144 each list.  For example,
2145
2146 @example
2147 data_DATA = file1 @dots{} file@var{N} file@var{N+1} @dots{} file@var{2N}
2148 @end example
2149
2150 @noindent
2151 may also be written as
2152
2153 @c Keep in sync with primary-prefix-couples-documented-valid.sh
2154 @example
2155 data_DATA = file1 @dots{} file@var{N}
2156 data2dir = $(datadir)
2157 data2_DATA = file@var{N+1} @dots{} file@var{2N}
2158 @end example
2159
2160 @noindent
2161 and will cause Automake to treat the two lists separately during
2162 @code{make install}.  See @ref{The Two Parts of Install} for choosing
2163 directory names that will keep the ordering of the two parts of
2164 installation Note that @code{make dist} may still only work on a host
2165 with a higher length limit in this example.
2166
2167 Automake itself employs a couple of strategies to avoid long command
2168 lines.  For example, when @samp{$@{srcdir@}/} is prepended to file
2169 names, as can happen with above @code{$(data_DATA)} lists, it limits
2170 the amount of arguments passed to external commands.
2171
2172 Unfortunately, some system's @command{make} commands may prepend
2173 @code{VPATH} prefixes like @samp{$@{srcdir@}/} to file names from the
2174 source tree automatically (@pxref{Automatic Rule Rewriting, , Automatic
2175 Rule Rewriting, autoconf, The Autoconf Manual}).  In this case, the user
2176 may have to switch to use GNU Make, or refrain from using VPATH builds,
2177 in order to stay below the length limit.
2178
2179 For libraries and programs built from many sources, convenience archives
2180 may be used as intermediates in order to limit the object list length
2181 (@pxref{Libtool Convenience Libraries}).
2182
2183
2184 @node Canonicalization
2185 @section How derived variables are named
2186
2187 @cindex canonicalizing Automake variables
2188
2189 Sometimes a Makefile variable name is derived from some text the
2190 maintainer supplies.  For instance, a program name listed in
2191 @samp{_PROGRAMS} is rewritten into the name of a @samp{_SOURCES}
2192 variable.  In cases like this, Automake canonicalizes the text, so that
2193 program names and the like do not have to follow Makefile variable naming
2194 rules.  All characters in the name except for letters, numbers, the
2195 strudel (@@), and the underscore are turned into underscores when making
2196 variable references.
2197
2198 For example, if your program is named @file{sniff-glue}, the derived
2199 variable name would be @samp{sniff_glue_SOURCES}, not
2200 @samp{sniff-glue_SOURCES}.  Similarly the sources for a library named
2201 @file{libmumble++.a} should be listed in the
2202 @samp{libmumble___a_SOURCES} variable.
2203
2204 The strudel is an addition, to make the use of Autoconf substitutions in
2205 variable names less obfuscating.
2206
2207
2208 @node User Variables
2209 @section Variables reserved for the user
2210
2211 @cindex variables, reserved for the user
2212 @cindex user variables
2213
2214 Some @file{Makefile} variables are reserved by the GNU Coding Standards
2215 for the use of the ``user''---the person building the package.  For
2216 instance, @code{CFLAGS} is one such variable.
2217
2218 Sometimes package developers are tempted to set user variables such as
2219 @code{CFLAGS} because it appears to make their job easier.  However,
2220 the package itself should never set a user variable, particularly not
2221 to include switches that are required for proper compilation of the
2222 package.  Since these variables are documented as being for the
2223 package builder, that person rightfully expects to be able to override
2224 any of these variables at build time.
2225
2226 To get around this problem, Automake introduces an automake-specific
2227 shadow variable for each user flag variable.  (Shadow variables are
2228 not introduced for variables like @code{CC}, where they would make no
2229 sense.)  The shadow variable is named by prepending @samp{AM_} to the
2230 user variable's name.  For instance, the shadow variable for
2231 @code{YFLAGS} is @code{AM_YFLAGS}.  The package maintainer---that is,
2232 the author(s) of the @file{Makefile.am} and @file{configure.ac}
2233 files---may adjust these shadow variables however necessary.
2234
2235 @xref{Flag Variables Ordering}, for more discussion about these
2236 variables and how they interact with per-target variables.
2237
2238 @node Auxiliary Programs
2239 @section Programs automake might require
2240
2241 @cindex Programs, auxiliary
2242 @cindex Auxiliary programs
2243
2244 Automake sometimes requires helper programs so that the generated
2245 @file{Makefile} can do its work properly.  There are a fairly large
2246 number of them, and we list them here.
2247
2248 Although all of these files are distributed and installed with
2249 Automake, a couple of them are maintained separately.  The Automake
2250 copies are updated before each release, but we mention the original
2251 source in case you need more recent versions.
2252
2253 @table @code
2254 @item ar-lib
2255 This is a wrapper primarily for the Microsoft lib archiver, to make
2256 it more POSIX-like.
2257
2258 @item compile
2259 This is a wrapper for compilers that do not accept options @option{-c}
2260 and @option{-o} at the same time.  It is only used when absolutely
2261 required.  Such compilers are rare, with the Microsoft C/C++ Compiler
2262 as the most notable exception. This wrapper also makes the following
2263 common options available for that compiler, while performing file name
2264 translation where needed: @option{-I}, @option{-L}, @option{-l},
2265 @option{-Wl,} and @option{-Xlinker}.
2266
2267 @item config.guess
2268 @itemx config.sub
2269 These two programs compute the canonical triplets for the given build,
2270 host, or target architecture.  These programs are updated regularly to
2271 support new architectures and fix probes broken by changes in new
2272 kernel versions.  Each new release of Automake comes with up-to-date
2273 copies of these programs.  If your copy of Automake is getting old,
2274 you are encouraged to fetch the latest versions of these files from
2275 @url{http://savannah.gnu.org/git/?group=config} before making a
2276 release.
2277
2278 @item depcomp
2279 This program understands how to run a compiler so that it will
2280 generate not only the desired output but also dependency information
2281 that is then used by the automatic dependency tracking feature
2282 (@pxref{Dependencies}).
2283
2284 @item elisp-comp
2285 This program is used to byte-compile Emacs Lisp code.
2286
2287 @item install-sh
2288 This is a replacement for the @command{install} program that works on
2289 platforms where @command{install} is unavailable or unusable.
2290
2291 @item mdate-sh
2292 This script is used to generate a @file{version.texi} file.  It examines
2293 a file and prints some date information about it.
2294
2295 @item missing
2296 This wraps a number of programs that are typically only required by
2297 maintainers.  If the program in question doesn't exist, or seems to old,
2298 @command{missing} will print an informative warning before failing out,
2299 to provide the user with more context and information.
2300
2301 @item mkinstalldirs
2302 This script used to be a wrapper around @samp{mkdir -p}, which is not
2303 portable.  Now we prefer to use @samp{install-sh -d} when @command{configure}
2304 finds that @samp{mkdir -p} does not work, this makes one less script to
2305 distribute.
2306
2307 For backward compatibility @file{mkinstalldirs} is still used and
2308 distributed when @command{automake} finds it in a package.  But it is no
2309 longer installed automatically, and it should be safe to remove it.
2310
2311 @item py-compile
2312 This is used to byte-compile Python scripts.
2313
2314 @item test-driver
2315 This implements the default test driver offered by the parallel
2316 testsuite harness.
2317
2318 @item texinfo.tex
2319 Not a program, this file is required for @samp{make dvi}, @samp{make
2320 ps} and @samp{make pdf} to work when Texinfo sources are in the
2321 package.  The latest version can be downloaded from
2322 @url{http://www.gnu.org/software/texinfo/}.
2323
2324 @item ylwrap
2325 This program wraps @command{lex} and @command{yacc} to rename their
2326 output files.  It also ensures that, for instance, multiple
2327 @command{yacc} instances can be invoked in a single directory in
2328 parallel.
2329
2330 @end table
2331
2332
2333 @node Examples
2334 @chapter Some example packages
2335
2336 This section contains two small examples.
2337
2338 The first example (@pxref{Complete}) assumes you have an existing
2339 project already using Autoconf, with handcrafted @file{Makefile}s, and
2340 that you want to convert it to using Automake.  If you are discovering
2341 both tools, it is probably better that you look at the Hello World
2342 example presented earlier (@pxref{Hello World}).
2343
2344 The second example (@pxref{true}) shows how two programs can be built
2345 from the same file, using different compilation parameters.  It
2346 contains some technical digressions that are probably best skipped on
2347 first read.
2348
2349 @menu
2350 * Complete::                    A simple example, start to finish
2351 * true::                        Building true and false
2352 @end menu
2353
2354
2355 @node Complete
2356 @section A simple example, start to finish
2357
2358 @cindex Complete example
2359
2360 Let's suppose you just finished writing @code{zardoz}, a program to make
2361 your head float from vortex to vortex.  You've been using Autoconf to
2362 provide a portability framework, but your @file{Makefile.in}s have been
2363 ad-hoc.  You want to make them bulletproof, so you turn to Automake.
2364
2365 @cindex @code{AM_INIT_AUTOMAKE}, example use
2366
2367 The first step is to update your @file{configure.ac} to include the
2368 commands that @command{automake} needs.  The way to do this is to add an
2369 @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:
2370
2371 @example
2372 AC_INIT([zardoz], [1.0])
2373 AM_INIT_AUTOMAKE
2374 @dots{}
2375 @end example
2376
2377 Since your program doesn't have any complicating factors (e.g., it
2378 doesn't use @code{gettext}, it doesn't want to build a shared library),
2379 you're done with this part.  That was easy!
2380
2381 @cindex @command{aclocal} program, introduction
2382 @cindex @file{aclocal.m4}, preexisting
2383 @cindex @file{acinclude.m4}, defined
2384
2385 Now you must regenerate @file{configure}.  But to do that, you'll need
2386 to tell @command{autoconf} how to find the new macro you've used.  The
2387 easiest way to do this is to use the @command{aclocal} program to
2388 generate your @file{aclocal.m4} for you.  But wait@dots{} maybe you
2389 already have an @file{aclocal.m4}, because you had to write some hairy
2390 macros for your program.  The @command{aclocal} program lets you put
2391 your own macros into @file{acinclude.m4}, so simply rename and then
2392 run:
2393
2394 @example
2395 mv aclocal.m4 acinclude.m4
2396 aclocal
2397 autoconf
2398 @end example
2399
2400 @cindex @command{zardoz} example
2401
2402 Now it is time to write your @file{Makefile.am} for @code{zardoz}.
2403 Since @code{zardoz} is a user program, you want to install it where the
2404 rest of the user programs go: @code{bindir}.  Additionally,
2405 @code{zardoz} has some Texinfo documentation.  Your @file{configure.ac}
2406 script uses @code{AC_REPLACE_FUNCS}, so you need to link against
2407 @samp{$(LIBOBJS)}.  So here's what you'd write:
2408
2409 @example
2410 bin_PROGRAMS = zardoz
2411 zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c
2412 zardoz_LDADD = $(LIBOBJS)
2413
2414 info_TEXINFOS = zardoz.texi
2415 @end example
2416
2417 Now you can run @samp{automake --add-missing} to generate your
2418 @file{Makefile.in} and grab any auxiliary files you might need, and
2419 you're done!
2420
2421
2422 @node true
2423 @section Building true and false
2424
2425 @cindex Example, @command{false} and @command{true}
2426 @cindex @command{false} Example
2427 @cindex @command{true} Example
2428
2429 Here is another, trickier example.  It shows how to generate two
2430 programs (@code{true} and @code{false}) from the same source file
2431 (@file{true.c}).  The difficult part is that each compilation of
2432 @file{true.c} requires different @code{cpp} flags.
2433
2434 @example
2435 bin_PROGRAMS = true false
2436 false_SOURCES =
2437 false_LDADD = false.o
2438
2439 true.o: true.c
2440         $(COMPILE) -DEXIT_CODE=0 -c true.c
2441
2442 false.o: true.c
2443         $(COMPILE) -DEXIT_CODE=1 -o false.o -c true.c
2444 @end example
2445
2446 Note that there is no @code{true_SOURCES} definition.  Automake will
2447 implicitly assume that there is a source file named @file{true.c}
2448 (@pxref{Default _SOURCES}), and
2449 define rules to compile @file{true.o} and link @file{true}.  The
2450 @samp{true.o: true.c} rule supplied by the above @file{Makefile.am},
2451 will override the Automake generated rule to build @file{true.o}.
2452
2453 @code{false_SOURCES} is defined to be empty---that way no implicit value
2454 is substituted.  Because we have not listed the source of
2455 @file{false}, we have to tell Automake how to link the program.  This is
2456 the purpose of the @code{false_LDADD} line.  A @code{false_DEPENDENCIES}
2457 variable, holding the dependencies of the @file{false} target will be
2458 automatically generated by Automake from the content of
2459 @code{false_LDADD}.
2460
2461 The above rules won't work if your compiler doesn't accept both
2462 @option{-c} and @option{-o}.  The simplest fix for this is to introduce a
2463 bogus dependency (to avoid problems with a parallel @command{make}):
2464
2465 @example
2466 true.o: true.c false.o
2467         $(COMPILE) -DEXIT_CODE=0 -c true.c
2468
2469 false.o: true.c
2470         $(COMPILE) -DEXIT_CODE=1 -c true.c && mv true.o false.o
2471 @end example
2472
2473 As it turns out, there is also a much easier way to do this same task.
2474 Some of the above technique is useful enough that we've kept the
2475 example in the manual.  However if you were to build @code{true} and
2476 @code{false} in real life, you would probably use per-program
2477 compilation flags, like so:
2478
2479 @c Keep in sync with specflg7.sh and specflg8.sh
2480 @example
2481 bin_PROGRAMS = false true
2482
2483 false_SOURCES = true.c
2484 false_CPPFLAGS = -DEXIT_CODE=1
2485
2486 true_SOURCES = true.c
2487 true_CPPFLAGS = -DEXIT_CODE=0
2488 @end example
2489
2490 In this case Automake will cause @file{true.c} to be compiled twice,
2491 with different flags.  In this instance, the names of the object files
2492 would be chosen by automake; they would be @file{false-true.o} and
2493 @file{true-true.o}. (The name of the object files rarely matters.)
2494
2495 @node automake Invocation
2496 @chapter Creating a @file{Makefile.in}
2497 @c This node used to be named "Invoking automake".  This @anchor
2498 @c allows old links to still work.
2499 @anchor{Invoking automake}
2500
2501 @cindex Multiple @file{configure.ac} files
2502 @cindex Invoking @command{automake}
2503 @cindex @command{automake}, invoking
2504 @cindex Invocation of @command{automake}
2505 @cindex @command{automake}, invocation
2506
2507 To create all the @file{Makefile.in}s for a package, run the
2508 @command{automake} program in the top level directory, with no
2509 arguments.  @command{automake} will automatically find each
2510 appropriate @file{Makefile.am} (by scanning @file{configure.ac};
2511 @pxref{configure}) and generate the corresponding @file{Makefile.in}.
2512 Note that @command{automake} has a rather simplistic view of what
2513 constitutes a package; it assumes that a package has only one
2514 @file{configure.ac}, at the top.  If your package has multiple
2515 @file{configure.ac}s, then you must run @command{automake} in each
2516 directory holding a @file{configure.ac}.  (Alternatively, you may rely
2517 on Autoconf's @command{autoreconf}, which is able to recurse your
2518 package tree and run @command{automake} where appropriate.)
2519
2520 You can optionally give @command{automake} an argument; @file{.am} is
2521 appended to the argument and the result is used as the name of the
2522 input file.  This feature is generally only used to automatically
2523 rebuild an out-of-date @file{Makefile.in}.  Note that
2524 @command{automake} must always be run from the topmost directory of a
2525 project, even if being used to regenerate the @file{Makefile.in} in
2526 some subdirectory.  This is necessary because @command{automake} must
2527 scan @file{configure.ac}, and because @command{automake} uses the
2528 knowledge that a @file{Makefile.in} is in a subdirectory to change its
2529 behavior in some cases.
2530
2531 @vindex AUTOCONF
2532 Automake will run @command{autoconf} to scan @file{configure.ac} and
2533 its dependencies (i.e., @file{aclocal.m4} and any included file),
2534 therefore @command{autoconf} must be in your @env{PATH}.  If there is
2535 an @env{AUTOCONF} variable in your environment it will be used
2536 instead of @command{autoconf}, this allows you to select a particular
2537 version of Autoconf.  By the way, don't misunderstand this paragraph:
2538 @command{automake} runs @command{autoconf} to @strong{scan} your
2539 @file{configure.ac}, this won't build @file{configure} and you still
2540 have to run @command{autoconf} yourself for this purpose.
2541
2542 @cindex @command{automake} options
2543 @cindex Options, @command{automake}
2544 @cindex Strictness, command line
2545
2546 @command{automake} accepts the following options:
2547
2548 @cindex Extra files distributed with Automake
2549 @cindex Files distributed with Automake
2550 @cindex @file{config.guess}
2551
2552 @table @code
2553 @item -a
2554 @itemx --add-missing
2555 @opindex -a
2556 @opindex --add-missing
2557 Automake requires certain common files to exist in certain situations;
2558 for instance, @file{config.guess} is required if @file{configure.ac} invokes
2559 @code{AC_CANONICAL_HOST}.  Automake is distributed with several of these
2560 files (@pxref{Auxiliary Programs}); this option will cause the missing
2561 ones to be automatically added to the package, whenever possible.  In
2562 general if Automake tells you a file is missing, try using this option.
2563 By default Automake tries to make a symbolic link pointing to its own
2564 copy of the missing file; this can be changed with @option{--copy}.
2565
2566 Many of the potentially-missing files are common scripts whose
2567 location may be specified via the @code{AC_CONFIG_AUX_DIR} macro.
2568 Therefore, @code{AC_CONFIG_AUX_DIR}'s setting affects whether a
2569 file is considered missing, and where the missing file is added
2570 (@pxref{Optional}).
2571
2572 In some strictness modes, additional files are installed, see @ref{Gnits}
2573 for more information.
2574
2575 @item --libdir=@var{dir}
2576 @opindex --libdir
2577 Look for Automake data files in directory @var{dir} instead of in the
2578 installation directory.  This is typically used for debugging.
2579
2580 @item --print-libdir
2581 @opindex --print-libdir
2582 Print the path of the installation directory containing Automake-provided
2583 scripts and data files (like e.g., @file{texinfo.texi} and
2584 @file{install-sh}).
2585
2586 @item -c
2587 @opindex -c
2588 @itemx --copy
2589 @opindex --copy
2590 When used with @option{--add-missing}, causes installed files to be
2591 copied.  The default is to make a symbolic link.
2592
2593 @item -f
2594 @opindex -f
2595 @itemx --force-missing
2596 @opindex --force-missing
2597 When used with @option{--add-missing}, causes standard files to be reinstalled
2598 even if they already exist in the source tree.  This involves removing
2599 the file from the source tree before creating the new symlink (or, with
2600 @option{--copy}, copying the new file).
2601
2602 @item --foreign
2603 @opindex --foreign
2604 Set the global strictness to @option{foreign}.  For more information, see
2605 @ref{Strictness}.
2606
2607 @item --gnits
2608 @opindex --gnits
2609 Set the global strictness to @option{gnits}.  For more information, see
2610 @ref{Gnits}.
2611
2612 @item --gnu
2613 @opindex --gnu
2614 Set the global strictness to @option{gnu}.  For more information, see
2615 @ref{Gnits}.  This is the default strictness.
2616
2617 @item --help
2618 @opindex --help
2619 Print a summary of the command line options and exit.
2620
2621 @item -i
2622 @itemx --ignore-deps
2623 @opindex -i
2624 This disables the dependency tracking feature in generated
2625 @file{Makefile}s; see @ref{Dependencies}.
2626
2627 @item --include-deps
2628 @opindex --include-deps
2629 This enables the dependency tracking feature.  This feature is enabled
2630 by default.  This option is provided for historical reasons only and
2631 probably should not be used.
2632
2633 @item --no-force
2634 @opindex --no-force
2635 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
2636 @file{configure.ac}.  This option causes it to only update those
2637 @file{Makefile.in}s that are out of date with respect to one of their
2638 dependents.
2639
2640 @item -o @var{dir}
2641 @itemx --output-dir=@var{dir}
2642 @opindex -o
2643 @opindex --output-dir
2644 Put the generated @file{Makefile.in} in the directory @var{dir}.
2645 Ordinarily each @file{Makefile.in} is created in the directory of the
2646 corresponding @file{Makefile.am}.  This option is deprecated and will be
2647 removed in a future release.
2648
2649 @item -v
2650 @itemx --verbose
2651 @opindex -v
2652 @opindex --verbose
2653 Cause Automake to print information about which files are being read or
2654 created.
2655
2656 @item --version
2657 @opindex --version
2658 Print the version number of Automake and exit.
2659
2660 @item -W CATEGORY
2661 @itemx --warnings=@var{category}
2662 @opindex -W
2663 @opindex --warnings
2664 Output warnings falling in @var{category}.  @var{category} can be
2665 one of:
2666 @table @code
2667 @item gnu
2668 warnings related to the GNU Coding Standards
2669 (@pxref{Top, , , standards, The GNU Coding Standards}).
2670 @item obsolete
2671 obsolete features or constructions
2672 @item override
2673 user redefinitions of Automake rules or variables
2674 @item portability
2675 portability issues (e.g., use of @command{make} features that are
2676 known to be not portable)
2677 @item extra-portability
2678 extra portability issues related to obscure tools.  One example of such
2679 a tool is the Microsoft @command{lib} archiver.
2680 @item syntax
2681 weird syntax, unused variables, typos
2682 @item unsupported
2683 unsupported or incomplete features
2684 @item all
2685 all the warnings
2686 @item none
2687 turn off all the warnings
2688 @item error
2689 treat warnings as errors
2690 @end table
2691
2692 A category can be turned off by prefixing its name with @samp{no-}.  For
2693 instance, @option{-Wno-syntax} will hide the warnings about unused
2694 variables.
2695
2696 The categories output by default are @samp{syntax} and
2697 @samp{unsupported}.  Additionally, @samp{gnu} and @samp{portability}
2698 are enabled in @option{--gnu} and @option{--gnits} strictness.
2699
2700 @c Checked by extra-portability.sh
2701 Turning off @samp{portability} will also turn off @samp{extra-portability},
2702 and similarly turning on @samp{extra-portability} will also turn on
2703 @samp{portability}.  However, turning on @samp{portability} or turning
2704 off @samp{extra-portability} will not affect the other category.
2705
2706 @vindex WARNINGS
2707 The environment variable @env{WARNINGS} can contain a comma separated
2708 list of categories to enable.  It will be taken into account before the
2709 command-line switches, this way @option{-Wnone} will also ignore any
2710 warning category enabled by @env{WARNINGS}.  This variable is also used
2711 by other tools like @command{autoconf}; unknown categories are ignored
2712 for this reason.
2713
2714 @end table
2715
2716 @vindex AUTOMAKE_JOBS
2717 If the environment variable @env{AUTOMAKE_JOBS} contains a positive
2718 number, it is taken as the maximum number of Perl threads to use in
2719 @command{automake} for generating multiple @file{Makefile.in} files
2720 concurrently.  This is an experimental feature.
2721
2722
2723 @node configure
2724 @chapter Scanning @file{configure.ac}, using @command{aclocal}
2725
2726 @cindex @file{configure.ac}, scanning
2727 @cindex Scanning @file{configure.ac}
2728 @cindex Using @command{aclocal}
2729 @cindex @command{aclocal}, using
2730
2731 Automake scans the package's @file{configure.ac} to determine certain
2732 information about the package.  Some @command{autoconf} macros are required
2733 and some variables must be defined in @file{configure.ac}.  Automake
2734 will also use information from @file{configure.ac} to further tailor its
2735 output.
2736
2737 Automake also supplies some Autoconf macros to make the maintenance
2738 easier.  These macros can automatically be put into your
2739 @file{aclocal.m4} using the @command{aclocal} program.
2740
2741 @menu
2742 * Requirements::                Configuration requirements
2743 * Optional::                    Other things Automake recognizes
2744 * aclocal Invocation::          Auto-generating aclocal.m4
2745 * Macros::                      Autoconf macros supplied with Automake
2746 @end menu
2747
2748
2749 @node Requirements
2750 @section Configuration requirements
2751
2752 @cindex Automake requirements
2753 @cindex Requirements of Automake
2754
2755 @acindex AM_INIT_AUTOMAKE
2756 The one real requirement of Automake is that your @file{configure.ac}
2757 call @code{AM_INIT_AUTOMAKE}.  This macro does several things that are
2758 required for proper Automake operation (@pxref{Macros}).
2759
2760 Here are the other macros that Automake requires but which are not run
2761 by @code{AM_INIT_AUTOMAKE}:
2762
2763 @table @code
2764 @item AC_CONFIG_FILES
2765 @itemx AC_OUTPUT
2766 @acindex AC_CONFIG_FILES
2767 @acindex AC_OUTPUT
2768 These two macros are usually invoked as follows near the end of
2769 @file{configure.ac}.
2770
2771 @example
2772 @dots{}
2773 AC_CONFIG_FILES([
2774   Makefile
2775   doc/Makefile
2776   src/Makefile
2777   src/lib/Makefile
2778   @dots{}
2779 ])
2780 AC_OUTPUT
2781 @end example
2782
2783 Automake uses these to determine which files to create (@pxref{Output, ,
2784 Creating Output Files, autoconf, The Autoconf Manual}).  A listed file
2785 is considered to be an Automake generated @file{Makefile} if there
2786 exists a file with the same name and the @file{.am} extension appended.
2787 Typically, @samp{AC_CONFIG_FILES([foo/Makefile])} will cause Automake to
2788 generate @file{foo/Makefile.in} if @file{foo/Makefile.am} exists.
2789
2790 When using @code{AC_CONFIG_FILES} with multiple input files, as in
2791
2792 @example
2793 AC_CONFIG_FILES([Makefile:top.in:Makefile.in:bot.in])
2794 @end example
2795
2796 @noindent
2797 @command{automake} will generate the first @file{.in} input file for
2798 which a @file{.am} file exists.  If no such file exists the output
2799 file is not considered to be generated by Automake.
2800
2801 Files created by @code{AC_CONFIG_FILES}, be they Automake
2802 @file{Makefile}s or not, are all removed by @samp{make distclean}.
2803 Their inputs are automatically distributed, unless they
2804 are the output of prior @code{AC_CONFIG_FILES} commands.
2805 Finally, rebuild rules are generated in the Automake @file{Makefile}
2806 existing in the subdirectory of the output file, if there is one, or
2807 in the top-level @file{Makefile} otherwise.
2808
2809 The above machinery (cleaning, distributing, and rebuilding) works
2810 fine if the @code{AC_CONFIG_FILES} specifications contain only
2811 literals.  If part of the specification uses shell variables,
2812 @command{automake} will not be able to fulfill this setup, and you will
2813 have to complete the missing bits by hand.  For instance, on
2814
2815 @c Keep in sync with output11.sh
2816 @example
2817 file=input
2818 @dots{}
2819 AC_CONFIG_FILES([output:$file],, [file=$file])
2820 @end example
2821
2822 @noindent
2823 @command{automake} will output rules to clean @file{output}, and
2824 rebuild it.  However the rebuild rule will not depend on @file{input},
2825 and this file will not be distributed either.  (You must add
2826 @samp{EXTRA_DIST = input} to your @file{Makefile.am} if @file{input} is a
2827 source file.)
2828
2829 Similarly
2830
2831 @c Keep in sync with output11.sh
2832 @example
2833 file=output
2834 file2=out:in
2835 @dots{}
2836 AC_CONFIG_FILES([$file:input],, [file=$file])
2837 AC_CONFIG_FILES([$file2],, [file2=$file2])
2838 @end example
2839
2840 @noindent
2841 will only cause @file{input} to be distributed.  No file will be
2842 cleaned automatically (add @samp{DISTCLEANFILES = output out}
2843 yourself), and no rebuild rule will be output.
2844
2845 Obviously @command{automake} cannot guess what value @samp{$file} is
2846 going to hold later when @file{configure} is run, and it cannot use
2847 the shell variable @samp{$file} in a @file{Makefile}.  However, if you
2848 make reference to @samp{$file} as @samp{$@{file@}} (i.e., in a way
2849 that is compatible with @command{make}'s syntax) and furthermore use
2850 @code{AC_SUBST} to ensure that @samp{$@{file@}} is meaningful in a
2851 @file{Makefile}, then @command{automake} will be able to use
2852 @samp{$@{file@}} to generate all of these rules.  For instance, here is
2853 how the Automake package itself generates versioned scripts for its
2854 test suite:
2855
2856 @example
2857 AC_SUBST([APIVERSION], @dots{})
2858 @dots{}
2859 AC_CONFIG_FILES(
2860   [tests/aclocal-$@{APIVERSION@}:tests/aclocal.in],
2861   [chmod +x tests/aclocal-$@{APIVERSION@}],
2862   [APIVERSION=$APIVERSION])
2863 AC_CONFIG_FILES(
2864   [tests/automake-$@{APIVERSION@}:tests/automake.in],
2865   [chmod +x tests/automake-$@{APIVERSION@}])
2866 @end example
2867
2868 @noindent
2869 Here cleaning, distributing, and rebuilding are done automatically,
2870 because @samp{$@{APIVERSION@}} is known at @command{make}-time.
2871
2872 Note that you should not use shell variables to declare
2873 @file{Makefile} files for which @command{automake} must create
2874 @file{Makefile.in}.  Even @code{AC_SUBST} does not help here, because
2875 @command{automake} needs to know the file name when it runs in order
2876 to check whether @file{Makefile.am} exists.  (In the very hairy case
2877 that your setup requires such use of variables, you will have to tell
2878 Automake which @file{Makefile.in}s to generate on the command-line.)
2879
2880 It is possible to let @command{automake} emit conditional rules for
2881 @code{AC_CONFIG_FILES} with the help of @code{AM_COND_IF}
2882 (@pxref{Optional}).
2883
2884 To summarize:
2885 @itemize @bullet
2886 @item
2887 Use literals for @file{Makefile}s, and for other files whenever possible.
2888 @item
2889 Use @samp{$file} (or @samp{$@{file@}} without @samp{AC_SUBST([file])})
2890 for files that @command{automake} should ignore.
2891 @item
2892 Use @samp{$@{file@}} and @samp{AC_SUBST([file])} for files
2893 that @command{automake} should not ignore.
2894 @end itemize
2895
2896 @end table
2897
2898
2899 @node Optional
2900 @section Other things Automake recognizes
2901
2902 @cindex Macros Automake recognizes
2903 @cindex Recognized macros by Automake
2904
2905 Every time Automake is run it calls Autoconf to trace
2906 @file{configure.ac}.  This way it can recognize the use of certain
2907 macros and tailor the generated @file{Makefile.in} appropriately.
2908 Currently recognized macros and their effects are:
2909
2910 @ftable @code
2911 @item AC_CANONICAL_BUILD
2912 @itemx AC_CANONICAL_HOST
2913 @itemx AC_CANONICAL_TARGET
2914 @vindex build_triplet
2915 @vindex host_triplet
2916 @vindex target_triplet
2917 Automake will ensure that @file{config.guess} and @file{config.sub}
2918 exist.  Also, the @file{Makefile} variables @code{build_triplet},
2919 @code{host_triplet} and @code{target_triplet} are introduced.  See
2920 @ref{Canonicalizing, , Getting the Canonical System Type, autoconf,
2921 The Autoconf Manual}.
2922
2923 @item AC_CONFIG_AUX_DIR
2924 Automake will look for various helper scripts, such as
2925 @file{install-sh}, in the directory named in this macro invocation.
2926 @c This list is accurate relative to version 1.11
2927 (The full list of scripts is:
2928 @file{ar-lib},
2929 @file{config.guess},
2930 @file{config.sub},
2931 @file{depcomp},
2932 @file{elisp-comp},
2933 @file{compile},
2934 @file{install-sh},
2935 @file{ltmain.sh},
2936 @file{mdate-sh},
2937 @file{missing},
2938 @file{mkinstalldirs},
2939 @file{py-compile},
2940 @file{test-driver},
2941 @file{texinfo.tex},
2942 @file{ylwrap}.)
2943 Not all scripts are always searched for; some scripts
2944 will only be sought if the generated @file{Makefile.in} requires them.
2945
2946 If @code{AC_CONFIG_AUX_DIR} is not given, the scripts are looked for in
2947 their standard locations.  For @file{mdate-sh},
2948 @file{texinfo.tex}, and @file{ylwrap}, the standard location is the
2949 source directory corresponding to the current @file{Makefile.am}.  For
2950 the rest, the standard location is the first one of @file{.}, @file{..},
2951 or @file{../..} (relative to the top source directory) that provides any
2952 one of the helper scripts.  @xref{Input, , Finding `configure' Input,
2953 autoconf, The Autoconf Manual}.
2954
2955 Required files from @code{AC_CONFIG_AUX_DIR} are automatically
2956 distributed, even if there is no @file{Makefile.am} in this directory.
2957
2958 @item AC_CONFIG_LIBOBJ_DIR
2959 Automake will require the sources file declared with
2960 @code{AC_LIBSOURCE} (see below) in the directory specified by this
2961 macro.
2962
2963 @item AC_CONFIG_HEADERS
2964 Automake will generate rules to rebuild these headers.  Older versions
2965 of Automake required the use of @code{AM_CONFIG_HEADER}; this is no
2966 longer the case, and that macro has indeed been removed.
2967
2968 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2969 specification using shell variables will be ignored as far as
2970 cleaning, distributing, and rebuilding is concerned.
2971
2972 @item AC_CONFIG_LINKS
2973 Automake will generate rules to remove @file{configure} generated
2974 links on @samp{make distclean} and to distribute named source files as
2975 part of @samp{make dist}.
2976
2977 As for @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
2978 specification using shell variables will be ignored as far as cleaning
2979 and distributing is concerned.  (There are no rebuild rules for links.)
2980
2981 @item AC_LIBOBJ
2982 @itemx AC_LIBSOURCE
2983 @itemx AC_LIBSOURCES
2984 @vindex LIBOBJS
2985 Automake will automatically distribute any file listed in
2986 @code{AC_LIBSOURCE} or @code{AC_LIBSOURCES}.
2987
2988 Note that the @code{AC_LIBOBJ} macro calls @code{AC_LIBSOURCE}.  So if
2989 an Autoconf macro is documented to call @samp{AC_LIBOBJ([file])}, then
2990 @file{file.c} will be distributed automatically by Automake.  This
2991 encompasses many macros like @code{AC_FUNC_ALLOCA},
2992 @code{AC_FUNC_MEMCMP}, @code{AC_REPLACE_FUNCS}, and others.
2993
2994 By the way, direct assignments to @code{LIBOBJS} are no longer
2995 supported.  You should always use @code{AC_LIBOBJ} for this purpose.
2996 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
2997 autoconf, The Autoconf Manual}.
2998
2999 @item AC_PROG_RANLIB
3000 This is required if any libraries are built in the package.
3001 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3002 Autoconf Manual}.
3003
3004 @item AC_PROG_CXX
3005 This is required if any C++ source is included.  @xref{Particular
3006 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3007
3008 @item AC_PROG_OBJC
3009 This is required if any Objective C source is included.  @xref{Particular
3010 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3011
3012 @item AC_PROG_OBJCXX
3013 This is required if any Objective C++ source is included.  @xref{Particular
3014 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3015
3016 @item AC_PROG_F77
3017 This is required if any Fortran 77 source is included.  @xref{Particular
3018 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3019
3020 @item AC_F77_LIBRARY_LDFLAGS
3021 This is required for programs and shared libraries that are a mixture of
3022 languages that include Fortran 77 (@pxref{Mixing Fortran 77 With C and
3023 C++}).  @xref{Macros, , Autoconf macros supplied with Automake}.
3024
3025 @item AC_FC_SRCEXT
3026 Automake will add the flags computed by @code{AC_FC_SRCEXT} to compilation
3027 of files with the respective source extension (@pxref{Fortran Compiler, ,
3028 Fortran Compiler Characteristics, autoconf, The Autoconf Manual}).
3029
3030 @item AC_PROG_FC
3031 This is required if any Fortran 90/95 source is included.  This macro is
3032 distributed with Autoconf version 2.58 and later.  @xref{Particular
3033 Programs, , Particular Program Checks, autoconf, The Autoconf Manual}.
3034
3035 @item AC_PROG_LIBTOOL
3036 Automake will turn on processing for @command{libtool} (@pxref{Top, ,
3037 Introduction, libtool, The Libtool Manual}).
3038
3039 @item AC_PROG_YACC
3040 @vindex YACC
3041 If a Yacc source file is seen, then you must either use this macro or
3042 define the variable @code{YACC} in @file{configure.ac}.  The former is
3043 preferred (@pxref{Particular Programs, , Particular Program Checks,
3044 autoconf, The Autoconf Manual}).
3045
3046 @item AC_PROG_LEX
3047 If a Lex source file is seen, then this macro must be used.
3048 @xref{Particular Programs, , Particular Program Checks, autoconf, The
3049 Autoconf Manual}.
3050
3051 @item AC_REQUIRE_AUX_FILE
3052 For each @code{AC_REQUIRE_AUX_FILE([@var{file}])},
3053 @command{automake} will ensure that @file{@var{file}} exists in the
3054 aux directory, and will complain otherwise.  It
3055 will also automatically distribute the file.  This macro should be
3056 used by third-party Autoconf macros that require some supporting
3057 files in the aux directory specified with @code{AC_CONFIG_AUX_DIR}
3058 above.  @xref{Input, , Finding @command{configure} Input, autoconf,
3059 The Autoconf Manual}.
3060
3061 @item AC_SUBST
3062 The first argument is automatically defined as a variable in each
3063 generated @file{Makefile.in}, unless @code{AM_SUBST_NOTMAKE} is also
3064 used for this variable.  @xref{Setting Output Variables, , Setting
3065 Output Variables, autoconf, The Autoconf Manual}.
3066
3067 For every substituted variable @var{var}, @command{automake} will add
3068 a line @code{@var{var} = @var{value}} to each @file{Makefile.in} file.
3069 Many Autoconf macros invoke @code{AC_SUBST} to set output variables
3070 this way, e.g., @code{AC_PATH_XTRA} defines @code{X_CFLAGS} and
3071 @code{X_LIBS}.  Thus, you can access these variables as
3072 @code{$(X_CFLAGS)} and @code{$(X_LIBS)} in any @file{Makefile.am}
3073 if @code{AC_PATH_XTRA} is called.
3074
3075 @item AM_CONDITIONAL
3076 This introduces an Automake conditional (@pxref{Conditionals}).
3077
3078 @item AM_COND_IF
3079 This macro allows @code{automake} to detect subsequent access within
3080 @file{configure.ac} to a conditional previously introduced with
3081 @code{AM_CONDITIONAL}, thus enabling conditional @code{AC_CONFIG_FILES}
3082 (@pxref{Usage of Conditionals}).
3083
3084 @item AM_GNU_GETTEXT
3085 This macro is required for packages that use GNU gettext
3086 (@pxref{gettext}).  It is distributed with gettext.  If Automake sees
3087 this macro it ensures that the package meets some of gettext's
3088 requirements.
3089
3090 @item AM_GNU_GETTEXT_INTL_SUBDIR
3091 This macro specifies that the @file{intl/} subdirectory is to be built,
3092 even if the @code{AM_GNU_GETTEXT} macro was invoked with a first argument
3093 of @samp{external}.
3094
3095 @item AM_MAINTAINER_MODE(@ovar{default-mode})
3096 @opindex --enable-maintainer-mode
3097 @opindex --disable-maintainer-mode
3098 This macro adds an @option{--enable-maintainer-mode} option to
3099 @command{configure}.  If this is used, @command{automake} will cause
3100 ``maintainer-only'' rules to be turned off by default in the
3101 generated @file{Makefile.in}s, unless @var{default-mode} is
3102 @samp{enable}.  This macro defines the @code{MAINTAINER_MODE}
3103 conditional, which you can use in your own @file{Makefile.am}.
3104 @xref{maintainer-mode}.
3105
3106 @item AM_SUBST_NOTMAKE(@var{var})
3107 Prevent Automake from defining a variable @var{var}, even if it is
3108 substituted by @command{config.status}.  Normally, Automake defines a
3109 @command{make} variable for each @command{configure} substitution,
3110 i.e., for each @code{AC_SUBST([@var{var}])}.  This macro prevents that
3111 definition from Automake.  If @code{AC_SUBST} has not been called
3112 for this variable, then @code{AM_SUBST_NOTMAKE} has no effects.
3113 Preventing variable definitions may be useful for substitution of
3114 multi-line values, where @code{@var{var} = @@@var{value}@@} might yield
3115 unintended results.
3116
3117 @item m4_include
3118 Files included by @file{configure.ac} using this macro will be
3119 detected by Automake and automatically distributed.  They will also
3120 appear as dependencies in @file{Makefile} rules.
3121
3122 @code{m4_include} is seldom used by @file{configure.ac} authors, but
3123 can appear in @file{aclocal.m4} when @command{aclocal} detects that
3124 some required macros come from files local to your package (as opposed to
3125 macros installed in a system-wide directory, @pxref{aclocal Invocation}).
3126
3127 @end ftable
3128
3129 @node aclocal Invocation
3130 @section Auto-generating aclocal.m4
3131 @c This node used to be named "Invoking automake".  This @anchor
3132 @c allows old links to still work.
3133 @anchor{Invoking aclocal}
3134
3135 @cindex Invocation of @command{aclocal}
3136 @cindex @command{aclocal}, Invocation
3137 @cindex Invoking @command{aclocal}
3138 @cindex @command{aclocal}, Invoking
3139
3140 Automake includes a number of Autoconf macros that can be used in
3141 your package (@pxref{Macros}); some of them are actually required by
3142 Automake in certain situations.  These macros must be defined in your
3143 @file{aclocal.m4}; otherwise they will not be seen by
3144 @command{autoconf}.
3145
3146 The @command{aclocal} program will automatically generate
3147 @file{aclocal.m4} files based on the contents of @file{configure.ac}.
3148 This provides a convenient way to get Automake-provided macros,
3149 without having to search around.  The @command{aclocal} mechanism
3150 allows other packages to supply their own macros (@pxref{Extending
3151 aclocal}).  You can also use it to maintain your own set of custom
3152 macros (@pxref{Local Macros}).
3153
3154 At startup, @command{aclocal} scans all the @file{.m4} files it can
3155 find, looking for macro definitions (@pxref{Macro Search Path}).  Then
3156 it scans @file{configure.ac}.  Any mention of one of the macros found
3157 in the first step causes that macro, and any macros it in turn
3158 requires, to be put into @file{aclocal.m4}.
3159
3160 @emph{Putting} the file that contains the macro definition into
3161 @file{aclocal.m4} is usually done by copying the entire text of this
3162 file, including unused macro definitions as well as both @samp{#} and
3163 @samp{dnl} comments.  If you want to make a comment that will be
3164 completely ignored by @command{aclocal}, use @samp{##} as the comment
3165 leader.
3166
3167 When a file selected by @command{aclocal} is located in a subdirectory
3168 specified as a relative search path with @command{aclocal}'s @option{-I}
3169 argument, @command{aclocal} assumes the file belongs to the package
3170 and uses @code{m4_include} instead of copying it into
3171 @file{aclocal.m4}.  This makes the package smaller, eases dependency
3172 tracking, and cause the file to be distributed automatically.
3173 (@xref{Local Macros}, for an example.)  Any macro that is found in a
3174 system-wide directory, or via an absolute search path will be copied.
3175 So use @samp{-I `pwd`/reldir} instead of @samp{-I reldir} whenever
3176 some relative directory should be considered outside the package.
3177
3178 The contents of @file{acinclude.m4}, if this file exists, are also
3179 automatically included in @file{aclocal.m4}.  We recommend against
3180 using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
3181
3182 @vindex AUTOM4TE
3183 @cindex autom4te
3184 While computing @file{aclocal.m4}, @command{aclocal} runs
3185 @command{autom4te} (@pxref{Using autom4te, , Using @command{Autom4te},
3186 autoconf, The Autoconf Manual}) in order to trace the macros that are
3187 really used, and omit from @file{aclocal.m4} all macros that are
3188 mentioned but otherwise unexpanded (this can happen when a macro is
3189 called conditionally).  @command{autom4te} is expected to be in the
3190 @env{PATH}, just as @command{autoconf}.  Its location can be
3191 overridden using the @env{AUTOM4TE} environment variable.
3192
3193 @menu
3194 * aclocal Options::             Options supported by aclocal
3195 * Macro Search Path::           How aclocal finds .m4 files
3196 * Extending aclocal::           Writing your own aclocal macros
3197 * Local Macros::                Organizing local macros
3198 * Serials::                     Serial lines in Autoconf macros
3199 * Future of aclocal::           aclocal's scheduled death
3200 @end menu
3201
3202 @node aclocal Options
3203 @subsection aclocal Options
3204
3205 @cindex @command{aclocal}, Options
3206 @cindex Options, @command{aclocal}
3207
3208 @command{aclocal} accepts the following options:
3209
3210 @table @code
3211 @item --automake-acdir=@var{dir}
3212 @opindex --automake-acdir
3213 Look for the automake-provided macro files in @var{dir} instead of
3214 in the installation directory.  This is typically used for debugging.
3215
3216 @item --system-acdir=@var{dir}
3217 @opindex --system-acdir
3218 Look for the system-wide third-party macro files (and the special
3219 @file{dirlist} file) in @var{dir} instead of in the installation
3220 directory.  This is typically used for debugging.
3221
3222 @item --diff[=@var{command}]
3223 @opindex --diff
3224 Run @var{command} on M4 file that would be installed or overwritten
3225 by @option{--install}.  The default @var{command} is @samp{diff -u}.
3226 This option implies @option{--install} and @option{--dry-run}.
3227
3228 @item --dry-run
3229 @opindex --dry-run
3230 Do not actually overwrite (or create) @file{aclocal.m4} and M4
3231 files installed by @option{--install}.
3232
3233 @item --help
3234 @opindex --help
3235 Print a summary of the command line options and exit.
3236
3237 @item -I @var{dir}
3238 @opindex -I
3239 Add the directory @var{dir} to the list of directories searched for
3240 @file{.m4} files.
3241
3242 @item --install
3243 @opindex --install
3244 Install system-wide third-party macros into the first directory
3245 specified with @samp{-I @var{dir}} instead of copying them in the
3246 output file.
3247 @c Keep in sync with aclocal-install-absdir.sh
3248 Note that this will happen also if @var{dir} is an absolute path.
3249
3250 @cindex serial number and @option{--install}
3251 When this option is used, and only when this option is used,
3252 @command{aclocal} will also honor @samp{#serial @var{number}} lines
3253 that appear in macros: an M4 file is ignored if there exists another
3254 M4 file with the same basename and a greater serial number in the
3255 search path (@pxref{Serials}).
3256
3257 @item --force
3258 @opindex --force
3259 Always overwrite the output file.  The default is to overwrite the output
3260 file only when really needed, i.e., when its contents changes or if one
3261 of its dependencies is younger.
3262
3263 This option forces the update of @file{aclocal.m4} (or the file
3264 specified with @file{--output} below) and only this file, it has
3265 absolutely no influence on files that may need to be installed by
3266 @option{--install}.
3267
3268 @item --output=@var{file}
3269 @opindex --output
3270 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
3271
3272 @item --print-ac-dir
3273 @opindex --print-ac-dir
3274 Prints the name of the directory that @command{aclocal} will search to
3275 find third-party @file{.m4} files.  When this option is given, normal
3276 processing is suppressed.  This option was used @emph{in the past} by
3277 third-party packages to determine where to install @file{.m4} macro
3278 files, but @emph{this usage is today discouraged}, since it causes
3279 @samp{$(prefix)} not to be thoroughly honoured (which violates the
3280 GNU Coding Standards), and a similar semantics can be better obtained
3281 with the @env{ACLOCAL_PATH} environment variable; @pxref{Extending aclocal}.
3282
3283 @item --verbose
3284 @opindex --verbose
3285 Print the names of the files it examines.
3286
3287 @item --version
3288 @opindex --version
3289 Print the version number of Automake and exit.
3290
3291 @item -W CATEGORY
3292 @item --warnings=@var{category}
3293 @opindex -W
3294 @opindex --warnings
3295 Output warnings falling in @var{category}.  @var{category} can be
3296 one of:
3297 @table @code
3298 @item syntax
3299 dubious syntactic constructs, underquoted macros, unused macros, etc.
3300 @item unsupported
3301 unknown macros
3302 @item all
3303 all the warnings, this is the default
3304 @item none
3305 turn off all the warnings
3306 @item error
3307 treat warnings as errors
3308 @end table
3309
3310 All warnings are output by default.
3311
3312 @vindex WARNINGS
3313 The environment variable @env{WARNINGS} is honored in the same
3314 way as it is for @command{automake} (@pxref{automake Invocation}).
3315
3316 @end table
3317
3318 @node Macro Search Path
3319 @subsection Macro Search Path
3320
3321 @cindex Macro search path
3322 @cindex @command{aclocal} search path
3323
3324 By default, @command{aclocal} searches for @file{.m4} files in the following
3325 directories, in this order:
3326
3327 @table @code
3328 @item @var{acdir-APIVERSION}
3329 This is where the @file{.m4} macros distributed with Automake itself
3330 are stored.  @var{APIVERSION} depends on the Automake release used;
3331 for example, for Automake 1.11.x, @var{APIVERSION} = @code{1.11}.
3332
3333 @item @var{acdir}
3334 This directory is intended for third party @file{.m4} files, and is
3335 configured when @command{automake} itself is built.  This is
3336 @file{@@datadir@@/aclocal/}, which typically
3337 expands to @file{$@{prefix@}/share/aclocal/}.  To find the compiled-in
3338 value of @var{acdir}, use the @option{--print-ac-dir} option
3339 (@pxref{aclocal Options}).
3340 @end table
3341
3342 As an example, suppose that @command{automake-1.11.2} was configured with
3343 @option{--prefix=@-/usr/local}.  Then, the search path would be:
3344
3345 @enumerate
3346 @item @file{/usr/local/share/aclocal-1.11.2/}
3347 @item @file{/usr/local/share/aclocal/}
3348 @end enumerate
3349
3350 The paths for the @var{acdir} and @var{acdir-APIVERSION} directories can
3351 be changed respectively through aclocal options @option{--system-acdir}
3352 and @option{--automake-acdir} (@pxref{aclocal Options}).  Note however
3353 that these options are only intended for use by the internal Automake
3354 test suite, or for debugging under highly unusual situations; they are
3355 not ordinarily needed by end-users.
3356
3357 As explained in (@pxref{aclocal Options}), there are several options that
3358 can be used to change or extend this search path.
3359
3360 @subsubheading Modifying the Macro Search Path: @samp{-I @var{dir}}
3361
3362 Any extra directories specified using @option{-I} options
3363 (@pxref{aclocal Options}) are @emph{prepended} to this search list.  Thus,
3364 @samp{aclocal -I /foo -I /bar} results in the following search path:
3365
3366 @enumerate
3367 @item @file{/foo}
3368 @item @file{/bar}
3369 @item @var{acdir}-@var{APIVERSION}
3370 @item @var{acdir}
3371 @end enumerate
3372
3373 @subsubheading Modifying the Macro Search Path: @file{dirlist}
3374 @cindex @file{dirlist}
3375
3376 There is a third mechanism for customizing the search path.  If a
3377 @file{dirlist} file exists in @var{acdir}, then that file is assumed to
3378 contain a list of directory patterns, one per line.  @command{aclocal}
3379 expands these patterns to directory names, and adds them to the search
3380 list @emph{after} all other directories.  @file{dirlist} entries may
3381 use shell wildcards such as @samp{*}, @samp{?}, or @code{[...]}.
3382
3383 For example, suppose
3384 @file{@var{acdir}/dirlist} contains the following:
3385
3386 @example
3387 /test1
3388 /test2
3389 /test3*
3390 @end example
3391
3392 @noindent
3393 and that @command{aclocal} was called with the @samp{-I /foo -I /bar} options.
3394 Then, the search path would be
3395
3396 @c @code looks better than @file here
3397 @enumerate
3398 @item @code{/foo}
3399 @item @code{/bar}
3400 @item @var{acdir}-@var{APIVERSION}
3401 @item @var{acdir}
3402 @item @code{/test1}
3403 @item @code{/test2}
3404 @end enumerate
3405
3406 @noindent
3407 and all directories with path names starting with @code{/test3}.
3408
3409 If the @option{--system-acdir=@var{dir}} option is used, then
3410 @command{aclocal} will search for the @file{dirlist} file in
3411 @var{dir}; but remember the warnings  above against the use of
3412 @option{--system-acdir}.
3413
3414 @file{dirlist} is useful in the following situation: suppose that
3415 @command{automake} version @code{1.11.2} is installed with
3416 @samp{--prefix=/usr} by the system vendor.  Thus, the default search
3417 directories are
3418
3419 @c @code looks better than @file here
3420 @enumerate
3421 @item @code{/usr/share/aclocal-1.11/}
3422 @item @code{/usr/share/aclocal/}
3423 @end enumerate
3424
3425 However, suppose further that many packages have been manually
3426 installed on the system, with $prefix=/usr/local, as is typical.  In
3427 that case, many of these ``extra'' @file{.m4} files are in
3428 @file{/usr/local/share/aclocal}.  The only way to force
3429 @file{/usr/bin/aclocal} to find these ``extra'' @file{.m4} files is to
3430 always call @samp{aclocal -I /usr/local/share/aclocal}.  This is
3431 inconvenient.  With @file{dirlist}, one may create a file
3432 @file{/usr/share/aclocal/dirlist} containing only the single line
3433
3434 @example
3435 /usr/local/share/aclocal
3436 @end example
3437
3438 Now, the ``default'' search path on the affected system is
3439
3440 @c @code looks better than @file here
3441 @enumerate
3442 @item @code{/usr/share/aclocal-1.11/}
3443 @item @code{/usr/share/aclocal/}
3444 @item @code{/usr/local/share/aclocal/}
3445 @end enumerate
3446
3447 without the need for @option{-I} options; @option{-I} options can be reserved
3448 for project-specific needs (@file{my-source-dir/m4/}), rather than
3449 using it to work around local system-dependent tool installation
3450 directories.
3451
3452 Similarly, @file{dirlist} can be handy if you have installed a local
3453 copy of Automake in your account and want @command{aclocal} to look for
3454 macros installed at other places on the system.
3455
3456 @anchor{ACLOCAL_PATH}
3457 @subsubheading Modifying the Macro Search Path: @file{ACLOCAL_PATH}
3458 @cindex @env{ACLOCAL_PATH}
3459
3460 The fourth and last mechanism to customize the macro search path is
3461 also the simplest.  Any directory included in the colon-separated
3462 environment variable @env{ACLOCAL_PATH} is added to the search path
3463 @c Keep in sync with aclocal-path-precedence.sh
3464 and takes precedence over system directories (including those found via
3465 @file{dirlist}), with the exception of the versioned directory
3466 @var{acdir-APIVERSION} (@pxref{Macro Search Path}).  However, directories
3467 passed via @option{-I} will take precedence over directories in
3468 @env{ACLOCAL_PATH}.
3469
3470 @c Keep in sync with aclocal-path-installed.sh
3471 Also note that, if the @option{--install} option is used, any @file{.m4}
3472 file containing a required macro that is found in a directory listed in
3473 @env{ACLOCAL_PATH} will be installed locally.
3474 @c Keep in sync with aclocal-path-installed-serial.sh
3475 In this case, serial numbers in @file{.m4} are honoured too,
3476 @pxref{Serials}.
3477
3478 Conversely to @file{dirlist}, @env{ACLOCAL_PATH} is useful if you are
3479 using a global copy of Automake and want @command{aclocal} to look for
3480 macros somewhere under your home directory.
3481
3482 @subsubheading Planned future incompatibilities
3483
3484 The order in which the directories in the macro search path are currently
3485 looked up is confusing and/or suboptimal in various aspects, and is
3486 probably going to be changed in the future Automake release.  In
3487 particular, directories in @env{ACLOCAL_PATH} and @file{@var{acdir}}
3488 might end up taking precedence over @file{@var{acdir-APIVERSION}}, and
3489 directories in @file{@var{acdir}/dirlist} might end up taking precedence
3490 over @file{@var{acdir}}.  @emph{This is a possible future incompatibility!}
3491
3492 @node Extending aclocal
3493 @subsection Writing your own aclocal macros
3494
3495 @cindex @command{aclocal}, extending
3496 @cindex Extending @command{aclocal}
3497
3498 The @command{aclocal} program doesn't have any built-in knowledge of any
3499 macros, so it is easy to extend it with your own macros.
3500
3501 This can be used by libraries that want to supply their own Autoconf
3502 macros for use by other programs.  For instance, the @command{gettext}
3503 library supplies a macro @code{AM_GNU_GETTEXT} that should be used by
3504 any package using @command{gettext}.  When the library is installed, it
3505 installs this macro so that @command{aclocal} will find it.
3506
3507 A macro file's name should end in @file{.m4}.  Such files should be
3508 installed in @file{$(datadir)/aclocal}.  This is as simple as writing:
3509
3510 @c Keep in sync with primary-prefix-couples-documented-valid.sh
3511 @example
3512 aclocaldir = $(datadir)/aclocal
3513 aclocal_DATA = mymacro.m4 myothermacro.m4
3514 @end example
3515
3516 @noindent
3517 Please do use @file{$(datadir)/aclocal}, and not something based on
3518 the result of @samp{aclocal --print-ac-dir} (@pxref{Hard-Coded Install
3519 Paths}, for arguments).  It might also be helpful to suggest to
3520 the user to add the @file{$(datadir)/aclocal} directory to his
3521 @env{ACLOCAL_PATH} variable (@pxref{ACLOCAL_PATH}) so that
3522 @command{aclocal} will find the @file{.m4} files installed by your
3523 package automatically.
3524
3525 A file of macros should be a series of properly quoted
3526 @code{AC_DEFUN}'s (@pxref{Macro Definitions, , , autoconf, The
3527 Autoconf Manual}).  The @command{aclocal} programs also understands
3528 @code{AC_REQUIRE} (@pxref{Prerequisite Macros, , , autoconf, The
3529 Autoconf Manual}), so it is safe to put each macro in a separate file.
3530 Each file should have no side effects but macro definitions.
3531 Especially, any call to @code{AC_PREREQ} should be done inside the
3532 defined macro, not at the beginning of the file.
3533
3534 @cindex underquoted @code{AC_DEFUN}
3535 @acindex AC_DEFUN
3536 @acindex AC_PREREQ
3537
3538 Starting with Automake 1.8, @command{aclocal} will warn about all
3539 underquoted calls to @code{AC_DEFUN}.  We realize this will annoy a
3540 lot of people, because @command{aclocal} was not so strict in the past
3541 and many third party macros are underquoted; and we have to apologize
3542 for this temporary inconvenience.  The reason we have to be stricter
3543 is that a future implementation of @command{aclocal} (@pxref{Future of
3544 aclocal}) will have to temporarily include all of these third party
3545 @file{.m4} files, maybe several times, including even files that are
3546 not actually needed.  Doing so should alleviate many problems of the
3547 current implementation, however it requires a stricter style from the
3548 macro authors.  Hopefully it is easy to revise the existing macros.
3549 For instance,
3550
3551 @example
3552 # bad style
3553 AC_PREREQ(2.68)
3554 AC_DEFUN(AX_FOOBAR,
3555 [AC_REQUIRE([AX_SOMETHING])dnl
3556 AX_FOO
3557 AX_BAR
3558 ])
3559 @end example
3560
3561 @noindent
3562 should be rewritten as
3563
3564 @example
3565 AC_DEFUN([AX_FOOBAR],
3566 [AC_PREREQ([2.68])dnl
3567 AC_REQUIRE([AX_SOMETHING])dnl
3568 AX_FOO
3569 AX_BAR
3570 ])
3571 @end example
3572
3573 Wrapping the @code{AC_PREREQ} call inside the macro ensures that
3574 Autoconf 2.68 will not be required if @code{AX_FOOBAR} is not actually
3575 used.  Most importantly, quoting the first argument of @code{AC_DEFUN}
3576 allows the macro to be redefined or included twice (otherwise this
3577 first argument would be expanded during the second definition).  For
3578 consistency we like to quote even arguments such as @code{2.68} that
3579 do not require it.
3580
3581 If you have been directed here by the @command{aclocal} diagnostic but
3582 are not the maintainer of the implicated macro, you will want to
3583 contact the maintainer of that macro.  Please make sure you have the
3584 latest version of the macro and that the problem hasn't already been
3585 reported before doing so: people tend to work faster when they aren't
3586 flooded by mails.
3587
3588 Another situation where @command{aclocal} is commonly used is to
3589 manage macros that are used locally by the package, @ref{Local
3590 Macros}.
3591
3592 @node Local Macros
3593 @subsection Handling Local Macros
3594
3595 Feature tests offered by Autoconf do not cover all needs.  People
3596 often have to supplement existing tests with their own macros, or
3597 with third-party macros.
3598
3599 There are two ways to organize custom macros in a package.
3600
3601 The first possibility (the historical practice) is to list all your
3602 macros in @file{acinclude.m4}.  This file will be included in
3603 @file{aclocal.m4} when you run @command{aclocal}, and its macro(s) will
3604 henceforth be visible to @command{autoconf}.  However if it contains
3605 numerous macros, it will rapidly become difficult to maintain, and it
3606 will be almost impossible to share macros between packages.
3607
3608 @vindex ACLOCAL_AMFLAGS
3609 The second possibility, which we do recommend, is to write each macro
3610 in its own file and gather all of these files in a directory.  This
3611 directory is usually called @file{m4/}.  To build @file{aclocal.m4},
3612 one should therefore instruct @command{aclocal} to scan @file{m4/}.
3613 From the command line, this is done with @samp{aclocal -I m4}.  The
3614 top-level @file{Makefile.am} should also be updated to define
3615
3616 @example
3617 ACLOCAL_AMFLAGS = -I m4
3618 @end example
3619
3620 @code{ACLOCAL_AMFLAGS} contains options to pass to @command{aclocal}
3621 when @file{aclocal.m4} is to be rebuilt by @command{make}.  This line is
3622 also used by @command{autoreconf} (@pxref{autoreconf Invocation, ,
3623 Using @command{autoreconf} to Update @file{configure} Scripts,
3624 autoconf, The Autoconf Manual}) to run @command{aclocal} with suitable
3625 options, or by @command{autopoint} (@pxref{autopoint Invocation, ,
3626 Invoking the @command{autopoint} Program, gettext, GNU gettext tools})
3627 and @command{gettextize} (@pxref{gettextize Invocation, , Invoking the
3628 @command{gettextize} Program, gettext, GNU gettext tools}) to locate
3629 the place where Gettext's macros should be installed.  So even if you
3630 do not really care about the rebuild rules, you should define
3631 @code{ACLOCAL_AMFLAGS}.
3632
3633 When @samp{aclocal -I m4} is run, it will build an @file{aclocal.m4}
3634 that @code{m4_include}s any file from @file{m4/} that defines a
3635 required macro.  Macros not found locally will still be searched in
3636 system-wide directories, as explained in @ref{Macro Search Path}.
3637
3638 Custom macros should be distributed for the same reason that
3639 @file{configure.ac} is: so that other people have all the sources of
3640 your package if they want to work on it.  Actually, this distribution
3641 happens automatically because all @code{m4_include}d files are
3642 distributed.
3643
3644 However there is no consensus on the distribution of third-party
3645 macros that your package may use.  Many libraries install their own
3646 macro in the system-wide @command{aclocal} directory (@pxref{Extending
3647 aclocal}).  For instance, Guile ships with a file called
3648 @file{guile.m4} that contains the macro @code{GUILE_FLAGS} that can
3649 be used to define setup compiler and linker flags appropriate for
3650 using Guile.  Using @code{GUILE_FLAGS} in @file{configure.ac} will
3651 cause @command{aclocal} to copy @file{guile.m4} into
3652 @file{aclocal.m4}, but as @file{guile.m4} is not part of the project,
3653 it will not be distributed.  Technically, that means a user who
3654 needs to rebuild @file{aclocal.m4} will have to install Guile first.
3655 This is probably OK, if Guile already is a requirement to build the
3656 package.  However, if Guile is only an optional feature, or if your
3657 package might run on architectures where Guile cannot be installed,
3658 this requirement will hinder development.  An easy solution is to copy
3659 such third-party macros in your local @file{m4/} directory so they get
3660 distributed.
3661
3662 Since Automake 1.10, @command{aclocal} offers an option to copy these
3663 system-wide third-party macros in your local macro directory, solving
3664 the above problem.  Simply use:
3665
3666 @example
3667 ACLOCAL_AMFLAGS = -I m4 --install
3668 @end example
3669
3670 @noindent
3671 With this setup, system-wide macros will be copied to @file{m4/}
3672 the first time you run @command{autoreconf}.  Then the locally
3673 installed macros will have precedence over the system-wide installed
3674 macros each time @command{aclocal} is run again.
3675
3676 One reason why you should keep @option{--install} in the flags even
3677 after the first run is that when you later edit @file{configure.ac}
3678 and depend on a new macro, this macro will be installed in your
3679 @file{m4/} automatically.  Another one is that serial numbers
3680 (@pxref{Serials}) can be used to update the macros in your source tree
3681 automatically when new system-wide versions are installed.  A serial
3682 number should be a single line of the form
3683
3684 @example
3685 #serial @var{nnn}
3686 @end example
3687
3688 @noindent
3689 where @var{nnn} contains only digits and dots.  It should appear in
3690 the M4 file before any macro definition.  It is a good practice to
3691 maintain a serial number for each macro you distribute, even if you do
3692 not use the @option{--install} option of @command{aclocal}: this allows
3693 other people to use it.
3694
3695
3696 @node Serials
3697 @subsection Serial Numbers
3698 @cindex serial numbers in macros
3699 @cindex macro serial numbers
3700 @cindex @code{#serial} syntax
3701 @cindex @command{aclocal} and serial numbers
3702
3703 Because third-party macros defined in @file{*.m4} files are naturally
3704 shared between multiple projects, some people like to version them.
3705 This makes it easier to tell which of two M4 files is newer.  Since at
3706 least 1996, the tradition is to use a @samp{#serial} line for this.
3707
3708 A serial number should be a single line of the form
3709
3710 @example
3711 # serial @var{version}
3712 @end example
3713
3714 @noindent
3715 where @var{version} is a version number containing only digits and
3716 dots.  Usually people use a single integer, and they increment it each
3717 time they change the macro (hence the name of ``serial'').  Such a
3718 line should appear in the M4 file before any macro definition.
3719
3720 The @samp{#} must be the first character on the line,
3721 and it is OK to have extra words after the version, as in
3722
3723 @example
3724 #serial @var{version} @var{garbage}
3725 @end example
3726
3727 Normally these serial numbers are completely ignored by
3728 @command{aclocal} and @command{autoconf}, like any genuine comment.
3729 However when using @command{aclocal}'s @option{--install} feature, these
3730 serial numbers will modify the way @command{aclocal} selects the
3731 macros to install in the package: if two files with the same basename
3732 exist in your search path, and if at least one of them uses a
3733 @samp{#serial} line, @command{aclocal} will ignore the file that has
3734 the older @samp{#serial} line (or the file that has none).
3735
3736 Note that a serial number applies to a whole M4 file, not to any macro
3737 it contains.  A file can contains multiple macros, but only one
3738 serial.
3739
3740 Here is a use case that illustrates the use of @option{--install} and
3741 its interaction with serial numbers.  Let's assume we maintain a
3742 package called MyPackage, the @file{configure.ac} of which requires a
3743 third-party macro @code{AX_THIRD_PARTY} defined in
3744 @file{/usr/share/aclocal/thirdparty.m4} as follows:
3745
3746 @example
3747 # serial 1
3748 AC_DEFUN([AX_THIRD_PARTY], [...])
3749 @end example
3750
3751 MyPackage uses an @file{m4/} directory to store local macros as
3752 explained in @ref{Local Macros}, and has
3753
3754 @example
3755 ACLOCAL_AMFLAGS = -I m4 --install
3756 @end example
3757
3758 @noindent
3759 in its top-level @file{Makefile.am}.
3760
3761 Initially the @file{m4/} directory is empty.  The first time we run
3762 @command{autoreconf}, it will fetch the options to pass to
3763 @command{aclocal} in @file{Makefile.am}, and run @samp{aclocal -I m4
3764 --install}.  @command{aclocal} will notice that
3765
3766 @itemize @bullet
3767 @item
3768 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3769 @item
3770 No local macros define @code{AX_THIRD_PARTY}
3771 @item
3772 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3773 with serial 1.
3774 @end itemize
3775
3776 @noindent
3777 Because @file{/usr/share/aclocal/thirdparty.m4} is a system-wide macro
3778 and @command{aclocal} was given the @option{--install} option, it will
3779 copy this file in @file{m4/thirdparty.m4}, and output an
3780 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3781
3782 The next time @samp{aclocal -I m4 --install} is run (either via
3783 @command{autoreconf}, by hand, or from the @file{Makefile} rebuild
3784 rules) something different happens.  @command{aclocal} notices that
3785
3786 @itemize @bullet
3787 @item
3788 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3789 @item
3790 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3791 with serial 1.
3792 @item
3793 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3794 with serial 1.
3795 @end itemize
3796
3797 @noindent
3798 Because both files have the same serial number, @command{aclocal} uses
3799 the first it found in its search path order (@pxref{Macro Search
3800 Path}).  @command{aclocal} therefore ignores
3801 @file{/usr/share/aclocal/thirdparty.m4} and outputs an
3802 @file{aclocal.m4} that contains @samp{m4_include([m4/thirdparty.m4])}.
3803
3804 Local directories specified with @option{-I} are always searched before
3805 system-wide directories, so a local file will always be preferred to
3806 the system-wide file in case of equal serial numbers.
3807
3808 Now suppose the system-wide third-party macro is changed.  This can
3809 happen if the package installing this macro is updated.  Let's suppose
3810 the new macro has serial number 2.  The next time @samp{aclocal -I m4
3811 --install} is run the situation is the following:
3812
3813 @itemize @bullet
3814 @item
3815 @file{configure.ac} uses @code{AX_THIRD_PARTY}
3816 @item
3817 @file{m4/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3818 with serial 1.
3819 @item
3820 @file{/usr/share/aclocal/thirdparty.m4} defines @code{AX_THIRD_PARTY}
3821 with serial 2.
3822 @end itemize
3823
3824 @noindent
3825 When @command{aclocal} sees a greater serial number, it immediately
3826 forgets anything it knows from files that have the same basename and a
3827 smaller serial number.  So after it has found
3828 @file{/usr/share/aclocal/thirdparty.m4} with serial 2,
3829 @command{aclocal} will proceed as if it had never seen
3830 @file{m4/thirdparty.m4}.  This brings us back to a situation similar
3831 to that at the beginning of our example, where no local file defined
3832 the macro.  @command{aclocal} will install the new version of the
3833 macro in @file{m4/thirdparty.m4}, in this case overriding the old
3834 version.  MyPackage just had its macro updated as a side effect of
3835 running @command{aclocal}.
3836
3837 If you are leery of letting @command{aclocal} update your local macro,
3838 you can run @samp{aclocal -I m4 --diff} to review the changes
3839 @samp{aclocal -I m4 --install} would perform on these macros.
3840
3841 Finally, note that the @option{--force} option of @command{aclocal} has
3842 absolutely no effect on the files installed by @option{--install}.  For
3843 instance, if you have modified your local macros, do not expect
3844 @option{--install --force} to replace the local macros by their
3845 system-wide versions.  If you want to do so, simply erase the local
3846 macros you want to revert, and run @samp{aclocal -I m4 --install}.
3847
3848
3849 @node Future of aclocal
3850 @subsection The Future of @command{aclocal}
3851 @cindex @command{aclocal}'s scheduled death
3852
3853 @command{aclocal} is expected to disappear.  This feature really
3854 should not be offered by Automake.  Automake should focus on
3855 generating @file{Makefile}s; dealing with M4 macros really is
3856 Autoconf's job.  The fact that some people install Automake just to use
3857 @command{aclocal}, but do not use @command{automake} otherwise is an
3858 indication of how that feature is misplaced.
3859
3860 The new implementation will probably be done slightly differently.
3861 For instance, it could enforce the @file{m4/}-style layout discussed in
3862 @ref{Local Macros}.
3863
3864 We have no idea when and how this will happen.  This has been
3865 discussed several times in the past, but someone still has to commit
3866 to that non-trivial task.
3867
3868 From the user point of view, @command{aclocal}'s removal might turn
3869 out to be painful.  There is a simple precaution that you may take to
3870 make that switch more seamless: never call @command{aclocal} yourself.
3871 Keep this guy under the exclusive control of @command{autoreconf} and
3872 Automake's rebuild rules.  Hopefully you won't need to worry about
3873 things breaking, when @command{aclocal} disappears, because everything
3874 will have been taken care of.  If otherwise you used to call
3875 @command{aclocal} directly yourself or from some script, you will
3876 quickly notice the change.
3877
3878 Many packages come with a script called @file{bootstrap.sh} or
3879 @file{autogen.sh}, that will just call @command{aclocal},
3880 @command{libtoolize}, @command{gettextize} or @command{autopoint},
3881 @command{autoconf}, @command{autoheader}, and @command{automake} in
3882 the right order.  Actually this is precisely what @command{autoreconf}
3883 can do for you.  If your package has such a @file{bootstrap.sh} or
3884 @file{autogen.sh} script, consider using @command{autoreconf}.  That
3885 should simplify its logic a lot (less things to maintain, yum!), it's
3886 even likely you will not need the script anymore, and more to the point
3887 you will not call @command{aclocal} directly anymore.
3888
3889 For the time being, third-party packages should continue to install
3890 public macros into @file{/usr/share/aclocal/}.  If @command{aclocal}
3891 is replaced by another tool it might make sense to rename the
3892 directory, but supporting @file{/usr/share/aclocal/} for backward
3893 compatibility should be really easy provided all macros are properly
3894 written (@pxref{Extending aclocal}).
3895
3896
3897
3898 @node Macros
3899 @section Autoconf macros supplied with Automake
3900
3901 Automake ships with several Autoconf macros that you can use from your
3902 @file{configure.ac}.  When you use one of them it will be included by
3903 @command{aclocal} in @file{aclocal.m4}.
3904
3905 @menu
3906 * Public Macros::               Macros that you can use.
3907 * Private Macros::              Macros that you should not use.
3908 @end menu
3909
3910 @c consider generating the following subsections automatically from m4 files.
3911
3912 @node Public Macros
3913 @subsection Public Macros
3914
3915 @table @code
3916
3917 @item AM_INIT_AUTOMAKE([OPTIONS])
3918 @acindex AM_INIT_AUTOMAKE
3919 Runs many macros required for proper operation of the generated Makefiles.
3920
3921 @vindex AUTOMAKE_OPTIONS
3922 @code{AM_INIT_AUTOMAKE} is called with a single argument: a space-separated
3923 list of Automake options that should be applied to every @file{Makefile.am}
3924 in the tree.  The effect is as if each option were listed in
3925 @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
3926
3927 @c FIXME: Remove this "modernization advice" in Automake 1.14 (and adjust
3928 @c FIXME: the error message in m4/init.m4:AM_INIT_AUTOMAKE accordingly).
3929
3930 @acindex AC_INIT
3931 This macro could once (before Automake 1.13) also be called in the
3932 @emph{now obsolete and completely unsupported} form
3933 @code{AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])}.  In this form,
3934 there were two required arguments: the package and the version number.
3935
3936 @anchor{Modernize AM_INIT_AUTOMAKE invocation}
3937 If your @file{configure.ac} has:
3938
3939 @example
3940 AC_INIT([src/foo.c])
3941 AM_INIT_AUTOMAKE([mumble], [1.5])
3942 @end example
3943
3944 @noindent
3945 you must modernize it as follows in order to make it work with Automake
3946 1.13 or later:
3947
3948 @example
3949 AC_INIT([mumble], [1.5])
3950 AC_CONFIG_SRCDIR([src/foo.c])
3951 AM_INIT_AUTOMAKE
3952 @end example
3953
3954 Note that if you're upgrading your @file{configure.ac} from an earlier
3955 version of Automake, it is not always correct to simply move the
3956 package and version arguments from @code{AM_INIT_AUTOMAKE} directly to
3957 @code{AC_INIT}, as in the example above.  The first argument to
3958 @code{AC_INIT} should be the name of your package (e.g., @samp{GNU
3959 Automake}), not the tarball name (e.g., @samp{automake}) that you used
3960 to pass to @code{AM_INIT_AUTOMAKE}.  Autoconf tries to derive a
3961 tarball name from the package name, which should work for most but not
3962 all package names.  (If it doesn't work for yours, you can use the
3963 four-argument form of @code{AC_INIT} to provide the tarball name
3964 explicitly).
3965
3966 @cindex @code{PACKAGE}, prevent definition
3967 @cindex @code{VERSION}, prevent definition
3968 @opindex no-define
3969 By default this macro @code{AC_DEFINE}'s @code{PACKAGE} and
3970 @code{VERSION}.  This can be avoided by passing the @option{no-define}
3971 option:
3972 @example
3973 AM_INIT_AUTOMAKE([gnits 1.5 no-define dist-bzip2])
3974 @end example
3975
3976 @item AM_PATH_LISPDIR
3977 @acindex AM_PATH_LISPDIR
3978 @vindex EMACS
3979 @vindex lispdir
3980 Searches for the program @command{emacs}, and, if found, sets the
3981 output variable @code{lispdir} to the full path to Emacs' site-lisp
3982 directory.
3983
3984 Note that this test assumes the @command{emacs} found to be a version
3985 that supports Emacs Lisp (such as GNU Emacs or XEmacs).  Other
3986 emacsen can cause this test to hang (some, like old versions of
3987 MicroEmacs, start up in interactive mode, requiring @kbd{C-x C-c} to
3988 exit, which is hardly obvious for a non-emacs user).  In most cases,
3989 however, you should be able to use @kbd{C-c} to kill the test.  In
3990 order to avoid problems, you can set @env{EMACS} to ``no'' in the
3991 environment, or use the @option{--with-lispdir} option to
3992 @command{configure} to explicitly set the correct path (if you're sure
3993 you have an @command{emacs} that supports Emacs Lisp).
3994
3995 @item AM_PROG_AR(@ovar{act-if-fail})
3996 @acindex AM_PROG_AR
3997 @vindex AR
3998 You must use this macro when you use the archiver in your project, if
3999 you want support for unusual archivers such as Microsoft @command{lib}.
4000 The content of the optional argument is executed if the archiver
4001 interface is not recognized; the default action is to abort configure
4002 with an error message.
4003
4004 @item AM_PROG_AS
4005 @acindex AM_PROG_AS
4006 @vindex CCAS
4007 @vindex CCASFLAGS
4008 Use this macro when you have assembly code in your project.  This will
4009 choose the assembler for you (by default the C compiler) and set
4010 @code{CCAS}, and will also set @code{CCASFLAGS} if required.
4011
4012 @item AM_PROG_CC_C_O
4013 @acindex AM_PROG_CC_C_O
4014 @acindex AC_PROG_CC_C_O
4015 This is like @code{AC_PROG_CC_C_O}, but it generates its results in
4016 the manner required by Automake.  You must use this instead of
4017 @code{AC_PROG_CC_C_O} when you need this functionality, that is, when
4018 using per-target flags or subdir-objects with C sources.
4019
4020 @item AM_PROG_LEX
4021 @acindex AM_PROG_LEX
4022 @acindex AC_PROG_LEX
4023 @cindex HP-UX 10, @command{lex} problems
4024 @cindex @command{lex} problems with HP-UX 10
4025 Like @code{AC_PROG_LEX} (@pxref{Particular Programs, , Particular
4026 Program Checks, autoconf, The Autoconf Manual}), but uses the
4027 @command{missing} script on systems that do not have @command{lex}.
4028 HP-UX 10 is one such system.
4029
4030 @item AM_PROG_GCJ
4031 @acindex AM_PROG_GCJ
4032 @vindex GCJ
4033 @vindex GCJFLAGS
4034 This macro finds the @command{gcj} program or causes an error.  It sets
4035 @code{GCJ} and @code{GCJFLAGS}.  @command{gcj} is the Java front-end to the
4036 GNU Compiler Collection.
4037
4038 @item AM_PROG_UPC([@var{compiler-search-list}])
4039 @acindex AM_PROG_UPC
4040 @vindex UPC
4041 Find a compiler for Unified Parallel C and define the @code{UPC}
4042 variable.  The default @var{compiler-search-list} is @samp{upcc upc}.
4043 This macro will abort @command{configure} if no Unified Parallel C
4044 compiler is found.
4045
4046 @item AM_MISSING_PROG(@var{name}, @var{program})
4047 @acindex AM_MISSING_PROG
4048 @vindex MISSING
4049 Find a maintainer tool @var{program} and define the @var{name}
4050 environment variable with its location.  If @var{program} is not
4051 detected, then @var{name} will instead invoke the @command{missing}
4052 script, in order to give useful advice to the user about the missing
4053 maintainer tool.  @xref{maintainer-mode}, for more information on when
4054 the @command{missing} script is appropriate.
4055
4056 @item AM_SILENT_RULES
4057 @acindex AM_SILENT_RULES
4058 Control the machinery for less verbose build output
4059 (@pxref{Automake Silent Rules}).
4060
4061 @item AM_WITH_DMALLOC
4062 @acindex AM_WITH_DMALLOC
4063 @cindex @command{dmalloc}, support for
4064 @vindex WITH_DMALLOC
4065 @opindex --with-dmalloc
4066 Add support for the @uref{http://dmalloc.com/, Dmalloc package}.  If
4067 the user runs @command{configure} with @option{--with-dmalloc}, then
4068 define @code{WITH_DMALLOC} and add @option{-ldmalloc} to @code{LIBS}.
4069
4070 @end table
4071
4072
4073 @node Private Macros
4074 @subsection Private Macros
4075
4076 The following macros are private macros you should not call directly.
4077 They are called by the other public macros when appropriate.  Do not
4078 rely on them, as they might be changed in a future version.  Consider
4079 them as implementation details; or better, do not consider them at all:
4080 skip this section!
4081
4082 @ftable @code
4083 @item _AM_DEPENDENCIES
4084 @itemx AM_SET_DEPDIR
4085 @itemx AM_DEP_TRACK
4086 @itemx AM_OUTPUT_DEPENDENCY_COMMANDS
4087 These macros are used to implement Automake's automatic dependency
4088 tracking scheme.  They are called automatically by Automake when
4089 required, and there should be no need to invoke them manually.
4090
4091 @item AM_MAKE_INCLUDE
4092 This macro is used to discover how the user's @command{make} handles
4093 @code{include} statements.  This macro is automatically invoked when
4094 needed; there should be no need to invoke it manually.
4095
4096 @item AM_PROG_INSTALL_STRIP
4097 This is used to find a version of @code{install} that can be used to
4098 strip a program at installation time.  This macro is automatically
4099 included when required.
4100
4101 @item AM_SANITY_CHECK
4102 This checks to make sure that a file created in the build directory is
4103 newer than a file in the source directory.  This can fail on systems
4104 where the clock is set incorrectly.  This macro is automatically run
4105 from @code{AM_INIT_AUTOMAKE}.
4106
4107 @end ftable
4108
4109
4110 @node Directories
4111 @chapter Directories
4112
4113 For simple projects that distribute all files in the same directory
4114 it is enough to have a single @file{Makefile.am} that builds
4115 everything in place.
4116
4117 In larger projects, it is common to organize files in different
4118 directories, in a tree.  For example, there could be a directory
4119 for the program's source, one for the testsuite, and one for the
4120 documentation; or, for very large projects, there could be one
4121 directory per program, per library or per module.
4122
4123 The traditional approach is to build these subdirectories recursively,
4124 employing @emph{make recursion}: each directory contains its
4125 own @file{Makefile}, and when @command{make} is run from the top-level
4126 directory, it enters each subdirectory in turn, and invokes there a
4127 new @command{make} instance to build the directory's contents.
4128
4129 Because this approach is very widespread, Automake offers built-in
4130 support for it.  However, it is worth nothing that the use of make
4131 recursion has its own serious issues and drawbacks, and that it's
4132 well possible to have packages with a multi directory layout that
4133 make little or no use of such recursion (examples of such packages
4134 are GNU Bison and GNU Automake itself); see also the @ref{Alternative}
4135 section below.
4136
4137 @menu
4138 * Subdirectories::              Building subdirectories recursively
4139 * Conditional Subdirectories::  Conditionally not building directories
4140 * Alternative::                 Subdirectories without recursion
4141 * Subpackages::                 Nesting packages
4142 @end menu
4143
4144 @node Subdirectories
4145 @section Recursing subdirectories
4146
4147 @cindex @code{SUBDIRS}, explained
4148
4149 In packages using make recursion, the top level @file{Makefile.am} must
4150 tell Automake which subdirectories are to be built.  This is done via
4151 the @code{SUBDIRS} variable.
4152 @vindex SUBDIRS
4153
4154 The @code{SUBDIRS} variable holds a list of subdirectories in which
4155 building of various sorts can occur.  The rules for many targets
4156 (e.g., @code{all}) in the generated @file{Makefile} will run commands
4157 both locally and in all specified subdirectories.  Note that the
4158 directories listed in @code{SUBDIRS} are not required to contain
4159 @file{Makefile.am}s; only @file{Makefile}s (after configuration).
4160 This allows inclusion of libraries from packages that do not use
4161 Automake (such as @code{gettext}; see also @ref{Third-Party
4162 Makefiles}).
4163
4164 In packages that use subdirectories, the top-level @file{Makefile.am} is
4165 often very short.  For instance, here is the @file{Makefile.am} from the
4166 GNU Hello distribution:
4167
4168 @example
4169 EXTRA_DIST = BUGS ChangeLog.O README-alpha
4170 SUBDIRS = doc intl po src tests
4171 @end example
4172
4173 When Automake invokes @command{make} in a subdirectory, it uses the value
4174 of the @code{MAKE} variable.  It passes the value of the variable
4175 @code{AM_MAKEFLAGS} to the @command{make} invocation; this can be set in
4176 @file{Makefile.am} if there are flags you must always pass to
4177 @command{make}.
4178 @vindex MAKE
4179 @vindex AM_MAKEFLAGS
4180
4181 The directories mentioned in @code{SUBDIRS} are usually direct
4182 children of the current directory, each subdirectory containing its
4183 own @file{Makefile.am} with a @code{SUBDIRS} pointing to deeper
4184 subdirectories.  Automake can be used to construct packages of
4185 arbitrary depth this way.
4186
4187 By default, Automake generates @file{Makefiles} that work depth-first
4188 in postfix order: the subdirectories are built before the current
4189 directory.  However, it is possible to change this ordering.  You can
4190 do this by putting @samp{.} into @code{SUBDIRS}.  For instance,
4191 putting @samp{.} first will cause a prefix ordering of
4192 directories.
4193
4194 Using
4195
4196 @example
4197 SUBDIRS = lib src . test
4198 @end example
4199
4200 @noindent
4201 will cause @file{lib/} to be built before @file{src/}, then the
4202 current directory will be built, finally the @file{test/} directory
4203 will be built.  It is customary to arrange test directories to be
4204 built after everything else since they are meant to test what has
4205 been constructed.
4206
4207 @node Conditional Subdirectories
4208 @section Conditional Subdirectories
4209 @cindex Subdirectories, building conditionally
4210 @cindex Conditional subdirectories
4211 @cindex @code{SUBDIRS}, conditional
4212 @cindex Conditional @code{SUBDIRS}
4213
4214 It is possible to define the @code{SUBDIRS} variable conditionally if,
4215 like in the case of GNU Inetutils, you want to only build a subset of
4216 the entire package.
4217
4218 To illustrate how this works, let's assume we have two directories
4219 @file{src/} and @file{opt/}.  @file{src/} should always be built, but we
4220 want to decide in @command{configure} whether @file{opt/} will be built
4221 or not.  (For this example we will assume that @file{opt/} should be
4222 built when the variable @samp{$want_opt} was set to @samp{yes}.)
4223
4224 Running @command{make} should thus recurse into @file{src/} always, and
4225 then maybe in @file{opt/}.
4226
4227 However @samp{make dist} should always recurse into both @file{src/}
4228 and @file{opt/}.  Because @file{opt/} should be distributed even if it
4229 is not needed in the current configuration.  This means
4230 @file{opt/Makefile} should be created @emph{unconditionally}.
4231
4232 There are two ways to setup a project like this.  You can use Automake
4233 conditionals (@pxref{Conditionals}) or use Autoconf @code{AC_SUBST}
4234 variables (@pxref{Setting Output Variables, , Setting Output
4235 Variables, autoconf, The Autoconf Manual}).  Using Automake
4236 conditionals is the preferred solution.  Before we illustrate these
4237 two possibilities, let's introduce @code{DIST_SUBDIRS}.
4238
4239 @menu
4240 * SUBDIRS vs DIST_SUBDIRS::     Two sets of directories
4241 * Subdirectories with AM_CONDITIONAL::  Specifying conditional subdirectories
4242 * Subdirectories with AC_SUBST::  Another way for conditional recursion
4243 * Unconfigured Subdirectories::  Not even creating a @samp{Makefile}
4244 @end menu
4245
4246 @node SUBDIRS vs DIST_SUBDIRS
4247 @subsection @code{SUBDIRS} vs.@: @code{DIST_SUBDIRS}
4248 @cindex @code{DIST_SUBDIRS}, explained
4249
4250 Automake considers two sets of directories, defined by the variables
4251 @code{SUBDIRS} and @code{DIST_SUBDIRS}.
4252
4253 @code{SUBDIRS} contains the subdirectories of the current directory
4254 that must be built (@pxref{Subdirectories}).  It must be defined
4255 manually; Automake will never guess a directory is to be built.  As we
4256 will see in the next two sections, it is possible to define it
4257 conditionally so that some directory will be omitted from the build.
4258
4259 @code{DIST_SUBDIRS} is used in rules that need to recurse in all
4260 directories, even those that have been conditionally left out of the
4261 build.  Recall our example where we may not want to build subdirectory
4262 @file{opt/}, but yet we want to distribute it?  This is where
4263 @code{DIST_SUBDIRS} comes into play: @samp{opt} may not appear in
4264 @code{SUBDIRS}, but it must appear in @code{DIST_SUBDIRS}.
4265
4266 Precisely, @code{DIST_SUBDIRS} is used by @samp{make
4267 maintainer-clean}, @samp{make distclean} and @samp{make dist}.  All
4268 other recursive rules use @code{SUBDIRS}.
4269
4270 If @code{SUBDIRS} is defined conditionally using Automake
4271 conditionals, Automake will define @code{DIST_SUBDIRS} automatically
4272 from the possible values of @code{SUBDIRS} in all conditions.
4273
4274 If @code{SUBDIRS} contains @code{AC_SUBST} variables,
4275 @code{DIST_SUBDIRS} will not be defined correctly because Automake
4276 does not know the possible values of these variables.  In this case
4277 @code{DIST_SUBDIRS} needs to be defined manually.
4278
4279 @node Subdirectories with AM_CONDITIONAL
4280 @subsection Subdirectories with @code{AM_CONDITIONAL}
4281 @cindex @code{SUBDIRS} and @code{AM_CONDITIONAL}
4282 @cindex @code{AM_CONDITIONAL} and @code{SUBDIRS}
4283
4284 @c Keep in sync with subdir-am-cond.sh
4285
4286 @file{configure} should output the @file{Makefile} for each directory
4287 and define a condition into which @file{opt/} should be built.
4288
4289 @example
4290 @dots{}
4291 AM_CONDITIONAL([COND_OPT], [test "$want_opt" = yes])
4292 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4293 @dots{}
4294 @end example
4295
4296 Then @code{SUBDIRS} can be defined in the top-level @file{Makefile.am}
4297 as follows.
4298
4299 @example
4300 if COND_OPT
4301   MAYBE_OPT = opt
4302 endif
4303 SUBDIRS = src $(MAYBE_OPT)
4304 @end example
4305
4306 As you can see, running @command{make} will rightly recurse into
4307 @file{src/} and maybe @file{opt/}.
4308
4309 @vindex DIST_SUBDIRS
4310 As you can't see, running @samp{make dist} will recurse into both
4311 @file{src/} and @file{opt/} directories because @samp{make dist}, unlike
4312 @samp{make all}, doesn't use the @code{SUBDIRS} variable.  It uses the
4313 @code{DIST_SUBDIRS} variable.
4314
4315 In this case Automake will define @samp{DIST_SUBDIRS = src opt}
4316 automatically because it knows that @code{MAYBE_OPT} can contain
4317 @samp{opt} in some condition.
4318
4319 @node Subdirectories with AC_SUBST
4320 @subsection Subdirectories with @code{AC_SUBST}
4321 @cindex @code{SUBDIRS} and @code{AC_SUBST}
4322 @cindex @code{AC_SUBST} and @code{SUBDIRS}
4323
4324 @c Keep in sync with subdir-ac-subst.sh
4325
4326 Another possibility is to define @code{MAYBE_OPT} from
4327 @file{./configure} using @code{AC_SUBST}:
4328
4329 @example
4330 @dots{}
4331 if test "$want_opt" = yes; then
4332   MAYBE_OPT=opt
4333 else
4334   MAYBE_OPT=
4335 fi
4336 AC_SUBST([MAYBE_OPT])
4337 AC_CONFIG_FILES([Makefile src/Makefile opt/Makefile])
4338 @dots{}
4339 @end example
4340
4341 In this case the top-level @file{Makefile.am} should look as follows.
4342
4343 @example
4344 SUBDIRS = src $(MAYBE_OPT)
4345 DIST_SUBDIRS = src opt
4346 @end example
4347
4348 The drawback is that since Automake cannot guess what the possible
4349 values of @code{MAYBE_OPT} are, it is necessary to define
4350 @code{DIST_SUBDIRS}.
4351
4352 @node Unconfigured Subdirectories
4353 @subsection Unconfigured Subdirectories
4354 @cindex Subdirectories, configured conditionally
4355
4356 The semantics of @code{DIST_SUBDIRS} are often misunderstood by some
4357 users that try to @emph{configure and build} subdirectories
4358 conditionally.  Here by configuring we mean creating the
4359 @file{Makefile} (it might also involve running a nested
4360 @command{configure} script: this is a costly operation that explains
4361 why people want to do it conditionally, but only the @file{Makefile}
4362 is relevant to the discussion).
4363
4364 The above examples all assume that every @file{Makefile} is created,
4365 even in directories that are not going to be built.  The simple reason
4366 is that we want @samp{make dist} to distribute even the directories
4367 that are not being built (e.g., platform-dependent code), hence
4368 @file{make dist} must recurse into the subdirectory, hence this
4369 directory must be configured and appear in @code{DIST_SUBDIRS}.
4370
4371 Building packages that do not configure every subdirectory is a tricky
4372 business, and we do not recommend it to the novice as it is easy to
4373 produce an incomplete tarball by mistake.  We will not discuss this
4374 topic in depth here, yet for the adventurous here are a few rules to
4375 remember.
4376
4377 @cartouche
4378 @itemize
4379 @item @code{SUBDIRS} should always be a subset of @code{DIST_SUBDIRS}.
4380
4381 It makes little sense to have a directory in @code{SUBDIRS} that
4382 is not in @code{DIST_SUBDIRS}.  Think of the former as a way to tell
4383 which directories listed in the latter should be built.
4384 @item Any directory listed in @code{DIST_SUBDIRS} and @code{SUBDIRS}
4385 must be configured.
4386
4387 I.e., the @file{Makefile} must exists or the recursive @command{make}
4388 rules will not be able to process the directory.
4389 @item Any configured directory must be listed in @code{DIST_SUBDIRS}.
4390
4391 So that the cleaning rules remove the generated @file{Makefile}s.
4392 It would be correct to see @code{DIST_SUBDIRS} as a variable that
4393 lists all the directories that have been configured.
4394 @end itemize
4395 @end cartouche
4396
4397 In order to prevent recursion in some unconfigured directory you
4398 must therefore ensure that this directory does not appear in
4399 @code{DIST_SUBDIRS} (and @code{SUBDIRS}).  For instance, if you define
4400 @code{SUBDIRS} conditionally using @code{AC_SUBST} and do not define
4401 @code{DIST_SUBDIRS} explicitly, it will be default to
4402 @samp{$(SUBDIRS)}; another possibility is to force @code{DIST_SUBDIRS
4403 = $(SUBDIRS)}.
4404
4405 Of course, directories that are omitted from @code{DIST_SUBDIRS} will
4406 not be distributed unless you make other arrangements for this to
4407 happen (for instance, always running @samp{make dist} in a
4408 configuration where all directories are known to appear in
4409 @code{DIST_SUBDIRS}; or writing a @code{dist-hook} target to
4410 distribute these directories).
4411
4412 @cindex Subdirectories, not distributed
4413 In few packages, unconfigured directories are not even expected to
4414 be distributed.  Although these packages do not require the
4415 aforementioned extra arrangements, there is another pitfall.  If the
4416 name of a directory appears in @code{SUBDIRS} or @code{DIST_SUBDIRS},
4417 @command{automake} will make sure the directory exists.  Consequently
4418 @command{automake} cannot be run on such a distribution when one
4419 directory has been omitted.  One way to avoid this check is to use the
4420 @code{AC_SUBST} method to declare conditional directories; since
4421 @command{automake} does not know the values of @code{AC_SUBST}
4422 variables it cannot ensure the corresponding directory exists.
4423
4424 @node Alternative
4425 @section An Alternative Approach to Subdirectories
4426
4427 If you've ever read Peter Miller's excellent paper,
4428 @uref{http://miller.emu.id.au/pmiller/books/rmch/,
4429 Recursive Make Considered Harmful}, the preceding sections on the use of
4430 make recursion will probably come as unwelcome advice.  For those who
4431 haven't read the paper, Miller's main thesis is that recursive
4432 @command{make} invocations are both slow and error-prone.
4433
4434 Automake provides sufficient cross-directory support @footnote{We
4435 believe.  This work is new and there are probably warts.
4436 @xref{Introduction}, for information on reporting bugs.} to enable you
4437 to write a single @file{Makefile.am} for a complex multi-directory
4438 package.
4439
4440 By default an installable file specified in a subdirectory will have its
4441 directory name stripped before installation.  For instance, in this
4442 example, the header file will be installed as
4443 @file{$(includedir)/stdio.h}:
4444
4445 @example
4446 include_HEADERS = inc/stdio.h
4447 @end example
4448
4449 @vindex nobase_
4450 @cindex @code{nobase_} prefix
4451 @cindex Path stripping, avoiding
4452 @cindex Avoiding path stripping
4453
4454 However, the @samp{nobase_} prefix can be used to circumvent this path
4455 stripping.  In this example, the header file will be installed as
4456 @file{$(includedir)/sys/types.h}:
4457
4458 @example
4459 nobase_include_HEADERS = sys/types.h
4460 @end example
4461
4462 @cindex @code{nobase_} and @code{dist_} or @code{nodist_}
4463 @cindex @code{dist_} and @code{nobase_}
4464 @cindex @code{nodist_} and @code{nobase_}
4465 @vindex dist_
4466 @vindex nodist_
4467
4468 @samp{nobase_} should be specified first when used in conjunction with
4469 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
4470 Control}).  For instance:
4471
4472 @example
4473 nobase_dist_pkgdata_DATA = images/vortex.pgm sounds/whirl.ogg
4474 @end example
4475
4476 Finally, note that a variable using the @samp{nobase_} prefix can
4477 often be replaced by several variables, one for each destination
4478 directory (@pxref{Uniform}).  For instance, the last example could be
4479 rewritten as follows:
4480
4481 @c Keep in sync with primary-prefix-couples-documented-valid.sh
4482 @example
4483 imagesdir = $(pkgdatadir)/images
4484 soundsdir = $(pkgdatadir)/sounds
4485 dist_images_DATA = images/vortex.pgm
4486 dist_sounds_DATA = sounds/whirl.ogg
4487 @end example
4488
4489 @noindent
4490 This latter syntax makes it possible to change one destination
4491 directory without changing the layout of the source tree.
4492
4493 Currently, @samp{nobase_*_LTLIBRARIES} are the only exception to this
4494 rule, in that there is no particular installation order guarantee for
4495 an otherwise equivalent set of variables without @samp{nobase_} prefix.
4496
4497 @node Subpackages
4498 @section Nesting Packages
4499 @cindex Nesting packages
4500 @cindex Subpackages
4501 @acindex AC_CONFIG_SUBDIRS
4502 @acindex AC_CONFIG_AUX_DIR
4503
4504
4505 In the GNU Build System, packages can be nested to arbitrary depth.
4506 This means that a package can embed other packages with their own
4507 @file{configure}, @file{Makefile}s, etc.
4508
4509 These other packages should just appear as subdirectories of their
4510 parent package.  They must be listed in @code{SUBDIRS} like other
4511 ordinary directories.  However the subpackage's @file{Makefile}s
4512 should be output by its own @file{configure} script, not by the
4513 parent's @file{configure}.  This is achieved using the
4514 @code{AC_CONFIG_SUBDIRS} Autoconf macro (@pxref{Subdirectories,
4515 AC_CONFIG_SUBDIRS, Configuring Other Packages in Subdirectories,
4516 autoconf, The Autoconf Manual}).
4517
4518 Here is an example package for an @code{arm} program that links with
4519 a @code{hand} library that is a nested package in subdirectory
4520 @file{hand/}.
4521
4522 @code{arm}'s @file{configure.ac}:
4523
4524 @example
4525 AC_INIT([arm], [1.0])
4526 AC_CONFIG_AUX_DIR([.])
4527 AM_INIT_AUTOMAKE
4528 AC_PROG_CC
4529 AC_CONFIG_FILES([Makefile])
4530 # Call hand's ./configure script recursively.
4531 AC_CONFIG_SUBDIRS([hand])
4532 AC_OUTPUT
4533 @end example
4534
4535 @code{arm}'s @file{Makefile.am}:
4536
4537 @example
4538 # Build the library in the hand subdirectory first.
4539 SUBDIRS = hand
4540
4541 # Include hand's header when compiling this directory.
4542 AM_CPPFLAGS = -I$(srcdir)/hand
4543
4544 bin_PROGRAMS = arm
4545 arm_SOURCES = arm.c
4546 # link with the hand library.
4547 arm_LDADD = hand/libhand.a
4548 @end example
4549
4550 Now here is @code{hand}'s @file{hand/configure.ac}:
4551
4552 @example
4553 AC_INIT([hand], [1.2])
4554 AC_CONFIG_AUX_DIR([.])
4555 AM_INIT_AUTOMAKE
4556 AC_PROG_CC
4557 AM_PROG_AR
4558 AC_PROG_RANLIB
4559 AC_CONFIG_FILES([Makefile])
4560 AC_OUTPUT
4561 @end example
4562
4563 @noindent
4564 and its @file{hand/Makefile.am}:
4565
4566 @example
4567 lib_LIBRARIES = libhand.a
4568 libhand_a_SOURCES = hand.c
4569 @end example
4570
4571 When @samp{make dist} is run from the top-level directory it will
4572 create an archive @file{arm-1.0.tar.gz} that contains the @code{arm}
4573 code as well as the @file{hand} subdirectory.  This package can be
4574 built and installed like any ordinary package, with the usual
4575 @samp{./configure && make && make install} sequence (the @code{hand}
4576 subpackage will be built and installed by the process).
4577
4578 When @samp{make dist} is run from the hand directory, it will create a
4579 self-contained @file{hand-1.2.tar.gz} archive.  So although it appears
4580 to be embedded in another package, it can still be used separately.
4581
4582 The purpose of the @samp{AC_CONFIG_AUX_DIR([.])} instruction is to
4583 force Automake and Autoconf to search for auxiliary scripts in the
4584 current directory.  For instance, this means that there will be two
4585 copies of @file{install-sh}: one in the top-level of the @code{arm}
4586 package, and another one in the @file{hand/} subdirectory for the
4587 @code{hand} package.
4588
4589 The historical default is to search for these auxiliary scripts in
4590 the parent directory and the grandparent directory.  So if the
4591 @samp{AC_CONFIG_AUX_DIR([.])} line was removed from
4592 @file{hand/configure.ac}, that subpackage would share the auxiliary
4593 script of the @code{arm} package.  This may looks like a gain in size
4594 (a few kilobytes), but it is actually a loss of modularity as the
4595 @code{hand} subpackage is no longer self-contained (@samp{make dist}
4596 in the subdirectory will not work anymore).
4597
4598 Packages that do not use Automake need more work to be integrated this
4599 way.  @xref{Third-Party Makefiles}.
4600
4601 @node Programs
4602 @chapter Building Programs and Libraries
4603
4604 A large part of Automake's functionality is dedicated to making it easy
4605 to build programs and libraries.
4606
4607 @menu
4608 * A Program::                   Building a program
4609 * A Library::                   Building a library
4610 * A Shared Library::            Building a Libtool library
4611 * Program and Library Variables::  Variables controlling program and
4612                                 library builds
4613 * Default _SOURCES::            Default source files
4614 * LIBOBJS::                     Special handling for LIBOBJS and ALLOCA
4615 * Program Variables::           Variables used when building a program
4616 * Yacc and Lex::                Yacc and Lex support
4617 * C++ Support::                 Compiling C++ sources
4618 * Objective C Support::         Compiling Objective C sources
4619 * Objective C++ Support::       Compiling Objective C++ sources
4620 * Unified Parallel C Support::  Compiling Unified Parallel C sources
4621 * Assembly Support::            Compiling assembly sources
4622 * Fortran 77 Support::          Compiling Fortran 77 sources
4623 * Fortran 9x Support::          Compiling Fortran 9x sources
4624 * Java Support with gcj::       Compiling Java sources using gcj
4625 * Vala Support::                Compiling Vala sources
4626 * Support for Other Languages::  Compiling other languages
4627 * Dependencies::                Automatic dependency tracking
4628 * EXEEXT::                      Support for executable extensions
4629 @end menu
4630
4631
4632 @node A Program
4633 @section Building a program
4634
4635 In order to build a program, you need to tell Automake which sources
4636 are part of it, and which libraries it should be linked with.
4637
4638 This section also covers conditional compilation of sources or
4639 programs.  Most of the comments about these also apply to libraries
4640 (@pxref{A Library}) and libtool libraries (@pxref{A Shared Library}).
4641
4642 @menu
4643 * Program Sources::             Defining program sources
4644 * Linking::                     Linking with libraries or extra objects
4645 * Conditional Sources::         Handling conditional sources
4646 * Conditional Programs::        Building a program conditionally
4647 @end menu
4648
4649 @node Program Sources
4650 @subsection Defining program sources
4651
4652 @cindex @code{PROGRAMS}, @code{bindir}
4653 @vindex _PROGRAMS
4654 @vindex bin_PROGRAMS
4655 @vindex sbin_PROGRAMS
4656 @vindex libexec_PROGRAMS
4657 @vindex pkglibexec_PROGRAMS
4658 @vindex noinst_PROGRAMS
4659 @vindex check_PROGRAMS
4660
4661 In a directory containing source that gets built into a program (as
4662 opposed to a library or a script), the @code{PROGRAMS} primary is used.
4663 Programs can be installed in @code{bindir}, @code{sbindir},
4664 @code{libexecdir}, @code{pkglibexecdir}, or not at all
4665 (@code{noinst_}).  They can also be built only for @samp{make check}, in
4666 which case the prefix is @samp{check_}.
4667
4668 For instance:
4669
4670 @example
4671 bin_PROGRAMS = hello
4672 @end example
4673
4674 In this simple case, the resulting @file{Makefile.in} will contain code
4675 to generate a program named @code{hello}.
4676
4677 Associated with each program are several assisting variables that are
4678 named after the program.  These variables are all optional, and have
4679 reasonable defaults.  Each variable, its use, and default is spelled out
4680 below; we use the ``hello'' example throughout.
4681
4682 The variable @code{hello_SOURCES} is used to specify which source files
4683 get built into an executable:
4684
4685 @example
4686 hello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h
4687 @end example
4688
4689 This causes each mentioned @file{.c} file to be compiled into the
4690 corresponding @file{.o}.  Then all are linked to produce @file{hello}.
4691
4692 @cindex @code{_SOURCES} primary, defined
4693 @cindex @code{SOURCES} primary, defined
4694 @cindex Primary variable, @code{SOURCES}
4695 @vindex _SOURCES
4696
4697 If @code{hello_SOURCES} is not specified, then it defaults to the single
4698 file @file{hello.c} (@pxref{Default _SOURCES}).
4699 @vindex _SOURCES
4700 @vindex SOURCES
4701
4702 Multiple programs can be built in a single directory.  Multiple programs
4703 can share a single source file, which must be listed in each
4704 @code{_SOURCES} definition.
4705
4706 @cindex Header files in @code{_SOURCES}
4707 @cindex @code{_SOURCES} and header files
4708
4709 Header files listed in a @code{_SOURCES} definition will be included in
4710 the distribution but otherwise ignored.  In case it isn't obvious, you
4711 should not include the header file generated by @file{configure} in a
4712 @code{_SOURCES} variable; this file should not be distributed.  Lex
4713 (@file{.l}) and Yacc (@file{.y}) files can also be listed; see @ref{Yacc
4714 and Lex}.
4715
4716
4717 @node Linking
4718 @subsection Linking the program
4719
4720 If you need to link against libraries that are not found by
4721 @command{configure}, you can use @code{LDADD} to do so.  This variable is
4722 used to specify additional objects or libraries to link with; it is
4723 inappropriate for specifying specific linker flags, you should use
4724 @code{AM_LDFLAGS} for this purpose.
4725 @vindex LDADD
4726 @vindex AM_LDFLAGS
4727
4728 @cindex @code{prog_LDADD}, defined
4729
4730 Sometimes, multiple programs are built in one directory but do not share
4731 the same link-time requirements.  In this case, you can use the
4732 @code{@var{prog}_LDADD} variable (where @var{prog} is the name of the
4733 program as it appears in some @code{_PROGRAMS} variable, and usually
4734 written in lowercase) to override @code{LDADD}.  If this variable exists
4735 for a given program, then that program is not linked using @code{LDADD}.
4736 @vindex maude_LDADD
4737
4738 For instance, in GNU cpio, @code{pax}, @code{cpio} and @code{mt} are
4739 linked against the library @file{libcpio.a}.  However, @code{rmt} is
4740 built in the same directory, and has no such link requirement.  Also,
4741 @code{mt} and @code{rmt} are only built on certain architectures.  Here
4742 is what cpio's @file{src/Makefile.am} looks like (abridged):
4743
4744 @example
4745 bin_PROGRAMS = cpio pax $(MT)
4746 libexec_PROGRAMS = $(RMT)
4747 EXTRA_PROGRAMS = mt rmt
4748
4749 LDADD = ../lib/libcpio.a $(INTLLIBS)
4750 rmt_LDADD =
4751
4752 cpio_SOURCES = @dots{}
4753 pax_SOURCES = @dots{}
4754 mt_SOURCES = @dots{}
4755 rmt_SOURCES = @dots{}
4756 @end example
4757
4758 @cindex @code{_LDFLAGS}, defined
4759 @vindex maude_LDFLAGS
4760 @code{@var{prog}_LDADD} is inappropriate for passing program-specific
4761 linker flags (except for @option{-l}, @option{-L}, @option{-dlopen} and
4762 @option{-dlpreopen}).  So, use the @code{@var{prog}_LDFLAGS} variable for
4763 this purpose.
4764
4765 @cindex @code{_DEPENDENCIES}, defined
4766 @vindex maude_DEPENDENCIES
4767 @vindex EXTRA_maude_DEPENDENCIES
4768 It is also occasionally useful to have a program depend on some other
4769 target that is not actually part of that program.  This can be done
4770 using either the @code{@var{prog}_DEPENDENCIES} or the
4771 @code{EXTRA_@var{prog}_DEPENDENCIES} variable.  Each program depends on
4772 the contents both variables, but no further interpretation is done.
4773
4774 Since these dependencies are associated to the link rule used to
4775 create the programs they should normally list files used by the link
4776 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la}
4777 files.  In rare cases you may need to add other kinds of files such as
4778 linker scripts, but @emph{listing a source file in
4779 @code{_DEPENDENCIES} is wrong}.  If some source file needs to be built
4780 before all the components of a program are built, consider using the
4781 @code{BUILT_SOURCES} variable instead (@pxref{Sources}).
4782
4783 If @code{@var{prog}_DEPENDENCIES} is not supplied, it is computed by
4784 Automake.  The automatically-assigned value is the contents of
4785 @code{@var{prog}_LDADD}, with most configure substitutions, @option{-l},
4786 @option{-L}, @option{-dlopen} and @option{-dlpreopen} options removed.  The
4787 configure substitutions that are left in are only @samp{$(LIBOBJS)} and
4788 @samp{$(ALLOCA)}; these are left because it is known that they will not
4789 cause an invalid value for @code{@var{prog}_DEPENDENCIES} to be
4790 generated.
4791
4792 @ref{Conditional Sources} shows a situation where @code{_DEPENDENCIES}
4793 may be used.
4794
4795 The @code{EXTRA_@var{prog}_DEPENDENCIES} may be useful for cases where
4796 you merely want to augment the @command{automake}-generated
4797 @code{@var{prog}_DEPENDENCIES} rather than replacing it.
4798
4799 @cindex @code{LDADD} and @option{-l}
4800 @cindex @option{-l} and @code{LDADD}
4801 We recommend that you avoid using @option{-l} options in @code{LDADD}
4802 or @code{@var{prog}_LDADD} when referring to libraries built by your
4803 package.  Instead, write the file name of the library explicitly as in
4804 the above @code{cpio} example.  Use @option{-l} only to list
4805 third-party libraries.  If you follow this rule, the default value of
4806 @code{@var{prog}_DEPENDENCIES} will list all your local libraries and
4807 omit the other ones.
4808
4809
4810 @node Conditional Sources
4811 @subsection Conditional compilation of sources
4812
4813 You can't put a configure substitution (e.g., @samp{@@FOO@@} or
4814 @samp{$(FOO)} where @code{FOO} is defined via @code{AC_SUBST}) into a
4815 @code{_SOURCES} variable.  The reason for this is a bit hard to
4816 explain, but suffice to say that it simply won't work.  Automake will
4817 give an error if you try to do this.
4818
4819 Fortunately there are two other ways to achieve the same result.  One is
4820 to use configure substitutions in @code{_LDADD} variables, the other is
4821 to use an Automake conditional.
4822
4823 @subsubheading Conditional Compilation using @code{_LDADD} Substitutions
4824
4825 @cindex @code{EXTRA_prog_SOURCES}, defined
4826
4827 Automake must know all the source files that could possibly go into a
4828 program, even if not all the files are built in every circumstance.  Any
4829 files that are only conditionally built should be listed in the
4830 appropriate @code{EXTRA_} variable.  For instance, if
4831 @file{hello-linux.c} or @file{hello-generic.c} were conditionally included
4832 in @code{hello}, the @file{Makefile.am} would contain:
4833
4834 @example
4835 bin_PROGRAMS = hello
4836 hello_SOURCES = hello-common.c
4837 EXTRA_hello_SOURCES = hello-linux.c hello-generic.c
4838 hello_LDADD = $(HELLO_SYSTEM)
4839 hello_DEPENDENCIES = $(HELLO_SYSTEM)
4840 @end example
4841
4842 @noindent
4843 You can then setup the @samp{$(HELLO_SYSTEM)} substitution from
4844 @file{configure.ac}:
4845
4846 @example
4847 @dots{}
4848 case $host in
4849   *linux*) HELLO_SYSTEM='hello-linux.$(OBJEXT)' ;;
4850   *)       HELLO_SYSTEM='hello-generic.$(OBJEXT)' ;;
4851 esac
4852 AC_SUBST([HELLO_SYSTEM])
4853 @dots{}
4854 @end example
4855
4856 In this case, the variable @code{HELLO_SYSTEM} should be replaced by
4857 either @file{hello-linux.o} or @file{hello-generic.o}, and added to
4858 both @code{hello_DEPENDENCIES} and @code{hello_LDADD} in order to be
4859 built and linked in.
4860
4861 @subsubheading Conditional Compilation using Automake Conditionals
4862
4863 An often simpler way to compile source files conditionally is to use
4864 Automake conditionals.  For instance, you could use this
4865 @file{Makefile.am} construct to build the same @file{hello} example:
4866
4867 @example
4868 bin_PROGRAMS = hello
4869 if LINUX
4870 hello_SOURCES = hello-linux.c hello-common.c
4871 else
4872 hello_SOURCES = hello-generic.c hello-common.c
4873 endif
4874 @end example
4875
4876 In this case, @file{configure.ac} should setup the @code{LINUX}
4877 conditional using @code{AM_CONDITIONAL} (@pxref{Conditionals}).
4878
4879 When using conditionals like this you don't need to use the
4880 @code{EXTRA_} variable, because Automake will examine the contents of
4881 each variable to construct the complete list of source files.
4882
4883 If your program uses a lot of files, you will probably prefer a
4884 conditional @samp{+=}.
4885
4886 @example
4887 bin_PROGRAMS = hello
4888 hello_SOURCES = hello-common.c
4889 if LINUX
4890 hello_SOURCES += hello-linux.c
4891 else
4892 hello_SOURCES += hello-generic.c
4893 endif
4894 @end example
4895
4896 @node Conditional Programs
4897 @subsection Conditional compilation of programs
4898 @cindex Conditional programs
4899 @cindex Programs, conditional
4900
4901 Sometimes it is useful to determine the programs that are to be built
4902 at configure time.  For instance, GNU @code{cpio} only builds
4903 @code{mt} and @code{rmt} under special circumstances.  The means to
4904 achieve conditional compilation of programs are the same you can use
4905 to compile source files conditionally: substitutions or conditionals.
4906
4907 @subsubheading Conditional Programs using @command{configure} Substitutions
4908
4909 @vindex EXTRA_PROGRAMS
4910 @cindex @code{EXTRA_PROGRAMS}, defined
4911 In this case, you must notify Automake of all the programs that can
4912 possibly be built, but at the same time cause the generated
4913 @file{Makefile.in} to use the programs specified by @command{configure}.
4914 This is done by having @command{configure} substitute values into each
4915 @code{_PROGRAMS} definition, while listing all optionally built programs
4916 in @code{EXTRA_PROGRAMS}.
4917
4918 @example
4919 bin_PROGRAMS = cpio pax $(MT)
4920 libexec_PROGRAMS = $(RMT)
4921 EXTRA_PROGRAMS = mt rmt
4922 @end example
4923
4924 As explained in @ref{EXEEXT}, Automake will rewrite
4925 @code{bin_PROGRAMS}, @code{libexec_PROGRAMS}, and
4926 @code{EXTRA_PROGRAMS}, appending @samp{$(EXEEXT)} to each binary.
4927 Obviously it cannot rewrite values obtained at run-time through
4928 @command{configure} substitutions, therefore you should take care of
4929 appending @samp{$(EXEEXT)} yourself, as in @samp{AC_SUBST([MT],
4930 ['mt$@{EXEEXT@}'])}.
4931
4932 @subsubheading Conditional Programs using Automake Conditionals
4933
4934 You can also use Automake conditionals (@pxref{Conditionals}) to
4935 select programs to be built.  In this case you don't have to worry
4936 about @samp{$(EXEEXT)} or @code{EXTRA_PROGRAMS}.
4937
4938 @c Keep in sync with exeext.sh
4939 @example
4940 bin_PROGRAMS = cpio pax
4941 if WANT_MT
4942   bin_PROGRAMS += mt
4943 endif
4944 if WANT_RMT
4945   libexec_PROGRAMS = rmt
4946 endif
4947 @end example
4948
4949
4950 @node A Library
4951 @section Building a library
4952
4953 @cindex @code{_LIBRARIES} primary, defined
4954 @cindex @code{LIBRARIES} primary, defined
4955 @cindex Primary variable, @code{LIBRARIES}
4956 @vindex _LIBRARIES
4957
4958 @vindex lib_LIBRARIES
4959 @vindex pkglib_LIBRARIES
4960 @vindex noinst_LIBRARIES
4961
4962 Building a library is much like building a program.  In this case, the
4963 name of the primary is @code{LIBRARIES}.  Libraries can be installed in
4964 @code{libdir} or @code{pkglibdir}.
4965
4966 @xref{A Shared Library}, for information on how to build shared
4967 libraries using libtool and the @code{LTLIBRARIES} primary.
4968
4969 Each @code{_LIBRARIES} variable is a list of the libraries to be built.
4970 For instance, to create a library named @file{libcpio.a}, but not install
4971 it, you would write:
4972
4973 @example
4974 noinst_LIBRARIES = libcpio.a
4975 libcpio_a_SOURCES = @dots{}
4976 @end example
4977
4978 The sources that go into a library are determined exactly as they are
4979 for programs, via the @code{_SOURCES} variables.  Note that the library
4980 name is canonicalized (@pxref{Canonicalization}), so the @code{_SOURCES}
4981 variable corresponding to @file{libcpio.a} is @samp{libcpio_a_SOURCES},
4982 not @samp{libcpio.a_SOURCES}.
4983
4984 @vindex maude_LIBADD
4985 Extra objects can be added to a library using the
4986 @code{@var{library}_LIBADD} variable.  This should be used for objects
4987 determined by @command{configure}.  Again from @code{cpio}:
4988
4989 @c Keep in sync with pr401c.sh
4990 @example
4991 libcpio_a_LIBADD = $(LIBOBJS) $(ALLOCA)
4992 @end example
4993
4994 In addition, sources for extra objects that will not exist until
4995 configure-time must be added to the @code{BUILT_SOURCES} variable
4996 (@pxref{Sources}).
4997
4998 Building a static library is done by compiling all object files, then
4999 by invoking @samp{$(AR) $(ARFLAGS)} followed by the name of the
5000 library and the list of objects, and finally by calling
5001 @samp{$(RANLIB)} on that library.  You should call
5002 @code{AC_PROG_RANLIB} from your @file{configure.ac} to define
5003 @code{RANLIB} (Automake will complain otherwise).  You should also
5004 call @code{AM_PROG_AR} to define @code{AR}, in order to support unusual
5005 archivers such as Microsoft lib.  @code{ARFLAGS} will default to
5006 @code{cru}; you can override this variable by setting it in your
5007 @file{Makefile.am} or by @code{AC_SUBST}ing it from your
5008 @file{configure.ac}.  You can override the @code{AR} variable by
5009 defining a per-library @code{maude_AR} variable (@pxref{Program and
5010 Library Variables}).
5011
5012 @cindex Empty libraries
5013 Be careful when selecting library components conditionally.  Because
5014 building an empty library is not portable, you should ensure that any
5015 library always contains at least one object.
5016
5017 To use a static library when building a program, add it to
5018 @code{LDADD} for this program.  In the following example, the program
5019 @file{cpio} is statically linked with the library @file{libcpio.a}.
5020
5021 @example
5022 noinst_LIBRARIES = libcpio.a
5023 libcpio_a_SOURCES = @dots{}
5024
5025 bin_PROGRAMS = cpio
5026 cpio_SOURCES = cpio.c @dots{}
5027 cpio_LDADD = libcpio.a
5028 @end example
5029
5030
5031 @node A Shared Library
5032 @section Building a Shared Library
5033
5034 @cindex Shared libraries, support for
5035
5036 Building shared libraries portably is a relatively complex matter.
5037 For this reason, GNU Libtool (@pxref{Top, , Introduction, libtool, The
5038 Libtool Manual}) was created to help build shared libraries in a
5039 platform-independent way.
5040
5041 @menu
5042 * Libtool Concept::             Introducing Libtool
5043 * Libtool Libraries::           Declaring Libtool Libraries
5044 * Conditional Libtool Libraries::  Building Libtool Libraries Conditionally
5045 * Conditional Libtool Sources::  Choosing Library Sources Conditionally
5046 * Libtool Convenience Libraries::  Building Convenience Libtool Libraries
5047 * Libtool Modules::             Building Libtool Modules
5048 * Libtool Flags::               Using _LIBADD, _LDFLAGS, and _LIBTOOLFLAGS
5049 * LTLIBOBJS::                   Using $(LTLIBOBJS) and $(LTALLOCA)
5050 * Libtool Issues::              Common Issues Related to Libtool's Use
5051 @end menu
5052
5053 @node Libtool Concept
5054 @subsection The Libtool Concept
5055
5056 @cindex @command{libtool}, introduction
5057 @cindex libtool library, definition
5058 @cindex suffix @file{.la}, defined
5059 @cindex @file{.la} suffix, defined
5060
5061 Libtool abstracts shared and static libraries into a unified concept
5062 henceforth called @dfn{libtool libraries}.  Libtool libraries are
5063 files using the @file{.la} suffix, and can designate a static library,
5064 a shared library, or maybe both.  Their exact nature cannot be
5065 determined until @file{./configure} is run: not all platforms support
5066 all kinds of libraries, and users can explicitly select which
5067 libraries should be built.  (However the package's maintainers can
5068 tune the default, @pxref{AC_PROG_LIBTOOL, , The @code{AC_PROG_LIBTOOL}
5069 macro, libtool, The Libtool Manual}.)
5070
5071 @cindex suffix @file{.lo}, defined
5072 Because object files for shared and static libraries must be compiled
5073 differently, libtool is also used during compilation.  Object files
5074 built by libtool are called @dfn{libtool objects}: these are files
5075 using the @file{.lo} suffix.  Libtool libraries are built from these
5076 libtool objects.
5077
5078 You should not assume anything about the structure of @file{.la} or
5079 @file{.lo} files and how libtool constructs them: this is libtool's
5080 concern, and the last thing one wants is to learn about libtool's
5081 guts.  However the existence of these files matters, because they are
5082 used as targets and dependencies in @file{Makefile}s rules when
5083 building libtool libraries.  There are situations where you may have
5084 to refer to these, for instance when expressing dependencies for
5085 building source files conditionally (@pxref{Conditional Libtool
5086 Sources}).
5087
5088 @cindex @file{libltdl}, introduction
5089
5090 People considering writing a plug-in system, with dynamically loaded
5091 modules, should look into @file{libltdl}: libtool's dlopening library
5092 (@pxref{Using libltdl, , Using libltdl, libtool, The Libtool Manual}).
5093 This offers a portable dlopening facility to load libtool libraries
5094 dynamically, and can also achieve static linking where unavoidable.
5095
5096 Before we discuss how to use libtool with Automake in details, it
5097 should be noted that the libtool manual also has a section about how
5098 to use Automake with libtool (@pxref{Using Automake, , Using Automake
5099 with Libtool, libtool, The Libtool Manual}).
5100
5101 @node Libtool Libraries
5102 @subsection Building Libtool Libraries
5103
5104 @cindex @code{_LTLIBRARIES} primary, defined
5105 @cindex @code{LTLIBRARIES} primary, defined
5106 @cindex Primary variable, @code{LTLIBRARIES}
5107 @cindex Example of shared libraries
5108 @vindex lib_LTLIBRARIES
5109 @vindex pkglib_LTLIBRARIES
5110 @vindex _LTLIBRARIES
5111
5112 Automake uses libtool to build libraries declared with the
5113 @code{LTLIBRARIES} primary.  Each @code{_LTLIBRARIES} variable is a
5114 list of libtool libraries to build.  For instance, to create a libtool
5115 library named @file{libgettext.la}, and install it in @code{libdir},
5116 write:
5117
5118 @example
5119 lib_LTLIBRARIES = libgettext.la
5120 libgettext_la_SOURCES = gettext.c gettext.h @dots{}
5121 @end example
5122
5123 Automake predefines the variable @code{pkglibdir}, so you can use
5124 @code{pkglib_LTLIBRARIES} to install libraries in
5125 @samp{$(libdir)/@@PACKAGE@@/}.
5126
5127 If @file{gettext.h} is a public header file that needs to be installed
5128 in order for people to use the library, it should be declared using a
5129 @code{_HEADERS} variable, not in @code{libgettext_la_SOURCES}.
5130 Headers listed in the latter should be internal headers that are not
5131 part of the public interface.
5132
5133 @example
5134 lib_LTLIBRARIES = libgettext.la
5135 libgettext_la_SOURCES = gettext.c @dots{}
5136 include_HEADERS = gettext.h @dots{}
5137 @end example
5138
5139 A package can build and install such a library along with other
5140 programs that use it.  This dependency should be specified using
5141 @code{LDADD}.  The following example builds a program named
5142 @file{hello} that is linked with @file{libgettext.la}.
5143
5144 @example
5145 lib_LTLIBRARIES = libgettext.la
5146 libgettext_la_SOURCES = gettext.c @dots{}
5147
5148 bin_PROGRAMS = hello
5149 hello_SOURCES = hello.c @dots{}
5150 hello_LDADD = libgettext.la
5151 @end example
5152
5153 @noindent
5154 Whether @file{hello} is statically or dynamically linked with
5155 @file{libgettext.la} is not yet known: this will depend on the
5156 configuration of libtool and the capabilities of the host.
5157
5158
5159 @node Conditional Libtool Libraries
5160 @subsection Building Libtool Libraries Conditionally
5161 @cindex libtool libraries, conditional
5162 @cindex conditional libtool libraries
5163
5164 Like conditional programs (@pxref{Conditional Programs}), there are
5165 two main ways to build conditional libraries: using Automake
5166 conditionals or using Autoconf @code{AC_SUBST}itutions.
5167
5168 The important implementation detail you have to be aware of is that
5169 the place where a library will be installed matters to libtool: it
5170 needs to be indicated @emph{at link-time} using the @option{-rpath}
5171 option.
5172
5173 For libraries whose destination directory is known when Automake runs,
5174 Automake will automatically supply the appropriate @option{-rpath}
5175 option to libtool.  This is the case for libraries listed explicitly in
5176 some installable @code{_LTLIBRARIES} variables such as
5177 @code{lib_LTLIBRARIES}.
5178
5179 However, for libraries determined at configure time (and thus
5180 mentioned in @code{EXTRA_LTLIBRARIES}), Automake does not know the
5181 final installation directory.  For such libraries you must add the
5182 @option{-rpath} option to the appropriate @code{_LDFLAGS} variable by
5183 hand.
5184
5185 The examples below illustrate the differences between these two methods.
5186
5187 Here is an example where @code{WANTEDLIBS} is an @code{AC_SUBST}ed
5188 variable set at @file{./configure}-time to either @file{libfoo.la},
5189 @file{libbar.la}, both, or none.  Although @samp{$(WANTEDLIBS)}
5190 appears in the @code{lib_LTLIBRARIES}, Automake cannot guess it
5191 relates to @file{libfoo.la} or @file{libbar.la} at the time it creates
5192 the link rule for these two libraries.  Therefore the @option{-rpath}
5193 argument must be explicitly supplied.
5194
5195 @c Keep in sync with ltcond.sh
5196 @example
5197 EXTRA_LTLIBRARIES = libfoo.la libbar.la
5198 lib_LTLIBRARIES = $(WANTEDLIBS)
5199 libfoo_la_SOURCES = foo.c @dots{}
5200 libfoo_la_LDFLAGS = -rpath '$(libdir)'
5201 libbar_la_SOURCES = bar.c @dots{}
5202 libbar_la_LDFLAGS = -rpath '$(libdir)'
5203 @end example
5204
5205 Here is how the same @file{Makefile.am} would look using Automake
5206 conditionals named @code{WANT_LIBFOO} and @code{WANT_LIBBAR}.  Now
5207 Automake is able to compute the @option{-rpath} setting itself, because
5208 it's clear that both libraries will end up in @samp{$(libdir)} if they
5209 are installed.
5210
5211 @c Keep in sync with ltcond.sh
5212 @example
5213 lib_LTLIBRARIES =
5214 if WANT_LIBFOO
5215 lib_LTLIBRARIES += libfoo.la
5216 endif
5217 if WANT_LIBBAR
5218 lib_LTLIBRARIES += libbar.la
5219 endif
5220 libfoo_la_SOURCES = foo.c @dots{}
5221 libbar_la_SOURCES = bar.c @dots{}
5222 @end example
5223
5224 @node Conditional Libtool Sources
5225 @subsection Libtool Libraries with Conditional Sources
5226
5227 Conditional compilation of sources in a library can be achieved in the
5228 same way as conditional compilation of sources in a program
5229 (@pxref{Conditional Sources}).  The only difference is that
5230 @code{_LIBADD} should be used instead of @code{_LDADD} and that it
5231 should mention libtool objects (@file{.lo} files).
5232
5233 So, to mimic the @file{hello} example from @ref{Conditional Sources},
5234 we could build a @file{libhello.la} library using either
5235 @file{hello-linux.c} or @file{hello-generic.c} with the following
5236 @file{Makefile.am}.
5237
5238 @c Keep in sync with ltcond2.sh
5239 @example
5240 lib_LTLIBRARIES = libhello.la
5241 libhello_la_SOURCES = hello-common.c
5242 EXTRA_libhello_la_SOURCES = hello-linux.c hello-generic.c
5243 libhello_la_LIBADD = $(HELLO_SYSTEM)
5244 libhello_la_DEPENDENCIES = $(HELLO_SYSTEM)
5245 @end example
5246
5247 @noindent
5248 And make sure @command{configure} defines @code{HELLO_SYSTEM} as
5249 either @file{hello-linux.lo} or @file{hello-@-generic.lo}.
5250
5251 Or we could simply use an Automake conditional as follows.
5252
5253 @c Keep in sync with ltcond2.sh
5254 @example
5255 lib_LTLIBRARIES = libhello.la
5256 libhello_la_SOURCES = hello-common.c
5257 if LINUX
5258 libhello_la_SOURCES += hello-linux.c
5259 else
5260 libhello_la_SOURCES += hello-generic.c
5261 endif
5262 @end example
5263
5264 @node Libtool Convenience Libraries
5265 @subsection Libtool Convenience Libraries
5266 @cindex convenience libraries, libtool
5267 @cindex libtool convenience libraries
5268 @vindex noinst_LTLIBRARIES
5269 @vindex check_LTLIBRARIES
5270
5271 Sometimes you want to build libtool libraries that should not be
5272 installed.  These are called @dfn{libtool convenience libraries} and
5273 are typically used to encapsulate many sublibraries, later gathered
5274 into one big installed library.
5275
5276 Libtool convenience libraries are declared by directory-less variables
5277 such as @code{noinst_LTLIBRARIES}, @code{check_LTLIBRARIES}, or even
5278 @code{EXTRA_LTLIBRARIES}.  Unlike installed libtool libraries they do
5279 not need an @option{-rpath} flag at link time (actually this is the only
5280 difference).
5281
5282 Convenience libraries listed in @code{noinst_LTLIBRARIES} are always
5283 built.  Those listed in @code{check_LTLIBRARIES} are built only upon
5284 @samp{make check}.  Finally, libraries listed in
5285 @code{EXTRA_LTLIBRARIES} are never built explicitly: Automake outputs
5286 rules to build them, but if the library does not appear as a Makefile
5287 dependency anywhere it won't be built (this is why
5288 @code{EXTRA_LTLIBRARIES} is used for conditional compilation).
5289
5290 Here is a sample setup merging libtool convenience libraries from
5291 subdirectories into one main @file{libtop.la} library.
5292
5293 @c Keep in sync with ltconv.sh
5294 @example
5295 # -- Top-level Makefile.am --
5296 SUBDIRS = sub1 sub2 @dots{}
5297 lib_LTLIBRARIES = libtop.la
5298 libtop_la_SOURCES =
5299 libtop_la_LIBADD = \
5300   sub1/libsub1.la \
5301   sub2/libsub2.la \
5302   @dots{}
5303
5304 # -- sub1/Makefile.am --
5305 noinst_LTLIBRARIES = libsub1.la
5306 libsub1_la_SOURCES = @dots{}
5307
5308 # -- sub2/Makefile.am --
5309 # showing nested convenience libraries
5310 SUBDIRS = sub2.1 sub2.2 @dots{}
5311 noinst_LTLIBRARIES = libsub2.la
5312 libsub2_la_SOURCES =
5313 libsub2_la_LIBADD = \
5314   sub21/libsub21.la \
5315   sub22/libsub22.la \
5316   @dots{}
5317 @end example
5318
5319 When using such setup, beware that @command{automake} will assume
5320 @file{libtop.la} is to be linked with the C linker.  This is because
5321 @code{libtop_la_SOURCES} is empty, so @command{automake} picks C as
5322 default language.  If @code{libtop_la_SOURCES} was not empty,
5323 @command{automake} would select the linker as explained in @ref{How
5324 the Linker is Chosen}.
5325
5326 If one of the sublibraries contains non-C source, it is important that
5327 the appropriate linker be chosen.  One way to achieve this is to
5328 pretend that there is such a non-C file among the sources of the
5329 library, thus forcing @command{automake} to select the appropriate
5330 linker.  Here is the top-level @file{Makefile} of our example updated
5331 to force C++ linking.
5332
5333 @example
5334 SUBDIRS = sub1 sub2 @dots{}
5335 lib_LTLIBRARIES = libtop.la
5336 libtop_la_SOURCES =
5337 # Dummy C++ source to cause C++ linking.
5338 nodist_EXTRA_libtop_la_SOURCES = dummy.cxx
5339 libtop_la_LIBADD = \
5340   sub1/libsub1.la \
5341   sub2/libsub2.la \
5342   @dots{}
5343 @end example
5344
5345 @samp{EXTRA_*_SOURCES} variables are used to keep track of source
5346 files that might be compiled (this is mostly useful when doing
5347 conditional compilation using @code{AC_SUBST}, @pxref{Conditional
5348 Libtool Sources}), and the @code{nodist_} prefix means the listed
5349 sources are not to be distributed (@pxref{Program and Library
5350 Variables}).  In effect the file @file{dummy.cxx} does not need to
5351 exist in the source tree.  Of course if you have some real source file
5352 to list in @code{libtop_la_SOURCES} there is no point in cheating with
5353 @code{nodist_EXTRA_libtop_la_SOURCES}.
5354
5355
5356 @node Libtool Modules
5357 @subsection Libtool Modules
5358 @cindex modules, libtool
5359 @cindex libtool modules
5360 @cindex @option{-module}, libtool
5361
5362 These are libtool libraries meant to be dlopened.  They are
5363 indicated to libtool by passing @option{-module} at link-time.
5364
5365 @example
5366 pkglib_LTLIBRARIES = mymodule.la
5367 mymodule_la_SOURCES = doit.c
5368 mymodule_la_LDFLAGS = -module
5369 @end example
5370
5371 Ordinarily, Automake requires that a library's name start with
5372 @code{lib}.  However, when building a dynamically loadable module you
5373 might wish to use a "nonstandard" name.  Automake will not complain
5374 about such nonstandard names if it knows the library being built is a
5375 libtool module, i.e., if @option{-module} explicitly appears in the
5376 library's @code{_LDFLAGS} variable (or in the common @code{AM_LDFLAGS}
5377 variable when no per-library @code{_LDFLAGS} variable is defined).
5378
5379 As always, @code{AC_SUBST} variables are black boxes to Automake since
5380 their values are not yet known when @command{automake} is run.
5381 Therefore if @option{-module} is set via such a variable, Automake
5382 cannot notice it and will proceed as if the library was an ordinary
5383 libtool library, with strict naming.
5384
5385 If @code{mymodule_la_SOURCES} is not specified, then it defaults to
5386 the single file @file{mymodule.c} (@pxref{Default _SOURCES}).
5387
5388 @node Libtool Flags
5389 @subsection @code{_LIBADD}, @code{_LDFLAGS}, and @code{_LIBTOOLFLAGS}
5390 @cindex @code{_LIBADD}, libtool
5391 @cindex @code{_LDFLAGS}, libtool
5392 @cindex @code{_LIBTOOLFLAGS}, libtool
5393 @vindex AM_LIBTOOLFLAGS
5394 @vindex LIBTOOLFLAGS
5395 @vindex maude_LIBTOOLFLAGS
5396
5397 As shown in previous sections, the @samp{@var{library}_LIBADD}
5398 variable should be used to list extra libtool objects (@file{.lo}
5399 files) or libtool libraries (@file{.la}) to add to @var{library}.
5400
5401 The @samp{@var{library}_LDFLAGS} variable is the place to list
5402 additional libtool linking flags, such as @option{-version-info},
5403 @option{-static}, and a lot more.  @xref{Link mode, , Link mode,
5404 libtool, The Libtool Manual}.
5405
5406 The @command{libtool} command has two kinds of options: mode-specific
5407 options and generic options.  Mode-specific options such as the
5408 aforementioned linking flags should be lumped with the other flags
5409 passed to the tool invoked by @command{libtool} (hence the use of
5410 @samp{@var{library}_LDFLAGS} for libtool linking flags).  Generic
5411 options include @option{--tag=@var{tag}} and @option{--silent}
5412 (@pxref{Invoking libtool, , Invoking @command{libtool}, libtool, The
5413 Libtool Manual} for more options) should appear before the mode
5414 selection on the command line; in @file{Makefile.am}s they should
5415 be listed in the @samp{@var{library}_LIBTOOLFLAGS} variable.
5416
5417 If @samp{@var{library}_LIBTOOLFLAGS} is not defined, then the variable
5418 @code{AM_LIBTOOLFLAGS} is used instead.
5419
5420 These flags are passed to libtool after the @option{--tag=@var{tag}}
5421 option computed by Automake (if any), so
5422 @samp{@var{library}_LIBTOOLFLAGS} (or @code{AM_LIBTOOLFLAGS}) is a
5423 good place to override or supplement the @option{--tag=@var{tag}}
5424 setting.
5425
5426 The libtool rules also use a @code{LIBTOOLFLAGS} variable that should
5427 not be set in @file{Makefile.am}: this is a user variable (@pxref{Flag
5428 Variables Ordering}.  It allows users to run @samp{make
5429 LIBTOOLFLAGS=--silent}, for instance.  Note that the verbosity of
5430 @command{libtool} can also be influenced by the Automake support
5431 for silent rules (@pxref{Automake Silent Rules}).
5432
5433 @node LTLIBOBJS, Libtool Issues, Libtool Flags, A Shared Library
5434 @subsection @code{LTLIBOBJS} and @code{LTALLOCA}
5435 @cindex @code{LTLIBOBJS}, special handling
5436 @cindex @code{LIBOBJS}, and Libtool
5437 @cindex @code{LTALLOCA}, special handling
5438 @cindex @code{ALLOCA}, and Libtool
5439 @vindex LTLIBOBJS
5440 @vindex LIBOBJS
5441 @vindex LTALLOCA
5442 @vindex ALLOCA
5443 @acindex AC_LIBOBJ
5444
5445 Where an ordinary library might include @samp{$(LIBOBJS)} or
5446 @samp{$(ALLOCA)} (@pxref{LIBOBJS}), a libtool library must use
5447 @samp{$(LTLIBOBJS)} or @samp{$(LTALLOCA)}.  This is required because
5448 the object files that libtool operates on do not necessarily end in
5449 @file{.o}.
5450
5451 Nowadays, the computation of @code{LTLIBOBJS} from @code{LIBOBJS} is
5452 performed automatically by Autoconf (@pxref{AC_LIBOBJ vs LIBOBJS, ,
5453 @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}, autoconf, The Autoconf Manual}).
5454
5455 @node Libtool Issues
5456 @subsection Common Issues Related to Libtool's Use
5457
5458 @menu
5459 * Error required file ltmain.sh not found::  The need to run libtoolize
5460 * Objects created both with libtool and without::  Avoid a specific build race
5461 @end menu
5462
5463 @node Error required file ltmain.sh not found
5464 @subsubsection Error: @samp{required file `./ltmain.sh' not found}
5465 @cindex @file{ltmain.sh} not found
5466 @cindex @command{libtoolize}, no longer run by @command{automake}
5467 @cindex @command{libtoolize} and @command{autoreconf}
5468 @cindex @command{autoreconf} and @command{libtoolize}
5469 @cindex @file{bootstrap.sh} and @command{autoreconf}
5470 @cindex @file{autogen.sh} and @command{autoreconf}
5471
5472 Libtool comes with a tool called @command{libtoolize} that will
5473 install libtool's supporting files into a package.  Running this
5474 command will install @file{ltmain.sh}.  You should execute it before
5475 @command{aclocal} and @command{automake}.
5476
5477 People upgrading old packages to newer autotools are likely to face
5478 this issue because older Automake versions used to call
5479 @command{libtoolize}.  Therefore old build scripts do not call
5480 @command{libtoolize}.
5481
5482 Since Automake 1.6, it has been decided that running
5483 @command{libtoolize} was none of Automake's business.  Instead, that
5484 functionality has been moved into the @command{autoreconf} command
5485 (@pxref{autoreconf Invocation, , Using @command{autoreconf}, autoconf,
5486 The Autoconf Manual}).  If you do not want to remember what to run and
5487 when, just learn the @command{autoreconf} command.  Hopefully,
5488 replacing existing @file{bootstrap.sh} or @file{autogen.sh} scripts by
5489 a call to @command{autoreconf} should also free you from any similar
5490 incompatible change in the future.
5491
5492 @node Objects created both with libtool and without
5493 @subsubsection Objects @samp{created with both libtool and without}
5494
5495 Sometimes, the same source file is used both to build a libtool
5496 library and to build another non-libtool target (be it a program or
5497 another library).
5498
5499 Let's consider the following @file{Makefile.am}.
5500
5501 @example
5502 bin_PROGRAMS = prog
5503 prog_SOURCES = prog.c foo.c @dots{}
5504
5505 lib_LTLIBRARIES = libfoo.la
5506 libfoo_la_SOURCES = foo.c @dots{}
5507 @end example
5508
5509 @noindent
5510 (In this trivial case the issue could be avoided by linking
5511 @file{libfoo.la} with @file{prog} instead of listing @file{foo.c} in
5512 @code{prog_SOURCES}.  But let's assume we really want to keep
5513 @file{prog} and @file{libfoo.la} separate.)
5514
5515 Technically, it means that we should build @file{foo.$(OBJEXT)} for
5516 @file{prog}, and @file{foo.lo} for @file{libfoo.la}.  The problem is
5517 that in the course of creating @file{foo.lo}, libtool may erase (or
5518 replace) @file{foo.$(OBJEXT)}, and this cannot be avoided.
5519
5520 Therefore, when Automake detects this situation it will complain
5521 with a message such as
5522 @example
5523 object 'foo.$(OBJEXT)' created both with libtool and without
5524 @end example
5525
5526 A workaround for this issue is to ensure that these two objects get
5527 different basenames.  As explained in @ref{Renamed Objects}, this
5528 happens automatically when per-targets flags are used.
5529
5530 @example
5531 bin_PROGRAMS = prog
5532 prog_SOURCES = prog.c foo.c @dots{}
5533 prog_CFLAGS = $(AM_CFLAGS)
5534
5535 lib_LTLIBRARIES = libfoo.la
5536 libfoo_la_SOURCES = foo.c @dots{}
5537 @end example
5538
5539 @noindent
5540 Adding @samp{prog_CFLAGS = $(AM_CFLAGS)} is almost a no-op, because
5541 when the @code{prog_CFLAGS} is defined, it is used instead of
5542 @code{AM_CFLAGS}.  However as a side effect it will cause
5543 @file{prog.c} and @file{foo.c} to be compiled as
5544 @file{prog-prog.$(OBJEXT)} and @file{prog-foo.$(OBJEXT)}, which solves
5545 the issue.
5546
5547 @node Program and Library Variables
5548 @section Program and Library Variables
5549
5550 Associated with each program is a collection of variables that can be
5551 used to modify how that program is built.  There is a similar list of
5552 such variables for each library.  The canonical name of the program (or
5553 library) is used as a base for naming these variables.
5554
5555 In the list below, we use the name ``maude'' to refer to the program or
5556 library.  In your @file{Makefile.am} you would replace this with the
5557 canonical name of your program.  This list also refers to ``maude'' as a
5558 program, but in general the same rules apply for both static and dynamic
5559 libraries; the documentation below notes situations where programs and
5560 libraries differ.
5561
5562 @vtable @code
5563 @item maude_SOURCES
5564 This variable, if it exists, lists all the source files that are
5565 compiled to build the program.  These files are added to the
5566 distribution by default.  When building the program, Automake will cause
5567 each source file to be compiled to a single @file{.o} file (or
5568 @file{.lo} when using libtool).  Normally these object files are named
5569 after the source file, but other factors can change this.  If a file in
5570 the @code{_SOURCES} variable has an unrecognized extension, Automake
5571 will do one of two things with it.  If a suffix rule exists for turning
5572 files with the unrecognized extension into @file{.o} files, then
5573 @command{automake} will treat this file as it will any other source file
5574 (@pxref{Support for Other Languages}).  Otherwise, the file will be
5575 ignored as though it were a header file.
5576
5577 The prefixes @code{dist_} and @code{nodist_} can be used to control
5578 whether files listed in a @code{_SOURCES} variable are distributed.
5579 @code{dist_} is redundant, as sources are distributed by default, but it
5580 can be specified for clarity if desired.
5581
5582 It is possible to have both @code{dist_} and @code{nodist_} variants of
5583 a given @code{_SOURCES} variable at once; this lets you easily
5584 distribute some files and not others, for instance:
5585
5586 @example
5587 nodist_maude_SOURCES = nodist.c
5588 dist_maude_SOURCES = dist-me.c
5589 @end example
5590
5591 By default the output file (on Unix systems, the @file{.o} file) will
5592 be put into the current build directory.  However, if the option
5593 @option{subdir-objects} is in effect in the current directory then the
5594 @file{.o} file will be put into the subdirectory named after the
5595 source file.  For instance, with @option{subdir-objects} enabled,
5596 @file{sub/dir/file.c} will be compiled to @file{sub/dir/file.o}.  Some
5597 people prefer this mode of operation.  You can specify
5598 @option{subdir-objects} in @code{AUTOMAKE_OPTIONS} (@pxref{Options}).
5599 @cindex Subdirectory, objects in
5600 @cindex Objects in subdirectory
5601
5602
5603 @item EXTRA_maude_SOURCES
5604 Automake needs to know the list of files you intend to compile
5605 @emph{statically}.  For one thing, this is the only way Automake has of
5606 knowing what sort of language support a given @file{Makefile.in}
5607 requires.  @footnote{There are other, more obscure reasons for
5608 this limitation as well.}  This means that, for example, you can't put a
5609 configure substitution like @samp{@@my_sources@@} into a @samp{_SOURCES}
5610 variable.  If you intend to conditionally compile source files and use
5611 @file{configure} to substitute the appropriate object names into, e.g.,
5612 @code{_LDADD} (see below), then you should list the corresponding source
5613 files in the @code{EXTRA_} variable.
5614
5615 This variable also supports @code{dist_} and @code{nodist_} prefixes.
5616 For instance, @code{nodist_EXTRA_maude_SOURCES} would list extra
5617 sources that may need to be built, but should not be distributed.
5618
5619 @item maude_AR
5620 A static library is created by default by invoking @samp{$(AR)
5621 $(ARFLAGS)} followed by the name of the library and then the objects
5622 being put into the library.  You can override this by setting the
5623 @code{_AR} variable.  This is usually used with C++; some C++
5624 compilers require a special invocation in order to instantiate all the
5625 templates that should go into a library.  For instance, the SGI C++
5626 compiler likes this variable set like so:
5627 @example
5628 libmaude_a_AR = $(CXX) -ar -o
5629 @end example
5630
5631 @item maude_LIBADD
5632 Extra objects can be added to a @emph{library} using the @code{_LIBADD}
5633 variable.  For instance, this should be used for objects determined by
5634 @command{configure} (@pxref{A Library}).
5635
5636 In the case of libtool libraries, @code{maude_LIBADD} can also refer
5637 to other libtool libraries.
5638
5639 @item maude_LDADD
5640 Extra objects (@file{*.$(OBJEXT)}) and libraries (@file{*.a},
5641 @file{*.la}) can be added to a @emph{program} by listing them in the
5642 @code{_LDADD} variable.  For instance, this should be used for objects
5643 determined by @command{configure} (@pxref{Linking}).
5644
5645 @code{_LDADD} and @code{_LIBADD} are inappropriate for passing
5646 program-specific linker flags (except for @option{-l}, @option{-L},
5647 @option{-dlopen} and @option{-dlpreopen}).  Use the @code{_LDFLAGS} variable
5648 for this purpose.
5649
5650 For instance, if your @file{configure.ac} uses @code{AC_PATH_XTRA}, you
5651 could link your program against the X libraries like so:
5652
5653 @example
5654 maude_LDADD = $(X_PRE_LIBS) $(X_LIBS) $(X_EXTRA_LIBS)
5655 @end example
5656
5657 We recommend that you use @option{-l} and @option{-L} only when
5658 referring to third-party libraries, and give the explicit file names
5659 of any library built by your package.  Doing so will ensure that
5660 @code{maude_DEPENDENCIES} (see below) is correctly defined by default.
5661
5662 @item maude_LDFLAGS
5663 This variable is used to pass extra flags to the link step of a program
5664 or a shared library.  It overrides the @code{AM_LDFLAGS} variable.
5665
5666 @item maude_LIBTOOLFLAGS
5667 This variable is used to pass extra options to @command{libtool}.
5668 It overrides the @code{AM_LIBTOOLFLAGS} variable.
5669 These options are output before @command{libtool}'s @option{--mode=@var{mode}}
5670 option, so they should not be mode-specific options (those belong to
5671 the compiler or linker flags).  @xref{Libtool Flags}.
5672
5673 @item maude_DEPENDENCIES
5674 @itemx EXTRA_maude_DEPENDENCIES
5675 It is also occasionally useful to have a target (program or library)
5676 depend on some other file that is not actually part of that target.
5677 This can be done using the @code{_DEPENDENCIES} variable.  Each
5678 target depends on the contents of such a variable, but no further
5679 interpretation is done.
5680
5681 Since these dependencies are associated to the link rule used to
5682 create the programs they should normally list files used by the link
5683 command.  That is @file{*.$(OBJEXT)}, @file{*.a}, or @file{*.la} files
5684 for programs; @file{*.lo} and @file{*.la} files for Libtool libraries;
5685 and @file{*.$(OBJEXT)} files for static libraries.  In rare cases you
5686 may need to add other kinds of files such as linker scripts, but
5687 @emph{listing a source file in @code{_DEPENDENCIES} is wrong}.  If
5688 some source file needs to be built before all the components of a
5689 program are built, consider using the @code{BUILT_SOURCES} variable
5690 (@pxref{Sources}).
5691
5692 If @code{_DEPENDENCIES} is not supplied, it is computed by Automake.
5693 The automatically-assigned value is the contents of @code{_LDADD} or
5694 @code{_LIBADD}, with most configure substitutions, @option{-l}, @option{-L},
5695 @option{-dlopen} and @option{-dlpreopen} options removed.  The configure
5696 substitutions that are left in are only @samp{$(LIBOBJS)} and
5697 @samp{$(ALLOCA)}; these are left because it is known that they will not
5698 cause an invalid value for @code{_DEPENDENCIES} to be generated.
5699
5700 @code{_DEPENDENCIES} is more likely used to perform conditional
5701 compilation using an @code{AC_SUBST} variable that contains a list of
5702 objects.  @xref{Conditional Sources}, and @ref{Conditional Libtool
5703 Sources}.
5704
5705 The @code{EXTRA_*_DEPENDENCIES} variable may be useful for cases where
5706 you merely want to augment the @command{automake}-generated
5707 @code{_DEPENDENCIES} variable rather than replacing it.
5708
5709 @item maude_LINK
5710 You can override the linker on a per-program basis.  By default the
5711 linker is chosen according to the languages used by the program.  For
5712 instance, a program that includes C++ source code would use the C++
5713 compiler to link.  The @code{_LINK} variable must hold the name of a
5714 command that can be passed all the @file{.o} file names and libraries
5715 to link against as arguments.  Note that the name of the underlying
5716 program is @emph{not} passed to @code{_LINK}; typically one uses
5717 @samp{$@@}:
5718
5719 @example
5720 maude_LINK = $(CCLD) -magic -o $@@
5721 @end example
5722
5723 If a @code{_LINK} variable is not supplied, it may still be generated
5724 and used by Automake due to the use of per-target link flags such as
5725 @code{_CFLAGS}, @code{_LDFLAGS} or @code{_LIBTOOLFLAGS}, in cases where
5726 they apply.
5727
5728 @item maude_CCASFLAGS
5729 @itemx maude_CFLAGS
5730 @itemx maude_CPPFLAGS
5731 @itemx maude_CXXFLAGS
5732 @itemx maude_FFLAGS
5733 @itemx maude_GCJFLAGS
5734 @itemx maude_LFLAGS
5735 @itemx maude_OBJCFLAGS
5736 @itemx maude_OBJCXXFLAGS
5737 @itemx maude_RFLAGS
5738 @itemx maude_UPCFLAGS
5739 @itemx maude_YFLAGS
5740 @cindex per-target compilation flags, defined
5741 Automake allows you to set compilation flags on a per-program (or
5742 per-library) basis.  A single source file can be included in several
5743 programs, and it will potentially be compiled with different flags for
5744 each program.  This works for any language directly supported by
5745 Automake.  These @dfn{per-target compilation flags} are
5746 @samp{_CCASFLAGS},
5747 @samp{_CFLAGS},
5748 @samp{_CPPFLAGS},
5749 @samp{_CXXFLAGS},
5750 @samp{_FFLAGS},
5751 @samp{_GCJFLAGS},
5752 @samp{_LFLAGS},
5753 @samp{_OBJCFLAGS},
5754 @samp{_OBJCXXFLAGS},
5755 @samp{_RFLAGS},
5756 @samp{_UPCFLAGS}, and
5757 @samp{_YFLAGS}.
5758
5759 When using a per-target compilation flag, Automake will choose a
5760 different name for the intermediate object files.  Ordinarily a file
5761 like @file{sample.c} will be compiled to produce @file{sample.o}.
5762 However, if the program's @code{_CFLAGS} variable is set, then the
5763 object file will be named, for instance, @file{maude-sample.o}.  (See
5764 also @ref{Renamed Objects}.)  The use of per-target compilation flags
5765 with C sources requires that the macro @code{AM_PROG_CC_C_O} be called
5766 from @file{configure.ac}.
5767
5768 In compilations with per-target flags, the ordinary @samp{AM_} form of
5769 the flags variable is @emph{not} automatically included in the
5770 compilation (however, the user form of the variable @emph{is} included).
5771 So for instance, if you want the hypothetical @file{maude} compilations
5772 to also use the value of @code{AM_CFLAGS}, you would need to write:
5773
5774 @example
5775 maude_CFLAGS = @dots{} your flags @dots{} $(AM_CFLAGS)
5776 @end example
5777
5778 @xref{Flag Variables Ordering}, for more discussion about the
5779 interaction between user variables, @samp{AM_} shadow variables, and
5780 per-target variables.
5781
5782 @item maude_SHORTNAME
5783 On some platforms the allowable file names are very short.  In order to
5784 support these systems and per-target compilation flags at the same
5785 time, Automake allows you to set a ``short name'' that will influence
5786 how intermediate object files are named.  For instance, in the following
5787 example,
5788
5789 @example
5790 bin_PROGRAMS = maude
5791 maude_CPPFLAGS = -DSOMEFLAG
5792 maude_SHORTNAME = m
5793 maude_SOURCES = sample.c @dots{}
5794 @end example
5795
5796 @noindent
5797 the object file would be named @file{m-sample.o} rather than
5798 @file{maude-sample.o}.
5799
5800 This facility is rarely needed in practice,
5801 and we recommend avoiding it until you find it is required.
5802 @end vtable
5803
5804 @node Default _SOURCES
5805 @section Default @code{_SOURCES}
5806
5807 @vindex _SOURCES
5808 @vindex SOURCES
5809 @cindex @code{_SOURCES}, default
5810 @cindex default @code{_SOURCES}
5811 @vindex AM_DEFAULT_SOURCE_EXT
5812
5813 @code{_SOURCES} variables are used to specify source files of programs
5814 (@pxref{A Program}), libraries (@pxref{A Library}), and Libtool
5815 libraries (@pxref{A Shared Library}).
5816
5817 When no such variable is specified for a target, Automake will define
5818 one itself.  The default is to compile a single C file whose base name
5819 is the name of the target itself, with any extension replaced by
5820 @code{AM_DEFAULT_SOURCE_EXT}, which defaults to @file{.c}.
5821
5822 For example if you have the following somewhere in your
5823 @file{Makefile.am} with no corresponding @code{libfoo_a_SOURCES}:
5824
5825 @example
5826 lib_LIBRARIES = libfoo.a sub/libc++.a
5827 @end example
5828
5829 @noindent
5830 @file{libfoo.a} will be built using a default source file named
5831 @file{libfoo.c}, and @file{sub/libc++.a} will be built from
5832 @file{sub/libc++.c}.  (In older versions @file{sub/libc++.a}
5833 would be built from @file{sub_libc___a.c}, i.e., the default source
5834 was the canonized name of the target, with @file{.c} appended.
5835 We believe the new behavior is more sensible, but for backward
5836 compatibility @command{automake} will use the old name if a file or a rule
5837 with that name exists and @code{AM_DEFAULT_SOURCE_EXT} is not used.)
5838
5839 @cindex @code{check_PROGRAMS} example
5840 @vindex check_PROGRAMS
5841 Default sources are mainly useful in test suites, when building many
5842 test programs each from a single source.  For instance, in
5843
5844 @example
5845 check_PROGRAMS = test1 test2 test3
5846 AM_DEFAULT_SOURCE_EXT = .cpp
5847 @end example
5848
5849 @noindent
5850 @file{test1}, @file{test2}, and @file{test3} will be built
5851 from @file{test1.cpp}, @file{test2.cpp}, and @file{test3.cpp}.
5852 Without the last line, they will be built from @file{test1.c},
5853 @file{test2.c}, and @file{test3.c}.
5854
5855 @cindex Libtool modules, default source example
5856 @cindex default source, Libtool modules example
5857 Another case where this is convenient is building many Libtool modules
5858 (@file{module@var{n}.la}), each defined in its own file
5859 (@file{module@var{n}.c}).
5860
5861 @example
5862 AM_LDFLAGS = -module
5863 lib_LTLIBRARIES = module1.la module2.la module3.la
5864 @end example
5865
5866 @cindex empty @code{_SOURCES}
5867 @cindex @code{_SOURCES}, empty
5868 Finally, there is one situation where this default source computation
5869 needs to be avoided: when a target should not be built from sources.
5870 We already saw such an example in @ref{true}; this happens when all
5871 the constituents of a target have already been compiled and just need
5872 to be combined using a @code{_LDADD} variable.  Then it is necessary
5873 to define an empty @code{_SOURCES} variable, so that @command{automake}
5874 does not compute a default.
5875
5876 @example
5877 bin_PROGRAMS = target
5878 target_SOURCES =
5879 target_LDADD = libmain.a libmisc.a
5880 @end example
5881
5882 @node LIBOBJS
5883 @section Special handling for @code{LIBOBJS} and @code{ALLOCA}
5884
5885 @cindex @code{LIBOBJS}, example
5886 @cindex @code{ALLOCA}, example
5887 @cindex @code{LIBOBJS}, special handling
5888 @cindex @code{ALLOCA}, special handling
5889 @vindex LTLIBOBJS
5890 @vindex LIBOBJS
5891 @vindex LTALLOCA
5892 @vindex ALLOCA
5893
5894 The @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} variables list object
5895 files that should be compiled into the project to provide an
5896 implementation for functions that are missing or broken on the host
5897 system.  They are substituted by @file{configure}.
5898
5899 @acindex AC_LIBOBJ
5900
5901 These variables are defined by Autoconf macros such as
5902 @code{AC_LIBOBJ}, @code{AC_REPLACE_FUNCS} (@pxref{Generic Functions, ,
5903 Generic Function Checks, autoconf, The Autoconf Manual}), or
5904 @code{AC_FUNC_ALLOCA} (@pxref{Particular Functions, , Particular
5905 Function Checks, autoconf, The Autoconf Manual}).  Many other Autoconf
5906 macros call @code{AC_LIBOBJ} or @code{AC_REPLACE_FUNCS} to
5907 populate @samp{$(LIBOBJS)}.
5908
5909 @acindex AC_LIBSOURCE
5910
5911 Using these variables is very similar to doing conditional compilation
5912 using @code{AC_SUBST} variables, as described in @ref{Conditional
5913 Sources}.  That is, when building a program, @samp{$(LIBOBJS)} and
5914 @samp{$(ALLOCA)} should be added to the associated @samp{*_LDADD}
5915 variable, or to the @samp{*_LIBADD} variable when building a library.
5916 However there is no need to list the corresponding sources in
5917 @samp{EXTRA_*_SOURCES} nor to define @samp{*_DEPENDENCIES}.  Automake
5918 automatically adds @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} to the
5919 dependencies, and it will discover the list of corresponding source
5920 files automatically (by tracing the invocations of the
5921 @code{AC_LIBSOURCE} Autoconf macros).  If you have already defined
5922 @samp{*_DEPENDENCIES} explicitly for an unrelated reason, then you
5923 either need to add these variables manually, or use
5924 @samp{EXTRA_*_DEPENDENCIES} instead of @samp{*_DEPENDENCIES}.
5925
5926 These variables are usually used to build a portability library that
5927 is linked with all the programs of the project.  We now review a
5928 sample setup.  First, @file{configure.ac} contains some checks that
5929 affect either @code{LIBOBJS} or @code{ALLOCA}.
5930
5931 @example
5932 # configure.ac
5933 @dots{}
5934 AC_CONFIG_LIBOBJ_DIR([lib])
5935 @dots{}
5936 AC_FUNC_MALLOC             dnl May add malloc.$(OBJEXT) to LIBOBJS
5937 AC_FUNC_MEMCMP             dnl May add memcmp.$(OBJEXT) to LIBOBJS
5938 AC_REPLACE_FUNCS([strdup]) dnl May add strdup.$(OBJEXT) to LIBOBJS
5939 AC_FUNC_ALLOCA             dnl May add alloca.$(OBJEXT) to ALLOCA
5940 @dots{}
5941 AC_CONFIG_FILES([
5942   lib/Makefile
5943   src/Makefile
5944 ])
5945 AC_OUTPUT
5946 @end example
5947
5948 @acindex AC_CONFIG_LIBOBJ_DIR
5949
5950 The @code{AC_CONFIG_LIBOBJ_DIR} tells Autoconf that the source files
5951 of these object files are to be found in the @file{lib/} directory.
5952 Automake can also use this information, otherwise it expects the
5953 source files are to be in the directory where the @samp{$(LIBOBJS)}
5954 and @samp{$(ALLOCA)} variables are used.
5955
5956 The @file{lib/} directory should therefore contain @file{malloc.c},
5957 @file{memcmp.c}, @file{strdup.c}, @file{alloca.c}.  Here is its
5958 @file{Makefile.am}:
5959
5960 @example
5961 # lib/Makefile.am
5962
5963 noinst_LIBRARIES = libcompat.a
5964 libcompat_a_SOURCES =
5965 libcompat_a_LIBADD = $(LIBOBJS) $(ALLOCA)
5966 @end example
5967
5968 The library can have any name, of course, and anyway it is not going
5969 to be installed: it just holds the replacement versions of the missing
5970 or broken functions so we can later link them in.  Many projects
5971 also include extra functions, specific to the project, in that
5972 library: they are simply added on the @code{_SOURCES} line.
5973
5974 @cindex Empty libraries and @samp{$(LIBOBJS)}
5975 @cindex @samp{$(LIBOBJS)} and empty libraries
5976 There is a small trap here, though: @samp{$(LIBOBJS)} and
5977 @samp{$(ALLOCA)} might be empty, and building an empty library is not
5978 portable.  You should ensure that there is always something to put in
5979 @file{libcompat.a}.  Most projects will also add some utility
5980 functions in that directory, and list them in
5981 @code{libcompat_a_SOURCES}, so in practice @file{libcompat.a} cannot
5982 be empty.
5983
5984 Finally here is how this library could be used from the @file{src/}
5985 directory.
5986
5987 @example
5988 # src/Makefile.am
5989
5990 # Link all programs in this directory with libcompat.a
5991 LDADD = ../lib/libcompat.a
5992
5993 bin_PROGRAMS = tool1 tool2 @dots{}
5994 tool1_SOURCES = @dots{}
5995 tool2_SOURCES = @dots{}
5996 @end example
5997
5998 When option @option{subdir-objects} is not used, as in the above
5999 example, the variables @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} can only
6000 be used in the directory where their sources lie.  E.g., here it would
6001 be wrong to use @samp{$(LIBOBJS)} or @samp{$(ALLOCA)} in
6002 @file{src/Makefile.am}.  However if both @option{subdir-objects} and
6003 @code{AC_CONFIG_LIBOBJ_DIR} are used, it is OK to use these variables
6004 in other directories.  For instance @file{src/Makefile.am} could be
6005 changed as follows.
6006
6007 @example
6008 # src/Makefile.am
6009
6010 AUTOMAKE_OPTIONS = subdir-objects
6011 LDADD = $(LIBOBJS) $(ALLOCA)
6012
6013 bin_PROGRAMS = tool1 tool2 @dots{}
6014 tool1_SOURCES = @dots{}
6015 tool2_SOURCES = @dots{}
6016 @end example
6017
6018 Because @samp{$(LIBOBJS)} and @samp{$(ALLOCA)} contain object
6019 file names that end with @samp{.$(OBJEXT)}, they are not suitable for
6020 Libtool libraries (where the expected object extension is @file{.lo}):
6021 @code{LTLIBOBJS} and @code{LTALLOCA} should be used instead.
6022
6023 @code{LTLIBOBJS} is defined automatically by Autoconf and should not
6024 be defined by hand (as in the past), however at the time of writing
6025 @code{LTALLOCA} still needs to be defined from @code{ALLOCA} manually.
6026 @xref{AC_LIBOBJ vs LIBOBJS, , @code{AC_LIBOBJ} vs.@: @code{LIBOBJS},
6027 autoconf, The Autoconf Manual}.
6028
6029
6030 @node Program Variables
6031 @section Variables used when building a program
6032
6033 Occasionally it is useful to know which @file{Makefile} variables
6034 Automake uses for compilations, and in which order (@pxref{Flag
6035 Variables Ordering}); for instance, you might need to do your own
6036 compilation in some special cases.
6037
6038 Some variables are inherited from Autoconf; these are @code{CC},
6039 @code{CFLAGS}, @code{CPPFLAGS}, @code{DEFS}, @code{LDFLAGS}, and
6040 @code{LIBS}.
6041 @vindex CC
6042 @vindex CFLAGS
6043 @vindex CPPFLAGS
6044 @vindex DEFS
6045 @vindex LDFLAGS
6046 @vindex LIBS
6047
6048 There are some additional variables that Automake defines on its own:
6049
6050 @vtable @code
6051 @item AM_CPPFLAGS
6052 The contents of this variable are passed to every compilation that invokes
6053 the C preprocessor; it is a list of arguments to the preprocessor.  For
6054 instance, @option{-I} and @option{-D} options should be listed here.
6055
6056 Automake already provides some @option{-I} options automatically, in a
6057 separate variable that is also passed to every compilation that invokes
6058 the C preprocessor.  In particular it generates @samp{-I.},
6059 @samp{-I$(srcdir)}, and a @option{-I} pointing to the directory holding
6060 @file{config.h} (if you've used @code{AC_CONFIG_HEADERS}).  You can
6061 disable the default @option{-I} options using the @option{nostdinc}
6062 option.
6063
6064 When a file to be included is generated during the build and not part
6065 of a distribution tarball, its location is under @code{$(builddir)},
6066 not under @code{$(srcdir)}.  This matters especially for packages that
6067 use header files placed in sub-directories and want to allow builds
6068 outside the source tree (@pxref{VPATH Builds}). In that case we
6069 recommend to use a pair of @option{-I} options, such as, e.g.,
6070 @samp{-Isome/subdir -I$(srcdir)/some/subdir} or
6071 @samp{-I$(top_builddir)/some/subdir -I$(top_srcdir)/some/subdir}.
6072 Note that the reference to the build tree should come before the
6073 reference to the source tree, so that accidentally leftover generated
6074 files in the source directory are ignored.
6075
6076 @code{AM_CPPFLAGS} is ignored in preference to a per-executable (or
6077 per-library) @code{_CPPFLAGS} variable if it is defined.
6078
6079 @item INCLUDES
6080 This does the same job as @code{AM_CPPFLAGS} (or any per-target
6081 @code{_CPPFLAGS} variable if it is used).  It is an older name for the
6082 same functionality.  This variable is deprecated; we suggest using
6083 @code{AM_CPPFLAGS} and per-target @code{_CPPFLAGS} instead.
6084
6085 @item AM_CFLAGS
6086 This is the variable the @file{Makefile.am} author can use to pass
6087 in additional C compiler flags.  It is more fully documented elsewhere.
6088 In some situations, this is not used, in preference to the
6089 per-executable (or per-library) @code{_CFLAGS}.
6090
6091 @item COMPILE
6092 This is the command used to actually compile a C source file.  The
6093 file name is appended to form the complete command line.
6094
6095 @item AM_LDFLAGS
6096 This is the variable the @file{Makefile.am} author can use to pass
6097 in additional linker flags.  In some situations, this is not used, in
6098 preference to the per-executable (or per-library) @code{_LDFLAGS}.
6099
6100 @item LINK
6101 This is the command used to actually link a C program.  It already
6102 includes @samp{-o $@@} and the usual variable references (for instance,
6103 @code{CFLAGS}); it takes as ``arguments'' the names of the object files
6104 and libraries to link in.  This variable is not used when the linker is
6105 overridden with a per-target @code{_LINK} variable or per-target flags
6106 cause Automake to define such a @code{_LINK} variable.
6107 @end vtable
6108
6109
6110 @node Yacc and Lex
6111 @section Yacc and Lex support
6112
6113 Automake has somewhat idiosyncratic support for Yacc and Lex.
6114
6115 Automake assumes that the @file{.c} file generated by @command{yacc}
6116 (or @command{lex}) should be named using the basename of the input
6117 file.  That is, for a yacc source file @file{foo.y}, Automake will
6118 cause the intermediate file to be named @file{foo.c} (as opposed to
6119 @file{y.tab.c}, which is more traditional).
6120
6121 The extension of a yacc source file is used to determine the extension
6122 of the resulting C or C++ source and header files.  Note that header
6123 files are generated only when the @option{-d} Yacc option is used; see
6124 below for more information about this flag, and how to specify it.
6125 Files with the extension @file{.y} will thus be turned into @file{.c}
6126 sources and @file{.h} headers; likewise, @file{.yy} will become
6127 @file{.cc} and @file{.hh}, @file{.y++} will become @file{c++} and
6128 @file{h++}, @file{.yxx} will become @file{.cxx} and @file{.hxx},
6129 and @file{.ypp} will become @file{.cpp} and @file{.hpp}.
6130
6131 Similarly, lex source files can be used to generate C or C++; the
6132 extensions @file{.l}, @file{.ll}, @file{.l++}, @file{.lxx}, and
6133 @file{.lpp} are recognized.
6134
6135 You should never explicitly mention the intermediate (C or C++) file
6136 in any @code{SOURCES} variable; only list the source file.
6137
6138 The intermediate files generated by @command{yacc} (or @command{lex})
6139 will be included in any distribution that is made.  That way the user
6140 doesn't need to have @command{yacc} or @command{lex}.
6141
6142 If a @command{yacc} source file is seen, then your @file{configure.ac} must
6143 define the variable @code{YACC}.  This is most easily done by invoking
6144 the macro @code{AC_PROG_YACC} (@pxref{Particular Programs, , Particular
6145 Program Checks, autoconf, The Autoconf Manual}).
6146
6147 @vindex YFLAGS
6148 @vindex AM_YFLAGS
6149 When @code{yacc} is invoked, it is passed @code{AM_YFLAGS} and
6150 @code{YFLAGS}.  The latter is a user variable and the former is
6151 intended for the @file{Makefile.am} author.
6152
6153 @code{AM_YFLAGS} is usually used to pass the @option{-d} option to
6154 @command{yacc}.  Automake knows what this means and will automatically
6155 adjust its rules to update and distribute the header file built by
6156 @samp{yacc -d}@footnote{Please note that @command{automake} recognizes
6157 @option{-d} in @code{AM_YFLAGS} only if it is not clustered with other
6158 options; for example, it won't be recognized if @code{AM_YFLAGS} is
6159 @option{-dt}, but it will be if @code{AM_YFLAGS} is @option{-d -t} or
6160 @option{-t -d}.}.
6161 What Automake cannot guess, though, is where this
6162 header will be used: it is up to you to ensure the header gets built
6163 before it is first used.  Typically this is necessary in order for
6164 dependency tracking to work when the header is included by another
6165 file.  The common solution is listing the header file in
6166 @code{BUILT_SOURCES} (@pxref{Sources}) as follows.
6167
6168 @example
6169 BUILT_SOURCES = parser.h
6170 AM_YFLAGS = -d
6171 bin_PROGRAMS = foo
6172 foo_SOURCES = @dots{} parser.y @dots{}
6173 @end example
6174
6175 If a @command{lex} source file is seen, then your @file{configure.ac}
6176 must define the variable @code{LEX}.  You can use @code{AC_PROG_LEX}
6177 to do this (@pxref{Particular Programs, , Particular Program Checks,
6178 autoconf, The Autoconf Manual}), but using @code{AM_PROG_LEX} macro
6179 (@pxref{Macros}) is recommended.
6180
6181 @vindex LFLAGS
6182 @vindex AM_LFLAGS
6183 When @command{lex} is invoked, it is passed @code{AM_LFLAGS} and
6184 @code{LFLAGS}.  The latter is a user variable and the former is
6185 intended for the @file{Makefile.am} author.
6186
6187 When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the
6188 rebuild rule for distributed Yacc and Lex sources are only used when
6189 @code{maintainer-mode} is enabled, or when the files have been erased.
6190
6191 @cindex @command{ylwrap}
6192 @cindex @command{yacc}, multiple parsers
6193 @cindex Multiple @command{yacc} parsers
6194 @cindex Multiple @command{lex} lexers
6195 @cindex @command{lex}, multiple lexers
6196
6197 When @command{lex} or @command{yacc} sources are used, @code{automake
6198 -i} automatically installs an auxiliary program called
6199 @command{ylwrap} in your package (@pxref{Auxiliary Programs}).  This
6200 program is used by the build rules to rename the output of these
6201 tools, and makes it possible to include multiple @command{yacc} (or
6202 @command{lex}) source files in a single directory.  (This is necessary
6203 because yacc's output file name is fixed, and a parallel make could
6204 conceivably invoke more than one instance of @command{yacc}
6205 simultaneously.)
6206
6207 For @command{yacc}, simply managing locking is insufficient.  The output of
6208 @command{yacc} always uses the same symbol names internally, so it isn't
6209 possible to link two @command{yacc} parsers into the same executable.
6210
6211 We recommend using the following renaming hack used in @command{gdb}:
6212 @example
6213 #define yymaxdepth c_maxdepth
6214 #define yyparse c_parse
6215 #define yylex   c_lex
6216 #define yyerror c_error
6217 #define yylval  c_lval
6218 #define yychar  c_char
6219 #define yydebug c_debug
6220 #define yypact  c_pact
6221 #define yyr1    c_r1
6222 #define yyr2    c_r2
6223 #define yydef   c_def
6224 #define yychk   c_chk
6225 #define yypgo   c_pgo
6226 #define yyact   c_act
6227 #define yyexca  c_exca
6228 #define yyerrflag c_errflag
6229 #define yynerrs c_nerrs
6230 #define yyps    c_ps
6231 #define yypv    c_pv
6232 #define yys     c_s
6233 #define yy_yys  c_yys
6234 #define yystate c_state
6235 #define yytmp   c_tmp
6236 #define yyv     c_v
6237 #define yy_yyv  c_yyv
6238 #define yyval   c_val
6239 #define yylloc  c_lloc
6240 #define yyreds  c_reds
6241 #define yytoks  c_toks
6242 #define yylhs   c_yylhs
6243 #define yylen   c_yylen
6244 #define yydefred c_yydefred
6245 #define yydgoto  c_yydgoto
6246 #define yysindex c_yysindex
6247 #define yyrindex c_yyrindex
6248 #define yygindex c_yygindex
6249 #define yytable  c_yytable
6250 #define yycheck  c_yycheck
6251 #define yyname   c_yyname
6252 #define yyrule   c_yyrule
6253 @end example
6254
6255 For each define, replace the @samp{c_} prefix with whatever you like.
6256 These defines work for @command{bison}, @command{byacc}, and
6257 traditional @code{yacc}s.  If you find a parser generator that uses a
6258 symbol not covered here, please report the new name so it can be added
6259 to the list.
6260
6261
6262 @node C++ Support
6263 @section C++ Support
6264
6265 @cindex C++ support
6266 @cindex Support for C++
6267
6268 Automake includes full support for C++.
6269
6270 Any package including C++ code must define the output variable
6271 @code{CXX} in @file{configure.ac}; the simplest way to do this is to use
6272 the @code{AC_PROG_CXX} macro (@pxref{Particular Programs, , Particular
6273 Program Checks, autoconf, The Autoconf Manual}).
6274
6275 A few additional variables are defined when a C++ source file is seen:
6276
6277 @vtable @code
6278 @item CXX
6279 The name of the C++ compiler.
6280
6281 @item CXXFLAGS
6282 Any flags to pass to the C++ compiler.
6283
6284 @item AM_CXXFLAGS
6285 The maintainer's variant of @code{CXXFLAGS}.
6286
6287 @item CXXCOMPILE
6288 The command used to actually compile a C++ source file.  The file name
6289 is appended to form the complete command line.
6290
6291 @item CXXLINK
6292 The command used to actually link a C++ program.
6293 @end vtable
6294
6295
6296 @node Objective C Support
6297 @section Objective C Support
6298
6299 @cindex Objective C support
6300 @cindex Support for Objective C
6301
6302 Automake includes some support for Objective C.
6303
6304 Any package including Objective C code must define the output variable
6305 @code{OBJC} in @file{configure.ac}; the simplest way to do this is to use
6306 the @code{AC_PROG_OBJC} macro (@pxref{Particular Programs, , Particular
6307 Program Checks, autoconf, The Autoconf Manual}).
6308
6309 A few additional variables are defined when an Objective C source file
6310 is seen:
6311
6312 @vtable @code
6313 @item OBJC
6314 The name of the Objective C compiler.
6315
6316 @item OBJCFLAGS
6317 Any flags to pass to the Objective C compiler.
6318
6319 @item AM_OBJCFLAGS
6320 The maintainer's variant of @code{OBJCFLAGS}.
6321
6322 @item OBJCCOMPILE
6323 The command used to actually compile an Objective C source file.  The
6324 file name is appended to form the complete command line.
6325
6326 @item OBJCLINK
6327 The command used to actually link an Objective C program.
6328 @end vtable
6329
6330
6331 @node Objective C++ Support
6332 @section Objective C++ Support
6333
6334 @cindex Objective C++ support
6335 @cindex Support for Objective C++
6336
6337 Automake includes some support for Objective C++.
6338
6339 Any package including Objective C++ code must define the output variable
6340 @code{OBJCXX} in @file{configure.ac}; the simplest way to do this is to use
6341 the @code{AC_PROG_OBJCXX} macro (@pxref{Particular Programs, , Particular
6342 Program Checks, autoconf, The Autoconf Manual}).
6343
6344 A few additional variables are defined when an Objective C++ source file
6345 is seen:
6346
6347 @vtable @code
6348 @item OBJCXX
6349 The name of the Objective C++ compiler.
6350
6351 @item OBJCXXFLAGS
6352 Any flags to pass to the Objective C++ compiler.
6353
6354 @item AM_OBJCXXFLAGS
6355 The maintainer's variant of @code{OBJCXXFLAGS}.
6356
6357 @item OBJCXXCOMPILE
6358 The command used to actually compile an Objective C++ source file.  The
6359 file name is appended to form the complete command line.
6360
6361 @item OBJCXXLINK
6362 The command used to actually link an Objective C++ program.
6363 @end vtable
6364
6365
6366 @node Unified Parallel C Support
6367 @section Unified Parallel C Support
6368
6369 @cindex Unified Parallel C support
6370 @cindex Support for Unified Parallel C
6371
6372 Automake includes some support for Unified Parallel C.
6373
6374 Any package including Unified Parallel C code must define the output
6375 variable @code{UPC} in @file{configure.ac}; the simplest way to do
6376 this is to use the @code{AM_PROG_UPC} macro (@pxref{Public Macros}).
6377
6378 A few additional variables are defined when a Unified Parallel C
6379 source file is seen:
6380
6381 @vtable @code
6382 @item UPC
6383 The name of the Unified Parallel C compiler.
6384
6385 @item UPCFLAGS
6386 Any flags to pass to the Unified Parallel C compiler.
6387
6388 @item AM_UPCFLAGS
6389 The maintainer's variant of @code{UPCFLAGS}.
6390
6391 @item UPCCOMPILE
6392 The command used to actually compile a Unified Parallel C source file.
6393 The file name is appended to form the complete command line.
6394
6395 @item UPCLINK
6396 The command used to actually link a Unified Parallel C program.
6397 @end vtable
6398
6399
6400 @node Assembly Support
6401 @section Assembly Support
6402
6403 Automake includes some support for assembly code.  There are two forms
6404 of assembler files: normal (@file{*.s}) and preprocessed by @code{CPP}
6405 (@file{*.S} or @file{*.sx}).
6406
6407 @vindex CCAS
6408 @vindex CCASFLAGS
6409 @vindex CPPFLAGS
6410 @vindex AM_CCASFLAGS
6411 @vindex AM_CPPFLAGS
6412 The variable @code{CCAS} holds the name of the compiler used to build
6413 assembly code.  This compiler must work a bit like a C compiler; in
6414 particular it must accept @option{-c} and @option{-o}.  The values of
6415 @code{CCASFLAGS} and @code{AM_CCASFLAGS} (or its per-target
6416 definition) is passed to the compilation.  For preprocessed files,
6417 @code{DEFS}, @code{DEFAULT_INCLUDES}, @code{INCLUDES}, @code{CPPFLAGS}
6418 and @code{AM_CPPFLAGS} are also used.
6419
6420 The autoconf macro @code{AM_PROG_AS} will define @code{CCAS} and
6421 @code{CCASFLAGS} for you (unless they are already set, it simply sets
6422 @code{CCAS} to the C compiler and @code{CCASFLAGS} to the C compiler
6423 flags), but you are free to define these variables by other means.
6424
6425 Only the suffixes @file{.s}, @file{.S}, and @file{.sx} are recognized by
6426 @command{automake} as being files containing assembly code.
6427
6428
6429 @node Fortran 77 Support
6430 @comment  node-name,  next,  previous,  up
6431 @section Fortran 77 Support
6432
6433 @cindex Fortran 77 support
6434 @cindex Support for Fortran 77
6435
6436 Automake includes full support for Fortran 77.
6437
6438 Any package including Fortran 77 code must define the output variable
6439 @code{F77} in @file{configure.ac}; the simplest way to do this is to use
6440 the @code{AC_PROG_F77} macro (@pxref{Particular Programs, , Particular
6441 Program Checks, autoconf, The Autoconf Manual}).
6442
6443 A few additional variables are defined when a Fortran 77 source file is
6444 seen:
6445
6446 @vtable @code
6447
6448 @item F77
6449 The name of the Fortran 77 compiler.
6450
6451 @item FFLAGS
6452 Any flags to pass to the Fortran 77 compiler.
6453
6454 @item AM_FFLAGS
6455 The maintainer's variant of @code{FFLAGS}.
6456
6457 @item RFLAGS
6458 Any flags to pass to the Ratfor compiler.
6459
6460 @item AM_RFLAGS
6461 The maintainer's variant of @code{RFLAGS}.
6462
6463 @item F77COMPILE
6464 The command used to actually compile a Fortran 77 source file.  The file
6465 name is appended to form the complete command line.
6466
6467 @item FLINK
6468 The command used to actually link a pure Fortran 77 program or shared
6469 library.
6470
6471 @end vtable
6472
6473 Automake can handle preprocessing Fortran 77 and Ratfor source files in
6474 addition to compiling them@footnote{Much, if not most, of the
6475 information in the following sections pertaining to preprocessing
6476 Fortran 77 programs was taken almost verbatim from @ref{Catalogue of
6477 Rules, , Catalogue of Rules, make, The GNU Make Manual}.}.  Automake
6478 also contains some support for creating programs and shared libraries
6479 that are a mixture of Fortran 77 and other languages (@pxref{Mixing
6480 Fortran 77 With C and C++}).
6481
6482 These issues are covered in the following sections.
6483
6484 @menu
6485 * Preprocessing Fortran 77::    Preprocessing Fortran 77 sources
6486 * Compiling Fortran 77 Files::  Compiling Fortran 77 sources
6487 * Mixing Fortran 77 With C and C++::  Mixing Fortran 77 With C and C++
6488 @end menu
6489
6490
6491 @node Preprocessing Fortran 77
6492 @comment  node-name,  next,  previous,  up
6493 @subsection Preprocessing Fortran 77
6494
6495 @cindex Preprocessing Fortran 77
6496 @cindex Fortran 77, Preprocessing
6497 @cindex Ratfor programs
6498
6499 @file{N.f} is made automatically from @file{N.F} or @file{N.r}.  This
6500 rule runs just the preprocessor to convert a preprocessable Fortran 77
6501 or Ratfor source file into a strict Fortran 77 source file.  The precise
6502 command used is as follows:
6503
6504 @table @file
6505
6506 @item .F
6507 @code{$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6508 $(AM_FFLAGS) $(FFLAGS)}
6509
6510 @item .r
6511 @code{$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6512
6513 @end table
6514
6515
6516 @node Compiling Fortran 77 Files
6517 @comment  node-name,  next,  previous,  up
6518 @subsection Compiling Fortran 77 Files
6519
6520 @file{N.o} is made automatically from @file{N.f}, @file{N.F} or
6521 @file{N.r} by running the Fortran 77 compiler.  The precise command used
6522 is as follows:
6523
6524 @table @file
6525
6526 @item .f
6527 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS)}
6528
6529 @item .F
6530 @code{$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS)@*
6531 $(AM_FFLAGS) $(FFLAGS)}
6532
6533 @item .r
6534 @code{$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)}
6535
6536 @end table
6537
6538
6539 @node Mixing Fortran 77 With C and C++
6540 @comment  node-name,  next,  previous,  up
6541 @subsection Mixing Fortran 77 With C and C++
6542
6543 @cindex Fortran 77, mixing with C and C++
6544 @cindex Mixing Fortran 77 with C and C++
6545 @cindex Linking Fortran 77 with C and C++
6546 @cindex cfortran
6547 @cindex Mixing Fortran 77 with C and/or C++
6548
6549 Automake currently provides @emph{limited} support for creating programs
6550 and shared libraries that are a mixture of Fortran 77 and C and/or C++.
6551 However, there are many other issues related to mixing Fortran 77 with
6552 other languages that are @emph{not} (currently) handled by Automake, but
6553 that are handled by other packages@footnote{For example,
6554 @uref{http://www-zeus.desy.de/~burow/cfortran/, the cfortran package}
6555 addresses all of these inter-language issues, and runs under nearly all
6556 Fortran 77, C and C++ compilers on nearly all platforms.  However,
6557 @command{cfortran} is not yet Free Software, but it will be in the next
6558 major release.}.
6559
6560 Automake can help in two ways:
6561
6562 @enumerate
6563 @item
6564 Automatic selection of the linker depending on which combinations of
6565 source code.
6566
6567 @item
6568 Automatic selection of the appropriate linker flags (e.g., @option{-L} and
6569 @option{-l}) to pass to the automatically selected linker in order to link
6570 in the appropriate Fortran 77 intrinsic and run-time libraries.
6571
6572 @cindex @code{FLIBS}, defined
6573 @vindex FLIBS
6574 These extra Fortran 77 linker flags are supplied in the output variable
6575 @code{FLIBS} by the @code{AC_F77_LIBRARY_LDFLAGS} Autoconf macro.
6576 @xref{Fortran Compiler, , Fortran Compiler Characteristics, autoconf,
6577 The Autoconf Manual}.
6578 @end enumerate
6579
6580 If Automake detects that a program or shared library (as mentioned in
6581 some @code{_PROGRAMS} or @code{_LTLIBRARIES} primary) contains source
6582 code that is a mixture of Fortran 77 and C and/or C++, then it requires
6583 that the macro @code{AC_F77_LIBRARY_LDFLAGS} be called in
6584 @file{configure.ac}, and that either @code{$(FLIBS)}
6585 appear in the appropriate @code{_LDADD} (for programs) or @code{_LIBADD}
6586 (for shared libraries) variables.  It is the responsibility of the
6587 person writing the @file{Makefile.am} to make sure that @samp{$(FLIBS)}
6588 appears in the appropriate @code{_LDADD} or
6589 @code{_LIBADD} variable.
6590
6591 @cindex Mixed language example
6592 @cindex Example, mixed language
6593
6594 For example, consider the following @file{Makefile.am}:
6595
6596 @example
6597 bin_PROGRAMS = foo
6598 foo_SOURCES  = main.cc foo.f
6599 foo_LDADD    = libfoo.la $(FLIBS)
6600
6601 pkglib_LTLIBRARIES = libfoo.la
6602 libfoo_la_SOURCES  = bar.f baz.c zardoz.cc
6603 libfoo_la_LIBADD   = $(FLIBS)
6604 @end example
6605
6606 In this case, Automake will insist that @code{AC_F77_LIBRARY_LDFLAGS}
6607 is mentioned in @file{configure.ac}.  Also, if @samp{$(FLIBS)} hadn't
6608 been mentioned in @code{foo_LDADD} and @code{libfoo_la_LIBADD}, then
6609 Automake would have issued a warning.
6610
6611 @menu
6612 * How the Linker is Chosen::    Automatic linker selection
6613 @end menu
6614
6615 @node How the Linker is Chosen
6616 @comment  node-name,  next,  previous,  up
6617 @subsubsection How the Linker is Chosen
6618
6619 @cindex Automatic linker selection
6620 @cindex Selecting the linker automatically
6621
6622 When a program or library mixes several languages, Automake choose the
6623 linker according to the following priorities.  (The names in
6624 parentheses are the variables containing the link command.)
6625
6626 @enumerate
6627 @item
6628 @vindex GCJLINK
6629 Native Java (@code{GCJLINK})
6630 @item
6631 @vindex OBJCXXLINK
6632 Objective C++ (@code{OBJCXXLINK})
6633 @item
6634 @vindex CXXLINK
6635 C++ (@code{CXXLINK})
6636 @item
6637 @vindex F77LINK
6638 Fortran 77 (@code{F77LINK})
6639 @item
6640 @vindex FCLINK
6641 Fortran (@code{FCLINK})
6642 @item
6643 @vindex OBJCLINK
6644 Objective C (@code{OBJCLINK})
6645 @item
6646 @vindex UPCLINK
6647 Unified Parallel C (@code{UPCLINK})
6648 @item
6649 @vindex LINK
6650 C (@code{LINK})
6651 @end enumerate
6652
6653 For example, if Fortran 77, C and C++ source code is compiled
6654 into a program, then the C++ linker will be used.  In this case, if the
6655 C or Fortran 77 linkers required any special libraries that weren't
6656 included by the C++ linker, then they must be manually added to an
6657 @code{_LDADD} or @code{_LIBADD} variable by the user writing the
6658 @file{Makefile.am}.
6659
6660 Automake only looks at the file names listed in @file{_SOURCES}
6661 variables to choose the linker, and defaults to the C linker.
6662 Sometimes this is inconvenient because you are linking against a
6663 library written in another language and would like to set the linker
6664 more appropriately.  @xref{Libtool Convenience Libraries}, for a
6665 trick with @code{nodist_EXTRA_@dots{}_SOURCES}.
6666
6667 A per-target @code{_LINK} variable will override the above selection.
6668 Per-target link flags will cause Automake to write a per-target
6669 @code{_LINK} variable according to the language chosen as above.
6670
6671
6672 @node Fortran 9x Support
6673 @comment  node-name,  next,  previous,  up
6674 @section Fortran 9x Support
6675
6676 @cindex Fortran 9x support
6677 @cindex Support for Fortran 9x
6678
6679 Automake includes support for Fortran 9x.
6680
6681 Any package including Fortran 9x code must define the output variable
6682 @code{FC} in @file{configure.ac}; the simplest way to do this is to use
6683 the @code{AC_PROG_FC} macro (@pxref{Particular Programs, , Particular
6684 Program Checks, autoconf, The Autoconf Manual}).
6685
6686 A few additional variables are defined when a Fortran 9x source file is
6687 seen:
6688
6689 @vtable @code
6690
6691 @item FC
6692 The name of the Fortran 9x compiler.
6693
6694 @item FCFLAGS
6695 Any flags to pass to the Fortran 9x compiler.
6696
6697 @item AM_FCFLAGS
6698 The maintainer's variant of @code{FCFLAGS}.
6699
6700 @item FCCOMPILE
6701 The command used to actually compile a Fortran 9x source file.  The file
6702 name is appended to form the complete command line.
6703
6704 @item FCLINK
6705 The command used to actually link a pure Fortran 9x program or shared
6706 library.
6707
6708 @end vtable
6709
6710 @menu
6711 * Compiling Fortran 9x Files::  Compiling Fortran 9x sources
6712 @end menu
6713
6714 @node Compiling Fortran 9x Files
6715 @comment  node-name,  next,  previous,  up
6716 @subsection Compiling Fortran 9x Files
6717
6718 @file{@var{file}.o} is made automatically from @file{@var{file}.f90},
6719 @file{@var{file}.f95}, @file{@var{file}.f03}, or @file{@var{file}.f08}
6720 by running the Fortran 9x compiler.  The precise command used
6721 is as follows:
6722
6723 @table @file
6724
6725 @item .f90
6726 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f90) $<}
6727
6728 @item .f95
6729 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f95) $<}
6730
6731 @item .f03
6732 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f03) $<}
6733
6734 @item .f08
6735 @code{$(FC) $(AM_FCFLAGS) $(FCFLAGS) -c $(FCFLAGS_f08) $<}
6736
6737 @end table
6738
6739 @node Java Support with gcj
6740 @comment  node-name,  next,  previous,  up
6741 @section Compiling Java sources using gcj
6742
6743 @cindex Java support with gcj
6744 @cindex Support for Java with gcj
6745 @cindex Java to native code, compilation
6746 @cindex Compilation of Java to native code
6747
6748 Automake includes support for natively compiled Java, using @command{gcj},
6749 the Java front end to the GNU Compiler Collection (rudimentary support
6750 for compiling Java to bytecode using the @command{javac} compiler is
6751 also present, @emph{albeit deprecated}; @pxref{Java}).
6752
6753 Any package including Java code to be compiled must define the output
6754 variable @code{GCJ} in @file{configure.ac}; the variable @code{GCJFLAGS}
6755 must also be defined somehow (either in @file{configure.ac} or
6756 @file{Makefile.am}).  The simplest way to do this is to use the
6757 @code{AM_PROG_GCJ} macro.
6758
6759 @vindex GCJFLAGS
6760
6761 By default, programs including Java source files are linked with
6762 @command{gcj}.
6763
6764 As always, the contents of @code{AM_GCJFLAGS} are passed to every
6765 compilation invoking @command{gcj} (in its role as an ahead-of-time
6766 compiler, when invoking it to create @file{.class} files,
6767 @code{AM_JAVACFLAGS} is used instead).  If it is necessary to pass
6768 options to @command{gcj} from @file{Makefile.am}, this variable, and not
6769 the user variable @code{GCJFLAGS}, should be used.
6770
6771 @vindex AM_GCJFLAGS
6772
6773 @command{gcj} can be used to compile @file{.java}, @file{.class},
6774 @file{.zip}, or @file{.jar} files.
6775
6776 When linking, @command{gcj} requires that the main class be specified
6777 using the @option{--main=} option.  The easiest way to do this is to use
6778 the @code{_LDFLAGS} variable for the program.
6779
6780
6781 @node Vala Support
6782 @comment  node-name,  next,  previous,  up
6783 @section Vala Support
6784
6785 @cindex Vala Support
6786 @cindex Support for Vala
6787
6788 Automake provides initial support for Vala
6789 (@uref{http://www.vala-project.org/}).
6790 This requires valac version 0.7.0 or later, and currently requires
6791 the user to use GNU @command{make}.
6792
6793 @example
6794 foo_SOURCES = foo.vala bar.vala zardoc.c
6795 @end example
6796
6797 Any @file{.vala} file listed in a @code{_SOURCES} variable will be
6798 compiled into C code by the Vala compiler. The generated @file{.c} files are
6799 distributed. The end user does not need to have a Vala compiler installed.
6800
6801 Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
6802 that will locate the Vala compiler and optionally check its version
6803 number.
6804
6805 @defmac AM_PROG_VALAC (@ovar{minimum-version})
6806 Try to find a Vala compiler in @env{PATH}. If it is found, the variable
6807 @code{VALAC} is set. Optionally a minimum release number of the compiler
6808 can be requested:
6809
6810 @example
6811 AM_PROG_VALAC([0.7.0])
6812 @end example
6813 @end defmac
6814
6815 There are a few variables that are used when compiling Vala sources:
6816
6817 @vtable @code
6818 @item VALAC
6819 Path to the Vala compiler.
6820
6821 @item VALAFLAGS
6822 Additional arguments for the Vala compiler.
6823
6824 @item AM_VALAFLAGS
6825 The maintainer's variant of @code{VALAFLAGS}.
6826
6827 @example
6828 lib_LTLIBRARIES = libfoo.la
6829 libfoo_la_SOURCES = foo.vala
6830 @end example
6831 @end vtable
6832
6833 Note that currently, you cannot use per-target @code{*_VALAFLAGS}
6834 (@pxref{Renamed Objects}) to produce different C files from one Vala
6835 source file.
6836
6837
6838 @node Support for Other Languages
6839 @comment  node-name,  next,  previous,  up
6840 @section Support for Other Languages
6841
6842 Automake currently only includes full support for C, C++ (@pxref{C++
6843 Support}), Objective C (@pxref{Objective C Support}),
6844 Objective C++ (@pxref{Objective C++ Support}),
6845 Fortran 77
6846 (@pxref{Fortran 77 Support}), Fortran 9x (@pxref{Fortran 9x Support}),
6847 and Java (@pxref{Java Support with gcj}).  There is only rudimentary
6848 support for other languages, support for which will be improved based
6849 on user demand.
6850
6851 Some limited support for adding your own languages is available via the
6852 suffix rule handling (@pxref{Suffixes}).
6853
6854 @node Dependencies
6855 @section Automatic dependency tracking
6856
6857 As a developer it is often painful to continually update the
6858 @file{Makefile.am} whenever the include-file dependencies change in a
6859 project.  Automake supplies a way to automatically track dependency
6860 changes (@pxref{Dependency Tracking}).
6861
6862 @cindex Dependency tracking
6863 @cindex Automatic dependency tracking
6864
6865 Automake always uses complete dependencies for a compilation,
6866 including system headers.  Automake's model is that dependency
6867 computation should be a side effect of the build.  To this end,
6868 dependencies are computed by running all compilations through a
6869 special wrapper program called @command{depcomp}.  @command{depcomp}
6870 understands how to coax many different C and C++ compilers into
6871 generating dependency information in the format it requires.
6872 @samp{automake -a} will install @command{depcomp} into your source
6873 tree for you.  If @command{depcomp} can't figure out how to properly
6874 invoke your compiler, dependency tracking will simply be disabled for
6875 your build.
6876
6877 @cindex @command{depcomp}
6878
6879 Experience with earlier versions of Automake (@pxref{Dependency Tracking
6880 Evolution, , Dependency Tracking Evolution, automake-history, Brief History
6881 of Automake}) taught us that it is not reliable to generate dependencies
6882 only on the maintainer's system, as configurations vary too much.  So
6883 instead Automake implements dependency tracking at build time.
6884
6885 Automatic dependency tracking can be suppressed by putting
6886 @option{no-dependencies} in the variable @code{AUTOMAKE_OPTIONS}, or
6887 passing @option{no-dependencies} as an argument to @code{AM_INIT_AUTOMAKE}
6888 (this should be the preferred way).  Or, you can invoke @command{automake}
6889 with the @option{-i} option.  Dependency tracking is enabled by default.
6890
6891 @vindex AUTOMAKE_OPTIONS
6892 @opindex no-dependencies
6893
6894 The person building your package also can choose to disable dependency
6895 tracking by configuring with @option{--disable-dependency-tracking}.
6896
6897 @cindex Disabling dependency tracking
6898 @cindex Dependency tracking, disabling
6899
6900
6901 @node EXEEXT
6902 @section Support for executable extensions
6903
6904 @cindex Executable extension
6905 @cindex Extension, executable
6906 @cindex Windows
6907
6908 On some platforms, such as Windows, executables are expected to have an
6909 extension such as @file{.exe}.  On these platforms, some compilers (GCC
6910 among them) will automatically generate @file{foo.exe} when asked to
6911 generate @file{foo}.
6912
6913 Automake provides mostly-transparent support for this.  Unfortunately
6914 @emph{mostly} doesn't yet mean @emph{fully}.  Until the English
6915 dictionary is revised, you will have to assist Automake if your package
6916 must support those platforms.
6917
6918 One thing you must be aware of is that, internally, Automake rewrites
6919 something like this:
6920
6921 @example
6922 bin_PROGRAMS = liver
6923 @end example
6924
6925 to this:
6926
6927 @example
6928 bin_PROGRAMS = liver$(EXEEXT)
6929 @end example
6930
6931 The targets Automake generates are likewise given the @samp{$(EXEEXT)}
6932 extension.
6933
6934 The variables @code{TESTS} and @code{XFAIL_TESTS} (@pxref{Simple Tests})
6935 are also rewritten if they contain filenames that have been declared as
6936 programs in the same @file{Makefile}.  (This is mostly useful when some
6937 programs from @code{check_PROGRAMS} are listed in @code{TESTS}.)
6938
6939 However, Automake cannot apply this rewriting to @command{configure}
6940 substitutions.  This means that if you are conditionally building a
6941 program using such a substitution, then your @file{configure.ac} must
6942 take care to add @samp{$(EXEEXT)} when constructing the output variable.
6943
6944 Sometimes maintainers like to write an explicit link rule for their
6945 program.  Without executable extension support, this is easy---you
6946 simply write a rule whose target is the name of the program.  However,
6947 when executable extension support is enabled, you must instead add the
6948 @samp{$(EXEEXT)} suffix.
6949
6950 This might be a nuisance for maintainers who know their package will
6951 never run on a platform that has
6952 executable extensions.  For those maintainers, the @option{no-exeext}
6953 option (@pxref{Options}) will disable this feature.  This works in a
6954 fairly ugly way; if @option{no-exeext} is seen, then the presence of a
6955 rule for a target named @code{foo} in @file{Makefile.am} will override
6956 an @command{automake}-generated rule for @samp{foo$(EXEEXT)}.  Without
6957 the @option{no-exeext} option, this use will give a diagnostic.
6958
6959
6960 @node Other Objects
6961 @chapter Other Derived Objects
6962
6963 Automake can handle derived objects that are not C programs.  Sometimes
6964 the support for actually building such objects must be explicitly
6965 supplied, but Automake will still automatically handle installation and
6966 distribution.
6967
6968 @menu
6969 * Scripts::                     Executable scripts
6970 * Headers::                     Header files
6971 * Data::                        Architecture-independent data files
6972 * Sources::                     Derived sources
6973 @end menu
6974
6975
6976 @node Scripts
6977 @section Executable Scripts
6978
6979 @cindex @code{_SCRIPTS} primary, defined
6980 @cindex @code{SCRIPTS} primary, defined
6981 @cindex Primary variable, @code{SCRIPTS}
6982 @vindex _SCRIPTS
6983 @cindex Installing scripts
6984
6985 It is possible to define and install programs that are scripts.  Such
6986 programs are listed using the @code{SCRIPTS} primary name.  When the
6987 script is distributed in its final, installable form, the
6988 @file{Makefile} usually looks as follows:
6989 @vindex SCRIPTS
6990
6991 @example
6992 # Install my_script in $(bindir) and distribute it.
6993 dist_bin_SCRIPTS = my_script
6994 @end example
6995
6996 Scripts are not distributed by default; as we have just seen, those
6997 that should be distributed can be specified using a @code{dist_}
6998 prefix as with other primaries.
6999
7000 @cindex @code{SCRIPTS}, installation directories
7001 @vindex bin_SCRIPTS
7002 @vindex sbin_SCRIPTS
7003 @vindex libexec_SCRIPTS
7004 @vindex pkgdata_SCRIPTS
7005 @vindex pkglibexec_SCRIPTS
7006 @vindex noinst_SCRIPTS
7007 @vindex check_SCRIPTS
7008
7009 Scripts can be installed in @code{bindir}, @code{sbindir},
7010 @code{libexecdir}, @code{pkglibexecdir}, or @code{pkgdatadir}.
7011
7012 Scripts that need not be installed can be listed in
7013 @code{noinst_SCRIPTS}, and among them, those which are needed only by
7014 @samp{make check} should go in @code{check_SCRIPTS}.
7015
7016 When a script needs to be built, the @file{Makefile.am} should include
7017 the appropriate rules.  For instance the @command{automake} program
7018 itself is a Perl script that is generated from @file{automake.in}.
7019 Here is how this is handled:
7020
7021 @example
7022 bin_SCRIPTS = automake
7023 CLEANFILES = $(bin_SCRIPTS)
7024 EXTRA_DIST = automake.in
7025
7026 do_subst = sed -e 's,[@@]datadir[@@],$(datadir),g' \
7027             -e 's,[@@]PERL[@@],$(PERL),g' \
7028             -e 's,[@@]PACKAGE[@@],$(PACKAGE),g' \
7029             -e 's,[@@]VERSION[@@],$(VERSION),g' \
7030             @dots{}
7031
7032 automake: automake.in Makefile
7033         $(do_subst) < $(srcdir)/automake.in > automake
7034         chmod +x automake
7035 @end example
7036
7037 Such scripts for which a build rule has been supplied need to be
7038 deleted explicitly using @code{CLEANFILES} (@pxref{Clean}), and their
7039 sources have to be distributed, usually with @code{EXTRA_DIST}
7040 (@pxref{Basics of Distribution}).
7041
7042 Another common way to build scripts is to process them from
7043 @file{configure} with @code{AC_CONFIG_FILES}.  In this situation
7044 Automake knows which files should be cleaned and distributed, and what
7045 the rebuild rules should look like.
7046
7047 For instance if @file{configure.ac} contains
7048
7049 @example
7050 AC_CONFIG_FILES([src/my_script], [chmod +x src/my_script])
7051 @end example
7052
7053 @noindent
7054 to build @file{src/my_script} from @file{src/my_script.in}, then a
7055 @file{src/Makefile.am} to install this script in @code{$(bindir)} can
7056 be as simple as
7057
7058 @example
7059 bin_SCRIPTS = my_script
7060 CLEANFILES = $(bin_SCRIPTS)
7061 @end example
7062
7063 @noindent
7064 There is no need for @code{EXTRA_DIST} or any build rule: Automake
7065 infers them from @code{AC_CONFIG_FILES} (@pxref{Requirements}).
7066 @code{CLEANFILES} is still useful, because by default Automake will
7067 clean targets of @code{AC_CONFIG_FILES} in @code{distclean}, not
7068 @code{clean}.
7069
7070 Although this looks simpler, building scripts this way has one
7071 drawback: directory variables such as @code{$(datadir)} are not fully
7072 expanded and may refer to other directory variables.
7073
7074 @node Headers
7075 @section Header files
7076
7077 @cindex @code{_HEADERS} primary, defined
7078 @cindex @code{HEADERS} primary, defined
7079 @cindex Primary variable, @code{HEADERS}
7080 @vindex _HEADERS
7081 @vindex noinst_HEADERS
7082 @cindex @code{HEADERS}, installation directories
7083 @cindex Installing headers
7084 @vindex include_HEADERS
7085 @vindex oldinclude_HEADERS
7086 @vindex pkginclude_HEADERS
7087
7088
7089 Header files that must be installed are specified by the
7090 @code{HEADERS} family of variables.  Headers can be installed in
7091 @code{includedir}, @code{oldincludedir}, @code{pkgincludedir} or any
7092 other directory you may have defined (@pxref{Uniform}).  For instance,
7093
7094 @example
7095 include_HEADERS = foo.h bar/bar.h
7096 @end example
7097
7098 @noindent
7099 will install the two files as @file{$(includedir)/foo.h} and
7100 @file{$(includedir)/bar.h}.
7101
7102 The @code{nobase_} prefix is also supported,
7103
7104 @example
7105 nobase_include_HEADERS = foo.h bar/bar.h
7106 @end example
7107
7108 @noindent
7109 will install the two files as @file{$(includedir)/foo.h} and
7110 @file{$(includedir)/bar/bar.h} (@pxref{Alternative}).
7111
7112 @vindex noinst_HEADERS
7113 Usually, only header files that accompany installed libraries need to
7114 be installed.  Headers used by programs or convenience libraries are
7115 not installed.  The @code{noinst_HEADERS} variable can be used for
7116 such headers.  However when the header actually belongs to a single
7117 convenience library or program, we recommend listing it in the
7118 program's or library's @code{_SOURCES} variable (@pxref{Program
7119 Sources}) instead of in @code{noinst_HEADERS}.  This is clearer for
7120 the @file{Makefile.am} reader.  @code{noinst_HEADERS} would be the
7121 right variable to use in a directory containing only headers and no
7122 associated library or program.
7123
7124 All header files must be listed somewhere; in a @code{_SOURCES}
7125 variable or in a @code{_HEADERS} variable.  Missing ones will not
7126 appear in the distribution.
7127
7128 For header files that are built and must not be distributed, use the
7129 @code{nodist_} prefix as in @code{nodist_include_HEADERS} or
7130 @code{nodist_prog_SOURCES}.  If these generated headers are needed
7131 during the build, you must also ensure they exist before they are
7132 used (@pxref{Sources}).
7133
7134
7135 @node Data
7136 @section Architecture-independent data files
7137
7138 @cindex @code{_DATA} primary, defined
7139 @cindex @code{DATA} primary, defined
7140 @cindex Primary variable, @code{DATA}
7141 @vindex _DATA
7142
7143 Automake supports the installation of miscellaneous data files using the
7144 @code{DATA} family of variables.
7145 @vindex DATA
7146
7147 @vindex data_DATA
7148 @vindex sysconf_DATA
7149 @vindex sharedstate_DATA
7150 @vindex localstate_DATA
7151 @vindex pkgdata_DATA
7152
7153 Such data can be installed in the directories @code{datadir},
7154 @code{sysconfdir}, @code{sharedstatedir}, @code{localstatedir}, or
7155 @code{pkgdatadir}.
7156
7157 By default, data files are @emph{not} included in a distribution.  Of
7158 course, you can use the @code{dist_} prefix to change this on a
7159 per-variable basis.
7160
7161 Here is how Automake declares its auxiliary data files:
7162
7163 @example
7164 dist_pkgdata_DATA = clean-kr.am clean.am @dots{}
7165 @end example
7166
7167
7168 @node Sources
7169 @section Built Sources
7170
7171 Because Automake's automatic dependency tracking works as a side-effect
7172 of compilation (@pxref{Dependencies}) there is a bootstrap issue: a
7173 target should not be compiled before its dependencies are made, but
7174 these dependencies are unknown until the target is first compiled.
7175
7176 Ordinarily this is not a problem, because dependencies are distributed
7177 sources: they preexist and do not need to be built.  Suppose that
7178 @file{foo.c} includes @file{foo.h}.  When it first compiles
7179 @file{foo.o}, @command{make} only knows that @file{foo.o} depends on
7180 @file{foo.c}.  As a side-effect of this compilation @command{depcomp}
7181 records the @file{foo.h} dependency so that following invocations of
7182 @command{make} will honor it.  In these conditions, it's clear there is
7183 no problem: either @file{foo.o} doesn't exist and has to be built
7184 (regardless of the dependencies), or accurate dependencies exist and
7185 they can be used to decide whether @file{foo.o} should be rebuilt.
7186
7187 It's a different story if @file{foo.h} doesn't exist by the first
7188 @command{make} run.  For instance, there might be a rule to build
7189 @file{foo.h}.  This time @file{file.o}'s build will fail because the
7190 compiler can't find @file{foo.h}.  @command{make} failed to trigger the
7191 rule to build @file{foo.h} first by lack of dependency information.
7192
7193 @vindex BUILT_SOURCES
7194 @cindex @code{BUILT_SOURCES}, defined
7195
7196 The @code{BUILT_SOURCES} variable is a workaround for this problem.  A
7197 source file listed in @code{BUILT_SOURCES} is made on @samp{make all}
7198 or @samp{make check} (or even @samp{make install}) before other
7199 targets are processed.  However, such a source file is not
7200 @emph{compiled} unless explicitly requested by mentioning it in some
7201 other @code{_SOURCES} variable.
7202
7203 So, to conclude our introductory example, we could use
7204 @samp{BUILT_SOURCES = foo.h} to ensure @file{foo.h} gets built before
7205 any other target (including @file{foo.o}) during @samp{make all} or
7206 @samp{make check}.
7207
7208 @code{BUILT_SOURCES} is actually a bit of a misnomer, as any file which
7209 must be created early in the build process can be listed in this
7210 variable.  Moreover, all built sources do not necessarily have to be
7211 listed in @code{BUILT_SOURCES}.  For instance, a generated @file{.c} file
7212 doesn't need to appear in @code{BUILT_SOURCES} (unless it is included by
7213 another source), because it's a known dependency of the associated
7214 object.
7215
7216 It might be important to emphasize that @code{BUILT_SOURCES} is
7217 honored only by @samp{make all}, @samp{make check} and @samp{make
7218 install}.  This means you cannot build a specific target (e.g.,
7219 @samp{make foo}) in a clean tree if it depends on a built source.
7220 However it will succeed if you have run @samp{make all} earlier,
7221 because accurate dependencies are already available.
7222
7223 The next section illustrates and discusses the handling of built sources
7224 on a toy example.
7225
7226 @menu
7227 * Built Sources Example::       Several ways to handle built sources.
7228 @end menu
7229
7230 @node Built Sources Example
7231 @subsection Built Sources Example
7232
7233 Suppose that @file{foo.c} includes @file{bindir.h}, which is
7234 installation-dependent and not distributed: it needs to be built.  Here
7235 @file{bindir.h} defines the preprocessor macro @code{bindir} to the
7236 value of the @command{make} variable @code{bindir} (inherited from
7237 @file{configure}).
7238
7239 We suggest several implementations below.  It's not meant to be an
7240 exhaustive listing of all ways to handle built sources, but it will give
7241 you a few ideas if you encounter this issue.
7242
7243 @subsubheading First Try
7244
7245 This first implementation will illustrate the bootstrap issue mentioned
7246 in the previous section (@pxref{Sources}).
7247
7248 Here is a tentative @file{Makefile.am}.
7249
7250 @example
7251 # This won't work.
7252 bin_PROGRAMS = foo
7253 foo_SOURCES = foo.c
7254 nodist_foo_SOURCES = bindir.h
7255 CLEANFILES = bindir.h
7256 bindir.h: Makefile
7257         echo '#define bindir "$(bindir)"' >$@@
7258 @end example
7259
7260 This setup doesn't work, because Automake doesn't know that @file{foo.c}
7261 includes @file{bindir.h}.  Remember, automatic dependency tracking works
7262 as a side-effect of compilation, so the dependencies of @file{foo.o} will
7263 be known only after @file{foo.o} has been compiled (@pxref{Dependencies}).
7264 The symptom is as follows.
7265
7266 @example
7267 % make
7268 source='foo.c' object='foo.o' libtool=no \
7269 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7270 depmode=gcc /bin/sh ./depcomp \
7271 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7272 foo.c:2: bindir.h: No such file or directory
7273 make: *** [foo.o] Error 1
7274 @end example
7275
7276 In this example @file{bindir.h} is not distributed nor installed, and
7277 it is not even being built on-time.  One may wonder if the
7278 @samp{nodist_foo_SOURCES = bindir.h} line has any use at all.  This
7279 line simply states that @file{bindir.h} is a source of @code{foo}, so
7280 for instance, it should be inspected while generating tags
7281 (@pxref{Tags}).  In other words, it does not help our present problem,
7282 and the build would fail identically without it.
7283
7284 @subsubheading Using @code{BUILT_SOURCES}
7285
7286 A solution is to require @file{bindir.h} to be built before anything
7287 else.  This is what @code{BUILT_SOURCES} is meant for (@pxref{Sources}).
7288
7289 @example
7290 bin_PROGRAMS = foo
7291 foo_SOURCES = foo.c
7292 nodist_foo_SOURCES = bindir.h
7293 BUILT_SOURCES = bindir.h
7294 CLEANFILES = bindir.h
7295 bindir.h: Makefile
7296         echo '#define bindir "$(bindir)"' >$@@
7297 @end example
7298
7299 See how @file{bindir.h} gets built first:
7300
7301 @example
7302 % make
7303 echo '#define bindir "/usr/local/bin"' >bindir.h
7304 make  all-am
7305 make[1]: Entering directory `/home/adl/tmp'
7306 source='foo.c' object='foo.o' libtool=no \
7307 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7308 depmode=gcc /bin/sh ./depcomp \
7309 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7310 gcc  -g -O2   -o foo  foo.o
7311 make[1]: Leaving directory `/home/adl/tmp'
7312 @end example
7313
7314 However, as said earlier, @code{BUILT_SOURCES} applies only to the
7315 @code{all}, @code{check}, and @code{install} targets.  It still fails
7316 if you try to run @samp{make foo} explicitly:
7317
7318 @example
7319 % make clean
7320 test -z "bindir.h" || rm -f bindir.h
7321 test -z "foo" || rm -f foo
7322 rm -f *.o
7323 % : > .deps/foo.Po # Suppress previously recorded dependencies
7324 % make foo
7325 source='foo.c' object='foo.o' libtool=no \
7326 depfile='.deps/foo.Po' tmpdepfile='.deps/foo.TPo' \
7327 depmode=gcc /bin/sh ./depcomp \
7328 gcc -I. -I. -g -O2 -c `test -f 'foo.c' || echo './'`foo.c
7329 foo.c:2: bindir.h: No such file or directory
7330 make: *** [foo.o] Error 1
7331 @end example
7332
7333 @subsubheading Recording Dependencies manually
7334
7335 Usually people are happy enough with @code{BUILT_SOURCES} because they
7336 never build targets such as @samp{make foo} before @samp{make all}, as
7337 in the previous example.  However if this matters to you, you can
7338 avoid @code{BUILT_SOURCES} and record such dependencies explicitly in
7339 the @file{Makefile.am}.
7340
7341 @example
7342 bin_PROGRAMS = foo
7343 foo_SOURCES = foo.c
7344 nodist_foo_SOURCES = bindir.h
7345 foo.$(OBJEXT): bindir.h
7346 CLEANFILES = bindir.h
7347 bindir.h: Makefile
7348         echo '#define bindir "$(bindir)"' >$@@
7349 @end example
7350
7351 You don't have to list @emph{all} the dependencies of @file{foo.o}
7352 explicitly, only those that might need to be built.  If a dependency
7353 already exists, it will not hinder the first compilation and will be
7354 recorded by the normal dependency tracking code.  (Note that after
7355 this first compilation the dependency tracking code will also have
7356 recorded the dependency between @file{foo.o} and
7357 @file{bindir.h}; so our explicit dependency is really useful to
7358 the first build only.)
7359
7360 Adding explicit dependencies like this can be a bit dangerous if you are
7361 not careful enough.  This is due to the way Automake tries not to
7362 overwrite your rules (it assumes you know better than it).
7363 @samp{foo.$(OBJEXT): bindir.h} supersedes any rule Automake may want to
7364 output to build @samp{foo.$(OBJEXT)}.  It happens to work in this case
7365 because Automake doesn't have to output any @samp{foo.$(OBJEXT):}
7366 target: it relies on a suffix rule instead (i.e., @samp{.c.$(OBJEXT):}).
7367 Always check the generated @file{Makefile.in} if you do this.
7368
7369 @subsubheading Build @file{bindir.h} from @file{configure}
7370
7371 It's possible to define this preprocessor macro from @file{configure},
7372 either in @file{config.h} (@pxref{Defining Directories, , Defining
7373 Directories, autoconf, The Autoconf Manual}), or by processing a
7374 @file{bindir.h.in} file using @code{AC_CONFIG_FILES}
7375 (@pxref{Configuration Actions, ,Configuration Actions, autoconf, The
7376 Autoconf Manual}).
7377
7378 At this point it should be clear that building @file{bindir.h} from
7379 @file{configure} works well for this example.  @file{bindir.h} will exist
7380 before you build any target, hence will not cause any dependency issue.
7381
7382 The Makefile can be shrunk as follows.  We do not even have to mention
7383 @file{bindir.h}.
7384
7385 @example
7386 bin_PROGRAMS = foo
7387 foo_SOURCES = foo.c
7388 @end example
7389
7390 However, it's not always possible to build sources from
7391 @file{configure}, especially when these sources are generated by a tool
7392 that needs to be built first.
7393
7394 @subsubheading Build @file{bindir.c}, not @file{bindir.h}.
7395
7396 Another attractive idea is to define @code{bindir} as a variable or
7397 function exported from @file{bindir.o}, and build @file{bindir.c}
7398 instead of @file{bindir.h}.
7399
7400 @example
7401 noinst_PROGRAMS = foo
7402 foo_SOURCES = foo.c bindir.h
7403 nodist_foo_SOURCES = bindir.c
7404 CLEANFILES = bindir.c
7405 bindir.c: Makefile
7406         echo 'const char bindir[] = "$(bindir)";' >$@@
7407 @end example
7408
7409 @file{bindir.h} contains just the variable's declaration and doesn't
7410 need to be built, so it won't cause any trouble.  @file{bindir.o} is
7411 always dependent on @file{bindir.c}, so @file{bindir.c} will get built
7412 first.
7413
7414 @subsubheading Which is best?
7415
7416 There is no panacea, of course.  Each solution has its merits and
7417 drawbacks.
7418
7419 You cannot use @code{BUILT_SOURCES} if the ability to run @samp{make
7420 foo} on a clean tree is important to you.
7421
7422 You won't add explicit dependencies if you are leery of overriding
7423 an Automake rule by mistake.
7424
7425 Building files from @file{./configure} is not always possible, neither
7426 is converting @file{.h} files into @file{.c} files.
7427
7428
7429 @node Other GNU Tools
7430 @chapter Other GNU Tools
7431
7432 Since Automake is primarily intended to generate @file{Makefile.in}s for
7433 use in GNU programs, it tries hard to interoperate with other GNU tools.
7434
7435 @menu
7436 * Emacs Lisp::                  Emacs Lisp
7437 * gettext::                     Gettext
7438 * Libtool::                     Libtool
7439 * Java::                        Java bytecode compilation (deprecated)
7440 * Python::                      Python
7441 @end menu
7442
7443
7444 @node Emacs Lisp
7445 @section Emacs Lisp
7446
7447 @cindex @code{_LISP} primary, defined
7448 @cindex @code{LISP} primary, defined
7449 @cindex Primary variable, @code{LISP}
7450
7451 @vindex _LISP
7452 @vindex lisp_LISP
7453 @vindex noinst_LISP
7454
7455 Automake provides some support for Emacs Lisp.  The @code{LISP} primary
7456 is used to hold a list of @file{.el} files.  Possible prefixes for this
7457 primary are @code{lisp_} and @code{noinst_}.  Note that if
7458 @code{lisp_LISP} is defined, then @file{configure.ac} must run
7459 @code{AM_PATH_LISPDIR} (@pxref{Macros}).
7460
7461 @vindex dist_lisp_LISP
7462 @vindex dist_noinst_LISP
7463 Lisp sources are not distributed by default.  You can prefix the
7464 @code{LISP} primary with @code{dist_}, as in @code{dist_lisp_LISP} or
7465 @code{dist_noinst_LISP}, to indicate that these files should be
7466 distributed.
7467
7468 Automake will byte-compile all Emacs Lisp source files using the Emacs
7469 found by @code{AM_PATH_LISPDIR}, if any was found.
7470
7471 Byte-compiled Emacs Lisp files are not portable among all versions of
7472 Emacs, so it makes sense to turn this off if you expect sites to have
7473 more than one version of Emacs installed.  Furthermore, many packages
7474 don't actually benefit from byte-compilation.  Still, we recommend
7475 that you byte-compile your Emacs Lisp sources.  It is probably better
7476 for sites with strange setups to cope for themselves than to make the
7477 installation less nice for everybody else.
7478
7479 There are two ways to avoid byte-compiling.  Historically, we have
7480 recommended the following construct.
7481
7482 @example
7483 lisp_LISP = file1.el file2.el
7484 ELCFILES =
7485 @end example
7486
7487 @noindent
7488 @code{ELCFILES} is an internal Automake variable that normally lists
7489 all @file{.elc} files that must be byte-compiled.  Automake defines
7490 @code{ELCFILES} automatically from @code{lisp_LISP}.  Emptying this
7491 variable explicitly prevents byte-compilation.
7492
7493 Since Automake 1.8, we now recommend using @code{lisp_DATA} instead:
7494
7495 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7496 @example
7497 lisp_DATA = file1.el file2.el
7498 @end example
7499
7500 Note that these two constructs are not equivalent.  @code{_LISP} will
7501 not install a file if Emacs is not installed, while @code{_DATA} will
7502 always install its files.
7503
7504 @node gettext
7505 @section Gettext
7506
7507 @cindex GNU Gettext support
7508 @cindex Gettext support
7509 @cindex Support for GNU Gettext
7510
7511 If @code{AM_GNU_GETTEXT} is seen in @file{configure.ac}, then Automake
7512 turns on support for GNU gettext, a message catalog system for
7513 internationalization
7514 (@pxref{Top, , Introduction, gettext, GNU gettext utilities}).
7515
7516 The @code{gettext} support in Automake requires the addition of one or
7517 two subdirectories to the package: @file{po} and possibly also @file{intl}.
7518 The latter is needed if @code{AM_GNU_GETTEXT} is not invoked with the
7519 @samp{external} argument, or if @code{AM_GNU_GETTEXT_INTL_SUBDIR} is used.
7520 Automake ensures that these directories exist and are mentioned in
7521 @code{SUBDIRS}.
7522
7523 @node Libtool
7524 @section Libtool
7525
7526 Automake provides support for GNU Libtool (@pxref{Top, , Introduction,
7527 libtool, The Libtool Manual}) with the @code{LTLIBRARIES} primary.
7528 @xref{A Shared Library}.
7529
7530
7531 @node Java
7532 @section Java bytecode compilation (deprecated)
7533
7534 @cindex @code{_JAVA} primary, defined
7535 @cindex @code{JAVA} primary, defined
7536 @cindex Primary variable, @code{JAVA}
7537 @cindex Java to bytecode, compilation
7538 @cindex Compilation of Java to bytecode
7539
7540 Automake provides some minimal support for Java bytecode compilation with
7541 the @code{JAVA} primary (in addition to the support for compiling Java to
7542 native machine code; @pxref{Java Support with gcj}).  Note however that
7543 @emph{the interface and most features described here are deprecated}; the
7544 next automake release will strive to provide a better and cleaner
7545 interface, which however @emph{won't be backward-compatible}; the present
7546 interface will probably be removed altogether in future automake releases
7547 (1.13 or later), so don't use it in new code.
7548
7549 Any @file{.java} files listed in a @code{_JAVA} variable will be
7550 compiled with @code{JAVAC} at build time.  By default, @file{.java}
7551 files are not included in the distribution, you should use the
7552 @code{dist_} prefix to distribute them.
7553
7554 Here is a typical setup for distributing @file{.java} files and
7555 installing the @file{.class} files resulting from their compilation.
7556
7557 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7558 @example
7559 javadir = $(datadir)/java
7560 dist_java_JAVA = a.java b.java @dots{}
7561 @end example
7562
7563 @cindex @code{JAVA} restrictions
7564 @cindex Restrictions for @code{JAVA}
7565
7566 Currently Automake enforces the restriction that only one @code{_JAVA}
7567 primary can be used in a given @file{Makefile.am}.  The reason for this
7568 restriction is that, in general, it isn't possible to know which
7569 @file{.class} files were generated from which @file{.java} files, so
7570 it would be impossible to know which files to install where.  For
7571 instance, a @file{.java} file can define multiple classes; the resulting
7572 @file{.class} file names cannot be predicted without parsing the
7573 @file{.java} file.
7574
7575 There are a few variables that are used when compiling Java sources:
7576
7577 @vtable @code
7578 @item JAVAC
7579 The name of the Java compiler.  This defaults to @samp{javac}.
7580
7581 @item JAVACFLAGS
7582 The flags to pass to the compiler.  This is considered to be a user
7583 variable (@pxref{User Variables}).
7584
7585 @item AM_JAVACFLAGS
7586 More flags to pass to the Java compiler.  This, and not
7587 @code{JAVACFLAGS}, should be used when it is necessary to put Java
7588 compiler flags into @file{Makefile.am}.
7589
7590 @item JAVAROOT
7591 The value of this variable is passed to the @option{-d} option to
7592 @code{javac}.  It defaults to @samp{$(top_builddir)}.
7593
7594 @item CLASSPATH_ENV
7595 This variable is a shell expression that is used to set the
7596 @env{CLASSPATH} environment variable on the @code{javac} command line.
7597 (In the future we will probably handle class path setting differently.)
7598 @end vtable
7599
7600
7601 @node Python
7602 @section Python
7603
7604 @cindex @code{_PYTHON} primary, defined
7605 @cindex @code{PYTHON} primary, defined
7606 @cindex Primary variable, @code{PYTHON}
7607 @vindex _PYTHON
7608
7609 Automake provides support for Python compilation with the
7610 @code{PYTHON} primary.  A typical setup is to call
7611 @code{AM_PATH_PYTHON} in @file{configure.ac} and use a line like the
7612 following in @file{Makefile.am}:
7613
7614 @example
7615 python_PYTHON = tree.py leave.py
7616 @end example
7617
7618 Any files listed in a @code{_PYTHON} variable will be byte-compiled
7619 with @command{py-compile} at install time.  @command{py-compile}
7620 actually creates both standard (@file{.pyc}) and optimized
7621 (@file{.pyo}) byte-compiled versions of the source files.  Note that
7622 because byte-compilation occurs at install time, any files listed in
7623 @code{noinst_PYTHON} will not be compiled.  Python source files are
7624 included in the distribution by default, prepend @code{nodist_} (as in
7625 @code{nodist_python_PYTHON}) to omit them.
7626
7627 Automake ships with an Autoconf macro called @code{AM_PATH_PYTHON}
7628 that will determine some Python-related directory variables (see
7629 below).  If you have called @code{AM_PATH_PYTHON} from
7630 @file{configure.ac}, then you may use the variables
7631 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7632 @code{python_PYTHON} or @code{pkgpython_PYTHON} to list Python source
7633 files in your @file{Makefile.am}, depending on where you want your files
7634 installed (see the definitions of @code{pythondir} and
7635 @code{pkgpythondir} below).
7636
7637 @defmac AM_PATH_PYTHON (@ovar{version}, @ovar{action-if-found},
7638   @ovar{action-if-not-found})
7639
7640 Search for a Python interpreter on the system.  This macro takes three
7641 optional arguments.  The first argument, if present, is the minimum
7642 version of Python required for this package: @code{AM_PATH_PYTHON}
7643 will skip any Python interpreter that is older than @var{version}.
7644 If an interpreter is found and satisfies @var{version}, then
7645 @var{action-if-found} is run.  Otherwise, @var{action-if-not-found} is
7646 run.
7647
7648 If @var{action-if-not-found} is not specified, as in the following
7649 example, the default is to abort @command{configure}.
7650
7651 @example
7652 AM_PATH_PYTHON([2.2])
7653 @end example
7654
7655 @noindent
7656 This is fine when Python is an absolute requirement for the package.
7657 If Python >= 2.5 was only @emph{optional} to the package,
7658 @code{AM_PATH_PYTHON} could be called as follows.
7659
7660 @example
7661 AM_PATH_PYTHON([2.5],, [:])
7662 @end example
7663
7664 If the @env{PYTHON} variable is set when @code{AM_PATH_PYTHON} is
7665 called, then that will be the only Python interpreter that is tried.
7666
7667 @code{AM_PATH_PYTHON} creates the following output variables based on
7668 the Python installation found during configuration.
7669 @end defmac
7670
7671 @vtable @code
7672 @item PYTHON
7673 The name of the Python executable, or @samp{:} if no suitable
7674 interpreter could be found.
7675
7676 Assuming @var{action-if-not-found} is used (otherwise @file{./configure}
7677 will abort if Python is absent), the value of @code{PYTHON} can be used
7678 to setup a conditional in order to disable the relevant part of a build
7679 as follows.
7680
7681 @example
7682 AM_PATH_PYTHON(,, [:])
7683 AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :])
7684 @end example
7685
7686 @item PYTHON_VERSION
7687 The Python version number, in the form @var{major}.@var{minor}
7688 (e.g., @samp{2.5}).  This is currently the value of
7689 @samp{sys.version[:3]}.
7690
7691 @item PYTHON_PREFIX
7692 The string @samp{$@{prefix@}}.  This term may be used in future work
7693 that needs the contents of Python's @samp{sys.prefix}, but general
7694 consensus is to always use the value from @command{configure}.
7695
7696 @item PYTHON_EXEC_PREFIX
7697 The string @samp{$@{exec_prefix@}}.  This term may be used in future work
7698 that needs the contents of Python's @samp{sys.exec_prefix}, but general
7699 consensus is to always use the value from @command{configure}.
7700
7701 @item PYTHON_PLATFORM
7702 The canonical name used by Python to describe the operating system, as
7703 given by @samp{sys.platform}.  This value is sometimes needed when
7704 building Python extensions.
7705
7706 @item pythondir
7707 The directory name for the @file{site-packages} subdirectory of the
7708 standard Python install tree.
7709
7710 @item pkgpythondir
7711 This is the directory under @code{pythondir} that is named after the
7712 package.  That is, it is @samp{$(pythondir)/$(PACKAGE)}.  It is provided
7713 as a convenience.
7714
7715 @item pyexecdir
7716 This is the directory where Python extension modules (shared libraries)
7717 should be installed.  An extension module written in C could be declared
7718 as follows to Automake:
7719
7720 @c Keep in sync with primary-prefix-couples-documented-valid.sh
7721 @example
7722 pyexec_LTLIBRARIES = quaternion.la
7723 quaternion_la_SOURCES = quaternion.c support.c support.h
7724 quaternion_la_LDFLAGS = -avoid-version -module
7725 @end example
7726
7727 @item pkgpyexecdir
7728 This is a convenience variable that is defined as
7729 @samp{$(pyexecdir)/$(PACKAGE)}.
7730 @end vtable
7731
7732 All of these directory variables have values that start with either
7733 @samp{$@{prefix@}} or @samp{$@{exec_prefix@}} unexpanded.  This works
7734 fine in @file{Makefiles}, but it makes these variables hard to use in
7735 @file{configure}.  This is mandated by the GNU coding standards, so
7736 that the user can run @samp{make prefix=/foo install}.  The Autoconf
7737 manual has a section with more details on this topic
7738 (@pxref{Installation Directory Variables, , Installation Directory
7739 Variables, autoconf, The Autoconf Manual}).  See also @ref{Hard-Coded
7740 Install Paths}.
7741
7742
7743 @node Documentation
7744 @chapter Building documentation
7745
7746 Currently Automake provides support for Texinfo and man pages.
7747
7748 @menu
7749 * Texinfo::                     Texinfo
7750 * Man Pages::                   Man pages
7751 @end menu
7752
7753
7754 @node Texinfo
7755 @section Texinfo
7756
7757 @cindex @code{_TEXINFOS} primary, defined
7758 @cindex @code{TEXINFOS} primary, defined
7759 @cindex Primary variable, @code{TEXINFOS}
7760 @cindex HTML output using Texinfo
7761 @cindex PDF output using Texinfo
7762 @cindex PS output using Texinfo
7763 @cindex DVI output using Texinfo
7764 @vindex _TEXINFOS
7765 @vindex info_TEXINFOS
7766
7767 If the current directory contains Texinfo source, you must declare it
7768 with the @code{TEXINFOS} primary.  Generally Texinfo files are converted
7769 into info, and thus the @code{info_TEXINFOS} variable is most commonly used
7770 here.  Any Texinfo source file must end in the @file{.texi},
7771 @file{.txi}, or @file{.texinfo} extension.  We recommend @file{.texi}
7772 for new manuals.
7773
7774 Automake generates rules to build @file{.info}, @file{.dvi},
7775 @file{.ps}, @file{.pdf} and @file{.html} files from your Texinfo
7776 sources.  Following the GNU Coding Standards, only the @file{.info}
7777 files are built by @samp{make all} and installed by @samp{make
7778 install} (unless you use @option{no-installinfo}, see below).
7779 Furthermore, @file{.info} files are automatically distributed so that
7780 Texinfo is not a prerequisite for installing your package.
7781
7782 @trindex dvi
7783 @trindex html
7784 @trindex pdf
7785 @trindex ps
7786 @trindex install-dvi
7787 @trindex install-html
7788 @trindex install-pdf
7789 @trindex install-ps
7790 Other documentation formats can be built on request by @samp{make
7791 dvi}, @samp{make ps}, @samp{make pdf} and @samp{make html}, and they
7792 can be installed with @samp{make install-dvi}, @samp{make install-ps},
7793 @samp{make install-pdf} and @samp{make install-html} explicitly.
7794 @samp{make uninstall} will remove everything: the Texinfo
7795 documentation installed by default as well as all the above optional
7796 formats.
7797
7798 All of these targets can be extended using @samp{-local} rules
7799 (@pxref{Extending}).
7800
7801 @cindex Texinfo flag, @code{VERSION}
7802 @cindex Texinfo flag, @code{UPDATED}
7803 @cindex Texinfo flag, @code{EDITION}
7804 @cindex Texinfo flag, @code{UPDATED-MONTH}
7805
7806 @cindex @code{VERSION} Texinfo flag
7807 @cindex @code{UPDATED} Texinfo flag
7808 @cindex @code{EDITION} Texinfo flag
7809 @cindex @code{UPDATED-MONTH} Texinfo flag
7810
7811 @cindex @file{mdate-sh}
7812
7813 If the @file{.texi} file @code{@@include}s @file{version.texi}, then
7814 that file will be automatically generated.  The file @file{version.texi}
7815 defines four Texinfo flag you can reference using
7816 @code{@@value@{EDITION@}}, @code{@@value@{VERSION@}},
7817 @code{@@value@{UPDATED@}}, and @code{@@value@{UPDATED-MONTH@}}.
7818
7819 @table @code
7820 @item EDITION
7821 @itemx VERSION
7822 Both of these flags hold the version number of your program.  They are
7823 kept separate for clarity.
7824
7825 @item UPDATED
7826 This holds the date the primary @file{.texi} file was last modified.
7827
7828 @item UPDATED-MONTH
7829 This holds the name of the month in which the primary @file{.texi} file
7830 was last modified.
7831 @end table
7832
7833 The @file{version.texi} support requires the @command{mdate-sh}
7834 script; this script is supplied with Automake and automatically
7835 included when @command{automake} is invoked with the
7836 @option{--add-missing} option.
7837
7838 If you have multiple Texinfo files, and you want to use the
7839 @file{version.texi} feature, then you have to have a separate version
7840 file for each Texinfo file.  Automake will treat any include in a
7841 Texinfo file that matches @file{vers*.texi} just as an automatically
7842 generated version file.
7843
7844 Sometimes an info file actually depends on more than one @file{.texi}
7845 file.  For instance, in GNU Hello, @file{hello.texi} includes the file
7846 @file{fdl.texi}.  You can tell Automake about these dependencies using
7847 the @code{@var{texi}_TEXINFOS} variable.  Here is how GNU Hello does it:
7848 @vindex TEXINFOS
7849 @vindex _TEXINFOS
7850
7851 @example
7852 info_TEXINFOS = hello.texi
7853 hello_TEXINFOS = fdl.texi
7854 @end example
7855
7856 @cindex @file{texinfo.tex}
7857
7858 By default, Automake requires the file @file{texinfo.tex} to appear in
7859 the same directory as the @file{Makefile.am} file that lists the
7860 @file{.texi} files.  If you used @code{AC_CONFIG_AUX_DIR} in
7861 @file{configure.ac} (@pxref{Input, , Finding `configure' Input,
7862 autoconf, The Autoconf Manual}), then @file{texinfo.tex} is looked for
7863 there.  In both cases, @command{automake} then supplies @file{texinfo.tex} if
7864 @option{--add-missing} is given, and takes care of its distribution.
7865 However, if you set the @code{TEXINFO_TEX} variable (see below),
7866 it overrides the location of the file and turns off its installation
7867 into the source as well as its distribution.
7868
7869 The option @option{no-texinfo.tex} can be used to eliminate the
7870 requirement for the file @file{texinfo.tex}.  Use of the variable
7871 @code{TEXINFO_TEX} is preferable, however, because that allows the
7872 @code{dvi}, @code{ps}, and @code{pdf} targets to still work.
7873
7874 @cindex Option, @code{no-installinfo}
7875 @cindex Target, @code{install-info}
7876 @cindex @code{install-info} target
7877 @cindex @code{no-installinfo} option
7878
7879 @opindex no-installinfo
7880 @trindex install-info
7881
7882 Automake generates an @code{install-info} rule; some people apparently
7883 use this.  By default, info pages are installed by @samp{make
7884 install}, so running @code{make install-info} is pointless.  This can
7885 be prevented via the @code{no-installinfo} option.  In this case,
7886 @file{.info} files are not installed by default, and user must
7887 request this explicitly using @samp{make install-info}.
7888
7889 @vindex AM_UPDATE_INFO_DIR
7890 By default, @code{make install-info} and @code{make install-info}
7891 will try to run the @command{install-info} program (if available)
7892 to update (or create) the @file{@code{$@{infodir@}}/dir} index.
7893 If this is undesired, it can be prevented by exporting the
7894 @code{AM_UPDATE_INFO_DIR} variable to "@code{no}".
7895
7896 The following variables are used by the Texinfo build rules.
7897
7898 @vtable @code
7899 @item MAKEINFO
7900 The name of the program invoked to build @file{.info} files.  This
7901 variable is defined by Automake.  If the @command{makeinfo} program is
7902 found on the system then it will be used by default; otherwise
7903 @command{missing} will be used instead.
7904
7905 @item MAKEINFOHTML
7906 The command invoked to build @file{.html} files.  Automake
7907 defines this to @samp{$(MAKEINFO) --html}.
7908
7909 @item MAKEINFOFLAGS
7910 User flags passed to each invocation of @samp{$(MAKEINFO)} and
7911 @samp{$(MAKEINFOHTML)}.  This user variable (@pxref{User Variables}) is
7912 not expected to be defined in any @file{Makefile}; it can be used by
7913 users to pass extra flags to suit their needs.
7914
7915 @item AM_MAKEINFOFLAGS
7916 @itemx AM_MAKEINFOHTMLFLAGS
7917 Maintainer flags passed to each @command{makeinfo} invocation.  Unlike
7918 @code{MAKEINFOFLAGS}, these variables are meant to be defined by
7919 maintainers in @file{Makefile.am}.  @samp{$(AM_MAKEINFOFLAGS)} is
7920 passed to @code{makeinfo} when building @file{.info} files; and
7921 @samp{$(AM_MAKEINFOHTMLFLAGS)} is used when building @file{.html}
7922 files.
7923
7924 @c Keep in sync with txinfo21.sh
7925 For instance, the following setting can be used to obtain one single
7926 @file{.html} file per manual, without node separators.
7927 @example
7928 AM_MAKEINFOHTMLFLAGS = --no-headers --no-split
7929 @end example
7930
7931 @code{AM_MAKEINFOHTMLFLAGS} defaults to @samp{$(AM_MAKEINFOFLAGS)}.
7932 This means that defining @code{AM_MAKEINFOFLAGS} without defining
7933 @code{AM_MAKEINFOHTMLFLAGS} will impact builds of both @file{.info}
7934 and @file{.html} files.
7935
7936 @item TEXI2DVI
7937 The name of the command that converts a @file{.texi} file into a
7938 @file{.dvi} file.  This defaults to @samp{texi2dvi}, a script that ships
7939 with the Texinfo package.
7940
7941 @item TEXI2PDF
7942 The name of the command that translates a @file{.texi} file into a
7943 @file{.pdf} file.  This defaults to @samp{$(TEXI2DVI) --pdf --batch}.
7944
7945 @item DVIPS
7946 The name of the command that builds a @file{.ps} file out of a
7947 @file{.dvi} file.  This defaults to @samp{dvips}.
7948
7949 @item TEXINFO_TEX
7950
7951 If your package has Texinfo files in many directories, you can use the
7952 variable @code{TEXINFO_TEX} to tell Automake where to find the canonical
7953 @file{texinfo.tex} for your package.  The value of this variable should
7954 be the relative path from the current @file{Makefile.am} to
7955 @file{texinfo.tex}:
7956
7957 @example
7958 TEXINFO_TEX = ../doc/texinfo.tex
7959 @end example
7960 @end vtable
7961
7962
7963 @node Man Pages
7964 @section Man Pages
7965
7966 @cindex @code{_MANS} primary, defined
7967 @cindex @code{MANS} primary, defined
7968 @cindex Primary variable, @code{MANS}
7969
7970 @vindex _MANS
7971 @vindex man_MANS
7972 A package can also include man pages (but see the GNU standards on this
7973 matter, @ref{Man Pages, , , standards, The GNU Coding Standards}.)  Man
7974 pages are declared using the @code{MANS} primary.  Generally the
7975 @code{man_MANS} variable is used.  Man pages are automatically installed in
7976 the correct subdirectory of @code{mandir}, based on the file extension.
7977
7978 File extensions such as @file{.1c} are handled by looking for the valid
7979 part of the extension and using that to determine the correct
7980 subdirectory of @code{mandir}.  Valid section names are the digits
7981 @samp{0} through @samp{9}, and the letters @samp{l} and @samp{n}.
7982
7983 Sometimes developers prefer to name a man page something like
7984 @file{foo.man} in the source, and then rename it to have the correct
7985 suffix, for example @file{foo.1}, when installing the file.  Automake
7986 also supports this mode.  For a valid section named @var{section},
7987 there is a corresponding directory named @samp{man@var{section}dir},
7988 and a corresponding @code{_MANS} variable.  Files listed in such a
7989 variable are installed in the indicated section.  If the file already
7990 has a valid suffix, then it is installed as-is; otherwise the file
7991 suffix is changed to match the section.
7992
7993 For instance, consider this example:
7994 @example
7995 man1_MANS = rename.man thesame.1 alsothesame.1c
7996 @end example
7997
7998 @noindent
7999 In this case, @file{rename.man} will be renamed to @file{rename.1} when
8000 installed, but the other files will keep their names.
8001
8002 @cindex Target, @code{install-man}
8003 @cindex Option, @option{no-installman}
8004 @cindex @code{install-man} target
8005 @cindex @option{no-installman} option
8006 @opindex no-installman
8007 @trindex install-man
8008
8009 By default, man pages are installed by @samp{make install}.  However,
8010 since the GNU project does not require man pages, many maintainers do
8011 not expend effort to keep the man pages up to date.  In these cases, the
8012 @option{no-installman} option will prevent the man pages from being
8013 installed by default.  The user can still explicitly install them via
8014 @samp{make install-man}.
8015
8016 For fast installation, with many files it is preferable to use
8017 @samp{man@var{section}_MANS} over @samp{man_MANS} as well as files that
8018 do not need to be renamed.
8019
8020 Man pages are not currently considered to be source, because it is not
8021 uncommon for man pages to be automatically generated.  Therefore they
8022 are not automatically included in the distribution.  However, this can
8023 be changed by use of the @code{dist_} prefix.  For instance here is
8024 how to distribute and install the two man pages of GNU @command{cpio}
8025 (which includes both Texinfo documentation and man pages):
8026
8027 @example
8028 dist_man_MANS = cpio.1 mt.1
8029 @end example
8030
8031 The @code{nobase_} prefix is meaningless for man pages and is
8032 disallowed.
8033
8034 @vindex notrans_
8035 @cindex @code{notrans_} prefix
8036 @cindex Man page renaming, avoiding
8037 @cindex Avoiding man page renaming
8038
8039 Executables and manpages may be renamed upon installation
8040 (@pxref{Renaming}).  For manpages this can be avoided by use of the
8041 @code{notrans_} prefix.  For instance, suppose an executable @samp{foo}
8042 allowing to access a library function @samp{foo} from the command line.
8043 The way to avoid renaming of the @file{foo.3} manpage is:
8044
8045 @example
8046 man_MANS = foo.1
8047 notrans_man_MANS = foo.3
8048 @end example
8049
8050 @cindex @code{notrans_} and @code{dist_} or @code{nodist_}
8051 @cindex @code{dist_} and @code{notrans_}
8052 @cindex @code{nodist_} and @code{notrans_}
8053
8054 @samp{notrans_} must be specified first when used in conjunction with
8055 either @samp{dist_} or @samp{nodist_} (@pxref{Fine-grained Distribution
8056 Control}).  For instance:
8057
8058 @example
8059 notrans_dist_man3_MANS = bar.3
8060 @end example
8061
8062 @node Install
8063 @chapter What Gets Installed
8064
8065 @cindex Installation support
8066 @cindex @samp{make install} support
8067
8068 Naturally, Automake handles the details of actually installing your
8069 program once it has been built.  All files named by the various
8070 primaries are automatically installed in the appropriate places when the
8071 user runs @samp{make install}.
8072
8073 @menu
8074 * Basics of Installation::      What gets installed where
8075 * The Two Parts of Install::    Installing data and programs separately
8076 * Extending Installation::      Adding your own rules for installation
8077 * Staged Installs::             Installation in a temporary location
8078 * Install Rules for the User::  Useful additional rules
8079 @end menu
8080
8081 @node Basics of Installation
8082 @section Basics of Installation
8083
8084 A file named in a primary is installed by copying the built file into
8085 the appropriate directory.  The base name of the file is used when
8086 installing.
8087
8088 @example
8089 bin_PROGRAMS = hello subdir/goodbye
8090 @end example
8091
8092 In this example, both @samp{hello} and @samp{goodbye} will be installed
8093 in @samp{$(bindir)}.
8094
8095 Sometimes it is useful to avoid the basename step at install time.  For
8096 instance, you might have a number of header files in subdirectories of
8097 the source tree that are laid out precisely how you want to install
8098 them.  In this situation you can use the @code{nobase_} prefix to
8099 suppress the base name step.  For example:
8100
8101 @example
8102 nobase_include_HEADERS = stdio.h sys/types.h
8103 @end example
8104
8105 @noindent
8106 will install @file{stdio.h} in @samp{$(includedir)} and @file{types.h}
8107 in @samp{$(includedir)/sys}.
8108
8109 For most file types, Automake will install multiple files at once, while
8110 avoiding command line length issues (@pxref{Length Limitations}).  Since
8111 some @command{install} programs will not install the same file twice in
8112 one invocation, you may need to ensure that file lists are unique within
8113 one variable such as @samp{nobase_include_HEADERS} above.
8114
8115 You should not rely on the order in which files listed in one variable
8116 are installed.  Likewise, to cater for parallel make, you should not
8117 rely on any particular file installation order even among different
8118 file types (library dependencies are an exception here).
8119
8120
8121 @node The Two Parts of Install
8122 @section The Two Parts of Install
8123
8124 Automake generates separate @code{install-data} and @code{install-exec}
8125 rules, in case the installer is installing on multiple machines that
8126 share directory structure---these targets allow the machine-independent
8127 parts to be installed only once.  @code{install-exec} installs
8128 platform-dependent files, and @code{install-data} installs
8129 platform-independent files.  The @code{install} target depends on both
8130 of these targets.  While Automake tries to automatically segregate
8131 objects into the correct category, the @file{Makefile.am} author is, in
8132 the end, responsible for making sure this is done correctly.
8133 @trindex install-data
8134 @trindex install-exec
8135 @trindex install
8136 @cindex Install, two parts of
8137
8138 Variables using the standard directory prefixes @samp{data},
8139 @samp{info}, @samp{man}, @samp{include}, @samp{oldinclude},
8140 @samp{pkgdata}, or @samp{pkginclude} are installed by
8141 @code{install-data}.
8142
8143 Variables using the standard directory prefixes @samp{bin},
8144 @samp{sbin}, @samp{libexec}, @samp{sysconf}, @samp{localstate},
8145 @samp{lib}, or @samp{pkglib} are installed by @code{install-exec}.
8146
8147 For instance, @code{data_DATA} files are installed by @code{install-data},
8148 while @code{bin_PROGRAMS} files are installed by @code{install-exec}.
8149
8150 Any variable using a user-defined directory prefix with
8151 @samp{exec} in the name (e.g.,
8152 @c Keep in sync with primary-prefix-couples-documented-valid.sh
8153 @code{myexecbin_PROGRAMS}) is installed by @code{install-exec}.  All
8154 other user-defined prefixes are installed by @code{install-data}.
8155
8156 @node Extending Installation
8157 @section Extending Installation
8158
8159 It is possible to extend this mechanism by defining an
8160 @code{install-exec-local} or @code{install-data-local} rule.  If these
8161 rules exist, they will be run at @samp{make install} time.  These
8162 rules can do almost anything; care is required.
8163 @trindex install-exec-local
8164 @trindex install-data-local
8165
8166 Automake also supports two install hooks, @code{install-exec-hook} and
8167 @code{install-data-hook}.  These hooks are run after all other install
8168 rules of the appropriate type, exec or data, have completed.  So, for
8169 instance, it is possible to perform post-installation modifications
8170 using an install hook.  @xref{Extending}, for some examples.
8171 @cindex Install hook
8172
8173 @node Staged Installs
8174 @section Staged Installs
8175
8176 @vindex DESTDIR
8177 Automake generates support for the @code{DESTDIR} variable in all
8178 install rules.  @code{DESTDIR} is used during the @samp{make install}
8179 step to relocate install objects into a staging area.  Each object and
8180 path is prefixed with the value of @code{DESTDIR} before being copied
8181 into the install area.  Here is an example of typical DESTDIR usage:
8182
8183 @example
8184 mkdir /tmp/staging &&
8185 make DESTDIR=/tmp/staging install
8186 @end example
8187
8188 The @command{mkdir} command avoids a security problem if the attacker
8189 creates a symbolic link from @file{/tmp/staging} to a victim area;
8190 then @command{make} places install objects in a directory tree built under
8191 @file{/tmp/staging}.  If @file{/gnu/bin/foo} and
8192 @file{/gnu/share/aclocal/foo.m4} are to be installed, the above command
8193 would install @file{/tmp/staging/gnu/bin/foo} and
8194 @file{/tmp/staging/gnu/share/aclocal/foo.m4}.
8195
8196 This feature is commonly used to build install images and packages
8197 (@pxref{DESTDIR}).
8198
8199 Support for @code{DESTDIR} is implemented by coding it directly into
8200 the install rules.  If your @file{Makefile.am} uses a local install
8201 rule (e.g., @code{install-exec-local}) or an install hook, then you
8202 must write that code to respect @code{DESTDIR}.
8203
8204 @xref{Makefile Conventions, , , standards, The GNU Coding Standards},
8205 for another usage example.
8206
8207 @node Install Rules for the User
8208 @section Install Rules for the User
8209
8210 Automake also generates rules for targets @code{uninstall},
8211 @code{installdirs}, and @code{install-strip}.
8212 @trindex uninstall
8213 @trindex installdirs
8214 @trindex install-strip
8215
8216 Automake supports @code{uninstall-local} and @code{uninstall-hook}.
8217 There is no notion of separate uninstalls for ``exec'' and ``data'', as
8218 these features would not provide additional functionality.
8219
8220 Note that @code{uninstall} is not meant as a replacement for a real
8221 packaging tool.
8222
8223
8224 @node Clean
8225 @chapter What Gets Cleaned
8226
8227 @cindex @samp{make clean} support
8228
8229 The GNU Makefile Standards specify a number of different clean rules.
8230 @xref{Standard Targets, , Standard Targets for Users, standards,
8231 The GNU Coding Standards}.
8232
8233 Generally the files that can be cleaned are determined automatically by
8234 Automake.  Of course, Automake also recognizes some variables that can
8235 be defined to specify additional files to clean.  These variables are
8236 @code{MOSTLYCLEANFILES}, @code{CLEANFILES}, @code{DISTCLEANFILES}, and
8237 @code{MAINTAINERCLEANFILES}.
8238 @vindex MOSTLYCLEANFILES
8239 @vindex CLEANFILES
8240 @vindex DISTCLEANFILES
8241 @vindex MAINTAINERCLEANFILES
8242
8243 @trindex mostlyclean-local
8244 @trindex clean-local
8245 @trindex distclean-local
8246 @trindex maintainer-clean-local
8247 When cleaning involves more than deleting some hard-coded list of
8248 files, it is also possible to supplement the cleaning rules with your
8249 own commands.  Simply define a rule for any of the
8250 @code{mostlyclean-local}, @code{clean-local}, @code{distclean-local},
8251 or @code{maintainer-clean-local} targets (@pxref{Extending}).  A common
8252 case is deleting a directory, for instance, a directory created by the
8253 test suite:
8254
8255 @example
8256 clean-local:
8257         -rm -rf testSubDir
8258 @end example
8259
8260 Since @command{make} allows only one set of rules for a given target,
8261 a more extensible way of writing this is to use a separate target
8262 listed as a dependency:
8263
8264 @example
8265 clean-local: clean-local-check
8266 .PHONY: clean-local-check
8267 clean-local-check:
8268         -rm -rf testSubDir
8269 @end example
8270
8271 As the GNU Standards aren't always explicit as to which files should
8272 be removed by which rule, we've adopted a heuristic that we believe
8273 was first formulated by Fran@,{c}ois Pinard:
8274
8275 @itemize @bullet
8276 @item
8277 If @command{make} built it, and it is commonly something that one would
8278 want to rebuild (for instance, a @file{.o} file), then
8279 @code{mostlyclean} should delete it.
8280
8281 @item
8282 Otherwise, if @command{make} built it, then @code{clean} should delete it.
8283
8284 @item
8285 If @command{configure} built it, then @code{distclean} should delete it.
8286
8287 @item
8288 If the maintainer built it (for instance, a @file{.info} file), then
8289 @code{maintainer-clean} should delete it.  However
8290 @code{maintainer-clean} should not delete anything that needs to exist
8291 in order to run @samp{./configure && make}.
8292 @end itemize
8293
8294 We recommend that you follow this same set of heuristics in your
8295 @file{Makefile.am}.
8296
8297
8298 @node Dist
8299 @chapter What Goes in a Distribution
8300
8301 @menu
8302 * Basics of Distribution::      Files distributed by default
8303 * Fine-grained Distribution Control::  @code{dist_} and @code{nodist_} prefixes
8304 * The dist Hook::               A target for last-minute distribution changes
8305 * Checking the Distribution::   @samp{make distcheck} explained
8306 * The Types of Distributions::  A variety of formats and compression methods
8307 @end menu
8308
8309 @node Basics of Distribution
8310 @section Basics of Distribution
8311
8312 @cindex @samp{make dist}
8313
8314 @vindex PACKAGE
8315 @vindex VERSION
8316 @trindex dist
8317 The @code{dist} rule in the generated @file{Makefile.in} can be used
8318 to generate a gzipped @code{tar} file and other flavors of archive for
8319 distribution.  The file is named based on the @code{PACKAGE} and
8320 @code{VERSION} variables defined by @code{AM_INIT_AUTOMAKE}
8321 (@pxref{Macros}); more precisely the gzipped @code{tar} file is named
8322 @samp{@var{package}-@var{version}.tar.gz}.
8323 @vindex GZIP_ENV
8324 You can use the @command{make} variable @code{GZIP_ENV} to control how gzip
8325 is run.  The default setting is @option{--best}.
8326
8327 @cindex @code{m4_include}, distribution
8328 @cindex @code{include}, distribution
8329 @acindex m4_include
8330 @cmindex include
8331 For the most part, the files to distribute are automatically found by
8332 Automake: all source files are automatically included in a distribution,
8333 as are all @file{Makefile.am} and @file{Makefile.in} files.  Automake also
8334 has a built-in list of commonly used files that are automatically
8335 included if they are found in the current directory (either physically,
8336 or as the target of a @file{Makefile.am} rule); this list is printed by
8337 @samp{automake --help}.  Note that some files in this list are actually
8338 distributed only if other certain conditions hold (for example,
8339 @c Keep in sync with autodist-config-headers.sh
8340 the @file{config.h.top} and @file{config.h.bot} files are automatically
8341 distributed only if, e.g., @samp{AC_CONFIG_HEADERS([config.h])} is used
8342 in @file{configure.ac}).  Also, files that are read by @command{configure}
8343 (i.e.@: the source files corresponding to the files specified in various
8344 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
8345 automatically distributed.  Files included in a @file{Makefile.am} (using
8346 @code{include}) or in @file{configure.ac} (using @code{m4_include}), and
8347 helper scripts installed with @samp{automake --add-missing} are also
8348 distributed.
8349
8350 @vindex EXTRA_DIST
8351 Still, sometimes there are files that must be distributed, but which
8352 are not covered in the automatic rules.  These files should be listed in
8353 the @code{EXTRA_DIST} variable.  You can mention files from
8354 subdirectories in @code{EXTRA_DIST}.
8355
8356 You can also mention a directory in @code{EXTRA_DIST}; in this case the
8357 entire directory will be recursively copied into the distribution.
8358 Please note that this will also copy @emph{everything} in the directory,
8359 including, e.g., Subversion's @file{.svn} private directories or CVS/RCS
8360 version control files.  We recommend against using this feature.
8361
8362 @vindex SUBDIRS
8363 @vindex DIST_SUBDIRS
8364 If you define @code{SUBDIRS}, Automake will recursively include the
8365 subdirectories in the distribution.  If @code{SUBDIRS} is defined
8366 conditionally (@pxref{Conditionals}), Automake will normally include
8367 all directories that could possibly appear in @code{SUBDIRS} in the
8368 distribution.  If you need to specify the set of directories
8369 conditionally, you can set the variable @code{DIST_SUBDIRS} to the
8370 exact list of subdirectories to include in the distribution
8371 (@pxref{Conditional Subdirectories}).
8372
8373
8374 @node Fine-grained Distribution Control
8375 @section Fine-grained Distribution Control
8376
8377 @vindex dist_
8378 @vindex nodist_
8379 Sometimes you need tighter control over what does @emph{not} go into the
8380 distribution; for instance, you might have source files that are
8381 generated and that you do not want to distribute.  In this case
8382 Automake gives fine-grained control using the @code{dist} and
8383 @code{nodist} prefixes.  Any primary or @code{_SOURCES} variable can be
8384 prefixed with @code{dist_} to add the listed files to the distribution.
8385 Similarly, @code{nodist_} can be used to omit the files from the
8386 distribution.
8387
8388 As an example, here is how you would cause some data to be distributed
8389 while leaving some source code out of the distribution:
8390
8391 @example
8392 dist_data_DATA = distribute-this
8393 bin_PROGRAMS = foo
8394 nodist_foo_SOURCES = do-not-distribute.c
8395 @end example
8396
8397 @node The dist Hook
8398 @section The dist Hook
8399
8400 @trindex dist-hook
8401
8402 Occasionally it is useful to be able to change the distribution before
8403 it is packaged up.  If the @code{dist-hook} rule exists, it is run
8404 after the distribution directory is filled, but before the actual
8405 distribution archives are created.  One way to use this is for
8406 removing unnecessary files that get recursively included by specifying
8407 a directory in @code{EXTRA_DIST}:
8408
8409 @example
8410 EXTRA_DIST = doc
8411 dist-hook:
8412         rm -rf `find $(distdir)/doc -type d -name .svn`
8413 @end example
8414
8415 @c The caveates described here should be documented in 'disthook.test'.
8416 @noindent
8417 Note that the @code{dist-hook} recipe shouldn't assume that the regular
8418 files in the distribution directory are writable; this might not be the
8419 case if one is packaging from a read-only source tree, or when a
8420 @code{make distcheck} is being done.  For similar reasons, the recipe
8421 shouldn't assume that the subdirectories put into the distribution
8422 directory as effect of having them listed in @code{EXTRA_DIST} are
8423 writable.  So, if the @code{dist-hook} recipe wants to modify the
8424 content of an existing file (or @code{EXTRA_DIST} subdirectory) in the
8425 distribution directory, it should explicitly to make it writable first:
8426
8427 @example
8428 EXTRA_DIST = README doc
8429 dist-hook:
8430         chmod u+w $(distdir)/README $(distdir)/doc
8431         echo "Distribution date: `date`" >> README
8432         rm -f $(distdir)/doc/HACKING
8433 @end example
8434
8435 @vindex distdir
8436 @vindex top_distdir
8437 Two variables that come handy when writing @code{dist-hook} rules are
8438 @samp{$(distdir)} and @samp{$(top_distdir)}.
8439
8440 @samp{$(distdir)} points to the directory where the @code{dist} rule
8441 will copy files from the current directory before creating the
8442 tarball.  If you are at the top-level directory, then @samp{distdir =
8443 $(PACKAGE)-$(VERSION)}.  When used from subdirectory named
8444 @file{foo/}, then @samp{distdir = ../$(PACKAGE)-$(VERSION)/foo}.
8445 @samp{$(distdir)} can be a relative or absolute path, do not assume
8446 any form.
8447
8448 @samp{$(top_distdir)} always points to the root directory of the
8449 distributed tree.  At the top-level it's equal to @samp{$(distdir)}.
8450 In the @file{foo/} subdirectory
8451 @samp{top_distdir = ../$(PACKAGE)-$(VERSION)}.
8452 @samp{$(top_distdir)} too can be a relative or absolute path.
8453
8454 Note that when packages are nested using @code{AC_CONFIG_SUBDIRS}
8455 (@pxref{Subpackages}), then @samp{$(distdir)} and
8456 @samp{$(top_distdir)} are relative to the package where @samp{make
8457 dist} was run, not to any sub-packages involved.
8458
8459 @node Checking the Distribution
8460 @section Checking the Distribution
8461
8462 @cindex @samp{make distcheck}
8463 @trindex distcheck
8464 Automake also generates a @code{distcheck} rule that can be of help
8465 to ensure that a given distribution will actually work.  Simplifying
8466 a bit, we can say this rule first makes a distribution, and then,
8467 @emph{operating from it}, takes the following steps:
8468 @itemize
8469 @item
8470 tries to do a @code{VPATH} build (@pxref{VPATH Builds}), with the
8471 @code{srcdir} and all its content made @emph{read-only};
8472 @item
8473 runs the test suite (with @command{make check}) on this fresh build;
8474 @item
8475 installs the package in a temporary directory (with @command{make
8476 install}), and tries runs the test suite on the resulting installation
8477 (with @command{make installcheck});
8478 @item
8479 checks that the package can be correctly uninstalled (by @command{make
8480 uninstall}) and cleaned (by @code{make distclean});
8481 @item
8482 finally, makes another tarball to ensure the distribution is
8483 self-contained.
8484 @end itemize
8485
8486 @vindex AM_DISTCHECK_CONFIGURE_FLAGS
8487 @vindex DISTCHECK_CONFIGURE_FLAGS
8488 @subheading DISTCHECK_CONFIGURE_FLAGS
8489 Building the package involves running @samp{./configure}.  If you need
8490 to supply additional flags to @command{configure}, define them in the
8491 @code{AM_DISTCHECK_CONFIGURE_FLAGS} variable in your top-level
8492 @file{Makefile.am}.  The user can still extend or override the flags
8493 provided there by defining the @code{DISTCHECK_CONFIGURE_FLAGS} variable,
8494 on the command line when invoking @command{make}.
8495
8496 Still, developers are encouraged to strive to make their code buildable
8497 without requiring any special configure option; thus, in general, you
8498 shouldn't define @code{AM_DISTCHECK_CONFIGURE_FLAGS}. However, there
8499 might be few scenarios in which the use of this variable is justified.
8500 GNU @command{m4} offers an example.  GNU @command{m4} configures by
8501 default with its experimental and seldom used "changeword" feature
8502 disabled; so in its case it is useful to have @command{make distcheck}
8503 run configure with the @option{--with-changeword} option, to ensure that
8504 the code for changeword support still compiles correctly.
8505 GNU @command{m4} also employs the @code{AM_DISTCHECK_CONFIGURE_FLAGS}
8506 variable to stress-test the use of @option{--program-prefix=g}, since at
8507 one point the @command{m4} build system had a bug where @command{make
8508 installcheck} was wrongly assuming it could blindly test "@command{m4}",
8509 rather than the just-installed "@command{gm4}".
8510
8511 @trindex distcheck-hook
8512 @subheading distcheck-hook
8513 If the @code{distcheck-hook} rule is defined in your top-level
8514 @file{Makefile.am}, then it will be invoked by @code{distcheck} after
8515 the new distribution has been unpacked, but before the unpacked copy
8516 is configured and built.  Your @code{distcheck-hook} can do almost
8517 anything, though as always caution is advised.  Generally this hook is
8518 used to check for potential distribution errors not caught by the
8519 standard mechanism.  Note that @code{distcheck-hook} as well as
8520 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8521 are not honored in a subpackage @file{Makefile.am}, but the flags from
8522 @code{AM_DISTCHECK_CONFIGURE_FLAGS} and @code{DISTCHECK_CONFIGURE_FLAGS}
8523 are passed down to the @command{configure} script of the subpackage.
8524
8525 @cindex @samp{make distcleancheck}
8526 @trindex distcleancheck
8527 @vindex DISTCLEANFILES
8528 @vindex distcleancheck_listfiles
8529
8530 @subheading distcleancheck
8531 Speaking of potential distribution errors, @code{distcheck} also
8532 ensures that the @code{distclean} rule actually removes all built
8533 files.  This is done by running @samp{make distcleancheck} at the end of
8534 the @code{VPATH} build.  By default, @code{distcleancheck} will run
8535 @code{distclean} and then make sure the build tree has been emptied by
8536 running @samp{$(distcleancheck_listfiles)}.  Usually this check will
8537 find generated files that you forgot to add to the @code{DISTCLEANFILES}
8538 variable (@pxref{Clean}).
8539
8540 The @code{distcleancheck} behavior should be OK for most packages,
8541 otherwise you have the possibility to override the definition of
8542 either the @code{distcleancheck} rule, or the
8543 @samp{$(distcleancheck_listfiles)} variable.  For instance, to disable
8544 @code{distcleancheck} completely, add the following rule to your
8545 top-level @file{Makefile.am}:
8546
8547 @example
8548 distcleancheck:
8549         @@:
8550 @end example
8551
8552 If you want @code{distcleancheck} to ignore built files that have not
8553 been cleaned because they are also part of the distribution, add the
8554 following definition instead:
8555
8556 @c Keep in sync with distcleancheck.sh
8557 @example
8558 distcleancheck_listfiles = \
8559   find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
8560        sh '@{@}' ';'
8561 @end example
8562
8563 The above definition is not the default because it's usually an error if
8564 your Makefiles cause some distributed files to be rebuilt when the user
8565 build the package.  (Think about the user missing the tool required to
8566 build the file; or if the required tool is built by your package,
8567 consider the cross-compilation case where it can't be run.)  There is
8568 an entry in the FAQ about this (@pxref{Errors with distclean}), make
8569 sure you read it before playing with @code{distcleancheck_listfiles}.
8570
8571 @cindex @samp{make distuninstallcheck}
8572 @trindex distuninstallcheck
8573 @vindex distuninstallcheck_listfiles
8574
8575 @subheading distuninstallcheck
8576 @code{distcheck} also checks that the @code{uninstall} rule works
8577 properly, both for ordinary and @code{DESTDIR} builds.  It does this
8578 by invoking @samp{make uninstall}, and then it checks the install tree
8579 to see if any files are left over.  This check will make sure that you
8580 correctly coded your @code{uninstall}-related rules.
8581
8582 By default, the checking is done by the @code{distuninstallcheck} rule,
8583 and the list of files in the install tree is generated by
8584 @samp{$(distuninstallcheck_listfiles)} (this is a variable whose value is
8585 a shell command to run that prints the list of files to stdout).
8586
8587 Either of these can be overridden to modify the behavior of
8588 @code{distcheck}.  For instance, to disable this check completely, you
8589 would write:
8590
8591 @example
8592 distuninstallcheck:
8593         @@:
8594 @end example
8595
8596 @node The Types of Distributions
8597 @section The Types of Distributions
8598
8599 Automake generates rules to provide archives of the project for
8600 distributions in various formats.  Their targets are:
8601
8602 @table @asis
8603 @vindex BZIP2
8604 @item @code{dist-bzip2}
8605 Generate a bzip2 tar archive of the distribution.  bzip2 archives are
8606 frequently smaller than gzipped archives.
8607 By default, this rule makes @samp{bzip2} use a compression option of @option{-9}.
8608 To make it use a different one, set the @env{BZIP2} environment variable.
8609 For example, @samp{make dist-bzip2 BZIP2=-7}.
8610 @trindex dist-bzip2
8611
8612 @item @code{dist-gzip}
8613 Generate a gzip tar archive of the distribution.
8614 @trindex dist-gzip
8615
8616 @item @code{dist-lzip}
8617 Generate an @samp{lzip} tar archive of the distribution.  @command{lzip}
8618 archives are frequently smaller than @command{bzip2}-compressed archives.
8619 @trindex dist-lzip
8620
8621 @item @code{dist-shar}
8622 Generate a shar archive of the distribution.
8623 @trindex dist-shar
8624
8625 @vindex XZ_OPT
8626 @item @code{dist-xz}
8627 Generate an @samp{xz} tar archive of the distribution.  @command{xz}
8628 archives are frequently smaller than @command{bzip2}-compressed archives.
8629 By default, this rule makes @samp{xz} use a compression option of
8630 @option{-e}.  To make it use a different one, set the @env{XZ_OPT}
8631 environment variable.  For example, run this command to use the
8632 default compression ratio, but with a progress indicator:
8633 @samp{make dist-xz XZ_OPT=-7e}.
8634 @trindex dist-xz
8635
8636 @item @code{dist-zip}
8637 Generate a zip archive of the distribution.
8638 @trindex dist-zip
8639
8640 @item @code{dist-tarZ}
8641 Generate a compressed tar archive of
8642 the distribution.
8643 @trindex dist-tarZ
8644 @end table
8645
8646 The rule @code{dist} (and its historical synonym @code{dist-all}) will
8647 create archives in all the enabled formats, @ref{Options}.  By
8648 default, only the @code{dist-gzip} target is hooked to @code{dist}.
8649
8650
8651 @node Tests
8652 @chapter Support for test suites
8653
8654 @cindex Test suites
8655 @cindex @code{make check}
8656 @trindex check
8657
8658 Automake can generate code to handle two kinds of test suites.  One is
8659 based on integration with the @command{dejagnu} framework.  The other
8660 (and most used) form is based on the use of generic test scripts, and
8661 its activation is triggered by the definition of the special @code{TESTS}
8662 variable.  This second form allows for various degrees of sophistication
8663 and customization; in particular, it allows for concurrent execution
8664 of test scripts, use of established test protocols such as TAP, and
8665 definition of custom test drivers and test runners.
8666
8667 @noindent
8668 In either case, the testsuite is invoked via @samp{make check}.
8669
8670 @menu
8671 * Generalities about Testing::  Concepts and terminology about testing
8672 * Simple Tests::                Listing test scripts in @code{TESTS}
8673 * Custom Test Drivers::         Writing and using custom test drivers
8674 * Using the TAP test protocol:: Integrating test scripts that use the TAP protocol
8675 * DejaGnu Tests::               Interfacing with the @command{dejagnu} testing framework
8676 * Install Tests::               Running tests on installed packages
8677 @end menu
8678
8679 @node Generalities about Testing
8680 @section Generalities about Testing
8681
8682 The purpose of testing is to determine whether a program or system behaves
8683 as expected (e.g., known inputs produce the expected outputs, error
8684 conditions are correctly handled or reported, and older bugs do not
8685 resurface).
8686
8687 @cindex test case
8688 The minimal unit of testing is usually called @emph{test case}, or simply
8689 @emph{test}.  How a test case is defined or delimited, and even what
8690 exactly @emph{constitutes} a test case, depends heavily on the testing
8691 paradigm and/or framework in use, so we won't attempt any more precise
8692 definition.  The set of the test cases for a given program or system
8693 constitutes its @emph{testsuite}.
8694
8695 @cindex test harness
8696 @cindex testsuite harness
8697 A @emph{test harness} (also @emph{testsuite harness}) is a program or
8698 software component that executes all (or part of) the defined test cases,
8699 analyzes their outcomes, and report or register these outcomes
8700 appropriately.  Again, the details of how this is accomplished (and how
8701 the developer and user can influence it or interface with it) varies
8702 wildly, and we'll attempt no precise definition.
8703
8704 @cindex test pass
8705 @cindex test failure
8706 A test is said to @emph{pass} when it can determine that the condition or
8707 behaviour it means to verify holds, and is said to @emph{fail} when it can
8708 determine that such condition of behaviour does @emph{not} hold.
8709
8710 @cindex test skip
8711 Sometimes, tests can rely on non-portable tools or prerequisites, or
8712 simply make no sense on a given system (for example, a test checking a
8713 Windows-specific feature makes no sense on a GNU/Linux system).  In this
8714 case, accordingly to the definition above, the tests can neither be
8715 considered passed nor failed; instead, they are @emph{skipped} -- i.e.,
8716 they are not run, or their result is anyway ignored for what concerns
8717 the count of failures an successes.  Skips are usually explicitly
8718 reported though, so that the user will be aware that not all of the
8719 testsuite has really run.
8720
8721 @cindex xfail
8722 @cindex expected failure
8723 @cindex expected test failure
8724 @cindex xpass
8725 @cindex unexpected pass
8726 @cindex unexpected test pass
8727 It's not uncommon, especially during early development stages, that some
8728 tests fail for known reasons, and that the developer doesn't want to
8729 tackle these failures immediately (this is especially true when the
8730 failing tests deal with corner cases).  In this situation, the better
8731 policy is to declare that each of those failures is an @emph{expected
8732 failure} (or @emph{xfail}).  In case a test that is expected to fail ends
8733 up passing instead, many testing environments will flag the result as a
8734 special kind of failure called @emph{unexpected pass} (or @emph{xpass}).
8735
8736 @cindex hard error
8737 @cindex Distinction between errors and failures in testsuites
8738 Many testing environments and frameworks distinguish between test failures
8739 and hard errors.  As we've seen, a test failure happens when some invariant
8740 or expected behaviour of the software under test is not met.  An @emph{hard
8741 error} happens when e.g., the set-up of a test case scenario fails, or when
8742 some other unexpected or highly undesirable condition is encountered (for
8743 example, the program under test experiences a segmentation fault).
8744
8745 @emph{TODO}: Links to other test harnesses (esp. those sharing our
8746 terminology)?
8747
8748 @node Simple Tests
8749 @section Simple Tests
8750
8751 @menu
8752 * Scripts-based Testsuites::    Automake-specific concepts and terminology
8753 * Serial Test Harness::         Older (and obsolescent) serial test harness
8754 * Parallel Test Harness::       Generic concurrent test harness
8755 @end menu
8756
8757 @node Scripts-based Testsuites
8758 @subsection Scripts-based Testsuites
8759
8760 If the special variable @code{TESTS} is defined, its value is taken to be
8761 a list of programs or scripts to run in order to do the testing.  Under
8762 the appropriate circumstances, it's possible for @code{TESTS} to list
8763 also data files to be passed to one or more test scripts defined by
8764 different means (the so-called ``log compilers'', @pxref{Parallel Test
8765 Harness}).
8766
8767 Test scripts can be executed serially or concurrently.  Automake supports
8768 both these kinds of test execution, with the parallel test harness being
8769 the default.  The concurrent test harness relies on the concurrence
8770 capabilities (if any) offered by the underlying @command{make}
8771 implementation, and can thus only be as good as those are.
8772
8773 By default, only the exit statuses of the test scripts are considered when
8774 determining the testsuite outcome.  But Automake allows also the use of
8775 more complex test protocols, either standard (@pxref{Using the TAP test
8776 protocol}) or custom (@pxref{Custom Test Drivers}).  Note that you can't
8777 enable such protocols when the serial harness is used, though.
8778 In the rest of this section we are going to concentrate mostly on
8779 protocol-less tests, since we cover test protocols in a later section
8780 (again, @pxref{Custom Test Drivers}).
8781
8782 @cindex Exit status 77, special interpretation
8783 @cindex Exit status 99, special interpretation
8784 When no test protocol is in use, an exit status of 0 from a test script will
8785 denote a success, an exit status of 77 a skipped test, an exit status of 99
8786 an hard error, and any other exit status will denote a failure.
8787
8788 @cindex Tests, expected failure
8789 @cindex Expected test failure
8790 @vindex XFAIL_TESTS
8791 @vindex DISABLE_HARD_ERRORS
8792 @cindex Disabling hard errors
8793 You may define the variable @code{XFAIL_TESTS} to a list of tests
8794 (usually a subset of @code{TESTS}) that are expected to fail; this will
8795 effectively reverse the result of those tests (with the provision that
8796 skips and hard errors remain untouched).  You may also instruct the
8797 testsuite harness to treat hard errors like simple failures, by defining
8798 the @code{DISABLE_HARD_ERRORS} make variable to a nonempty value.
8799
8800 Note however that, for tests based on more complex test protocols,
8801 the exact effects of @code{XFAIL_TESTS} and @code{DISABLE_HARD_ERRORS}
8802 might change, or they might even have no effect at all (for example,
8803 @c Keep this in sync with tap-no-disable-hard-errors.sh
8804 in tests using TAP, there is not way to disable hard errors, and the
8805 @code{DISABLE_HARD_ERRORS} variable has no effect on them).
8806
8807 @anchor{Testsuite progress on console}
8808 @cindex Testsuite progress on console
8809 The result of each test case run by the scripts in @code{TESTS} will be
8810 printed on standard output, along with the test name.  For test protocols
8811 that allow more test cases per test script (such as TAP), a number,
8812 identifier and/or brief description specific for the single test case is
8813 expected to be printed in addition to the name of the test script.  The
8814 possible results (whose meanings should be clear from the previous
8815 @ref{Generalities about Testing}) are @code{PASS}, @code{FAIL},
8816 @code{SKIP}, @code{XFAIL}, @code{XPASS} and @code{ERROR}.  Here is an
8817 example of output from an hypothetical testsuite that uses both plain
8818 and TAP tests:
8819 @c Keep in sync with tap-doc.sh
8820 @example
8821 PASS: foo.sh
8822 PASS: zardoz.tap 1 - Daemon started
8823 PASS: zardoz.tap 2 - Daemon responding
8824 SKIP: zardoz.tap 3 - Daemon uses /proc # SKIP /proc is not mounted
8825 PASS: zardoz.tap 4 - Daemon stopped
8826 SKIP: bar.sh
8827 PASS: mu.tap 1
8828 XFAIL: mu.tap 2 # TODO frobnication not yet implemented
8829 @end example
8830
8831 @noindent
8832 A testsuite summary (expected to report at least the number of run,
8833 skipped and failed tests) will be printed at the end of the testsuite
8834 run.
8835
8836 @anchor{Simple tests and color-tests}
8837 @vindex AM_COLOR_TESTS
8838 @cindex Colorized testsuite output
8839 If the Automake option @code{color-tests} is used (@pxref{Options})
8840 and standard output is connected to a capable terminal, then the test
8841 results and the summary are colored appropriately.  The user can disable
8842 colored output by setting the @command{make} variable
8843 @samp{AM_COLOR_TESTS=no}, or force colored output even without a connecting
8844 terminal with @samp{AM_COLOR_TESTS=always}.  It's also worth noting that
8845 some @command{make} implementations, when used in parallel mode, have
8846 slightly different semantics (@pxref{Parallel make,,, autoconf,
8847 The Autoconf Manual}), which can break the automatic detection of a
8848 connection to a capable terminal.  If this is the case, you'll have to
8849 resort to the use of @samp{AM_COLOR_TESTS=always} in order to have the
8850 testsuite output colorized.
8851
8852 Test programs that need data files should look for them in @code{srcdir}
8853 (which is both a make variable and an environment variable made available
8854 to the tests), so that they work when building in a separate directory
8855 (@pxref{Build Directories, , Build Directories , autoconf,
8856 The Autoconf Manual}), and in particular for the @code{distcheck} rule
8857 (@pxref{Checking the Distribution}).
8858
8859 @vindex TESTS
8860 @vindex TESTS_ENVIRONMENT
8861 @vindex AM_TESTS_ENVIRONMENT
8862 The @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables can
8863 be used to run initialization code and set environment variables for the
8864 test scripts.  The former variable is developer-reserved, and can be
8865 defined in the @file{Makefile.am}, while the latter is reserved for the
8866 user, which can employ it to extend or override the settings in the
8867 former; for this to work portably, however, the contents of a non-empty
8868 @code{AM_TESTS_ENVIRONMENT} @emph{must} be terminated by a semicolon.
8869
8870 @vindex AM_TESTS_FD_REDIRECT
8871 The @code{AM_TESTS_FD_REDIRECT} variable can be used to define file
8872 descriptor redirections for the test scripts.  One might think that
8873 @code{AM_TESTS_ENVIRONMENT} could be used for this purpose, but experience
8874 has shown that doing so portably is practically impossible.  The main
8875 hurdle is constituted by Korn shells, which usually set the close-on-exec
8876 flag on file descriptors opened with the @command{exec} builtin, thus
8877 rendering an idiom like @code{AM_TESTS_ENVIRONMENT = exec 9>&2;}
8878 ineffectual.  This issue also affects some Bourne shells, such as the
8879 HP-UX's @command{/bin/sh},
8880 @c FIXME: should we offer a link to the relevant discussions on the
8881 @c bug-autoconf list?
8882
8883 @c Keep in sync with tests-environment-backcompat.sh
8884 @example
8885 AM_TESTS_ENVIRONMENT = \
8886 ## Some environment initializations are kept in a separate shell
8887 ## file 'tests-env.sh', which can make it easier to also run tests
8888 ## from the command line.
8889   . $(srcdir)/tests-env.sh; \
8890 ## On Solaris, prefer more POSIX-compliant versions of the standard
8891 ## tools by default.
8892   if test -d /usr/xpg4/bin; then \
8893     PATH=/usr/xpg4/bin:$$PATH; export PATH; \
8894   fi;
8895 @c $$ restore font-lock
8896 ## With this, the test scripts will be able to print diagnostic
8897 ## messages to the original standard error stream, even if the test
8898 ## driver redirects the stderr of the test scripts to a log file
8899 ## before executing them.
8900 AM_TESTS_FD_REDIRECT = 9>&2
8901 @end example
8902
8903 @noindent
8904 Note however that @code{AM_TESTS_ENVIRONMENT} is, for historical and
8905 implementation reasons, @emph{not} supported by the serial harness
8906 (@pxref{Serial Test Harness}).
8907
8908 Automake ensures that each file listed in @code{TESTS} is built before
8909 it is run; you can list both source and derived programs (or scripts)
8910 in @code{TESTS}; the generated rule will look both in @code{srcdir} and
8911 @file{.}.  For instance, you might want to run a C program as a test.
8912 To do this you would list its name in @code{TESTS} and also in
8913 @code{check_PROGRAMS}, and then specify it as you would any other
8914 program.
8915
8916 Programs listed in @code{check_PROGRAMS} (and @code{check_LIBRARIES},
8917 @code{check_LTLIBRARIES}...) are only built during @code{make check},
8918 not during @code{make all}.  You should list there any program needed
8919 by your tests that does not need to be built by @code{make all}.  Note
8920 that @code{check_PROGRAMS} are @emph{not} automatically added to
8921 @code{TESTS} because @code{check_PROGRAMS} usually lists programs used
8922 by the tests, not the tests themselves.  Of course you can set
8923 @code{TESTS = $(check_PROGRAMS)} if all your programs are test cases.
8924
8925 @node Serial Test Harness
8926 @subsection Older (and obsolescent) serial test harness
8927 @cindex @option{serial-tests}, Using
8928
8929 @emph{This harness is obsolescent}, and kept for backward-compatibility
8930 reasons only.  The user is strongly advised to just use the parallel test
8931 harness instead (@pxref{Parallel Test Harness}).
8932
8933 The serial test harness is enabled by the Automake option
8934 @option{serial-tests}. It operates by simply running the tests serially,
8935 one at the time, without any I/O redirection.  It's up to the user to
8936 implement logging of tests' output, if that's requited or desired.
8937 @c TODO: give an example of how this can be done.
8938
8939 For historical and implementation reasons, the @code{AM_TESTS_ENVIRONMENT}
8940 variable is @emph{not} supported by this harness (it will be silently
8941 ignored if defined); only @code{TESTS_ENVIRONMENT} is, and it is to be
8942 considered a developer-reserved variable.  This is done so that, when
8943 using the serial harness, @code{TESTS_ENVIRONMENT} can be defined to an
8944 invocation of an interpreter through which the tests are to be run.
8945 For instance, the following setup may be used to run tests with Perl:
8946
8947 @example
8948 TESTS_ENVIRONMENT = $(PERL) -Mstrict -w
8949 TESTS = foo.pl bar.pl baz.pl
8950 @end example
8951
8952 @noindent
8953 It's important to note that the use of @code{TESTS_ENVIRONMENT} endorsed
8954 here would be @emph{invalid} with the parallel harness.  That harness
8955 provides a more elegant way to achieve the same effect, with the further
8956 benefit of freeing the @code{TESTS_ENVIRONMENT} variable for the user
8957 (@pxref{Parallel Test Harness}).
8958
8959 Another, less serious limit of the serial harness is that it doesn't
8960 really distinguish between simple failures and hard errors; this is
8961 due to historical reasons only, and might be fixed in future Automake
8962 versions.
8963
8964 @node Parallel Test Harness
8965 @subsection Parallel Test Harness
8966
8967 By default, Automake generated a parallel (concurrent) test harness.  It
8968 features automatic collection of the test scripts output in @file{.log}
8969 files, concurrent execution of tests with @code{make -j}, specification
8970 of inter-test dependencies, lazy reruns of tests that have not completed
8971 in a prior run, and hard errors for exceptional failures.
8972
8973 This harness is still somewhat experimental and may undergo changes in
8974 order to satisfy additional portability requirements.
8975
8976 @anchor{Basics of test metadata}
8977 @vindex TEST_SUITE_LOG
8978 @vindex TESTS
8979 @cindex @file{.log} files
8980 @cindex @file{.trs} files
8981 @cindex test metadata
8982 The parallel test harness operates by defining a set of @command{make}
8983 rules that run the test scripts listed in @code{TESTS}, and, for each
8984 such script, save its output in a corresponding @file{.log} file and
8985 its results (and other ``metadata'', @pxref{API for Custom Test Drivers})
8986 in a corresponding @file{.trs} (as in @b{T}est @b{R}e@b{S}ults) file.
8987 @c We choose the '.trs' extension also because, at the time of writing,
8988 @c it isn't already used for other significant purposes; see e.g.:
8989 @c   - http://filext.com/file-extension/trs
8990 @c   - http://www.file-extensions.org/search/?searchstring=trs
8991 The @file{.log} file will contain all the output emitted by the test on
8992 its standard output and its standard error.  The @file{.trs} file will
8993 contain, among the other things, the results of the test cases run by
8994 the script.
8995
8996 The parallel test harness will also create a summary log file,
8997 @code{TEST_SUITE_LOG}, which defaults to @file{test-suite.log} and requires
8998 a @file{.log} suffix.  This file depends upon all the @file{.log} and
8999 @file{.trs} files created for the test scripts listed in @code{TESTS}.
9000
9001 @vindex VERBOSE
9002 As with the serial harness above, by default one status line is printed
9003 per completed test, and a short summary after the suite has completed.
9004 However, standard output and standard error of the test are redirected
9005 to a per-test log file, so that parallel execution does not produce
9006 intermingled output.  The output from failed tests is collected in the
9007 @file{test-suite.log} file.  If the variable @samp{VERBOSE} is set, this
9008 file is output after the summary.
9009 @c FIXME: we should be clearer about what we mean exactly here ...
9010 For best results, the tests should be verbose by default now.
9011
9012 @vindex TEST_EXTENSIONS
9013 @vindex TEST_LOGS
9014 Each couple of @file{.log} and @file{.trs} files is created when the
9015 corresponding test has completed.  The set of log files is listed in
9016 the read-only variable @code{TEST_LOGS}, and defaults to @code{TESTS},
9017 with the executable extension if any (@pxref{EXEEXT}), as well as any
9018 suffix listed in @code{TEST_EXTENSIONS} removed, and @file{.log} appended.
9019 Results are undefined if a test file name ends in several concatenated
9020 suffixes.  @code{TEST_EXTENSIONS} defaults to @file{.test}; it can be
9021 overridden by the user, in which case any extension listed in it must be
9022 constituted by a dot, followed by a non-digit alphabetic character,
9023 followed by any number of alphabetic characters.
9024 @c Keep in sync with test-extensions.sh
9025 For example, @samp{.sh}, @samp{.T} and @samp{.t1} are valid extensions,
9026 while @samp{.x-y}, @samp{.6c} and @samp{.t.1} are not.
9027
9028 @vindex _LOG_COMPILE
9029 @vindex _LOG_COMPILER
9030 @vindex _LOG_FLAGS
9031 @vindex LOG_COMPILE
9032 @vindex LOG_COMPILER
9033 @vindex LOG_FLAGS
9034 @vindex @var{ext}_LOG_COMPILE
9035 @vindex @var{ext}_LOG_COMPILER
9036 @vindex @var{ext}_LOG_FLAGS
9037 @vindex AM_@var{ext}_LOG_FLAGS
9038 @vindex AM_LOG_FLAGS
9039 For tests that match an extension @code{.@var{ext}} listed in
9040 @code{TEST_EXTENSIONS}, you can provide a custom ``test runner'' using
9041 the variable @code{@var{ext}_LOG_COMPILER} (note the upper-case
9042 extension) and pass options in @code{AM_@var{ext}_LOG_FLAGS} and allow
9043 the user to pass options in @code{@var{ext}_LOG_FLAGS}.  It will cause
9044 all tests with this extension to be called with this runner.  For all
9045 tests without a registered extension, the variables @code{LOG_COMPILER},
9046 @code{AM_LOG_FLAGS}, and @code{LOG_FLAGS} may be used.  For example,
9047
9048 @c Keep in sync with parallel-tests-log-compiler-example.sh
9049 @example
9050 TESTS = foo.pl bar.py baz
9051 TEST_EXTENSIONS = .pl .py
9052 PL_LOG_COMPILER = $(PERL)
9053 AM_PL_LOG_FLAGS = -w
9054 PY_LOG_COMPILER = $(PYTHON)
9055 AM_PY_LOG_FLAGS = -v
9056 LOG_COMPILER = ./wrapper-script
9057 AM_LOG_FLAGS = -d
9058 @end example
9059
9060 @noindent
9061 will invoke @samp{$(PERL) -w foo.pl}, @samp{$(PYTHON) -v bar.py},
9062 and @samp{./wrapper-script -d baz} to produce @file{foo.log},
9063 @file{bar.log}, and @file{baz.log}, respectively.  The @file{foo.trs},
9064 @file{bar.trs} and @file{baz.trs} files will be automatically produced
9065 as a side-effect.
9066
9067 It's important to note that, differently from what we've seen for the
9068 serial test harness (@pxref{Parallel Test Harness}), the
9069 @code{AM_TESTS_ENVIRONMENT} and @code{TESTS_ENVIRONMENT} variables
9070 @emph{cannot} be use to define a custom test runner; the
9071 @code{LOG_COMPILER} and @code{LOG_FLAGS} (or their extension-specific
9072 counterparts) should be used instead:
9073
9074 @example
9075 ## This is WRONG!
9076 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib' $(PERL) -Mstrict -w
9077 @end example
9078
9079 @example
9080 ## Do this instead.
9081 AM_TESTS_ENVIRONMENT = PERL5LIB='$(srcdir)/lib'; export PERL5LIB;
9082 LOG_COMPILER = $(PERL)
9083 AM_LOG_FLAGS = -Mstrict -w
9084 @end example
9085
9086 By default, the test suite harness will run all tests, but there are
9087 several ways to limit the set of tests that are run:
9088
9089 @itemize @bullet
9090 @item
9091 You can set the @code{TESTS} variable.  For example, you can use a
9092 command like this to run only a subset of the tests:
9093
9094 @example
9095 env TESTS="foo.test bar.test" make -e check
9096 @end example
9097
9098 Note however that the command above will unconditionally overwrite the
9099 @file{test-suite.log} file, thus clobbering the recorded results
9100 of any previous testsuite run.  This might be undesirable for packages
9101 whose testsuite takes long time to execute.  Luckily, this problem can
9102 easily be avoided by overriding also @code{TEST_SUITE_LOG} at runtime;
9103 for example,
9104
9105 @c Keep in sync with parallel-tests-log-override-2.sh
9106 @example
9107 env TEST_SUITE_LOG=partial.log TESTS="..." make -e check
9108 @end example
9109
9110 will write the result of the partial testsuite runs to the
9111 @file{partial.log}, without touching @file{test-suite.log}.
9112
9113 @item
9114 You can set the @code{TEST_LOGS} variable.  By default, this variable is
9115 computed at @command{make} run time from the value of @code{TESTS} as
9116 described above.  For example, you can use the following:
9117
9118 @example
9119 set x subset*.log; shift
9120 env TEST_LOGS="foo.log $*" make -e check
9121 @end example
9122
9123 The comments made above about @code{TEST_SUITE_LOG} overriding applies
9124 here too.
9125
9126 @item
9127 @vindex RECHECK_LOGS
9128 @cindex lazy test execution
9129 By default, the test harness removes all old per-test @file{.log} and
9130 @file{.trs} files before it starts running tests to regenerate them.  The
9131 variable @code{RECHECK_LOGS} contains the set of @file{.log} (and, by
9132 implication, @file{.trs}) files which are removed.  @code{RECHECK_LOGS}
9133 defaults to @code{TEST_LOGS}, which means all tests need to be rechecked.
9134 By overriding this variable, you can choose which tests need to be
9135 reconsidered.  For example, you can lazily rerun only those tests which
9136 are outdated, i.e., older than their prerequisite test files, by setting
9137 this variable to the empty value:
9138
9139 @example
9140 env RECHECK_LOGS= make -e check
9141 @end example
9142
9143 @item
9144 @trindex recheck
9145 You can ensure that all tests are rerun which have failed or passed
9146 unexpectedly, by running @code{make recheck} in the test directory.
9147 This convenience target will set @code{RECHECK_LOGS} appropriately
9148 before invoking the main test harness.
9149 @end itemize
9150
9151 @noindent
9152 In order to guarantee an ordering between tests even with @code{make
9153 -j@var{N}}, dependencies between the corresponding @file{.log} files
9154 may be specified through usual @command{make} dependencies.  For example,
9155 the following snippet lets the test named @file{foo-execute.test} depend
9156 upon completion of the test @file{foo-compile.test}:
9157
9158 @example
9159 TESTS = foo-compile.test foo-execute.test
9160 foo-execute.log: foo-compile.log
9161 @end example
9162
9163 @noindent
9164 Please note that this ordering ignores the @emph{results} of required
9165 tests, thus the test @file{foo-execute.test} is run even if the test
9166 @file{foo-compile.test} failed or was skipped beforehand.  Further,
9167 please note that specifying such dependencies currently works only for
9168 tests that end in one of the suffixes listed in @code{TEST_EXTENSIONS}.
9169
9170 Tests without such specified dependencies may be run concurrently with
9171 parallel @command{make -j@var{N}}, so be sure they are prepared for
9172 concurrent execution.
9173
9174 @cindex Unit tests
9175 @c Keep in sync with 'parallel-tests-extra-programs.test'.
9176 The combination of lazy test execution and correct dependencies between
9177 tests and their sources may be exploited for efficient unit testing
9178 during development.  To further speed up the edit-compile-test cycle, it
9179 may even be useful to specify compiled programs in @code{EXTRA_PROGRAMS}
9180 instead of with @code{check_PROGRAMS}, as the former allows intertwined
9181 compilation and test execution (but note that @code{EXTRA_PROGRAMS} are
9182 not cleaned automatically, @pxref{Uniform}).
9183
9184 The variables @code{TESTS} and @code{XFAIL_TESTS} may contain
9185 conditional parts as well as configure substitutions.  In the latter
9186 case, however, certain restrictions apply: substituted test names
9187 must end with a nonempty test suffix like @file{.test}, so that one of
9188 the inference rules generated by @command{automake} can apply.  For
9189 literal test names, @command{automake} can generate per-target rules
9190 to avoid this limitation.
9191
9192 Please note that it is currently not possible to use @code{$(srcdir)/}
9193 or @code{$(top_srcdir)/} in the @code{TESTS} variable.  This technical
9194 limitation is necessary to avoid generating test logs in the source tree
9195 and has the unfortunate consequence that it is not possible to specify
9196 distributed tests that are themselves generated by means of explicit
9197 rules, in a way that is portable to all @command{make} implementations
9198 (@pxref{Make Target Lookup,,, autoconf, The Autoconf Manual}, the
9199 semantics of FreeBSD and OpenBSD @command{make} conflict with this).
9200 In case of doubt you may want to require to use GNU @command{make},
9201 or work around the issue with inference rules to generate the tests.
9202
9203 @node Custom Test Drivers
9204 @section Custom Test Drivers
9205
9206 @menu
9207 * Overview of Custom Test Drivers Support::
9208 * Declaring Custom Test Drivers::
9209 * API for Custom Test Drivers::
9210 @end menu
9211
9212 @node Overview of Custom Test Drivers Support
9213 @subsection Overview of Custom Test Drivers Support
9214
9215 Starting from Automake version 1.12, the parallel test harness allows
9216 the package authors to use third-party custom test drivers, in case the
9217 default ones are inadequate for their purposes, or do not support their
9218 testing protocol of choice.
9219
9220 A custom test driver is expected to properly run the test programs passed
9221 to it (including the command-line arguments passed to those programs, if
9222 any), to analyze their execution and outcome, to create the @file{.log}
9223 and @file{.trs} files associated to these test runs, and to display the test
9224 results on the console. It is responsibility of the author of the test
9225 driver to ensure that it implements all the above steps meaningfully and
9226 correctly; Automake isn't and can't be of any help here.  On the other
9227 hand, the Automake-provided code for testsuite summary generation offers
9228 support for test drivers allowing several test results per test script,
9229 if they take care to register such results properly (@pxref{Log files
9230 generation and test results recording}).
9231
9232 The exact details of how test scripts' results are to be determined and
9233 analyzed is left to the individual drivers.  Some drivers might only
9234 consider the test script exit status (this is done for example by the
9235 default test driver used by the parallel test harness, described
9236 in the previous section).  Other drivers might implement more complex and
9237 advanced test protocols, which might require them to parse and interpreter
9238 the output emitted by the test script they're running (examples of such
9239 protocols are TAP and SubUnit).
9240
9241 It's very important to note that, even when using custom test drivers,
9242 most of the infrastructure described in the previous section about the
9243 parallel harness remains in place; this includes:
9244
9245 @itemize
9246 @item
9247 list of test scripts defined in @code{TESTS}, and overridable at
9248 runtime through the redefinition of @code{TESTS} or @code{TEST_LOGS};
9249 @item
9250 concurrency through the use of @command{make}'s option @option{-j};
9251 @item
9252 per-test @file{.log} and @file{.trs} files, and generation of a summary
9253 @file{.log} file from them;
9254 @item
9255 @code{recheck} target, @code{RECHECK_LOGS} variable, and lazy reruns
9256 of tests;
9257 @item
9258 inter-test dependencies;
9259 @item
9260 support for @code{check_*} variables (@code{check_PROGRAMS},
9261 @code{check_LIBRARIES}, ...);
9262 @item
9263 use of @code{VERBOSE} environment variable to get verbose output on
9264 testsuite failures;
9265 @item
9266 definition and honoring of @code{TESTS_ENVIRONMENT},
9267 @code{AM_TESTS_ENVIRONMENT} and @code{AM_TESTS_FD_REDIRECT}
9268 variables;
9269 @item
9270 definition of generic and extension-specific @code{LOG_COMPILER} and
9271 @code{LOG_FLAGS} variables.
9272 @end itemize
9273
9274 @noindent
9275 On the other hand, the exact semantics of how (and if)
9276 @option{color-tests}, @code{XFAIL_TESTS}, and hard errors are supported
9277 and handled is left to the individual test drivers.
9278
9279 @c TODO: We should really add a working example in the doc/ directory,
9280 @c TODO: and reference if from here.
9281
9282 @node Declaring Custom Test Drivers
9283 @subsection Declaring Custom Test Drivers
9284
9285 @vindex _LOG_DRIVER
9286 @vindex _LOG_DRIVER_FLAGS
9287 @vindex LOG_DRIVER
9288 @vindex LOG_DRIVER_FLAGS
9289 @vindex @var{ext}_LOG_DRIVER
9290 @vindex @var{ext}_LOG_DRIVER_FLAGS
9291 @vindex AM_@var{ext}_LOG_DRIVER_FLAGS
9292 @vindex AM_LOG_DRIVER_FLAGS
9293 Custom testsuite drivers are declared by defining the make variables
9294 @code{LOG_DRIVER} or @code{@var{ext}_LOG_DRIVER} (where @var{ext} must
9295 be declared in @code{TEST_EXTENSIONS}).  They must be defined to
9296 programs or scripts that will be used to drive the execution, logging,
9297 and outcome report of the tests with corresponding extensions (or of
9298 those with no registered extension in the case of @code{LOG_DRIVER}).
9299 Clearly, multiple distinct test drivers can be declared in the same
9300 @file{Makefile.am}.  Note moreover that the @code{LOG_DRIVER} variables
9301 are @emph{not} a substitute for the @code{LOG_COMPILER} variables: the
9302 two sets of variables can, and often do, usefully and legitimately
9303 coexist.
9304
9305 @c TODO: We should really be able to point to a clarifying example here!
9306
9307 The developer-reserved variable @code{AM_LOG_DRIVER_FLAGS} and the
9308 user-reserved variable @code{LOG_DRIVER_FLAGS} can be used to define
9309 flags that will be passed to each invocation of @code{LOG_DRIVER},
9310 with the user-defined flags obviously taking precedence over the
9311 developer-reserved ones.  Similarly, for each extension @var{ext}
9312 declared in @code{TEST_EXTENSIONS}, flags listed in
9313 @code{AM_@var{ext}_LOG_DRIVER_FLAGS} and
9314 @code{@var{ext}_LOG_DRIVER_FLAGS} will be passed to
9315 invocations of @code{@var{ext}_LOG_DRIVER}.
9316
9317 @node API for Custom Test Drivers
9318 @subsection API for Custom Test Drivers
9319
9320 Note that @emph{the APIs described here are still highly experimental},
9321 and will very likely undergo tightenings and likely also extensive changes
9322 in the future, to accommodate for new features or to satisfy additional
9323 portability requirements.
9324
9325 The main characteristic of these APIs is that they are designed to share
9326 as much infrastructure, semantics, and implementation details as possible
9327 with the parallel test harness and its default driver.
9328
9329 @menu
9330 * Command-line arguments for test drivers::
9331 * Log files generation and test results recording::
9332 * Testsuite progress output::
9333 @end menu
9334
9335 @node Command-line arguments for test drivers
9336 @subsubsection Command-line arguments for test drivers
9337
9338 A custom driver can rely on various command-line options and arguments
9339 being passed to it automatically by the Automake-generated test harness.
9340 It is @emph{mandatory} that it understands all of them (even if the exact
9341 interpretation of the associated semantics can legitimately change
9342 between a test driver and another, and even be a no-op in some drivers).
9343
9344 @noindent
9345 Here is the list of options:
9346
9347 @table @option
9348 @item --test-name=@var{NAME}
9349 The name of the test, with VPATH prefix (if any) removed.  This can have a
9350 suffix and a directory component (as in e.g., @file{sub/foo.test}), and is
9351 mostly meant to be used in console reports about testsuite advancements and
9352 results (@pxref{Testsuite progress output}).
9353 @item --log-file=@file{@var{PATH}.log}
9354 The @file{.log} file the test driver must create (@pxref{Basics of
9355 test metadata}).  If it has a directory component (as in e.g.,
9356 @file{sub/foo.log}), the test harness will ensure that such directory
9357 exists @emph{before} the test driver is called.
9358 @item --trs-file=@file{@var{PATH}.trs}
9359 The @file{.trs} file the test driver must create (@pxref{Basics of
9360 test metadata}).  If it has a directory component (as in e.g.,
9361 @file{sub/foo.trs}), the test harness will ensure that such directory
9362 exists @emph{before} the test driver is called.
9363 @item --color-tests=@{yes|no@}
9364 Whether the console output should be colorized or not (@pxref{Simple
9365 tests and color-tests}, to learn when this option gets activated and
9366 when it doesn't).
9367 @item --expect-failure=@{yes|no@}
9368 Whether the tested program is expected to fail.
9369 @item --enable-hard-errors=@{yes|no@}
9370 Whether ``hard errors'' in the tested program should be treated differently
9371 from normal failures or not (the default should be @code{yes}).  The exact
9372 meaning of ``hard error'' is highly dependent from the test protocols or
9373 conventions in use.
9374 @item --
9375 Explicitly terminate the list of options.
9376 @end table
9377
9378 @noindent
9379 The first non-option argument passed to the test driver is the program to
9380 be run, and all the following ones are command-line options and arguments
9381 for this program.
9382
9383 Note that the exact semantics attached to the @option{--color-tests},
9384 @option{--expect-failure} and @option{--enable-hard-errors} options are
9385 left up to the individual test drivers.  Still, having a behaviour
9386 compatible or at least similar to that provided by the default driver
9387 is advised, as that would offer a better consistency and a more pleasant
9388 user experience.
9389
9390 @node Log files generation and test results recording
9391 @subsubsection Log files generation and test results recording
9392
9393 The test driver must correctly generate the files specified by the
9394 @option{--log-file} and @option{--trs-file} option (even when the tested
9395 program fails or crashes).
9396
9397 The @file{.log} file should ideally contain all the output produced by the
9398 tested program, plus optionally other information that might facilitate
9399 debugging or analysis of bug reports.  Apart from that, its format is
9400 basically free.
9401
9402 The @file{.trs} file is used to register some metadata through the use
9403 of custom reStructuredText fields.  This metadata is expected to be
9404 employed in various ways by the parallel test harness; for example, to
9405 count the test results when printing the testsuite summary, or to decide
9406 which tests to re-run upon @command{make reheck}.  Unrecognized metadata
9407 in a @file{.trs} file is currently ignored by the harness, but this might
9408 change in the future. The list of currently recognized metadata follows.
9409
9410 @table @code
9411
9412 @item :test-result:
9413 @cindex Register test result
9414 @cindex Register test case result
9415 @cindex Test result, registering
9416 @cindex Test case result, registering
9417 @cindex @code{:test-result:}
9418 @cindex reStructuredText field, @code{:test-result:}
9419 The test driver must use this field to register the results of @emph{each}
9420 test case run by a test script file.  Several @code{:test-result:} fields
9421 can be present in the same @file{.trs} file; this is done in order to
9422 support test protocols that allow a single test script to run more test
9423 cases.
9424
9425 @c Keep this in sync with lib/am/check-am:$(TEST_SUITE_LOG).
9426 The only recognized test results are currently @code{PASS}, @code{XFAIL},
9427 @code{SKIP}, @code{FAIL}, @code{XPASS} and @code{ERROR}.  These results,
9428 when declared with @code{:test-result:}, can be optionally followed by
9429 text holding the name and/or a brief description of the corresponding
9430 test; the harness will ignore such extra text when generating
9431 @file{test-suite.log} and preparing the testsuite summary.
9432
9433 @c Keep in sync with 'test-metadata-recheck.test'.
9434 @item @code{:recheck:}
9435 @cindex :recheck:
9436 @cindex reStructuredText field, @code{:recheck:}
9437 If this field is present and defined to @code{no}, then the corresponding
9438 test script will @emph{not} be run upon a @command{make recheck}.  What
9439 happens when two or more @code{:recheck:} fields are present in the same
9440 @file{.trs} file is undefined behaviour.
9441
9442 @c Keep in sync with 'test-metadata-global-log.test'.
9443 @item @code{:copy-in-global-log:}
9444 @cindex :copy-in-global-log:
9445 @cindex reStructuredText field, @code{:copy-in-global-log:}
9446 If this field is present and defined to @code{no}, then the content
9447 of the @file{.log} file will @emph{not} be copied into the global
9448 @file{test-suite.log}.  We allow to forsake such copying because, while
9449 it can be useful in debugging and analysis of bug report, it can also be
9450 just a waste of space in normal situations, e.g., when a test script is
9451 successful.  What happens when two or more @code{:copy-in-global-log:}
9452 fields are present in the same @file{.trs} file is undefined behaviour.
9453
9454 @c Keep in sync with 'test-metadata-global-result.test'.
9455 @item @code{:test-global-result:}
9456 @cindex :test-global-result:
9457 @cindex reStructuredText field, @code{:test-global-result:}
9458 This is used to declare the "global result" of the script.  Currently,
9459 the value of this field is needed only to be reported (more or less
9460 verbatim) in the generated global log file @code{$(TEST_SUITE_LOG)},
9461 so it's quite free-form.  For example, a test script which run 10 test
9462 cases, 6 of which pass and 4 of which are skipped, could reasonably have
9463 a @code{PASS/SKIP} value for this field, while a test script which run
9464 19 successful tests and one failed test could have an @code{ALMOST
9465 PASSED} value.  What happens when two or more @code{:test-global-result:}
9466 fields are present in the same @file{.trs} file is undefined behaviour.
9467 @end table
9468
9469 @noindent
9470 Let's see a small example.  Assume a @file{.trs} file contains the
9471 following lines:
9472
9473 @example
9474 :test-result: PASS server starts
9475 :global-log-copy: no
9476 :test-result: PASS HTTP/1.1 request
9477 :test-result: FAIL HTTP/1.0 request
9478 :recheck: yes
9479 :test-result: SKIP HTTPS request (TLS library wasn't available)
9480 :test-result: PASS server stops
9481 @end example
9482
9483 @noindent
9484 Then the corresponding test script will be re-run by @command{make check},
9485 will contribute with @emph{five} test results to the testsuite summary
9486 (three of these tests being successful, one failed, and one skipped), and
9487 the content of the corresponding @file{.log} file will @emph{not} be
9488 copied in the global log file @file{test-suite.log}.
9489
9490 @node Testsuite progress output
9491 @subsubsection Testsuite progress output
9492
9493 A custom test driver also has the task of displaying, on the standard
9494 output, the test results as soon as they become available.  Depending on
9495 the protocol in use, it can also display the reasons for failures and
9496 skips, and, more generally, any useful diagnostic output (but remember
9497 that each line on the screen is precious, so that cluttering the screen
9498 with overly verbose information is bad idea).  The exact format of this
9499 progress output is left up to the test driver; in fact, a custom test
9500 driver might @emph{theoretically} even decide not to do any such report,
9501 leaving it all to the testsuite summary (that would be a very lousy idea,
9502 of course, and serves only to illustrate the flexibility that is
9503 granted here).
9504
9505 Remember that consistency is good; so, if possible, try to be consistent
9506 with the output of the built-in Automake test drivers, providing a similar
9507 ``look & feel''.  In particular, the testsuite progress output should be
9508 colorized when the @option{--color-tests} is passed to the driver.  On the
9509 other end, if you are using a known and widespread test protocol with
9510 well-established implementations, being consistent with those
9511 implementations' output might be a good idea too.
9512
9513 @c TODO: Give an example, maybe inspired to py.test-style output.
9514 @c TODO: That is a good idea because it shows a test driver that allows
9515 @c TODO: for different levels of verbosity in the progress output (could
9516 @c TODO: be implemented either using a driver cmdline flag, or an
9517 @c TODO: environment variable, or both).
9518
9519 @node Using the TAP test protocol
9520 @section Using the TAP test protocol
9521
9522 @menu
9523 * Introduction to TAP::
9524 * Use TAP with the Automake test harness::
9525 * Incompatibilities with other TAP parsers and drivers::
9526 * Links and external resources on TAP::
9527 @end menu
9528
9529 @node Introduction to TAP
9530 @subsection Introduction to TAP
9531
9532 TAP, the Test Anything Protocol, is a simple text-based interface between
9533 testing modules or programs and a test harness.  The tests (also called
9534 ``TAP producers'' in this context) write test results in a simple format
9535 on standard output; a test harness (also called ``TAP consumer'') will
9536 parse and interpret these results, and properly present them to the user,
9537 and/or register them for later analysis.  The exact details of how this
9538 is accomplished can vary among different test harnesses.  The Automake
9539 harness will present the results on the console in the usual
9540 fashion (@pxref{Testsuite progress on console}), and will use the
9541 @file{.trs} files (@pxref{Basics of test metadata}) to store the test
9542 results and related metadata.  Apart from that, it will try to remain
9543 as much compatible as possible with pre-existing and widespread utilities,
9544 such as the @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9545 @command{prove} utility}, at least for the simpler usages.
9546
9547 TAP started its life as part of the test harness for Perl, but today
9548 it has been (mostly) standardized, and has various independent
9549 implementations in different languages; among them, C, C++, Perl,
9550 Python, PHP, and Java.  For a semi-official specification of the
9551 TAP protocol, please refer to the documentation of
9552 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9553       @samp{Test::Harness::TAP}}.
9554
9555 The most relevant real-world usages of TAP are obviously in the testsuites
9556 of @command{perl} and of many perl modules.  Still, also other important
9557 third-party packages, such as @uref{http://git-scm.com/, @command{git}},
9558 use TAP in their testsuite.
9559
9560 @node Use TAP with the Automake test harness
9561 @subsection Use TAP with the Automake test harness
9562
9563 Currently, the TAP driver that comes with Automake requires some by-hand
9564 steps on the developer's part (this situation should hopefully be improved
9565 in future Automake versions).  You'll have to grab the @file{tap-driver.sh}
9566 script from the Automake distribution by hand, copy it in your source tree,
9567 add a call to @code{AC_PROG_AWK} in @file{configure.ac} to search for a
9568 proper awk program, and use the Automake support for third-party test
9569 drivers to instruct the harness to use the @file{tap-driver.sh} script
9570 and that awk program to run your TAP-producing tests.  See the example
9571 below for clarification.
9572
9573 Apart from the options common to all the Automake test drivers
9574 (@pxref{Command-line arguments for test drivers}), the @file{tap-driver.sh}
9575 supports the following options, whose names are chosen for enhanced
9576 compatibility with the @command{prove} utility.
9577
9578 @table @option
9579 @c Keep in sync with 'tap-exit.test' and 'tap-signal.tap'.
9580 @item --ignore-exit
9581 Causes the test driver to ignore the exit status of the test scripts;
9582 by default, the driver will report an error if the script exits with a
9583 non-zero status.  This option has effect also on non-zero exit statuses
9584 due to termination by a signal.
9585 @item --comments
9586 Instruct the test driver to display TAP diagnostic (i.e., lines beginning
9587 with the @samp{#} character) in the testsuite progress output too; by
9588 default, TAP diagnostic is only copied to the @file{.log} file.
9589 @item --no-comments
9590 Revert the effects of @option{--comments}.
9591 @item --merge
9592 Instruct the test driver to merge the test scripts' standard error into
9593 their standard output.  This is necessary if you want to ensure that
9594 diagnostics from the test scripts are displayed in the correct order
9595 relative to test results; this can be of great help in debugging
9596 (especially if your test scripts are shell scripts run with shell
9597 tracing active).  As a downside, this option might cause the test
9598 harness to get confused if anything that appears on standard error
9599 looks like a test result.
9600 @item --no-merge
9601 Revert the effects of @option{--merge}.
9602 @item --diagnostic-string=@var{STRING}
9603 Change the string that introduces TAP diagnostic from the default value
9604 of ``@code{#}'' to @code{@var{STRING}}.  This can be useful if your
9605 TAP-based test scripts produce verbose output on which they have limited
9606 control (because, say, the output comes from other tools invoked in the
9607 scripts), and it might contain text that gets spuriously interpreted as
9608 TAP diagnostic: such an issue can be solved by redefining the string that
9609 activates TAP diagnostic to a value you know won't appear by chance in
9610 the tests' output.  Note however that this feature is non-standard, as
9611 the ``official'' TAP protocol does not allow for such a customization; so
9612 don't use it if you can avoid it.
9613 @end table
9614
9615 @noindent
9616 Here is an example of how the TAP driver can be set up and used.
9617
9618 @c Keep in sync with tap-doc2.sh
9619 @example
9620 % @kbd{cat configure.ac}
9621 AC_INIT([GNU Try Tap], [1.0], [bug-automake@@gnu.org])
9622 AC_CONFIG_AUX_DIR([build-aux])
9623 AM_INIT_AUTOMAKE([foreign -Wall -Werror])
9624 AC_CONFIG_FILES([Makefile])
9625 AC_REQUIRE_AUX_FILE([tap-driver.sh])
9626 AC_PROG_AWK
9627 AC_OUTPUT
9628
9629 % @kbd{cat Makefile.am}
9630 TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
9631                   $(top_srcdir)/build-aux/tap-driver.sh
9632 TESTS = foo.test bar.test baz.test
9633 EXTRA_DIST = $(TESTS)
9634
9635 % @kbd{cat foo.test}
9636 #!/bin/sh
9637 echo 1..4 # Number of tests to be executed.
9638 echo 'ok 1 - Swallows fly'
9639 echo 'not ok 2 - Caterpillars fly # TODO metamorphosis in progress'
9640 echo 'ok 3 - Pigs fly # SKIP not enough acid'
9641 echo '# I just love word plays ...'
9642 echo 'ok 4 - Flies fly too :-)'
9643
9644 % @kbd{cat bar.test}
9645 #!/bin/sh
9646 echo 1..3
9647 echo 'not ok 1 - Bummer, this test has failed.'
9648 echo 'ok 2 - This passed though.'
9649 echo 'Bail out! Ennui kicking in, sorry...'
9650 echo 'ok 3 - This will not be seen.'
9651
9652 % @kbd{cat baz.test}
9653 #!/bin/sh
9654 echo 1..1
9655 echo ok 1
9656 # Exit with error, even if all the tests have been successful.
9657 exit 7
9658
9659 % @kbd{cp @var{PREFIX}/share/automake-@var{APIVERSION}/tap-driver.pl .}
9660 % @kbd{autoreconf -vi && ./configure && make check}
9661 ...
9662 PASS: foo.test 1 - Swallows fly
9663 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9664 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9665 PASS: foo.test 4 - Flies fly too :-)
9666 FAIL: bar.test 1 - Bummer, this test has failed.
9667 PASS: bar.test 2 - This passed though.
9668 ERROR: bar.test - Bail out! Ennui kicking in, sorry...
9669 PASS: baz.test 1
9670 ERROR: baz.test - exited with status 7
9671 ...
9672 Please report to bug-automake@@gnu.org
9673 ...
9674 % @kbd{echo exit status: $?}
9675 exit status: 1
9676
9677 @c Keep the "skewed" indentation below, it produces pretty PDF output.
9678 % @kbd{env TEST_LOG_DRIVER_FLAGS='--comments --ignore-exit' \
9679       TESTS='foo.test baz.test' make -e check}
9680 ...
9681 PASS: foo.test 1 - Swallows fly
9682 XFAIL: foo.test 2 - Caterpillars fly # TODO metamorphosis in progress
9683 SKIP: foo.test 3 - Pigs fly # SKIP not enough acid
9684 # foo.test: I just love word plays...
9685 PASS: foo.test 4 - Flies fly too :-)
9686 PASS: baz.test 1
9687 ...
9688 % @kbd{echo exit status: $?}
9689 exit status: 0
9690 @end example
9691
9692 @node Incompatibilities with other TAP parsers and drivers
9693 @subsection Incompatibilities with other TAP parsers and drivers
9694
9695 For implementation or historical reasons, the TAP driver and harness as
9696 implemented by Automake have some minors incompatibilities with the
9697 mainstream versions, which you should be aware of.
9698
9699 @itemize @bullet
9700 @item
9701 A @code{Bail out!} directive doesn't stop the whole testsuite, but only
9702 the test script it occurs in.  This doesn't follow TAP specifications,
9703 but on the other hand it maximizes compatibility (and code sharing) with
9704 the ``hard error'' concept of the default testsuite driver.
9705 @item
9706 The @code{version} and @code{pragma} directives are not supported.
9707 @item
9708 The @option{--diagnostic-string} option of our driver allows to modify
9709 the string that introduces TAP diagnostic from the default value
9710 of ``@code{#}''.  The standard TAP protocol has currently no way to
9711 allow this, so if you use it your diagnostic will be lost to more
9712 compliant tools like @command{prove} and @code{Test::Harness}
9713 @item
9714 And there are probably some other small and yet undiscovered
9715 incompatibilities, especially in corner cases or with rare usages.
9716 @end itemize
9717
9718 @node Links and external resources on TAP
9719 @subsection Links and external resources on TAP
9720
9721 @noindent
9722 Here are some links to more extensive official or third-party
9723 documentation and resources about the TAP protocol and related
9724 tools and libraries.
9725 @itemize @bullet
9726 @item
9727 @uref{http://search.cpan.org/~petdance/Test-Harness/lib/Test/Harness/TAP.pod,
9728       @samp{Test::Harness::TAP}},
9729 the (mostly) official documentation about the TAP format and protocol.
9730 @item
9731 @uref{http://search.cpan.org/~andya/Test-Harness/bin/prove,
9732       @command{prove}},
9733 the most famous command-line TAP test driver, included in the distribution
9734 of @command{perl} and
9735 @uref{http://search.cpan.org/~andya/Test-Harness/lib/Test/Harness.pm,
9736       @samp{Test::Harness}}.
9737 @item
9738 The @uref{http://testanything.org/wiki/index.php/Main_Page,TAP wiki}.
9739 @item
9740 A ``gentle introduction'' to testing for perl coders:
9741 @uref{http://search.cpan.org/dist/Test-Simple/lib/Test/Tutorial.pod,
9742       @samp{Test::Tutorial}}.
9743 @item
9744 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/Simple.pm,
9745       @samp{Test::Simple}}
9746 and
9747 @uref{http://search.cpan.org/~mschwern/Test-Simple/lib/Test/More.pm,
9748       @samp{Test::More}},
9749 the standard perl testing libraries, which are based on TAP.
9750 @item
9751 @uref{http://www.eyrie.org/~eagle/software/c-tap-harness/,C TAP Harness},
9752 a C-based project implementing both a TAP producer and a TAP consumer.
9753 @item
9754 @uref{http://www.tap4j.org/,tap4j},
9755 a Java-based project implementing both a TAP producer and a TAP consumer.
9756 @end itemize
9757
9758 @node DejaGnu Tests
9759 @section DejaGnu Tests
9760
9761 If @uref{ftp://ftp.gnu.org/gnu/dejagnu/, @command{dejagnu}} appears in
9762 @code{AUTOMAKE_OPTIONS}, then a @command{dejagnu}-based test suite is
9763 assumed.  The variable @code{DEJATOOL} is a list of names that are
9764 passed, one at a time, as the @option{--tool} argument to
9765 @command{runtest} invocations; it defaults to the name of the package.
9766
9767 The variable @code{RUNTESTDEFAULTFLAGS} holds the @option{--tool} and
9768 @option{--srcdir} flags that are passed to dejagnu by default; this can be
9769 overridden if necessary.
9770 @vindex RUNTESTDEFAULTFLAGS
9771
9772 The variables @code{EXPECT} and @code{RUNTEST} can
9773 also be overridden to provide project-specific values.  For instance,
9774 you will need to do this if you are testing a compiler toolchain,
9775 because the default values do not take into account host and target
9776 names.
9777 @opindex dejagnu
9778 @vindex DEJATOOL
9779 @vindex EXPECT
9780 @vindex RUNTEST
9781
9782 The contents of the variable @code{RUNTESTFLAGS} are passed to the
9783 @code{runtest} invocation.  This is considered a ``user variable''
9784 (@pxref{User Variables}).  If you need to set @command{runtest} flags in
9785 @file{Makefile.am}, you can use @code{AM_RUNTESTFLAGS} instead.
9786 @vindex RUNTESTFLAGS
9787 @vindex AM_RUNTESTFLAGS
9788
9789 @cindex @file{site.exp}
9790 Automake will generate rules to create a local @file{site.exp} file,
9791 defining various variables detected by @command{configure}.  This file
9792 is automatically read by DejaGnu.  It is OK for the user of a package
9793 to edit this file in order to tune the test suite.  However this is
9794 not the place where the test suite author should define new variables:
9795 this should be done elsewhere in the real test suite code.
9796 Especially, @file{site.exp} should not be distributed.
9797
9798 Still, if the package author has legitimate reasons to extend
9799 @file{site.exp} at @command{make} time, he can do so by defining
9800 the variable @code{EXTRA_DEJAGNU_SITE_CONFIG}; the files listed
9801 there will be considered @file{site.exp} prerequisites, and their
9802 content will be appended to it (in the same order in which they
9803 appear in @code{EXTRA_DEJAGNU_SITE_CONFIG}).  Note that files are
9804 @emph{not} distributed by default.
9805
9806 For more information regarding DejaGnu test suites, see @ref{Top, , ,
9807 dejagnu, The DejaGnu Manual}.
9808
9809 @node Install Tests
9810 @section Install Tests
9811
9812 The @code{installcheck} target is available to the user as a way to
9813 run any tests after the package has been installed.  You can add tests
9814 to this by writing an @code{installcheck-local} rule.
9815
9816
9817 @node Rebuilding
9818 @chapter Rebuilding Makefiles
9819 @cindex rebuild rules
9820
9821 Automake generates rules to automatically rebuild @file{Makefile}s,
9822 @file{configure}, and other derived files like @file{Makefile.in}.
9823
9824 @acindex AM_MAINTAINER_MODE
9825 If you are using @code{AM_MAINTAINER_MODE} in @file{configure.ac}, then
9826 these automatic rebuilding rules are only enabled in maintainer mode.
9827
9828 @vindex ACLOCAL_AMFLAGS
9829 Sometimes you need to run @command{aclocal} with an argument like
9830 @option{-I} to tell it where to find @file{.m4} files.  Since
9831 sometimes @command{make} will automatically run @command{aclocal}, you
9832 need a way to specify these arguments.  You can do this by defining
9833 @code{ACLOCAL_AMFLAGS}; this holds arguments that are passed verbatim
9834 to @command{aclocal}.  This variable is only useful in the top-level
9835 @file{Makefile.am}.
9836
9837 @vindex CONFIG_STATUS_DEPENDENCIES
9838 @vindex CONFIGURE_DEPENDENCIES
9839 @cindex @file{version.sh}, example
9840 @cindex @file{version.m4}, example
9841
9842 Sometimes it is convenient to supplement the rebuild rules for
9843 @file{configure} or @file{config.status} with additional dependencies.
9844 The variables @code{CONFIGURE_DEPENDENCIES} and
9845 @code{CONFIG_STATUS_DEPENDENCIES} can be used to list these extra
9846 dependencies.  These variables should be defined in all
9847 @file{Makefile}s of the tree (because these two rebuild rules are
9848 output in all them), so it is safer and easier to @code{AC_SUBST} them
9849 from @file{configure.ac}.  For instance, the following statement will
9850 cause @file{configure} to be rerun each time @file{version.sh} is
9851 changed.
9852
9853 @example
9854 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/version.sh'])
9855 @end example
9856
9857 @noindent
9858 Note the @samp{$(top_srcdir)/} in the file name.  Since this variable
9859 is to be used in all @file{Makefile}s, its value must be sensible at
9860 any level in the build hierarchy.
9861
9862 Beware not to mistake @code{CONFIGURE_DEPENDENCIES} for
9863 @code{CONFIG_STATUS_DEPENDENCIES}.
9864
9865 @code{CONFIGURE_DEPENDENCIES} adds dependencies to the
9866 @file{configure} rule, whose effect is to run @command{autoconf}.  This
9867 variable should be seldom used, because @command{automake} already tracks
9868 @code{m4_include}d files.  However it can be useful when playing
9869 tricky games with @code{m4_esyscmd} or similar non-recommendable
9870 macros with side effects.
9871
9872 @code{CONFIG_STATUS_DEPENDENCIES} adds dependencies to the
9873 @file{config.status} rule, whose effect is to run @file{configure}.
9874 This variable should therefore carry any non-standard source that may
9875 be read as a side effect of running @command{configure}, like @file{version.sh}
9876 in the example above.
9877
9878 Speaking of @file{version.sh} scripts, we recommend against them
9879 today.  We recommend that @file{version.sh} be replaced by an M4 file
9880 that is included by @file{configure.ac}:
9881
9882 @example
9883 m4_include([version.m4])
9884 AC_INIT([name], VERSION_NUMBER)
9885 AM_INIT_AUTOMAKE
9886 @dots{}
9887 @end example
9888
9889 @noindent
9890 Here @file{version.m4} could contain something like
9891 @samp{m4_define([VERSION_NUMBER], [1.2])}.  The advantage of this
9892 second form is that @command{automake} will take care of the
9893 dependencies when defining the rebuild rule, and will also distribute
9894 the file automatically.
9895
9896
9897 @node Options
9898 @chapter Changing Automake's Behavior
9899
9900 @menu
9901 * Options generalities::        Semantics of Automake option
9902 * List of Automake options::    A comprehensive list of Automake options
9903 @end menu
9904
9905 @node Options generalities
9906 @section Options generalities
9907
9908 Various features of Automake can be controlled by options.  Except where
9909 noted otherwise, options can be specified in one of several ways.  Most
9910 options can be applied on a per-@file{Makefile} basis when listed in a
9911 special @file{Makefile} variable named @code{AUTOMAKE_OPTIONS}.  Some
9912 of these options only make sense when specified in the toplevel
9913 @file{Makefile.am} file.  Options are applied globally to all processed
9914 @file{Makefile} files when listed in the first argument of
9915 @code{AM_INIT_AUTOMAKE} in @file{configure.ac}, and some options which
9916 require changes to the @command{configure} script can only be specified
9917 there.  These are annotated below.
9918
9919 As a general rule, options specified in @code{AUTOMAKE_OPTIONS} take
9920 precedence over those specified in @code{AM_INIT_AUTOMAKE}, which in
9921 turn take precedence over those specified on the command line.
9922
9923 Also, some care must be taken about the interactions among strictness
9924 level and warning categories.  As a general rule, strictness-implied
9925 warnings are overridden by those specified by explicit options.  For
9926 example, even if @samp{portability} warnings are disabled by default
9927 in @option{foreign} strictness, an usage like this will end up enabling
9928 them:
9929
9930 @example
9931 AUTOMAKE_OPTIONS = -Wportability foreign
9932 @end example
9933
9934 However, a strictness level specified in a higher-priority context
9935 will override all the explicit warnings specified in a lower-priority
9936 context.  For example, if @file{configure.ac} contains:
9937
9938 @example
9939 AM_INIT_AUTOMAKE([-Wportability])
9940 @end example
9941
9942 @noindent
9943 and @file{Makefile.am} contains:
9944
9945 @example
9946 AUTOMAKE_OPTIONS = foreign
9947 @end example
9948
9949 @noindent
9950 then @samp{portability} warnings will be @emph{disabled} in
9951 @file{Makefile.am}.
9952
9953 @node List of Automake options
9954 @section List of Automake options
9955
9956 @vindex AUTOMAKE_OPTIONS
9957
9958 @table @asis
9959 @item @option{gnits}
9960 @itemx @option{gnu}
9961 @itemx @option{foreign}
9962 @cindex Option, @option{gnits}
9963 @cindex Option, @option{gnu}
9964 @cindex Option, @option{foreign}
9965 @opindex gnits
9966 @opindex gnu
9967 @opindex foreign
9968
9969 Set the strictness as appropriate.  The @option{gnits} option also
9970 implies options @option{readme-alpha} and @option{check-news}.
9971
9972 @item @option{check-news}
9973 @cindex Option, @option{check-news}
9974 @opindex check-news
9975 Cause @samp{make dist} to fail unless the current version number appears
9976 in the first few lines of the @file{NEWS} file.
9977
9978 @item @option{color-tests}
9979 @cindex Option, @option{color-tests}
9980 @opindex color-tests
9981 Cause output of the serial and parallel test harnesses (see @ref{Simple
9982 Tests}) and of properly-written custom test drivers (@pxref{Custom Test
9983 Drivers}) to be colorized on capable terminals.
9984
9985 @item @option{dejagnu}
9986 @cindex Option, @option{dejagnu}
9987 @opindex dejagnu
9988 Cause @command{dejagnu}-specific rules to be generated.  @xref{DejaGnu Tests}.
9989
9990 @item @option{dist-bzip2}
9991 @cindex Option, @option{dist-bzip2}
9992 @opindex dist-bzip2
9993 Hook @code{dist-bzip2} to @code{dist}.
9994 @trindex dist-bzip2
9995
9996 @item @option{dist-lzip}
9997 @cindex Option, @option{dist-lzip}
9998 @opindex dist-lzip
9999 Hook @code{dist-lzip} to @code{dist}.
10000 @trindex dist-lzip
10001
10002 @item @option{dist-shar}
10003 @cindex Option, @option{dist-shar}
10004 @opindex dist-shar
10005 Hook @code{dist-shar} to @code{dist}.
10006 @trindex dist-shar
10007
10008 @item @option{dist-zip}
10009 @cindex Option, @option{dist-zip}
10010 @opindex dist-zip
10011 Hook @code{dist-zip} to @code{dist}.
10012 @trindex dist-zip
10013
10014 @item @option{dist-tarZ}
10015 @cindex Option, @option{dist-tarZ}
10016 @opindex dist-tarZ
10017 Hook @code{dist-tarZ} to @code{dist}.
10018 @trindex dist-tarZ
10019
10020 @item @option{filename-length-max=99}
10021 @cindex Option, @option{filename-length-max=99}
10022 @opindex filename-length-max=99
10023 Abort if file names longer than 99 characters are found during
10024 @samp{make dist}.  Such long file names are generally considered not to
10025 be portable in tarballs.  See the @option{tar-v7} and @option{tar-ustar}
10026 options below.  This option should be used in the top-level
10027 @file{Makefile.am} or as an argument of @code{AM_INIT_AUTOMAKE} in
10028 @file{configure.ac}, it will be ignored otherwise.  It will also be
10029 ignored in sub-packages of nested packages (@pxref{Subpackages}).
10030
10031 @item @option{no-define}
10032 @cindex Option, @option{no-define}
10033 @opindex no-define
10034 This option is meaningful only when passed as an argument to
10035 @code{AM_INIT_AUTOMAKE}.  It will prevent the @code{PACKAGE} and
10036 @code{VERSION} variables from being @code{AC_DEFINE}d.
10037
10038 @item @option{no-dependencies}
10039 @cindex Option, @option{no-dependencies}
10040 @opindex no-dependencies
10041 This is similar to using @option{--ignore-deps} on the command line,
10042 but is useful for those situations where you don't have the necessary
10043 bits to make automatic dependency tracking work
10044 (@pxref{Dependencies}).  In this case the effect is to effectively
10045 disable automatic dependency tracking.
10046
10047 @item @option{no-dist}
10048 @cindex Option, @option{no-dist}
10049 @opindex no-dist
10050 Don't emit any code related to @code{dist} target.  This is useful
10051 when a package has its own method for making distributions.
10052
10053 @item @option{no-dist-gzip}
10054 @cindex Option, @option{no-dist-gzip}
10055 @opindex no-dist-gzip
10056 Do not hook @code{dist-gzip} to @code{dist}.
10057 @trindex no-dist-gzip
10058
10059 @item @option{no-exeext}
10060 @cindex Option, @option{no-exeext}
10061 @opindex no-exeext
10062 If your @file{Makefile.am} defines a rule for target @code{foo}, it
10063 will override a rule for a target named @samp{foo$(EXEEXT)}.  This is
10064 necessary when @code{EXEEXT} is found to be empty.  However, by
10065 default @command{automake} will generate an error for this use.  The
10066 @option{no-exeext} option will disable this error.  This is intended for
10067 use only where it is known in advance that the package will not be
10068 ported to Windows, or any other operating system using extensions on
10069 executables.
10070
10071 @item @option{no-installinfo}
10072 @cindex Option, @option{no-installinfo}
10073 @opindex no-installinfo
10074 The generated @file{Makefile.in} will not cause info pages to be built
10075 or installed by default.  However, @code{info} and @code{install-info}
10076 targets will still be available.  This option is disallowed at
10077 @option{gnu} strictness and above.
10078 @trindex info
10079 @trindex install-info
10080
10081 @item @option{no-installman}
10082 @cindex Option, @option{no-installman}
10083 @opindex no-installman
10084 The generated @file{Makefile.in} will not cause man pages to be
10085 installed by default.  However, an @code{install-man} target will still
10086 be available for optional installation.  This option is disallowed at
10087 @option{gnu} strictness and above.
10088 @trindex install-man
10089
10090 @item @option{nostdinc}
10091 @cindex Option, @option{nostdinc}
10092 @opindex nostdinc
10093 This option can be used to disable the standard @option{-I} options that
10094 are ordinarily automatically provided by Automake.
10095
10096 @item @option{no-texinfo.tex}
10097 @cindex Option, @option{no-texinfo.tex}
10098 @opindex no-texinfo.tex
10099 Don't require @file{texinfo.tex}, even if there are texinfo files in
10100 this directory.
10101
10102 @item @option{serial-tests}
10103 @cindex Option, @option{serial-tests}
10104 @opindex serial-tests
10105 Enable the older serial test suite harness for @code{TESTS} (@pxref{Serial
10106 Test Harness}, for more information).
10107
10108 @item @option{parallel-tests}
10109 @cindex Option, @option{parallel-tests}
10110 @opindex parallel-tests
10111 Enable test suite harness for @code{TESTS} that can run tests in parallel
10112 (@pxref{Parallel Test Harness}, for more information).  This option is
10113 only kept for backward-compatibility, since the parallel test harness is
10114 the default now.
10115
10116 @item @option{readme-alpha}
10117 @cindex Option, @option{readme-alpha}
10118 @opindex readme-alpha
10119 If this release is an alpha release, and the file @file{README-alpha}
10120 exists, then it will be added to the distribution.  If this option is
10121 given, version numbers are expected to follow one of two forms.  The
10122 first form is @samp{@var{major}.@var{minor}.@var{alpha}}, where each
10123 element is a number; the final period and number should be left off for
10124 non-alpha releases.  The second form is
10125 @samp{@var{major}.@var{minor}@var{alpha}}, where @var{alpha} is a
10126 letter; it should be omitted for non-alpha releases.
10127
10128 @item @option{std-options}
10129 @cindex Options, @option{std-options}
10130 @cindex @samp{make installcheck}, testing @option{--help} and @option{--version}
10131 @cindex @option{--help} check
10132 @cindex @option{--version} check
10133 @opindex std-options
10134
10135 Make the @code{installcheck} rule check that installed scripts and
10136 programs support the @option{--help} and @option{--version} options.
10137 This also provides a basic check that the program's
10138 run-time dependencies are satisfied after installation.
10139
10140 @vindex AM_INSTALLCHECK_STD_OPTIONS_EXEMPT
10141 In a few situations, programs (or scripts) have to be exempted from this
10142 test.  For instance, @command{false} (from GNU coreutils) is never
10143 successful, even for @option{--help} or @option{--version}.  You can list
10144 such programs in the variable @code{AM_INSTALLCHECK_STD_OPTIONS_EXEMPT}.
10145 Programs (not scripts) listed in this variable should be suffixed by
10146 @samp{$(EXEEXT)} for the sake of Windows or OS/2.  For instance, suppose we
10147 build @file{false} as a program but @file{true.sh} as a script, and that
10148 neither of them support @option{--help} or @option{--version}:
10149
10150 @example
10151 AUTOMAKE_OPTIONS = std-options
10152 bin_PROGRAMS = false ...
10153 bin_SCRIPTS = true.sh ...
10154 AM_INSTALLCHECK_STD_OPTIONS_EXEMPT = false$(EXEEXT) true.sh
10155 @end example
10156
10157 @item @option{subdir-objects}
10158 @cindex Options, @option{subdir-objects}
10159 @opindex subdir-objects
10160 If this option is specified, then objects are placed into the
10161 subdirectory of the build directory corresponding to the subdirectory of
10162 the source file.  For instance, if the source file is
10163 @file{subdir/file.cxx}, then the output file would be
10164 @file{subdir/file.o}.
10165
10166 In order to use this option with C sources, you should add
10167 @code{AM_PROG_CC_C_O} to @file{configure.ac}.
10168
10169 @anchor{tar-formats}
10170 @item @option{tar-v7}
10171 @itemx @option{tar-ustar}
10172 @itemx @option{tar-pax}
10173 @cindex Option, @option{tar-v7}
10174 @cindex Option, @option{tar-ustar}
10175 @cindex Option, @option{tar-pax}
10176 @cindex @command{tar} formats
10177 @cindex v7 @command{tar} format
10178 @cindex ustar format
10179 @cindex pax format
10180 @opindex tar-v7
10181 @opindex tar-ustar
10182 @opindex tar-pax
10183
10184 These three mutually exclusive options select the tar format to use
10185 when generating tarballs with @samp{make dist}.  (The tar file created
10186 is then compressed according to the set of @option{no-dist-gzip},
10187 @option{dist-bzip2}, @option{dist-lzip}, @option{dist-xz} and
10188 @option{dist-tarZ} options in use.)
10189
10190 These options must be passed as arguments to @code{AM_INIT_AUTOMAKE}
10191 (@pxref{Macros}) because they can require additional configure checks.
10192 Automake will complain if it sees such options in an
10193 @code{AUTOMAKE_OPTIONS} variable.
10194
10195 @option{tar-v7} selects the old V7 tar format.  This is the historical
10196 default.  This antiquated format is understood by all tar
10197 implementations and supports file names with up to 99 characters.  When
10198 given longer file names some tar implementations will diagnose the
10199 problem while other will generate broken tarballs or use non-portable
10200 extensions.  Furthermore, the V7 format cannot store empty
10201 directories.  When using this format, consider using the
10202 @option{filename-length-max=99} option to catch file names too long.
10203
10204 @option{tar-ustar} selects the ustar format defined by POSIX
10205 1003.1-1988.  This format is believed to be old enough to be portable.
10206 It fully supports empty directories.  It can store file names with up
10207 to 256 characters, provided that the file name can be split at
10208 directory separator in two parts, first of them being at most 155
10209 bytes long.  So, in most cases the maximum file name length will be
10210 shorter than 256 characters.  However you may run against broken tar
10211 implementations that incorrectly handle file names longer than 99
10212 characters (please report them to @email{@value{PACKAGE_BUGREPORT}} so we
10213 can document this accurately).
10214
10215 @option{tar-pax} selects the new pax interchange format defined by POSIX
10216 1003.1-2001.  It does not limit the length of file names.  However,
10217 this format is very young and should probably be restricted to
10218 packages that target only very modern platforms.  There are moves to
10219 change the pax format in an upward-compatible way, so this option may
10220 refer to a more recent version in the future.
10221
10222 @xref{Formats, , Controlling the Archive Format, tar, GNU Tar}, for
10223 further discussion about tar formats.
10224
10225 @command{configure} knows several ways to construct these formats.  It
10226 will not abort if it cannot find a tool up to the task (so that the
10227 package can still be built), but @samp{make dist} will fail.
10228
10229 @item @var{version}
10230 @cindex Option, @var{version}
10231 A version number (e.g., @samp{0.30}) can be specified.  If Automake is not
10232 newer than the version specified, creation of the @file{Makefile.in}
10233 will be suppressed.
10234
10235 @item @option{-W@var{category}} or @option{--warnings=@var{category}}
10236 @cindex Option, warnings
10237 @cindex Option, @option{-W@var{category}}
10238 @cindex Option, @option{--warnings=@var{category}}
10239 These options behave exactly like their command-line counterpart
10240 (@pxref{automake Invocation}).  This allows you to enable or disable some
10241 warning categories on a per-file basis.  You can also setup some warnings
10242 for your entire project; for instance, try @samp{AM_INIT_AUTOMAKE([-Wall])}
10243 in your @file{configure.ac}.
10244
10245 @end table
10246
10247 Unrecognized options are diagnosed by @command{automake}.
10248
10249 If you want an option to apply to all the files in the tree, you can use
10250 the @code{AM_INIT_AUTOMAKE} macro in @file{configure.ac}.
10251 @xref{Macros}.
10252
10253
10254 @node Miscellaneous
10255 @chapter Miscellaneous Rules
10256
10257 There are a few rules and variables that didn't fit anywhere else.
10258
10259 @menu
10260 * Tags::                        Interfacing to cscope, etags and mkid
10261 * Suffixes::                    Handling new file extensions
10262 @end menu
10263
10264
10265 @node Tags
10266 @section Interfacing to @command{etags}
10267
10268 @cindex @file{TAGS} support
10269
10270 Automake will generate rules to generate @file{TAGS} files for use with
10271 GNU Emacs under some circumstances.
10272
10273 @trindex tags
10274 If any C, C++ or Fortran 77 source code or headers are present, then
10275 @code{tags} and @code{TAGS} rules will be generated for the directory.
10276 All files listed using the @code{_SOURCES}, @code{_HEADERS}, and
10277 @code{_LISP} primaries will be used to generate tags.  Note that
10278 generated source files that are not distributed must be declared in
10279 variables like @code{nodist_noinst_HEADERS} or
10280 @code{nodist_@var{prog}_SOURCES} or they will be ignored.
10281
10282 A @code{tags} rule will be output at the topmost directory of a
10283 multi-directory package.  When run from this topmost directory,
10284 @samp{make tags} will generate a @file{TAGS} file that includes by
10285 reference all @file{TAGS} files from subdirectories.
10286
10287 The @code{tags} rule will also be generated if the variable
10288 @code{ETAGS_ARGS} is defined.  This variable is intended for use in
10289 directories that contain taggable source that @command{etags} does
10290 not understand.  The user can use the @code{ETAGSFLAGS} to pass
10291 additional flags to @command{etags}; @code{AM_ETAGSFLAGS} is also
10292 available for use in @file{Makefile.am}.
10293 @vindex ETAGS_ARGS
10294 @vindex ETAGSFLAGS
10295 @vindex AM_ETAGSFLAGS
10296
10297 Here is how Automake generates tags for its source, and for nodes in its
10298 Texinfo file:
10299
10300 @example
10301 ETAGS_ARGS = automake.in --lang=none \
10302  --regex='/^@@node[ \t]+\([^,]+\)/\1/' automake.texi
10303 @end example
10304
10305 If you add file names to @code{ETAGS_ARGS}, you will probably also
10306 want to define @code{TAGS_DEPENDENCIES}.  The contents of this variable
10307 are added directly to the dependencies for the @code{tags} rule.
10308 @vindex TAGS_DEPENDENCIES
10309
10310 Automake also generates a @code{ctags} rule that can be used to
10311 build @command{vi}-style @file{tags} files.  The variable @code{CTAGS}
10312 is the name of the program to invoke (by default @command{ctags});
10313 @code{CTAGSFLAGS} can be used by the user to pass additional flags,
10314 and @code{AM_CTAGSFLAGS} can be used by the @file{Makefile.am}.
10315
10316 @trindex id
10317 Automake will also generate an @code{ID} rule that will run
10318 @command{mkid} on the source.  This is only supported on a
10319 directory-by-directory basis.
10320
10321 Similarly, the @code{cscope} rule will create a list of all the source
10322 files in the tree and run @command{cscope} to build an inverted index
10323 database.  The variable @code{CSCOPE} is the name of the program to invoke
10324 (by default @command{cscope}); @code{CSCOPEFLAGS} and
10325 @code{CSCOPE_ARGS} can be used by the user to pass additional flags and
10326 file names respectively, while @code{AM_CSCOPEFLAGS} can be used by the
10327 @file{Makefile.am}.  Note that, currently, the Automake-provided
10328 @code{cscope} support, when used in a VPATH build, might not work well
10329 with non-GNU make implementations (especially with make implementations
10330 performing @ref{Automatic Rule Rewriting, , VPATH rewrites, autoconf,
10331 The Autoconf Manual}).
10332
10333 Finally, Automake also emits rules to support the
10334 @uref{http://www.gnu.org/software/global/, GNU Global Tags program}.
10335 The @code{GTAGS} rule runs Global Tags and puts the
10336 result in the top build directory.  The variable @code{GTAGS_ARGS}
10337 holds arguments that are passed to @command{gtags}.
10338 @vindex GTAGS_ARGS
10339
10340
10341 @node Suffixes
10342 @section Handling new file extensions
10343
10344 @cindex Adding new @code{SUFFIXES}
10345 @cindex @code{SUFFIXES}, adding
10346 @vindex SUFFIXES
10347
10348 It is sometimes useful to introduce a new implicit rule to handle a file
10349 type that Automake does not know about.
10350
10351 For instance, suppose you had a compiler that could compile @file{.foo}
10352 files to @file{.o} files.  You would simply define a suffix rule for
10353 your language:
10354
10355 @example
10356 .foo.o:
10357         foocc -c -o $@@ $<
10358 @end example
10359
10360 Then you could directly use a @file{.foo} file in a @code{_SOURCES}
10361 variable and expect the correct results:
10362
10363 @example
10364 bin_PROGRAMS = doit
10365 doit_SOURCES = doit.foo
10366 @end example
10367
10368 This was the simpler and more common case.  In other cases, you will
10369 have to help Automake to figure out which extensions you are defining your
10370 suffix rule for.  This usually happens when your extension does not
10371 start with a dot.  Then, all you have to do is to put a list of new
10372 suffixes in the @code{SUFFIXES} variable @strong{before} you define your
10373 implicit rule.
10374
10375 For instance, the following definition prevents Automake from misinterpreting
10376 the @samp{.idlC.cpp:} rule as an attempt to transform @file{.idlC} files into
10377 @file{.cpp} files.
10378
10379 @c Keep in sync with suffix7.sh
10380 @example
10381 SUFFIXES = .idl C.cpp
10382 .idlC.cpp:
10383         # whatever
10384 @end example
10385
10386 As you may have noted, the @code{SUFFIXES} variable behaves like the
10387 @code{.SUFFIXES} special target of @command{make}.  You should not touch
10388 @code{.SUFFIXES} yourself, but use @code{SUFFIXES} instead and let
10389 Automake generate the suffix list for @code{.SUFFIXES}.  Any given
10390 @code{SUFFIXES} go at the start of the generated suffixes list, followed
10391 by Automake generated suffixes not already in the list.
10392
10393 @node Include
10394 @chapter Include
10395
10396 @cmindex include
10397 @cindex Including @file{Makefile} fragment
10398 @cindex @file{Makefile} fragment, including
10399
10400 Automake supports an @code{include} directive that  can be used to
10401 include other @file{Makefile} fragments when @command{automake} is run.
10402 Note that these fragments are read and interpreted by @command{automake},
10403 not by @command{make}.  As with conditionals, @command{make} has no idea that
10404 @code{include} is in use.
10405
10406 There are two forms of @code{include}:
10407
10408 @table @code
10409 @item include $(srcdir)/file
10410 Include a fragment that is found relative to the current source
10411 directory.
10412
10413 @item include $(top_srcdir)/file
10414 Include a fragment that is found relative to the top source directory.
10415 @end table
10416
10417 Note that if a fragment is included inside a conditional, then the
10418 condition applies to the entire contents of that fragment.
10419
10420 Makefile fragments included this way are always distributed because
10421 they are needed to rebuild @file{Makefile.in}.
10422
10423 @node Conditionals
10424 @chapter Conditionals
10425
10426 @cindex Conditionals
10427
10428 Automake supports a simple type of conditionals.
10429
10430 These conditionals are not the same as conditionals in
10431 GNU Make.  Automake conditionals are checked at configure time by the
10432 @file{configure} script, and affect the translation from
10433 @file{Makefile.in} to @file{Makefile}.  They are based on options passed
10434 to @file{configure} and on results that @file{configure} has discovered
10435 about the host system.  GNU Make conditionals are checked at @command{make}
10436 time, and are based on variables passed to the make program or defined
10437 in the @file{Makefile}.
10438
10439 Automake conditionals will work with any make program.
10440
10441 @menu
10442 * Usage of Conditionals::       Declaring conditional content
10443 * Limits of Conditionals::      Enclosing complete statements
10444 @end menu
10445
10446 @node Usage of Conditionals
10447 @section Usage of Conditionals
10448
10449 @acindex AM_CONDITIONAL
10450 Before using a conditional, you must define it by using
10451 @code{AM_CONDITIONAL} in the @file{configure.ac} file (@pxref{Macros}).
10452
10453 @defmac AM_CONDITIONAL (@var{conditional}, @var{condition})
10454 The conditional name, @var{conditional}, should be a simple string
10455 starting with a letter and containing only letters, digits, and
10456 underscores.  It must be different from @samp{TRUE} and @samp{FALSE}
10457 that are reserved by Automake.
10458
10459 The shell @var{condition} (suitable for use in a shell @code{if}
10460 statement) is evaluated when @command{configure} is run.  Note that you
10461 must arrange for @emph{every} @code{AM_CONDITIONAL} to be invoked every
10462 time @command{configure} is run.  If @code{AM_CONDITIONAL} is run
10463 conditionally (e.g., in a shell @code{if} statement), then the result
10464 will confuse @command{automake}.
10465 @end defmac
10466
10467 @cindex @option{--enable-debug}, example
10468 @cindex Example conditional @option{--enable-debug}
10469 @cindex Conditional example, @option{--enable-debug}
10470
10471 Conditionals typically depend upon options that the user provides to
10472 the @command{configure} script.  Here is an example of how to write a
10473 conditional that is true if the user uses the @option{--enable-debug}
10474 option.
10475
10476 @example
10477 AC_ARG_ENABLE([debug],
10478 [  --enable-debug    Turn on debugging],
10479 [case "$@{enableval@}" in
10480   yes) debug=true ;;
10481   no)  debug=false ;;
10482   *) AC_MSG_ERROR([bad value $@{enableval@} for --enable-debug]) ;;
10483 esac],[debug=false])
10484 AM_CONDITIONAL([DEBUG], [test x$debug = xtrue])
10485 @end example
10486
10487 Here is an example of how to use that conditional in @file{Makefile.am}:
10488
10489 @cmindex if
10490 @cmindex endif
10491 @cmindex else
10492
10493 @example
10494 if DEBUG
10495 DBG = debug
10496 else
10497 DBG =
10498 endif
10499 noinst_PROGRAMS = $(DBG)
10500 @end example
10501
10502 This trivial example could also be handled using @code{EXTRA_PROGRAMS}
10503 (@pxref{Conditional Programs}).
10504
10505 You may only test a single variable in an @code{if} statement, possibly
10506 negated using @samp{!}.  The @code{else} statement may be omitted.
10507 Conditionals may be nested to any depth.  You may specify an argument to
10508 @code{else} in which case it must be the negation of the condition used
10509 for the current @code{if}.  Similarly you may specify the condition
10510 that is closed on the @code{endif} line:
10511
10512 @example
10513 if DEBUG
10514 DBG = debug
10515 else !DEBUG
10516 DBG =
10517 endif !DEBUG
10518 @end example
10519
10520 @noindent
10521 Unbalanced conditions are errors.  The @code{if}, @code{else}, and
10522 @code{endif} statements should not be indented, i.e., start on column
10523 one.
10524
10525 The @code{else} branch of the above two examples could be omitted,
10526 since assigning the empty string to an otherwise undefined variable
10527 makes no difference.
10528
10529 @acindex AM_COND_IF
10530 In order to allow access to the condition registered by
10531 @code{AM_CONDITIONAL} inside @file{configure.ac}, and to allow
10532 conditional @code{AC_CONFIG_FILES}, @code{AM_COND_IF} may be used:
10533
10534 @defmac AM_COND_IF (@var{conditional}, @ovar{if-true}, @ovar{if-false})
10535 If @var{conditional} is fulfilled, execute @var{if-true}, otherwise
10536 execute @var{if-false}.  If either branch contains @code{AC_CONFIG_FILES},
10537 it will cause @command{automake} to output the rules for the respective
10538 files only for the given condition.
10539 @end defmac
10540
10541 @code{AM_COND_IF} macros may be nested when m4 quotation is used
10542 properly (@pxref{M4 Quotation, ,, autoconf, The Autoconf Manual}).
10543
10544 @cindex Example conditional @code{AC_CONFIG_FILES}
10545 @cindex @code{AC_CONFIG_FILES}, conditional
10546
10547 Here is an example of how to define a conditional config file:
10548
10549 @example
10550 AM_CONDITIONAL([SHELL_WRAPPER], [test "x$with_wrapper" = xtrue])
10551 AM_COND_IF([SHELL_WRAPPER],
10552            [AC_CONFIG_FILES([wrapper:wrapper.in])])
10553 @end example
10554
10555 @node Limits of Conditionals
10556 @section Limits of Conditionals
10557
10558 Conditionals should enclose complete statements like variables or
10559 rules definitions.  Automake cannot deal with conditionals used inside
10560 a variable definition, for instance, and is not even able to diagnose
10561 this situation.  The following example would not work:
10562
10563 @example
10564 # This syntax is not understood by Automake
10565 AM_CPPFLAGS = \
10566   -DFEATURE_A \
10567 if WANT_DEBUG
10568   -DDEBUG \
10569 endif
10570   -DFEATURE_B
10571 @end example
10572
10573 However the intended definition of @code{AM_CPPFLAGS} can be achieved
10574 with
10575
10576 @example
10577 if WANT_DEBUG
10578   DEBUGFLAGS = -DDEBUG
10579 endif
10580 AM_CPPFLAGS = -DFEATURE_A $(DEBUGFLAGS) -DFEATURE_B
10581 @end example
10582
10583 @noindent
10584 or
10585
10586 @example
10587 AM_CPPFLAGS = -DFEATURE_A
10588 if WANT_DEBUG
10589 AM_CPPFLAGS += -DDEBUG
10590 endif
10591 AM_CPPFLAGS += -DFEATURE_B
10592 @end example
10593
10594 More details and examples of conditionals are described alongside
10595 various Automake features in this manual (@pxref{Conditional
10596 Subdirectories}, @pxref{Conditional Sources}, @pxref{Conditional
10597 Programs}, @pxref{Conditional Libtool Libraries}, @pxref{Conditional
10598 Libtool Sources}).
10599
10600 @node Silencing Make
10601 @chapter Silencing @command{make}
10602
10603 @cindex Silent @command{make}
10604 @cindex Silencing @command{make}
10605 @cindex Silent rules
10606 @cindex Silent @command{make} rules
10607
10608 @menu
10609 * Make verbosity::              Make is verbose by default
10610 * Tricks For Silencing Make::   Standard and generic ways to silence make
10611 * Automake Silent Rules::       How Automake can help in silencing make
10612 @end menu
10613
10614 @node Make verbosity
10615 @section Make is verbose by default
10616
10617 Normally, when executing the set of rules associated with a target,
10618 @command{make} prints each rule before it is executed.  This behaviour,
10619 while having been in place for a long time, and being even mandated by
10620 the POSIX standard, starkly violates the ``silence is golden'' UNIX
10621 principle@footnote{See also
10622 @uref{http://catb.org/~esr/writings/taoup/html/ch11s09.html}.}:
10623
10624 @quotation
10625 When a program has nothing interesting or surprising to say, it should
10626 say nothing.  Well-behaved Unix programs do their jobs unobtrusively,
10627 with a minimum of fuss and bother.  Silence is golden.
10628 @end quotation
10629
10630 In fact, while such verbosity of @command{make} can theoretically be
10631 useful to track bugs and understand reasons of failures right away, it
10632 can also hide warning and error messages from @command{make}-invoked
10633 tools, drowning them in a flood of uninteresting and seldom useful
10634 messages, and thus allowing them to go easily undetected.
10635
10636 This problem can be very annoying, especially for developers, who usually
10637 know quite well what's going on behind the scenes, and for whom the
10638 verbose output from @command{make} ends up being mostly noise that hampers
10639 the easy detection of potentially important warning messages.
10640
10641 @node Tricks For Silencing Make
10642 @section Standard and generic ways to silence make
10643
10644 Here we describe some common idioms/tricks to obtain a quieter make
10645 output, with their relative advantages and drawbacks.  In the next
10646 section (@ref{Automake Silent Rules}) we'll see how Automake can help
10647 in this respect, providing more elaborate and flexible idioms.
10648
10649 @itemize @bullet
10650
10651 @item @command{make -s}
10652
10653 This simply causes @command{make} not to print @emph{any} rule before
10654 executing it.
10655
10656 The @option{-s} flag is mandated by POSIX, universally supported, and
10657 its purpose and function are easy to understand.
10658
10659 But it also has its serious limitations too.  First of all, it embodies
10660 an ``all or nothing'' strategy, i.e., either everything is silenced, or
10661 nothing is; this lack of granularity can sometimes be a fatal flaw.
10662 Moreover, when the @option{-s} flag is used, the @command{make} output
10663 might turn out to be too much terse; in case of errors, the user won't
10664 be able to easily see what rule or command have caused them, or even,
10665 in case of tools with poor error reporting, what the errors were!
10666
10667 @item @command{make >/dev/null || make}
10668
10669 Apparently, this perfectly obeys the ``silence is golden'' rule: warnings
10670 from stderr are passed through, output reporting is done only in case of
10671 error, and in that case it should provide a verbose-enough report to allow
10672 an easy determination of the error location and causes.
10673
10674 However, calling @command{make} two times in a row might hide errors
10675 (especially intermittent ones), or subtly change the expected semantic
10676 of the @command{make} calls --- things these which can clearly make
10677 debugging and error assessment very difficult.
10678
10679 @item @command{make --no-print-directory}
10680
10681 This is GNU @command{make} specific.  When called with the
10682 @option{--no-print-directory} option, GNU @command{make} will disable
10683 printing of the working directory by invoked sub-@command{make}s (the
10684 well-known ``@i{Entering/Leaving directory ...}'' messages).  This helps
10685 to decrease the verbosity of the output, but experience has shown that
10686 it can also often render debugging considerably harder in projects using
10687 deeply-nested @command{make} recursion.
10688
10689 As an aside, notice that the @option{--no-print-directory} option is
10690 automatically activated if the @option{-s} flag is used.
10691
10692 @c TODO: Other tricks?
10693 @c TODO: Maybe speak about the @code{.SILENT} target?
10694 @c TODO:  - Pros: More granularity on what to silence.
10695 @c TODO:  - Cons: No easy way to temporarily override.
10696
10697 @end itemize
10698
10699 @node Automake Silent Rules
10700 @section How Automake can help in silencing make
10701
10702 The tricks and idioms for silencing @command{make} described in the
10703 previous section can be useful from time to time, but we've seen that
10704 they all have their serious drawbacks and limitations.  That's why
10705 automake provides support for a more advanced and flexible way of
10706 obtaining quieter output from @command{make} (for most rules at least).
10707
10708 @c TODO: Maybe describe in brief the precedent set by the build system
10709 @c of the Linux Kernel, from which Automake took inspiration ... Links?
10710
10711 To give the gist of what Automake can do in this respect, here is a simple
10712 comparison between a typical @command{make} output (where silent rules
10713 are disabled) and one with silent rules enabled:
10714
10715 @example
10716 % @kbd{cat Makefile.am}
10717 bin_PROGRAMS = foo
10718 foo_SOURCES = main.c func.c
10719 % @kbd{cat main.c}
10720 int main (void) @{ return func (); @}  /* func used undeclared */
10721 % @kbd{cat func.c}
10722 int func (void) @{ int i; return i; @} /* i used uninitialized */
10723
10724 @i{The make output is by default very verbose.  This causes warnings
10725 from the compiler to be somewhat hidden, and not immediate to spot.}
10726 % @kbd{make CFLAGS=-Wall}
10727 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10728 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10729 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT main.o
10730 -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
10731 main.c: In function â€˜main’:
10732 main.c:3:3: warning: implicit declaration of function â€˜func’
10733 mv -f .deps/main.Tpo .deps/main.Po
10734 gcc -DPACKAGE_NAME=\"foo\" -DPACKAGE_TARNAME=\"foo\" ...
10735 -DPACKAGE_STRING=\"foo\ 1.0\" -DPACKAGE_BUGREPORT=\"\" ...
10736 -DPACKAGE=\"foo\" -DVERSION=\"1.0\" -I. -Wall -MT func.o
10737 -MD -MP -MF .deps/func.Tpo -c -o func.o func.c
10738 func.c: In function â€˜func’:
10739 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10740 mv -f .deps/func.Tpo .deps/func.Po
10741 gcc -Wall -o foo main.o func.o
10742
10743 @i{Clean up, so that we we can rebuild everything from scratch.}
10744 % @kbd{make clean}
10745 test -z "foo" || rm -f foo
10746 rm -f *.o
10747
10748 @i{Silent rules enabled: the output is minimal but informative.  In
10749 particular, the warnings from the compiler stick out very clearly.}
10750 % @kbd{make V=0 CFLAGS=-Wall}
10751   CC     main.o
10752 main.c: In function â€˜main’:
10753 main.c:3:3: warning: implicit declaration of function â€˜func’
10754   CC     func.o
10755 func.c: In function â€˜func’:
10756 func.c:4:3: warning: â€˜i’ used uninitialized in this function
10757   CCLD   foo
10758 @end example
10759
10760 @cindex silent rules and libtool
10761 Also, in projects using @command{libtool}, the use of silent rules can
10762 automatically enable the @command{libtool}'s @option{--silent} option:
10763
10764 @example
10765 % @kbd{cat Makefile.am}
10766 lib_LTLIBRARIES = libx.la
10767
10768 % @kbd{make # Both make and libtool are verbose by default.}
10769 ...
10770 libtool: compile: gcc -DPACKAGE_NAME=\"foo\" ... -DLT_OBJDIR=\".libs/\"
10771   -I. -g -O2 -MT libx.lo -MD -MP -MF .deps/libx.Tpo -c libx.c -fPIC
10772   -DPIC -o .libs/libx.o
10773 mv -f .deps/libx.Tpo .deps/libx.Plo
10774 /bin/sh ./libtool --tag=CC --mode=link gcc -g -O2 -o libx.la -rpath
10775   /usr/local/lib libx.lo
10776 libtool: link: gcc -shared .libs/libx.o -Wl,-soname -Wl,libx.so.0
10777   -o .libs/libx.so.0.0.0
10778 libtool: link: cd .libs && rm -f libx.so && ln -s libx.so.0.0.0 libx.so
10779 ...
10780
10781 % @kbd{make V=0}
10782   CC     libx.lo
10783   CCLD   libx.la
10784 @end example
10785
10786 For Automake-generated @file{Makefile}s, the user may influence the
10787 verbosity at @command{configure} run time as well as at @command{make}
10788 run time:
10789
10790 @itemize @bullet
10791 @item
10792 @opindex --enable-silent-rules
10793 @opindex --disable-silent-rules
10794 Passing @option{--enable-silent-rules} to @command{configure} will cause
10795 build rules to be less verbose; the option @option{--disable-silent-rules}
10796 will cause normal verbose output.
10797 @item
10798 @vindex @code{V}
10799 At @command{make} run time, the default chosen at @command{configure}
10800 time may be overridden: @code{make V=1} will produce verbose output,
10801 @code{make V=0} less verbose output.
10802 @end itemize
10803
10804 @cindex default verbosity for silent rules
10805 Note that silent rules are @emph{disabled} by default; the user must
10806 enable them explicitly at either @command{configure} run time or at
10807 @command{make} run time.  We think that this is a good policy, since
10808 it provides the casual user with enough information to prepare a good
10809 bug report in case anything breaks.
10810
10811 Still, notwithstanding the rationales above, a developer who really
10812 wants to make silent rules enabled by default in his own package can
10813 do so by calling @code{AM_SILENT_RULES([yes])} in @file{configure.ac}.
10814
10815 @c Keep in sync with silent-configsite.sh
10816 Users who prefer to have silent rules enabled by default can edit their
10817 @file{config.site} file to make the variable @code{enable_silent_rules}
10818 default to @samp{yes}.  This should still allow disabling silent rules
10819 at @command{configure} time and at @command{make} time.
10820
10821 @c FIXME: there's really a need to specify this explicitly?
10822 For portability to different @command{make} implementations, package authors
10823 are advised to not set the variable @code{V} inside the @file{Makefile.am}
10824 file, to allow the user to override the value for subdirectories as well.
10825
10826 To work at its best, the current implementation of this feature normally
10827 uses nested variable expansion @samp{$(@var{var1}$(V))}, a @file{Makefile}
10828 feature that is not required by POSIX 2008 but is widely supported in
10829 practice.  On the rare @command{make} implementations that do not support
10830 nested variable expansion, whether rules are silent is always determined at
10831 configure time, and cannot be overridden at make time.  Future versions of
10832 POSIX are likely to require nested variable expansion, so this minor
10833 limitation should go away with time.
10834
10835 @vindex @code{AM_V_GEN}
10836 @vindex @code{AM_V_at}
10837 @vindex @code{AM_DEFAULT_VERBOSITY}
10838 @vindex @code{AM_V}
10839 @vindex @code{AM_DEFAULT_V}
10840 To extend the silent mode to your own rules, you have few choices:
10841
10842 @itemize @bullet
10843
10844 @item
10845 You can use the predefined variable @code{AM_V_GEN} as a prefix to
10846 commands that should output a status line in silent mode, and
10847 @code{AM_V_at} as a prefix to commands that should not output anything
10848 in silent mode.  When output is to be verbose, both of these variables
10849 will expand to the empty string.
10850
10851 @item
10852 You can silence a recipe unconditionally with @code{@@}, and then use
10853 the predefined variable @code{AM_V_P} to know whether make is being run
10854 in silent or verbose mode, adjust the verbose information your recipe
10855 displays accordingly:
10856
10857 @example
10858 generate-headers:
10859         @set -e; \
10860         ... [commands defining a shell variable '$headers'] ...; \
10861         if $(AM_V_P); then set -x; else echo " GEN   [headers]"; fi; \
10862         rm -f $$headers && generate-header --flags $$headers
10863 @end example
10864
10865 @item
10866 You can add your own variables, so strings of your own choice are shown.
10867 The following snippet shows how you would define your own equivalent of
10868 @code{AM_V_GEN}:
10869
10870 @example
10871 pkg_verbose = $(pkg_verbose_@@AM_V@@)
10872 pkg_verbose_ = $(pkg_verbose_@@AM_DEFAULT_V@@)
10873 pkg_verbose_0 = @@echo PKG-GEN $@@;
10874
10875 foo: foo.in
10876         $(pkg_verbose)cp $(srcdir)/foo.in $@@
10877 @end example
10878
10879 @end itemize
10880
10881 As a final note, observe that, even when silent rules are enabled,
10882 the @option{--no-print-directory} option is still required with GNU
10883 @command{make} if the ``@i{Entering/Leaving directory ...}'' messages
10884 are to be disabled.
10885
10886 @node Gnits
10887 @chapter The effect of @option{--gnu} and @option{--gnits}
10888
10889 @cindex @option{--gnu}, required files
10890 @cindex @option{--gnu}, complete description
10891
10892 The @option{--gnu} option (or @option{gnu} in the
10893 @code{AUTOMAKE_OPTIONS} variable) causes @command{automake} to check
10894 the following:
10895
10896 @itemize @bullet
10897 @item
10898 The files @file{INSTALL}, @file{NEWS}, @file{README}, @file{AUTHORS},
10899 and @file{ChangeLog}, plus one of @file{COPYING.LIB}, @file{COPYING.LESSER}
10900 or @file{COPYING}, are required at the topmost directory of the package.
10901
10902 If the @option{--add-missing} option is given, @command{automake} will
10903 add a generic version of the @file{INSTALL} file as well as the
10904 @file{COPYING} file containing the text of the current version of the
10905 GNU General Public License existing at the time of this Automake release
10906 (version 3 as this is written, @uref{http://www.gnu.org/@/copyleft/@/gpl.html}).
10907 However, an existing @file{COPYING} file will never be overwritten by
10908 @command{automake}.
10909
10910 @item
10911 The options @option{no-installman} and @option{no-installinfo} are
10912 prohibited.
10913 @end itemize
10914
10915 Note that this option will be extended in the future to do even more
10916 checking; it is advisable to be familiar with the precise requirements
10917 of the GNU standards.  Also, @option{--gnu} can require certain
10918 non-standard GNU programs to exist for use by various maintainer-only
10919 rules; for instance, in the future @command{pathchk} might be required for
10920 @samp{make dist}.
10921
10922 @cindex @option{--gnits}, complete description
10923
10924 The @option{--gnits} option does everything that @option{--gnu} does, and
10925 checks the following as well:
10926
10927 @itemize @bullet
10928 @item
10929 @samp{make installcheck} will check to make sure that the @option{--help}
10930 and @option{--version} really print a usage message and a version string,
10931 respectively.  This is the @option{std-options} option (@pxref{Options}).
10932
10933 @item
10934 @samp{make dist} will check to make sure the @file{NEWS} file has been
10935 updated to the current version.
10936
10937 @item
10938 @code{VERSION} is checked to make sure its format complies with Gnits
10939 standards.
10940 @c FIXME xref when standards are finished
10941
10942 @item
10943 @cindex @file{README-alpha}
10944 If @code{VERSION} indicates that this is an alpha release, and the file
10945 @file{README-alpha} appears in the topmost directory of a package, then
10946 it is included in the distribution.  This is done in @option{--gnits}
10947 mode, and no other, because this mode is the only one where version
10948 number formats are constrained, and hence the only mode where Automake
10949 can automatically determine whether @file{README-alpha} should be
10950 included.
10951
10952 @item
10953 The file @file{THANKS} is required.
10954 @end itemize
10955
10956
10957 @node Not Enough
10958 @chapter When Automake Isn't Enough
10959
10960 In some situations, where Automake is not up to one task, one has to
10961 resort to handwritten rules or even handwritten @file{Makefile}s.
10962
10963 @menu
10964 * Extending::                   Adding new rules or overriding existing ones.
10965 * Third-Party Makefiles::       Integrating Non-Automake @file{Makefile}s.
10966 @end menu
10967
10968 @node Extending
10969 @section Extending Automake Rules
10970
10971 With some minor exceptions (for example @code{_PROGRAMS} variables,
10972 @code{TESTS}, or @code{XFAIL_TESTS}) being rewritten to append
10973 @samp{$(EXEEXT)}), the contents of a @file{Makefile.am} is copied to
10974 @file{Makefile.in} verbatim.
10975
10976 @cindex copying semantics
10977
10978 These copying semantics mean that many problems can be worked around
10979 by simply adding some @command{make} variables and rules to
10980 @file{Makefile.am}.  Automake will ignore these additions.
10981
10982 @cindex conflicting definitions
10983 @cindex rules, conflicting
10984 @cindex variables, conflicting
10985 @cindex definitions, conflicts
10986
10987 Since a @file{Makefile.in} is built from data gathered from three
10988 different places (@file{Makefile.am}, @file{configure.ac}, and
10989 @command{automake} itself), it is possible to have conflicting
10990 definitions of rules or variables.  When building @file{Makefile.in}
10991 the following priorities are respected by @command{automake} to ensure
10992 the user always has the last word:
10993
10994 @itemize
10995 @item
10996 User defined variables in @file{Makefile.am} have priority over
10997 variables @code{AC_SUBST}ed from @file{configure.ac}, and
10998 @code{AC_SUBST}ed variables have priority over
10999 @command{automake}-defined variables.
11000 @item
11001 As far as rules are concerned, a user-defined rule overrides any
11002 @command{automake}-defined rule for the same target.
11003 @end itemize
11004
11005 @cindex overriding rules
11006 @cindex overriding semantics
11007 @cindex rules, overriding
11008
11009 These overriding semantics make it possible to fine tune some default
11010 settings of Automake, or replace some of its rules.  Overriding
11011 Automake rules is often inadvisable, particularly in the topmost
11012 directory of a package with subdirectories.  The @option{-Woverride}
11013 option (@pxref{automake Invocation}) comes in handy to catch overridden
11014 definitions.
11015
11016 Note that Automake does not make any distinction between rules with
11017 commands and rules that only specify dependencies.  So it is not
11018 possible to append new dependencies to an @command{automake}-defined
11019 target without redefining the entire rule.
11020
11021 @cindex @option{-local} targets
11022 @cindex local targets
11023
11024 However, various useful targets have a @samp{-local} version you can
11025 specify in your @file{Makefile.am}.  Automake will supplement the
11026 standard target with these user-supplied targets.
11027
11028 @trindex  all
11029 @trindex  all-local
11030 @trindex  info
11031 @trindex  info-local
11032 @trindex  dvi
11033 @trindex  dvi-local
11034 @trindex  ps
11035 @trindex  ps-local
11036 @trindex  pdf
11037 @trindex  pdf-local
11038 @trindex  html
11039 @trindex  html-local
11040 @trindex  check
11041 @trindex  check-local
11042 @trindex  install
11043 @trindex  install-data
11044 @trindex  install-data-local
11045 @trindex  install-dvi
11046 @trindex  install-dvi-local
11047 @trindex  install-exec
11048 @trindex  install-exec-local
11049 @trindex  install-html
11050 @trindex  install-html-local
11051 @trindex  install-info
11052 @trindex  install-info-local
11053 @trindex  install-pdf
11054 @trindex  install-pdf-local
11055 @trindex  install-ps
11056 @trindex  install-ps-local
11057 @trindex  uninstall
11058 @trindex  uninstall-local
11059 @trindex  mostlyclean
11060 @trindex  mostlyclean-local
11061 @trindex  clean
11062 @trindex  clean-local
11063 @trindex  distclean
11064 @trindex  distclean-local
11065 @trindex  installdirs
11066 @trindex  installdirs-local
11067 @trindex  installcheck
11068 @trindex  installcheck-local
11069
11070 The targets that support a local version are @code{all}, @code{info},
11071 @code{dvi}, @code{ps}, @code{pdf}, @code{html}, @code{check},
11072 @code{install-data}, @code{install-dvi}, @code{install-exec},
11073 @code{install-html}, @code{install-info}, @code{install-pdf},
11074 @code{install-ps}, @code{uninstall}, @code{installdirs},
11075 @code{installcheck} and the various @code{clean} targets
11076 (@code{mostlyclean}, @code{clean}, @code{distclean}, and
11077 @code{maintainer-clean}).
11078
11079 Note that there are no @code{uninstall-exec-local} or
11080 @code{uninstall-data-local} targets; just use @code{uninstall-local}.
11081 It doesn't make sense to uninstall just data or just executables.
11082
11083 For instance, here is one way to erase a subdirectory during
11084 @samp{make clean} (@pxref{Clean}).
11085
11086 @example
11087 clean-local:
11088         -rm -rf testSubDir
11089 @end example
11090
11091 You may be tempted to use @code{install-data-local} to install a file
11092 to some hard-coded location, but you should avoid this
11093 (@pxref{Hard-Coded Install Paths}).
11094
11095 With the @code{-local} targets, there is no particular guarantee of
11096 execution order; typically, they are run early, but with parallel
11097 make, there is no way to be sure of that.
11098
11099 @cindex @option{-hook} targets
11100 @cindex hook targets
11101 @trindex install-data-hook
11102 @trindex install-exec-hook
11103 @trindex uninstall-hook
11104 @trindex dist-hook
11105
11106 In contrast, some rules also have a way to run another rule, called a
11107 @dfn{hook}; hooks are always executed after the main rule's work is done.
11108 The hook is named after the principal target, with @samp{-hook} appended.
11109 The targets allowing hooks are @code{install-data},
11110 @code{install-exec}, @code{uninstall}, @code{dist}, and
11111 @code{distcheck}.
11112
11113 For instance, here is how to create a hard link to an installed program:
11114
11115 @example
11116 install-exec-hook:
11117         ln $(DESTDIR)$(bindir)/program$(EXEEXT) \
11118            $(DESTDIR)$(bindir)/proglink$(EXEEXT)
11119 @end example
11120
11121 Although cheaper and more portable than symbolic links, hard links
11122 will not work everywhere (for instance, OS/2 does not have
11123 @command{ln}).  Ideally you should fall back to @samp{cp -p} when
11124 @command{ln} does not work.  An easy way, if symbolic links are
11125 acceptable to you, is to add @code{AC_PROG_LN_S} to
11126 @file{configure.ac} (@pxref{Particular Programs, , Particular Program
11127 Checks, autoconf, The Autoconf Manual}) and use @samp{$(LN_S)} in
11128 @file{Makefile.am}.
11129
11130 @cindex versioned binaries, installing
11131 @cindex installing versioned binaries
11132 @cindex @code{LN_S} example
11133 For instance, here is how you could install a versioned copy of a
11134 program using @samp{$(LN_S)}:
11135
11136 @c Keep in sync with insthook.sh
11137 @example
11138 install-exec-hook:
11139         cd $(DESTDIR)$(bindir) && \
11140           mv -f prog$(EXEEXT) prog-$(VERSION)$(EXEEXT) && \
11141           $(LN_S) prog-$(VERSION)$(EXEEXT) prog$(EXEEXT)
11142 @end example
11143
11144 Note that we rename the program so that a new version will erase the
11145 symbolic link, not the real binary.  Also we @command{cd} into the
11146 destination directory in order to create relative links.
11147
11148 When writing @code{install-exec-hook} or @code{install-data-hook},
11149 please bear in mind that the exec/data distinction is based on the
11150 installation directory, not on the primary used (@pxref{The Two Parts of
11151 Install}).
11152 @c Keep in sync with primary-prefix-couples-documented-valid.sh
11153 So a @code{foo_SCRIPTS} will be installed by
11154 @code{install-data}, and a @code{barexec_SCRIPTS} will be installed by
11155 @code{install-exec}.  You should define your hooks consequently.
11156
11157 @c FIXME should include discussion of variables you can use in these
11158 @c rules
11159
11160 @node Third-Party Makefiles
11161 @section Third-Party @file{Makefile}s
11162
11163 @cindex Third-party packages, interfacing with
11164 @cindex Interfacing with third-party packages
11165
11166 In most projects all @file{Makefile}s are generated by Automake.  In
11167 some cases, however, projects need to embed subdirectories with
11168 handwritten @file{Makefile}s.  For instance, one subdirectory could be
11169 a third-party project with its own build system, not using Automake.
11170
11171 It is possible to list arbitrary directories in @code{SUBDIRS} or
11172 @code{DIST_SUBDIRS} provided each of these directories has a
11173 @file{Makefile} that recognizes all the following recursive targets.
11174
11175 @cindex recursive targets and third-party @file{Makefile}s
11176 When a user runs one of these targets, that target is run recursively
11177 in all subdirectories.  This is why it is important that even
11178 third-party @file{Makefile}s support them.
11179
11180 @table @code
11181 @item all
11182 Compile the entire package.  This is the default target in
11183 Automake-generated @file{Makefile}s, but it does not need to be the
11184 default in third-party @file{Makefile}s.
11185
11186 @item distdir
11187 @trindex distdir
11188 @vindex distdir
11189 @vindex top_distdir
11190 Copy files to distribute into @samp{$(distdir)}, before a tarball is
11191 constructed.  Of course this target is not required if the
11192 @option{no-dist} option (@pxref{Options}) is used.
11193
11194 The variables @samp{$(top_distdir)} and @samp{$(distdir)}
11195 (@pxref{The dist Hook}) will be passed from the outer package to the subpackage
11196 when the @code{distdir} target is invoked.  These two variables have
11197 been adjusted for the directory that is being recursed into, so they
11198 are ready to use.
11199
11200 @item install
11201 @itemx install-data
11202 @itemx install-exec
11203 @itemx uninstall
11204 Install or uninstall files (@pxref{Install}).
11205
11206 @item install-dvi
11207 @itemx install-html
11208 @itemx install-info
11209 @itemx install-ps
11210 @itemx install-pdf
11211 Install only some specific documentation format (@pxref{Texinfo}).
11212
11213 @item installdirs
11214 Create install directories, but do not install any files.
11215
11216 @item check
11217 @itemx installcheck
11218 Check the package (@pxref{Tests}).
11219
11220 @item mostlyclean
11221 @itemx clean
11222 @itemx distclean
11223 @itemx maintainer-clean
11224 Cleaning rules (@pxref{Clean}).
11225
11226 @item dvi
11227 @itemx pdf
11228 @itemx ps
11229 @itemx info
11230 @itemx html
11231 Build the documentation in various formats (@pxref{Texinfo}).
11232
11233 @item tags
11234 @itemx ctags
11235 Build @file{TAGS} and @file{CTAGS} (@pxref{Tags}).
11236 @end table
11237
11238 If you have ever used Gettext in a project, this is a good example of
11239 how third-party @file{Makefile}s can be used with Automake.  The
11240 @file{Makefile}s @command{gettextize} puts in the @file{po/} and
11241 @file{intl/} directories are handwritten @file{Makefile}s that
11242 implement all of these targets.  That way they can be added to
11243 @code{SUBDIRS} in Automake packages.
11244
11245 Directories that are only listed in @code{DIST_SUBDIRS} but not in
11246 @code{SUBDIRS} need only the @code{distclean},
11247 @code{maintainer-clean}, and @code{distdir} rules (@pxref{Conditional
11248 Subdirectories}).
11249
11250 Usually, many of these rules are irrelevant to the third-party
11251 subproject, but they are required for the whole package to work.  It's
11252 OK to have a rule that does nothing, so if you are integrating a
11253 third-party project with no documentation or tag support, you could
11254 simply augment its @file{Makefile} as follows:
11255
11256 @example
11257 EMPTY_AUTOMAKE_TARGETS = dvi pdf ps info html tags ctags
11258 .PHONY: $(EMPTY_AUTOMAKE_TARGETS)
11259 $(EMPTY_AUTOMAKE_TARGETS):
11260 @end example
11261
11262 Another aspect of integrating third-party build systems is whether
11263 they support VPATH builds (@pxref{VPATH Builds}).  Obviously if the
11264 subpackage does not support VPATH builds the whole package will not
11265 support VPATH builds.  This in turns means that @samp{make distcheck}
11266 will not work, because it relies on VPATH builds.  Some people can
11267 live without this (actually, many Automake users have never heard of
11268 @samp{make distcheck}).  Other people may prefer to revamp the
11269 existing @file{Makefile}s to support VPATH@.  Doing so does not
11270 necessarily require Automake, only Autoconf is needed (@pxref{Build
11271 Directories, , Build Directories, autoconf, The Autoconf Manual}).
11272 The necessary substitutions: @samp{@@srcdir@@}, @samp{@@top_srcdir@@},
11273 and @samp{@@top_builddir@@} are defined by @file{configure} when it
11274 processes a @file{Makefile} (@pxref{Preset Output Variables, , Preset
11275 Output Variables, autoconf, The Autoconf Manual}), they are not
11276 computed by the Makefile like the aforementioned @samp{$(distdir)} and
11277 @samp{$(top_distdir)} variables.
11278
11279 It is sometimes inconvenient to modify a third-party @file{Makefile}
11280 to introduce the above required targets.  For instance, one may want to
11281 keep the third-party sources untouched to ease upgrades to new
11282 versions.
11283
11284 @cindex @file{GNUmakefile} including @file{Makefile}
11285 Here are two other ideas.  If GNU make is assumed, one possibility is
11286 to add to that subdirectory a @file{GNUmakefile} that defines the
11287 required targets and includes the third-party @file{Makefile}.  For
11288 this to work in VPATH builds, @file{GNUmakefile} must lie in the build
11289 directory; the easiest way to do this is to write a
11290 @file{GNUmakefile.in} instead, and have it processed with
11291 @code{AC_CONFIG_FILES} from the outer package.  For example if we
11292 assume @file{Makefile} defines all targets except the documentation
11293 targets, and that the @code{check} target is actually called
11294 @code{test}, we could write @file{GNUmakefile} (or
11295 @file{GNUmakefile.in}) like this:
11296
11297 @example
11298 # First, include the real Makefile
11299 include Makefile
11300 # Then, define the other targets needed by Automake Makefiles.
11301 .PHONY: dvi pdf ps info html check
11302 dvi pdf ps info html:
11303 check: test
11304 @end example
11305
11306 @cindex Proxy @file{Makefile} for third-party packages
11307 A similar idea that does not use @code{include} is to write a proxy
11308 @file{Makefile} that dispatches rules to the real @file{Makefile},
11309 either with @samp{$(MAKE) -f Makefile.real $(AM_MAKEFLAGS) target} (if
11310 it's OK to rename the original @file{Makefile}) or with @samp{cd
11311 subdir && $(MAKE) $(AM_MAKEFLAGS) target} (if it's OK to store the
11312 subdirectory project one directory deeper).  The good news is that
11313 this proxy @file{Makefile} can be generated with Automake.  All we
11314 need are @option{-local} targets (@pxref{Extending}) that perform the
11315 dispatch.  Of course the other Automake features are available, so you
11316 could decide to let Automake perform distribution or installation.
11317 Here is a possible @file{Makefile.am}:
11318
11319 @example
11320 all-local:
11321         cd subdir && $(MAKE) $(AM_MAKEFLAGS) all
11322 check-local:
11323         cd subdir && $(MAKE) $(AM_MAKEFLAGS) test
11324 clean-local:
11325         cd subdir && $(MAKE) $(AM_MAKEFLAGS) clean
11326
11327 # Assuming the package knows how to install itself
11328 install-data-local:
11329         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-data
11330 install-exec-local:
11331         cd subdir && $(MAKE) $(AM_MAKEFLAGS) install-exec
11332 uninstall-local:
11333         cd subdir && $(MAKE) $(AM_MAKEFLAGS) uninstall
11334
11335 # Distribute files from here.
11336 EXTRA_DIST = subdir/Makefile subdir/program.c ...
11337 @end example
11338
11339 Pushing this idea to the extreme, it is also possible to ignore the
11340 subproject build system and build everything from this proxy
11341 @file{Makefile.am}.  This might sound very sensible if you need VPATH
11342 builds but the subproject does not support them.
11343
11344 @node Distributing
11345 @chapter Distributing @file{Makefile.in}s
11346
11347 Automake places no restrictions on the distribution of the resulting
11348 @file{Makefile.in}s.  We still encourage software authors to
11349 distribute their work under terms like those of the GPL, but doing so
11350 is not required to use Automake.
11351
11352 Some of the files that can be automatically installed via the
11353 @option{--add-missing} switch do fall under the GPL@.  However, these also
11354 have a special exception allowing you to distribute them with your
11355 package, regardless of the licensing you choose.
11356
11357
11358 @node API Versioning
11359 @chapter Automake API Versioning
11360
11361 New Automake releases usually include bug fixes and new features.
11362 Unfortunately they may also introduce new bugs and incompatibilities.
11363 This makes four reasons why a package may require a particular Automake
11364 version.
11365
11366 Things get worse when maintaining a large tree of packages, each one
11367 requiring a different version of Automake.  In the past, this meant that
11368 any developer (and sometimes users) had to install several versions of
11369 Automake in different places, and switch @samp{$PATH} appropriately for
11370 each package.
11371
11372 Starting with version 1.6, Automake installs versioned binaries.  This
11373 means you can install several versions of Automake in the same
11374 @samp{$prefix}, and can select an arbitrary Automake version by running
11375 @command{automake-1.6} or @command{automake-1.7} without juggling with
11376 @samp{$PATH}.  Furthermore, @file{Makefile}'s generated by Automake 1.6
11377 will use @command{automake-1.6} explicitly in their rebuild rules.
11378
11379 The number @samp{1.6} in @command{automake-1.6} is Automake's API version,
11380 not Automake's version.  If a bug fix release is made, for instance
11381 Automake 1.6.1, the API version will remain 1.6.  This means that a
11382 package that works with Automake 1.6 should also work with 1.6.1; after
11383 all, this is what people expect from bug fix releases.
11384
11385 If your package relies on a feature or a bug fix introduced in
11386 a release, you can pass this version as an option to Automake to ensure
11387 older releases will not be used.  For instance, use this in your
11388 @file{configure.ac}:
11389
11390 @example
11391   AM_INIT_AUTOMAKE([1.6.1])    dnl Require Automake 1.6.1 or better.
11392 @end example
11393
11394 @noindent
11395 or, in a particular @file{Makefile.am}:
11396
11397 @example
11398   AUTOMAKE_OPTIONS = 1.6.1   # Require Automake 1.6.1 or better.
11399 @end example
11400
11401 @noindent
11402 Automake will print an error message if its version is
11403 older than the requested version.
11404
11405
11406 @heading What is in the API
11407
11408 Automake's programming interface is not easy to define.  Basically it
11409 should include at least all @strong{documented} variables and targets
11410 that a @file{Makefile.am} author can use, any behavior associated with
11411 them (e.g., the places where @samp{-hook}'s are run), the command line
11412 interface of @command{automake} and @command{aclocal}, @dots{}
11413
11414 @heading What is not in the API
11415
11416 Every undocumented variable, target, or command line option, is not part
11417 of the API@.  You should avoid using them, as they could change from one
11418 version to the other (even in bug fix releases, if this helps to fix a
11419 bug).
11420
11421 If it turns out you need to use such an undocumented feature, contact
11422 @email{automake@@gnu.org} and try to get it documented and exercised by
11423 the test-suite.
11424
11425 @node Upgrading
11426 @chapter Upgrading a Package to a Newer Automake Version
11427
11428 Automake maintains three kind of files in a package.
11429
11430 @itemize
11431 @item @file{aclocal.m4}
11432 @item @file{Makefile.in}s
11433 @item auxiliary tools like @file{install-sh} or @file{py-compile}
11434 @end itemize
11435
11436 @file{aclocal.m4} is generated by @command{aclocal} and contains some
11437 Automake-supplied M4 macros.  Auxiliary tools are installed by
11438 @samp{automake --add-missing} when needed.  @file{Makefile.in}s are
11439 built from @file{Makefile.am} by @command{automake}, and rely on the
11440 definitions of the M4 macros put in @file{aclocal.m4} as well as the
11441 behavior of the auxiliary tools installed.
11442
11443 Because all of these files are closely related, it is important to
11444 regenerate all of them when upgrading to a newer Automake release.
11445 The usual way to do that is
11446
11447 @example
11448 aclocal # with any option needed (such a -I m4)
11449 autoconf
11450 automake --add-missing --force-missing
11451 @end example
11452
11453 @noindent
11454 or more conveniently:
11455
11456 @example
11457 autoreconf -vfi
11458 @end example
11459
11460 The use of @option{--force-missing} ensures that auxiliary tools will be
11461 overridden by new versions (@pxref{automake Invocation}).
11462
11463 It is important to regenerate all of these files each time Automake is
11464 upgraded, even between bug fixes releases.  For instance, it is not
11465 unusual for a bug fix to involve changes to both the rules generated
11466 in @file{Makefile.in} and the supporting M4 macros copied to
11467 @file{aclocal.m4}.
11468
11469 Presently @command{automake} is able to diagnose situations where
11470 @file{aclocal.m4} has been generated with another version of
11471 @command{aclocal}.  However it never checks whether auxiliary scripts
11472 are up-to-date.  In other words, @command{automake} will tell you when
11473 @command{aclocal} needs to be rerun, but it will never diagnose a
11474 missing @option{--force-missing}.
11475
11476 Before upgrading to a new major release, it is a good idea to read the
11477 file @file{NEWS}.  This file lists all changes between releases: new
11478 features, obsolete constructs, known incompatibilities, and
11479 workarounds.
11480
11481 @node FAQ
11482 @chapter Frequently Asked Questions about Automake
11483
11484 This chapter covers some questions that often come up on the mailing
11485 lists.
11486
11487 @menu
11488 * CVS::                         CVS and generated files
11489 * maintainer-mode::             missing and AM_MAINTAINER_MODE
11490 * Wildcards::                   Why doesn't Automake support wildcards?
11491 * Limitations on File Names::   Limitations on source and installed file names
11492 * Errors with distclean::       Files left in build directory after distclean
11493 * Flag Variables Ordering::     CFLAGS vs.@: AM_CFLAGS vs.@: mumble_CFLAGS
11494 * Renamed Objects::             Why are object files sometimes renamed?
11495 * Per-Object Flags::            How to simulate per-object flags?
11496 * Multiple Outputs::            Writing rules for tools with many output files
11497 * Hard-Coded Install Paths::    Installing to hard-coded locations
11498 * Debugging Make Rules::        Strategies when things don't work as expected
11499 * Reporting Bugs::              Feedback on bugs and feature requests
11500 @end menu
11501
11502 @node CVS
11503 @section CVS and generated files
11504
11505 @subheading Background: distributed generated Files
11506 @cindex generated files, distributed
11507 @cindex rebuild rules
11508
11509 Packages made with Autoconf and Automake ship with some generated
11510 files like @file{configure} or @file{Makefile.in}.  These files were
11511 generated on the developer's machine and are distributed so that
11512 end-users do not have to install the maintainer tools required to
11513 rebuild them.  Other generated files like Lex scanners, Yacc parsers,
11514 or Info documentation, are usually distributed on similar grounds.
11515
11516 Automake output rules in @file{Makefile}s to rebuild these files.  For
11517 instance, @command{make} will run @command{autoconf} to rebuild
11518 @file{configure} whenever @file{configure.ac} is changed.  This makes
11519 development safer by ensuring a @file{configure} is never out-of-date
11520 with respect to @file{configure.ac}.
11521
11522 As generated files shipped in packages are up-to-date, and because
11523 @command{tar} preserves times-tamps, these rebuild rules are not
11524 triggered when a user unpacks and builds a package.
11525
11526 @subheading Background: CVS and Timestamps
11527 @cindex timestamps and CVS
11528 @cindex CVS and timestamps
11529
11530 Unless you use CVS keywords (in which case files must be updated at
11531 commit time), CVS preserves timestamp during @samp{cvs commit} and
11532 @samp{cvs import -d} operations.
11533
11534 When you check out a file using @samp{cvs checkout} its timestamp is
11535 set to that of the revision that is being checked out.
11536
11537 However, during @command{cvs update}, files will have the date of the
11538 update, not the original timestamp of this revision.  This is meant to
11539 make sure that @command{make} notices sources files have been updated.
11540
11541 This timestamp shift is troublesome when both sources and generated
11542 files are kept under CVS@.  Because CVS processes files in lexical
11543 order, @file{configure.ac} will appear newer than @file{configure}
11544 after a @command{cvs update} that updates both files, even if
11545 @file{configure} was newer than @file{configure.ac} when it was
11546 checked in.  Calling @command{make} will then trigger a spurious rebuild
11547 of @file{configure}.
11548
11549 @subheading Living with CVS in Autoconfiscated Projects
11550 @cindex CVS and generated files
11551 @cindex generated files and CVS
11552
11553 There are basically two clans amongst maintainers: those who keep all
11554 distributed files under CVS, including generated files, and those who
11555 keep generated files @emph{out} of CVS.
11556
11557 @subsubheading All Files in CVS
11558
11559 @itemize @bullet
11560 @item
11561 The CVS repository contains all distributed files so you know exactly
11562 what is distributed, and you can checkout any prior version entirely.
11563
11564 @item
11565 Maintainers can see how generated files evolve (for instance, you can
11566 see what happens to your @file{Makefile.in}s when you upgrade Automake
11567 and make sure they look OK).
11568
11569 @item
11570 Users do not need the autotools to build a checkout of the project, it
11571 works just like a released tarball.
11572
11573 @item
11574 If users use @command{cvs update} to update their copy, instead of
11575 @command{cvs checkout} to fetch a fresh one, timestamps will be
11576 inaccurate.  Some rebuild rules will be triggered and attempt to
11577 run developer tools such as @command{autoconf} or @command{automake}.
11578
11579 Calls to such tools are all wrapped into a call to the @command{missing}
11580 script discussed later (@pxref{maintainer-mode}), so that the user will
11581 see more descriptive warnings about missing or out-of-date tools, and
11582 possible suggestions about how to obtain them, rather than just some
11583 ``command not found'' error, or (worse) some obscure message from some
11584 older version of the required tool they happen to have installed.
11585
11586 Maintainers interested in keeping their package buildable from a CVS
11587 checkout even for those users that lack maintainer-specific tools might
11588 want to provide an helper script (or to enhance their existing bootstrap
11589 script) to fix the timestamps after a
11590 @command{cvs update} or a @command{git checkout}, to prevent spurious
11591 rebuilds.  In case of a project committing the Autotools-generated
11592 files, as well as the generated @file{.info} files, such script might
11593 look something like this:
11594
11595 @smallexample
11596 #!/bin/sh
11597 # fix-timestamp.sh: prevents useless rebuilds after "cvs update"
11598 sleep 1
11599 # aclocal-generated aclocal.m4 depends on locally-installed
11600 # '.m4' macro files, as well as on 'configure.ac'
11601 touch aclocal.m4
11602 sleep 1
11603 # autoconf-generated configure depends on aclocal.m4 and on
11604 # configure.ac
11605 configure config.h.in
11606 # so does autoheader-generated config.h.in
11607 configure config.h.in
11608 # and all the automake-generated Makefile.in files
11609 touch `find . -name Makefile.in -print`
11610 # finally, the makeinfo-generated '.info' files depend on the
11611 # corresponding '.texi' files
11612 touch doc/*.info
11613 @end smallexample
11614
11615 @item
11616 In distributed development, developers are likely to have different
11617 version of the maintainer tools installed.  In this case rebuilds
11618 triggered by timestamp lossage will lead to spurious changes
11619 to generated files.  There are several solutions to this:
11620
11621 @itemize
11622 @item
11623 All developers should use the same versions, so that the rebuilt files
11624 are identical to files in CVS@.  (This starts to be difficult when each
11625 project you work on uses different versions.)
11626 @item
11627 Or people use a script to fix the timestamp after a checkout (the GCC
11628 folks have such a script).
11629 @item
11630 Or @file{configure.ac} uses @code{AM_MAINTAINER_MODE}, which will
11631 disable all of these rebuild rules by default.  This is further discussed
11632 in @ref{maintainer-mode}.
11633 @end itemize
11634
11635 @item
11636 Although we focused on spurious rebuilds, the converse can also
11637 happen.  CVS's timestamp handling can also let you think an
11638 out-of-date file is up-to-date.
11639
11640 For instance, suppose a developer has modified @file{Makefile.am} and
11641 has rebuilt @file{Makefile.in}, and then decides to do a last-minute
11642 change to @file{Makefile.am} right before checking in both files
11643 (without rebuilding @file{Makefile.in} to account for the change).
11644
11645 This last change to @file{Makefile.am} makes the copy of
11646 @file{Makefile.in} out-of-date.  Since CVS processes files
11647 alphabetically, when another developer @samp{cvs update}s his or her
11648 tree, @file{Makefile.in} will happen to be newer than
11649 @file{Makefile.am}.  This other developer will not see that
11650 @file{Makefile.in} is out-of-date.
11651
11652 @end itemize
11653
11654 @subsubheading Generated Files out of CVS
11655
11656 One way to get CVS and @command{make} working peacefully is to never
11657 store generated files in CVS, i.e., do not CVS-control files that
11658 are @file{Makefile} targets (also called @emph{derived} files).
11659
11660 This way developers are not annoyed by changes to generated files.  It
11661 does not matter if they all have different versions (assuming they are
11662 compatible, of course).  And finally, timestamps are not lost, changes
11663 to sources files can't be missed as in the
11664 @file{Makefile.am}/@file{Makefile.in} example discussed earlier.
11665
11666 The drawback is that the CVS repository is not an exact copy of what
11667 is distributed and that users now need to install various development
11668 tools (maybe even specific versions) before they can build a checkout.
11669 But, after all, CVS's job is versioning, not distribution.
11670
11671 Allowing developers to use different versions of their tools can also
11672 hide bugs during distributed development.  Indeed, developers will be
11673 using (hence testing) their own generated files, instead of the
11674 generated files that will be released actually.  The developer who
11675 prepares the tarball might be using a version of the tool that
11676 produces bogus output (for instance a non-portable C file), something
11677 other developers could have noticed if they weren't using their own
11678 versions of this tool.
11679
11680 @subheading Third-party Files
11681 @cindex CVS and third-party files
11682 @cindex third-party files and CVS
11683
11684 Another class of files not discussed here (because they do not cause
11685 timestamp issues) are files that are shipped with a package, but
11686 maintained elsewhere.  For instance, tools like @command{gettextize}
11687 and @command{autopoint} (from Gettext) or @command{libtoolize} (from
11688 Libtool), will install or update files in your package.
11689
11690 These files, whether they are kept under CVS or not, raise similar
11691 concerns about version mismatch between developers' tools.  The
11692 Gettext manual has a section about this, see @ref{CVS Issues, CVS
11693 Issues, Integrating with CVS, gettext, GNU gettext tools}.
11694
11695 @node maintainer-mode
11696 @section @command{missing} and @code{AM_MAINTAINER_MODE}
11697
11698 @subheading @command{missing}
11699 @cindex @command{missing}, purpose
11700
11701 The @command{missing} script is a wrapper around several maintainer
11702 tools, designed to warn users if a maintainer tool is required but
11703 missing.  Typical maintainer tools are @command{autoconf},
11704 @command{automake}, @command{bison}, etc.  Because file generated by
11705 these tools are shipped with the other sources of a package, these
11706 tools shouldn't be required during a user build and they are not
11707 checked for in @file{configure}.
11708
11709 However, if for some reason a rebuild rule is triggered and involves a
11710 missing tool, @command{missing} will notice it and warn the user, even
11711 suggesting how to obtain such a tool (at least in case it is a well-known
11712 one, like @command{makeinfo} or @command{bison}).  This is more helpful
11713 and user-friendly than just having the rebuild rules spewing out a terse
11714 error message like @samp{sh: @var{tool}: command not found}.  Similarly,
11715 @command{missing} will warn the user if it detects that a maintainer
11716 tool it attempted to use seems too old (be warned that diagnosing this
11717 correctly is typically more difficult that detecting missing tools, and
11718 requires cooperation from the tool itself, so it won't always work).
11719
11720 If the required tool is installed, @command{missing} will run it and
11721 won't attempt to continue after failures.  This is correct during
11722 development: developers love fixing failures.  However, users with
11723 missing or too old maintainer tools may get an error when the rebuild
11724 rule is spuriously triggered, halting the build.  This failure to let
11725 the build continue is one of the arguments of the
11726 @code{AM_MAINTAINER_MODE} advocates.
11727
11728 @subheading @code{AM_MAINTAINER_MODE}
11729 @cindex @code{AM_MAINTAINER_MODE}, purpose
11730 @acindex AM_MAINTAINER_MODE
11731
11732 @code{AM_MAINTAINER_MODE} allows you to choose whether the so called
11733 "rebuild rules" should be enabled or disabled.  With
11734 @code{AM_MAINTAINER_MODE([enable])}, they are enabled by default,
11735 otherwise they are disabled by default.  In the latter case, if
11736 you have @code{AM_MAINTAINER_MODE} in @file{configure.ac}, and run
11737 @samp{./configure && make}, then @command{make} will *never* attempt to
11738 rebuild @file{configure}, @file{Makefile.in}s, Lex or Yacc outputs, etc.
11739 I.e., this disables build rules for files that are usually distributed
11740 and that users should normally not have to update.
11741
11742 The user can override the default setting by passing either
11743 @samp{--enable-maintainer-mode} or @samp{--disable-maintainer-mode}
11744 to @command{configure}.
11745
11746 People use @code{AM_MAINTAINER_MODE} either because they do not want their
11747 users (or themselves) annoyed by timestamps lossage (@pxref{CVS}), or
11748 because they simply can't stand the rebuild rules and prefer running
11749 maintainer tools explicitly.
11750
11751 @code{AM_MAINTAINER_MODE} also allows you to disable some custom build
11752 rules conditionally.  Some developers use this feature to disable
11753 rules that need exotic tools that users may not have available.
11754
11755 Several years ago Fran@,{c}ois Pinard pointed out several arguments
11756 against this @code{AM_MAINTAINER_MODE} macro.  Most of them relate to
11757 insecurity.  By removing dependencies you get non-dependable builds:
11758 changes to sources files can have no effect on generated files and this
11759 can be very confusing when unnoticed.  He adds that security shouldn't
11760 be reserved to maintainers (what @option{--enable-maintainer-mode}
11761 suggests), on the contrary.  If one user has to modify a
11762 @file{Makefile.am}, then either @file{Makefile.in} should be updated
11763 or a warning should be output (this is what Automake uses
11764 @command{missing} for) but the last thing you want is that nothing
11765 happens and the user doesn't notice it (this is what happens when
11766 rebuild rules are disabled by @code{AM_MAINTAINER_MODE}).
11767
11768 Jim Meyering, the inventor of the @code{AM_MAINTAINER_MODE} macro was
11769 swayed by Fran@,{c}ois's arguments, and got rid of
11770 @code{AM_MAINTAINER_MODE} in all of his packages.
11771
11772 Still many people continue to use @code{AM_MAINTAINER_MODE}, because
11773 it helps them working on projects where all files are kept under version
11774 control, and because @command{missing} isn't enough if you have the
11775 wrong version of the tools.
11776
11777
11778 @node Wildcards
11779 @section Why doesn't Automake support wildcards?
11780 @cindex wildcards
11781
11782 Developers are lazy.  They would often like to use wildcards in
11783 @file{Makefile.am}s, so that they would not need to remember to
11784 update @file{Makefile.am}s every time they add, delete, or rename
11785 a file.
11786
11787 There are several objections to this:
11788 @itemize
11789 @item
11790 When using CVS (or similar) developers need to remember they have to
11791 run @samp{cvs add} or @samp{cvs rm} anyway.  Updating
11792 @file{Makefile.am} accordingly quickly becomes a reflex.
11793
11794 Conversely, if your application doesn't compile
11795 because you forgot to add a file in @file{Makefile.am}, it will help
11796 you remember to @samp{cvs add} it.
11797
11798 @item
11799 Using wildcards makes it easy to distribute files by mistake.  For
11800 instance, some code a developer is experimenting with (a test case,
11801 say) that should not be part of the distribution.
11802
11803 @item
11804 Using wildcards it's easy to omit some files by mistake.  For
11805 instance, one developer creates a new file, uses it in many places,
11806 but forgets to commit it.  Another developer then checks out the
11807 incomplete project and is able to run @samp{make dist} successfully,
11808 even though a file is missing. By listing files, @samp{make dist}
11809 @emph{will} complain.
11810
11811 @item
11812 Wildcards are not portable to some non-GNU @command{make} implementations,
11813 e.g., NetBSD @command{make} will not expand globs such as @samp{*} in
11814 prerequisites of a target.
11815
11816 @item
11817 Finally, it's really hard to @emph{forget} to add a file to
11818 @file{Makefile.am}: files that are not listed in @file{Makefile.am} are
11819 not compiled or installed, so you can't even test them.
11820 @end itemize
11821
11822 Still, these are philosophical objections, and as such you may disagree,
11823 or find enough value in wildcards to dismiss all of them.  Before you
11824 start writing a patch against Automake to teach it about wildcards,
11825 let's see the main technical issue: portability.
11826
11827 Although @samp{$(wildcard ...)} works with GNU @command{make}, it is
11828 not portable to other @command{make} implementations.
11829
11830 The only way Automake could support @command{$(wildcard ...)} is by
11831 expending @command{$(wildcard ...)} when @command{automake} is run.
11832 The resulting @file{Makefile.in}s would be portable since they would
11833 list all files and not use @samp{$(wildcard ...)}.  However that
11834 means developers would need to remember to run @command{automake} each
11835 time they add, delete, or rename files.
11836
11837 Compared to editing @file{Makefile.am}, this is a very small gain.  Sure,
11838 it's easier and faster to type @samp{automake; make} than to type
11839 @samp{emacs Makefile.am; make}.  But nobody bothered enough to write a
11840 patch to add support for this syntax.  Some people use scripts to
11841 generate file lists in @file{Makefile.am} or in separate
11842 @file{Makefile} fragments.
11843
11844 Even if you don't care about portability, and are tempted to use
11845 @samp{$(wildcard ...)} anyway because you target only GNU Make, you
11846 should know there are many places where Automake needs to know exactly
11847 which files should be processed.  As Automake doesn't know how to
11848 expand @samp{$(wildcard ...)}, you cannot use it in these places.
11849 @samp{$(wildcard ...)} is a black box comparable to @code{AC_SUBST}ed
11850 variables as far Automake is concerned.
11851
11852 You can get warnings about @samp{$(wildcard ...}) constructs using the
11853 @option{-Wportability} flag.
11854
11855 @node Limitations on File Names
11856 @section Limitations on File Names
11857 @cindex file names, limitations on
11858
11859 Automake attempts to support all kinds of file names, even those that
11860 contain unusual characters or are unusually long.  However, some
11861 limitations are imposed by the underlying operating system and tools.
11862
11863 Most operating systems prohibit the use of the null byte in file
11864 names, and reserve @samp{/} as a directory separator.  Also, they
11865 require that file names are properly encoded for the user's locale.
11866 Automake is subject to these limits.
11867
11868 Portable packages should limit themselves to POSIX file
11869 names.  These can contain ASCII letters and digits,
11870 @samp{_}, @samp{.}, and @samp{-}.  File names consist of components
11871 separated by @samp{/}.  File name components cannot begin with
11872 @samp{-}.
11873
11874 Portable POSIX file names cannot contain components that exceed a
11875 14-byte limit, but nowadays it's normally safe to assume the
11876 more-generous XOPEN limit of 255 bytes.  POSIX
11877 limits file names to 255 bytes (XOPEN allows 1023 bytes),
11878 but you may want to limit a source tarball to file names of 99 bytes
11879 to avoid interoperability problems with old versions of @command{tar}.
11880
11881 If you depart from these rules (e.g., by using non-ASCII
11882 characters in file names, or by using lengthy file names), your
11883 installers may have problems for reasons unrelated to Automake.
11884 However, if this does not concern you, you should know about the
11885 limitations imposed by Automake itself.  These limitations are
11886 undesirable, but some of them seem to be inherent to underlying tools
11887 like Autoconf, Make, M4, and the shell.  They fall into three
11888 categories: install directories, build directories, and file names.
11889
11890 The following characters:
11891
11892 @example
11893 @r{newline} " # $ ' `
11894 @end example
11895
11896 should not appear in the names of install directories.  For example,
11897 the operand of @command{configure}'s @option{--prefix} option should
11898 not contain these characters.
11899
11900 Build directories suffer the same limitations as install directories,
11901 and in addition should not contain the following characters:
11902
11903 @example
11904 & @@ \
11905 @end example
11906
11907 For example, the full name of the directory containing the source
11908 files should not contain these characters.
11909
11910 Source and installation file names like @file{main.c} are limited even
11911 further: they should conform to the POSIX/XOPEN
11912 rules described above.  In addition, if you plan to port to
11913 non-POSIX environments, you should avoid file names that
11914 differ only in case (e.g., @file{makefile} and @file{Makefile}).
11915 Nowadays it is no longer worth worrying about the 8.3 limits of
11916 DOS file systems.
11917
11918 @c FIXME This should probably be moved in the "Checking the Distribution"
11919 @c FIXME section...
11920 @node Errors with distclean
11921 @section Errors with distclean
11922 @cindex @code{distclean}, diagnostic
11923 @cindex @samp{make distclean}, diagnostic
11924 @cindex dependencies and distributed files
11925 @trindex distclean
11926
11927 This is a diagnostic you might encounter while running @samp{make
11928 distcheck}.
11929
11930 As explained in @ref{Checking the Distribution}, @samp{make distcheck}
11931 attempts to build and check your package for errors like this one.
11932
11933 @samp{make distcheck} will perform a @code{VPATH} build of your
11934 package (@pxref{VPATH Builds}), and then call @samp{make distclean}.
11935 Files left in the build directory after @samp{make distclean} has run
11936 are listed after this error.
11937
11938 This diagnostic really covers two kinds of errors:
11939
11940 @itemize @bullet
11941 @item
11942 files that are forgotten by distclean;
11943 @item
11944 distributed files that are erroneously rebuilt.
11945 @end itemize
11946
11947 The former left-over files are not distributed, so the fix is to mark
11948 them for cleaning (@pxref{Clean}), this is obvious and doesn't deserve
11949 more explanations.
11950
11951 The latter bug is not always easy to understand and fix, so let's
11952 proceed with an example.  Suppose our package contains a program for
11953 which we want to build a man page using @command{help2man}.  GNU
11954 @command{help2man} produces simple manual pages from the @option{--help}
11955 and @option{--version} output of other commands (@pxref{Top, , Overview,
11956 help2man, The Help2man Manual}).  Because we don't want to force our
11957 users to install @command{help2man}, we decide to distribute the
11958 generated man page using the following setup.
11959
11960 @example
11961 # This Makefile.am is bogus.
11962 bin_PROGRAMS = foo
11963 foo_SOURCES = foo.c
11964 dist_man_MANS = foo.1
11965
11966 foo.1: foo$(EXEEXT)
11967         help2man --output=foo.1 ./foo$(EXEEXT)
11968 @end example
11969
11970 This will effectively distribute the man page.  However,
11971 @samp{make distcheck} will fail with:
11972
11973 @example
11974 ERROR: files left in build directory after distclean:
11975 ./foo.1
11976 @end example
11977
11978 Why was @file{foo.1} rebuilt?  Because although distributed,
11979 @file{foo.1} depends on a non-distributed built file:
11980 @file{foo$(EXEEXT)}.  @file{foo$(EXEEXT)} is built by the user, so it
11981 will always appear to be newer than the distributed @file{foo.1}.
11982
11983 @samp{make distcheck} caught an inconsistency in our package.  Our
11984 intent was to distribute @file{foo.1} so users do not need to install
11985 @command{help2man}, however since this rule causes this file to be
11986 always rebuilt, users @emph{do} need @command{help2man}.  Either we
11987 should ensure that @file{foo.1} is not rebuilt by users, or there is
11988 no point in distributing @file{foo.1}.
11989
11990 More generally, the rule is that distributed files should never depend
11991 on non-distributed built files.  If you distribute something
11992 generated, distribute its sources.
11993
11994 One way to fix the above example, while still distributing
11995 @file{foo.1} is to not depend on @file{foo$(EXEEXT)}.  For instance,
11996 assuming @command{foo --version} and @command{foo --help} do not
11997 change unless @file{foo.c} or @file{configure.ac} change, we could
11998 write the following @file{Makefile.am}:
11999
12000 @example
12001 bin_PROGRAMS = foo
12002 foo_SOURCES = foo.c
12003 dist_man_MANS = foo.1
12004
12005 foo.1: foo.c $(top_srcdir)/configure.ac
12006         $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
12007         help2man --output=foo.1 ./foo$(EXEEXT)
12008 @end example
12009
12010 This way, @file{foo.1} will not get rebuilt every time
12011 @file{foo$(EXEEXT)} changes.  The @command{make} call makes sure
12012 @file{foo$(EXEEXT)} is up-to-date before @command{help2man}.  Another
12013 way to ensure this would be to use separate directories for binaries
12014 and man pages, and set @code{SUBDIRS} so that binaries are built
12015 before man pages.
12016
12017 We could also decide not to distribute @file{foo.1}.  In
12018 this case it's fine to have @file{foo.1} dependent upon
12019 @file{foo$(EXEEXT)}, since both will have to be rebuilt.
12020 However it would be impossible to build the package in a
12021 cross-compilation, because building @file{foo.1} involves
12022 an @emph{execution} of @file{foo$(EXEEXT)}.
12023
12024 Another context where such errors are common is when distributed files
12025 are built by tools that are built by the package.  The pattern is
12026 similar:
12027
12028 @example
12029 distributed-file: built-tools distributed-sources
12030         build-command
12031 @end example
12032
12033 @noindent
12034 should be changed to
12035
12036 @example
12037 distributed-file: distributed-sources
12038         $(MAKE) $(AM_MAKEFLAGS) built-tools
12039         build-command
12040 @end example
12041
12042 @noindent
12043 or you could choose not to distribute @file{distributed-file}, if
12044 cross-compilation does not matter.
12045
12046 The points made through these examples are worth a summary:
12047
12048 @cartouche
12049 @itemize
12050 @item
12051 Distributed files should never depend upon non-distributed built
12052 files.
12053 @item
12054 Distributed files should be distributed with all their dependencies.
12055 @item
12056 If a file is @emph{intended} to be rebuilt by users, then there is no point
12057 in distributing it.
12058 @end itemize
12059 @end cartouche
12060
12061 @vrindex distcleancheck_listfiles
12062 For desperate cases, it's always possible to disable this check by
12063 setting @code{distcleancheck_listfiles} as documented in @ref{Checking
12064 the Distribution}.
12065 Make sure you do understand the reason why @samp{make distcheck}
12066 complains before you do this.  @code{distcleancheck_listfiles} is a
12067 way to @emph{hide} errors, not to fix them.  You can always do better.
12068
12069 @node Flag Variables Ordering
12070 @section Flag Variables Ordering
12071 @cindex Ordering flag variables
12072 @cindex Flag variables, ordering
12073
12074 @display
12075 What is the difference between @code{AM_CFLAGS}, @code{CFLAGS}, and
12076 @code{mumble_CFLAGS}?
12077 @end display
12078
12079 @display
12080 Why does @command{automake} output @code{CPPFLAGS} after
12081 @code{AM_CPPFLAGS} on compile lines?  Shouldn't it be the converse?
12082 @end display
12083
12084 @display
12085 My @file{configure} adds some warning flags into @code{CXXFLAGS}.  In
12086 one @file{Makefile.am} I would like to append a new flag, however if I
12087 put the flag into @code{AM_CXXFLAGS} it is prepended to the other
12088 flags, not appended.
12089 @end display
12090
12091 @subheading Compile Flag Variables
12092 @cindex Flag Variables, Ordering
12093 @cindex Compile Flag Variables
12094 @cindex @code{AM_CCASFLAGS} and @code{CCASFLAGS}
12095 @cindex @code{AM_CFLAGS} and @code{CFLAGS}
12096 @cindex @code{AM_CPPFLAGS} and @code{CPPFLAGS}
12097 @cindex @code{AM_CXXFLAGS} and @code{CXXFLAGS}
12098 @cindex @code{AM_FCFLAGS} and @code{FCFLAGS}
12099 @cindex @code{AM_FFLAGS} and @code{FFLAGS}
12100 @cindex @code{AM_GCJFLAGS} and @code{GCJFLAGS}
12101 @cindex @code{AM_LDFLAGS} and @code{LDFLAGS}
12102 @cindex @code{AM_LFLAGS} and @code{LFLAGS}
12103 @cindex @code{AM_LIBTOOLFLAGS} and @code{LIBTOOLFLAGS}
12104 @cindex @code{AM_OBJCFLAGS} and @code{OBJCFLAGS}
12105 @cindex @code{AM_OBJCXXFLAGS} and @code{OBJXXCFLAGS}
12106 @cindex @code{AM_RFLAGS} and @code{RFLAGS}
12107 @cindex @code{AM_UPCFLAGS} and @code{UPCFLAGS}
12108 @cindex @code{AM_YFLAGS} and @code{YFLAGS}
12109 @cindex @code{CCASFLAGS} and @code{AM_CCASFLAGS}
12110 @cindex @code{CFLAGS} and @code{AM_CFLAGS}
12111 @cindex @code{CPPFLAGS} and @code{AM_CPPFLAGS}
12112 @cindex @code{CXXFLAGS} and @code{AM_CXXFLAGS}
12113 @cindex @code{FCFLAGS} and @code{AM_FCFLAGS}
12114 @cindex @code{FFLAGS} and @code{AM_FFLAGS}
12115 @cindex @code{GCJFLAGS} and @code{AM_GCJFLAGS}
12116 @cindex @code{LDFLAGS} and @code{AM_LDFLAGS}
12117 @cindex @code{LFLAGS} and @code{AM_LFLAGS}
12118 @cindex @code{LIBTOOLFLAGS} and @code{AM_LIBTOOLFLAGS}
12119 @cindex @code{OBJCFLAGS} and @code{AM_OBJCFLAGS}
12120 @cindex @code{OBJCXXFLAGS} and @code{AM_OBJCXXFLAGS}
12121 @cindex @code{RFLAGS} and @code{AM_RFLAGS}
12122 @cindex @code{UPCFLAGS} and @code{AM_UPCFLAGS}
12123 @cindex @code{YFLAGS} and @code{AM_YFLAGS}
12124
12125 This section attempts to answer all the above questions.  We will
12126 mostly discuss @code{CPPFLAGS} in our examples, but actually the
12127 answer holds for all the compile flags used in Automake:
12128 @code{CCASFLAGS}, @code{CFLAGS}, @code{CPPFLAGS}, @code{CXXFLAGS},
12129 @code{FCFLAGS}, @code{FFLAGS}, @code{GCJFLAGS}, @code{LDFLAGS},
12130 @code{LFLAGS}, @code{LIBTOOLFLAGS}, @code{OBJCFLAGS}, @code{OBJCXXFLAGS},
12131 @code{RFLAGS}, @code{UPCFLAGS}, and @code{YFLAGS}.
12132
12133 @code{CPPFLAGS}, @code{AM_CPPFLAGS}, and @code{mumble_CPPFLAGS} are
12134 three variables that can be used to pass flags to the C preprocessor
12135 (actually these variables are also used for other languages like C++
12136 or preprocessed Fortran).  @code{CPPFLAGS} is the user variable
12137 (@pxref{User Variables}), @code{AM_CPPFLAGS} is the Automake variable,
12138 and @code{mumble_CPPFLAGS} is the variable specific to the
12139 @code{mumble} target (we call this a per-target variable,
12140 @pxref{Program and Library Variables}).
12141
12142 Automake always uses two of these variables when compiling C sources
12143 files.  When compiling an object file for the @code{mumble} target,
12144 the first variable will be @code{mumble_CPPFLAGS} if it is defined, or
12145 @code{AM_CPPFLAGS} otherwise.  The second variable is always
12146 @code{CPPFLAGS}.
12147
12148 In the following example,
12149
12150 @example
12151 bin_PROGRAMS = foo bar
12152 foo_SOURCES = xyz.c
12153 bar_SOURCES = main.c
12154 foo_CPPFLAGS = -DFOO
12155 AM_CPPFLAGS = -DBAZ
12156 @end example
12157
12158 @noindent
12159 @file{xyz.o} will be compiled with @samp{$(foo_CPPFLAGS) $(CPPFLAGS)},
12160 (because @file{xyz.o} is part of the @code{foo} target), while
12161 @file{main.o} will be compiled with @samp{$(AM_CPPFLAGS) $(CPPFLAGS)}
12162 (because there is no per-target variable for target @code{bar}).
12163
12164 The difference between @code{mumble_CPPFLAGS} and @code{AM_CPPFLAGS}
12165 being clear enough, let's focus on @code{CPPFLAGS}.  @code{CPPFLAGS}
12166 is a user variable, i.e., a variable that users are entitled to modify
12167 in order to compile the package.  This variable, like many others,
12168 is documented at the end of the output of @samp{configure --help}.
12169
12170 For instance, someone who needs to add @file{/home/my/usr/include} to
12171 the C compiler's search path would configure a package with
12172
12173 @example
12174 ./configure CPPFLAGS='-I /home/my/usr/include'
12175 @end example
12176
12177 @noindent
12178 and this flag would be propagated to the compile rules of all
12179 @file{Makefile}s.
12180
12181 It is also not uncommon to override a user variable at
12182 @command{make}-time.  Many installers do this with @code{prefix}, but
12183 this can be useful with compiler flags too.  For instance, if, while
12184 debugging a C++ project, you need to disable optimization in one
12185 specific object file, you can run something like
12186
12187 @example
12188 rm file.o
12189 make CXXFLAGS=-O0 file.o
12190 make
12191 @end example
12192
12193 The reason @samp{$(CPPFLAGS)} appears after @samp{$(AM_CPPFLAGS)} or
12194 @samp{$(mumble_CPPFLAGS)} in the compile command is that users
12195 should always have the last say.  It probably makes more sense if you
12196 think about it while looking at the @samp{CXXFLAGS=-O0} above, which
12197 should supersede any other switch from @code{AM_CXXFLAGS} or
12198 @code{mumble_CXXFLAGS} (and this of course replaces the previous value
12199 of @code{CXXFLAGS}).
12200
12201 You should never redefine a user variable such as @code{CPPFLAGS} in
12202 @file{Makefile.am}.  Use @samp{automake -Woverride} to diagnose such
12203 mistakes.  Even something like
12204
12205 @example
12206 CPPFLAGS = -DDATADIR=\"$(datadir)\" @@CPPFLAGS@@
12207 @end example
12208
12209 @noindent
12210 is erroneous.  Although this preserves @file{configure}'s value of
12211 @code{CPPFLAGS}, the definition of @code{DATADIR} will disappear if a
12212 user attempts to override @code{CPPFLAGS} from the @command{make}
12213 command line.
12214
12215 @example
12216 AM_CPPFLAGS = -DDATADIR=\"$(datadir)\"
12217 @end example
12218
12219 @noindent
12220 is all that is needed here if no per-target flags are used.
12221
12222 You should not add options to these user variables within
12223 @file{configure} either, for the same reason.  Occasionally you need
12224 to modify these variables to perform a test, but you should reset
12225 their values afterwards.  In contrast, it is OK to modify the
12226 @samp{AM_} variables within @file{configure} if you @code{AC_SUBST}
12227 them, but it is rather rare that you need to do this, unless you
12228 really want to change the default definitions of the @samp{AM_}
12229 variables in all @file{Makefile}s.
12230
12231 What we recommend is that you define extra flags in separate
12232 variables.  For instance, you may write an Autoconf macro that computes
12233 a set of warning options for the C compiler, and @code{AC_SUBST} them
12234 in @code{WARNINGCFLAGS}; you may also have an Autoconf macro that
12235 determines which compiler and which linker flags should be used to
12236 link with library @file{libfoo}, and @code{AC_SUBST} these in
12237 @code{LIBFOOCFLAGS} and @code{LIBFOOLDFLAGS}.  Then, a
12238 @file{Makefile.am} could use these variables as follows:
12239
12240 @example
12241 AM_CFLAGS = $(WARNINGCFLAGS)
12242 bin_PROGRAMS = prog1 prog2
12243 prog1_SOURCES = @dots{}
12244 prog2_SOURCES = @dots{}
12245 prog2_CFLAGS = $(LIBFOOCFLAGS) $(AM_CFLAGS)
12246 prog2_LDFLAGS = $(LIBFOOLDFLAGS)
12247 @end example
12248
12249 In this example both programs will be compiled with the flags
12250 substituted into @samp{$(WARNINGCFLAGS)}, and @code{prog2} will
12251 additionally be compiled with the flags required to link with
12252 @file{libfoo}.
12253
12254 Note that listing @code{AM_CFLAGS} in a per-target @code{CFLAGS}
12255 variable is a common idiom to ensure that @code{AM_CFLAGS} applies to
12256 every target in a @file{Makefile.in}.
12257
12258 Using variables like this gives you full control over the ordering of
12259 the flags.  For instance, if there is a flag in $(WARNINGCFLAGS) that
12260 you want to negate for a particular target, you can use something like
12261 @samp{prog1_CFLAGS = $(AM_CFLAGS) -no-flag}.  If all of these flags had
12262 been forcefully appended to @code{CFLAGS}, there would be no way to
12263 disable one flag.  Yet another reason to leave user variables to
12264 users.
12265
12266 Finally, we have avoided naming the variable of the example
12267 @code{LIBFOO_LDFLAGS} (with an underscore) because that would cause
12268 Automake to think that this is actually a per-target variable (like
12269 @code{mumble_LDFLAGS}) for some non-declared @code{LIBFOO} target.
12270
12271 @subheading Other Variables
12272
12273 There are other variables in Automake that follow similar principles
12274 to allow user options.  For instance, Texinfo rules (@pxref{Texinfo})
12275 use @code{MAKEINFOFLAGS} and @code{AM_MAKEINFOFLAGS}.  Similarly,
12276 DejaGnu tests (@pxref{DejaGnu Tests}) use @code{RUNTESTDEFAULTFLAGS} and
12277 @code{AM_RUNTESTDEFAULTFLAGS}.  The tags and ctags rules
12278 (@pxref{Tags}) use @code{ETAGSFLAGS}, @code{AM_ETAGSFLAGS},
12279 @code{CTAGSFLAGS}, and @code{AM_CTAGSFLAGS}.  Java rules
12280 (@pxref{Java}) use @code{JAVACFLAGS} and @code{AM_JAVACFLAGS}.  None
12281 of these rules support per-target flags (yet).
12282
12283 To some extent, even @code{AM_MAKEFLAGS} (@pxref{Subdirectories})
12284 obeys this naming scheme.  The slight difference is that
12285 @code{MAKEFLAGS} is passed to sub-@command{make}s implicitly by
12286 @command{make} itself.
12287
12288 However you should not think that all variables ending with @code{FLAGS}
12289 follow this convention.  For instance, @code{ACLOCAL_AMFLAGS} (see
12290 @ref{Rebuilding} and @ref{Local Macros}) is a variable that is only
12291 useful to the maintainer and has no user counterpart.
12292
12293 @code{ARFLAGS} (@pxref{A Library}) is usually defined by Automake and
12294 has neither @code{AM_} nor per-target cousin.
12295
12296 Finally you should not think that the existence of a per-target
12297 variable implies the existence of an @code{AM_} variable or of a user
12298 variable.  For instance, the @code{mumble_LDADD} per-target variable
12299 overrides the makefile-wide @code{LDADD} variable (which is not a user
12300 variable), and @code{mumble_LIBADD} exists only as a per-target
12301 variable.  @xref{Program and Library Variables}.
12302
12303
12304 @node Renamed Objects
12305 @section Why are object files sometimes renamed?
12306
12307 This happens when per-target compilation flags are used.  Object
12308 files need to be renamed just in case they would clash with object
12309 files compiled from the same sources, but with different flags.
12310 Consider the following example.
12311
12312 @example
12313 bin_PROGRAMS = true false
12314 true_SOURCES = generic.c
12315 true_CPPFLAGS = -DEXIT_CODE=0
12316 false_SOURCES = generic.c
12317 false_CPPFLAGS = -DEXIT_CODE=1
12318 @end example
12319
12320 @noindent
12321 Obviously the two programs are built from the same source, but it
12322 would be bad if they shared the same object, because @file{generic.o}
12323 cannot be built with both @samp{-DEXIT_CODE=0} @emph{and}
12324 @samp{-DEXIT_CODE=1}.  Therefore @command{automake} outputs rules to
12325 build two different objects: @file{true-generic.o} and
12326 @file{false-generic.o}.
12327
12328 @command{automake} doesn't actually look whether source files are
12329 shared to decide if it must rename objects.  It will just rename all
12330 objects of a target as soon as it sees per-target compilation flags
12331 used.
12332
12333 It's OK to share object files when per-target compilation flags are not
12334 used.  For instance, @file{true} and @file{false} will both use
12335 @file{version.o} in the following example.
12336
12337 @example
12338 AM_CPPFLAGS = -DVERSION=1.0
12339 bin_PROGRAMS = true false
12340 true_SOURCES = true.c version.c
12341 false_SOURCES = false.c version.c
12342 @end example
12343
12344 Note that the renaming of objects is also affected by the
12345 @code{_SHORTNAME} variable (@pxref{Program and Library Variables}).
12346
12347
12348 @node Per-Object Flags
12349 @section Per-Object Flags Emulation
12350 @cindex Per-object flags, emulated
12351
12352 @display
12353 One of my source files needs to be compiled with different flags.  How
12354 do I do?
12355 @end display
12356
12357 Automake supports per-program and per-library compilation flags (see
12358 @ref{Program and Library Variables} and @ref{Flag Variables
12359 Ordering}).  With this you can define compilation flags that apply to
12360 all files compiled for a target.  For instance, in
12361
12362 @example
12363 bin_PROGRAMS = foo
12364 foo_SOURCES = foo.c foo.h bar.c bar.h main.c
12365 foo_CFLAGS = -some -flags
12366 @end example
12367
12368 @noindent
12369 @file{foo-foo.o}, @file{foo-bar.o}, and @file{foo-main.o} will all be
12370 compiled with @samp{-some -flags}.  (If you wonder about the names of
12371 these object files, see @ref{Renamed Objects}.)  Note that
12372 @code{foo_CFLAGS} gives the flags to use when compiling all the C
12373 sources of the @emph{program} @code{foo}, it has nothing to do with
12374 @file{foo.c} or @file{foo-foo.o} specifically.
12375
12376 What if @file{foo.c} needs to be compiled into @file{foo.o} using some
12377 specific flags, that none of the other files requires?  Obviously
12378 per-program flags are not directly applicable here.  Something like
12379 per-object flags are expected, i.e., flags that would be used only
12380 when creating @file{foo-foo.o}.  Automake does not support that,
12381 however this is easy to simulate using a library that contains only
12382 that object, and compiling this library with per-library flags.
12383
12384 @example
12385 bin_PROGRAMS = foo
12386 foo_SOURCES = bar.c bar.h main.c
12387 foo_CFLAGS = -some -flags
12388 foo_LDADD = libfoo.a
12389 noinst_LIBRARIES = libfoo.a
12390 libfoo_a_SOURCES = foo.c foo.h
12391 libfoo_a_CFLAGS = -some -other -flags
12392 @end example
12393
12394 Here @file{foo-bar.o} and @file{foo-main.o} will all be
12395 compiled with @samp{-some -flags}, while @file{libfoo_a-foo.o} will
12396 be compiled using @samp{-some -other -flags}.  Eventually, all
12397 three objects will be linked to form @file{foo}.
12398
12399 This trick can also be achieved using Libtool convenience libraries,
12400 for instance @samp{noinst_LTLIBRARIES = libfoo.la} (@pxref{Libtool
12401 Convenience Libraries}).
12402
12403 Another tempting idea to implement per-object flags is to override the
12404 compile rules @command{automake} would output for these files.
12405 Automake will not define a rule for a target you have defined, so you
12406 could think about defining the @samp{foo-foo.o: foo.c} rule yourself.
12407 We recommend against this, because this is error prone.  For instance,
12408 if you add such a rule to the first example, it will break the day you
12409 decide to remove @code{foo_CFLAGS} (because @file{foo.c} will then be
12410 compiled as @file{foo.o} instead of @file{foo-foo.o}, @pxref{Renamed
12411 Objects}).  Also in order to support dependency tracking, the two
12412 @file{.o}/@file{.obj} extensions, and all the other flags variables
12413 involved in a compilation, you will end up modifying a copy of the
12414 rule previously output by @command{automake} for this file.  If a new
12415 release of Automake generates a different rule, your copy will need to
12416 be updated by hand.
12417
12418 @node Multiple Outputs
12419 @section Handling Tools that Produce Many Outputs
12420 @cindex multiple outputs, rules with
12421 @cindex many outputs, rules with
12422 @cindex rules with multiple outputs
12423
12424 This section describes a @command{make} idiom that can be used when a
12425 tool produces multiple output files.  It is not specific to Automake
12426 and can be used in ordinary @file{Makefile}s.
12427
12428 Suppose we have a program called @command{foo} that will read one file
12429 called @file{data.foo} and produce two files named @file{data.c} and
12430 @file{data.h}.  We want to write a @file{Makefile} rule that captures
12431 this one-to-two dependency.
12432
12433 The naive rule is incorrect:
12434
12435 @example
12436 # This is incorrect.
12437 data.c data.h: data.foo
12438         foo data.foo
12439 @end example
12440
12441 @noindent
12442 What the above rule really says is that @file{data.c} and
12443 @file{data.h} each depend on @file{data.foo}, and can each be built by
12444 running @samp{foo data.foo}.  In other words it is equivalent to:
12445
12446 @example
12447 # We do not want this.
12448 data.c: data.foo
12449         foo data.foo
12450 data.h: data.foo
12451         foo data.foo
12452 @end example
12453
12454 @noindent
12455 which means that @command{foo} can be run twice.  Usually it will not
12456 be run twice, because @command{make} implementations are smart enough
12457 to check for the existence of the second file after the first one has
12458 been built; they will therefore detect that it already exists.
12459 However there are a few situations where it can run twice anyway:
12460
12461 @itemize
12462 @item
12463 The most worrying case is when running a parallel @command{make}.  If
12464 @file{data.c} and @file{data.h} are built in parallel, two @samp{foo
12465 data.foo} commands will run concurrently.  This is harmful.
12466 @item
12467 Another case is when the dependency (here @file{data.foo}) is
12468 (or depends upon) a phony target.
12469 @end itemize
12470
12471 A solution that works with parallel @command{make} but not with
12472 phony dependencies is the following:
12473
12474 @example
12475 data.c data.h: data.foo
12476         foo data.foo
12477 data.h: data.c
12478 @end example
12479
12480 @noindent
12481 The above rules are equivalent to
12482
12483 @example
12484 data.c: data.foo
12485         foo data.foo
12486 data.h: data.foo data.c
12487         foo data.foo
12488 @end example
12489
12490 @noindent
12491 therefore a parallel @command{make} will have to serialize the builds
12492 of @file{data.c} and @file{data.h}, and will detect that the second is
12493 no longer needed once the first is over.
12494
12495 Using this pattern is probably enough for most cases.  However it does
12496 not scale easily to more output files (in this scheme all output files
12497 must be totally ordered by the dependency relation), so we will
12498 explore a more complicated solution.
12499
12500 Another idea is to write the following:
12501
12502 @example
12503 # There is still a problem with this one.
12504 data.c: data.foo
12505         foo data.foo
12506 data.h: data.c
12507 @end example
12508
12509 @noindent
12510 The idea is that @samp{foo data.foo} is run only when @file{data.c}
12511 needs to be updated, but we further state that @file{data.h} depends
12512 upon @file{data.c}.  That way, if @file{data.h} is required and
12513 @file{data.foo} is out of date, the dependency on @file{data.c} will
12514 trigger the build.
12515
12516 This is almost perfect, but suppose we have built @file{data.h} and
12517 @file{data.c}, and then we erase @file{data.h}.  Then, running
12518 @samp{make data.h} will not rebuild @file{data.h}.  The above rules
12519 just state that @file{data.c} must be up-to-date with respect to
12520 @file{data.foo}, and this is already the case.
12521
12522 What we need is a rule that forces a rebuild when @file{data.h} is
12523 missing.  Here it is:
12524
12525 @example
12526 data.c: data.foo
12527         foo data.foo
12528 data.h: data.c
12529 ## Recover from the removal of $@@
12530         @@if test -f $@@; then :; else \
12531           rm -f data.c; \
12532           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12533         fi
12534 @end example
12535
12536 The above scheme can be extended to handle more outputs and more
12537 inputs.  One of the outputs is selected to serve as a witness to the
12538 successful completion of the command, it depends upon all inputs, and
12539 all other outputs depend upon it.  For instance, if @command{foo}
12540 should additionally read @file{data.bar} and also produce
12541 @file{data.w} and @file{data.x}, we would write:
12542
12543 @example
12544 data.c: data.foo data.bar
12545         foo data.foo data.bar
12546 data.h data.w data.x: data.c
12547 ## Recover from the removal of $@@
12548         @@if test -f $@@; then :; else \
12549           rm -f data.c; \
12550           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12551         fi
12552 @end example
12553
12554 However there are now three minor problems in this setup.  One is related
12555 to the timestamp ordering of @file{data.h}, @file{data.w},
12556 @file{data.x}, and @file{data.c}.  Another one is a race condition
12557 if a parallel @command{make} attempts to run multiple instances of the
12558 recover block at once.  Finally, the recursive rule breaks @samp{make -n}
12559 when run with GNU @command{make} (as well as some other @command{make}
12560 implementations), as it may remove @file{data.h} even when it should not
12561 (@pxref{MAKE Variable, , How the @code{MAKE} Variable Works, make,
12562 The GNU Make Manual}).
12563
12564 Let us deal with the first problem.  @command{foo} outputs four files,
12565 but we do not know in which order these files are created.  Suppose
12566 that @file{data.h} is created before @file{data.c}.  Then we have a
12567 weird situation.  The next time @command{make} is run, @file{data.h}
12568 will appear older than @file{data.c}, the second rule will be
12569 triggered, a shell will be started to execute the @samp{if@dots{}fi}
12570 command, but actually it will just execute the @code{then} branch,
12571 that is: nothing.  In other words, because the witness we selected is
12572 not the first file created by @command{foo}, @command{make} will start
12573 a shell to do nothing each time it is run.
12574
12575 A simple riposte is to fix the timestamps when this happens.
12576
12577 @example
12578 data.c: data.foo data.bar
12579         foo data.foo data.bar
12580 data.h data.w data.x: data.c
12581         @@if test -f $@@; then \
12582           touch $@@; \
12583         else \
12584 ## Recover from the removal of $@@
12585           rm -f data.c; \
12586           $(MAKE) $(AM_MAKEFLAGS) data.c; \
12587         fi
12588 @end example
12589
12590 Another solution is to use a different and dedicated file as witness,
12591 rather than using any of @command{foo}'s outputs.
12592
12593 @example
12594 data.stamp: data.foo data.bar
12595         @@rm -f data.tmp
12596         @@touch data.tmp
12597         foo data.foo data.bar
12598         @@mv -f data.tmp $@@
12599 data.c data.h data.w data.x: data.stamp
12600 ## Recover from the removal of $@@
12601         @@if test -f $@@; then :; else \
12602           rm -f data.stamp; \
12603           $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12604         fi
12605 @end example
12606
12607 @file{data.tmp} is created before @command{foo} is run, so it has a
12608 timestamp older than output files output by @command{foo}.  It is then
12609 renamed to @file{data.stamp} after @command{foo} has run, because we
12610 do not want to update @file{data.stamp} if @command{foo} fails.
12611
12612 This solution still suffers from the second problem: the race
12613 condition in the recover rule.  If, after a successful build, a user
12614 erases @file{data.c} and @file{data.h}, and runs @samp{make -j}, then
12615 @command{make} may start both recover rules in parallel.  If the two
12616 instances of the rule execute @samp{$(MAKE) $(AM_MAKEFLAGS)
12617 data.stamp} concurrently the build is likely to fail (for instance, the
12618 two rules will create @file{data.tmp}, but only one can rename it).
12619
12620 Admittedly, such a weird situation does not arise during ordinary
12621 builds.  It occurs only when the build tree is mutilated.  Here
12622 @file{data.c} and @file{data.h} have been explicitly removed without
12623 also removing @file{data.stamp} and the other output files.
12624 @code{make clean; make} will always recover from these situations even
12625 with parallel makes, so you may decide that the recover rule is solely
12626 to help non-parallel make users and leave things as-is.  Fixing this
12627 requires some locking mechanism to ensure only one instance of the
12628 recover rule rebuilds @file{data.stamp}.  One could imagine something
12629 along the following lines.
12630
12631 @example
12632 data.c data.h data.w data.x: data.stamp
12633 ## Recover from the removal of $@@
12634         @@if test -f $@@; then :; else \
12635           trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
12636 ## mkdir is a portable test-and-set
12637           if mkdir data.lock 2>/dev/null; then \
12638 ## This code is being executed by the first process.
12639             rm -f data.stamp; \
12640             $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
12641             result=$$?; rm -rf data.lock; exit $$result; \
12642           else \
12643 ## This code is being executed by the follower processes.
12644 ## Wait until the first process is done.
12645             while test -d data.lock; do sleep 1; done; \
12646 ## Succeed if and only if the first process succeeded.
12647             test -f data.stamp; \
12648           fi; \
12649         fi
12650 @end example
12651
12652 Using a dedicated witness, like @file{data.stamp}, is very handy when
12653 the list of output files is not known beforehand.  As an illustration,
12654 consider the following rules to compile many @file{*.el} files into
12655 @file{*.elc} files in a single command.  It does not matter how
12656 @code{ELFILES} is defined (as long as it is not empty: empty targets
12657 are not accepted by POSIX).
12658
12659 @example
12660 ELFILES = one.el two.el three.el @dots{}
12661 ELCFILES = $(ELFILES:=c)
12662
12663 elc-stamp: $(ELFILES)
12664         @@rm -f elc-temp
12665         @@touch elc-temp
12666         $(elisp_comp) $(ELFILES)
12667         @@mv -f elc-temp $@@
12668
12669 $(ELCFILES): elc-stamp
12670         @@if test -f $@@; then :; else \
12671 ## Recover from the removal of $@@
12672           trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12673           if mkdir elc-lock 2>/dev/null; then \
12674 ## This code is being executed by the first process.
12675             rm -f elc-stamp; \
12676             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12677             rmdir elc-lock; \
12678           else \
12679 ## This code is being executed by the follower processes.
12680 ## Wait until the first process is done.
12681             while test -d elc-lock; do sleep 1; done; \
12682 ## Succeed if and only if the first process succeeded.
12683             test -f elc-stamp; exit $$?; \
12684 @c $$
12685           fi; \
12686         fi
12687 @end example
12688
12689 These solutions all still suffer from the third problem, namely that
12690 they break the promise that @samp{make -n} should not cause any actual
12691 changes to the tree.  For those solutions that do not create lock files,
12692 it is possible to split the recover rules into two separate recipe
12693 commands, one of which does all work but the recursion, and the
12694 other invokes the recursive @samp{$(MAKE)}.  The solutions involving
12695 locking could act upon the contents of the @samp{MAKEFLAGS} variable,
12696 but parsing that portably is not easy (@pxref{The Make Macro MAKEFLAGS,,,
12697 autoconf, The Autoconf Manual}).  Here is an example:
12698
12699 @example
12700 ELFILES = one.el two.el three.el @dots{}
12701 ELCFILES = $(ELFILES:=c)
12702
12703 elc-stamp: $(ELFILES)
12704         @@rm -f elc-temp
12705         @@touch elc-temp
12706         $(elisp_comp) $(ELFILES)
12707         @@mv -f elc-temp $@@
12708
12709 $(ELCFILES): elc-stamp
12710 ## Recover from the removal of $@@
12711         @@dry=; for f in x $$MAKEFLAGS; do \
12712           case $$f in \
12713             *=*|--*);; \
12714             *n*) dry=:;; \
12715           esac; \
12716         done; \
12717         if test -f $@@; then :; else \
12718           $$dry trap 'rm -rf elc-lock elc-stamp' 1 2 13 15; \
12719           if $$dry mkdir elc-lock 2>/dev/null; then \
12720 ## This code is being executed by the first process.
12721             $$dry rm -f elc-stamp; \
12722             $(MAKE) $(AM_MAKEFLAGS) elc-stamp; \
12723             $$dry rmdir elc-lock; \
12724           else \
12725 ## This code is being executed by the follower processes.
12726 ## Wait until the first process is done.
12727             while test -d elc-lock && test -z "$$dry"; do \
12728 @c $$
12729               sleep 1; \
12730             done; \
12731 ## Succeed if and only if the first process succeeded.
12732             $$dry test -f elc-stamp; exit $$?; \
12733           fi; \
12734         fi
12735 @end example
12736
12737 For completeness it should be noted that GNU @command{make} is able to
12738 express rules with multiple output files using pattern rules
12739 (@pxref{Pattern Examples, , Pattern Rule Examples, make, The GNU Make
12740 Manual}).  We do not discuss pattern rules here because they are not
12741 portable, but they can be convenient in packages that assume GNU
12742 @command{make}.
12743
12744
12745 @node Hard-Coded Install Paths
12746 @section Installing to Hard-Coded Locations
12747
12748 @display
12749 My package needs to install some configuration file.  I tried to use
12750 the following rule, but @samp{make distcheck} fails.  Why?
12751
12752 @example
12753 # Do not do this.
12754 install-data-local:
12755         $(INSTALL_DATA) $(srcdir)/afile $(DESTDIR)/etc/afile
12756 @end example
12757 @end display
12758
12759 @display
12760 My package needs to populate the installation directory of another
12761 package at install-time.  I can easily compute that installation
12762 directory in @file{configure}, but if I install files therein,
12763 @samp{make distcheck} fails.  How else should I do?
12764 @end display
12765
12766 These two setups share their symptoms: @samp{make distcheck} fails
12767 because they are installing files to hard-coded paths.  In the later
12768 case the path is not really hard-coded in the package, but we can
12769 consider it to be hard-coded in the system (or in whichever tool that
12770 supplies the path).  As long as the path does not use any of the
12771 standard directory variables (@samp{$(prefix)}, @samp{$(bindir)},
12772 @samp{$(datadir)}, etc.), the effect will be the same:
12773 user-installations are impossible.
12774
12775 As a (non-root) user who wants to install a package, you usually have no
12776 right to install anything in @file{/usr} or @file{/usr/local}.  So you
12777 do something like @samp{./configure --prefix ~/usr} to install a
12778 package in your own @file{~/usr} tree.
12779
12780 If a package attempts to install something to some hard-coded path
12781 (e.g., @file{/etc/afile}), regardless of this @option{--prefix} setting,
12782 then the installation will fail.  @samp{make distcheck} performs such
12783 a @option{--prefix} installation, hence it will fail too.
12784
12785 Now, there are some easy solutions.
12786
12787 The above @code{install-data-local} example for installing
12788 @file{/etc/afile} would be better replaced by
12789
12790 @example
12791 sysconf_DATA = afile
12792 @end example
12793
12794 @noindent
12795 by default @code{sysconfdir} will be @samp{$(prefix)/etc}, because
12796 this is what the GNU Standards require.  When such a package is
12797 installed on an FHS compliant system, the installer will have to set
12798 @samp{--sysconfdir=/etc}.  As the maintainer of the package you
12799 should not be concerned by such site policies: use the appropriate
12800 standard directory variable to install your files so that the installer
12801 can easily redefine these variables to match their site conventions.
12802
12803 Installing files that should be used by another package is slightly
12804 more involved.  Let's take an example and assume you want to install
12805 a shared library that is a Python extension module.  If you ask Python
12806 where to install the library, it will answer something like this:
12807
12808 @example
12809 % @kbd{python -c 'from distutils import sysconfig;
12810              print sysconfig.get_python_lib(1,0)'}
12811 /usr/lib/python2.5/site-packages
12812 @end example
12813
12814 If you indeed use this absolute path to install your shared library,
12815 non-root users will not be able to install the package, hence
12816 distcheck fails.
12817
12818 Let's do better.  The @samp{sysconfig.get_python_lib()} function
12819 actually accepts a third argument that will replace Python's
12820 installation prefix.
12821
12822 @example
12823 % @kbd{python -c 'from distutils import sysconfig;
12824              print sysconfig.get_python_lib(1,0,"$@{exec_prefix@}")'}
12825 $@{exec_prefix@}/lib/python2.5/site-packages
12826 @end example
12827
12828 You can also use this new path.  If you do
12829 @itemize @bullet
12830 @item
12831 root users can install your package with the same @option{--prefix}
12832 as Python (you get the behavior of the previous attempt)
12833
12834 @item
12835 non-root users can install your package too, they will have the
12836 extension module in a place that is not searched by Python but they
12837 can work around this using environment variables (and if you installed
12838 scripts that use this shared library, it's easy to tell Python were to
12839 look in the beginning of your script, so the script works in both
12840 cases).
12841 @end itemize
12842
12843 The @code{AM_PATH_PYTHON} macro uses similar commands to define
12844 @samp{$(pythondir)} and @samp{$(pyexecdir)} (@pxref{Python}).
12845
12846 Of course not all tools are as advanced as Python regarding that
12847 substitution of @var{prefix}.  So another strategy is to figure the
12848 part of the installation directory that must be preserved.  For
12849 instance, here is how @code{AM_PATH_LISPDIR} (@pxref{Emacs Lisp})
12850 computes @samp{$(lispdir)}:
12851
12852 @example
12853 $EMACS -batch -q -eval '(while load-path
12854   (princ (concat (car load-path) "\n"))
12855   (setq load-path (cdr load-path)))' >conftest.out
12856 lispdir=`sed -n
12857   -e 's,/$,,'
12858   -e '/.*\/lib\/x*emacs\/site-lisp$/@{
12859         s,.*/lib/\(x*emacs/site-lisp\)$,$@{libdir@}/\1,;p;q;
12860       @}'
12861   -e '/.*\/share\/x*emacs\/site-lisp$/@{
12862         s,.*/share/\(x*emacs/site-lisp\),$@{datarootdir@}/\1,;p;q;
12863       @}'
12864   conftest.out`
12865 @end example
12866
12867 I.e., it just picks the first directory that looks like
12868 @file{*/lib/*emacs/site-lisp} or @file{*/share/*emacs/site-lisp} in
12869 the search path of emacs, and then substitutes @samp{$@{libdir@}} or
12870 @samp{$@{datadir@}} appropriately.
12871
12872 The emacs case looks complicated because it processes a list and
12873 expects two possible layouts, otherwise it's easy, and the benefits for
12874 non-root users are really worth the extra @command{sed} invocation.
12875
12876
12877 @node Debugging Make Rules
12878 @section Debugging Make Rules
12879 @cindex debugging rules
12880 @cindex rules, debugging
12881
12882 The rules and dependency trees generated by @command{automake} can get
12883 rather complex, and leave the developer head-scratching when things
12884 don't work as expected.  Besides the debug options provided by the
12885 @command{make} command (@pxref{Options Summary,,, make, The GNU Make
12886 Manual}), here's a couple of further hints for debugging makefiles
12887 generated by @command{automake} effectively:
12888
12889 @itemize
12890 @item
12891 If less verbose output has been enabled in the package with the use
12892 of silent rules (@pxref{Automake Silent Rules}), you can use
12893 @code{make V=1} to see the commands being executed.
12894 @item
12895 @code{make -n} can help show what would be done without actually doing
12896 it.  Note however, that this will @emph{still execute} commands prefixed
12897 with @samp{+}, and, when using GNU @command{make}, commands that contain
12898 the strings @samp{$(MAKE)} or @samp{$@{MAKE@}} (@pxref{Instead of
12899 Execution,,, make, The GNU Make Manual}).
12900 Typically, this is helpful to show what recursive rules would do, but it
12901 means that, in your own rules, you should not mix such recursion with
12902 actions that change any files.@footnote{Automake's @samp{dist} and
12903 @samp{distcheck} rules had a bug in this regard in that they created
12904 directories even with @option{-n}, but this has been fixed in Automake
12905 1.11.}  Furthermore, note that GNU @command{make} will update
12906 prerequisites for the @file{Makefile} file itself even with @option{-n}
12907 (@pxref{Remaking Makefiles,,, make, The GNU Make Manual}).
12908 @item
12909 @code{make SHELL="/bin/bash -vx"} can help debug complex rules.
12910 @xref{The Make Macro SHELL,,, autoconf, The Autoconf Manual}, for some
12911 portability quirks associated with this construct.
12912 @item
12913 @code{echo 'print: ; @@echo "$(VAR)"' | make -f Makefile -f - print}
12914 can be handy to examine the expanded value of variables.  You may need
12915 to use a target other than @samp{print} if that is already used or a
12916 file with that name exists.
12917 @item
12918 @url{http://bashdb.sourceforge.net/@/remake/} provides a modified
12919 GNU @command{make} command called @command{remake} that copes with
12920 complex GNU @command{make}-specific Makefiles and allows to trace
12921 execution, examine variables, and call rules interactively, much like
12922 a debugger.
12923 @end itemize
12924
12925
12926 @node Reporting Bugs
12927 @section Reporting Bugs
12928
12929 Most nontrivial software has bugs.  Automake is no exception.  Although
12930 we cannot promise we can or will fix a bug, and we might not even agree
12931 that it is a bug, we want to hear about problems you encounter. Often we
12932 agree they are bugs and want to fix them.
12933
12934 To make it possible for us to fix a bug, please report it. In order to
12935 do so effectively, it helps to know when and how to do it.
12936
12937 Before reporting a bug, it is a good idea to see if it is already known.
12938 You can look at the @uref{http://debbugs.gnu.org/, GNU Bug Tracker}
12939 and the @uref{http://lists.gnu.org/@/archive/@/html/@/bug-automake/,
12940 bug-automake mailing list archives} for previous bug reports.  We
12941 previously used a
12942 @uref{http://sourceware.org/@/cgi-bin/@/gnatsweb.pl?database=automake,
12943 Gnats database} for bug tracking, so some bugs might have been reported
12944 there already.  Please do not use it for new bug reports, however.
12945
12946 If the bug is not already known, it should be reported.  It is very
12947 important to report bugs in a way that is useful and efficient.  For
12948 this, please familiarize yourself with
12949 @uref{http://www.chiark.greenend.org.uk/@/~sgtatham/@/bugs.html, How to
12950 Report Bugs Effectively} and
12951 @uref{http://catb.org/@/~esr/@/faqs/@/smart-questions.html, How to Ask
12952 Questions the Smart Way}.  This helps you and developers to save time
12953 which can then be spent on fixing more bugs and implementing more
12954 features.
12955
12956 For a bug report, a feature request or other suggestions, please send
12957 email to @email{@value{PACKAGE_BUGREPORT}}.  This will then open a new
12958 bug in the @uref{http://debbugs.gnu.org/@/automake, bug tracker}.  Be
12959 sure to include the versions of Autoconf and Automake that you use.
12960 Ideally, post a minimal @file{Makefile.am} and @file{configure.ac} that
12961 reproduces the problem you encounter.  If you have encountered test
12962 suite failures, please attach the @file{test-suite.log} file.
12963
12964 @c ========================================================== Appendices
12965
12966 @page
12967 @node Copying This Manual
12968 @appendix Copying This Manual
12969
12970 @menu
12971 * GNU Free Documentation License::  License for copying this manual
12972 @end menu
12973
12974 @node GNU Free Documentation License
12975 @appendixsec GNU Free Documentation License
12976 @include fdl.texi
12977
12978 @page
12979 @node Indices
12980 @appendix Indices
12981
12982 @menu
12983 * Macro Index::                 Index of Autoconf macros
12984 * Variable Index::              Index of Makefile variables
12985 * General Index::               General index
12986 @end menu
12987
12988 @node Macro Index
12989 @appendixsec Macro Index
12990
12991 @printindex fn
12992
12993 @node Variable Index
12994 @appendixsec Variable Index
12995
12996 @printindex vr
12997
12998 @node General Index
12999 @appendixsec General Index
13000
13001 @printindex cp
13002
13003
13004 @bye
13005
13006 @c  LocalWords:  texinfo setfilename settitle setchapternewpage texi direntry
13007 @c  LocalWords:  dircategory in's aclocal ifinfo titlepage Tromey vskip pt sp
13008 @c  LocalWords:  filll defcodeindex ov cv op tr syncodeindex fn cp vr ifnottex
13009 @c  LocalWords:  dir Automake's ac Dist Gnits gnits dfn Autoconf's pxref
13010 @c  LocalWords:  cindex Autoconf autoconf perl samp cvs dist trindex SUBST foo
13011 @c  LocalWords:  xs emph FIXME ref vindex pkglibdir pkgincludedir pkgdatadir mt
13012 @c  LocalWords:  pkg libdir cpio bindir sbindir rmt pax sbin zar zardir acindex
13013 @c  LocalWords:  HTML htmldir html noinst TEXINFOS nodist nobase strudel CFLAGS
13014 @c  LocalWords:  libmumble CC YFLAGS itemx de fication config url comp
13015 @c  LocalWords:  depcomp elisp sh mdate mkinstalldirs mkdir py tex dvi ps pdf
13016 @c  LocalWords:  ylwrap zardoz INIT gettext acinclude mv FUNCS LIBOBJS LDADD fr
13017 @c  LocalWords:  uref featureful dnl src LINGUAS es ko nl pl sl sv PROG ISC doc
13018 @c  LocalWords:  POSIX STDC fcntl FUNC ALLOCA blksize struct stat intl po chmod
13019 @c  LocalWords:  ChangeLog SUBDIRS gettextize gpl testdata getopt INTLLIBS cpp
13020 @c  LocalWords:  localedir datadir DLOCALEDIR DEXIT CPPFLAGS autoreconf opindex
13021 @c  LocalWords:  AUX var symlink deps Wno Wnone package's aclocal's distclean
13022 @c  LocalWords:  ltmain xref LIBSOURCE LIBSOURCES LIBOBJ MEMCMP vs RANLIB CXX
13023 @c  LocalWords:  LDFLAGS LIBTOOL libtool XTRA LIBS gettext's acdir APIVERSION
13024 @c  LocalWords:  dirlist noindent usr TIOCGWINSZ sc
13025 @c  LocalWords:  GWINSZ termios SRCDIR tarball bzip LISPDIR lispdir XEmacs CCAS
13026 @c  LocalWords:  emacsen MicroEmacs CCASFLAGS UX GCJ gcj GCJFLAGS posix DMALLOC
13027 @c  LocalWords:  dmalloc ldmalloc REGEX regex DEPDIR DEP DEFUN aclocaldir fi
13028 @c  LocalWords:  mymacro myothermacro AMFLAGS autopoint autogen libtoolize yum
13029 @c  LocalWords:  autoheader README MAKEFLAGS subdir Inetutils sync COND endif
13030 @c  LocalWords:  Miller's installable includedir inc pkgdata EXEEXT libexec bsd
13031 @c  LocalWords:  pkglib libexecdir prog libcpio cpio's dlopen dlpreopen linux
13032 @c  LocalWords:  subsubsection OBJEXT esac lib LTLIBRARIES liblob LIBADD AR ar
13033 @c  LocalWords:  ARFLAGS cru ing maude libgettext lo LTLIBOBJS rpath SGI PRE yy
13034 @c  LocalWords:  libmaude CCLD CXXFLAGS FFLAGS LFLAGS OBJCFLAGS RFLAGS DEFS cc
13035 @c  LocalWords:  OBJCXXFLAGS
13036 @c  LocalWords:  SHORTNAME vtable srcdir nostdinc basename yxx cxx ll lxx gdb
13037 @c  LocalWords:  lexers yymaxdepth maxdepth yyparse yylex yyerror yylval lval
13038 @c  LocalWords:  yychar yydebug yypact yyr yydef def yychk chk yypgo pgo yyact
13039 @c  LocalWords:  yyexca exca yyerrflag errflag yynerrs nerrs yyps yypv pv yys
13040 @c  LocalWords:  yystate yytmp tmp yyv yyval val yylloc lloc yyreds yytoks toks
13041 @c  LocalWords:  yylhs yylen yydefred yydgoto yysindex yyrindex yygindex yyname
13042 @c  LocalWords:  yytable yycheck yyrule byacc CXXCOMPILE CXXLINK FLINK cfortran
13043 @c  LocalWords:  Catalogue preprocessable FLIBS libfoo baz JAVACFLAGS java exe
13044 @c  LocalWords:  SunOS fying basenames exeext uninstalled oldinclude kr FSF's
13045 @c  LocalWords:  pkginclude oldincludedir sysconf sharedstate localstate gcc rm
13046 @c  LocalWords:  sysconfdir sharedstatedir localstatedir preexist CLEANFILES gz
13047 @c  LocalWords:  depfile tmpdepfile depmode const interoperate
13048 @c  LocalWords:  JAVAC javac JAVAROOT builddir CLASSPATH ENV pyc pyo pkgpython
13049 @c  LocalWords:  pyexecdir pkgpyexecdir Python's pythondir pkgpythondir txi ois
13050 @c  LocalWords:  installinfo vers MAKEINFO makeinfo MAKEINFOFLAGS noinstall rf
13051 @c  LocalWords:  mandir thesame alsothesame installman myexecbin DESTDIR Pinard
13052 @c  LocalWords:  uninstall installdirs uninstalls MOSTLYCLEANFILES mostlyclean
13053 @c  LocalWords:  DISTCLEANFILES MAINTAINERCLEANFILES GZIP gzip shar exp
13054 @c  LocalWords:  distdir distcheck distcleancheck listfiles distuninstallcheck
13055 @c  LocalWords:  VPATH tarfile stdout XFAIL DejaGnu dejagnu DEJATOOL runtest ln
13056 @c  LocalWords:  RUNTESTDEFAULTFLAGS toolchain RUNTESTFLAGS asis readme DVIPS
13057 @c  LocalWords:  installcheck gzipped tarZ std utils etags mkid cd
13058 @c  LocalWords:  ARGS taggable ETAGSFLAGS lang ctags CTAGSFLAGS GTAGS gtags idl
13059 @c  LocalWords:  foocc doit idlC multilibs ABIs cmindex defmac ARG enableval FC
13060 @c  LocalWords:  MSG xtrue DBG pathchk CYGWIN afile proglink versioned CVS's TE
13061 @c  LocalWords:  wildcards Autoconfiscated subsubheading autotools Meyering API
13062 @c  LocalWords:  ois's wildcard Wportability cartouche vrindex printindex Duret
13063 @c  LocalWords:  DSOMEFLAG DVERSION automake Lutz insertcopying versioning FAQ
13064 @c  LocalWords:  LTLIBOBJ Libtool's libtool's libltdl dlopening itutions libbar
13065 @c  LocalWords:  WANTEDLIBS libhello sublibraries libtop libsub dlopened Ratfor
13066 @c  LocalWords:  mymodule timestamps timestamp underquoted MAKEINFOHTMLFLAGS te
13067 @c  LocalWords:  GNUmakefile Subpackages subpackage's subpackages aux
13068 @c  LocalWords:  detailmenu Timeline pwd reldir AUTOM autom PREREQ FOOBAR libc
13069 @c  LocalWords:  libhand subpackage moduleN libmain libmisc FCFLAGS FCCOMPILE
13070 @c  LocalWords:  FCLINK subst sed ELCFILES elc MAKEINFOHTML dvips esyscmd ustar
13071 @c  LocalWords:  tarballs Woverride vfi ELFILES djm AutoMake honkin FSF
13072 @c  LocalWords:  fileutils precanned MacKenzie's reimplement termutils Tromey's
13073 @c  LocalWords:  cois gnitsians LIBPROGRAMS progs LIBLIBRARIES Textutils Ulrich
13074 @c  LocalWords:  Matzigkeit Drepper's Gord Matzigkeit's jm Dalley Debian org
13075 @c  LocalWords:  Administrivia ILU CORBA Sourceware Molenda sourceware Elliston
13076 @c  LocalWords:  dep Oliva Akim Demaille Aiieeee Demaillator Akim's sourcequake
13077 @c  LocalWords:  grep backported screenshots libgcj KB unnumberedsubsubsec pre
13078 @c  LocalWords:  precomputing hacky makedepend inline clearmake LD PRELOAD Rel
13079 @c  LocalWords:  syscalls perlhist acl pm multitable headitem fdl appendixsec
13080 @c  LocalWords:  LTALLOCA MALLOC malloc memcmp strdup alloca libcompat xyz DFOO
13081 @c  LocalWords:  unprefixed buildable preprocessed DBAZ DDATADIR WARNINGCFLAGS
13082 @c  LocalWords:  LIBFOOCFLAGS LIBFOOLDFLAGS ftable testSubDir obj LIBTOOLFLAGS
13083 @c  LocalWords:  barexec Pinard's automatize initialize lzip xz cscope